Re: Adding PHP Include Re: Adding PHP Include
 

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

Re: Adding PHP Include

Started by Nibbler, May 09, 2005, 05:11:25 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Nibbler

Try posting a link to your site and the changes you have made to your theme.php.

donnoman

FAQ: Custom Header.

I'll use the classic theme as the example.

You've got two custom includes so we establish which tokens we want to use for each. There's nothing magical about {CUSTOM_HEADER}.. as long as we don't use a token thats already in coppermine we're fine.

{NEWSLETTER}
{REMOTE_IP}

In your template.html stick them where you want the content to end up. (pick your own places, unless you really like mine ;D )

                               <td width="100%" align="center">
                                       <h1>{GAL_NAME}</h1>
                                       <h3>{GAL_DESCRIPTION}</h3><br />
                                       {NEWSLETTER}
                                       {MAIN_MENU}
                               </td>



               <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                       <tr>
                               <td align="center" valign="top">
                                       {ADMIN_MENU}
                                       {GALLERY}
                                       {REMOTE_IP}
                               </td>
                       </tr>
               </table>


Now you need to edit theme.php so you can establish what each token should be

{NEWSLETTER} Appears before {GALLERY} so we will edit the pageheader function to be able to replace it.
find function pageheader in theme.php

function pageheader($section, $meta = '')
{
   global $CONFIG, $THEME_DIR;
   global $template_header, $lang_charset, $lang_text_dir;

   $charset = ($CONFIG['charset'] == 'language file') ? $lang_charset : $CONFIG['charset'];

   header('P3P: CP="CAO DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM PRE"');
   header("Content-Type: text/html; charset=$charset");
   user_save_profile();

   $template_vars = array('{LANG_DIR}' => $lang_text_dir,
       '{TITLE}' => $CONFIG['gallery_name'] . ' - ' . $section,
       '{CHARSET}' => $charset,
       '{META}' => $meta,
       '{GAL_NAME}' => $CONFIG['gallery_name'],
       '{GAL_DESCRIPTION}' => $CONFIG['gallery_description'],
       '{MAIN_MENU}' => theme_main_menu(),
       '{ADMIN_MENU}' => theme_admin_mode_menu(),
       );

   echo template_eval($template_header, $template_vars);
}


update to:

function pageheader($section, $meta = '')
{
   global $CONFIG, $THEME_DIR;
   global $template_header, $lang_charset, $lang_text_dir;

   if(empty($newsletter)){
      ob_start();
      require('themes/classic/newsletter.php'); //paths are relative to coppermines index.php
      static $newsletter;
      $newsletter= ob_get_contents();
      ob_clean();
   }

   $charset = ($CONFIG['charset'] == 'language file') ? $lang_charset : $CONFIG['charset'];

   header('P3P: CP="CAO DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM PRE"');
   header("Content-Type: text/html; charset=$charset");
   user_save_profile();

   $template_vars = array('{LANG_DIR}' => $lang_text_dir,
       '{TITLE}' => $CONFIG['gallery_name'] . ' - ' . $section,
       '{CHARSET}' => $charset,
       '{META}' => $meta,
       '{GAL_NAME}' => $CONFIG['gallery_name'],
       '{GAL_DESCRIPTION}' => $CONFIG['gallery_description'],
       '{MAIN_MENU}' => theme_main_menu(),
       '{ADMIN_MENU}' => theme_admin_mode_menu(),
       '{NEWSLETTER}' => $newsletter,
       );

   echo template_eval($template_header, $template_vars);
}


{REMOTE_IP} is after {GALLERY} in my template.html so I need to edit the pagefooter function to be able to replace it.

find function pagefooter in theme.php

function pagefooter()
{
   global $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_SERVER_VARS;
   global $USER, $USER_DATA, $ALBUM_SET, $CONFIG, $time_start, $query_stats, $queries;;
   global $template_footer;

   if ($CONFIG['debug_mode']==1 || ($CONFIG['debug_mode']==2 && GALLERY_ADMIN_MODE)) {
   cpg_debug_output();
   }

   echo $template_footer;
}


update to:

function pagefooter()
{
   global $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_SERVER_VARS;
   global $USER, $USER_DATA, $ALBUM_SET, $CONFIG, $time_start, $query_stats, $queries;;
   global $template_footer;

   if ($CONFIG['debug_mode']==1 || ($CONFIG['debug_mode']==2 && GALLERY_ADMIN_MODE)) {
   cpg_debug_output();
   }

   $template_vars = array(
       '{REMOTE_IP}' =>$_SERVER["REMOTE_ADDR"],
       );

   echo template_eval($template_footer, $template_vars);
}


Notice I don't actually bother doing an include just to set one variable. Just make the substitution right in pagefooter itself.

If you really want to include the php follow the example for pageheader.

Crash_Sys

Yeah-

Thank you. Specially donnoman, Thank YOU! I got it to work. Thanks Great Coding
;D ;D