@@ -87,12 +87,24 @@ |
||
| 87 | 87 | // adds foreach properties |
| 88 | 88 | if ($usesAny) { |
| 89 | 89 | $pre .= "\n".'$this->globals["loop"]['.$name.'] = array'."\n("; |
| 90 | - if ($usesIndex) $pre .="\n\t".'"index" => 0,'; |
|
| 91 | - if ($usesIteration) $pre .="\n\t".'"iteration" => 1,'; |
|
| 92 | - if ($usesFirst) $pre .="\n\t".'"first" => null,'; |
|
| 93 | - if ($usesLast) $pre .="\n\t".'"last" => null,'; |
|
| 94 | - if ($usesShow) $pre .="\n\t".'"show" => $this->isTraversable($_loop'.$cnt.'_data, true),'; |
|
| 95 | - if ($usesTotal) $pre .="\n\t".'"total" => $this->count($_loop'.$cnt.'_data),'; |
|
| 90 | + if ($usesIndex) { |
|
| 91 | + $pre .="\n\t".'"index" => 0,'; |
|
| 92 | + } |
|
| 93 | + if ($usesIteration) { |
|
| 94 | + $pre .="\n\t".'"iteration" => 1,'; |
|
| 95 | + } |
|
| 96 | + if ($usesFirst) { |
|
| 97 | + $pre .="\n\t".'"first" => null,'; |
|
| 98 | + } |
|
| 99 | + if ($usesLast) { |
|
| 100 | + $pre .="\n\t".'"last" => null,'; |
|
| 101 | + } |
|
| 102 | + if ($usesShow) { |
|
| 103 | + $pre .="\n\t".'"show" => $this->isTraversable($_loop'.$cnt.'_data, true),'; |
|
| 104 | + } |
|
| 105 | + if ($usesTotal) { |
|
| 106 | + $pre .="\n\t".'"total" => $this->count($_loop'.$cnt.'_data),'; |
|
| 107 | + } |
|
| 96 | 108 | $pre.="\n);\n".'$_loop'.$cnt.'_glob =& $this->globals["loop"]['.$name.'];'; |
| 97 | 109 | } |
| 98 | 110 | // checks if the loop must be looped |
@@ -47,8 +47,9 @@ |
||
| 47 | 47 | case 'hexentity': |
| 48 | 48 | $out = ''; |
| 49 | 49 | $cnt = strlen((string) $value); |
| 50 | - for ($i=0; $i < $cnt; $i++) |
|
| 51 | - $out .= '&#x' . bin2hex((string) $value[$i]) . ';'; |
|
| 50 | + for ($i=0; $i < $cnt; $i++) { |
|
| 51 | + $out .= '&#x' . bin2hex((string) $value[$i]) . ';'; |
|
| 52 | + } |
|
| 52 | 53 | return $out; |
| 53 | 54 | case 'javascript': |
| 54 | 55 | return strtr((string) $value, array('\\'=>'\\\\',"'"=>"\\'",'"'=>'\\"',"\r"=>'\\r',"\n"=>'\\n','</'=>'<\/')); |
@@ -722,7 +722,9 @@ discard block |
||
| 722 | 722 | echo 'COMPILER INIT' . "\n"; |
| 723 | 723 | } |
| 724 | 724 | |
| 725 | - if ($this->debug) echo 'PROCESSING PREPROCESSORS ('.count($this->processors['pre']).')' . "\n"; |
|
| 725 | + if ($this->debug) { |
|
| 726 | + echo 'PROCESSING PREPROCESSORS ('.count($this->processors['pre']).')' . "\n"; |
|
| 727 | + } |
|
| 726 | 728 | |
| 727 | 729 | // runs preprocessors |
| 728 | 730 | foreach ($this->processors['pre'] as $preProc) { |
@@ -738,7 +740,9 @@ discard block |
||
| 738 | 740 | unset($preProc); |
| 739 | 741 | |
| 740 | 742 | // show template source if debug |
| 741 | - if ($this->debug) echo '<pre>'.print_r(htmlentities($tpl), true).'</pre>' . "\n"; |
|
| 743 | + if ($this->debug) { |
|
| 744 | + echo '<pre>'.print_r(htmlentities($tpl), true).'</pre>' . "\n"; |
|
| 745 | + } |
|
| 742 | 746 | |
| 743 | 747 | // strips php tags if required by the security policy |
| 744 | 748 | if ($this->securityPolicy !== null) { |
@@ -827,7 +831,9 @@ discard block |
||
| 827 | 831 | |
| 828 | 832 | $compiled .= $this->removeBlock('topLevelBlock'); |
| 829 | 833 | |
| 830 | - if ($this->debug) echo 'PROCESSING POSTPROCESSORS' . "\n"; |
|
| 834 | + if ($this->debug) { |
|
| 835 | + echo 'PROCESSING POSTPROCESSORS' . "\n"; |
|
| 836 | + } |
|
| 831 | 837 | |
| 832 | 838 | foreach ($this->processors['post'] as $postProc) { |
| 833 | 839 | if (is_array($postProc) && isset($postProc['autoload'])) { |
@@ -841,7 +847,9 @@ discard block |
||
| 841 | 847 | } |
| 842 | 848 | unset($postProc); |
| 843 | 849 | |
| 844 | - if ($this->debug) echo 'COMPILATION COMPLETE : MEM USAGE : '.memory_get_usage() . "\n"; |
|
| 850 | + if ($this->debug) { |
|
| 851 | + echo 'COMPILATION COMPLETE : MEM USAGE : '.memory_get_usage() . "\n"; |
|
| 852 | + } |
|
| 845 | 853 | |
| 846 | 854 | $output = "<?php\n/* template head */\n"; |
| 847 | 855 | |
@@ -924,7 +932,9 @@ discard block |
||
| 924 | 932 | */ |
| 925 | 933 | protected function resolveSubTemplateDependencies($function) |
| 926 | 934 | { |
| 927 | - if ($this->debug) echo 'Compiler::'.__FUNCTION__."\n"; |
|
| 935 | + if ($this->debug) { |
|
| 936 | + echo 'Compiler::'.__FUNCTION__."\n"; |
|
| 937 | + } |
|
| 928 | 938 | |
| 929 | 939 | $body = $this->templatePlugins[$function]['body']; |
| 930 | 940 | foreach ($this->templatePlugins as $func => $attr) { |
@@ -996,8 +1006,9 @@ discard block |
||
| 996 | 1006 | reset($this->scopeTree); |
| 997 | 1007 | $this->scope =& $this->data; |
| 998 | 1008 | $cnt = count($this->scopeTree); |
| 999 | - for ($i=0;$i<$cnt;$i++) |
|
| 1000 | - $this->scope =& $this->scope[$this->scopeTree[$i]]; |
|
| 1009 | + for ($i=0;$i<$cnt;$i++) { |
|
| 1010 | + $this->scope =& $this->scope[$this->scopeTree[$i]]; |
|
| 1011 | + } |
|
| 1001 | 1012 | } elseif ($bit === '_root' || $bit === '__') { |
| 1002 | 1013 | $this->scope =& $this->data; |
| 1003 | 1014 | $this->scopeTree = array(); |
@@ -1024,7 +1035,9 @@ discard block |
||
| 1024 | 1035 | */ |
| 1025 | 1036 | public function addBlock($type, array $params, $paramtype) |
| 1026 | 1037 | { |
| 1027 | - if ($this->debug) echo 'Compiler::'.__FUNCTION__."\n"; |
|
| 1038 | + if ($this->debug) { |
|
| 1039 | + echo 'Compiler::'.__FUNCTION__."\n"; |
|
| 1040 | + } |
|
| 1028 | 1041 | |
| 1029 | 1042 | $class = 'Dwoo_Plugin_'.$type; |
| 1030 | 1043 | if (class_exists($class) === false) { |
@@ -1071,7 +1084,9 @@ discard block |
||
| 1071 | 1084 | */ |
| 1072 | 1085 | public function injectBlock($type, array $params) |
| 1073 | 1086 | { |
| 1074 | - if ($this->debug) echo 'Compiler::'.__FUNCTION__."\n"; |
|
| 1087 | + if ($this->debug) { |
|
| 1088 | + echo 'Compiler::'.__FUNCTION__."\n"; |
|
| 1089 | + } |
|
| 1075 | 1090 | |
| 1076 | 1091 | $class = 'Dwoo_Plugin_'.$type; |
| 1077 | 1092 | if (class_exists($class) === false) { |
@@ -1090,7 +1105,9 @@ discard block |
||
| 1090 | 1105 | */ |
| 1091 | 1106 | public function removeBlock($type) |
| 1092 | 1107 | { |
| 1093 | - if ($this->debug) echo 'Compiler::'.__FUNCTION__."\n"; |
|
| 1108 | + if ($this->debug) { |
|
| 1109 | + echo 'Compiler::'.__FUNCTION__."\n"; |
|
| 1110 | + } |
|
| 1094 | 1111 | |
| 1095 | 1112 | $output = ''; |
| 1096 | 1113 | |
@@ -1177,7 +1194,9 @@ discard block |
||
| 1177 | 1194 | */ |
| 1178 | 1195 | public function removeTopBlock() |
| 1179 | 1196 | { |
| 1180 | - if ($this->debug) echo 'Compiler::'.__FUNCTION__."\n"; |
|
| 1197 | + if ($this->debug) { |
|
| 1198 | + echo 'Compiler::'.__FUNCTION__."\n"; |
|
| 1199 | + } |
|
| 1181 | 1200 | |
| 1182 | 1201 | $o = array_pop($this->stack); |
| 1183 | 1202 | if ($o === null) { |
@@ -1255,7 +1274,9 @@ discard block |
||
| 1255 | 1274 | */ |
| 1256 | 1275 | protected function parse($in, $from, $to, $parsingParams = false, $curBlock='', &$pointer = null) |
| 1257 | 1276 | { |
| 1258 | - if ($this->debug) echo 'Compiler::'.__FUNCTION__."\n"; |
|
| 1277 | + if ($this->debug) { |
|
| 1278 | + echo 'Compiler::'.__FUNCTION__."\n"; |
|
| 1279 | + } |
|
| 1259 | 1280 | |
| 1260 | 1281 | if ($to === null) { |
| 1261 | 1282 | $to = strlen($in); |
@@ -1270,7 +1291,9 @@ discard block |
||
| 1270 | 1291 | if ($curBlock === 'root' && substr($in, $from, strlen($this->rd)) === $this->rd) { |
| 1271 | 1292 | // end template tag |
| 1272 | 1293 | $pointer += strlen($this->rd); |
| 1273 | - if ($this->debug) echo 'TEMPLATE PARSING ENDED' . "\n"; |
|
| 1294 | + if ($this->debug) { |
|
| 1295 | + echo 'TEMPLATE PARSING ENDED' . "\n"; |
|
| 1296 | + } |
|
| 1274 | 1297 | return false; |
| 1275 | 1298 | } |
| 1276 | 1299 | $from++; |
@@ -1289,7 +1312,9 @@ discard block |
||
| 1289 | 1312 | |
| 1290 | 1313 | $substr = substr($in, $from, $to-$from); |
| 1291 | 1314 | |
| 1292 | - if ($this->debug) echo 'PARSE CALL : PARSING "<b>'.htmlentities(substr($in, $from, min($to-$from, 50))).(($to-$from) > 50 ? '...':'').'</b>" @ '.$from.':'.$to.' in '.$curBlock.' : pointer='.$pointer. "\n"; |
|
| 1315 | + if ($this->debug) { |
|
| 1316 | + echo 'PARSE CALL : PARSING "<b>'.htmlentities(substr($in, $from, min($to-$from, 50))).(($to-$from) > 50 ? '...':'').'</b>" @ '.$from.':'.$to.' in '.$curBlock.' : pointer='.$pointer. "\n"; |
|
| 1317 | + } |
|
| 1293 | 1318 | $parsed = ""; |
| 1294 | 1319 | |
| 1295 | 1320 | if ($curBlock === 'root' && $first === '*') { |
@@ -1373,7 +1398,9 @@ discard block |
||
| 1373 | 1398 | $parsed = 'func'; |
| 1374 | 1399 | } elseif ($first === ';') { |
| 1375 | 1400 | // instruction end |
| 1376 | - if ($this->debug) echo 'END OF INSTRUCTION' . "\n"; |
|
| 1401 | + if ($this->debug) { |
|
| 1402 | + echo 'END OF INSTRUCTION' . "\n"; |
|
| 1403 | + } |
|
| 1377 | 1404 | if ($pointer !== null) { |
| 1378 | 1405 | $pointer++; |
| 1379 | 1406 | } |
@@ -1393,20 +1420,28 @@ discard block |
||
| 1393 | 1420 | if ($this->curBlock['type'] == 'else' || $this->curBlock['type'] == 'elseif') { |
| 1394 | 1421 | $pointer -= strlen($match[0]); |
| 1395 | 1422 | } |
| 1396 | - if ($this->debug) echo 'TOP BLOCK CLOSED' . "\n"; |
|
| 1423 | + if ($this->debug) { |
|
| 1424 | + echo 'TOP BLOCK CLOSED' . "\n"; |
|
| 1425 | + } |
|
| 1397 | 1426 | return $this->removeTopBlock(); |
| 1398 | 1427 | } else { |
| 1399 | - if ($this->debug) echo 'BLOCK OF TYPE '.$match[1].' CLOSED' . "\n"; |
|
| 1428 | + if ($this->debug) { |
|
| 1429 | + echo 'BLOCK OF TYPE '.$match[1].' CLOSED' . "\n"; |
|
| 1430 | + } |
|
| 1400 | 1431 | return $this->removeBlock($match[1]); |
| 1401 | 1432 | } |
| 1402 | 1433 | } elseif ($curBlock === 'root' && substr($substr, 0, strlen($this->rd)) === $this->rd) { |
| 1403 | 1434 | // end template tag |
| 1404 | - if ($this->debug) echo 'TAG PARSING ENDED' . "\n"; |
|
| 1435 | + if ($this->debug) { |
|
| 1436 | + echo 'TAG PARSING ENDED' . "\n"; |
|
| 1437 | + } |
|
| 1405 | 1438 | $pointer += strlen($this->rd); |
| 1406 | 1439 | return false; |
| 1407 | 1440 | } elseif (is_array($parsingParams) && preg_match('#^(([\'"]?)[a-z0-9_]+\2\s*='.($curBlock === 'array' ? '>?':'').')(?:\s+|[^=]).*#i', $substr, $match)) { |
| 1408 | 1441 | // named parameter |
| 1409 | - if ($this->debug) echo 'NAMED PARAM FOUND' . "\n"; |
|
| 1442 | + if ($this->debug) { |
|
| 1443 | + echo 'NAMED PARAM FOUND' . "\n"; |
|
| 1444 | + } |
|
| 1410 | 1445 | $len = strlen($match[1]); |
| 1411 | 1446 | while (substr($in, $from+$len, 1)===' ') { |
| 1412 | 1447 | $len++; |
@@ -1446,7 +1481,9 @@ discard block |
||
| 1446 | 1481 | // var parsed, check if any var-extension applies |
| 1447 | 1482 | if ($parsed==='var') { |
| 1448 | 1483 | if (preg_match('#^\s*([/%+*-])\s*([a-z0-9]|\$)#i', $substr, $match)) { |
| 1449 | - if($this->debug) echo 'PARSING POST-VAR EXPRESSION '.$substr . "\n"; |
|
| 1484 | + if($this->debug) { |
|
| 1485 | + echo 'PARSING POST-VAR EXPRESSION '.$substr . "\n"; |
|
| 1486 | + } |
|
| 1450 | 1487 | // parse expressions |
| 1451 | 1488 | $pointer += strlen($match[0]) - 1; |
| 1452 | 1489 | if (is_array($parsingParams)) { |
@@ -1476,7 +1513,9 @@ discard block |
||
| 1476 | 1513 | } |
| 1477 | 1514 | } |
| 1478 | 1515 | } else if ($curBlock === 'root' && preg_match('#^(\s*(?:[+/*%-.]=|=|\+\+|--)\s*)(.*)#s', $substr, $match)) { |
| 1479 | - if($this->debug) echo 'PARSING POST-VAR ASSIGNMENT '.$substr . "\n"; |
|
| 1516 | + if($this->debug) { |
|
| 1517 | + echo 'PARSING POST-VAR ASSIGNMENT '.$substr . "\n"; |
|
| 1518 | + } |
|
| 1480 | 1519 | // parse assignment |
| 1481 | 1520 | $value = $match[2]; |
| 1482 | 1521 | $operator = trim($match[1]); |
@@ -1518,7 +1557,9 @@ discard block |
||
| 1518 | 1557 | $out = Dwoo_Compiler::PHP_OPEN. $echo . $out . $operator . implode(' ', $value) . Dwoo_Compiler::PHP_CLOSE; |
| 1519 | 1558 | } else if ($curBlock === 'array' && is_array($parsingParams) && preg_match('#^(\s*=>?\s*)#', $substr, $match)) { |
| 1520 | 1559 | // parse namedparam with var as name (only for array) |
| 1521 | - if ($this->debug) echo 'VARIABLE NAMED PARAM (FOR ARRAY) FOUND' . "\n"; |
|
| 1560 | + if ($this->debug) { |
|
| 1561 | + echo 'VARIABLE NAMED PARAM (FOR ARRAY) FOUND' . "\n"; |
|
| 1562 | + } |
|
| 1522 | 1563 | $len = strlen($match[1]); |
| 1523 | 1564 | $var = $out[count($out)-1]; |
| 1524 | 1565 | $pointer += $len; |
@@ -1594,7 +1635,9 @@ discard block |
||
| 1594 | 1635 | $cmdstr = $match[1]; |
| 1595 | 1636 | } |
| 1596 | 1637 | |
| 1597 | - if ($this->debug) echo 'FUNC FOUND ('.$func.')' . "\n"; |
|
| 1638 | + if ($this->debug) { |
|
| 1639 | + echo 'FUNC FOUND ('.$func.')' . "\n"; |
|
| 1640 | + } |
|
| 1598 | 1641 | |
| 1599 | 1642 | $paramsep = ''; |
| 1600 | 1643 | |
@@ -1656,17 +1699,25 @@ discard block |
||
| 1656 | 1699 | } |
| 1657 | 1700 | |
| 1658 | 1701 | if ($func !== 'if' && $func !== 'elseif' && $paramstr[$ptr] === ')') { |
| 1659 | - if ($this->debug) echo 'PARAM PARSING ENDED, ")" FOUND, POINTER AT '.$ptr . "\n"; |
|
| 1702 | + if ($this->debug) { |
|
| 1703 | + echo 'PARAM PARSING ENDED, ")" FOUND, POINTER AT '.$ptr . "\n"; |
|
| 1704 | + } |
|
| 1660 | 1705 | break 2; |
| 1661 | 1706 | } elseif ($paramstr[$ptr] === ';') { |
| 1662 | 1707 | $ptr++; |
| 1663 | - if ($this->debug) echo 'PARAM PARSING ENDED, ";" FOUND, POINTER AT '.$ptr . "\n"; |
|
| 1708 | + if ($this->debug) { |
|
| 1709 | + echo 'PARAM PARSING ENDED, ";" FOUND, POINTER AT '.$ptr . "\n"; |
|
| 1710 | + } |
|
| 1664 | 1711 | break 2; |
| 1665 | 1712 | } elseif ($func !== 'if' && $func !== 'elseif' && $paramstr[$ptr] === '/') { |
| 1666 | - if ($this->debug) echo 'PARAM PARSING ENDED, "/" FOUND, POINTER AT '.$ptr . "\n"; |
|
| 1713 | + if ($this->debug) { |
|
| 1714 | + echo 'PARAM PARSING ENDED, "/" FOUND, POINTER AT '.$ptr . "\n"; |
|
| 1715 | + } |
|
| 1667 | 1716 | break 2; |
| 1668 | 1717 | } elseif (substr($paramstr, $ptr, strlen($this->rd)) === $this->rd) { |
| 1669 | - if ($this->debug) echo 'PARAM PARSING ENDED, RIGHT DELIMITER FOUND, POINTER AT '.$ptr . "\n"; |
|
| 1718 | + if ($this->debug) { |
|
| 1719 | + echo 'PARAM PARSING ENDED, RIGHT DELIMITER FOUND, POINTER AT '.$ptr . "\n"; |
|
| 1720 | + } |
|
| 1670 | 1721 | break 2; |
| 1671 | 1722 | } |
| 1672 | 1723 | |
@@ -1677,7 +1728,9 @@ discard block |
||
| 1677 | 1728 | } |
| 1678 | 1729 | } |
| 1679 | 1730 | |
| 1680 | - if ($this->debug) echo 'FUNC START PARAM PARSING WITH POINTER AT '.$ptr . "\n"; |
|
| 1731 | + if ($this->debug) { |
|
| 1732 | + echo 'FUNC START PARAM PARSING WITH POINTER AT '.$ptr . "\n"; |
|
| 1733 | + } |
|
| 1681 | 1734 | |
| 1682 | 1735 | if ($func === 'if' || $func === 'elseif' || $func === 'tif') { |
| 1683 | 1736 | $params = $this->parse($paramstr, $ptr, strlen($paramstr), $params, 'condition', $ptr); |
@@ -1687,7 +1740,9 @@ discard block |
||
| 1687 | 1740 | $params = $this->parse($paramstr, $ptr, strlen($paramstr), $params, 'function', $ptr); |
| 1688 | 1741 | } |
| 1689 | 1742 | |
| 1690 | - if ($this->debug) echo 'PARAM PARSED, POINTER AT '.$ptr.' ('.substr($paramstr, $ptr-1, 3).')' . "\n"; |
|
| 1743 | + if ($this->debug) { |
|
| 1744 | + echo 'PARAM PARSED, POINTER AT '.$ptr.' ('.substr($paramstr, $ptr-1, 3).')' . "\n"; |
|
| 1745 | + } |
|
| 1691 | 1746 | } |
| 1692 | 1747 | } |
| 1693 | 1748 | $paramstr = substr($paramstr, 0, $ptr); |
@@ -1711,7 +1766,9 @@ discard block |
||
| 1711 | 1766 | |
| 1712 | 1767 | if ($pointer !== null) { |
| 1713 | 1768 | $pointer += (isset($paramstr) ? strlen($paramstr) : 0) + (')' === $paramsep ? 2 : ($paramspos === false ? 0 : 1)) + strlen($func) + (isset($whitespace) ? $whitespace : 0); |
| 1714 | - if ($this->debug) echo 'FUNC ADDS '.((isset($paramstr) ? strlen($paramstr) : 0) + (')' === $paramsep ? 2 : ($paramspos === false ? 0 : 1)) + strlen($func)).' TO POINTER' . "\n"; |
|
| 1769 | + if ($this->debug) { |
|
| 1770 | + echo 'FUNC ADDS '.((isset($paramstr) ? strlen($paramstr) : 0) + (')' === $paramsep ? 2 : ($paramspos === false ? 0 : 1)) + strlen($func)).' TO POINTER' . "\n"; |
|
| 1771 | + } |
|
| 1715 | 1772 | } |
| 1716 | 1773 | |
| 1717 | 1774 | if ($curBlock === 'method' || $func === 'do' || strstr($func, '::') !== false) { |
@@ -1836,8 +1893,7 @@ discard block |
||
| 1836 | 1893 | if ($callback instanceof \Closure) { |
| 1837 | 1894 | array_unshift($params, $this->getDwoo()); |
| 1838 | 1895 | $output = call_user_func_array($callback, $params); |
| 1839 | - } |
|
| 1840 | - else { |
|
| 1896 | + } else { |
|
| 1841 | 1897 | array_unshift($params, '$this'); |
| 1842 | 1898 | $params = self::implode_r($params); |
| 1843 | 1899 | $output = 'call_user_func(\'' . $callback . '\', ' . $params . ')'; |
@@ -1952,7 +2008,9 @@ discard block |
||
| 1952 | 2008 | $substr = substr($in, $from, $to-$from); |
| 1953 | 2009 | $first = $substr[0]; |
| 1954 | 2010 | |
| 1955 | - if ($this->debug) echo 'STRING FOUND (in '.htmlentities(substr($in, $from, min($to-$from, 50))).(($to-$from) > 50 ? '...':'').')' . "\n"; |
|
| 2011 | + if ($this->debug) { |
|
| 2012 | + echo 'STRING FOUND (in '.htmlentities(substr($in, $from, min($to-$from, 50))).(($to-$from) > 50 ? '...':'').')' . "\n"; |
|
| 2013 | + } |
|
| 1956 | 2014 | $strend = false; |
| 1957 | 2015 | $o = $from+1; |
| 1958 | 2016 | while ($strend === false) { |
@@ -1965,7 +2023,9 @@ discard block |
||
| 1965 | 2023 | $strend = false; |
| 1966 | 2024 | } |
| 1967 | 2025 | } |
| 1968 | - if ($this->debug) echo 'STRING DELIMITED: '.substr($in, $from, $strend+1-$from) . "\n"; |
|
| 2026 | + if ($this->debug) { |
|
| 2027 | + echo 'STRING DELIMITED: '.substr($in, $from, $strend+1-$from) . "\n"; |
|
| 2028 | + } |
|
| 1969 | 2029 | |
| 1970 | 2030 | $srcOutput = substr($in, $from, $strend+1-$from); |
| 1971 | 2031 | |
@@ -2171,11 +2231,15 @@ discard block |
||
| 2171 | 2231 | } |
| 2172 | 2232 | unset($uid, $current, $curTxt, $tree, $chars); |
| 2173 | 2233 | |
| 2174 | - if ($this->debug) echo 'RECURSIVE VAR REPLACEMENT : '.$key . "\n"; |
|
| 2234 | + if ($this->debug) { |
|
| 2235 | + echo 'RECURSIVE VAR REPLACEMENT : '.$key . "\n"; |
|
| 2236 | + } |
|
| 2175 | 2237 | |
| 2176 | 2238 | $key = $this->flattenVarTree($parsed); |
| 2177 | 2239 | |
| 2178 | - if ($this->debug) echo 'RECURSIVE VAR REPLACEMENT DONE : '.$key . "\n"; |
|
| 2240 | + if ($this->debug) { |
|
| 2241 | + echo 'RECURSIVE VAR REPLACEMENT DONE : '.$key . "\n"; |
|
| 2242 | + } |
|
| 2179 | 2243 | |
| 2180 | 2244 | $output = preg_replace('#(^""\.|""\.|\.""$|(\()""\.|\.""(\)))#', '$2$3', '$this->readVar("'.$key.'")'); |
| 2181 | 2245 | } else { |
@@ -2355,8 +2419,9 @@ discard block |
||
| 2355 | 2419 | $global = 'COOKIE'; |
| 2356 | 2420 | } |
| 2357 | 2421 | $key = '$_'.$global; |
| 2358 | - foreach (explode('.', ltrim($m[2], '.')) as $part) |
|
| 2359 | - $key .= '['.var_export($part, true).']'; |
|
| 2422 | + foreach (explode('.', ltrim($m[2], '.')) as $part) { |
|
| 2423 | + $key .= '['.var_export($part, true).']'; |
|
| 2424 | + } |
|
| 2360 | 2425 | if ($curBlock === 'root') { |
| 2361 | 2426 | $output = $key; |
| 2362 | 2427 | } else { |
@@ -2466,7 +2531,9 @@ discard block |
||
| 2466 | 2531 | } else { |
| 2467 | 2532 | $cnt = substr_count($key, '$'); |
| 2468 | 2533 | |
| 2469 | - if ($this->debug) echo 'PARSING SUBVARS IN : '.$key . "\n"; |
|
| 2534 | + if ($this->debug) { |
|
| 2535 | + echo 'PARSING SUBVARS IN : '.$key . "\n"; |
|
| 2536 | + } |
|
| 2470 | 2537 | if ($cnt > 0) { |
| 2471 | 2538 | while (--$cnt >= 0) { |
| 2472 | 2539 | if (isset($last)) { |
@@ -2488,7 +2555,9 @@ discard block |
||
| 2488 | 2555 | $last, |
| 2489 | 2556 | $len |
| 2490 | 2557 | ); |
| 2491 | - if ($this->debug) echo 'RECURSIVE VAR REPLACEMENT DONE : '.$key . "\n"; |
|
| 2558 | + if ($this->debug) { |
|
| 2559 | + echo 'RECURSIVE VAR REPLACEMENT DONE : '.$key . "\n"; |
|
| 2560 | + } |
|
| 2492 | 2561 | } |
| 2493 | 2562 | unset($last); |
| 2494 | 2563 | |
@@ -2569,15 +2638,21 @@ discard block |
||
| 2569 | 2638 | $substr = trim($substr); |
| 2570 | 2639 | |
| 2571 | 2640 | if (strtolower($substr) === 'false' || strtolower($substr) === 'no' || strtolower($substr) === 'off') { |
| 2572 | - if ($this->debug) echo 'BOOLEAN(FALSE) PARSED' . "\n"; |
|
| 2641 | + if ($this->debug) { |
|
| 2642 | + echo 'BOOLEAN(FALSE) PARSED' . "\n"; |
|
| 2643 | + } |
|
| 2573 | 2644 | $substr = 'false'; |
| 2574 | 2645 | $type = self::T_BOOL; |
| 2575 | 2646 | } elseif (strtolower($substr) === 'true' || strtolower($substr) === 'yes' || strtolower($substr) === 'on') { |
| 2576 | - if ($this->debug) echo 'BOOLEAN(TRUE) PARSED' . "\n"; |
|
| 2647 | + if ($this->debug) { |
|
| 2648 | + echo 'BOOLEAN(TRUE) PARSED' . "\n"; |
|
| 2649 | + } |
|
| 2577 | 2650 | $substr = 'true'; |
| 2578 | 2651 | $type = self::T_BOOL; |
| 2579 | 2652 | } elseif ($substr === 'null' || $substr === 'NULL') { |
| 2580 | - if ($this->debug) echo 'NULL PARSED' . "\n"; |
|
| 2653 | + if ($this->debug) { |
|
| 2654 | + echo 'NULL PARSED' . "\n"; |
|
| 2655 | + } |
|
| 2581 | 2656 | $substr = 'null'; |
| 2582 | 2657 | $type = self::T_NULL; |
| 2583 | 2658 | } elseif (is_numeric($substr)) { |
@@ -2586,19 +2661,27 @@ discard block |
||
| 2586 | 2661 | $substr = (int) $substr; |
| 2587 | 2662 | } |
| 2588 | 2663 | $type = self::T_NUMERIC; |
| 2589 | - if ($this->debug) echo 'NUMBER ('.$substr.') PARSED' . "\n"; |
|
| 2664 | + if ($this->debug) { |
|
| 2665 | + echo 'NUMBER ('.$substr.') PARSED' . "\n"; |
|
| 2666 | + } |
|
| 2590 | 2667 | } elseif (preg_match('{^-?(\d+|\d*(\.\d+))\s*([/*%+-]\s*-?(\d+|\d*(\.\d+)))+$}', $substr)) { |
| 2591 | - if ($this->debug) echo 'SIMPLE MATH PARSED . "\n"'; |
|
| 2668 | + if ($this->debug) { |
|
| 2669 | + echo 'SIMPLE MATH PARSED . "\n"'; |
|
| 2670 | + } |
|
| 2592 | 2671 | $type = self::T_MATH; |
| 2593 | 2672 | $substr = '('.$substr.')'; |
| 2594 | 2673 | } elseif ($curBlock === 'condition' && array_search($substr, $breakChars, true) !== false) { |
| 2595 | - if ($this->debug) echo 'BREAKCHAR ('.$substr.') PARSED' . "\n"; |
|
| 2674 | + if ($this->debug) { |
|
| 2675 | + echo 'BREAKCHAR ('.$substr.') PARSED' . "\n"; |
|
| 2676 | + } |
|
| 2596 | 2677 | $type = self::T_BREAKCHAR; |
| 2597 | 2678 | //$substr = '"'.$substr.'"'; |
| 2598 | 2679 | } else { |
| 2599 | 2680 | $substr = $this->replaceStringVars('\''.str_replace('\'', '\\\'', $substr).'\'', '\'', $curBlock); |
| 2600 | 2681 | $type = self::T_UNQUOTED_STRING; |
| 2601 | - if ($this->debug) echo 'BLABBER ('.$substr.') CASTED AS STRING' . "\n"; |
|
| 2682 | + if ($this->debug) { |
|
| 2683 | + echo 'BLABBER ('.$substr.') CASTED AS STRING' . "\n"; |
|
| 2684 | + } |
|
| 2602 | 2685 | } |
| 2603 | 2686 | |
| 2604 | 2687 | if (is_array($parsingParams)) { |
@@ -2624,7 +2707,9 @@ discard block |
||
| 2624 | 2707 | protected function replaceStringVars($string, $first, $curBlock='') |
| 2625 | 2708 | { |
| 2626 | 2709 | $pos = 0; |
| 2627 | - if ($this->debug) echo 'STRING VAR REPLACEMENT : '.$string . "\n"; |
|
| 2710 | + if ($this->debug) { |
|
| 2711 | + echo 'STRING VAR REPLACEMENT : '.$string . "\n"; |
|
| 2712 | + } |
|
| 2628 | 2713 | // replace vars |
| 2629 | 2714 | while (($pos = strpos($string, '$', $pos)) !== false) { |
| 2630 | 2715 | $prev = substr($string, $pos-1, 1); |
@@ -2643,7 +2728,9 @@ discard block |
||
| 2643 | 2728 | $string = substr_replace($string, $first.'.'.$var[1].'.'.$first, $pos, $len); |
| 2644 | 2729 | } |
| 2645 | 2730 | $pos += strlen($var[1]) + 2; |
| 2646 | - if ($this->debug) echo 'STRING VAR REPLACEMENT DONE : '.$string . "\n"; |
|
| 2731 | + if ($this->debug) { |
|
| 2732 | + echo 'STRING VAR REPLACEMENT DONE : '.$string . "\n"; |
|
| 2733 | + } |
|
| 2647 | 2734 | } |
| 2648 | 2735 | |
| 2649 | 2736 | // handle modifiers |
@@ -2669,7 +2756,9 @@ discard block |
||
| 2669 | 2756 | */ |
| 2670 | 2757 | protected function replaceModifiers(array $m, $curBlock = null, &$pointer = null) |
| 2671 | 2758 | { |
| 2672 | - if ($this->debug) echo 'PARSING MODIFIERS : '.$m[3] . "\n"; |
|
| 2759 | + if ($this->debug) { |
|
| 2760 | + echo 'PARSING MODIFIERS : '.$m[3] . "\n"; |
|
| 2761 | + } |
|
| 2673 | 2762 | |
| 2674 | 2763 | if ($pointer !== null) { |
| 2675 | 2764 | $pointer += strlen($m[3]); |
@@ -2691,7 +2780,9 @@ discard block |
||
| 2691 | 2780 | continue; |
| 2692 | 2781 | } |
| 2693 | 2782 | if ($cmdstrsrc[0] === ' ' || $cmdstrsrc[0] === ';' || substr($cmdstrsrc, 0, strlen($this->rd)) === $this->rd) { |
| 2694 | - if ($this->debug) echo 'MODIFIER PARSING ENDED, RIGHT DELIMITER or ";" FOUND' . "\n"; |
|
| 2783 | + if ($this->debug) { |
|
| 2784 | + echo 'MODIFIER PARSING ENDED, RIGHT DELIMITER or ";" FOUND' . "\n"; |
|
| 2785 | + } |
|
| 2695 | 2786 | $continue = false; |
| 2696 | 2787 | if ($pointer !== null) { |
| 2697 | 2788 | $pointer -= strlen($cmdstrsrc); |
@@ -2710,7 +2801,9 @@ discard block |
||
| 2710 | 2801 | if ($paramspos === false) { |
| 2711 | 2802 | $cmdstrsrc = substr($cmdstrsrc, strlen($func)); |
| 2712 | 2803 | $params = array(); |
| 2713 | - if ($this->debug) echo 'MODIFIER ('.$func.') CALLED WITH NO PARAMS' . "\n"; |
|
| 2804 | + if ($this->debug) { |
|
| 2805 | + echo 'MODIFIER ('.$func.') CALLED WITH NO PARAMS' . "\n"; |
|
| 2806 | + } |
|
| 2714 | 2807 | } else { |
| 2715 | 2808 | $paramstr = substr($cmdstr, $paramspos+1); |
| 2716 | 2809 | if (substr($paramstr, -1, 1) === $paramsep) { |
@@ -2720,18 +2813,28 @@ discard block |
||
| 2720 | 2813 | $ptr = 0; |
| 2721 | 2814 | $params = array(); |
| 2722 | 2815 | while ($ptr < strlen($paramstr)) { |
| 2723 | - if ($this->debug) echo 'MODIFIER ('.$func.') START PARAM PARSING WITH POINTER AT '.$ptr . "\n"; |
|
| 2724 | - if ($this->debug) echo $paramstr.'--'.$ptr.'--'.strlen($paramstr).'--modifier' . "\n"; |
|
| 2816 | + if ($this->debug) { |
|
| 2817 | + echo 'MODIFIER ('.$func.') START PARAM PARSING WITH POINTER AT '.$ptr . "\n"; |
|
| 2818 | + } |
|
| 2819 | + if ($this->debug) { |
|
| 2820 | + echo $paramstr.'--'.$ptr.'--'.strlen($paramstr).'--modifier' . "\n"; |
|
| 2821 | + } |
|
| 2725 | 2822 | $params = $this->parse($paramstr, $ptr, strlen($paramstr), $params, 'modifier', $ptr); |
| 2726 | - if ($this->debug) echo 'PARAM PARSED, POINTER AT '.$ptr . "\n"; |
|
| 2823 | + if ($this->debug) { |
|
| 2824 | + echo 'PARAM PARSED, POINTER AT '.$ptr . "\n"; |
|
| 2825 | + } |
|
| 2727 | 2826 | |
| 2728 | 2827 | if ($ptr >= strlen($paramstr)) { |
| 2729 | - if ($this->debug) echo 'PARAM PARSING ENDED, PARAM STRING CONSUMED' . "\n"; |
|
| 2828 | + if ($this->debug) { |
|
| 2829 | + echo 'PARAM PARSING ENDED, PARAM STRING CONSUMED' . "\n"; |
|
| 2830 | + } |
|
| 2730 | 2831 | break; |
| 2731 | 2832 | } |
| 2732 | 2833 | |
| 2733 | 2834 | if ($paramstr[$ptr] === ' ' || $paramstr[$ptr] === '|' || $paramstr[$ptr] === ';' || substr($paramstr, $ptr, strlen($this->rd)) === $this->rd) { |
| 2734 | - if ($this->debug) echo 'PARAM PARSING ENDED, " ", "|", RIGHT DELIMITER or ";" FOUND, POINTER AT '.$ptr . "\n"; |
|
| 2835 | + if ($this->debug) { |
|
| 2836 | + echo 'PARAM PARSING ENDED, " ", "|", RIGHT DELIMITER or ";" FOUND, POINTER AT '.$ptr . "\n"; |
|
| 2837 | + } |
|
| 2735 | 2838 | if ($paramstr[$ptr] !== '|') { |
| 2736 | 2839 | $continue = false; |
| 2737 | 2840 | if ($pointer !== null) { |
@@ -2792,8 +2895,9 @@ discard block |
||
| 2792 | 2895 | } |
| 2793 | 2896 | } elseif ($pluginType & Dwoo_Core::PROXY_PLUGIN) { |
| 2794 | 2897 | $params = $this->mapParams($params, $this->getDwoo()->getPluginProxy()->getCallback($func), $state); |
| 2795 | - foreach ($params as &$p) |
|
| 2796 | - $p = $p[0]; |
|
| 2898 | + foreach ($params as &$p) { |
|
| 2899 | + $p = $p[0]; |
|
| 2900 | + } |
|
| 2797 | 2901 | $output = call_user_func(array($this->dwoo->getPluginProxy(), 'getCode'), $func, $params); |
| 2798 | 2902 | } elseif ($pluginType & Dwoo_Core::SMARTY_MODIFIER) { |
| 2799 | 2903 | $params = $this->mapParams($params, null, $state); |
@@ -2835,8 +2939,9 @@ discard block |
||
| 2835 | 2939 | |
| 2836 | 2940 | $params = $this->mapParams($params, $callback, $state); |
| 2837 | 2941 | |
| 2838 | - foreach ($params as &$p) |
|
| 2839 | - $p = $p[0]; |
|
| 2942 | + foreach ($params as &$p) { |
|
| 2943 | + $p = $p[0]; |
|
| 2944 | + } |
|
| 2840 | 2945 | |
| 2841 | 2946 | if ($pluginType & Dwoo_Core::FUNC_PLUGIN) { |
| 2842 | 2947 | if ($pluginType & Dwoo_Core::COMPILABLE_PLUGIN) { |
@@ -2929,8 +3034,9 @@ discard block |
||
| 2929 | 3034 | foreach ($params as $k=>$p) { |
| 2930 | 3035 | if (is_array($p)) { |
| 2931 | 3036 | $out2 = 'array('; |
| 2932 | - foreach ($p as $k2=>$v) |
|
| 2933 | - $out2 .= var_export($k2, true).' => '.(is_array($v) ? 'array('.self::implode_r($v, true).')' : $v).', '; |
|
| 3037 | + foreach ($p as $k2=>$v) { |
|
| 3038 | + $out2 .= var_export($k2, true).' => '.(is_array($v) ? 'array('.self::implode_r($v, true).')' : $v).', '; |
|
| 3039 | + } |
|
| 2934 | 3040 | $p = rtrim($out2, ', ').')'; |
| 2935 | 3041 | } |
| 2936 | 3042 | if ($recursiveCall) { |