Author Topic: [FIX] - includes/template.php file  (Read 17350 times)

0 Members and 1 Guest are viewing this topic.

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
[FIX] - includes/template.php file
« on: October 03, 2007, 05:15:16 AM »
Quote
- Added support for {ifno ..} tags in addition to {ifnot ..}

http://www.4homepages.de/forum/index.php?topic=13732.msg73906#msg73906

If so, {ifno ... and {endifno ... is no clean in clean_template method.

in includes/template.php file,

find:

Quote
'='.preg_quote($this->start).'if(not?)?\s+([A-Z0-9_]+)'.preg_quote($this->end).'=Usi',
'='.preg_quote($this->start).'endif(not?)?\s+([A-Z0-9_]+)'.preg_quote($this->end).'=Usi',

replace:

Code: [Select]
'='.preg_quote($this->start).'if(not|no?)?\s+([A-Z0-9_]+)'.preg_quote($this->end).'=Usi',
'='.preg_quote($this->start).'endif(not|no?)?\s+([A-Z0-9_]+)'.preg_quote($this->end).'=Usi',
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: [FIX] - includes/template.php file
« Reply #1 on: October 05, 2007, 09:15:36 PM »
For php.html file hack, I create small patch.

In includes/template.php file,

find:

Quote
if (strpos($template, $this->start.'footer'.$this->end) !== false) {
      $footer = $this->parse_template("footer");
      $template = str_replace($this->start.'footer'.$this->end, $footer, $template);
}

add after:

Code: [Select]
if (@file_exists($this->template_path . '/media/php.'.$this->template_extension) && @is_writable($this->template_path . '/media')) {
      @unlink($this->template_path . '/media/php.'.$this->template_extension);
}
$handle = @opendir($this->template_path . '/media');
while (false !== ($file = @readdir($handle))) {
    if (preg_match("/\.php$/", get_file_name(basename($file))) && @is_writable($this->template_path . '/media')) {
        @unlink($this->template_path . '/media/' . $file);
    }
}
@closedir($handle);
unset ($handle);

Automatic remove of php.html file in media folder if found before file is load on screen + php extension remove in media folder. ;)
« Last Edit: February 18, 2011, 02:35:02 PM by thunderstrike »
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline mawenzi

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.500
    • View Profile
Re: [FIX] - includes/template.php file
« Reply #2 on: October 05, 2007, 10:09:51 PM »
For php.html file hack, I create small patch.

... that's a great idea ...
... thank thunderstrike ....  :D
Your first three "must do" before you ask a question ! ( © by V@no )
- please read the Forum Rules ...
- please study the FAQ ...
- please try to Search for your answer ...

You are on search for top 4images MOD's ?
- then please search here ... Mawenzi's Top 100+ MOD List (unsorted sorted) ...

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: [FIX] - includes/template.php file
« Reply #3 on: October 05, 2007, 10:28:23 PM »
All my fix is a great idea (axcept this one: http://www.4homepages.de/forum/index.php?topic=18931.0 - Nicky post tabular fix). ;)
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: [FIX] - includes/template.php file
« Reply #4 on: October 14, 2007, 04:21:11 PM »
Find:

Quote
// Compile condition tags
    $template = preg_replace_callback(
        '='.preg_quote($this->start).'if(not?)?\s+([A-Z0-9_]+)'.preg_quote($this->end).'=Usi',
        array(&$this, '_compile_condition_start'),
        $template
    );

    $template = preg_replace_callback(
        '='.preg_quote($this->start).'endif(not?)?\s+([A-Z0-9_]+)'.preg_quote($this->end).'=Usi',
        array(&$this, '_compile_condition_end'),
        $template
    );

replace:

Code: [Select]
// Compile condition tags
    $template = preg_replace_callback(
        '='.preg_quote($this->start).'if(not|no?)?\s+([A-Z0-9_]+)'.preg_quote($this->end).'=Usi',
        array(&$this, '_compile_condition_start'),
        $template
    );

    $template = preg_replace_callback(
        '='.preg_quote($this->start).'endif(not|no?)?\s+([A-Z0-9_]+)'.preg_quote($this->end).'=Usi',
        array(&$this, '_compile_condition_end'),
        $template
    );
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline honda2000

  • 4images Guru
  • *******
  • Posts: 3.263
    • View Profile
    • Wir machen Internet!
Re: [FIX] - includes/template.php file
« Reply #5 on: February 18, 2008, 07:26:29 PM »
wo kann man in includes/templates.php den Code finden??

Verson: 1.7.3

das ist meine /includes/templates.php

Code: [Select]

<?php
/**************************************************************************
 *                                                                        *
 *    4images - A Web Based Image Gallery Management System               *
 *    ----------------------------------------------------------------    *
 *                                                                        *
 *             File: template.php                                         *
 *        Copyright: (C) 2002 Jan Sorgalla                                *
 *            Email: jan@4homepages.de                                    *
 *              Web: http://www.4homepages.de                             *
 *    Scriptversion: 1.7.1                                                *
 *                                                                        *
 *    Never released without support from: Nicky (http://www.nicky.net)   *
 *                                                                        *
 **************************************************************************
 *                                                                        *
 *    Dieses Script ist KEINE Freeware. Bitte lesen Sie die Lizenz-       *
 *    bedingungen (Lizenz.txt) für weitere Informationen.                 *
 *    ---------------------------------------------------------------     *
 *    This script is NOT freeware! Please read the Copyright Notice       *
 *    (Licence.txt) for further information.                              *
 *                                                                        *
 *************************************************************************/
if (!defined('ROOT_PATH')) {
  die(
"Security violation");
}

class 
Template {

  var 
$no_error 0;
  var 
$val_cache = array();
  var 
$missing_val_cache = array();
  var 
$template_cache = array();
  var 
$template_path;
  var 
$template_extension "html";
  var 
$start "{";
  var 
$end "}";

  function 
Template($template_path "") {
    if (!@
is_dir($template_path)) {
      
$this->error("Couldn't open Template-Pack ".$template_path1);
    }
    
$this->template_path $template_path;
  }

  function 
register_vars($var_name$value "") {
    if (!
is_array($var_name)) {
      
$this->val_cache[$var_name] = $value;
    }
    else {
      
$this->val_cache array_merge($this->val_cache$var_name);
    }
  }

  function 
un_register_vars($var_list) {
    
$vars explode(","$var_list);
    foreach (
$vars as $val) {
      unset(
$this->val_cache[trim($val)]);
    }
  }

  function 
cache_templates($template_list) {
    
$template_list explode(","$template_list);
    foreach (
$template_list as $val) {
      
$val trim($val);
      if (!isset(
$this->template_cache[$val])) {
        
$this->get_template($val);
      }
    }
  }

  function 
get_template($template) {
    if (!isset(
$this->template_cache[$template])) {
      
$path $this->template_path."/".$template.".".$this->template_extension;
      
$line = @implode("", @file($path));
      if (empty(
$line)) {
        
$this->error("Couldn't open Template ".$path1);
      }

      if (
defined('EXEC_PHP_CODE') && EXEC_PHP_CODE == 0) {
        
$line preg_replace("/<[\?|%]+(php|=)?(.*)[\?|%]+>/siU"""$line);
        
$line preg_replace("/<script\s+language\s?=\s?[\"|']?php[\"|']?>
(.*)<\/script>/siU", "", $line);
      }

      $line = $this->compile_template($line);

      $this->template_cache[$template] = $line;
    }
    return $this->template_cache[$template];
  }

  function parse_template($template) {
    $template = $this->get_template($template);

    // Don't show error notices
    $old = error_reporting(E_ALL ^ E_NOTICE);

    extract($this->val_cache);
    ob_start();
    //echo $template;
    eval("?>".$template."<?php return 1;");

    
$str = ob_get_contents();
    ob_end_clean();

    // Reset error_reporting
    error_reporting(
$old);

    return 
$str;
  }

  function compile_template(
$template)
  {
    // Compile variables in PHP code
    preg_match_all(
        "
/<[\?|%]+(php|=)?(.*)[\?|%]+>/siU",
        
$template,
        
$regs,
        PREG_SET_ORDER
    );

    for (
$i = 0; isset($regs[$i]); $i++) {
      // Fix single quotes
      
$parsed = preg_replace_callback(
        "
/=\s*'(.*)".preg_quote($this->start)."([A-Z0-9_]+)".preg_quote($this->end)."(.*)';/Usi",
        array(&
$this, '_fix_php_quotes'),
        
$regs[$i][0]
      );

      
$parsed = preg_replace_callback(
        '='.preg_quote(
$this->start).'([A-Z0-9_]+)'.preg_quote($this->end).'=Usi',
        array(&
$this, '_compile_php_var'),
        
$parsed
      );

      
$template = str_replace($regs[$i][0], $parsed$template);
    }

    // Compile variables
    
$template = preg_replace_callback(
        '='.preg_quote(
$this->start).'([A-Z0-9_]+)'.preg_quote($this->end).'=Usi',
        array(&
$this, '_compile_var'),
        
$template
    );

    // Compile condition tags
    
$template = preg_replace_callback(
        '='.preg_quote(
$this->start).'if\s+([A-Z0-9_]+)'.preg_quote($this->end).'(.*)'.preg_quote($this->start).'endif\s+(\\1+)'.preg_quote($this->end).'=Usi',
        array(&
$this, '_compile_condition'),
        
$template
    );

    return 
$template;
  }

  function _compile_php_var(&
$matches) {
    return '
{$' . trim($matches[1]) . '}';
  }

  function _fix_php_quotes(&
$matches) {
    return '= "' . str_replace('"', '\\"', $matches[1])
           . $this->start.$matches[2].$this->end
           . str_replace('"', '\\"', $matches[3]) . '";';
  }

  function _compile_var(&
$matches) {
    return '<?php echo $' . trim(
$matches[1]) . '; ?>
';
  }

  function _compile_condition(&$matches) {
    return '<?php if (!empty($' . trim($matches[1]) . ') && $' . trim($matches[1]) . ' != REPLACE_EMPTY): ?>' . $matches[2] . '<?php endif; ?>';
  }

  function parse_array($array) {
    static $keys;

    foreach ($array as $key => $val) {
      if (is_array($val)) {
        $array[$key] = $this->parse_array($val);
      }
      else {
        if (!isset($keys) || count($keys) != count($this->val_cache)) {
          $keys = array_keys($this->val_cache);
          array_walk($keys, array(&$this, '_prepare_key'));
        }

        $array[$key] = str_replace($keys, $this->val_cache, $val);
      }
    }
    return $array;
  }

  function _prepare_key(&$item)
  {
    $item = $this->start.$item.$this->end;
  }

  function print_template($template) {
    print $this->clean_template($template);
  }

  function clean_template($template) {
    $template = preg_replace(
      "/".preg_quote($this->start)."[^".preg_quote($this->end)."\s]+".preg_quote($this->end)."/",
      '',
      $template
    );
    return $template;
  }
 

 

  function error($errmsg, $halt = 0) {
    if (!$this->no_error) {
      echo "<br /><font color='#FF0000'><b>Template Error</b></font>: ".$errmsg."<br />";
      if ($halt) {
        exit;
      }
    }
  }
} // end of class



?>
[code]

ich hab dieses Problem beim öffnen der index.php
Template Error: Couldn't open Template ./templates/default/media/php.html

[/code]
« Last Edit: February 18, 2008, 08:41:52 PM by honda2000 »

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: [FIX] - includes/template.php file
« Reply #6 on: February 18, 2008, 08:20:52 PM »
Code ist 4images v1.74+ .
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?