@@ -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 | } |
@@ -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(); |
@@ -89,7 +89,7 @@ |
||
89 | 89 | } |
90 | 90 | |
91 | 91 | $block = &$compiler->getCurrentBlock(); |
92 | - $block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
92 | + $block['params']['hasElse'] = Compiler::PHP_OPEN."else {\n".Compiler::PHP_CLOSE.$content.Compiler::PHP_OPEN."\n}".Compiler::PHP_CLOSE; |
|
93 | 93 | |
94 | 94 | return ''; |
95 | 95 | } |
@@ -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']; |
@@ -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 | } |
@@ -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 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | { |
79 | 79 | // textarea, pre, code tags and comments are to be left alone to avoid any non-wanted whitespace inside them so it just outputs them as they were |
80 | 80 | if (substr($input[1], 0, 9) == '<textarea' || substr($input[1], 0, 4) == '<pre' || substr($input[1], 0, 5) == '<code' || substr($input[1], 0, 4) == '<!--' || substr($input[1], 0, 9) == '<![CDATA[') { |
81 | - return $input[1] . $input[3]; |
|
81 | + return $input[1].$input[3]; |
|
82 | 82 | } |
83 | 83 | // closing textarea, code and pre tags and self-closed tags (i.e. <br />) are printed as singleTags because we didn't use openTag for the formers and the latter is a single tag |
84 | 84 | if (substr($input[1], 0, 10) == '</textarea' || substr($input[1], 0, 5) == '</pre' || substr($input[1], 0, 6) == '</code' || substr($input[1], - 2) == '/>') { |
@@ -104,20 +104,20 @@ discard block |
||
104 | 104 | */ |
105 | 105 | protected static function openTag($tag, $add, $whitespace) |
106 | 106 | { |
107 | - $tabs = str_pad('', self::$tabCount ++, "\t"); |
|
107 | + $tabs = str_pad('', self::$tabCount++, "\t"); |
|
108 | 108 | |
109 | 109 | if (preg_match('#^<(a|label|option|textarea|h1|h2|h3|h4|h5|h6|strong|b|em|i|abbr|acronym|cite|span|sub|sup|u|s|title)(?: [^>]*|)>#', $tag)) { |
110 | 110 | // if it's one of those tag it's inline so it does not require a leading line break |
111 | - $result = $tag . $whitespace . str_replace("\n", "\n" . $tabs, $add); |
|
111 | + $result = $tag.$whitespace.str_replace("\n", "\n".$tabs, $add); |
|
112 | 112 | } elseif (substr($tag, 0, 9) == '<!DOCTYPE') { |
113 | 113 | // it's the doctype declaration so no line break here either |
114 | - $result = $tabs . $tag; |
|
114 | + $result = $tabs.$tag; |
|
115 | 115 | } else { |
116 | 116 | // normal block tag |
117 | - $result = "\n" . $tabs . $tag; |
|
117 | + $result = "\n".$tabs.$tag; |
|
118 | 118 | |
119 | 119 | if (!empty($add)) { |
120 | - $result .= "\n" . $tabs . "\t" . str_replace("\n", "\n\t" . $tabs, $add); |
|
120 | + $result .= "\n".$tabs."\t".str_replace("\n", "\n\t".$tabs, $add); |
|
121 | 121 | } |
122 | 122 | } |
123 | 123 | |
@@ -141,12 +141,12 @@ discard block |
||
141 | 141 | |
142 | 142 | // if it's one of those tag it's inline so it does not require a leading line break |
143 | 143 | if (preg_match('#^</(a|label|option|textarea|h1|h2|h3|h4|h5|h6|strong|b|em|i|abbr|acronym|cite|span|sub|sup|u|s|title)>#', $tag)) { |
144 | - $result = $tag . $whitespace . str_replace("\n", "\n" . $tabs, $add); |
|
144 | + $result = $tag.$whitespace.str_replace("\n", "\n".$tabs, $add); |
|
145 | 145 | } else { |
146 | - $result = "\n" . $tabs . $tag; |
|
146 | + $result = "\n".$tabs.$tag; |
|
147 | 147 | |
148 | 148 | if (!empty($add)) { |
149 | - $result .= "\n" . $tabs . "\t" . str_replace("\n", "\n\t" . $tabs, $add); |
|
149 | + $result .= "\n".$tabs."\t".str_replace("\n", "\n\t".$tabs, $add); |
|
150 | 150 | } |
151 | 151 | } |
152 | 152 | |
@@ -170,16 +170,16 @@ discard block |
||
170 | 170 | // if it's img, br it's inline so it does not require a leading line break |
171 | 171 | // if it's a closing textarea, code or pre tag, it does not require a leading line break either or it creates whitespace at the end of those blocks |
172 | 172 | if (preg_match('#^<(img|br|/textarea|/pre|/code)(?: [^>]*|)>#', $tag)) { |
173 | - $result = $tag . $whitespace; |
|
173 | + $result = $tag.$whitespace; |
|
174 | 174 | |
175 | 175 | if (!empty($add)) { |
176 | - $result .= str_replace("\n", "\n" . $tabs, $add); |
|
176 | + $result .= str_replace("\n", "\n".$tabs, $add); |
|
177 | 177 | } |
178 | 178 | } else { |
179 | - $result = "\n" . $tabs . $tag; |
|
179 | + $result = "\n".$tabs.$tag; |
|
180 | 180 | |
181 | 181 | if (!empty($add)) { |
182 | - $result .= "\n" . $tabs . str_replace("\n", "\n" . $tabs, $add); |
|
182 | + $result .= "\n".$tabs.str_replace("\n", "\n".$tabs, $add); |
|
183 | 183 | } |
184 | 184 | } |
185 | 185 |
@@ -61,14 +61,14 @@ discard block |
||
61 | 61 | */ |
62 | 62 | public function __construct($cacheDir) |
63 | 63 | { |
64 | - $this->corePluginDir = __DIR__ . DIRECTORY_SEPARATOR . 'Plugins'; |
|
65 | - $this->cacheDir = rtrim($cacheDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; |
|
64 | + $this->corePluginDir = __DIR__.DIRECTORY_SEPARATOR.'Plugins'; |
|
65 | + $this->cacheDir = rtrim($cacheDir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; |
|
66 | 66 | |
67 | 67 | // include class paths or rebuild paths if the cache file isn't there |
68 | - $cacheFile = $this->cacheDir . 'classpath.cache.d' . Core::RELEASE_TAG . '.php'; |
|
68 | + $cacheFile = $this->cacheDir.'classpath.cache.d'.Core::RELEASE_TAG.'.php'; |
|
69 | 69 | if (file_exists($cacheFile)) { |
70 | 70 | $classpath = file_get_contents($cacheFile); |
71 | - $this->classPath = unserialize($classpath) + $this->classPath; |
|
71 | + $this->classPath = unserialize($classpath)+$this->classPath; |
|
72 | 72 | } else { |
73 | 73 | $this->rebuildClassPathCache($this->corePluginDir, $cacheFile); |
74 | 74 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | } |
91 | 91 | |
92 | 92 | // iterates over all files/folders |
93 | - $list = glob(rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '*'); |
|
93 | + $list = glob(rtrim($path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'*'); |
|
94 | 94 | if (is_array($list)) { |
95 | 95 | foreach ($list as $f) { |
96 | 96 | if (is_dir($f)) { |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | // save in file if it's the first call (not recursed) |
119 | 119 | if ($cacheFile !== false) { |
120 | 120 | if (!file_put_contents($cacheFile, serialize($this->classPath))) { |
121 | - throw new Exception('Could not write into ' . $cacheFile . |
|
121 | + throw new Exception('Could not write into '.$cacheFile. |
|
122 | 122 | ', either because the folder is not there (create it) or because of the chmod configuration (please ensure this directory is writable by php), alternatively you can change the directory used with $dwoo->setCompileDir() or provide a custom loader object with $dwoo->setLoader()'); |
123 | 123 | } |
124 | 124 | $this->classPath += $tmp; |
@@ -144,23 +144,23 @@ discard block |
||
144 | 144 | * so we check for that before trying to include() the plugin. |
145 | 145 | */ |
146 | 146 | if ((!isset($this->classPath[$class]) || !is_readable($this->classPath[$class])) || (!isset |
147 | - ($this->classPath[$class . 'Compile']) || !is_readable($this->classPath[$class . 'Compile']))) { |
|
147 | + ($this->classPath[$class.'Compile']) || !is_readable($this->classPath[$class.'Compile']))) { |
|
148 | 148 | if ($forceRehash) { |
149 | - $this->rebuildClassPathCache($this->corePluginDir, $this->cacheDir . 'classpath.cache.d' . |
|
150 | - Core::RELEASE_TAG . '.php'); |
|
149 | + $this->rebuildClassPathCache($this->corePluginDir, $this->cacheDir.'classpath.cache.d'. |
|
150 | + Core::RELEASE_TAG.'.php'); |
|
151 | 151 | foreach ($this->paths as $path => $file) { |
152 | 152 | $this->rebuildClassPathCache($path, $file); |
153 | 153 | } |
154 | 154 | if (isset($this->classPath[$class])) { |
155 | 155 | include_once $this->classPath[$class]; |
156 | - } elseif (isset($this->classPath[$class . 'Compile'])) { |
|
157 | - include_once $this->classPath[$class . 'Compile']; |
|
156 | + } elseif (isset($this->classPath[$class.'Compile'])) { |
|
157 | + include_once $this->classPath[$class.'Compile']; |
|
158 | 158 | } else { |
159 | - throw new Exception('Plugin "' . $class . |
|
159 | + throw new Exception('Plugin "'.$class. |
|
160 | 160 | '" can not be found, maybe you forgot to bind it if it\'s a custom plugin ?', E_USER_NOTICE); |
161 | 161 | } |
162 | 162 | } else { |
163 | - throw new Exception('Plugin "' . $class . |
|
163 | + throw new Exception('Plugin "'.$class. |
|
164 | 164 | '" can not be found, maybe you forgot to bind it if it\'s a custom plugin ?', E_USER_NOTICE); |
165 | 165 | } |
166 | 166 | } |
@@ -183,14 +183,14 @@ discard block |
||
183 | 183 | { |
184 | 184 | $pluginDir = realpath($pluginDirectory); |
185 | 185 | if (!$pluginDir) { |
186 | - throw new Exception('Plugin directory does not exist or can not be read : ' . $pluginDirectory); |
|
186 | + throw new Exception('Plugin directory does not exist or can not be read : '.$pluginDirectory); |
|
187 | 187 | } |
188 | - $cacheFile = $this->cacheDir . 'classpath-' . substr(strtr($pluginDir, '/\\:' . PATH_SEPARATOR, '----'), |
|
189 | - strlen($pluginDir) > 80 ? - 80 : 0) . '.d' . Core::RELEASE_TAG . '.php'; |
|
188 | + $cacheFile = $this->cacheDir.'classpath-'.substr(strtr($pluginDir, '/\\:'.PATH_SEPARATOR, '----'), |
|
189 | + strlen($pluginDir) > 80 ? -80 : 0).'.d'.Core::RELEASE_TAG.'.php'; |
|
190 | 190 | $this->paths[$pluginDir] = $cacheFile; |
191 | 191 | if (file_exists($cacheFile)) { |
192 | 192 | $classpath = file_get_contents($cacheFile); |
193 | - $this->classPath = unserialize($classpath) + $this->classPath; |
|
193 | + $this->classPath = unserialize($classpath)+$this->classPath; |
|
194 | 194 | } else { |
195 | 195 | $this->rebuildClassPathCache($pluginDir, $cacheFile); |
196 | 196 | } |
@@ -290,7 +290,7 @@ |
||
290 | 290 | return call_user_func_array(array($obj, $method), $args); |
291 | 291 | } |
292 | 292 | } |
293 | - $dwoo->triggerError('The current security policy prevents you from calling ' . get_class($obj) . '::' . $method . '()'); |
|
293 | + $dwoo->triggerError('The current security policy prevents you from calling '.get_class($obj).'::'.$method.'()'); |
|
294 | 294 | |
295 | 295 | return null; |
296 | 296 | } |