Skip to content

Commit 45a8b56

Browse files
author
Marius Cramer
committed
Improved tpl class from master
1 parent 1da57c0 commit 45a8b56

File tree

1 file changed

+29
-51
lines changed

1 file changed

+29
-51
lines changed

server/lib/classes/tpl.inc.php

Lines changed: 29 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ function _getData ($tmplfile, $do_eval=false) {
932932

933933
$regex = '/(<|<\/|{|{\/|<!--|<!--\/){1}\s*';
934934
$regex.= 'tmpl_([\w]+)\s*';
935-
$regex.= '(?:';
935+
$regex.= '((?:(?:';
936936
$regex.= '(?:';
937937
$regex.= '(name|format|escape|op|value|file)';
938938
$regex.= '\s*=\s*';
@@ -941,40 +941,9 @@ function _getData ($tmplfile, $do_eval=false) {
941941
$regex.= '((?<=[\"\'])';
942942
$regex.= '[^\"\']*|[a-z0-9_\.]*)';
943943
$regex.= '[\"\']?';
944-
$regex.= ')?\s*';
945-
$regex.= '(?:';
946-
$regex.= '(?:';
947-
$regex.= '(name|format|escape|op|value)';
948-
$regex.= '\s*=\s*';
949-
$regex.= ')';
950-
$regex.= '(?:[\"\'])?';
951-
$regex.= '((?<=[\"\'])';
952-
$regex.= '[^\"\']*|[a-z0-9_\.]*)';
953-
$regex.= '[\"\']?';
954-
$regex.= ')?\s*';
955-
$regex.= '(?:';
956-
$regex.= '(?:';
957-
$regex.= '(name|format|escape|op|value)';
958-
$regex.= '\s*=\s*';
959-
$regex.= ')';
960-
$regex.= '(?:[\"\'])?';
961-
$regex.= '((?<=[\"\'])';
962-
$regex.= '[^\"\']*|[a-z0-9_\.]*)';
963-
$regex.= '[\"\']?';
964-
$regex.= ')?\s*';
965-
$regex.= '(?:';
966-
$regex.= '(?:';
967-
$regex.= '(name|format|escape|op|value)';
968-
$regex.= '\s*=\s*';
969-
$regex.= ')';
970-
$regex.= '(?:[\"\'])?';
971-
$regex.= '((?<=[\"\'])';
972-
$regex.= '[^\"\']*|[a-z0-9_\.]*)';
973-
$regex.= '[\"\']?';
974-
$regex.= ')?\s*';
944+
$regex.= ')?\s*)*?)';
975945
$regex.= '(?:>|\/>|}|-->){1}';
976946
$regex.= '/i';
977-
//$regex.= '([\r\n|\n|\r])?/ie';
978947
$data = preg_replace_callback($regex, array($this, '_parseTag'), $data);
979948

980949
if ($this->_cache) { // add cache if need be
@@ -1300,28 +1269,37 @@ function _parseTag ($args) {
13001269
$wholetag = $args[0];
13011270
$openclose = $args[1];
13021271
$tag = strtolower($args[2]);
1303-
$newline = $args[11];
1304-
//echo "1#$newline#2";
1305-
1306-
if ($tag == 'else') return '<?php } else { ?>'.$newline;
1272+
1273+
if ($tag == 'else') return '<?php } else { ?>';
13071274
if ($tag == 'tmpl_include') return $wholetag; // ignore tmpl_include tags
13081275

13091276
if (preg_match("/^<\/|{\/|<!--\/$/s", $openclose) || preg_match("/^end[if|loop|unless|comment]$/", $tag)) {
13101277
if ($tag == 'loop' || $tag == 'endloop') array_pop($this->_namespace);
13111278
if ($tag == 'comment' || $tag == 'endcomment') {
1312-
return '<?php */ ?>'.$newline;
1279+
return '<?php */ ?>';
13131280
}
13141281
else {
1315-
return '<?php } ?>'.$newline;
1282+
return '<?php } ?>';
13161283
}
13171284
}
13181285

13191286
// arrange attributes
1320-
for ($i=3; $i < 10; $i=($i+2)) {
1321-
if (empty($args[$i]) && empty($args[($i+1)])) break;
1322-
$key = (empty($args[$i])) ? 'name' : strtolower($args[$i]);
1323-
if ($key == 'name' && preg_match('/^(php)?include$/', $tag)) $key = 'file';
1324-
$$key = $args[($i+1)];
1287+
$tmp_atts = $args[3];
1288+
$atts = preg_split('/\s+/', $tmp_atts);
1289+
foreach($atts as $att) {
1290+
$regex = '/(?:';
1291+
$regex.= '(name|format|escape|op|value|file)';
1292+
$regex.= '\s*=\s*';
1293+
$regex.= ')?';
1294+
$regex.= '(?:[\"\'])?';
1295+
$regex.= '((?<=[\"\'])';
1296+
$regex.= '[^\"\']*|[a-z0-9_\.]*)';
1297+
$regex.= '[\"\']?/';
1298+
if(preg_match($regex, $att, $match)) {
1299+
$key = (empty($match[1])) ? 'name' : strtolower($match[1]);
1300+
if ($key == 'name' && preg_match('/^(php)?include$/', $tag)) $key = 'file';
1301+
$$key = $match[2];
1302+
}
13251303
}
13261304

13271305
$var = ($this->OPTIONS['CASELESS']) ? strtolower($name) : $name;
@@ -1345,28 +1323,28 @@ function _parseTag ($args) {
13451323
if (empty($escape) && (!empty($this->OPTIONS['DEFAULT_ESCAPE']) && strtolower($this->OPTIONS['DEFAULT_ESCAPE']) != 'none')) {
13461324
$escape = strtolower($this->OPTIONS['DEFAULT_ESCAPE']);
13471325
}
1348-
return '<?php '.$this->_parseVar ($wholetag, $tag, $var, @$escape, @$format, @$namespace).' ?>'.$newline."\n";
1326+
return '<?php '.$this->_parseVar ($wholetag, $tag, $var, @$escape, @$format, @$namespace).' ?>'."\n";
13491327
break;
13501328

13511329
case 'if':
1352-
return '<?php if ('. $this->_parseIf($var, @$value, @$op, @$namespace, @$format) .') { ?>'.$newline;
1330+
return '<?php if ('. $this->_parseIf($var, @$value, @$op, @$namespace, @$format) .') { ?>';
13531331
break;
13541332

13551333
case 'unless':
1356-
return '<?php if (!'. $this->_parseIf($var, @$value, @$op, @$namespace, @$format) .') { ?>'.$newline;
1334+
return '<?php if (!'. $this->_parseIf($var, @$value, @$op, @$namespace, @$format) .') { ?>';
13571335
break;
13581336

13591337
case 'elseif':
1360-
return '<?php } elseif ('. $this->_parseIf($var, @$value, @$op, @$namespace, @$format) .') { ?>'.$newline;
1338+
return '<?php } elseif ('. $this->_parseIf($var, @$value, @$op, @$namespace, @$format) .') { ?>';
13611339
break;
13621340

13631341
case 'loop':
1364-
return '<?php '. $this->_parseLoop($var) .'?>'.$newline;
1342+
return '<?php '. $this->_parseLoop($var) .'?>';
13651343
break;
13661344

13671345
case 'comment':
13681346
if (empty($var)) { // full open/close style comment
1369-
return '<?php /* ?>'.$newline;
1347+
return '<?php /* ?>';
13701348
}
13711349
else { // just ignore tag if it was a one line comment
13721350
return;
@@ -1375,7 +1353,7 @@ function _parseTag ($args) {
13751353

13761354
case 'phpinclude':
13771355
if ($this->OPTIONS['ENABLE_PHPINCLUDE']) {
1378-
return '<?php include(\''.$file.'\'); ?>'.$newline;
1356+
return '<?php include(\''.$file.'\'); ?>';
13791357
}
13801358
break;
13811359

0 commit comments

Comments
 (0)