FAQ "custom header include" : does this even work? FAQ "custom header include" : does this even work?
 

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

Main Menu

FAQ "custom header include" : does this even work?

Started by duntuk, December 27, 2003, 08:35:35 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

duntuk

this is taken from:
http://coppermine.sourceforge.net/faq.php

under: "How do I add a custom header/footer to Coppermine?"

My server:
RedHat 7.3
PHP version 4.3.1

The below code doesn't seem to work... it gives this error:

QuoteParse error: parse error, expecting `','' or `';'' in /home/site123/public_html/portfolio/themes/stc/theme.php on line 1057

Fatal error: Call to undefined function: theme_display_album_list_cat() in /home/site123/public_html/portfolio/index.php on line 493


this is mainly due to the addition of the word 'static' (is that even a valid function? couldn't find it on php.net)

Quotestatic $custom_header = ob_get_contents();


nevertheless...  

the *closest* i've got to getting the "include" to work is by simply doing a regular include without the extra:

     static $custom_header = ob_get_contents();
      ob_clean();



however, that defeats the entire purpose of trying to use a CUSTOM TEMPLATE, i.e. {CUSTOM_HEADER}...

bottom line, either way, {CUSTOM_HEADER} is not parsed--doesn't work--when inserted into template.html at best, just shows the actual word "{CUSTOM_HEADER}"...


anyhow...

here is the FAQ's code in question....

I'm curious, if anyone ever got it to work as intended...

 (i studied the CPG backend template code, and it's too difficult for me to follow--- and yes i'm aware that i can create a custom layout with includes inside 'theme.php'... however, the including of {template} inside 'template.html' would be 100x more convenient)


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

  if(empty($custom_header)){
      include('/home/site123/public_html/news.php');
      static $custom_header = ob_get_contents();
      ob_clean();
   };


    header('P3P: CP="CAO DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM PRE"');
    user_save_profile();

    $template_vars = array('{LANG_DIR}' => $lang_text_dir,
        '{TITLE}' => $CONFIG['gallery_name'] . ' - ' . $section,
        '{CHARSET}' => $CONFIG['charset'] == 'language file' ? $lang_charset : $CONFIG['charset'],
        '{META}' => $meta,
        '{GAL_NAME}' => $CONFIG['gallery_name'],
        '{GAL_DESCRIPTION}' => $CONFIG['gallery_description'],
        '{MAIN_MENU1}' => theme_main_menu1(),
        '{MAIN_MENU2}' => theme_main_menu2(),
        '{ADMIN_MENU}' => theme_admin_mode_menu(),
        '{CUSTOM_HEADER}' => $custom_header
        );

    echo template_eval($template_header, $template_vars);
       
}


Joachim Müller

try this option:
  • remove all modifications in theme.php, but leave the {CUSTOM_HEADER} stuff inside template.html
  • edit functions.inc.php
  • find        $template = fread(fopen($template_file, 'r'), filesize($template_file));and add after it        $my_custom_header = '<h1>Hello World</h1>';
            $gallery_pos = strpos($template, '{CUSTOM_HEADER}');
            $template = str_replace('{CUSTOM_HEADER}', $my_custom_header ,$template);
    [/list:u]Does this look like an alternative to you?

    GauGau

duntuk

thanks gaugau !  you the best... :D

I'll give it a go

duntuk

oh well...

that didn't work either...

It simply replaced {CUSTOM_HEADER} with "1" (i have no idea why)..

and spit out the 'include' statement as the top of the file as the header....


anyhow.... i'm not too thrilled with this sort of templating scheme, because 1. it requires too many (in my opinion, needless) extra queries to complete the process

after all, php *is* a templating language, hence, hypethetically speaking:

<?php include_once &#40;'menu.php'&#41; ; ?>

or

<?php echo $menu?>

would do the same thing as

{MENU}

BUT without all the extra queries of having to read the template.html file, look for {MENU} and parse it with whatever templating structure the author decided to use....


and ...

2... it's too hard to interpret the authors templating scheme... you basically have to learn a *new* programming structure that the author invented as apposed one that every php programmer already knows right off hand...


anyhow...

a few times, the server choked on coopermines templating scheme, comming up with template errors when i guess too many queries were made at once.... not good, since our site doesn't get more than a few hundred visits per day...imagine what thousands would do....

if the this sort of templating structure was in a database, rather than flat file, it'll definitely be more server efficient...

blah... whatever... i'm just venting...  :wink: coopermine is very good...

guess i'm just going to have to design most the site in 'theme.php' and leave 'template.html' alone, since as of right now it doesn't seem very flexible to do any other way....  :roll:

Joachim Müller

you're right, the current template system isn't that good - it was "borrowed" by Greg (the original author of Coppermine) from phpBB template system some time ago. At some later point (read: not in the next version of coppermine, but later in the future) there will hopefully be a complete rework of the template system.

GauGau