Advanced search  

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Pages: [1]   Go Down

Author Topic: Plugin adding button to Admin Menu...  (Read 4959 times)

0 Members and 1 Guest are viewing this topic.

gmc

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: us
  • Offline Offline
  • Gender: Male
  • Posts: 785
    • GMC Design Photo Gallery
Plugin adding button to Admin Menu...
« 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 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
Logged
Thanks!
Greg
My Coppermine Gallery
Need a web hosting account? See my gallery for an offer for CPG Forum users.
Send me money

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: Plugin adding button to Admin Menu...
« Reply #1 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.
Logged

gmc

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: us
  • Offline Offline
  • Gender: Male
  • Posts: 785
    • GMC Design Photo Gallery
Re: Plugin adding button to Admin Menu...
« Reply #2 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...
Logged
Thanks!
Greg
My Coppermine Gallery
Need a web hosting account? See my gallery for an offer for CPG Forum users.
Send me money

gmc

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: us
  • Offline Offline
  • Gender: Male
  • Posts: 785
    • GMC Design Photo Gallery
Re: Plugin adding button to Admin Menu...
« Reply #3 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!
Logged
Thanks!
Greg
My Coppermine Gallery
Need a web hosting account? See my gallery for an offer for CPG Forum users.
Send me money

phill104

  • Administrator
  • Coppermine addict
  • *****
  • Country: gb
  • Offline Offline
  • Gender: Male
  • Posts: 4885
    • Windsurf.me
Re: Plugin adding button to Admin Menu...
« Reply #4 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.
Logged
It is a mistake to think you can solve any major problems just with potatoes.
Pages: [1]   Go Up
 

Page created in 0.02 seconds with 19 queries.