Adding Links Adding Links
 

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

Adding Links

Started by daklay, November 25, 2005, 07:12:19 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

daklay

I did this in the last version, but, dunno how to do it in this one.
(see attached image)

kegobeer

Read the documentation.  You can add a custom link without editing the theme.
Do not send me a private message unless I ask for one.  Make your post public so everyone can benefit.

There are no stupid questions
But there are a LOT of inquisitive idiots

donnoman

#2
There are several ways of adding links.

If you are just talking about adding one link use the "Custom menu link name" and "Custom menu link URL" options in the config. This will make a single custom button accross every theme that has been properly ugraded to a 1.4 theme.

You can also usurp the href that the "home" button points to in the config by modifing the url for the "URL of your home page" config option. Generally it points to your index.php of coppermine, but it could point anywhere that makes sense, for example the home page of your site, rather than coppermines home page.

For a specific theme:
If you have specified the entire button template ($template_sys_menu or $template_sub_menu) you can add links directly in those.

If you didn't specify a button template, then you can manipulate the links by overriding the button specification:

take the addbutton function and button specifications for the menu you want to modify from themes/sample/theme.php

// Creates an array of tokens to be used with function assemble_template_buttons
// this function is used in this file it needs to be declared before being called.
function addbutton(&$menu,$href_lnk,$href_title,$href_tgt,$block_id,$spacer) {
  $menu[]=array($href_lnk,$href_title,$href_tgt,$block_id,$spacer);
}
    // HTML template for template sub_menu buttons
    // {HREF_LNK}{HREF_TITLE}{HREF_TGT}{BLOCK_ID}{SPACER}
    addbutton($sub_menu_buttons,'{CUSTOM_LNK_LNK}','{CUSTOM_LNK_TITLE}','{CUSTOM_LNK_TGT}','custom_link',$template_sub_menu_spacer);
    addbutton($sub_menu_buttons,'{ALB_LIST_LNK}','{ALB_LIST_TITLE}','{ALB_LIST_TGT}','album_list',$template_sub_menu_spacer);
    addbutton($sub_menu_buttons,'{LASTUP_LNK}','{LASTUP_TITLE}','{LASTUP_TGT}','lastup',$template_sub_menu_spacer);
    addbutton($sub_menu_buttons,'{LASTCOM_LNK}','{LASTCOM_TITLE}','{LASTCOM_TGT}','lastcom',$template_sub_menu_spacer);
    addbutton($sub_menu_buttons,'{TOPN_LNK}','{TOPN_TITLE}','{TOPN_TGT}','topn',$template_sub_menu_spacer);
    addbutton($sub_menu_buttons,'{TOPRATED_LNK}','{TOPRATED_TITLE}','{TOPRATED_TGT}','toprated',$template_sub_menu_spacer);
    addbutton($sub_menu_buttons,'{FAV_LNK}','{FAV_TITLE}','{FAV_TGT}','favpics',$template_sub_menu_spacer);
    addbutton($sub_menu_buttons,'{SEARCH_LNK}','{SEARCH_TITLE}','{SEARCH_TGT}','search','');


and add a few links to it

    // HTML template for template sub_menu buttons
    // {HREF_LNK}{HREF_TITLE}{HREF_TGT}{BLOCK_ID}{SPACER}
    addbutton($sub_menu_buttons,'{CUSTOM_LNK_LNK}','{CUSTOM_LNK_TITLE}','{CUSTOM_LNK_TGT}','custom_link',$template_sub_menu_spacer);
    addbutton($sub_menu_buttons,'My Button 1','This is the First Custom Button','http://www.disney.com','custom1',$template_sub_menu_spacer);
    addbutton($sub_menu_buttons,'{ALB_LIST_LNK}','{ALB_LIST_TITLE}','{ALB_LIST_TGT}','album_list',$template_sub_menu_spacer);
    addbutton($sub_menu_buttons,'{LASTUP_LNK}','{LASTUP_TITLE}','{LASTUP_TGT}','lastup',$template_sub_menu_spacer);
    addbutton($sub_menu_buttons,'{LASTCOM_LNK}','{LASTCOM_TITLE}','{LASTCOM_TGT}','lastcom',$template_sub_menu_spacer);
    addbutton($sub_menu_buttons,'{TOPN_LNK}','{TOPN_TITLE}','{TOPN_TGT}','topn',$template_sub_menu_spacer);
    addbutton($sub_menu_buttons,'{TOPRATED_LNK}','{TOPRATED_TITLE}','{TOPRATED_TGT}','toprated',$template_sub_menu_spacer);
    addbutton($sub_menu_buttons,'{FAV_LNK}','{FAV_TITLE}','{FAV_TGT}','favpics',$template_sub_menu_spacer);
    addbutton($sub_menu_buttons,'My Button 2','This is the Second Custom Button','http://www.sun.com','custom2',$template_sub_menu_spacer);
    addbutton($sub_menu_buttons,'{SEARCH_LNK}','{SEARCH_TITLE}','{SEARCH_TGT}','search','');


You COULD modify the button specifications in include/themes.inc.php, just remember that any theme that uses thier own $template_sys_menu or $template_sub_menu, it will ignore the button specifications.  At least half of the core themes use thier own templates. (In almost all cases I discourage people from editing themes.inc.php, it is a core component of Coppermine, and shouldn't be messed with lightly.)

If you want to modify the buttons across all of your themes the best option would be to use the plugin system, this is an example of plugin code that modifies the admin buttons, it comes from the minicms plugin at cpg-contrib.org



// Add a action
$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()
{
  global $CONFIG, $MINICMS, $lang_minicms, $lang_minicms_config, $album, $cat;
  global $HTML_SUBST, $HTML_SUBST_DECODE, $template_minicms, $REFERER, $CURRENT_PIC_DATA;
  require 'plugins/minicms/include/init.inc.php';

  if ($MINICMS['redirect_index_php'] && empty($_SERVER["QUERY_STRING"]) && strstr($_SERVER["PHP_SELF"],'index.php')) {
      header('Location: '.html_entity_decode($MINICMS['redirect_index_php']));
      exit();
  }

  minicms_add_admin_button('index.php?file=minicms/cms_admin',$lang_minicms['admin_title'],'',$lang_minicms['admin_title']);
  minicms_add_admin_button('index.php?file=minicms/cms_config',$lang_minicms['config_title'],'',$lang_minicms['config_title']);
}


In a nutshell minicms_add_admin_button uses the global template variable $template_gallery_admin_menu to extract a button that has already been specified in that menu so that it can get the right styling, saves it to a variable, creates a new button based on the same template, evaluates the template with the custom button info, then adds both the original button that was saved and the new button back into the global template.

I would avoid using the plugin to replace the first or the last button in a template since thier styling can sometimes be different than the buttons in the middle.

daklay

K, i got how to do the first one for the sample theme, but how do I do it for rainy day?

daklay


Joachim Müller

in the same way as described above.

daklay

Wait...there isn't ANYTHING like that in the theme for rainy day.

Nibbler

You copy the code from the sample theme and paste it into the theme you want to modify. Don't modify the sample theme directly.

daklay

#8
K...when i do tht, my buttons gets messed up. Isn't there just a way I can add more custom menu button options?

daklay


Joachim Müller


daklay

Ya, I thought so.
Well, is there anyway to add more custom button options, or, will there be more in the future?

donnoman

Theres more than enough ways to add custom buttons to your theme, I can see no reason to provide additional methods.

If you want complete control of the buttons, then override the whole the $template_sys_menu and $template_sub_menu.

See the hardwired or mac_ox_x themes as examples.

daklay

There we go. The hardwired theme is like the last version themes. I can work with this now.

Joachim Müller

Locking this sticky FAQ thread to avoid further individual support cluttering and spoling the thread even further.