@@ -38,52 +38,52 @@ |
||
| 38 | 38 | protected $what; |
| 39 | 39 | |
| 40 | 40 | function __construct($s, Text $what) { |
| 41 | - if(preg_match("/^([a-z]+)(\\((.*)\\))?$/", $s, $m)) { |
|
| 41 | + if (preg_match("/^([a-z]+)(\\((.*)\\))?$/", $s, $m)) { |
|
| 42 | 42 | $this->filter = $m[1]; |
| 43 | 43 | $this->vars = isset($m[3]) ? explode(',', $m[3]) : []; |
| 44 | - foreach($this->vars as $k=>$v) |
|
| 45 | - $this->vars[$k] = str_replace(",",',',$v); |
|
| 44 | + foreach ($this->vars as $k=>$v) |
|
| 45 | + $this->vars[$k] = str_replace(",", ',', $v); |
|
| 46 | 46 | } else { |
| 47 | 47 | throw new ParseError("Unable to parse filter expression \"$s\""); |
| 48 | 48 | } |
| 49 | - if(!in_array($this->filter, ['itersplit', 'newlinebr', 'round', |
|
| 50 | - 'strtoupper', 'strtolower', 'ucfirst','replace'])) { |
|
| 49 | + if (!in_array($this->filter, ['itersplit', 'newlinebr', 'round', |
|
| 50 | + 'strtoupper', 'strtolower', 'ucfirst', 'replace'])) { |
|
| 51 | 51 | throw new ParseError("Unknown Filter Type \"{$this->filter}\""); |
| 52 | 52 | } |
| 53 | - if(in_array($this->filter,['itersplit','newlinebr', 'replace'])) { |
|
| 53 | + if (in_array($this->filter, ['itersplit', 'newlinebr', 'replace'])) { |
|
| 54 | 54 | $this->filter = "Seufert\\Hamle\\Text\\Filter::{$this->filter}"; |
| 55 | 55 | } |
| 56 | 56 | $this->what = $what; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | function toHTML($escape = false) { |
| 60 | - if($escape) |
|
| 61 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
| 62 | - return "<?=" . $this->toPHP() . "?>"; |
|
| 60 | + if ($escape) |
|
| 61 | + return "<?=htmlspecialchars(".$this->toPHP().")?>"; |
|
| 62 | + return "<?=".$this->toPHP()."?>"; |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | function toPHP() { |
| 66 | - $o = [$this->what->toPHPVar()] ; |
|
| 67 | - foreach($this->vars as $v) |
|
| 66 | + $o = [$this->what->toPHPVar()]; |
|
| 67 | + foreach ($this->vars as $v) |
|
| 68 | 68 | $o[] = $this->varToCode($v); |
| 69 | - return "{$this->filter}(" . implode(',',$o) . ")"; |
|
| 69 | + return "{$this->filter}(".implode(',', $o).")"; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | static function itersplit($v, $sep = ",") { |
| 73 | 73 | $o = []; |
| 74 | - foreach(explode($sep, $v) as $k=>$i) { |
|
| 75 | - if($i) |
|
| 76 | - $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k]; |
|
| 74 | + foreach (explode($sep, $v) as $k=>$i) { |
|
| 75 | + if ($i) |
|
| 76 | + $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k, 'key'=>$k]; |
|
| 77 | 77 | } |
| 78 | 78 | return new WrapArray($o); |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | static function newlinebr($v) { |
| 82 | - return str_replace("\n","<br />\n",$v); |
|
| 82 | + return str_replace("\n", "<br />\n", $v); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | static function replace($v, $src, $dst) { |
| 86 | - return str_replace($src,$dst,$v); |
|
| 86 | + return str_replace($src, $dst, $v); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | } |
| 90 | 90 | \ No newline at end of file |
@@ -41,8 +41,9 @@ discard block |
||
| 41 | 41 | if(preg_match("/^([a-z]+)(\\((.*)\\))?$/", $s, $m)) { |
| 42 | 42 | $this->filter = $m[1]; |
| 43 | 43 | $this->vars = isset($m[3]) ? explode(',', $m[3]) : []; |
| 44 | - foreach($this->vars as $k=>$v) |
|
| 45 | - $this->vars[$k] = str_replace(",",',',$v); |
|
| 44 | + foreach($this->vars as $k=>$v) { |
|
| 45 | + $this->vars[$k] = str_replace(",",',',$v); |
|
| 46 | + } |
|
| 46 | 47 | } else { |
| 47 | 48 | throw new ParseError("Unable to parse filter expression \"$s\""); |
| 48 | 49 | } |
@@ -57,23 +58,26 @@ discard block |
||
| 57 | 58 | } |
| 58 | 59 | |
| 59 | 60 | function toHTML($escape = false) { |
| 60 | - if($escape) |
|
| 61 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
| 61 | + if($escape) { |
|
| 62 | + return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
| 63 | + } |
|
| 62 | 64 | return "<?=" . $this->toPHP() . "?>"; |
| 63 | 65 | } |
| 64 | 66 | |
| 65 | 67 | function toPHP() { |
| 66 | 68 | $o = [$this->what->toPHPVar()] ; |
| 67 | - foreach($this->vars as $v) |
|
| 68 | - $o[] = $this->varToCode($v); |
|
| 69 | + foreach($this->vars as $v) { |
|
| 70 | + $o[] = $this->varToCode($v); |
|
| 71 | + } |
|
| 69 | 72 | return "{$this->filter}(" . implode(',',$o) . ")"; |
| 70 | 73 | } |
| 71 | 74 | |
| 72 | 75 | static function itersplit($v, $sep = ",") { |
| 73 | 76 | $o = []; |
| 74 | 77 | foreach(explode($sep, $v) as $k=>$i) { |
| 75 | - if($i) |
|
| 76 | - $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k]; |
|
| 78 | + if($i) { |
|
| 79 | + $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k]; |
|
| 80 | + } |
|
| 77 | 81 | } |
| 78 | 82 | return new WrapArray($o); |
| 79 | 83 | } |