Advanced search  

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]

Pages: [1]   Go Down

Author Topic: plugin tutorial  (Read 4232 times)

0 Members and 1 Guest are viewing this topic.

macmiller

  • Contributor
  • Coppermine regular visitor
  • ***
  • Offline Offline
  • Posts: 80
plugin tutorial
« on: March 13, 2011, 12:14:44 pm »

I am working my way through the plug-in tutorial and am having trouble getting the adding a button to the admin menu and adding a button to the system menu ones to work.  What happens is that they install but don't alter the display (ie. no additional buttons are displayed).

Here is the code I have for the system menu example, it is as written except that it seems a language file is needed. 

configuration.php
Code: [Select]
<?php
/*************************
  Coppermine Plugin - A test Plugin
  ************************
  Copyright (c) 2011
  ************************
  v1.0 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.
  ********************************************/

$name='button sys';
$description 'add a button to sys menu';
$author 'example';
$version '1.0';
$plugin_cpg_version = array('min' => '1.5');
?>

codebase.php
Code: [Select]
<?php
/**************************************************
  Coppermine Plugin - Button Sys
  *************************************************
  Copyright (c) 20011 Example Plugin
  *************************************************
  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.
***************************************************/
require_once "./plugins/buttonSys/initialize.inc.php";

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


// Add install & configure actions
$thisplugin->add_filter('sys_menu','coffee_maker_sys_button');


// Add a filter for the admin_menu
function coffee_maker_bar_sys_button($menu) {
    global 
$lang_plugin_coffee_maker$template_sys_menu_spacer$CONFIG;
    if (
$CONFIG['plugin_coffee_maker_how'] == 4) {
coffee_maker_bar_language(); // Call the function that populates the language variable
        
$new_button = array();
        
$new_button[0][0] = $lang_plugin_coffee_maker['picinfo_heading'];
        
$new_button[0][1] = $lang_plugin_coffee_maker['menu'];
        
$new_button[0][2] = 'index.php?file=coffee_maker/index';
        
$new_button[0][3] = 'coffee_maker';
        
$new_button[0][4] = $template_sys_menu_spacer;
        
$new_button[0][5] = 'rel="nofollow"';
        
array_splice($menucount($menu)-10$new_button);
    }
    return 
$menu;
}
?>
lang/english.php
Code: [Select]
<?php
$lang_plugin_coffee_maker
['plugin_name'] = 'Coffee Maker';
$lang_plugin_coffee_maker['plugin_description'] = 'This plugin will turn your gallery into a full-featured coffee machine.';
$lang_plugin_coffee_maker['coffee_bean'] = 'coffee bean';
$lang_plugin_coffee_maker['brew'] = 'brew';
$lang_plugin_coffee_maker['picinfo_heading']='testing1';
$lang_plugin_coffee_maker['menu']='testing2';
?>

initialize.inc.php
Code: [Select]
<?php
function coffee_maker_language() {
global $CONFIG$lang_plugin_coffee_maker;
require "./plugins/buttonSys/lang/english.php";
if ($CONFIG['lang'] != 'english' && file_exists("./plugins/coffee_maker/lang/{$CONFIG['lang']}.php")) {
    require "./plugins/buttonSys/lang/{$CONFIG['lang']}.php";
}
}
?>

I am not sure if the example is meant as a complete example that should display a button or if other code is needed.  It would be extremely instructive if I could get the example working.  I only added the language file since it seemed necessary to support the variables.  I wonder if there is a complete example of this coffee maker plugin if it is not complete. 

I also noticed in code that the add_filter command references coffee_maker_sys_button but the function is named coffee_maker_bar_sys_button.  Is a coffee_maker_sys_button function needed?

Hope this makes some sense, I appreciate any help.
Logged

macmiller

  • Contributor
  • Coppermine regular visitor
  • ***
  • Offline Offline
  • Posts: 80
Re: plugin tutorial
« Reply #1 on: March 13, 2011, 02:33:38 pm »

It seems there were some errors in the tutorial code, this code which was in some other documentation worked and added the button:
Code: [Select]
<?php
$thisplugin
->add_filter('sys_menu','add_sub_button');

function 
add_sub_button($menu) {
    
$new_button = array();
    
$new_button[0][0] = 'MENU LINK';
    
$new_button[0][1] = 'menu link';
    
$new_button[0][2] = './menu_link.php';
    
$new_button[0][3] = 'class_name';
    
$new_button[0][4] = '::';
    
$new_button[0][5] = 'rel="nofollow"';

    
array_splice($menucount($menu)-10$new_button);

    return 
$menu;
}
?>

For some reason it doesn't seem to add the button in the themes hardwired/curve/eyeball but does add them in rainy_day/water_drop.  Most likely has to do with how the themes were coded I imagine.

A related question is how would the code look to add say 2 buttons?

Logged

macmiller

  • Contributor
  • Coppermine regular visitor
  • ***
  • Offline Offline
  • Posts: 80
Re: plugin tutorial
« Reply #2 on: March 13, 2011, 02:37:40 pm »

never mind.. this worked.

Code: [Select]
<?php
$thisplugin
->add_filter('sys_menu','add_sub_button');

function 
add_sub_button($menu) {
    
$new_button = array();
    
$new_button[0][0] = 'MENU LINK';
    
$new_button[0][1] = 'menu link';
    
$new_button[0][2] = './menu_link.php';
    
$new_button[0][3] = 'class_name';
    
$new_button[0][4] = '::';
    
$new_button[0][5] = 'rel="nofollow"';
    
$new_button[1][0] = 'MENU LINK1';
    
$new_button[1][1] = 'menu link1';
    
$new_button[1][2] = './menu_link1.php';
    
$new_button[1][3] = 'class_name';
    
$new_button[1][4] = '::';
    
$new_button[1][5] = 'rel="nofollow"';

    
array_splice($menucount($menu)-10$new_button);

    return 
$menu;
}
?>
Logged
Pages: [1]   Go Up
 

Page created in 0.024 seconds with 19 queries.