@@ -47,53 +47,53 @@ |
||
47 | 47 | */ |
48 | 48 | class PluginWith extends BlockPlugin implements ICompilableBlock, IElseable |
49 | 49 | { |
50 | - protected static $cnt = 0; |
|
50 | + protected static $cnt = 0; |
|
51 | 51 | |
52 | - /** |
|
53 | - * @param $var |
|
54 | - */ |
|
55 | - public function init($var) |
|
56 | - { |
|
57 | - } |
|
52 | + /** |
|
53 | + * @param $var |
|
54 | + */ |
|
55 | + public function init($var) |
|
56 | + { |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @param Compiler $compiler |
|
61 | - * @param array $params |
|
62 | - * @param string $prepend |
|
63 | - * @param string $append |
|
64 | - * @param string $type |
|
65 | - * |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
69 | - { |
|
70 | - return ''; |
|
71 | - } |
|
59 | + /** |
|
60 | + * @param Compiler $compiler |
|
61 | + * @param array $params |
|
62 | + * @param string $prepend |
|
63 | + * @param string $append |
|
64 | + * @param string $type |
|
65 | + * |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
69 | + { |
|
70 | + return ''; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * @param Compiler $compiler |
|
75 | - * @param array $params |
|
76 | - * @param string $prepend |
|
77 | - * @param string $append |
|
78 | - * @param string $content |
|
79 | - * |
|
80 | - * @return string |
|
81 | - */ |
|
82 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
83 | - { |
|
84 | - $rparams = $compiler->getRealParams($params); |
|
85 | - $cparams = $compiler->getCompiledParams($params); |
|
73 | + /** |
|
74 | + * @param Compiler $compiler |
|
75 | + * @param array $params |
|
76 | + * @param string $prepend |
|
77 | + * @param string $append |
|
78 | + * @param string $content |
|
79 | + * |
|
80 | + * @return string |
|
81 | + */ |
|
82 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
83 | + { |
|
84 | + $rparams = $compiler->getRealParams($params); |
|
85 | + $cparams = $compiler->getCompiledParams($params); |
|
86 | 86 | |
87 | - $compiler->setScope($rparams['var']); |
|
87 | + $compiler->setScope($rparams['var']); |
|
88 | 88 | |
89 | - $pre = Compiler::PHP_OPEN . 'if (' . $cparams['var'] . ')' . "\n{\n" . '$_with' . (self::$cnt) . ' = $this->setScope("' . $rparams['var'] . '");' . "\n/* -- start with output */\n" . Compiler::PHP_CLOSE; |
|
89 | + $pre = Compiler::PHP_OPEN . 'if (' . $cparams['var'] . ')' . "\n{\n" . '$_with' . (self::$cnt) . ' = $this->setScope("' . $rparams['var'] . '");' . "\n/* -- start with output */\n" . Compiler::PHP_CLOSE; |
|
90 | 90 | |
91 | - $post = Compiler::PHP_OPEN . "\n/* -- end with output */\n" . '$this->setScope($_with' . (self::$cnt ++) . ', true);' . "\n}\n" . Compiler::PHP_CLOSE; |
|
91 | + $post = Compiler::PHP_OPEN . "\n/* -- end with output */\n" . '$this->setScope($_with' . (self::$cnt ++) . ', true);' . "\n}\n" . Compiler::PHP_CLOSE; |
|
92 | 92 | |
93 | - if (isset($params['hasElse'])) { |
|
94 | - $post .= $params['hasElse']; |
|
95 | - } |
|
93 | + if (isset($params['hasElse'])) { |
|
94 | + $post .= $params['hasElse']; |
|
95 | + } |
|
96 | 96 | |
97 | - return $pre . $content . $post; |
|
98 | - } |
|
97 | + return $pre . $content . $post; |
|
98 | + } |
|
99 | 99 | } |
@@ -86,14 +86,14 @@ |
||
86 | 86 | |
87 | 87 | $compiler->setScope($rparams['var']); |
88 | 88 | |
89 | - $pre = Compiler::PHP_OPEN . 'if (' . $cparams['var'] . ')' . "\n{\n" . '$_with' . (self::$cnt) . ' = $this->setScope("' . $rparams['var'] . '");' . "\n/* -- start with output */\n" . Compiler::PHP_CLOSE; |
|
89 | + $pre = Compiler::PHP_OPEN.'if ('.$cparams['var'].')'."\n{\n".'$_with'.(self::$cnt).' = $this->setScope("'.$rparams['var'].'");'."\n/* -- start with output */\n".Compiler::PHP_CLOSE; |
|
90 | 90 | |
91 | - $post = Compiler::PHP_OPEN . "\n/* -- end with output */\n" . '$this->setScope($_with' . (self::$cnt ++) . ', true);' . "\n}\n" . Compiler::PHP_CLOSE; |
|
91 | + $post = Compiler::PHP_OPEN."\n/* -- end with output */\n".'$this->setScope($_with'.(self::$cnt++).', true);'."\n}\n".Compiler::PHP_CLOSE; |
|
92 | 92 | |
93 | 93 | if (isset($params['hasElse'])) { |
94 | 94 | $post .= $params['hasElse']; |
95 | 95 | } |
96 | 96 | |
97 | - return $pre . $content . $post; |
|
97 | + return $pre.$content.$post; |
|
98 | 98 | } |
99 | 99 | } |
@@ -39,57 +39,57 @@ |
||
39 | 39 | */ |
40 | 40 | class PluginA extends BlockPlugin implements ICompilableBlock |
41 | 41 | { |
42 | - /** |
|
43 | - * @param $href |
|
44 | - * @param array $rest |
|
45 | - */ |
|
46 | - public function init($href, array $rest = array()) |
|
47 | - { |
|
48 | - } |
|
42 | + /** |
|
43 | + * @param $href |
|
44 | + * @param array $rest |
|
45 | + */ |
|
46 | + public function init($href, array $rest = array()) |
|
47 | + { |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @param Compiler $compiler |
|
52 | - * @param array $params |
|
53 | - * @param string $prepend |
|
54 | - * @param string $append |
|
55 | - * @param string $type |
|
56 | - * |
|
57 | - * @return string |
|
58 | - */ |
|
59 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
60 | - { |
|
61 | - $p = $compiler->getCompiledParams($params); |
|
50 | + /** |
|
51 | + * @param Compiler $compiler |
|
52 | + * @param array $params |
|
53 | + * @param string $prepend |
|
54 | + * @param string $append |
|
55 | + * @param string $type |
|
56 | + * |
|
57 | + * @return string |
|
58 | + */ |
|
59 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
60 | + { |
|
61 | + $p = $compiler->getCompiledParams($params); |
|
62 | 62 | |
63 | - $out = Compiler::PHP_OPEN . 'echo \'<a ' . self::paramsToAttributes($p, "'", $compiler); |
|
63 | + $out = Compiler::PHP_OPEN . 'echo \'<a ' . self::paramsToAttributes($p, "'", $compiler); |
|
64 | 64 | |
65 | - return $out . '>\';' . Compiler::PHP_CLOSE; |
|
66 | - } |
|
65 | + return $out . '>\';' . Compiler::PHP_CLOSE; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @param Compiler $compiler |
|
70 | - * @param array $params |
|
71 | - * @param string $prepend |
|
72 | - * @param string $append |
|
73 | - * @param string $content |
|
74 | - * |
|
75 | - * @return string |
|
76 | - */ |
|
77 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
78 | - { |
|
79 | - $p = $compiler->getCompiledParams($params); |
|
68 | + /** |
|
69 | + * @param Compiler $compiler |
|
70 | + * @param array $params |
|
71 | + * @param string $prepend |
|
72 | + * @param string $append |
|
73 | + * @param string $content |
|
74 | + * |
|
75 | + * @return string |
|
76 | + */ |
|
77 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
78 | + { |
|
79 | + $p = $compiler->getCompiledParams($params); |
|
80 | 80 | |
81 | - // no content was provided so use the url as display text |
|
82 | - if ($content == '') { |
|
83 | - // merge </a> into the href if href is a string |
|
84 | - if (substr($p['href'], - 1) === '"' || substr($p['href'], - 1) === '\'') { |
|
85 | - return Compiler::PHP_OPEN . 'echo ' . substr($p['href'], 0, - 1) . '</a>' . substr($p['href'], - 1) . ';' . Compiler::PHP_CLOSE; |
|
86 | - } |
|
81 | + // no content was provided so use the url as display text |
|
82 | + if ($content == '') { |
|
83 | + // merge </a> into the href if href is a string |
|
84 | + if (substr($p['href'], - 1) === '"' || substr($p['href'], - 1) === '\'') { |
|
85 | + return Compiler::PHP_OPEN . 'echo ' . substr($p['href'], 0, - 1) . '</a>' . substr($p['href'], - 1) . ';' . Compiler::PHP_CLOSE; |
|
86 | + } |
|
87 | 87 | |
88 | - // otherwise append |
|
89 | - return Compiler::PHP_OPEN . 'echo ' . $p['href'] . '.\'</a>\';' . Compiler::PHP_CLOSE; |
|
90 | - } |
|
88 | + // otherwise append |
|
89 | + return Compiler::PHP_OPEN . 'echo ' . $p['href'] . '.\'</a>\';' . Compiler::PHP_CLOSE; |
|
90 | + } |
|
91 | 91 | |
92 | - // return content |
|
93 | - return $content . '</a>'; |
|
94 | - } |
|
92 | + // return content |
|
93 | + return $content . '</a>'; |
|
94 | + } |
|
95 | 95 | } |
@@ -60,9 +60,9 @@ discard block |
||
60 | 60 | { |
61 | 61 | $p = $compiler->getCompiledParams($params); |
62 | 62 | |
63 | - $out = Compiler::PHP_OPEN . 'echo \'<a ' . self::paramsToAttributes($p, "'", $compiler); |
|
63 | + $out = Compiler::PHP_OPEN.'echo \'<a '.self::paramsToAttributes($p, "'", $compiler); |
|
64 | 64 | |
65 | - return $out . '>\';' . Compiler::PHP_CLOSE; |
|
65 | + return $out.'>\';'.Compiler::PHP_CLOSE; |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -82,14 +82,14 @@ discard block |
||
82 | 82 | if ($content == '') { |
83 | 83 | // merge </a> into the href if href is a string |
84 | 84 | if (substr($p['href'], - 1) === '"' || substr($p['href'], - 1) === '\'') { |
85 | - return Compiler::PHP_OPEN . 'echo ' . substr($p['href'], 0, - 1) . '</a>' . substr($p['href'], - 1) . ';' . Compiler::PHP_CLOSE; |
|
85 | + return Compiler::PHP_OPEN.'echo '.substr($p['href'], 0, - 1).'</a>'.substr($p['href'], - 1).';'.Compiler::PHP_CLOSE; |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | // otherwise append |
89 | - return Compiler::PHP_OPEN . 'echo ' . $p['href'] . '.\'</a>\';' . Compiler::PHP_CLOSE; |
|
89 | + return Compiler::PHP_OPEN.'echo '.$p['href'].'.\'</a>\';'.Compiler::PHP_CLOSE; |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | // return content |
93 | - return $content . '</a>'; |
|
93 | + return $content.'</a>'; |
|
94 | 94 | } |
95 | 95 | } |
@@ -27,47 +27,47 @@ |
||
27 | 27 | */ |
28 | 28 | class PluginForelse extends BlockPlugin implements ICompilableBlock |
29 | 29 | { |
30 | - public function init() |
|
31 | - { |
|
32 | - } |
|
30 | + public function init() |
|
31 | + { |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * @param Compiler $compiler |
|
36 | - * @param array $params |
|
37 | - * @param string $prepend |
|
38 | - * @param string $append |
|
39 | - * @param string $type |
|
40 | - * |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
44 | - { |
|
45 | - $with = &$compiler->findBlock('for', true); |
|
34 | + /** |
|
35 | + * @param Compiler $compiler |
|
36 | + * @param array $params |
|
37 | + * @param string $prepend |
|
38 | + * @param string $append |
|
39 | + * @param string $type |
|
40 | + * |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
44 | + { |
|
45 | + $with = &$compiler->findBlock('for', true); |
|
46 | 46 | |
47 | - $params['initialized'] = true; |
|
48 | - $compiler->injectBlock($type, $params); |
|
47 | + $params['initialized'] = true; |
|
48 | + $compiler->injectBlock($type, $params); |
|
49 | 49 | |
50 | - return ''; |
|
51 | - } |
|
50 | + return ''; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @param Compiler $compiler |
|
55 | - * @param array $params |
|
56 | - * @param string $prepend |
|
57 | - * @param string $append |
|
58 | - * @param string $content |
|
59 | - * |
|
60 | - * @return string |
|
61 | - */ |
|
62 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
63 | - { |
|
64 | - if (!isset($params['initialized'])) { |
|
65 | - return ''; |
|
66 | - } |
|
53 | + /** |
|
54 | + * @param Compiler $compiler |
|
55 | + * @param array $params |
|
56 | + * @param string $prepend |
|
57 | + * @param string $append |
|
58 | + * @param string $content |
|
59 | + * |
|
60 | + * @return string |
|
61 | + */ |
|
62 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
63 | + { |
|
64 | + if (!isset($params['initialized'])) { |
|
65 | + return ''; |
|
66 | + } |
|
67 | 67 | |
68 | - $block = &$compiler->getCurrentBlock(); |
|
69 | - $block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
68 | + $block = &$compiler->getCurrentBlock(); |
|
69 | + $block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
70 | 70 | |
71 | - return ''; |
|
72 | - } |
|
71 | + return ''; |
|
72 | + } |
|
73 | 73 | } |
@@ -66,7 +66,7 @@ |
||
66 | 66 | } |
67 | 67 | |
68 | 68 | $block = &$compiler->getCurrentBlock(); |
69 | - $block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
69 | + $block['params']['hasElse'] = Compiler::PHP_OPEN."else {\n".Compiler::PHP_CLOSE.$content.Compiler::PHP_OPEN."\n}".Compiler::PHP_CLOSE; |
|
70 | 70 | |
71 | 71 | return ''; |
72 | 72 | } |
@@ -48,123 +48,123 @@ |
||
48 | 48 | */ |
49 | 49 | class PluginLoop extends BlockPlugin implements ICompilableBlock, IElseable |
50 | 50 | { |
51 | - public static $cnt = 0; |
|
51 | + public static $cnt = 0; |
|
52 | 52 | |
53 | - /** |
|
54 | - * @param $from |
|
55 | - * @param string $name |
|
56 | - */ |
|
57 | - public function init($from, $name = 'default') |
|
58 | - { |
|
59 | - } |
|
53 | + /** |
|
54 | + * @param $from |
|
55 | + * @param string $name |
|
56 | + */ |
|
57 | + public function init($from, $name = 'default') |
|
58 | + { |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @param Compiler $compiler |
|
63 | - * @param array $params |
|
64 | - * @param string $prepend |
|
65 | - * @param string $append |
|
66 | - * @param string $type |
|
67 | - * |
|
68 | - * @return string |
|
69 | - */ |
|
70 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
71 | - { |
|
72 | - // get block params and save the current template pointer to use it in the postProcessing method |
|
73 | - $currentBlock = &$compiler->getCurrentBlock(); |
|
74 | - $currentBlock['params']['tplPointer'] = $compiler->getPointer(); |
|
61 | + /** |
|
62 | + * @param Compiler $compiler |
|
63 | + * @param array $params |
|
64 | + * @param string $prepend |
|
65 | + * @param string $append |
|
66 | + * @param string $type |
|
67 | + * |
|
68 | + * @return string |
|
69 | + */ |
|
70 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
71 | + { |
|
72 | + // get block params and save the current template pointer to use it in the postProcessing method |
|
73 | + $currentBlock = &$compiler->getCurrentBlock(); |
|
74 | + $currentBlock['params']['tplPointer'] = $compiler->getPointer(); |
|
75 | 75 | |
76 | - return ''; |
|
77 | - } |
|
76 | + return ''; |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @param Compiler $compiler |
|
81 | - * @param array $params |
|
82 | - * @param string $prepend |
|
83 | - * @param string $append |
|
84 | - * @param string $content |
|
85 | - * |
|
86 | - * @return string |
|
87 | - */ |
|
88 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
89 | - { |
|
90 | - $params = $compiler->getCompiledParams($params); |
|
91 | - $tpl = $compiler->getTemplateSource($params['tplPointer']); |
|
79 | + /** |
|
80 | + * @param Compiler $compiler |
|
81 | + * @param array $params |
|
82 | + * @param string $prepend |
|
83 | + * @param string $append |
|
84 | + * @param string $content |
|
85 | + * |
|
86 | + * @return string |
|
87 | + */ |
|
88 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
89 | + { |
|
90 | + $params = $compiler->getCompiledParams($params); |
|
91 | + $tpl = $compiler->getTemplateSource($params['tplPointer']); |
|
92 | 92 | |
93 | - // assigns params |
|
94 | - $src = $params['from']; |
|
95 | - $name = $params['name']; |
|
93 | + // assigns params |
|
94 | + $src = $params['from']; |
|
95 | + $name = $params['name']; |
|
96 | 96 | |
97 | - // evaluates which global variables have to be computed |
|
98 | - $varName = '$dwoo.loop.' . trim($name, '"\'') . '.'; |
|
99 | - $shortVarName = '$.loop.' . trim($name, '"\'') . '.'; |
|
100 | - $usesAny = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false; |
|
101 | - $usesFirst = strpos($tpl, $varName . 'first') !== false || strpos($tpl, $shortVarName . 'first') !== false; |
|
102 | - $usesLast = strpos($tpl, $varName . 'last') !== false || strpos($tpl, $shortVarName . 'last') !== false; |
|
103 | - $usesIndex = $usesFirst || strpos($tpl, $varName . 'index') !== false || strpos($tpl, $shortVarName . 'index') !== false; |
|
104 | - $usesIteration = $usesLast || strpos($tpl, $varName . 'iteration') !== false || strpos($tpl, $shortVarName . 'iteration') !== false; |
|
105 | - $usesShow = strpos($tpl, $varName . 'show') !== false || strpos($tpl, $shortVarName . 'show') !== false; |
|
106 | - $usesTotal = $usesLast || strpos($tpl, $varName . 'total') !== false || strpos($tpl, $shortVarName . 'total') !== false; |
|
97 | + // evaluates which global variables have to be computed |
|
98 | + $varName = '$dwoo.loop.' . trim($name, '"\'') . '.'; |
|
99 | + $shortVarName = '$.loop.' . trim($name, '"\'') . '.'; |
|
100 | + $usesAny = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false; |
|
101 | + $usesFirst = strpos($tpl, $varName . 'first') !== false || strpos($tpl, $shortVarName . 'first') !== false; |
|
102 | + $usesLast = strpos($tpl, $varName . 'last') !== false || strpos($tpl, $shortVarName . 'last') !== false; |
|
103 | + $usesIndex = $usesFirst || strpos($tpl, $varName . 'index') !== false || strpos($tpl, $shortVarName . 'index') !== false; |
|
104 | + $usesIteration = $usesLast || strpos($tpl, $varName . 'iteration') !== false || strpos($tpl, $shortVarName . 'iteration') !== false; |
|
105 | + $usesShow = strpos($tpl, $varName . 'show') !== false || strpos($tpl, $shortVarName . 'show') !== false; |
|
106 | + $usesTotal = $usesLast || strpos($tpl, $varName . 'total') !== false || strpos($tpl, $shortVarName . 'total') !== false; |
|
107 | 107 | |
108 | - if (strpos($name, '$this->scope[') !== false) { |
|
109 | - $usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true; |
|
110 | - } |
|
108 | + if (strpos($name, '$this->scope[') !== false) { |
|
109 | + $usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true; |
|
110 | + } |
|
111 | 111 | |
112 | - // gets foreach id |
|
113 | - $cnt = self::$cnt ++; |
|
112 | + // gets foreach id |
|
113 | + $cnt = self::$cnt ++; |
|
114 | 114 | |
115 | - // builds pre processing output |
|
116 | - $pre = Compiler::PHP_OPEN . "\n" . '$_loop' . $cnt . '_data = ' . $src . ';'; |
|
117 | - // adds foreach properties |
|
118 | - if ($usesAny) { |
|
119 | - $pre .= "\n" . '$this->globals["loop"][' . $name . '] = array' . "\n("; |
|
120 | - if ($usesIndex) { |
|
121 | - $pre .= "\n\t" . '"index" => 0,'; |
|
122 | - } |
|
123 | - if ($usesIteration) { |
|
124 | - $pre .= "\n\t" . '"iteration" => 1,'; |
|
125 | - } |
|
126 | - if ($usesFirst) { |
|
127 | - $pre .= "\n\t" . '"first" => null,'; |
|
128 | - } |
|
129 | - if ($usesLast) { |
|
130 | - $pre .= "\n\t" . '"last" => null,'; |
|
131 | - } |
|
132 | - if ($usesShow) { |
|
133 | - $pre .= "\n\t" . '"show" => $this->isTraversable($_loop' . $cnt . '_data, true),'; |
|
134 | - } |
|
135 | - if ($usesTotal) { |
|
136 | - $pre .= "\n\t" . '"total" => $this->count($_loop' . $cnt . '_data),'; |
|
137 | - } |
|
138 | - $pre .= "\n);\n" . '$_loop' . $cnt . '_glob =& $this->globals["loop"][' . $name . '];'; |
|
139 | - } |
|
140 | - // checks if the loop must be looped |
|
141 | - $pre .= "\n" . 'if ($this->isTraversable($_loop' . $cnt . '_data' . (isset($params['hasElse']) ? ', true' : '') . ') == true)' . "\n{"; |
|
142 | - // iterates over keys |
|
143 | - $pre .= "\n\t" . 'foreach ($_loop' . $cnt . '_data as $tmp_key => $this->scope["-loop-"])' . "\n\t{"; |
|
144 | - // updates properties |
|
145 | - if ($usesFirst) { |
|
146 | - $pre .= "\n\t\t" . '$_loop' . $cnt . '_glob["first"] = (string) ($_loop' . $cnt . '_glob["index"] === 0);'; |
|
147 | - } |
|
148 | - if ($usesLast) { |
|
149 | - $pre .= "\n\t\t" . '$_loop' . $cnt . '_glob["last"] = (string) ($_loop' . $cnt . '_glob["iteration"] === $_loop' . $cnt . '_glob["total"]);'; |
|
150 | - } |
|
151 | - $pre .= "\n\t\t" . '$_loop' . $cnt . '_scope = $this->setScope(array("-loop-"));' . "\n/* -- loop start output */\n" . Compiler::PHP_CLOSE; |
|
115 | + // builds pre processing output |
|
116 | + $pre = Compiler::PHP_OPEN . "\n" . '$_loop' . $cnt . '_data = ' . $src . ';'; |
|
117 | + // adds foreach properties |
|
118 | + if ($usesAny) { |
|
119 | + $pre .= "\n" . '$this->globals["loop"][' . $name . '] = array' . "\n("; |
|
120 | + if ($usesIndex) { |
|
121 | + $pre .= "\n\t" . '"index" => 0,'; |
|
122 | + } |
|
123 | + if ($usesIteration) { |
|
124 | + $pre .= "\n\t" . '"iteration" => 1,'; |
|
125 | + } |
|
126 | + if ($usesFirst) { |
|
127 | + $pre .= "\n\t" . '"first" => null,'; |
|
128 | + } |
|
129 | + if ($usesLast) { |
|
130 | + $pre .= "\n\t" . '"last" => null,'; |
|
131 | + } |
|
132 | + if ($usesShow) { |
|
133 | + $pre .= "\n\t" . '"show" => $this->isTraversable($_loop' . $cnt . '_data, true),'; |
|
134 | + } |
|
135 | + if ($usesTotal) { |
|
136 | + $pre .= "\n\t" . '"total" => $this->count($_loop' . $cnt . '_data),'; |
|
137 | + } |
|
138 | + $pre .= "\n);\n" . '$_loop' . $cnt . '_glob =& $this->globals["loop"][' . $name . '];'; |
|
139 | + } |
|
140 | + // checks if the loop must be looped |
|
141 | + $pre .= "\n" . 'if ($this->isTraversable($_loop' . $cnt . '_data' . (isset($params['hasElse']) ? ', true' : '') . ') == true)' . "\n{"; |
|
142 | + // iterates over keys |
|
143 | + $pre .= "\n\t" . 'foreach ($_loop' . $cnt . '_data as $tmp_key => $this->scope["-loop-"])' . "\n\t{"; |
|
144 | + // updates properties |
|
145 | + if ($usesFirst) { |
|
146 | + $pre .= "\n\t\t" . '$_loop' . $cnt . '_glob["first"] = (string) ($_loop' . $cnt . '_glob["index"] === 0);'; |
|
147 | + } |
|
148 | + if ($usesLast) { |
|
149 | + $pre .= "\n\t\t" . '$_loop' . $cnt . '_glob["last"] = (string) ($_loop' . $cnt . '_glob["iteration"] === $_loop' . $cnt . '_glob["total"]);'; |
|
150 | + } |
|
151 | + $pre .= "\n\t\t" . '$_loop' . $cnt . '_scope = $this->setScope(array("-loop-"));' . "\n/* -- loop start output */\n" . Compiler::PHP_CLOSE; |
|
152 | 152 | |
153 | - // build post processing output and cache it |
|
154 | - $post = Compiler::PHP_OPEN . "\n" . '/* -- loop end output */' . "\n\t\t" . '$this->setScope($_loop' . $cnt . '_scope, true);'; |
|
155 | - // update properties |
|
156 | - if ($usesIndex) { |
|
157 | - $post .= "\n\t\t" . '$_loop' . $cnt . '_glob["index"]+=1;'; |
|
158 | - } |
|
159 | - if ($usesIteration) { |
|
160 | - $post .= "\n\t\t" . '$_loop' . $cnt . '_glob["iteration"]+=1;'; |
|
161 | - } |
|
162 | - // end loop |
|
163 | - $post .= "\n\t}\n}\n" . Compiler::PHP_CLOSE; |
|
164 | - if (isset($params['hasElse'])) { |
|
165 | - $post .= $params['hasElse']; |
|
166 | - } |
|
153 | + // build post processing output and cache it |
|
154 | + $post = Compiler::PHP_OPEN . "\n" . '/* -- loop end output */' . "\n\t\t" . '$this->setScope($_loop' . $cnt . '_scope, true);'; |
|
155 | + // update properties |
|
156 | + if ($usesIndex) { |
|
157 | + $post .= "\n\t\t" . '$_loop' . $cnt . '_glob["index"]+=1;'; |
|
158 | + } |
|
159 | + if ($usesIteration) { |
|
160 | + $post .= "\n\t\t" . '$_loop' . $cnt . '_glob["iteration"]+=1;'; |
|
161 | + } |
|
162 | + // end loop |
|
163 | + $post .= "\n\t}\n}\n" . Compiler::PHP_CLOSE; |
|
164 | + if (isset($params['hasElse'])) { |
|
165 | + $post .= $params['hasElse']; |
|
166 | + } |
|
167 | 167 | |
168 | - return $pre . $content . $post; |
|
169 | - } |
|
168 | + return $pre . $content . $post; |
|
169 | + } |
|
170 | 170 | } |
@@ -95,76 +95,76 @@ |
||
95 | 95 | $name = $params['name']; |
96 | 96 | |
97 | 97 | // evaluates which global variables have to be computed |
98 | - $varName = '$dwoo.loop.' . trim($name, '"\'') . '.'; |
|
99 | - $shortVarName = '$.loop.' . trim($name, '"\'') . '.'; |
|
98 | + $varName = '$dwoo.loop.'.trim($name, '"\'').'.'; |
|
99 | + $shortVarName = '$.loop.'.trim($name, '"\'').'.'; |
|
100 | 100 | $usesAny = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false; |
101 | - $usesFirst = strpos($tpl, $varName . 'first') !== false || strpos($tpl, $shortVarName . 'first') !== false; |
|
102 | - $usesLast = strpos($tpl, $varName . 'last') !== false || strpos($tpl, $shortVarName . 'last') !== false; |
|
103 | - $usesIndex = $usesFirst || strpos($tpl, $varName . 'index') !== false || strpos($tpl, $shortVarName . 'index') !== false; |
|
104 | - $usesIteration = $usesLast || strpos($tpl, $varName . 'iteration') !== false || strpos($tpl, $shortVarName . 'iteration') !== false; |
|
105 | - $usesShow = strpos($tpl, $varName . 'show') !== false || strpos($tpl, $shortVarName . 'show') !== false; |
|
106 | - $usesTotal = $usesLast || strpos($tpl, $varName . 'total') !== false || strpos($tpl, $shortVarName . 'total') !== false; |
|
101 | + $usesFirst = strpos($tpl, $varName.'first') !== false || strpos($tpl, $shortVarName.'first') !== false; |
|
102 | + $usesLast = strpos($tpl, $varName.'last') !== false || strpos($tpl, $shortVarName.'last') !== false; |
|
103 | + $usesIndex = $usesFirst || strpos($tpl, $varName.'index') !== false || strpos($tpl, $shortVarName.'index') !== false; |
|
104 | + $usesIteration = $usesLast || strpos($tpl, $varName.'iteration') !== false || strpos($tpl, $shortVarName.'iteration') !== false; |
|
105 | + $usesShow = strpos($tpl, $varName.'show') !== false || strpos($tpl, $shortVarName.'show') !== false; |
|
106 | + $usesTotal = $usesLast || strpos($tpl, $varName.'total') !== false || strpos($tpl, $shortVarName.'total') !== false; |
|
107 | 107 | |
108 | 108 | if (strpos($name, '$this->scope[') !== false) { |
109 | 109 | $usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true; |
110 | 110 | } |
111 | 111 | |
112 | 112 | // gets foreach id |
113 | - $cnt = self::$cnt ++; |
|
113 | + $cnt = self::$cnt++; |
|
114 | 114 | |
115 | 115 | // builds pre processing output |
116 | - $pre = Compiler::PHP_OPEN . "\n" . '$_loop' . $cnt . '_data = ' . $src . ';'; |
|
116 | + $pre = Compiler::PHP_OPEN."\n".'$_loop'.$cnt.'_data = '.$src.';'; |
|
117 | 117 | // adds foreach properties |
118 | 118 | if ($usesAny) { |
119 | - $pre .= "\n" . '$this->globals["loop"][' . $name . '] = array' . "\n("; |
|
119 | + $pre .= "\n".'$this->globals["loop"]['.$name.'] = array'."\n("; |
|
120 | 120 | if ($usesIndex) { |
121 | - $pre .= "\n\t" . '"index" => 0,'; |
|
121 | + $pre .= "\n\t".'"index" => 0,'; |
|
122 | 122 | } |
123 | 123 | if ($usesIteration) { |
124 | - $pre .= "\n\t" . '"iteration" => 1,'; |
|
124 | + $pre .= "\n\t".'"iteration" => 1,'; |
|
125 | 125 | } |
126 | 126 | if ($usesFirst) { |
127 | - $pre .= "\n\t" . '"first" => null,'; |
|
127 | + $pre .= "\n\t".'"first" => null,'; |
|
128 | 128 | } |
129 | 129 | if ($usesLast) { |
130 | - $pre .= "\n\t" . '"last" => null,'; |
|
130 | + $pre .= "\n\t".'"last" => null,'; |
|
131 | 131 | } |
132 | 132 | if ($usesShow) { |
133 | - $pre .= "\n\t" . '"show" => $this->isTraversable($_loop' . $cnt . '_data, true),'; |
|
133 | + $pre .= "\n\t".'"show" => $this->isTraversable($_loop'.$cnt.'_data, true),'; |
|
134 | 134 | } |
135 | 135 | if ($usesTotal) { |
136 | - $pre .= "\n\t" . '"total" => $this->count($_loop' . $cnt . '_data),'; |
|
136 | + $pre .= "\n\t".'"total" => $this->count($_loop'.$cnt.'_data),'; |
|
137 | 137 | } |
138 | - $pre .= "\n);\n" . '$_loop' . $cnt . '_glob =& $this->globals["loop"][' . $name . '];'; |
|
138 | + $pre .= "\n);\n".'$_loop'.$cnt.'_glob =& $this->globals["loop"]['.$name.'];'; |
|
139 | 139 | } |
140 | 140 | // checks if the loop must be looped |
141 | - $pre .= "\n" . 'if ($this->isTraversable($_loop' . $cnt . '_data' . (isset($params['hasElse']) ? ', true' : '') . ') == true)' . "\n{"; |
|
141 | + $pre .= "\n".'if ($this->isTraversable($_loop'.$cnt.'_data'.(isset($params['hasElse']) ? ', true' : '').') == true)'."\n{"; |
|
142 | 142 | // iterates over keys |
143 | - $pre .= "\n\t" . 'foreach ($_loop' . $cnt . '_data as $tmp_key => $this->scope["-loop-"])' . "\n\t{"; |
|
143 | + $pre .= "\n\t".'foreach ($_loop'.$cnt.'_data as $tmp_key => $this->scope["-loop-"])'."\n\t{"; |
|
144 | 144 | // updates properties |
145 | 145 | if ($usesFirst) { |
146 | - $pre .= "\n\t\t" . '$_loop' . $cnt . '_glob["first"] = (string) ($_loop' . $cnt . '_glob["index"] === 0);'; |
|
146 | + $pre .= "\n\t\t".'$_loop'.$cnt.'_glob["first"] = (string) ($_loop'.$cnt.'_glob["index"] === 0);'; |
|
147 | 147 | } |
148 | 148 | if ($usesLast) { |
149 | - $pre .= "\n\t\t" . '$_loop' . $cnt . '_glob["last"] = (string) ($_loop' . $cnt . '_glob["iteration"] === $_loop' . $cnt . '_glob["total"]);'; |
|
149 | + $pre .= "\n\t\t".'$_loop'.$cnt.'_glob["last"] = (string) ($_loop'.$cnt.'_glob["iteration"] === $_loop'.$cnt.'_glob["total"]);'; |
|
150 | 150 | } |
151 | - $pre .= "\n\t\t" . '$_loop' . $cnt . '_scope = $this->setScope(array("-loop-"));' . "\n/* -- loop start output */\n" . Compiler::PHP_CLOSE; |
|
151 | + $pre .= "\n\t\t".'$_loop'.$cnt.'_scope = $this->setScope(array("-loop-"));'."\n/* -- loop start output */\n".Compiler::PHP_CLOSE; |
|
152 | 152 | |
153 | 153 | // build post processing output and cache it |
154 | - $post = Compiler::PHP_OPEN . "\n" . '/* -- loop end output */' . "\n\t\t" . '$this->setScope($_loop' . $cnt . '_scope, true);'; |
|
154 | + $post = Compiler::PHP_OPEN."\n".'/* -- loop end output */'."\n\t\t".'$this->setScope($_loop'.$cnt.'_scope, true);'; |
|
155 | 155 | // update properties |
156 | 156 | if ($usesIndex) { |
157 | - $post .= "\n\t\t" . '$_loop' . $cnt . '_glob["index"]+=1;'; |
|
157 | + $post .= "\n\t\t".'$_loop'.$cnt.'_glob["index"]+=1;'; |
|
158 | 158 | } |
159 | 159 | if ($usesIteration) { |
160 | - $post .= "\n\t\t" . '$_loop' . $cnt . '_glob["iteration"]+=1;'; |
|
160 | + $post .= "\n\t\t".'$_loop'.$cnt.'_glob["iteration"]+=1;'; |
|
161 | 161 | } |
162 | 162 | // end loop |
163 | - $post .= "\n\t}\n}\n" . Compiler::PHP_CLOSE; |
|
163 | + $post .= "\n\t}\n}\n".Compiler::PHP_CLOSE; |
|
164 | 164 | if (isset($params['hasElse'])) { |
165 | 165 | $post .= $params['hasElse']; |
166 | 166 | } |
167 | 167 | |
168 | - return $pre . $content . $post; |
|
168 | + return $pre.$content.$post; |
|
169 | 169 | } |
170 | 170 | } |
@@ -32,67 +32,67 @@ |
||
32 | 32 | */ |
33 | 33 | class PluginAutoEscape extends BlockPlugin implements ICompilableBlock |
34 | 34 | { |
35 | - protected static $stack = array(); |
|
35 | + protected static $stack = array(); |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param $enabled |
|
39 | - */ |
|
40 | - public function init($enabled) |
|
41 | - { |
|
42 | - } |
|
37 | + /** |
|
38 | + * @param $enabled |
|
39 | + */ |
|
40 | + public function init($enabled) |
|
41 | + { |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param Compiler $compiler |
|
46 | - * @param array $params |
|
47 | - * @param string $prepend |
|
48 | - * @param string $append |
|
49 | - * @param string $type |
|
50 | - * |
|
51 | - * @return string |
|
52 | - * @throws CompilationException |
|
53 | - */ |
|
54 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
55 | - { |
|
56 | - $params = $compiler->getCompiledParams($params); |
|
57 | - switch (strtolower(trim((string)$params['enabled'], '"\''))) { |
|
44 | + /** |
|
45 | + * @param Compiler $compiler |
|
46 | + * @param array $params |
|
47 | + * @param string $prepend |
|
48 | + * @param string $append |
|
49 | + * @param string $type |
|
50 | + * |
|
51 | + * @return string |
|
52 | + * @throws CompilationException |
|
53 | + */ |
|
54 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
55 | + { |
|
56 | + $params = $compiler->getCompiledParams($params); |
|
57 | + switch (strtolower(trim((string)$params['enabled'], '"\''))) { |
|
58 | 58 | |
59 | - case 'on': |
|
60 | - case 'true': |
|
61 | - case 'enabled': |
|
62 | - case 'enable': |
|
63 | - case '1': |
|
64 | - $enable = true; |
|
65 | - break; |
|
66 | - case 'off': |
|
67 | - case 'false': |
|
68 | - case 'disabled': |
|
69 | - case 'disable': |
|
70 | - case '0': |
|
71 | - $enable = false; |
|
72 | - break; |
|
73 | - default: |
|
74 | - throw new CompilationException($compiler, 'Auto_Escape : Invalid parameter (' . $params['enabled'] . '), valid parameters are "enable"/true or "disable"/false'); |
|
75 | - } |
|
59 | + case 'on': |
|
60 | + case 'true': |
|
61 | + case 'enabled': |
|
62 | + case 'enable': |
|
63 | + case '1': |
|
64 | + $enable = true; |
|
65 | + break; |
|
66 | + case 'off': |
|
67 | + case 'false': |
|
68 | + case 'disabled': |
|
69 | + case 'disable': |
|
70 | + case '0': |
|
71 | + $enable = false; |
|
72 | + break; |
|
73 | + default: |
|
74 | + throw new CompilationException($compiler, 'Auto_Escape : Invalid parameter (' . $params['enabled'] . '), valid parameters are "enable"/true or "disable"/false'); |
|
75 | + } |
|
76 | 76 | |
77 | - self::$stack[] = $compiler->getAutoEscape(); |
|
78 | - $compiler->setAutoEscape($enable); |
|
77 | + self::$stack[] = $compiler->getAutoEscape(); |
|
78 | + $compiler->setAutoEscape($enable); |
|
79 | 79 | |
80 | - return ''; |
|
81 | - } |
|
80 | + return ''; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @param Compiler $compiler |
|
85 | - * @param array $params |
|
86 | - * @param string $prepend |
|
87 | - * @param string $append |
|
88 | - * @param string $content |
|
89 | - * |
|
90 | - * @return string |
|
91 | - */ |
|
92 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
93 | - { |
|
94 | - $compiler->setAutoEscape(array_pop(self::$stack)); |
|
83 | + /** |
|
84 | + * @param Compiler $compiler |
|
85 | + * @param array $params |
|
86 | + * @param string $prepend |
|
87 | + * @param string $append |
|
88 | + * @param string $content |
|
89 | + * |
|
90 | + * @return string |
|
91 | + */ |
|
92 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
93 | + { |
|
94 | + $compiler->setAutoEscape(array_pop(self::$stack)); |
|
95 | 95 | |
96 | - return $content; |
|
97 | - } |
|
96 | + return $content; |
|
97 | + } |
|
98 | 98 | } |
@@ -56,22 +56,22 @@ |
||
56 | 56 | $params = $compiler->getCompiledParams($params); |
57 | 57 | switch (strtolower(trim((string)$params['enabled'], '"\''))) { |
58 | 58 | |
59 | - case 'on': |
|
60 | - case 'true': |
|
61 | - case 'enabled': |
|
62 | - case 'enable': |
|
63 | - case '1': |
|
64 | - $enable = true; |
|
65 | - break; |
|
66 | - case 'off': |
|
67 | - case 'false': |
|
68 | - case 'disabled': |
|
69 | - case 'disable': |
|
70 | - case '0': |
|
71 | - $enable = false; |
|
72 | - break; |
|
73 | - default: |
|
74 | - throw new CompilationException($compiler, 'Auto_Escape : Invalid parameter (' . $params['enabled'] . '), valid parameters are "enable"/true or "disable"/false'); |
|
59 | + case 'on': |
|
60 | + case 'true': |
|
61 | + case 'enabled': |
|
62 | + case 'enable': |
|
63 | + case '1': |
|
64 | + $enable = true; |
|
65 | + break; |
|
66 | + case 'off': |
|
67 | + case 'false': |
|
68 | + case 'disabled': |
|
69 | + case 'disable': |
|
70 | + case '0': |
|
71 | + $enable = false; |
|
72 | + break; |
|
73 | + default: |
|
74 | + throw new CompilationException($compiler, 'Auto_Escape : Invalid parameter (' . $params['enabled'] . '), valid parameters are "enable"/true or "disable"/false'); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | self::$stack[] = $compiler->getAutoEscape(); |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
55 | 55 | { |
56 | 56 | $params = $compiler->getCompiledParams($params); |
57 | - switch (strtolower(trim((string)$params['enabled'], '"\''))) { |
|
57 | + switch (strtolower(trim((string) $params['enabled'], '"\''))) { |
|
58 | 58 | |
59 | 59 | case 'on': |
60 | 60 | case 'true': |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | $enable = false; |
72 | 72 | break; |
73 | 73 | default: |
74 | - throw new CompilationException($compiler, 'Auto_Escape : Invalid parameter (' . $params['enabled'] . '), valid parameters are "enable"/true or "disable"/false'); |
|
74 | + throw new CompilationException($compiler, 'Auto_Escape : Invalid parameter ('.$params['enabled'].'), valid parameters are "enable"/true or "disable"/false'); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | self::$stack[] = $compiler->getAutoEscape(); |
@@ -38,59 +38,59 @@ |
||
38 | 38 | */ |
39 | 39 | class PluginElse extends BlockPlugin implements ICompilableBlock |
40 | 40 | { |
41 | - public function init() |
|
42 | - { |
|
43 | - } |
|
41 | + public function init() |
|
42 | + { |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param Compiler $compiler |
|
47 | - * @param array $params |
|
48 | - * @param string $prepend |
|
49 | - * @param string $append |
|
50 | - * @param string $type |
|
51 | - * |
|
52 | - * @return string |
|
53 | - * @throws CompilationException |
|
54 | - */ |
|
55 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
56 | - { |
|
57 | - $preContent = ''; |
|
58 | - while (true) { |
|
59 | - $preContent .= $compiler->removeTopBlock(); |
|
60 | - $block = &$compiler->getCurrentBlock(); |
|
61 | - if (!$block) { |
|
62 | - throw new CompilationException($compiler, 'An else block was found but it was not preceded by an if or other else-able construct'); |
|
63 | - } |
|
64 | - $interfaces = class_implements($block['class']); |
|
65 | - if (in_array('Dwoo\IElseable', $interfaces) !== false) { |
|
66 | - break; |
|
67 | - } |
|
68 | - } |
|
45 | + /** |
|
46 | + * @param Compiler $compiler |
|
47 | + * @param array $params |
|
48 | + * @param string $prepend |
|
49 | + * @param string $append |
|
50 | + * @param string $type |
|
51 | + * |
|
52 | + * @return string |
|
53 | + * @throws CompilationException |
|
54 | + */ |
|
55 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
56 | + { |
|
57 | + $preContent = ''; |
|
58 | + while (true) { |
|
59 | + $preContent .= $compiler->removeTopBlock(); |
|
60 | + $block = &$compiler->getCurrentBlock(); |
|
61 | + if (!$block) { |
|
62 | + throw new CompilationException($compiler, 'An else block was found but it was not preceded by an if or other else-able construct'); |
|
63 | + } |
|
64 | + $interfaces = class_implements($block['class']); |
|
65 | + if (in_array('Dwoo\IElseable', $interfaces) !== false) { |
|
66 | + break; |
|
67 | + } |
|
68 | + } |
|
69 | 69 | |
70 | - $params['initialized'] = true; |
|
71 | - $compiler->injectBlock($type, $params); |
|
70 | + $params['initialized'] = true; |
|
71 | + $compiler->injectBlock($type, $params); |
|
72 | 72 | |
73 | - return $preContent; |
|
74 | - } |
|
73 | + return $preContent; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * @param Compiler $compiler |
|
78 | - * @param array $params |
|
79 | - * @param string $prepend |
|
80 | - * @param string $append |
|
81 | - * @param string $content |
|
82 | - * |
|
83 | - * @return string |
|
84 | - */ |
|
85 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
86 | - { |
|
87 | - if (!isset($params['initialized'])) { |
|
88 | - return ''; |
|
89 | - } |
|
76 | + /** |
|
77 | + * @param Compiler $compiler |
|
78 | + * @param array $params |
|
79 | + * @param string $prepend |
|
80 | + * @param string $append |
|
81 | + * @param string $content |
|
82 | + * |
|
83 | + * @return string |
|
84 | + */ |
|
85 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
86 | + { |
|
87 | + if (!isset($params['initialized'])) { |
|
88 | + return ''; |
|
89 | + } |
|
90 | 90 | |
91 | - $block = &$compiler->getCurrentBlock(); |
|
92 | - $block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
91 | + $block = &$compiler->getCurrentBlock(); |
|
92 | + $block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
93 | 93 | |
94 | - return ''; |
|
95 | - } |
|
94 | + return ''; |
|
95 | + } |
|
96 | 96 | } |
@@ -66,7 +66,7 @@ |
||
66 | 66 | } |
67 | 67 | |
68 | 68 | $block = &$compiler->getCurrentBlock(); |
69 | - $block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
69 | + $block['params']['hasElse'] = Compiler::PHP_OPEN."else {\n".Compiler::PHP_CLOSE.$content.Compiler::PHP_OPEN."\n}".Compiler::PHP_CLOSE; |
|
70 | 70 | |
71 | 71 | return ''; |
72 | 72 | } |
@@ -28,98 +28,98 @@ discard block |
||
28 | 28 | */ |
29 | 29 | class PluginSection extends BlockPlugin implements ICompilableBlock, IElseable |
30 | 30 | { |
31 | - public static $cnt = 0; |
|
32 | - |
|
33 | - /** |
|
34 | - * @param $name |
|
35 | - * @param $loop |
|
36 | - * @param null $start |
|
37 | - * @param null $step |
|
38 | - * @param null $max |
|
39 | - * @param bool $show |
|
40 | - */ |
|
41 | - public function init($name, $loop, $start = null, $step = null, $max = null, $show = true) |
|
42 | - { |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * @param Compiler $compiler |
|
47 | - * @param array $params |
|
48 | - * @param string $prepend |
|
49 | - * @param string $append |
|
50 | - * @param string $type |
|
51 | - * |
|
52 | - * @return string |
|
53 | - */ |
|
54 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
55 | - { |
|
56 | - return ''; |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * @param Compiler $compiler |
|
61 | - * @param array $params |
|
62 | - * @param string $prepend |
|
63 | - * @param string $append |
|
64 | - * @param string $content |
|
65 | - * |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
69 | - { |
|
70 | - $output = Compiler::PHP_OPEN; |
|
71 | - $params = $compiler->getCompiledParams($params); |
|
72 | - |
|
73 | - // assigns params |
|
74 | - $loop = $params['loop']; |
|
75 | - $start = $params['start']; |
|
76 | - $max = $params['max']; |
|
77 | - $name = $params['name']; |
|
78 | - $step = $params['step']; |
|
79 | - $show = $params['show']; |
|
80 | - |
|
81 | - // gets unique id |
|
82 | - $cnt = self::$cnt ++; |
|
83 | - |
|
84 | - $output .= '$this->globals[\'section\'][' . $name . '] = array();' . "\n" . '$_section' . $cnt . ' =& $this->globals[\'section\'][' . $name . '];' . "\n"; |
|
85 | - |
|
86 | - if ($loop !== 'null') { |
|
87 | - $output .= '$_section' . $cnt . '[\'loop\'] = is_array($tmp = ' . $loop . ') ? count($tmp) : max(0, (int) $tmp);' . "\n"; |
|
88 | - } else { |
|
89 | - $output .= '$_section' . $cnt . '[\'loop\'] = 1;' . "\n"; |
|
90 | - } |
|
91 | - |
|
92 | - if ($show !== 'null') { |
|
93 | - $output .= '$_section' . $cnt . '[\'show\'] = ' . $show . ";\n"; |
|
94 | - } else { |
|
95 | - $output .= '$_section' . $cnt . '[\'show\'] = true;' . "\n"; |
|
96 | - } |
|
97 | - |
|
98 | - if ($name !== 'null') { |
|
99 | - $output .= '$_section' . $cnt . '[\'name\'] = ' . $name . ";\n"; |
|
100 | - } else { |
|
101 | - $output .= '$_section' . $cnt . '[\'name\'] = true;' . "\n"; |
|
102 | - } |
|
103 | - |
|
104 | - if ($max !== 'null') { |
|
105 | - $output .= '$_section' . $cnt . '[\'max\'] = (int)' . $max . ";\n" . 'if($_section' . $cnt . '[\'max\'] < 0) { $_section' . $cnt . '[\'max\'] = $_section' . $cnt . '[\'loop\']; }' . "\n"; |
|
106 | - } else { |
|
107 | - $output .= '$_section' . $cnt . '[\'max\'] = $_section' . $cnt . '[\'loop\'];' . "\n"; |
|
108 | - } |
|
109 | - |
|
110 | - if ($step !== 'null') { |
|
111 | - $output .= '$_section' . $cnt . '[\'step\'] = (int)' . $step . ' == 0 ? 1 : (int) ' . $step . ";\n"; |
|
112 | - } else { |
|
113 | - $output .= '$_section' . $cnt . '[\'step\'] = 1;' . "\n"; |
|
114 | - } |
|
115 | - |
|
116 | - if ($start !== 'null') { |
|
117 | - $output .= '$_section' . $cnt . '[\'start\'] = (int)' . $start . ";\n"; |
|
118 | - } else { |
|
119 | - $output .= '$_section' . $cnt . '[\'start\'] = $_section' . $cnt . '[\'step\'] > 0 ? 0 : $_section' . $cnt . '[\'loop\'] - 1;' . "\n" . 'if ($_section' . $cnt . '[\'start\'] < 0) { $_section' . $cnt . '[\'start\'] = max($_section' . $cnt . '[\'step\'] > 0 ? 0 : -1, $_section' . $cnt . '[\'loop\'] + $_section' . $cnt . '[\'start\']); } ' . "\n" . 'else { $_section' . $cnt . '[\'start\'] = min($_section' . $cnt . '[\'start\'], $_section' . $cnt . '[\'step\'] > 0 ? $_section' . $cnt . '[\'loop\'] : $_section' . $cnt . '[\'loop\'] -1); }' . "\n"; |
|
120 | - } |
|
121 | - |
|
122 | - /* if ($usesAny) { |
|
31 | + public static $cnt = 0; |
|
32 | + |
|
33 | + /** |
|
34 | + * @param $name |
|
35 | + * @param $loop |
|
36 | + * @param null $start |
|
37 | + * @param null $step |
|
38 | + * @param null $max |
|
39 | + * @param bool $show |
|
40 | + */ |
|
41 | + public function init($name, $loop, $start = null, $step = null, $max = null, $show = true) |
|
42 | + { |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * @param Compiler $compiler |
|
47 | + * @param array $params |
|
48 | + * @param string $prepend |
|
49 | + * @param string $append |
|
50 | + * @param string $type |
|
51 | + * |
|
52 | + * @return string |
|
53 | + */ |
|
54 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
55 | + { |
|
56 | + return ''; |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * @param Compiler $compiler |
|
61 | + * @param array $params |
|
62 | + * @param string $prepend |
|
63 | + * @param string $append |
|
64 | + * @param string $content |
|
65 | + * |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
69 | + { |
|
70 | + $output = Compiler::PHP_OPEN; |
|
71 | + $params = $compiler->getCompiledParams($params); |
|
72 | + |
|
73 | + // assigns params |
|
74 | + $loop = $params['loop']; |
|
75 | + $start = $params['start']; |
|
76 | + $max = $params['max']; |
|
77 | + $name = $params['name']; |
|
78 | + $step = $params['step']; |
|
79 | + $show = $params['show']; |
|
80 | + |
|
81 | + // gets unique id |
|
82 | + $cnt = self::$cnt ++; |
|
83 | + |
|
84 | + $output .= '$this->globals[\'section\'][' . $name . '] = array();' . "\n" . '$_section' . $cnt . ' =& $this->globals[\'section\'][' . $name . '];' . "\n"; |
|
85 | + |
|
86 | + if ($loop !== 'null') { |
|
87 | + $output .= '$_section' . $cnt . '[\'loop\'] = is_array($tmp = ' . $loop . ') ? count($tmp) : max(0, (int) $tmp);' . "\n"; |
|
88 | + } else { |
|
89 | + $output .= '$_section' . $cnt . '[\'loop\'] = 1;' . "\n"; |
|
90 | + } |
|
91 | + |
|
92 | + if ($show !== 'null') { |
|
93 | + $output .= '$_section' . $cnt . '[\'show\'] = ' . $show . ";\n"; |
|
94 | + } else { |
|
95 | + $output .= '$_section' . $cnt . '[\'show\'] = true;' . "\n"; |
|
96 | + } |
|
97 | + |
|
98 | + if ($name !== 'null') { |
|
99 | + $output .= '$_section' . $cnt . '[\'name\'] = ' . $name . ";\n"; |
|
100 | + } else { |
|
101 | + $output .= '$_section' . $cnt . '[\'name\'] = true;' . "\n"; |
|
102 | + } |
|
103 | + |
|
104 | + if ($max !== 'null') { |
|
105 | + $output .= '$_section' . $cnt . '[\'max\'] = (int)' . $max . ";\n" . 'if($_section' . $cnt . '[\'max\'] < 0) { $_section' . $cnt . '[\'max\'] = $_section' . $cnt . '[\'loop\']; }' . "\n"; |
|
106 | + } else { |
|
107 | + $output .= '$_section' . $cnt . '[\'max\'] = $_section' . $cnt . '[\'loop\'];' . "\n"; |
|
108 | + } |
|
109 | + |
|
110 | + if ($step !== 'null') { |
|
111 | + $output .= '$_section' . $cnt . '[\'step\'] = (int)' . $step . ' == 0 ? 1 : (int) ' . $step . ";\n"; |
|
112 | + } else { |
|
113 | + $output .= '$_section' . $cnt . '[\'step\'] = 1;' . "\n"; |
|
114 | + } |
|
115 | + |
|
116 | + if ($start !== 'null') { |
|
117 | + $output .= '$_section' . $cnt . '[\'start\'] = (int)' . $start . ";\n"; |
|
118 | + } else { |
|
119 | + $output .= '$_section' . $cnt . '[\'start\'] = $_section' . $cnt . '[\'step\'] > 0 ? 0 : $_section' . $cnt . '[\'loop\'] - 1;' . "\n" . 'if ($_section' . $cnt . '[\'start\'] < 0) { $_section' . $cnt . '[\'start\'] = max($_section' . $cnt . '[\'step\'] > 0 ? 0 : -1, $_section' . $cnt . '[\'loop\'] + $_section' . $cnt . '[\'start\']); } ' . "\n" . 'else { $_section' . $cnt . '[\'start\'] = min($_section' . $cnt . '[\'start\'], $_section' . $cnt . '[\'step\'] > 0 ? $_section' . $cnt . '[\'loop\'] : $_section' . $cnt . '[\'loop\'] -1); }' . "\n"; |
|
120 | + } |
|
121 | + |
|
122 | + /* if ($usesAny) { |
|
123 | 123 | $output .= "\n".'$this->globals["section"]['.$name.'] = array'."\n("; |
124 | 124 | if ($usesIndex) $output .="\n\t".'"index" => 0,'; |
125 | 125 | if ($usesIteration) $output .="\n\t".'"iteration" => 1,'; |
@@ -131,29 +131,29 @@ discard block |
||
131 | 131 | } |
132 | 132 | */ |
133 | 133 | |
134 | - $output .= 'if ($_section' . $cnt . '[\'show\']) {' . "\n"; |
|
135 | - if ($start === 'null' && $step === 'null' && $max === 'null') { |
|
136 | - $output .= ' $_section' . $cnt . '[\'total\'] = $_section' . $cnt . '[\'loop\'];' . "\n"; |
|
137 | - } else { |
|
138 | - $output .= ' $_section' . $cnt . '[\'total\'] = min(ceil(($_section' . $cnt . '[\'step\'] > 0 ? $_section' . $cnt . '[\'loop\'] - $_section' . $cnt . '[\'start\'] : $_section' . $cnt . '[\'start\'] + 1) / abs($_section' . $cnt . '[\'step\'])), $_section' . $cnt . '[\'max\']);' . "\n"; |
|
139 | - } |
|
140 | - $output .= ' if ($_section' . $cnt . '[\'total\'] == 0) {' . "\n" . ' $_section' . $cnt . '[\'show\'] = false;' . "\n" . ' }' . "\n" . '} else {' . "\n" . ' $_section' . $cnt . '[\'total\'] = 0;' . "\n}\n"; |
|
141 | - $output .= 'if ($_section' . $cnt . '[\'show\']) {' . "\n"; |
|
142 | - $output .= "\t" . 'for ($this->scope[' . $name . '] = $_section' . $cnt . '[\'start\'], $_section' . $cnt . '[\'iteration\'] = 1; ' . '$_section' . $cnt . '[\'iteration\'] <= $_section' . $cnt . '[\'total\']; ' . '$this->scope[' . $name . '] += $_section' . $cnt . '[\'step\'], $_section' . $cnt . '[\'iteration\']++) {' . "\n"; |
|
143 | - $output .= "\t\t" . '$_section' . $cnt . '[\'rownum\'] = $_section' . $cnt . '[\'iteration\'];' . "\n"; |
|
144 | - $output .= "\t\t" . '$_section' . $cnt . '[\'index_prev\'] = $this->scope[' . $name . '] - $_section' . $cnt . '[\'step\'];' . "\n"; |
|
145 | - $output .= "\t\t" . '$_section' . $cnt . '[\'index_next\'] = $this->scope[' . $name . '] + $_section' . $cnt . '[\'step\'];' . "\n"; |
|
146 | - $output .= "\t\t" . '$_section' . $cnt . '[\'first\'] = ($_section' . $cnt . '[\'iteration\'] == 1);' . "\n"; |
|
147 | - $output .= "\t\t" . '$_section' . $cnt . '[\'last\'] = ($_section' . $cnt . '[\'iteration\'] == $_section' . $cnt . '[\'total\']);' . "\n"; |
|
148 | - |
|
149 | - $output .= Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN; |
|
150 | - |
|
151 | - $output .= "\n\t}\n} " . Compiler::PHP_CLOSE; |
|
152 | - |
|
153 | - if (isset($params['hasElse'])) { |
|
154 | - $output .= $params['hasElse']; |
|
155 | - } |
|
156 | - |
|
157 | - return $output; |
|
158 | - } |
|
134 | + $output .= 'if ($_section' . $cnt . '[\'show\']) {' . "\n"; |
|
135 | + if ($start === 'null' && $step === 'null' && $max === 'null') { |
|
136 | + $output .= ' $_section' . $cnt . '[\'total\'] = $_section' . $cnt . '[\'loop\'];' . "\n"; |
|
137 | + } else { |
|
138 | + $output .= ' $_section' . $cnt . '[\'total\'] = min(ceil(($_section' . $cnt . '[\'step\'] > 0 ? $_section' . $cnt . '[\'loop\'] - $_section' . $cnt . '[\'start\'] : $_section' . $cnt . '[\'start\'] + 1) / abs($_section' . $cnt . '[\'step\'])), $_section' . $cnt . '[\'max\']);' . "\n"; |
|
139 | + } |
|
140 | + $output .= ' if ($_section' . $cnt . '[\'total\'] == 0) {' . "\n" . ' $_section' . $cnt . '[\'show\'] = false;' . "\n" . ' }' . "\n" . '} else {' . "\n" . ' $_section' . $cnt . '[\'total\'] = 0;' . "\n}\n"; |
|
141 | + $output .= 'if ($_section' . $cnt . '[\'show\']) {' . "\n"; |
|
142 | + $output .= "\t" . 'for ($this->scope[' . $name . '] = $_section' . $cnt . '[\'start\'], $_section' . $cnt . '[\'iteration\'] = 1; ' . '$_section' . $cnt . '[\'iteration\'] <= $_section' . $cnt . '[\'total\']; ' . '$this->scope[' . $name . '] += $_section' . $cnt . '[\'step\'], $_section' . $cnt . '[\'iteration\']++) {' . "\n"; |
|
143 | + $output .= "\t\t" . '$_section' . $cnt . '[\'rownum\'] = $_section' . $cnt . '[\'iteration\'];' . "\n"; |
|
144 | + $output .= "\t\t" . '$_section' . $cnt . '[\'index_prev\'] = $this->scope[' . $name . '] - $_section' . $cnt . '[\'step\'];' . "\n"; |
|
145 | + $output .= "\t\t" . '$_section' . $cnt . '[\'index_next\'] = $this->scope[' . $name . '] + $_section' . $cnt . '[\'step\'];' . "\n"; |
|
146 | + $output .= "\t\t" . '$_section' . $cnt . '[\'first\'] = ($_section' . $cnt . '[\'iteration\'] == 1);' . "\n"; |
|
147 | + $output .= "\t\t" . '$_section' . $cnt . '[\'last\'] = ($_section' . $cnt . '[\'iteration\'] == $_section' . $cnt . '[\'total\']);' . "\n"; |
|
148 | + |
|
149 | + $output .= Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN; |
|
150 | + |
|
151 | + $output .= "\n\t}\n} " . Compiler::PHP_CLOSE; |
|
152 | + |
|
153 | + if (isset($params['hasElse'])) { |
|
154 | + $output .= $params['hasElse']; |
|
155 | + } |
|
156 | + |
|
157 | + return $output; |
|
158 | + } |
|
159 | 159 | } |
@@ -79,44 +79,44 @@ discard block |
||
79 | 79 | $show = $params['show']; |
80 | 80 | |
81 | 81 | // gets unique id |
82 | - $cnt = self::$cnt ++; |
|
82 | + $cnt = self::$cnt++; |
|
83 | 83 | |
84 | - $output .= '$this->globals[\'section\'][' . $name . '] = array();' . "\n" . '$_section' . $cnt . ' =& $this->globals[\'section\'][' . $name . '];' . "\n"; |
|
84 | + $output .= '$this->globals[\'section\']['.$name.'] = array();'."\n".'$_section'.$cnt.' =& $this->globals[\'section\']['.$name.'];'."\n"; |
|
85 | 85 | |
86 | 86 | if ($loop !== 'null') { |
87 | - $output .= '$_section' . $cnt . '[\'loop\'] = is_array($tmp = ' . $loop . ') ? count($tmp) : max(0, (int) $tmp);' . "\n"; |
|
87 | + $output .= '$_section'.$cnt.'[\'loop\'] = is_array($tmp = '.$loop.') ? count($tmp) : max(0, (int) $tmp);'."\n"; |
|
88 | 88 | } else { |
89 | - $output .= '$_section' . $cnt . '[\'loop\'] = 1;' . "\n"; |
|
89 | + $output .= '$_section'.$cnt.'[\'loop\'] = 1;'."\n"; |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | if ($show !== 'null') { |
93 | - $output .= '$_section' . $cnt . '[\'show\'] = ' . $show . ";\n"; |
|
93 | + $output .= '$_section'.$cnt.'[\'show\'] = '.$show.";\n"; |
|
94 | 94 | } else { |
95 | - $output .= '$_section' . $cnt . '[\'show\'] = true;' . "\n"; |
|
95 | + $output .= '$_section'.$cnt.'[\'show\'] = true;'."\n"; |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | if ($name !== 'null') { |
99 | - $output .= '$_section' . $cnt . '[\'name\'] = ' . $name . ";\n"; |
|
99 | + $output .= '$_section'.$cnt.'[\'name\'] = '.$name.";\n"; |
|
100 | 100 | } else { |
101 | - $output .= '$_section' . $cnt . '[\'name\'] = true;' . "\n"; |
|
101 | + $output .= '$_section'.$cnt.'[\'name\'] = true;'."\n"; |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | if ($max !== 'null') { |
105 | - $output .= '$_section' . $cnt . '[\'max\'] = (int)' . $max . ";\n" . 'if($_section' . $cnt . '[\'max\'] < 0) { $_section' . $cnt . '[\'max\'] = $_section' . $cnt . '[\'loop\']; }' . "\n"; |
|
105 | + $output .= '$_section'.$cnt.'[\'max\'] = (int)'.$max.";\n".'if($_section'.$cnt.'[\'max\'] < 0) { $_section'.$cnt.'[\'max\'] = $_section'.$cnt.'[\'loop\']; }'."\n"; |
|
106 | 106 | } else { |
107 | - $output .= '$_section' . $cnt . '[\'max\'] = $_section' . $cnt . '[\'loop\'];' . "\n"; |
|
107 | + $output .= '$_section'.$cnt.'[\'max\'] = $_section'.$cnt.'[\'loop\'];'."\n"; |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | if ($step !== 'null') { |
111 | - $output .= '$_section' . $cnt . '[\'step\'] = (int)' . $step . ' == 0 ? 1 : (int) ' . $step . ";\n"; |
|
111 | + $output .= '$_section'.$cnt.'[\'step\'] = (int)'.$step.' == 0 ? 1 : (int) '.$step.";\n"; |
|
112 | 112 | } else { |
113 | - $output .= '$_section' . $cnt . '[\'step\'] = 1;' . "\n"; |
|
113 | + $output .= '$_section'.$cnt.'[\'step\'] = 1;'."\n"; |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | if ($start !== 'null') { |
117 | - $output .= '$_section' . $cnt . '[\'start\'] = (int)' . $start . ";\n"; |
|
117 | + $output .= '$_section'.$cnt.'[\'start\'] = (int)'.$start.";\n"; |
|
118 | 118 | } else { |
119 | - $output .= '$_section' . $cnt . '[\'start\'] = $_section' . $cnt . '[\'step\'] > 0 ? 0 : $_section' . $cnt . '[\'loop\'] - 1;' . "\n" . 'if ($_section' . $cnt . '[\'start\'] < 0) { $_section' . $cnt . '[\'start\'] = max($_section' . $cnt . '[\'step\'] > 0 ? 0 : -1, $_section' . $cnt . '[\'loop\'] + $_section' . $cnt . '[\'start\']); } ' . "\n" . 'else { $_section' . $cnt . '[\'start\'] = min($_section' . $cnt . '[\'start\'], $_section' . $cnt . '[\'step\'] > 0 ? $_section' . $cnt . '[\'loop\'] : $_section' . $cnt . '[\'loop\'] -1); }' . "\n"; |
|
119 | + $output .= '$_section'.$cnt.'[\'start\'] = $_section'.$cnt.'[\'step\'] > 0 ? 0 : $_section'.$cnt.'[\'loop\'] - 1;'."\n".'if ($_section'.$cnt.'[\'start\'] < 0) { $_section'.$cnt.'[\'start\'] = max($_section'.$cnt.'[\'step\'] > 0 ? 0 : -1, $_section'.$cnt.'[\'loop\'] + $_section'.$cnt.'[\'start\']); } '."\n".'else { $_section'.$cnt.'[\'start\'] = min($_section'.$cnt.'[\'start\'], $_section'.$cnt.'[\'step\'] > 0 ? $_section'.$cnt.'[\'loop\'] : $_section'.$cnt.'[\'loop\'] -1); }'."\n"; |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /* if ($usesAny) { |
@@ -131,24 +131,24 @@ discard block |
||
131 | 131 | } |
132 | 132 | */ |
133 | 133 | |
134 | - $output .= 'if ($_section' . $cnt . '[\'show\']) {' . "\n"; |
|
134 | + $output .= 'if ($_section'.$cnt.'[\'show\']) {'."\n"; |
|
135 | 135 | if ($start === 'null' && $step === 'null' && $max === 'null') { |
136 | - $output .= ' $_section' . $cnt . '[\'total\'] = $_section' . $cnt . '[\'loop\'];' . "\n"; |
|
136 | + $output .= ' $_section'.$cnt.'[\'total\'] = $_section'.$cnt.'[\'loop\'];'."\n"; |
|
137 | 137 | } else { |
138 | - $output .= ' $_section' . $cnt . '[\'total\'] = min(ceil(($_section' . $cnt . '[\'step\'] > 0 ? $_section' . $cnt . '[\'loop\'] - $_section' . $cnt . '[\'start\'] : $_section' . $cnt . '[\'start\'] + 1) / abs($_section' . $cnt . '[\'step\'])), $_section' . $cnt . '[\'max\']);' . "\n"; |
|
138 | + $output .= ' $_section'.$cnt.'[\'total\'] = min(ceil(($_section'.$cnt.'[\'step\'] > 0 ? $_section'.$cnt.'[\'loop\'] - $_section'.$cnt.'[\'start\'] : $_section'.$cnt.'[\'start\'] + 1) / abs($_section'.$cnt.'[\'step\'])), $_section'.$cnt.'[\'max\']);'."\n"; |
|
139 | 139 | } |
140 | - $output .= ' if ($_section' . $cnt . '[\'total\'] == 0) {' . "\n" . ' $_section' . $cnt . '[\'show\'] = false;' . "\n" . ' }' . "\n" . '} else {' . "\n" . ' $_section' . $cnt . '[\'total\'] = 0;' . "\n}\n"; |
|
141 | - $output .= 'if ($_section' . $cnt . '[\'show\']) {' . "\n"; |
|
142 | - $output .= "\t" . 'for ($this->scope[' . $name . '] = $_section' . $cnt . '[\'start\'], $_section' . $cnt . '[\'iteration\'] = 1; ' . '$_section' . $cnt . '[\'iteration\'] <= $_section' . $cnt . '[\'total\']; ' . '$this->scope[' . $name . '] += $_section' . $cnt . '[\'step\'], $_section' . $cnt . '[\'iteration\']++) {' . "\n"; |
|
143 | - $output .= "\t\t" . '$_section' . $cnt . '[\'rownum\'] = $_section' . $cnt . '[\'iteration\'];' . "\n"; |
|
144 | - $output .= "\t\t" . '$_section' . $cnt . '[\'index_prev\'] = $this->scope[' . $name . '] - $_section' . $cnt . '[\'step\'];' . "\n"; |
|
145 | - $output .= "\t\t" . '$_section' . $cnt . '[\'index_next\'] = $this->scope[' . $name . '] + $_section' . $cnt . '[\'step\'];' . "\n"; |
|
146 | - $output .= "\t\t" . '$_section' . $cnt . '[\'first\'] = ($_section' . $cnt . '[\'iteration\'] == 1);' . "\n"; |
|
147 | - $output .= "\t\t" . '$_section' . $cnt . '[\'last\'] = ($_section' . $cnt . '[\'iteration\'] == $_section' . $cnt . '[\'total\']);' . "\n"; |
|
148 | - |
|
149 | - $output .= Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN; |
|
150 | - |
|
151 | - $output .= "\n\t}\n} " . Compiler::PHP_CLOSE; |
|
140 | + $output .= ' if ($_section'.$cnt.'[\'total\'] == 0) {'."\n".' $_section'.$cnt.'[\'show\'] = false;'."\n".' }'."\n".'} else {'."\n".' $_section'.$cnt.'[\'total\'] = 0;'."\n}\n"; |
|
141 | + $output .= 'if ($_section'.$cnt.'[\'show\']) {'."\n"; |
|
142 | + $output .= "\t".'for ($this->scope['.$name.'] = $_section'.$cnt.'[\'start\'], $_section'.$cnt.'[\'iteration\'] = 1; '.'$_section'.$cnt.'[\'iteration\'] <= $_section'.$cnt.'[\'total\']; '.'$this->scope['.$name.'] += $_section'.$cnt.'[\'step\'], $_section'.$cnt.'[\'iteration\']++) {'."\n"; |
|
143 | + $output .= "\t\t".'$_section'.$cnt.'[\'rownum\'] = $_section'.$cnt.'[\'iteration\'];'."\n"; |
|
144 | + $output .= "\t\t".'$_section'.$cnt.'[\'index_prev\'] = $this->scope['.$name.'] - $_section'.$cnt.'[\'step\'];'."\n"; |
|
145 | + $output .= "\t\t".'$_section'.$cnt.'[\'index_next\'] = $this->scope['.$name.'] + $_section'.$cnt.'[\'step\'];'."\n"; |
|
146 | + $output .= "\t\t".'$_section'.$cnt.'[\'first\'] = ($_section'.$cnt.'[\'iteration\'] == 1);'."\n"; |
|
147 | + $output .= "\t\t".'$_section'.$cnt.'[\'last\'] = ($_section'.$cnt.'[\'iteration\'] == $_section'.$cnt.'[\'total\']);'."\n"; |
|
148 | + |
|
149 | + $output .= Compiler::PHP_CLOSE.$content.Compiler::PHP_OPEN; |
|
150 | + |
|
151 | + $output .= "\n\t}\n} ".Compiler::PHP_CLOSE; |
|
152 | 152 | |
153 | 153 | if (isset($params['hasElse'])) { |
154 | 154 | $output .= $params['hasElse']; |
@@ -35,158 +35,158 @@ |
||
35 | 35 | */ |
36 | 36 | class PluginFor extends BlockPlugin implements ICompilableBlock, IElseable |
37 | 37 | { |
38 | - public static $cnt = 0; |
|
39 | - |
|
40 | - /** |
|
41 | - * @param $name |
|
42 | - * @param $from |
|
43 | - * @param null $to |
|
44 | - * @param int $step |
|
45 | - * @param int $skip |
|
46 | - */ |
|
47 | - public function init($name, $from, $to = null, $step = 1, $skip = 0) |
|
48 | - { |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * @param Compiler $compiler |
|
53 | - * @param array $params |
|
54 | - * @param string $prepend |
|
55 | - * @param string $append |
|
56 | - * @param string $type |
|
57 | - * |
|
58 | - * @return string |
|
59 | - */ |
|
60 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
61 | - { |
|
62 | - // get block params and save the current template pointer to use it in the postProcessing method |
|
63 | - $currentBlock = &$compiler->getCurrentBlock(); |
|
64 | - $currentBlock['params']['tplPointer'] = $compiler->getPointer(); |
|
65 | - |
|
66 | - return ''; |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * @param Compiler $compiler |
|
71 | - * @param array $params |
|
72 | - * @param string $prepend |
|
73 | - * @param string $append |
|
74 | - * @param string $content |
|
75 | - * |
|
76 | - * @return string |
|
77 | - */ |
|
78 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
79 | - { |
|
80 | - $params = $compiler->getCompiledParams($params); |
|
81 | - $tpl = $compiler->getTemplateSource($params['tplPointer']); |
|
82 | - |
|
83 | - // assigns params |
|
84 | - $from = $params['from']; |
|
85 | - $name = $params['name']; |
|
86 | - $step = $params['step']; |
|
87 | - $to = $params['to']; |
|
88 | - |
|
89 | - // evaluates which global variables have to be computed |
|
90 | - $varName = '$dwoo.for.' . trim($name, '"\'') . '.'; |
|
91 | - $shortVarName = '$.for.' . trim($name, '"\'') . '.'; |
|
92 | - $usesAny = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false; |
|
93 | - $usesFirst = strpos($tpl, $varName . 'first') !== false || strpos($tpl, $shortVarName . 'first') !== false; |
|
94 | - $usesLast = strpos($tpl, $varName . 'last') !== false || strpos($tpl, $shortVarName . 'last') !== false; |
|
95 | - $usesIndex = strpos($tpl, $varName . 'index') !== false || strpos($tpl, $shortVarName . 'index') !== false; |
|
96 | - $usesIteration = $usesFirst || $usesLast || strpos($tpl, $varName . 'iteration') !== false || strpos($tpl, $shortVarName . 'iteration') !== false; |
|
97 | - $usesShow = strpos($tpl, $varName . 'show') !== false || strpos($tpl, $shortVarName . 'show') !== false; |
|
98 | - $usesTotal = $usesLast || strpos($tpl, $varName . 'total') !== false || strpos($tpl, $shortVarName . 'total') !== false; |
|
99 | - |
|
100 | - if (strpos($name, '$this->scope[') !== false) { |
|
101 | - $usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true; |
|
102 | - } |
|
103 | - |
|
104 | - // gets foreach id |
|
105 | - $cnt = self::$cnt ++; |
|
106 | - |
|
107 | - // builds pre processing output for |
|
108 | - $out = Compiler::PHP_OPEN . "\n" . '$_for' . $cnt . '_from = ' . $from . ';' . "\n" . '$_for' . $cnt . '_to = ' . $to . ';' . "\n" . '$_for' . $cnt . '_step = abs(' . $step . ');' . "\n" . 'if (is_numeric($_for' . $cnt . '_from) && !is_numeric($_for' . $cnt . '_to)) { $this->triggerError(\'For requires the <em>to</em> parameter when using a numerical <em>from</em>\'); }' . "\n" . '$tmp_shows = $this->isArray($_for' . $cnt . '_from, true) || (is_numeric($_for' . $cnt . '_from) && (abs(($_for' . $cnt . '_from - $_for' . $cnt . '_to)/$_for' . $cnt . '_step) !== 0 || $_for' . $cnt . '_from == $_for' . $cnt . '_to));'; |
|
109 | - // adds for properties |
|
110 | - if ($usesAny) { |
|
111 | - $out .= "\n" . '$this->globals["for"][' . $name . '] = array' . "\n("; |
|
112 | - if ($usesIndex) { |
|
113 | - $out .= "\n\t" . '"index" => 0,'; |
|
114 | - } |
|
115 | - if ($usesIteration) { |
|
116 | - $out .= "\n\t" . '"iteration" => 1,'; |
|
117 | - } |
|
118 | - if ($usesFirst) { |
|
119 | - $out .= "\n\t" . '"first" => null,'; |
|
120 | - } |
|
121 | - if ($usesLast) { |
|
122 | - $out .= "\n\t" . '"last" => null,'; |
|
123 | - } |
|
124 | - if ($usesShow) { |
|
125 | - $out .= "\n\t" . '"show" => $tmp_shows,'; |
|
126 | - } |
|
127 | - if ($usesTotal) { |
|
128 | - $out .= "\n\t" . '"total" => $this->isArray($_for' . $cnt . '_from) ? floor($this->count($_for' . $cnt . '_from) / $_for' . $cnt . '_step) : (is_numeric($_for' . $cnt . '_from) ? abs(($_for' . $cnt . '_to + 1 - $_for' . $cnt . '_from)/$_for' . $cnt . '_step) : 0),'; |
|
129 | - } |
|
130 | - $out .= "\n);\n" . '$_for' . $cnt . '_glob =& $this->globals["for"][' . $name . '];'; |
|
131 | - } |
|
132 | - // checks if for must be looped |
|
133 | - $out .= "\n" . 'if ($tmp_shows)' . "\n{"; |
|
134 | - // set from/to to correct values if an array was given |
|
135 | - $out .= "\n\t" . 'if ($this->isArray($_for' . $cnt . '_from' . (isset($params['hasElse']) ? ', true' : '') . ') == true) { |
|
38 | + public static $cnt = 0; |
|
39 | + |
|
40 | + /** |
|
41 | + * @param $name |
|
42 | + * @param $from |
|
43 | + * @param null $to |
|
44 | + * @param int $step |
|
45 | + * @param int $skip |
|
46 | + */ |
|
47 | + public function init($name, $from, $to = null, $step = 1, $skip = 0) |
|
48 | + { |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * @param Compiler $compiler |
|
53 | + * @param array $params |
|
54 | + * @param string $prepend |
|
55 | + * @param string $append |
|
56 | + * @param string $type |
|
57 | + * |
|
58 | + * @return string |
|
59 | + */ |
|
60 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
61 | + { |
|
62 | + // get block params and save the current template pointer to use it in the postProcessing method |
|
63 | + $currentBlock = &$compiler->getCurrentBlock(); |
|
64 | + $currentBlock['params']['tplPointer'] = $compiler->getPointer(); |
|
65 | + |
|
66 | + return ''; |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * @param Compiler $compiler |
|
71 | + * @param array $params |
|
72 | + * @param string $prepend |
|
73 | + * @param string $append |
|
74 | + * @param string $content |
|
75 | + * |
|
76 | + * @return string |
|
77 | + */ |
|
78 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
79 | + { |
|
80 | + $params = $compiler->getCompiledParams($params); |
|
81 | + $tpl = $compiler->getTemplateSource($params['tplPointer']); |
|
82 | + |
|
83 | + // assigns params |
|
84 | + $from = $params['from']; |
|
85 | + $name = $params['name']; |
|
86 | + $step = $params['step']; |
|
87 | + $to = $params['to']; |
|
88 | + |
|
89 | + // evaluates which global variables have to be computed |
|
90 | + $varName = '$dwoo.for.' . trim($name, '"\'') . '.'; |
|
91 | + $shortVarName = '$.for.' . trim($name, '"\'') . '.'; |
|
92 | + $usesAny = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false; |
|
93 | + $usesFirst = strpos($tpl, $varName . 'first') !== false || strpos($tpl, $shortVarName . 'first') !== false; |
|
94 | + $usesLast = strpos($tpl, $varName . 'last') !== false || strpos($tpl, $shortVarName . 'last') !== false; |
|
95 | + $usesIndex = strpos($tpl, $varName . 'index') !== false || strpos($tpl, $shortVarName . 'index') !== false; |
|
96 | + $usesIteration = $usesFirst || $usesLast || strpos($tpl, $varName . 'iteration') !== false || strpos($tpl, $shortVarName . 'iteration') !== false; |
|
97 | + $usesShow = strpos($tpl, $varName . 'show') !== false || strpos($tpl, $shortVarName . 'show') !== false; |
|
98 | + $usesTotal = $usesLast || strpos($tpl, $varName . 'total') !== false || strpos($tpl, $shortVarName . 'total') !== false; |
|
99 | + |
|
100 | + if (strpos($name, '$this->scope[') !== false) { |
|
101 | + $usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true; |
|
102 | + } |
|
103 | + |
|
104 | + // gets foreach id |
|
105 | + $cnt = self::$cnt ++; |
|
106 | + |
|
107 | + // builds pre processing output for |
|
108 | + $out = Compiler::PHP_OPEN . "\n" . '$_for' . $cnt . '_from = ' . $from . ';' . "\n" . '$_for' . $cnt . '_to = ' . $to . ';' . "\n" . '$_for' . $cnt . '_step = abs(' . $step . ');' . "\n" . 'if (is_numeric($_for' . $cnt . '_from) && !is_numeric($_for' . $cnt . '_to)) { $this->triggerError(\'For requires the <em>to</em> parameter when using a numerical <em>from</em>\'); }' . "\n" . '$tmp_shows = $this->isArray($_for' . $cnt . '_from, true) || (is_numeric($_for' . $cnt . '_from) && (abs(($_for' . $cnt . '_from - $_for' . $cnt . '_to)/$_for' . $cnt . '_step) !== 0 || $_for' . $cnt . '_from == $_for' . $cnt . '_to));'; |
|
109 | + // adds for properties |
|
110 | + if ($usesAny) { |
|
111 | + $out .= "\n" . '$this->globals["for"][' . $name . '] = array' . "\n("; |
|
112 | + if ($usesIndex) { |
|
113 | + $out .= "\n\t" . '"index" => 0,'; |
|
114 | + } |
|
115 | + if ($usesIteration) { |
|
116 | + $out .= "\n\t" . '"iteration" => 1,'; |
|
117 | + } |
|
118 | + if ($usesFirst) { |
|
119 | + $out .= "\n\t" . '"first" => null,'; |
|
120 | + } |
|
121 | + if ($usesLast) { |
|
122 | + $out .= "\n\t" . '"last" => null,'; |
|
123 | + } |
|
124 | + if ($usesShow) { |
|
125 | + $out .= "\n\t" . '"show" => $tmp_shows,'; |
|
126 | + } |
|
127 | + if ($usesTotal) { |
|
128 | + $out .= "\n\t" . '"total" => $this->isArray($_for' . $cnt . '_from) ? floor($this->count($_for' . $cnt . '_from) / $_for' . $cnt . '_step) : (is_numeric($_for' . $cnt . '_from) ? abs(($_for' . $cnt . '_to + 1 - $_for' . $cnt . '_from)/$_for' . $cnt . '_step) : 0),'; |
|
129 | + } |
|
130 | + $out .= "\n);\n" . '$_for' . $cnt . '_glob =& $this->globals["for"][' . $name . '];'; |
|
131 | + } |
|
132 | + // checks if for must be looped |
|
133 | + $out .= "\n" . 'if ($tmp_shows)' . "\n{"; |
|
134 | + // set from/to to correct values if an array was given |
|
135 | + $out .= "\n\t" . 'if ($this->isArray($_for' . $cnt . '_from' . (isset($params['hasElse']) ? ', true' : '') . ') == true) { |
|
136 | 136 | $_for' . $cnt . '_to = is_numeric($_for' . $cnt . '_to) ? $_for' . $cnt . '_to - $_for' . $cnt . '_step : $this->count($_for' . $cnt . '_from) - 1; |
137 | 137 | $_for' . $cnt . '_from = 0; |
138 | 138 | }'; |
139 | 139 | |
140 | - // if input are pure numbers it shouldn't reorder them, if it's variables it gets too messy though so in that case a counter should be used |
|
141 | - $reverse = false; |
|
142 | - $condition = '<='; |
|
143 | - $incrementer = '+'; |
|
144 | - |
|
145 | - if (preg_match('{^(["\']?)([0-9]+)\1$}', $from, $mN1) && preg_match('{^(["\']?)([0-9]+)\1$}', $to, $mN2)) { |
|
146 | - $from = (int)$mN1[2]; |
|
147 | - $to = (int)$mN2[2]; |
|
148 | - if ($from > $to) { |
|
149 | - $reverse = true; |
|
150 | - $condition = '>='; |
|
151 | - $incrementer = '-'; |
|
152 | - } |
|
153 | - } |
|
154 | - |
|
155 | - // reverse from and to if needed |
|
156 | - if (!$reverse) { |
|
157 | - $out .= "\n\t" . 'if ($_for' . $cnt . '_from > $_for' . $cnt . '_to) { |
|
140 | + // if input are pure numbers it shouldn't reorder them, if it's variables it gets too messy though so in that case a counter should be used |
|
141 | + $reverse = false; |
|
142 | + $condition = '<='; |
|
143 | + $incrementer = '+'; |
|
144 | + |
|
145 | + if (preg_match('{^(["\']?)([0-9]+)\1$}', $from, $mN1) && preg_match('{^(["\']?)([0-9]+)\1$}', $to, $mN2)) { |
|
146 | + $from = (int)$mN1[2]; |
|
147 | + $to = (int)$mN2[2]; |
|
148 | + if ($from > $to) { |
|
149 | + $reverse = true; |
|
150 | + $condition = '>='; |
|
151 | + $incrementer = '-'; |
|
152 | + } |
|
153 | + } |
|
154 | + |
|
155 | + // reverse from and to if needed |
|
156 | + if (!$reverse) { |
|
157 | + $out .= "\n\t" . 'if ($_for' . $cnt . '_from > $_for' . $cnt . '_to) { |
|
158 | 158 | $tmp = $_for' . $cnt . '_from; |
159 | 159 | $_for' . $cnt . '_from = $_for' . $cnt . '_to; |
160 | 160 | $_for' . $cnt . '_to = $tmp; |
161 | 161 | }'; |
162 | - } |
|
163 | - |
|
164 | - $out .= "\n\t" . 'for ($this->scope[' . $name . '] = $_for' . $cnt . '_from; $this->scope[' . $name . '] ' . $condition . ' $_for' . $cnt . '_to; $this->scope[' . $name . '] ' . $incrementer . '= $_for' . $cnt . '_step)' . "\n\t{"; |
|
165 | - // updates properties |
|
166 | - if ($usesIndex) { |
|
167 | - $out .= "\n\t\t" . '$_for' . $cnt . '_glob["index"] = $this->scope[' . $name . '];'; |
|
168 | - } |
|
169 | - if ($usesFirst) { |
|
170 | - $out .= "\n\t\t" . '$_for' . $cnt . '_glob["first"] = (string) ($_for' . $cnt . '_glob["iteration"] === 1);'; |
|
171 | - } |
|
172 | - if ($usesLast) { |
|
173 | - $out .= "\n\t\t" . '$_for' . $cnt . '_glob["last"] = (string) ($_for' . $cnt . '_glob["iteration"] === $_for' . $cnt . '_glob["total"]);'; |
|
174 | - } |
|
175 | - $out .= "\n/* -- for start output */\n" . Compiler::PHP_CLOSE; |
|
176 | - |
|
177 | - // build post processing output and cache it |
|
178 | - $postOut = Compiler::PHP_OPEN . '/* -- for end output */'; |
|
179 | - // update properties |
|
180 | - if ($usesIteration) { |
|
181 | - $postOut .= "\n\t\t" . '$_for' . $cnt . '_glob["iteration"]+=1;'; |
|
182 | - } |
|
183 | - // end loop |
|
184 | - $postOut .= "\n\t}\n}\n" . Compiler::PHP_CLOSE; |
|
185 | - |
|
186 | - if (isset($params['hasElse'])) { |
|
187 | - $postOut .= $params['hasElse']; |
|
188 | - } |
|
189 | - |
|
190 | - return $out . $content . $postOut; |
|
191 | - } |
|
162 | + } |
|
163 | + |
|
164 | + $out .= "\n\t" . 'for ($this->scope[' . $name . '] = $_for' . $cnt . '_from; $this->scope[' . $name . '] ' . $condition . ' $_for' . $cnt . '_to; $this->scope[' . $name . '] ' . $incrementer . '= $_for' . $cnt . '_step)' . "\n\t{"; |
|
165 | + // updates properties |
|
166 | + if ($usesIndex) { |
|
167 | + $out .= "\n\t\t" . '$_for' . $cnt . '_glob["index"] = $this->scope[' . $name . '];'; |
|
168 | + } |
|
169 | + if ($usesFirst) { |
|
170 | + $out .= "\n\t\t" . '$_for' . $cnt . '_glob["first"] = (string) ($_for' . $cnt . '_glob["iteration"] === 1);'; |
|
171 | + } |
|
172 | + if ($usesLast) { |
|
173 | + $out .= "\n\t\t" . '$_for' . $cnt . '_glob["last"] = (string) ($_for' . $cnt . '_glob["iteration"] === $_for' . $cnt . '_glob["total"]);'; |
|
174 | + } |
|
175 | + $out .= "\n/* -- for start output */\n" . Compiler::PHP_CLOSE; |
|
176 | + |
|
177 | + // build post processing output and cache it |
|
178 | + $postOut = Compiler::PHP_OPEN . '/* -- for end output */'; |
|
179 | + // update properties |
|
180 | + if ($usesIteration) { |
|
181 | + $postOut .= "\n\t\t" . '$_for' . $cnt . '_glob["iteration"]+=1;'; |
|
182 | + } |
|
183 | + // end loop |
|
184 | + $postOut .= "\n\t}\n}\n" . Compiler::PHP_CLOSE; |
|
185 | + |
|
186 | + if (isset($params['hasElse'])) { |
|
187 | + $postOut .= $params['hasElse']; |
|
188 | + } |
|
189 | + |
|
190 | + return $out . $content . $postOut; |
|
191 | + } |
|
192 | 192 | } |
@@ -87,54 +87,54 @@ discard block |
||
87 | 87 | $to = $params['to']; |
88 | 88 | |
89 | 89 | // evaluates which global variables have to be computed |
90 | - $varName = '$dwoo.for.' . trim($name, '"\'') . '.'; |
|
91 | - $shortVarName = '$.for.' . trim($name, '"\'') . '.'; |
|
90 | + $varName = '$dwoo.for.'.trim($name, '"\'').'.'; |
|
91 | + $shortVarName = '$.for.'.trim($name, '"\'').'.'; |
|
92 | 92 | $usesAny = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false; |
93 | - $usesFirst = strpos($tpl, $varName . 'first') !== false || strpos($tpl, $shortVarName . 'first') !== false; |
|
94 | - $usesLast = strpos($tpl, $varName . 'last') !== false || strpos($tpl, $shortVarName . 'last') !== false; |
|
95 | - $usesIndex = strpos($tpl, $varName . 'index') !== false || strpos($tpl, $shortVarName . 'index') !== false; |
|
96 | - $usesIteration = $usesFirst || $usesLast || strpos($tpl, $varName . 'iteration') !== false || strpos($tpl, $shortVarName . 'iteration') !== false; |
|
97 | - $usesShow = strpos($tpl, $varName . 'show') !== false || strpos($tpl, $shortVarName . 'show') !== false; |
|
98 | - $usesTotal = $usesLast || strpos($tpl, $varName . 'total') !== false || strpos($tpl, $shortVarName . 'total') !== false; |
|
93 | + $usesFirst = strpos($tpl, $varName.'first') !== false || strpos($tpl, $shortVarName.'first') !== false; |
|
94 | + $usesLast = strpos($tpl, $varName.'last') !== false || strpos($tpl, $shortVarName.'last') !== false; |
|
95 | + $usesIndex = strpos($tpl, $varName.'index') !== false || strpos($tpl, $shortVarName.'index') !== false; |
|
96 | + $usesIteration = $usesFirst || $usesLast || strpos($tpl, $varName.'iteration') !== false || strpos($tpl, $shortVarName.'iteration') !== false; |
|
97 | + $usesShow = strpos($tpl, $varName.'show') !== false || strpos($tpl, $shortVarName.'show') !== false; |
|
98 | + $usesTotal = $usesLast || strpos($tpl, $varName.'total') !== false || strpos($tpl, $shortVarName.'total') !== false; |
|
99 | 99 | |
100 | 100 | if (strpos($name, '$this->scope[') !== false) { |
101 | 101 | $usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true; |
102 | 102 | } |
103 | 103 | |
104 | 104 | // gets foreach id |
105 | - $cnt = self::$cnt ++; |
|
105 | + $cnt = self::$cnt++; |
|
106 | 106 | |
107 | 107 | // builds pre processing output for |
108 | - $out = Compiler::PHP_OPEN . "\n" . '$_for' . $cnt . '_from = ' . $from . ';' . "\n" . '$_for' . $cnt . '_to = ' . $to . ';' . "\n" . '$_for' . $cnt . '_step = abs(' . $step . ');' . "\n" . 'if (is_numeric($_for' . $cnt . '_from) && !is_numeric($_for' . $cnt . '_to)) { $this->triggerError(\'For requires the <em>to</em> parameter when using a numerical <em>from</em>\'); }' . "\n" . '$tmp_shows = $this->isArray($_for' . $cnt . '_from, true) || (is_numeric($_for' . $cnt . '_from) && (abs(($_for' . $cnt . '_from - $_for' . $cnt . '_to)/$_for' . $cnt . '_step) !== 0 || $_for' . $cnt . '_from == $_for' . $cnt . '_to));'; |
|
108 | + $out = Compiler::PHP_OPEN."\n".'$_for'.$cnt.'_from = '.$from.';'."\n".'$_for'.$cnt.'_to = '.$to.';'."\n".'$_for'.$cnt.'_step = abs('.$step.');'."\n".'if (is_numeric($_for'.$cnt.'_from) && !is_numeric($_for'.$cnt.'_to)) { $this->triggerError(\'For requires the <em>to</em> parameter when using a numerical <em>from</em>\'); }'."\n".'$tmp_shows = $this->isArray($_for'.$cnt.'_from, true) || (is_numeric($_for'.$cnt.'_from) && (abs(($_for'.$cnt.'_from - $_for'.$cnt.'_to)/$_for'.$cnt.'_step) !== 0 || $_for'.$cnt.'_from == $_for'.$cnt.'_to));'; |
|
109 | 109 | // adds for properties |
110 | 110 | if ($usesAny) { |
111 | - $out .= "\n" . '$this->globals["for"][' . $name . '] = array' . "\n("; |
|
111 | + $out .= "\n".'$this->globals["for"]['.$name.'] = array'."\n("; |
|
112 | 112 | if ($usesIndex) { |
113 | - $out .= "\n\t" . '"index" => 0,'; |
|
113 | + $out .= "\n\t".'"index" => 0,'; |
|
114 | 114 | } |
115 | 115 | if ($usesIteration) { |
116 | - $out .= "\n\t" . '"iteration" => 1,'; |
|
116 | + $out .= "\n\t".'"iteration" => 1,'; |
|
117 | 117 | } |
118 | 118 | if ($usesFirst) { |
119 | - $out .= "\n\t" . '"first" => null,'; |
|
119 | + $out .= "\n\t".'"first" => null,'; |
|
120 | 120 | } |
121 | 121 | if ($usesLast) { |
122 | - $out .= "\n\t" . '"last" => null,'; |
|
122 | + $out .= "\n\t".'"last" => null,'; |
|
123 | 123 | } |
124 | 124 | if ($usesShow) { |
125 | - $out .= "\n\t" . '"show" => $tmp_shows,'; |
|
125 | + $out .= "\n\t".'"show" => $tmp_shows,'; |
|
126 | 126 | } |
127 | 127 | if ($usesTotal) { |
128 | - $out .= "\n\t" . '"total" => $this->isArray($_for' . $cnt . '_from) ? floor($this->count($_for' . $cnt . '_from) / $_for' . $cnt . '_step) : (is_numeric($_for' . $cnt . '_from) ? abs(($_for' . $cnt . '_to + 1 - $_for' . $cnt . '_from)/$_for' . $cnt . '_step) : 0),'; |
|
128 | + $out .= "\n\t".'"total" => $this->isArray($_for'.$cnt.'_from) ? floor($this->count($_for'.$cnt.'_from) / $_for'.$cnt.'_step) : (is_numeric($_for'.$cnt.'_from) ? abs(($_for'.$cnt.'_to + 1 - $_for'.$cnt.'_from)/$_for'.$cnt.'_step) : 0),'; |
|
129 | 129 | } |
130 | - $out .= "\n);\n" . '$_for' . $cnt . '_glob =& $this->globals["for"][' . $name . '];'; |
|
130 | + $out .= "\n);\n".'$_for'.$cnt.'_glob =& $this->globals["for"]['.$name.'];'; |
|
131 | 131 | } |
132 | 132 | // checks if for must be looped |
133 | - $out .= "\n" . 'if ($tmp_shows)' . "\n{"; |
|
133 | + $out .= "\n".'if ($tmp_shows)'."\n{"; |
|
134 | 134 | // set from/to to correct values if an array was given |
135 | - $out .= "\n\t" . 'if ($this->isArray($_for' . $cnt . '_from' . (isset($params['hasElse']) ? ', true' : '') . ') == true) { |
|
136 | - $_for' . $cnt . '_to = is_numeric($_for' . $cnt . '_to) ? $_for' . $cnt . '_to - $_for' . $cnt . '_step : $this->count($_for' . $cnt . '_from) - 1; |
|
137 | - $_for' . $cnt . '_from = 0; |
|
135 | + $out .= "\n\t".'if ($this->isArray($_for'.$cnt.'_from'.(isset($params['hasElse']) ? ', true' : '').') == true) { |
|
136 | + $_for' . $cnt.'_to = is_numeric($_for'.$cnt.'_to) ? $_for'.$cnt.'_to - $_for'.$cnt.'_step : $this->count($_for'.$cnt.'_from) - 1; |
|
137 | + $_for' . $cnt.'_from = 0; |
|
138 | 138 | }'; |
139 | 139 | |
140 | 140 | // if input are pure numbers it shouldn't reorder them, if it's variables it gets too messy though so in that case a counter should be used |
@@ -143,8 +143,8 @@ discard block |
||
143 | 143 | $incrementer = '+'; |
144 | 144 | |
145 | 145 | if (preg_match('{^(["\']?)([0-9]+)\1$}', $from, $mN1) && preg_match('{^(["\']?)([0-9]+)\1$}', $to, $mN2)) { |
146 | - $from = (int)$mN1[2]; |
|
147 | - $to = (int)$mN2[2]; |
|
146 | + $from = (int) $mN1[2]; |
|
147 | + $to = (int) $mN2[2]; |
|
148 | 148 | if ($from > $to) { |
149 | 149 | $reverse = true; |
150 | 150 | $condition = '>='; |
@@ -154,39 +154,39 @@ discard block |
||
154 | 154 | |
155 | 155 | // reverse from and to if needed |
156 | 156 | if (!$reverse) { |
157 | - $out .= "\n\t" . 'if ($_for' . $cnt . '_from > $_for' . $cnt . '_to) { |
|
158 | - $tmp = $_for' . $cnt . '_from; |
|
159 | - $_for' . $cnt . '_from = $_for' . $cnt . '_to; |
|
160 | - $_for' . $cnt . '_to = $tmp; |
|
157 | + $out .= "\n\t".'if ($_for'.$cnt.'_from > $_for'.$cnt.'_to) { |
|
158 | + $tmp = $_for' . $cnt.'_from; |
|
159 | + $_for' . $cnt.'_from = $_for'.$cnt.'_to; |
|
160 | + $_for' . $cnt.'_to = $tmp; |
|
161 | 161 | }'; |
162 | 162 | } |
163 | 163 | |
164 | - $out .= "\n\t" . 'for ($this->scope[' . $name . '] = $_for' . $cnt . '_from; $this->scope[' . $name . '] ' . $condition . ' $_for' . $cnt . '_to; $this->scope[' . $name . '] ' . $incrementer . '= $_for' . $cnt . '_step)' . "\n\t{"; |
|
164 | + $out .= "\n\t".'for ($this->scope['.$name.'] = $_for'.$cnt.'_from; $this->scope['.$name.'] '.$condition.' $_for'.$cnt.'_to; $this->scope['.$name.'] '.$incrementer.'= $_for'.$cnt.'_step)'."\n\t{"; |
|
165 | 165 | // updates properties |
166 | 166 | if ($usesIndex) { |
167 | - $out .= "\n\t\t" . '$_for' . $cnt . '_glob["index"] = $this->scope[' . $name . '];'; |
|
167 | + $out .= "\n\t\t".'$_for'.$cnt.'_glob["index"] = $this->scope['.$name.'];'; |
|
168 | 168 | } |
169 | 169 | if ($usesFirst) { |
170 | - $out .= "\n\t\t" . '$_for' . $cnt . '_glob["first"] = (string) ($_for' . $cnt . '_glob["iteration"] === 1);'; |
|
170 | + $out .= "\n\t\t".'$_for'.$cnt.'_glob["first"] = (string) ($_for'.$cnt.'_glob["iteration"] === 1);'; |
|
171 | 171 | } |
172 | 172 | if ($usesLast) { |
173 | - $out .= "\n\t\t" . '$_for' . $cnt . '_glob["last"] = (string) ($_for' . $cnt . '_glob["iteration"] === $_for' . $cnt . '_glob["total"]);'; |
|
173 | + $out .= "\n\t\t".'$_for'.$cnt.'_glob["last"] = (string) ($_for'.$cnt.'_glob["iteration"] === $_for'.$cnt.'_glob["total"]);'; |
|
174 | 174 | } |
175 | - $out .= "\n/* -- for start output */\n" . Compiler::PHP_CLOSE; |
|
175 | + $out .= "\n/* -- for start output */\n".Compiler::PHP_CLOSE; |
|
176 | 176 | |
177 | 177 | // build post processing output and cache it |
178 | - $postOut = Compiler::PHP_OPEN . '/* -- for end output */'; |
|
178 | + $postOut = Compiler::PHP_OPEN.'/* -- for end output */'; |
|
179 | 179 | // update properties |
180 | 180 | if ($usesIteration) { |
181 | - $postOut .= "\n\t\t" . '$_for' . $cnt . '_glob["iteration"]+=1;'; |
|
181 | + $postOut .= "\n\t\t".'$_for'.$cnt.'_glob["iteration"]+=1;'; |
|
182 | 182 | } |
183 | 183 | // end loop |
184 | - $postOut .= "\n\t}\n}\n" . Compiler::PHP_CLOSE; |
|
184 | + $postOut .= "\n\t}\n}\n".Compiler::PHP_CLOSE; |
|
185 | 185 | |
186 | 186 | if (isset($params['hasElse'])) { |
187 | 187 | $postOut .= $params['hasElse']; |
188 | 188 | } |
189 | 189 | |
190 | - return $out . $content . $postOut; |
|
190 | + return $out.$content.$postOut; |
|
191 | 191 | } |
192 | 192 | } |
@@ -26,35 +26,35 @@ |
||
26 | 26 | */ |
27 | 27 | final class PluginTopLevelBlock extends BlockPlugin implements ICompilableBlock |
28 | 28 | { |
29 | - public function init() |
|
30 | - { |
|
31 | - } |
|
29 | + public function init() |
|
30 | + { |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * @param Compiler $compiler |
|
35 | - * @param array $params |
|
36 | - * @param string $prepend |
|
37 | - * @param string $append |
|
38 | - * @param string $type |
|
39 | - * |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
43 | - { |
|
44 | - return '/* end template head */ ob_start(); /* template body */ ' . Compiler::PHP_CLOSE; |
|
45 | - } |
|
33 | + /** |
|
34 | + * @param Compiler $compiler |
|
35 | + * @param array $params |
|
36 | + * @param string $prepend |
|
37 | + * @param string $append |
|
38 | + * @param string $type |
|
39 | + * |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
43 | + { |
|
44 | + return '/* end template head */ ob_start(); /* template body */ ' . Compiler::PHP_CLOSE; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * @param Compiler $compiler |
|
49 | - * @param array $params |
|
50 | - * @param string $prepend |
|
51 | - * @param string $append |
|
52 | - * @param string $content |
|
53 | - * |
|
54 | - * @return string |
|
55 | - */ |
|
56 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
57 | - { |
|
58 | - return $content . Compiler::PHP_OPEN . ' /* end template body */' . "\n" . 'return $this->buffer . ob_get_clean();'; |
|
59 | - } |
|
47 | + /** |
|
48 | + * @param Compiler $compiler |
|
49 | + * @param array $params |
|
50 | + * @param string $prepend |
|
51 | + * @param string $append |
|
52 | + * @param string $content |
|
53 | + * |
|
54 | + * @return string |
|
55 | + */ |
|
56 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
57 | + { |
|
58 | + return $content . Compiler::PHP_OPEN . ' /* end template body */' . "\n" . 'return $this->buffer . ob_get_clean();'; |
|
59 | + } |
|
60 | 60 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
43 | 43 | { |
44 | - return '/* end template head */ ob_start(); /* template body */ ' . Compiler::PHP_CLOSE; |
|
44 | + return '/* end template head */ ob_start(); /* template body */ '.Compiler::PHP_CLOSE; |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -55,6 +55,6 @@ discard block |
||
55 | 55 | */ |
56 | 56 | public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
57 | 57 | { |
58 | - return $content . Compiler::PHP_OPEN . ' /* end template body */' . "\n" . 'return $this->buffer . ob_get_clean();'; |
|
58 | + return $content.Compiler::PHP_OPEN.' /* end template body */'."\n".'return $this->buffer . ob_get_clean();'; |
|
59 | 59 | } |
60 | 60 | } |