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: Coppermine Code Parsing Question  (Read 2600 times)

0 Members and 1 Guest are viewing this topic.

Cron

  • Coppermine newbie
  • Offline Offline
  • Posts: 5
Coppermine Code Parsing Question
« 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":

Code: [Select]
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

Code: [Select]
// 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
« Last Edit: January 19, 2006, 06:11:50 pm by GauGau »
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: Coppermine Code Parsing Question
« Reply #1 on: January 18, 2006, 11:50:40 pm »

http://coppermine-gallery.net/demo/cpg14x/docs/faq.htm#renameTemplateHtml

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.
Logged

Cron

  • Coppermine newbie
  • Offline Offline
  • Posts: 5
Re: Coppermine Code Parsing Question
« Reply #2 on: January 19, 2006, 10:46:17 am »

I managed to enable it by changing

Code: [Select]
$template = fread(fopen($template_file, 'r'), filesize($template_file));
to

Code: [Select]
//$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.
Logged
Pages: [1]   Go Up
 

Page created in 0.023 seconds with 15 queries.