@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | $i = self::indentLevel($indent); |
157 | 157 | unset($m[0]); |
158 | 158 | switch (strlen($code) ? $code[0] : ($textcode ? $textcode : "")) { |
159 | - case "|": //Control Tag |
|
159 | + case "|" : //Control Tag |
|
160 | 160 | if ($code == "|snippet") |
161 | 161 | $hTag = new Tag\Snippet($text); |
162 | 162 | elseif ($code == "|form") |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | break; |
197 | 197 | default: |
198 | 198 | $attr = array(); |
199 | - if(isset($params[0]) && $params[0] == "[") { |
|
199 | + if (isset($params[0]) && $params[0] == "[") { |
|
200 | 200 | $param = substr($params, 1, -1); |
201 | 201 | $param = str_replace(['+', '\\&'], ['%2B', '%26'], $param); |
202 | 202 | // parse_str($param, $attr); |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | if ($s[0] == ".") $class[] = substr($s, 1); |
210 | 210 | if ($s[0] == "!") $ref = substr($s, 1); |
211 | 211 | } |
212 | - if($ref) |
|
212 | + if ($ref) |
|
213 | 213 | $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref); |
214 | 214 | else |
215 | 215 | $hTag = new Tag\Html($tag, $class, $attr, $id); |
@@ -222,16 +222,16 @@ discard block |
||
222 | 222 | else |
223 | 223 | $this->root[] = $hTag; |
224 | 224 | } else |
225 | - throw new ParseError("Unable to parse line {$this->lineNo}\n\"$line\"/" . preg_last_error()); |
|
225 | + throw new ParseError("Unable to parse line {$this->lineNo}\n\"$line\"/".preg_last_error()); |
|
226 | 226 | $this->lineNo++; |
227 | 227 | } |
228 | 228 | } |
229 | 229 | |
230 | 230 | function parseQueryString($qs) { |
231 | 231 | $out = []; |
232 | - foreach(explode('&',$qs) as $s) { |
|
233 | - $kv = explode('=',$s,2); |
|
234 | - $out[urldecode($kv[0])] = isset($kv[1])?urldecode($kv[1]):null; |
|
232 | + foreach (explode('&', $qs) as $s) { |
|
233 | + $kv = explode('=', $s, 2); |
|
234 | + $out[urldecode($kv[0])] = isset($kv[1]) ?urldecode($kv[1]) : null; |
|
235 | 235 | } |
236 | 236 | return $out; |
237 | 237 | } |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | $m = array(); |
250 | 250 | while ($this->lineNo + 1 < $this->lineCount && |
251 | 251 | (!trim($this->lines[$this->lineNo + 1]) || |
252 | - preg_match('/^(\s){' . $indent . '}((\s)+[^\s].*)$/', |
|
252 | + preg_match('/^(\s){'.$indent.'}((\s)+[^\s].*)$/', |
|
253 | 253 | $this->lines[$this->lineNo + 1], $m))) { |
254 | 254 | if (trim($this->lines[$this->lineNo + 1])) |
255 | 255 | $out[] = $m[2]; |
@@ -109,22 +109,25 @@ discard block |
||
109 | 109 | $revSnip = array(); |
110 | 110 | /** @var Tag[] $roots */ |
111 | 111 | $roots = array(); |
112 | - foreach ($this->root as $snip) |
|
113 | - if ($snip instanceOf Tag\Snippet) { |
|
112 | + foreach ($this->root as $snip) { |
|
113 | + if ($snip instanceOf Tag\Snippet) { |
|
114 | 114 | if ($snip->getType() == "append") { |
115 | 115 | array_unshift($revSnip, $snip); |
116 | + } |
|
116 | 117 | } else { |
117 | 118 | $fwdSnip[] = $snip; |
118 | 119 | } |
119 | 120 | } else { |
120 | 121 | $roots[] = $snip; |
121 | 122 | } |
122 | - foreach ($fwdSnip as $snip) |
|
123 | - foreach ($roots as $root) |
|
123 | + foreach ($fwdSnip as $snip) { |
|
124 | + foreach ($roots as $root) |
|
124 | 125 | $snip->apply($root); |
125 | - foreach ($revSnip as $snip) |
|
126 | - foreach ($roots as $root) |
|
126 | + } |
|
127 | + foreach ($revSnip as $snip) { |
|
128 | + foreach ($roots as $root) |
|
127 | 129 | $snip->apply($root); |
130 | + } |
|
128 | 131 | $this->root = $roots; |
129 | 132 | } |
130 | 133 | |
@@ -143,9 +146,11 @@ discard block |
||
143 | 146 | $heir = array(); |
144 | 147 | while ($this->lineNo < $this->lineCount) { |
145 | 148 | $line = $this->lines[$this->lineNo]; |
146 | - if (trim($line)) if (preg_match(self::REGEX_PARSE_LINE, $line, $m)) { |
|
149 | + if (trim($line)) { |
|
150 | + if (preg_match(self::REGEX_PARSE_LINE, $line, $m)) { |
|
147 | 151 | if (FALSE !== strpos($m[1], "\t")) |
148 | 152 | throw new ParseError("Tabs are not supported in templates at this time"); |
153 | + } |
|
149 | 154 | $indent = strlen($m[1]); |
150 | 155 | $tag = isset($m[2]) ? $tag = $m[2] : ""; |
151 | 156 | $classid = isset($m[3]) ? $m[3] : ""; |
@@ -157,13 +162,13 @@ discard block |
||
157 | 162 | unset($m[0]); |
158 | 163 | switch (strlen($code) ? $code[0] : ($textcode ? $textcode : "")) { |
159 | 164 | case "|": //Control Tag |
160 | - if ($code == "|snippet") |
|
161 | - $hTag = new Tag\Snippet($text); |
|
162 | - elseif ($code == "|form") |
|
163 | - $hTag = new Tag\Form($text); |
|
164 | - elseif ($code == "|formhint") |
|
165 | - $hTag = new Tag\FormHint(); |
|
166 | - elseif ($code == "|else") { |
|
165 | + if ($code == "|snippet") { |
|
166 | + $hTag = new Tag\Snippet($text); |
|
167 | + } elseif ($code == "|form") { |
|
168 | + $hTag = new Tag\Form($text); |
|
169 | + } elseif ($code == "|formhint") { |
|
170 | + $hTag = new Tag\FormHint(); |
|
171 | + } elseif ($code == "|else") { |
|
167 | 172 | $hTag = new Tag\Control(substr($code, 1), $heir[$i - 1]); |
168 | 173 | $hTag->setVar($text); |
169 | 174 | } else { |
@@ -174,8 +179,9 @@ discard block |
||
174 | 179 | case ":": //Filter Tag |
175 | 180 | $hTag = new Tag\Filter(substr($code, 1)); |
176 | 181 | $hTag->addContent($text, Text::TOKEN_CODE); |
177 | - foreach ($this->consumeBlock($indent) as $l) |
|
178 | - $hTag->addContent($l, Text::TOKEN_CODE); |
|
182 | + foreach ($this->consumeBlock($indent) as $l) { |
|
183 | + $hTag->addContent($l, Text::TOKEN_CODE); |
|
184 | + } |
|
179 | 185 | break; |
180 | 186 | case "_": //String Tag |
181 | 187 | case "__": //Unescape String Tag |
@@ -191,8 +197,9 @@ discard block |
||
191 | 197 | case "//": // Non Printed Comment |
192 | 198 | $hTag = new Tag\Comment($textcode); |
193 | 199 | $hTag->addContent($text); |
194 | - foreach ($this->consumeBlock($indent) as $l) |
|
195 | - $hTag->addContent($l, Text::TOKEN_CODE); |
|
200 | + foreach ($this->consumeBlock($indent) as $l) { |
|
201 | + $hTag->addContent($l, Text::TOKEN_CODE); |
|
202 | + } |
|
196 | 203 | break; |
197 | 204 | default: |
198 | 205 | $attr = array(); |
@@ -204,25 +211,34 @@ discard block |
||
204 | 211 | } |
205 | 212 | $class = array(); $id = ""; $ref = ""; |
206 | 213 | preg_match_all('/[#\.!][a-zA-Z0-9\-\_]+/m', $classid, $cid); |
207 | - if (isset($cid[0])) foreach ($cid[0] as $s) { |
|
214 | + if (isset($cid[0])) { |
|
215 | + foreach ($cid[0] as $s) { |
|
208 | 216 | if ($s[0] == "#") $id = substr($s, 1); |
209 | - if ($s[0] == ".") $class[] = substr($s, 1); |
|
210 | - if ($s[0] == "!") $ref = substr($s, 1); |
|
211 | 217 | } |
212 | - if($ref) |
|
213 | - $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref); |
|
214 | - else |
|
215 | - $hTag = new Tag\Html($tag, $class, $attr, $id); |
|
218 | + if ($s[0] == ".") { |
|
219 | + $class[] = substr($s, 1); |
|
220 | + } |
|
221 | + if ($s[0] == "!") { |
|
222 | + $ref = substr($s, 1); |
|
223 | + } |
|
224 | + } |
|
225 | + if($ref) { |
|
226 | + $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref); |
|
227 | + } else { |
|
228 | + $hTag = new Tag\Html($tag, $class, $attr, $id); |
|
229 | + } |
|
216 | 230 | $hTag->addContent($text); |
217 | 231 | break; |
218 | 232 | } |
219 | 233 | $heir[$i] = $hTag; |
220 | - if ($i > 0) |
|
221 | - $heir[$i - 1]->addChild($hTag); |
|
222 | - else |
|
223 | - $this->root[] = $hTag; |
|
224 | - } else |
|
225 | - throw new ParseError("Unable to parse line {$this->lineNo}\n\"$line\"/" . preg_last_error()); |
|
234 | + if ($i > 0) { |
|
235 | + $heir[$i - 1]->addChild($hTag); |
|
236 | + } else { |
|
237 | + $this->root[] = $hTag; |
|
238 | + } |
|
239 | + } else { |
|
240 | + throw new ParseError("Unable to parse line {$this->lineNo}\n\"$line\"/" . preg_last_error()); |
|
241 | + } |
|
226 | 242 | $this->lineNo++; |
227 | 243 | } |
228 | 244 | } |
@@ -238,8 +254,9 @@ discard block |
||
238 | 254 | |
239 | 255 | function output($minify = false) { |
240 | 256 | $out = "<?php\nuse Seufert\\Hamle;\n?>"; |
241 | - foreach ($this->root as $tag) |
|
242 | - $out .= $tag->render(0, $minify); |
|
257 | + foreach ($this->root as $tag) { |
|
258 | + $out .= $tag->render(0, $minify); |
|
259 | + } |
|
243 | 260 | return $out; |
244 | 261 | |
245 | 262 | } |
@@ -251,15 +268,18 @@ discard block |
||
251 | 268 | (!trim($this->lines[$this->lineNo + 1]) || |
252 | 269 | preg_match('/^(\s){' . $indent . '}((\s)+[^\s].*)$/', |
253 | 270 | $this->lines[$this->lineNo + 1], $m))) { |
254 | - if (trim($this->lines[$this->lineNo + 1])) |
|
255 | - $out[] = $m[2]; |
|
271 | + if (trim($this->lines[$this->lineNo + 1])) { |
|
272 | + $out[] = $m[2]; |
|
273 | + } |
|
256 | 274 | $this->lineNo++; |
257 | 275 | } |
258 | 276 | return $out; |
259 | 277 | } |
260 | 278 | |
261 | 279 | function indentLevel($indent) { |
262 | - if (!isset($this->indents)) $this->indents = array(); |
|
280 | + if (!isset($this->indents)) { |
|
281 | + $this->indents = array(); |
|
282 | + } |
|
263 | 283 | if (!count($this->indents)) { |
264 | 284 | $this->indents = array(0 => $indent); |
265 | 285 | // Key = indent level, Value = Depth in spaces |
@@ -46,23 +46,23 @@ discard block |
||
46 | 46 | static $filterResolver = null; |
47 | 47 | |
48 | 48 | function __construct($s, Text $what) { |
49 | - if(preg_match("/^([a-z_]+)(?:\\((?P<vars>.*)\\))?(?:\\|(?P<chained>.+?))?$/", $s, $m)) { |
|
49 | + if (preg_match("/^([a-z_]+)(?:\\((?P<vars>.*)\\))?(?:\\|(?P<chained>.+?))?$/", $s, $m)) { |
|
50 | 50 | $this->filter = $m[1]; |
51 | 51 | $this->vars = isset($m['vars']) && strlen($m['vars']) ? explode(',', $m['vars']) : []; |
52 | - foreach($this->vars as $k=>$v) |
|
53 | - $this->vars[$k] = str_replace(",",',',$v); |
|
54 | - if(isset($m['chained']) && strlen($m['chained'])) { |
|
55 | - $this->chained = new Filter($m['chained'],$what); |
|
52 | + foreach ($this->vars as $k=>$v) |
|
53 | + $this->vars[$k] = str_replace(",", ',', $v); |
|
54 | + if (isset($m['chained']) && strlen($m['chained'])) { |
|
55 | + $this->chained = new Filter($m['chained'], $what); |
|
56 | 56 | } |
57 | 57 | } else { |
58 | 58 | throw new ParseError("Unable to parse filter expression \"$s\""); |
59 | 59 | } |
60 | - if(method_exists(Filter::class, $this->filter)) { |
|
60 | + if (method_exists(Filter::class, $this->filter)) { |
|
61 | 61 | $this->filter = Filter::class.'::'.$this->filter; |
62 | - } elseif(in_array($this->filter, ['round', 'strtoupper', 'strtolower', 'ucfirst'])) { |
|
63 | - } elseif($this->filter === 'json') { |
|
62 | + } elseif (in_array($this->filter, ['round', 'strtoupper', 'strtolower', 'ucfirst'])) { |
|
63 | + } elseif ($this->filter === 'json') { |
|
64 | 64 | $this->filter = 'json_encode'; |
65 | - } elseif(self::$filterResolver && $filter = (self::$filterResolver)($this->filter)) { |
|
65 | + } elseif (self::$filterResolver && $filter = (self::$filterResolver)($this->filter)) { |
|
66 | 66 | $this->filter = $filter; |
67 | 67 | } else { |
68 | 68 | throw new ParseError("Unknown Filter Type \"{$this->filter}\""); |
@@ -71,24 +71,24 @@ discard block |
||
71 | 71 | } |
72 | 72 | |
73 | 73 | function toHTML($escape = false) { |
74 | - if($escape) |
|
75 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
76 | - return "<?=" . $this->toPHP() . "?>"; |
|
74 | + if ($escape) |
|
75 | + return "<?=htmlspecialchars(".$this->toPHP().")?>"; |
|
76 | + return "<?=".$this->toPHP()."?>"; |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | function toPHPpre() { |
80 | 80 | $pre = ''; |
81 | - if($this->chained) |
|
81 | + if ($this->chained) |
|
82 | 82 | $pre = $this->chained->toPHPpre(); |
83 | 83 | return "$pre{$this->filter}("; |
84 | 84 | } |
85 | 85 | |
86 | 86 | function toPHPpost() { |
87 | 87 | $post = ''; |
88 | - if($this->chained) |
|
88 | + if ($this->chained) |
|
89 | 89 | $post = $this->chained->toPHPpost(); |
90 | 90 | $o = ''; |
91 | - foreach($this->vars as $v) |
|
91 | + foreach ($this->vars as $v) |
|
92 | 92 | $o .= ','.$this->varToCode($v); |
93 | 93 | return "$o)$post"; |
94 | 94 | } |
@@ -103,24 +103,24 @@ discard block |
||
103 | 103 | |
104 | 104 | static function itersplit($v, $sep = ",") { |
105 | 105 | $o = []; |
106 | - foreach(explode($sep, $v) as $k=>$i) { |
|
107 | - if($i) |
|
108 | - $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k]; |
|
106 | + foreach (explode($sep, $v) as $k=>$i) { |
|
107 | + if ($i) |
|
108 | + $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k, 'key'=>$k]; |
|
109 | 109 | } |
110 | 110 | return new WrapArray($o); |
111 | 111 | } |
112 | 112 | |
113 | 113 | static function newlinebr($v) { |
114 | - return str_replace("\n","<br />\n",$v); |
|
114 | + return str_replace("\n", "<br />\n", $v); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | static function replace($v, $src, $dst) { |
118 | - return str_replace($src,$dst,$v); |
|
118 | + return str_replace($src, $dst, $v); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | static function ascents($v) { |
122 | - $v = str_replace(['$',' ',','],'', $v); |
|
123 | - return (int) round($v * 100,0); |
|
122 | + $v = str_replace(['$', ' ', ','], '', $v); |
|
123 | + return (int) round($v * 100, 0); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | } |
@@ -49,8 +49,9 @@ discard block |
||
49 | 49 | if(preg_match("/^([a-z_]+)(?:\\((?P<vars>.*)\\))?(?:\\|(?P<chained>.+?))?$/", $s, $m)) { |
50 | 50 | $this->filter = $m[1]; |
51 | 51 | $this->vars = isset($m['vars']) && strlen($m['vars']) ? explode(',', $m['vars']) : []; |
52 | - foreach($this->vars as $k=>$v) |
|
53 | - $this->vars[$k] = str_replace(",",',',$v); |
|
52 | + foreach($this->vars as $k=>$v) { |
|
53 | + $this->vars[$k] = str_replace(",",',',$v); |
|
54 | + } |
|
54 | 55 | if(isset($m['chained']) && strlen($m['chained'])) { |
55 | 56 | $this->chained = new Filter($m['chained'],$what); |
56 | 57 | } |
@@ -71,25 +72,29 @@ discard block |
||
71 | 72 | } |
72 | 73 | |
73 | 74 | function toHTML($escape = false) { |
74 | - if($escape) |
|
75 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
75 | + if($escape) { |
|
76 | + return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
77 | + } |
|
76 | 78 | return "<?=" . $this->toPHP() . "?>"; |
77 | 79 | } |
78 | 80 | |
79 | 81 | function toPHPpre() { |
80 | 82 | $pre = ''; |
81 | - if($this->chained) |
|
82 | - $pre = $this->chained->toPHPpre(); |
|
83 | + if($this->chained) { |
|
84 | + $pre = $this->chained->toPHPpre(); |
|
85 | + } |
|
83 | 86 | return "$pre{$this->filter}("; |
84 | 87 | } |
85 | 88 | |
86 | 89 | function toPHPpost() { |
87 | 90 | $post = ''; |
88 | - if($this->chained) |
|
89 | - $post = $this->chained->toPHPpost(); |
|
91 | + if($this->chained) { |
|
92 | + $post = $this->chained->toPHPpost(); |
|
93 | + } |
|
90 | 94 | $o = ''; |
91 | - foreach($this->vars as $v) |
|
92 | - $o .= ','.$this->varToCode($v); |
|
95 | + foreach($this->vars as $v) { |
|
96 | + $o .= ','.$this->varToCode($v); |
|
97 | + } |
|
93 | 98 | return "$o)$post"; |
94 | 99 | } |
95 | 100 | |
@@ -104,8 +109,9 @@ discard block |
||
104 | 109 | static function itersplit($v, $sep = ",") { |
105 | 110 | $o = []; |
106 | 111 | foreach(explode($sep, $v) as $k=>$i) { |
107 | - if($i) |
|
108 | - $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k]; |
|
112 | + if($i) { |
|
113 | + $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k]; |
|
114 | + } |
|
109 | 115 | } |
110 | 116 | return new WrapArray($o); |
111 | 117 | } |