Skip to content

Commit

Permalink
Templates parsing fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sergejey committed Apr 8, 2019
1 parent e2c2b8f commit 43e0837
Show file tree
Hide file tree
Showing 2 changed files with 241 additions and 245 deletions.
156 changes: 76 additions & 80 deletions lib/objects.class.php
Expand Up @@ -1124,95 +1124,92 @@ function processTitle($title, $object = 0)


$title = $jTempl->result; $title = $jTempl->result;
endMeasure('processTitleJTemplate'); endMeasure('processTitleJTemplate');
return $title; // return $title;
} } else {

$title = preg_replace('/%rand%/is', rand(), $title);

$title=preg_replace('/%([\w\d\.]+?)\.([\w\d\.]+?)\|(\d+)%/uis', '%\1.\2%', $title);



$title = preg_replace('/%rand%/is', rand(), $title);
$title=preg_replace('/%([\w\d\.]+?)\.([\w\d\.]+?)\|(\d+)%/uis', '%\1.\2%', $title);
if (preg_match_all('/%([\w\d\.]+?)\.([\w\d\.]+?)%/uis', $title, $m))
{
startMeasure('processTitleProperties');


$total = count($m[0]);



for ($i = 0; $i < $total; $i++)
if (preg_match_all('/%([\w\d\.]+?)\.([\w\d\.]+?)%/uis', $title, $m)) {
{ $title = str_replace($m[0][$i], getGlobal($m[1][$i] . '.' . $m[2][$i]), $title);
startMeasure('processTitleProperties'); }

$total = count($m[0]);

for ($i = 0; $i < $total; $i++)
{
$title = str_replace($m[0][$i], getGlobal($m[1][$i] . '.' . $m[2][$i]), $title);
}


endMeasure('processTitleProperties'); endMeasure('processTitleProperties');
} }
if (preg_match_all('/%([\w\d\.]+?)\.([\w\d\.]+?)\|"(.+?)"%/uis', $title, $m)) if (preg_match_all('/%([\w\d\.]+?)\.([\w\d\.]+?)\|"(.+?)"%/uis', $title, $m))
{ {
startMeasure('processTitlePropertiesReplace'); startMeasure('processTitlePropertiesReplace');

$total = count($m[0]); $total = count($m[0]);

for ($i = 0; $i < $total; $i++) for ($i = 0; $i < $total; $i++)
{ {
$data=getGlobal($m[1][$i] . '.' . $m[2][$i]); $data=getGlobal($m[1][$i] . '.' . $m[2][$i]);
if ($data == '') $data = 0; if ($data == '') $data = 0;
$descr=$m[3][$i]; $descr=$m[3][$i];
$tmp=explode(';', $descr); $tmp=explode(';', $descr);
$totald=count($tmp); $totald=count($tmp);
$hsh=array(); $hsh=array();
if ($totald==1) { if ($totald==1) {
if ($data!='') { if ($data!='') {
$hsh[$data]=$descr; $hsh[$data]=$descr;
} else { } else {
$hsh[$data]=''; $hsh[$data]='';
} }
} else { } else {
for($id=0;$id<$totald;$id++) { for($id=0;$id<$totald;$id++) {
$item=trim($tmp[$id]); $item=trim($tmp[$id]);
if (preg_match('/(.+?)=(.+)/uis', $item, $md)) { if (preg_match('/(.+?)=(.+)/uis', $item, $md)) {
$search_value=$md[1]; $search_value=$md[1];
$search_replace=$md[2]; $search_replace=$md[2];
} else { } else {
$search_value=$id; $search_value=$id;
$search_replace=$item; $search_replace=$item;
} }
$hsh[$search_value]=$search_replace; $hsh[$search_value]=$search_replace;
} }
} }
$title = str_replace($m[0][$i], $hsh[$data], $title); $title = str_replace($m[0][$i], $hsh[$data], $title);
} }


endMeasure('processTitlePropertiesReplace'); endMeasure('processTitlePropertiesReplace');
} }
if (preg_match_all('/%([\w\d\.]+?)\.([\w\d\.]+?)\|(\w+?)%/uis', $title, $m)) { if (preg_match_all('/%([\w\d\.]+?)\.([\w\d\.]+?)\|(\w+?)%/uis', $title, $m)) {
startMeasure('processTitlePropertiesFunction'); startMeasure('processTitlePropertiesFunction');
$total = count($m[0]); $total = count($m[0]);
for($i=0;$i<$total;$i++) { for($i=0;$i<$total;$i++) {
$data = getGlobal($m[1][$i] . '.' . $m[2][$i]); $data = getGlobal($m[1][$i] . '.' . $m[2][$i]);
if (function_exists($m[3][$i])) { if (function_exists($m[3][$i])) {
$data=call_user_func($m[3][$i],$data); $data=call_user_func($m[3][$i],$data);
}
$title = str_replace($m[0][$i], $data, $title);
}
endMeasure('processTitlePropertiesFunction');
}
if (preg_match_all('/%([\w\d\.]+?)%/is', $title, $m))
{
$total = count($m[0]);

for ($i = 0; $i < $total; $i++)
{
if (preg_match('/^%\d/is', $m[0][$i]))
{
continue; // dirty hack, sorry for that
}

$title = str_replace($m[0][$i], getGlobal($m[1][$i]), $title);
} }
$title = str_replace($m[0][$i], $data, $title);
} }
endMeasure('processTitlePropertiesFunction');
}
if (preg_match_all('/%([\w\d\.]+?)%/is', $title, $m))
{
$total = count($m[0]);

for ($i = 0; $i < $total; $i++)
{
if (preg_match('/^%\d/is', $m[0][$i]))
{
continue; // dirty hack, sorry for that
}


$title = str_replace($m[0][$i], getGlobal($m[1][$i]), $title);
}
} }



if (preg_match_all('/<#LANG_(\w+?)#>/is', $title, $m)) if (preg_match_all('/<#LANG_(\w+?)#>/is', $title, $m))
{ {
$total = count($m[0]); $total = count($m[0]);
Expand All @@ -1222,7 +1219,6 @@ function processTitle($title, $object = 0)
$title = str_replace($m[0][$i], constant('LANG_' . $m[1][$i]), $title); $title = str_replace($m[0][$i], constant('LANG_' . $m[1][$i]), $title);
} }
} }

if (preg_match_all('/\&#060#LANG_(.+?)#\&#062/is', $title, $m)) if (preg_match_all('/\&#060#LANG_(.+?)#\&#062/is', $title, $m))
{ {
$total = count($m[0]); $total = count($m[0]);
Expand Down

0 comments on commit 43e0837

Please sign in to comment.