How to create a button on the menu for a plugin? How to create a button on the menu for a plugin?
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

How to create a button on the menu for a plugin?

Started by just_some_guy, October 04, 2007, 05:16:52 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

just_some_guy

Hey,

I have created a plugin and i am now creating the codebase. To do this i assume i just overwrite sections of the sample codebase.php included in the download and add some other code, correct?

Also, how do i create a new button on the admin menu for the plugin?
Also, i assume the configuration section, is the area where the user can customize the options displayed when they click on the admin menu, correct?

Sorry for all the questions, as you can probebly see: i am new to this.

Thanks!
Tambien, Hablo Español      PHP - Achieve Anything
"The Internet is becoming the town square for the global village of tomorrow. " - Bill Gates
Windows 7 Forums

François Keller

why did you not have a look into others plugins who have menu items in the admin menu ?
It's the best way to understand how plugin's works. (i did so before coding plugins  ;))
Avez vous lu la DOC ? la FAQ ? et cherché sur le forum avant de poster ?
Did you read the DOC ? the FAQ ? and search the board before posting ?
Mon Blog

just_some_guy

Tambien, Hablo Español      PHP - Achieve Anything
"The Internet is becoming the town square for the global village of tomorrow. " - Bill Gates
Windows 7 Forums

just_some_guy

Frantz, i see in your gallery stats plugin you use this code for selecting the lang file:

if (file_exists("plugins/stats/lang/{$CONFIG['lang']}.php")) {
  require "plugins/stats/lang/{$CONFIG['lang']}.php";
} else {require "plugins/stats/lang/english.php";}


can i use this too?
Tambien, Hablo Español      PHP - Achieve Anything
"The Internet is becoming the town square for the global village of tomorrow. " - Bill Gates
Windows 7 Forums

François Keller

yes of course.
Have you seen that you must have a lang file if you use this include file ?
Avez vous lu la DOC ? la FAQ ? et cherché sur le forum avant de poster ?
Did you read the DOC ? the FAQ ? and search the board before posting ?
Mon Blog

just_some_guy

Tambien, Hablo Español      PHP - Achieve Anything
"The Internet is becoming the town square for the global village of tomorrow. " - Bill Gates
Windows 7 Forums

just_some_guy

Hi am still having problems creating the codebase file, i have looked at several other codebases too.

The codebase consists of 3 parts:

- Executing database querys to accomadate the information.
- Creating the admin button.
- The html form which allows the user to conigure the plugin.

When i press install, it doesent just apply function plugin_install() . But it also carries on and trys to execute the querys that are used in the html form section (named function plugin_confiugure()

Can you suggest what i am doing wrong?
Tambien, Hablo Español      PHP - Achieve Anything
"The Internet is becoming the town square for the global village of tomorrow. " - Bill Gates
Windows 7 Forums

just_some_guy

Hello,

Im still having problems creating the admin button.

Here is some code i found on another plugin (now slightly modified)


// add config button
function plugin_config_button($href,$title,$target,$link)
{
  global $template_gallery_admin_menu;

  $new_template = $template_gallery_admin_menu;
  $button = template_extract_block($new_template,'documentation');
  $params = array(
      '{DOCUMENTATION_HREF}' => $href,
      '{DOCUMENTATION_TITLE}' => $title,
      'target="cpg_documentation"' => $target,
      '{DOCUMENTATION_LNK}' => $link,
   );
   $new_button="<!-- BEGIN $link -->".template_eval($button,$params)."<!-- END $link -->\n";
   template_extract_block($template_gallery_admin_menu,'documentation',"<!-- BEGIN documentation -->" . $button . "<!-- END documentation -->\n" . $new_button);
}
// add admin button to start of each page
function plugin_page_start()
{


if (GALLERY_ADMIN_MODE) {
plugin_config_button('index.php?file=plugin/plugin',plugin,'',plugin);

}

}


I get this when i try and install it.

unexpected T_STRING

Any ideas? thanks,


Tambien, Hablo Español      PHP - Achieve Anything
"The Internet is becoming the town square for the global village of tomorrow. " - Bill Gates
Windows 7 Forums

Stramm

post the entire file and not just parts of the code

just_some_guy

Ok, this is my plugin: It creates an interface for users to add meta tags to thier gallery:

Heres the code base:


<?php
/*************************
  Coppermine Photo Gallery
  ************************
  Copyright (c) 2003-2007 Coppermine Dev Team
  v1.1 originally written by Gregory DEMAR

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License version 3
  as published by the Free Software Foundation.

  ********************************************
  Coppermine version: 1.4.13
  $Source$
  $Revision: 3912 $
  $Author: gaugau $
  $Date: 2007-08-24 16:48:44 +0200 (Fr, 24 Aug 2007) $
**********************************************/
/***************************
 META DATA PLUGIN
 ****************************
 by - just_some_guy - mysimtractor.com
 *************************************
 version: 1.0
 ************************************/

if (!defined('IN_COPPERMINE')) die('Not in Coppermine...');

require 
'include/config.inc.php';
require 
'include/init.inc.php';

// Add an install action
$thisplugin->add_action('plugin_install','meta_install');

// Add a configure action
$thisplugin->add_action('plugin_configure','meta_configure');

// Add menu button

$thisplugin->add_action('page_start','meta_page_start');


// Install function
// Checks if uid is 'foo' and pwd is 'bar'; If so, then install the plugin

function meta_install() {

    
// Install
    
if ($_POST['uid']=='foo' && $_POST['pwd']=='bar') {

        return 
true;

    
// Loop again
    
} else {

        return 
1;
    }
}

$resultmysql_query("ALTER TABLE {$CONFIG['TABLE_CONFIG']} CHANGE `value` `value` MEDIUMTEXT CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL");


$resultmysql_query("INSERT INTO {$CONFIG['TABLE_CONFIG']} (`name`, `value`) VALUES ('meta_info', 'empty')");


// Display the config options
function meta_confiugure() {
    echo <<< EOT
        <strong><span style="text-decoration: underline">Meta Data Plugin</span></strong><br />
    <br />
    <?php echo 
$lang_plugin_meta_how[how]; ?>
:<br />
    <br />
<form method="post" action="{$_SERVER['PHP_SELF']}" >
    <table style="width: 500px" >
        <tr>
            <td style="width: 206px">
                <?php echo $lang_plugin_meta_menu[description]; ?> -</td>
            <td style="width: 205px">


   
            <input id="Description" type="text" /></td>
            <td style="width: 250px">
                <?php echo $lang_plugin_meta_describe[description_txt]; ?></td>
        </tr>
        <tr>
            <td style="width: 206px">
                <?php echo $lang_plugin_meta_menu[keyword]; ?> -</td>
            <td style="width: 205px">
   
    <input id="Keywords" type="text" /></td>
            <td style="width: 250px">
                <?php echo $lang_plugin_meta_describe[keyword_txt]; ?></td>
        </tr>
        <tr>
            <td style="width: 206px; height: 21px">
                <?php echo $lang_plugin_meta_menu[author]; ?></td>
            <td style="width: 205px; height: 21px">
   
    <input id="Author" type="text" /></td>
            <td style="width: 250px; height: 21px">
            </td>
        </tr>
        <tr>
            <td style="width: 206px; height: 21px">
                 <?php echo $lang_plugin_meta_menu[robots]; ?> -</td>
            <td style="width: 205px; height: 21px">
    <input id="Robots" type="text" /></td>
            <td style="width: 250px; height: 21px">
                See <a href="http://www.robotstxt.org/wc/meta-user.html">here</a> for more info
                on this meta tag.</td>
        </tr>
        <tr>
            <td style="width: 206px; height: 21px">
    <input id="Submit" type="submit"  value="<?php echo $lang_plugin_meta_go[apply]; ?>" /></td>
        </tr>
    </table>
</form>
EOT;
}
// Create variables from the inputs

$description = "$_POST[Description]";
$keywords = "$_POST[Keywords]";
$author = "$_POST[Author]";
$robots = "$_POST[robots]";


// Update the table rows with the variables

$value = "<META name="Author" content="" . $_POST['Description'] . "">
<META name="keywords" content="" . $_POST['Keywords'] . "" />
<META name="description" content="" . $_POST['Author'] . " " />
<meta name="robots" content="" . $_POST['robots'] . " " />";

$result = mysql_query("UPDATE {$CONFIG['TABLE_CONFIG']} SET value='" . mysql_real_escape_string($value) . "'
WHERE name='meta_info'") or die(mysql_error());

EOT;

// add config button
function plugin_config_button($href,$title,$target,$link)
{
  global $template_gallery_admin_menu;

  $new_template = $template_gallery_admin_menu;
  $button = template_extract_block($new_template,'documentation');
  $params = array(
      '{DOCUMENTATION_HREF}' => $href,
      '{DOCUMENTATION_TITLE}' => $title,
      'target="cpg_documentation"' => $target,
      '{DOCUMENTATION_LNK}' => $link,
   );
   $new_button="<!-- BEGIN $link -->".template_eval($button,$params)."<!-- END $link -->\n";
   template_extract_block($template_gallery_admin_menu,'documentation',"<!-- BEGIN documentation -->" . $button . "<!-- END documentation -->\n" . $new_button);
}
// add admin button to start of each page
function meta_data_page_start()
{


if (GALLERY_ADMIN_MODE) {
plugin_config_button('index.php?file=meta_data/meta_data',Meta Data,'',Meta Data);

}

}

?>


I would also like to thank the guys at the Dev Shed forum with the help in debugging some parts of the above.

Thanks Stramm.
Tambien, Hablo Español      PHP - Achieve Anything
"The Internet is becoming the town square for the global village of tomorrow. " - Bill Gates
Windows 7 Forums

Nibbler

Parse error on line 131 is caused by not escaping quotes
Parse error on line 163 is caused by not having quotes around 'Meta Data'

just_some_guy

But the script stops with a:

Parse error: syntax error, unexpected T_STRING
in /home/fhlinux164/m/path/plugins/meta_data/codebase.php on line 131

here:

$value = "<META name="Author" content="" . $_POST['Description'] . "" />
<META name="keywords" content="" . $_POST['Keywords'] . "" />
<META name="description" content="" . $_POST['Author'] . "" />
<meta name="robots" content="" . $_POST['robots'] . "" />";


Line 131 being the first line with the $value

Do you see anything wrong?

Thanks.
Tambien, Hablo Español      PHP - Achieve Anything
"The Internet is becoming the town square for the global village of tomorrow. " - Bill Gates
Windows 7 Forums

Stramm

Nibbler already told you that this is caused by not escaping quotes

not escaped: """
escaped:"\""

http://php.net/manual/en/language.types.string.php

just_some_guy

sorry i actually pasted the wrong code:


$value = "<META name=\"Author\" content=\"" . $_POST['Description'] . "\" />
<META name=\"keywords\" content=\"" . $_POST['Keywords'] . "\" />
<META name=\"description\" content=\"" . $_POST['Author'] . "\" />
<meta name=\"robots\" content=\"" . $_POST['robots'] . "\" />";
Tambien, Hablo Español      PHP - Achieve Anything
"The Internet is becoming the town square for the global village of tomorrow. " - Bill Gates
Windows 7 Forums

just_some_guy

It is now saying the following:

Fatal error: Cannot redeclare cpggetmicrotime() (previously declared
in /home/fhlinux164/m/include/init.inc.php:35)
in /home/fhlinux164/m/path/cpg1412/include/init.inc.php on line 37


Here is the plugins init.inc.php


<?php
/*************************
  Coppermine Photo Gallery
  ************************
  Copyright (c) 2003-2007 Coppermine Dev Team
  v1.1 originally written by Gregory DEMAR

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License version 3
  as published by the Free Software Foundation.

  ********************************************
  Coppermine version: 1.4.13
  $Source$
  $Revision: 3912 $
  $Author: gaugau $
  $Date: 2007-08-24 16:48:44 +0200 (Fr, 24 Aug 2007) $
**********************************************/
/***************************
 META DATA PLUGIN
 ****************************
 by - just_some_guy - mysimtractor.com
 *************************************
 version: 1.0
 ************************************/
/*************************************
 Following code by Frantz, thanks!
*************************************/

if (!defined('IN_COPPERMINE')) { die('Not in Coppermine...');}

// submit your lang file for this plugin on the coppermine forums
// plugin will try to use the configured language if it is available.

if (file_exists("plugins/meta_data/lang/{$CONFIG['lang']}.php")) {
  require 
"plugins/meta_data/lang/{$CONFIG['lang']}.php";
} else {require 
"plugins/meta_data/lang/english.php";}
?>


I really apologise for all this btw. Sorry.
Tambien, Hablo Español      PHP - Achieve Anything
"The Internet is becoming the town square for the global village of tomorrow. " - Bill Gates
Windows 7 Forums

Nibbler

Messages means init,inc.php is being included twice.

just_some_guy

But it is only included once on the codebase. i dont under stand?
Tambien, Hablo Español      PHP - Achieve Anything
"The Internet is becoming the town square for the global village of tomorrow. " - Bill Gates
Windows 7 Forums

Nibbler

The codebase.php is included by init.inc.php in the first place, so including init.inc.php from your codebase.php makes no sense atall.

just_some_guy

Sorry, i am new to making plugins and never knew that, the good thing is when i click install it does not return an error. And it goes to a screen with "Configure plugin: Meta Data" but nothing is shown underthat. see image.
Tambien, Hablo Español      PHP - Achieve Anything
"The Internet is becoming the town square for the global village of tomorrow. " - Bill Gates
Windows 7 Forums

just_some_guy

Can nobody help me with this problem?

here is the file:

Thanks,

<?php
/*************************
  Coppermine Photo Gallery
  ************************
  Copyright (c) 2003-2007 Coppermine Dev Team
  v1.1 originally written by Gregory DEMAR

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License version 3
  as published by the Free Software Foundation.

  ********************************************
  Coppermine version: 1.4.13
  $Source$
  $Revision: 3912 $
  $Author: gaugau $
  $Date: 2007-08-24 16:48:44 +0200 (Fr, 24 Aug 2007) $
**********************************************/
/***************************
 META DATA PLUGIN
 ****************************
 by - just_some_guy - mysimtractor.com
 *************************************
 version: 1.0
 ************************************/

if (!defined('IN_COPPERMINE')) die('Not in Coppermine...');

require 
'include/config.inc.php';


// Add an install action
$thisplugin->add_action('plugin_install','meta_install');

// Add a configure action
$thisplugin->add_action('plugin_configure','meta_configure');

// Add menu button

$thisplugin->add_action('page_start','meta_page_start');


// Install function
// Checks if uid is 'foo' and pwd is 'bar'; If so, then install the plugin

function meta_install() {

    
// Install
    
if ($_POST['uid']=='foo' && $_POST['pwd']=='bar') {

        return 
true;

    
// Loop again
    
} else {

        return 
1;
    }
}

$resultmysql_query("ALTER TABLE {$CONFIG['TABLE_CONFIG']} CHANGE `value` `value` MEDIUMTEXT CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL");


$resultmysql_query("INSERT INTO {$CONFIG['TABLE_CONFIG']} (`name`, `value`) VALUES ('meta_info', 'empty')");


// Display the config options
function meta_confiugure() {
    echo <<< EOT
        <strong><span style="text-decoration: underline">Meta Data Plugin</span></strong><br />
    <br />
    <?php echo 
$lang_plugin_meta_how[how]; ?>
:<br />
    <br />
<form method="post" action="{$_SERVER['PHP_SELF']}" >
    <table style="width: 500px" >
        <tr>
            <td style="width: 206px">
                <?php echo $lang_plugin_meta_menu[description]; ?> -</td>
            <td style="width: 205px">


   
            <input id="Description" type="text" /></td>
            <td style="width: 250px">
                <?php echo $lang_plugin_meta_describe[description_txt]; ?></td>
        </tr>
        <tr>
            <td style="width: 206px">
                <?php echo $lang_plugin_meta_menu[keyword]; ?> -</td>
            <td style="width: 205px">
   
    <input id="Keywords" type="text" /></td>
            <td style="width: 250px">
                <?php echo $lang_plugin_meta_describe[keyword_txt]; ?></td>
        </tr>
        <tr>
            <td style="width: 206px; height: 21px">
                <?php echo $lang_plugin_meta_menu[author]; ?></td>
            <td style="width: 205px; height: 21px">
   
    <input id="Author" type="text" /></td>
            <td style="width: 250px; height: 21px">
            </td>
        </tr>
        <tr>
            <td style="width: 206px; height: 21px">
                 <?php echo $lang_plugin_meta_menu[robots]; ?> -</td>
            <td style="width: 205px; height: 21px">
    <input id="Robots" type="text" /></td>
            <td style="width: 250px; height: 21px">
                See <a href="http://www.robotstxt.org/wc/meta-user.html">here</a> for more info
                on this meta tag.</td>
        </tr>
        <tr>
            <td style="width: 206px; height: 21px">
    <input id="Submit" type="submit"  value="<?php echo $lang_plugin_meta_go[apply]; ?>" /></td>
        </tr>
    </table>
</form>
EOT;
}
// Create variables from the inputs

$description = "$_POST[Description]";
$keywords = "$_POST[Keywords]";
$author = "$_POST[Author]";
$robots = "$_POST[robots]";


// Update the table rows with the variables

$value = "<META name=\"Author\" content=\"" . $_POST['Description'] . "\" />
<META name=\"keywords\" content=\"" . $_POST['Keywords'] . "\" />
<META name=\"description\" content=\"" . $_POST['Author'] . "\" />
<meta name=\"robots\" content=\"" . $_POST['robots'] . "\" />";

$result = mysql_query("UPDATE {$CONFIG['TABLE_CONFIG']} SET value='" . mysql_real_escape_string($value) . "'
WHERE name='meta_info'") or die(mysql_error());

EOT;

// add config button
function plugin_config_button($href,$title,$target,$link)
{
  global $template_gallery_admin_menu;

  $new_template = $template_gallery_admin_menu;
  $button = template_extract_block($new_template,'documentation');
  $params = array(
      '{DOCUMENTATION_HREF}' => $href,
      '{DOCUMENTATION_TITLE}' => $title,
      'target="cpg_documentation"' => $target,
      '{DOCUMENTATION_LNK}' => $link,
   );
   $new_button="<!-- BEGIN $link -->".template_eval($button,$params)."<!-- END $link -->
";
   template_extract_block($template_gallery_admin_menu,'documentation',"<!-- BEGIN documentation -->" . $button . "<!-- END documentation -->
" . $new_button);
}
// add admin button to start of each page
function meta_data_page_start()
{


if (GALLERY_ADMIN_MODE) {
plugin_config_button('index.php?file=meta_data/meta_data',"Meta Data",'',"Meta Data");

}

}

?>
Tambien, Hablo Español      PHP - Achieve Anything
"The Internet is becoming the town square for the global village of tomorrow. " - Bill Gates
Windows 7 Forums