forum.coppermine-gallery.net

Support => cpg1.5.x Support => cpg1.5 plugins => Topic started by: gmc on December 24, 2013, 09:21:36 pm

Title: Plugin adding button to Admin Menu...
Post by: gmc on December 24, 2013, 09:21:36 pm
While I've gotten this to work - I'm not sure I've done it the best way...

The documentation at http://documentation.coppermine-gallery.net/en/dev_plugin_api.htm#plugin_api_tutorial_button (http://documentation.coppermine-gallery.net/en/dev_plugin_api.htm#plugin_api_tutorial_button) suggests use of the plugin filter 'admin_menu' with code:
Code: [Select]
$thisplugin->add_filter('admin_menu','coffee_maker_config_button');

function coffee_maker_bar_config_button($admin_menu){
    global $lang_plugin_coffee_maker, $CONFIG, $coffee_maker_icon_array;
    if ($CONFIG['plugin_coffee_maker_config_link'] == 1) {
    $new_button = '<div class="admin_menu admin_float"><a href="index.php?file=coffee_maker/index&action=configure"';
    $new_button .= ' title="' . $lang_plugin_coffee_maker['config'] . '">';
    $new_button .= $coffee_maker_icon_array['config_menu'] . $lang_plugin_coffee_maker['config'] . '</a></div>';
    $look_for = '<!-- END export -->'; // This is where you determine the place in the admin menu
    $admin_menu = str_replace($look_for, $look_for . $new_button, $admin_menu);
    }
    return $admin_menu;
}
This seems to have issues with 'newer' themes with pull down menus... not displaying properly in the pull downs (in some case next to the block)

I see other plugins using this technique - and as I move through different themes - seem to have issues...

MiniCMS uses a different approach based on plugin action page_start with code:
Code: [Select]
$thisplugin->add_action('page_start','minicms_page_start');

function minicms_add_admin_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);
}

function minicms_page_start()
{
...
  if (GALLERY_ADMIN_MODE) {
      minicms_add_admin_button('index.php?file=minicms/cms_admin',$lang_minicms['admin_title'],'',$lang_minicms['admin_title']);
  }
...
}
This seems to work in all cases I've tried... but would seem not to be the ideal (or intended??) hookpoint for this function alone (minicms does other things at page start - initializing it's processing - so may make sense for that plugin...)

I adapted this for my use (direct call to function to add button since I have no other page_start actions needed...) but thought I would ask...
What is the 'recommended' way to add an admin menu button that works with the different styles of themes??

Thanks!
Greg
Title: Re: Plugin adding button to Admin Menu...
Post by: Αndré on December 30, 2013, 11:42:57 am
The curve theme has been created at a quite late stage during the development of cpg1.5.x. I assume the plugin docs have already been written before that theme existed and nobody checked that or updated the docs accordingly. Actually there are several ways to add buttons or other stuff. IMHO the recommended way is the way that works ;)

However, we should consider to update the docs.
Title: Re: Plugin adding button to Admin Menu...
Post by: gmc on December 31, 2013, 01:38:05 am
At least you know someone is reading the docs..  :D
Seriously though - it has been very helpful to me in learning more about Coppermine - so thank you to those that took the time to document the interfaces...

I agree the working one is the way to go - just wanted to be sure I was copying/propagating the best example.

If I can help with the doc (don't think I can write this section - but welcome to review if it would help) let me know...
Title: Re: Plugin adding button to Admin Menu...
Post by: gmc on December 31, 2013, 09:30:13 pm
Attached plugin gmc_test (V0.6) allows selection of two different ways to add admin button..
method from docs, and method used in minicms.
Doc method only invoked in admin mode but has issues with themes with dropdown menus
Minicms method called for all pages - must test if admin mode - but works fine in various themes (that I have tried)

Install plugin and select the method you want used for buttons from Config menu.
While I was updating this plugin to demonstrate my $GLOBALS issue - thought I would incorporate this code as well.

Thanks!
Happy New Year!
Title: Re: Plugin adding button to Admin Menu...
Post by: phill104 on January 01, 2014, 01:19:02 am
Many thanks Greg. And yes, we are always looking for help so anything you can offer will be much appreciated.