forum.coppermine-gallery.net

Support => cpg1.4.x Support => Older/other versions => cpg1.4 plugins => Topic started by: just_some_guy on October 04, 2007, 05:16:52 pm

Title: How to create a button on the menu for a plugin?
Post by: just_some_guy on October 04, 2007, 05:16:52 pm
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!
Title: Re: How to create a button on the menu for a plugin?
Post by: François Keller on October 04, 2007, 05:20:59 pm
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  ;))
Title: Re: How to create a button on the menu for a plugin?
Post by: just_some_guy on October 04, 2007, 05:21:57 pm
ok, thanks, will do.
Title: Re: How to create a button on the menu for a plugin?
Post by: just_some_guy on October 04, 2007, 07:39:04 pm
Frantz, i see in your gallery stats plugin you use this code for selecting the lang file:

Code: [Select]
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?
Title: Re: How to create a button on the menu for a plugin?
Post by: François Keller on October 04, 2007, 07:46:31 pm
yes of course.
Have you seen that you must have a lang file if you use this include file ?
Title: Re: How to create a button on the menu for a plugin?
Post by: just_some_guy on October 04, 2007, 07:48:47 pm
Thanks very much!

yes, i see that.
Title: Re: How to create a button on the menu for a plugin?
Post by: just_some_guy on October 05, 2007, 07:53:59 pm
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?
Title: Re: How to create a button on the menu for a plugin?
Post by: just_some_guy on October 09, 2007, 10:36:40 pm
Hello,

Im still having problems creating the admin button.

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

Code: [Select]
// 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,


Title: Re: How to create a button on the menu for a plugin?
Post by: Stramm on October 11, 2007, 02:21:57 pm
post the entire file and not just parts of the code
Title: Re: How to create a button on the menu for a plugin?
Post by: just_some_guy on October 11, 2007, 08:10:24 pm
Ok, this is my plugin: It creates an interface for users to add meta tags to thier gallery:

Heres the code base:

Code: [Select]
<?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.
Title: Re: How to create a button on the menu for a plugin?
Post by: Nibbler on October 11, 2007, 08:18:24 pm
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'
Title: Re: How to create a button on the menu for a plugin?
Post by: just_some_guy on October 11, 2007, 08:32:50 pm
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:

Code: [Select]
$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.
Title: Re: How to create a button on the menu for a plugin?
Post by: Stramm on October 11, 2007, 08:43:05 pm
Nibbler already told you that this is caused by not escaping quotes

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

http://php.net/manual/en/language.types.string.php
Title: Re: How to create a button on the menu for a plugin?
Post by: just_some_guy on October 11, 2007, 08:44:53 pm
sorry i actually pasted the wrong code:

Code: [Select]

$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'] . "\" />";
Title: Re: How to create a button on the menu for a plugin?
Post by: just_some_guy on October 11, 2007, 08:49:29 pm
It is now saying the following:

Code: [Select]
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

Code: [Select]
<?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.
Title: Re: How to create a button on the menu for a plugin?
Post by: Nibbler on October 11, 2007, 10:37:37 pm
Messages means init,inc.php is being included twice.
Title: Re: How to create a button on the menu for a plugin?
Post by: just_some_guy on October 11, 2007, 10:49:59 pm
But it is only included once on the codebase. i dont under stand?
Title: Re: How to create a button on the menu for a plugin?
Post by: Nibbler on October 11, 2007, 11:05:00 pm
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.
Title: Re: How to create a button on the menu for a plugin?
Post by: just_some_guy on October 11, 2007, 11:10:14 pm
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.
Title: Re: How to create a button on the menu for a plugin?
Post by: just_some_guy on October 12, 2007, 10:30:38 pm
Can nobody help me with this problem?

here is the file:

Thanks,

Code: [Select]
<?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");

}

}

?>
Title: Re: How to create a button on the menu for a plugin?
Post by: Nibbler on October 12, 2007, 11:24:34 pm
You spelled it confiugure instead of configure. Please stop asking endless coding questions.