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: How to add navigation buttons to your 1.4 theme  (Read 5662 times)

0 Members and 1 Guest are viewing this topic.

macmiller

  • Contributor
  • Coppermine regular visitor
  • ***
  • Offline Offline
  • Posts: 80
How to add navigation buttons to your 1.4 theme
« on: February 21, 2007, 01:57:38 am »

The documentation here is quite good:

http://forum.coppermine-gallery.net/index.php?topic=26897.msg123990#msg123990

Since I first tried to add buttons to my themes without reading it, then found it, then subsequently still spent some time figuring it out, I wanted to note what I found:

Quote
In all theme customizations, you copy code from the sample/theme.php to your theme.php

clarification:  You copy the code from /include/themes.inc.php to your theme, eg /themes/rainy_day/theme.php.

STEP 1 would be to copy the code indicated from the /include/themes.inc.php to your theme, eg. /themes/rainy_day/theme.php without changing anything.  Copy over this theme.php file to your server.  When you view your coppermine page you should notice no difference. 

STEP 2 You can now find the addbutton section, and go ahead and add your buttons, changing only the first, second and third parameters.  Here I have added three new navigation buttons after the original home button.  If you want to change the text displayed for the home button, you would edit your /lang/english.php file (to change the english version) and copy that over. 

like
Code: [Select]
    addbutton($sys_menu_buttons,'{HOME_LNK}','{HOME_TITLE}','{HOME_TGT}','home',$template_sys_menu_spacer);
    addbutton($sys_menu_buttons,'forum home','go to the mysite forum home','http://www.mysite.com/forum','home',$template_sys_menu_spacer);
    addbutton($sys_menu_buttons,'blog home','go to the mysite blog home','http://www.mysite.com/blog','home',$template_sys_menu_spacer);
    addbutton($sys_menu_buttons,'main home','go to the mysite main home page','http://www.mysite.com/','home',$template_sys_menu_spacer);

« Last Edit: February 23, 2007, 10:42:00 am by macmiller »
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: How to add navigation buttons to your 1.4 theme
« Reply #1 on: February 22, 2007, 08:13:12 am »

clarification:  You copy the code from \include\themes.inc.php to your theme, eg \themes\rainy_day\theme.php.
No, that's wrong. The original instructions apply: copy from themes/sample/theme.php.
Leave include/themes.inc.php alone! Don't even copy from it! We mean it.
Logged

macmiller

  • Contributor
  • Coppermine regular visitor
  • ***
  • Offline Offline
  • Posts: 80
Re: How to add navigation buttons to your 1.4 theme
« Reply #2 on: February 23, 2007, 11:14:52 am »

Thanks for the correction, sorry for being such a bonehead.  For some reason I wasn't able to locate sample/theme before which caused me to locate the wrong file, which coincidentally worked, but I'm sure would have broken something later. :-[

So now in correcting my previous error, here is what I did.   

1.)  Copied the stated code from sample/theme.php as stated to the target file, in this case /rainy_day/theme.php.
2.)  Moved the $template_sys_menu and $template_sys_menu_button down to replace the $template_sys_menu and $template_sys_menu_button in the copied over code.
3.)  Added in the new custom buttons.

(Originally I didn't do step 2 and the symptom was the themes custom buttons got hosed)

In the modified theme file below, I put a modificationstoaddbuttonsstart and modificationstoaddbuttonend comment at the beginning and end of every change I made.  This is now working.

Code: [Select]
<?php
/*************************
  Coppermine Photo Gallery
  ************************
  Copyright (c) 2003-2006 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 as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.
  ********************************************
  Coppermine version: 1.4.10
  $Source$
  $Revision: 3275 $
  $Author: gaugau $
  $Date: 2006-09-03 12:10:47 +0200 (So, 03 Sep 2006) $
**********************************************/

// ------------------------------------------------------------------------- //
// This theme has had all redundant CORE items removed                           //
// ------------------------------------------------------------------------- //

define('THEME_HAS_RATING_GRAPHICS'1);
define('THEME_IS_XHTML10_TRANSITIONAL',1);

/**modificationstoaddbuttonsstart These blocks get moved, are left here for reference only
// HTML template for sys_menu
$template_sys_menu = <<<EOT
  <div class="topmenu">
          <table border="0" cellpadding="0" cellspacing="0">
                  <tr>
  {BUTTONS}
                  </tr>
          </table>
  </div>
EOT;

// HTML template for template sys_menu buttons
$template_sys_menu_button = <<<EOT
<!-- BEGIN {BLOCK_ID} -->
  <td><img src="images/spacer.gif" width="5" height="25" border="0" alt="" /></td>
  <td><img src="themes/rainy_day/images/button1_r1_c1.gif" width="5" height="25" border="0" alt="" /></td>
  <td style="background-image:url(themes/rainy_day/images/button1_r1_c2.gif)">
          <a href="{HREF_TGT}" title="{HREF_TITLE}">{HREF_LNK}</a>
  </td>
  <td><img src="themes/rainy_day/images/button1_r1_c3.gif" width="5" height="25" border="0" alt="" /></td>
<!-- END {BLOCK_ID} -->
EOT;
modificationstoaddbuttonsend **/

// Creates buttons from a template using an array of tokens
// this function is used in this file it needs to be declared before being called.
function assemble_template_buttons($template_buttons,$buttons) {
    
$counter=0;
    
$output='';

    foreach (
$buttons as $button)  {
      if (isset(
$button[4])) {
         
$spacer=$button[4];
      } else {
      
$spacer='';
      }

        
$params = array(
            
'{SPACER}'     => $spacer,
            
'{BLOCK_ID}'   => $button[3],
            
'{HREF_TGT}'   => $button[2],
            
'{HREF_TITLE}' => $button[1],
            
'{HREF_LNK}'   => $button[0]
            );
        
$output.=template_eval($template_buttons$params);
    }
    return 
$output;
}


// 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);
}


/** modificationstoaddbuttonsstart this block of sample/theme.php gets replaced by the original
// HTML template for sys_menu
$template_sys_menu = <<<EOT
          {BUTTONS}
EOT;
modificationstoaddbuttonsend **/
// modificationstoaddbuttonsstart - the original template_sys_menu and template_sys_menu_button goes here
// HTML template for sys_menu
$template_sys_menu = <<<EOT
  <div class="topmenu">
          <table border="0" cellpadding="0" cellspacing="0">
                  <tr>
  {BUTTONS}
                  </tr>
          </table>
  </div>
EOT;

// HTML template for template sys_menu buttons
$template_sys_menu_button = <<<EOT
<!-- BEGIN {BLOCK_ID} -->
  <td><img src="images/spacer.gif" width="5" height="25" border="0" alt="" /></td>
  <td><img src="themes/rainy_day/images/button1_r1_c1.gif" width="5" height="25" border="0" alt="" /></td>
  <td style="background-image:url(themes/rainy_day/images/button1_r1_c2.gif)">
          <a href="{HREF_TGT}" title="{HREF_TITLE}">{HREF_LNK}</a>
  </td>
  <td><img src="themes/rainy_day/images/button1_r1_c3.gif" width="5" height="25" border="0" alt="" /></td>
<!-- END {BLOCK_ID} -->
EOT;
// modificationstoaddbuttonsend

// HTML template for sub_menu
$template_sub_menu $template_sys_menu;

if (!
defined('THEME_HAS_NO_SYS_MENU_BUTTONS')) {

  
// HTML template for template sys_menu spacer
  
$template_sys_menu_spacer ="::";

/** modificationstoaddbuttonsstart this sample/theme.php gets commented out 
  // HTML template for template sys_menu buttons
  $template_sys_menu_button = <<<EOT
  <!-- BEGIN {BLOCK_ID} -->
        <a href="{HREF_TGT}" title="{HREF_TITLE}">{HREF_LNK}</a> {SPACER}
  <!-- END {BLOCK_ID} -->
EOT;
modificationstoaddbuttonsend **/

  // HTML template for template sys_menu buttons
    // {HREF_LNK}{HREF_TITLE}{HREF_TGT}{BLOCK_ID}{SPACER}
    
addbutton($sys_menu_buttons,'{HOME_LNK}','{HOME_TITLE}','{HOME_TGT}','home',$template_sys_menu_spacer);
// modificationstoaddbuttonsstart - add buttons as desired
    
addbutton($sys_menu_buttons,'Forum Home','go to the testsite forum home','http://www.testsite.com/forum','home',$template_sys_menu_spacer);
    
addbutton($sys_menu_buttons,'Blog Home','go to the testsite blog home','http://www.testsite.com/blog','home',$template_sys_menu_spacer);
    
addbutton($sys_menu_buttons,'Main Home','go to the testsite main home page','http://www.testsite.com/','home',$template_sys_menu_spacer);
// modificationstoaddbuttonsend - end of adding buttons
    
addbutton($sys_menu_buttons,'{MY_GAL_LNK}','{MY_GAL_TITLE}','{MY_GAL_TGT}','my_gallery',$template_sys_menu_spacer);
    
addbutton($sys_menu_buttons,'{MEMBERLIST_LNK}','{MEMBERLIST_TITLE}','{MEMBERLIST_TGT}','allow_memberlist',$template_sys_menu_spacer);
    
addbutton($sys_menu_buttons,'{MY_PROF_LNK}','{MY_PROF_TITLE}','{MY_PROF_TGT}','my_profile',$template_sys_menu_spacer);
    
addbutton($sys_menu_buttons,'{ADM_MODE_LNK}','{ADM_MODE_TITLE}','{ADM_MODE_TGT}','enter_admin_mode',$template_sys_menu_spacer);
    
addbutton($sys_menu_buttons,'{USR_MODE_LNK}','{USR_MODE_TITLE}','{USR_MODE_TGT}','leave_admin_mode',$template_sys_menu_spacer);
    
addbutton($sys_menu_buttons,'{UPL_PIC_LNK}','{UPL_PIC_TITLE}','{UPL_PIC_TGT}','upload_pic',$template_sys_menu_spacer);
    
addbutton($sys_menu_buttons,'{REGISTER_LNK}','{REGISTER_TITLE}','{REGISTER_TGT}','register',$template_sys_menu_spacer);
    
addbutton($sys_menu_buttons,'{FAQ_LNK}','{FAQ_TITLE}','{FAQ_TGT}','faq',$template_sys_menu_spacer);
    
addbutton($sys_menu_buttons,'{LOGIN_LNK}','{LOGIN_TITLE}','{LOGIN_TGT}','login','');
    
addbutton($sys_menu_buttons,'{LOGOUT_LNK}','{LOGOUT_TITLE}','{LOGOUT_TGT}','logout','');
    
// Login and Logout don't have a spacer as only one is shown, and either would be the last option.

  
$params = array('{BUTTONS}' => assemble_template_buttons($template_sys_menu_button,$sys_menu_buttons));
  
$template_sys_menu template_eval($template_sys_menu,$params);
}

if (!
defined('THEME_HAS_NO_SUB_MENU_BUTTONS')) {

  
// HTML template for template sub_menu spacer
  
$template_sub_menu_spacer $template_sys_menu_spacer;

  
// HTML template for template sub_menu buttons
  
$template_sub_menu_button$template_sys_menu_button;

  
// 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','');

  
$params = array('{BUTTONS}' => assemble_template_buttons($template_sub_menu_button,$sub_menu_buttons));
  
$template_sub_menu template_eval($template_sub_menu,$params);
}
?>



By the way, I tried copying the code from the sample/theme to the code before the original $template_sys_menu_buttong and $template_sys_menu and this worked except for the fact that the buttons didn't display correctly.  I think that I may be making this more complicated than it needs to be, since I couldn't find instructions that match what I did, but my theme now is working, however if there is an easier way to do this I'm interested.
 

« Last Edit: February 23, 2007, 12:13:11 pm by macmiller »
Logged
Pages: [1]   Go Up
 

Page created in 0.021 seconds with 20 queries.