coppermine-gallery.com/forum

Support => cpg1.4.x Support => Older/other versions => cpg1.4 miscellaneous => Topic started by: Cron on January 18, 2006, 11:08:19 AM

Title: Coppermine Code Parsing Question
Post by: Cron on January 18, 2006, 11:08:19 AM
One day as I was designing a new template I decided that life would be much easyer if I could run PHP script directly in my template. I tried using {custom_header} and {footer} tags but you can not use other Coppermine tags in those pages (e.g. {title}). So I decided that the best way to go was to directly enable PHP in my template. In order to do this I first changed this code in "functions.inc.php":

if (file_exists(TEMPLATE_FILE)) {
        $template_file = TEMPLATE_FILE;
        } elseif (file_exists($THEME_DIR . TEMPLATE_FILE)) {
            $template_file = $THEME_DIR . TEMPLATE_FILE;
        } else die("<b>Coppermine critical error</b>:<br />Unable to load template file ".TEMPLATE_FILE."!</b>");


to

// CHECK FOR .PHP EXTENTION
//GET THE TEMPLATE_FLIE NAME
list($ajs_file, $ajs_extention) = explode(".", TEMPLATE_FILE);
//CHECK FOR .PHP EXTENTION
$ajs_theme = (file_exists($THEME_DIR . $ajs_file . '.php')) ? $ajs_file . '.php' : TEMPLATE_FILE;
// FIND THE FILE
        if (file_exists($ajs_theme)) {
            $template_file = $ajs_theme;
        } elseif (file_exists($THEME_DIR . $ajs_theme)) {
            $template_file = $THEME_DIR . $ajs_theme;
        } else die("<b>Coppermine critical error</b>:<br />Unable to load template file ".$ajs_theme."!</b>");
// ALL DONE


This enabled me to change the extention for my template file from "template.html" to "template.php". However when I tried to run PHP script nothing happened. My guess is that it is due to the the way Coppermine parses the PHP code.

I was wondering where the code for this praser is located and what hooks it uses to tie in. Is there any way to turn it of? Is there any reason I shouldent try to turn it off?

Any help would be appreciated,

Cron
http://tokyocrew51.zaeat.com (http://tokyocrew51.zaeat.com)
Title: Re: Coppermine Code Parsing Question
Post by: Joachim Müller on January 18, 2006, 11:50:40 PM
http://coppermine-gallery.net/demo/cpg14x/docs/faq.htm#renameTemplateHtml

Quote from: Cron on January 18, 2006, 11:08:19 AM
Is there any reason I shouldent try to turn it off?
Yes, plenty of them, explained in many postings already. Dynamic stiff should go into theme.php, that's what it was deigned for.
Title: Re: Coppermine Code Parsing Question
Post by: Cron on January 19, 2006, 10:46:17 AM
I managed to enable it by changing

$template = fread(fopen($template_file, 'r'), filesize($template_file));

to

//$template = fread(fopen($template_file, 'r'), filesize($template_file));
ob_start();                     // Start output buffering
include ($template_file);       // Parsed file goes to buffer
$template = ob_get_contents();  // Assign buffer to $template
ob_end_clean();                 // Clear buffer and turn off output buffering


in my  functions.inc.php


I have previously tried doing it via my theme.php but It was much easyer to do it this way concidering the VOLUME of php I have.