@@ -41,47 +41,47 @@ discard block |
||
41 | 41 | protected $chained; |
42 | 42 | |
43 | 43 | function __construct($s, Text $what) { |
44 | - if(preg_match("/^([a-z]+)(?:\\((?P<vars>.*)\\))?(?:\\|(?P<chained>.+?))?$/", $s, $m)) { |
|
44 | + if (preg_match("/^([a-z]+)(?:\\((?P<vars>.*)\\))?(?:\\|(?P<chained>.+?))?$/", $s, $m)) { |
|
45 | 45 | $this->filter = $m[1]; |
46 | 46 | $this->vars = isset($m['vars']) && strlen($m['vars']) ? explode(',', $m['vars']) : []; |
47 | - foreach($this->vars as $k=>$v) |
|
48 | - $this->vars[$k] = str_replace(",",',',$v); |
|
49 | - if(isset($m['chained']) && strlen($m['chained'])) { |
|
50 | - $this->chained = new Filter($m['chained'],$what); |
|
47 | + foreach ($this->vars as $k=>$v) |
|
48 | + $this->vars[$k] = str_replace(",", ',', $v); |
|
49 | + if (isset($m['chained']) && strlen($m['chained'])) { |
|
50 | + $this->chained = new Filter($m['chained'], $what); |
|
51 | 51 | } |
52 | 52 | } else { |
53 | 53 | throw new ParseError("Unable to parse filter expression \"$s\""); |
54 | 54 | } |
55 | - if(method_exists(Filter::class, $this->filter)) { |
|
55 | + if (method_exists(Filter::class, $this->filter)) { |
|
56 | 56 | $this->filter = "Seufert\\Hamle\\Text\\Filter::{$this->filter}"; |
57 | - } elseif(!in_array($this->filter, ['round', 'strtoupper', 'strtolower', 'ucfirst', 'json'])) { |
|
57 | + } elseif (!in_array($this->filter, ['round', 'strtoupper', 'strtolower', 'ucfirst', 'json'])) { |
|
58 | 58 | throw new ParseError("Unknown Filter Type \"{$this->filter}\""); |
59 | 59 | } |
60 | 60 | $mapFilter = ['json'=>'json_encode']; |
61 | - if(isset($mapFilter[$this->filter])) |
|
61 | + if (isset($mapFilter[$this->filter])) |
|
62 | 62 | $this->filter = $mapFilter[$this->filter]; |
63 | 63 | $this->what = $what; |
64 | 64 | } |
65 | 65 | |
66 | 66 | function toHTML($escape = false) { |
67 | - if($escape) |
|
68 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
69 | - return "<?=" . $this->toPHP() . "?>"; |
|
67 | + if ($escape) |
|
68 | + return "<?=htmlspecialchars(".$this->toPHP().")?>"; |
|
69 | + return "<?=".$this->toPHP()."?>"; |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | function toPHPpre() { |
73 | 73 | $pre = ''; |
74 | - if($this->chained) |
|
74 | + if ($this->chained) |
|
75 | 75 | $pre = $this->chained->toPHPpre(); |
76 | 76 | return "$pre{$this->filter}("; |
77 | 77 | } |
78 | 78 | |
79 | 79 | function toPHPpost() { |
80 | 80 | $post = ''; |
81 | - if($this->chained) |
|
81 | + if ($this->chained) |
|
82 | 82 | $post = $this->chained->toPHPpost(); |
83 | 83 | $o = ''; |
84 | - foreach($this->vars as $v) |
|
84 | + foreach ($this->vars as $v) |
|
85 | 85 | $o .= ','.$this->varToCode($v); |
86 | 86 | return "$o)$post"; |
87 | 87 | } |
@@ -96,24 +96,24 @@ discard block |
||
96 | 96 | |
97 | 97 | static function itersplit($v, $sep = ",") { |
98 | 98 | $o = []; |
99 | - foreach(explode($sep, $v) as $k=>$i) { |
|
100 | - if($i) |
|
101 | - $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k]; |
|
99 | + foreach (explode($sep, $v) as $k=>$i) { |
|
100 | + if ($i) |
|
101 | + $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k, 'key'=>$k]; |
|
102 | 102 | } |
103 | 103 | return new WrapArray($o); |
104 | 104 | } |
105 | 105 | |
106 | 106 | static function newlinebr($v) { |
107 | - return str_replace("\n","<br />\n",$v); |
|
107 | + return str_replace("\n", "<br />\n", $v); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | static function replace($v, $src, $dst) { |
111 | - return str_replace($src,$dst,$v); |
|
111 | + return str_replace($src, $dst, $v); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | static function ascents($v) { |
115 | - $v = str_replace(['$',' ',','],'', $v); |
|
116 | - return (int) round($v * 100,0); |
|
115 | + $v = str_replace(['$', ' ', ','], '', $v); |
|
116 | + return (int) round($v * 100, 0); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | } |
120 | 120 | \ No newline at end of file |
@@ -44,8 +44,9 @@ discard block |
||
44 | 44 | if(preg_match("/^([a-z]+)(?:\\((?P<vars>.*)\\))?(?:\\|(?P<chained>.+?))?$/", $s, $m)) { |
45 | 45 | $this->filter = $m[1]; |
46 | 46 | $this->vars = isset($m['vars']) && strlen($m['vars']) ? explode(',', $m['vars']) : []; |
47 | - foreach($this->vars as $k=>$v) |
|
48 | - $this->vars[$k] = str_replace(",",',',$v); |
|
47 | + foreach($this->vars as $k=>$v) { |
|
48 | + $this->vars[$k] = str_replace(",",',',$v); |
|
49 | + } |
|
49 | 50 | if(isset($m['chained']) && strlen($m['chained'])) { |
50 | 51 | $this->chained = new Filter($m['chained'],$what); |
51 | 52 | } |
@@ -58,31 +59,36 @@ discard block |
||
58 | 59 | throw new ParseError("Unknown Filter Type \"{$this->filter}\""); |
59 | 60 | } |
60 | 61 | $mapFilter = ['json'=>'json_encode']; |
61 | - if(isset($mapFilter[$this->filter])) |
|
62 | - $this->filter = $mapFilter[$this->filter]; |
|
62 | + if(isset($mapFilter[$this->filter])) { |
|
63 | + $this->filter = $mapFilter[$this->filter]; |
|
64 | + } |
|
63 | 65 | $this->what = $what; |
64 | 66 | } |
65 | 67 | |
66 | 68 | function toHTML($escape = false) { |
67 | - if($escape) |
|
68 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
69 | + if($escape) { |
|
70 | + return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
71 | + } |
|
69 | 72 | return "<?=" . $this->toPHP() . "?>"; |
70 | 73 | } |
71 | 74 | |
72 | 75 | function toPHPpre() { |
73 | 76 | $pre = ''; |
74 | - if($this->chained) |
|
75 | - $pre = $this->chained->toPHPpre(); |
|
77 | + if($this->chained) { |
|
78 | + $pre = $this->chained->toPHPpre(); |
|
79 | + } |
|
76 | 80 | return "$pre{$this->filter}("; |
77 | 81 | } |
78 | 82 | |
79 | 83 | function toPHPpost() { |
80 | 84 | $post = ''; |
81 | - if($this->chained) |
|
82 | - $post = $this->chained->toPHPpost(); |
|
85 | + if($this->chained) { |
|
86 | + $post = $this->chained->toPHPpost(); |
|
87 | + } |
|
83 | 88 | $o = ''; |
84 | - foreach($this->vars as $v) |
|
85 | - $o .= ','.$this->varToCode($v); |
|
89 | + foreach($this->vars as $v) { |
|
90 | + $o .= ','.$this->varToCode($v); |
|
91 | + } |
|
86 | 92 | return "$o)$post"; |
87 | 93 | } |
88 | 94 | |
@@ -97,8 +103,9 @@ discard block |
||
97 | 103 | static function itersplit($v, $sep = ",") { |
98 | 104 | $o = []; |
99 | 105 | foreach(explode($sep, $v) as $k=>$i) { |
100 | - if($i) |
|
101 | - $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k]; |
|
106 | + if($i) { |
|
107 | + $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k]; |
|
108 | + } |
|
102 | 109 | } |
103 | 110 | return new WrapArray($o); |
104 | 111 | } |