4images Forum & Community
4images Help / Hilfe => Bug Fixes & Patches => Topic started by: V@no on April 19, 2005, 12:24:19 AM
-
Since v1.7.1 introduced new, optimized template engine, a little bug was created which would not allow use conditional tags inside other conditional tags:
{if blah}{if blah2}...{endif blah2}{endif blah}
the {if blah2}{endif blah2} would be ignored.
Also, in this fix I added new feature {ifno blah}{endifno blah} type of conditional tags. That condition is opposite of {if blah} meaning that code between these tags will be showed only if {blah} tag is empty.
Open includes/templates.php
Find: // 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
);
Replace it with: // Compile condition tags
$template = preg_replace_callback(
'='.preg_quote($this->start).'if\s+([A-Z0-9_]+)'.preg_quote($this->end).'=Usi',
array(&$this, '_compile_condition_start'),
$template
);
$template = preg_replace_callback(
'='.preg_quote($this->start).'endif\s+([A-Z0-9_]+)'.preg_quote($this->end).'=Usi',
array(&$this, '_compile_condition_end'),
$template
);
$template = preg_replace_callback(
'='.preg_quote($this->start).'ifno\s+([A-Z0-9_]+)'.preg_quote($this->end).'=Usi',
array(&$this, '_compile_condition_no_start'),
$template
);
$template = preg_replace_callback(
'='.preg_quote($this->start).'endifno\s+([A-Z0-9_]+)'.preg_quote($this->end).'=Usi',
array(&$this, '_compile_condition_no_end'),
$template
);
Then find: function _compile_condition(&$matches) {
return '<?php if (!empty($' . trim($matches[1]) . ') && $' . trim($matches[1]) . ' != REPLACE_EMPTY): ?>' . $matches[2] . '<?php endif; ?>';
}
Replace it with: function _compile_condition_start(&$matches) {
return '<?php if (!empty($' . trim($matches[1]) . ') && $' . trim($matches[1]) . ' != REPLACE_EMPTY){ ?>';
}
function _compile_condition_end(&$matches) {
return '<?php } ?>';
}
function _compile_condition_no_start(&$matches) {
return '<?php if (empty($' . trim($matches[1]) . ') || $' . trim($matches[1]) . ' == REPLACE_EMPTY){ ?>';
}
function _compile_condition_no_end(&$matches) {
return '<?php } ?>';
}
P.S. if u dont need {ifno ..} feature, then I think it wouldn't be too dificult to figure out what needed to be removed ;)
-
Parse error: parse error, unexpected '}' in /home/bphotos/public_html/newsum/includes/template.php(101) : eval()'d code on line 259
For some reason .. it's giving me a parse error when I use that mod. Strange thing is that I don't even have a line 259 in the PHP coding .. it stops at 240-something
-
restore backups and try again.
-
it's still doing it .. and I did all the steps over (3 times)
It's weird because it's only doing it on pages other than index.php
{ links removed }
-
nevermind .. I fixed it by uploading a modified "template.php" file from 1.7
-
Thanks V@no!!!
:D
-
I also have a similar problem like ashantiforever described it above:
In my case it returns the parse error for index.php ONLY - the other pages seem to work with this MOD.
What more can I try? Thank you.
-
Ok, I killed this nasty bug with this fix: http://www.4homepages.de/forum/index.php?topic=6806.0
-
seems to me u have an opening conditional tag (if tag} but without closing one {endif tag} (or opposite)
-
For me it works. Thanks for that fix ;-)
-
Great work!
Thanks!.
Best regards.
WR.
-
thanks v@no :) :) great effort
-
Hello,
I am using the new 1.72 version of 4images and the {ifno...} blah {endifno...} feature doesn't work anymore, for me.
In the "Changelog.txt" it is mentioned, that the code of the 1.72 release differs from the solution in this forum post.
And since I am not very firm in PHP, it would be very helpful if someone may tell me which lines I have to change, in order to get my {ifno...} blah {endifno...} feature back. :oops:
Greetings, Mega
-
There is nothing needed to be changed, it should work just fine. Or perpahs you should be more describtive then saying "it doesnt work" ;)
-
Needs the Version 1.7.2 this Mod/Fix too?
Thanks, bye Konradin
-
no, v1.7.2 already has build-in, except its {ifnot ..}{endifnot ..}
-
for the 1.7 version ?!?!
because in the avatar mod that has this structure
Avatar:
{if user_avatar_file} Upload avatar:
Max. allowed 50x50px
ODER
{endif user_avatar_file} Select from the list: {if user_avatar_file}
{endif user_avatar_file}
it didt show
thanks for your help!
-
sorry, what?
this is only for v1.7.1
Plus I can't see anything in your reply even remotely relative to this topic...
-
In one reply of the MOD Avatar 2.0.1
in the add on for select the avatar when register
http://www.4homepages.de/forum/index.php?topic=3978.msg32232#msg32232
It says something about conditional tags, and when a user asked for this bug you refer to this topic, conditional tags
this conditionals didnt work for me :(
when i check my form the only thing that I wach its this:
(http://www.dosisdigital.com/avatarsectionform.jpg)
I hope this can help
thanks for your help
-
Im trying to use this with 1.76 to try to hide stuff from search engines, together with the non session -id and treat robot as user ...... But
1) First of all I dont have any include/templates.html I have includes/template.html
2) My template.html is different than what is listed in the first section
3) I would appreciate it if you can tell me which code to change, thanks!
<?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.6 *
* *
* 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_path, 1);
}
$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 ".$path, 1);
}
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)
{
// Replace <?xml by printing them via php to avoid error messages when short_open_tags is on
$template = preg_replace('/<\?xml/i', "<?php echo '<?xml'; ?>", $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(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
);
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) {
$name = trim($matches[1]);
if (!isset($this->val_cache[$name])) {
return $matches[0];
}
// Header and Footer are parsed in print_template()
if ($name == 'header' || $name == 'footer') {
return $matches[0];
}
return '<?php echo $' . $name . '; ?>';
}
function _compile_condition_start(&$matches) {
$name = trim($matches[2]);
if (!isset($this->val_cache[$name])) {
return $matches[0];
}
if ($matches[1] == 'not' || $matches[1] == 'no') {
return '<?php if (empty($' . $name . ') || $' . $name . ' === REPLACE_EMPTY){ ?>';
}
return '<?php if (!empty($' . $name . ') && $' . $name . ' !== REPLACE_EMPTY){ ?>';
}
function _compile_condition_end(&$matches) {
$name = trim($matches[2]);
if (!isset($this->val_cache[$name])) {
return $matches[0];
}
return '<?php } ?>';
}
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) {
if (strpos($template, $this->start.'header'.$this->end) !== false) {
$header = $this->parse_template("header");
$template = str_replace($this->start.'header'.$this->end, $header, $template);
}
if (strpos($template, $this->start.'footer'.$this->end) !== false) {
$footer = $this->parse_template("footer");
$template = str_replace($this->start.'footer'.$this->end, $footer, $template);
}
print $this->clean_template($template);
}
function clean_template($template) {
$search_array = array(
'='.preg_quote($this->start).'([A-Z0-9_]+)'.preg_quote($this->end).'=Usi',
'='.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_array = array(
"",
"",
""
);
$template = preg_replace($search_array, $replace_array, $template);
return $template;
}
function error($errmsg, $halt = 0) {
if (!$this->no_error) {
global $user_info;
//if (isset($user_info['user_level']) && $user_info['user_level'] == ADMIN){
echo "<br ><font color='#FF0000'><b>Template Error</b></font>: ".$errmsg."<br >";
/*} else {
echo "<br ><font color='#FF0000'><b>An unexpected error occured. Please try again later.</b></font><br >";
}*/
if ($halt) {
exit;
}
}
}
} // end of class
?>