Completed
Pull Request — develop (#725)
by Agel_Nash
08:07
created
manager/includes/src/Legacy/Modifiers.php 5 patches
Doc Comments   +27 added lines, -1 removed lines patch added patch discarded remove patch
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
     /**
95 95
      * @param string $mode
96 96
      * @param string $modifiers
97
-     * @return bool|string
97
+     * @return false|string
98 98
      */
99 99
     public function _getDelim($mode,$modifiers) {
100 100
         $c = substr($modifiers,0,1);
@@ -131,6 +131,14 @@  discard block
 block discarded – undo
131 131
             return $opt;
132 132
         }
133 133
     }
134
+
135
+    /**
136
+     * @param string $mode
137
+     * @param false|string $delim
138
+     * @param string $modifiers
139
+     *
140
+     * @return string
141
+     */
134 142
     public function _getRemainModifiers($mode,$delim,$modifiers) {
135 143
         if($delim) {
136 144
             if($mode=='(')
@@ -158,6 +166,9 @@  discard block
 block discarded – undo
158 166
         return substr($string,strpos($string, $delim)+$len);
159 167
     }
160 168
 
169
+    /**
170
+     * @param string $modifiers
171
+     */
161 172
     public function splitEachModifiers($modifiers) {
162 173
         $modx = evolutionCMS();
163 174
 
@@ -227,6 +238,10 @@  discard block
 block discarded – undo
227 238
         return $result;
228 239
     }
229 240
 
241
+    /**
242
+     * @param string $key
243
+     * @param string $value
244
+     */
230 245
     public function parsePhx($key,$value,$modifiers)
231 246
     {
232 247
         $modx = evolutionCMS();
@@ -293,6 +308,10 @@  discard block
 block discarded – undo
293 308
         else                  return true;
294 309
     }
295 310
 
311
+    /**
312
+     * @param string $cmd
313
+     * @param string $opt
314
+     */
296 315
     public function getValueFromPreset($key, $value, $cmd, $opt)
297 316
     {
298 317
         $modx = evolutionCMS();
@@ -978,6 +997,9 @@  discard block
 block discarded – undo
978 997
         return $value;
979 998
     }
980 999
 
1000
+    /**
1001
+     * @param string $cmd
1002
+     */
981 1003
     public function includeMdfFile($cmd) {
982 1004
         $modx = evolutionCMS();
983 1005
         $key = $this->key;
@@ -1133,6 +1155,10 @@  discard block
 block discarded – undo
1133 1155
     }
1134 1156
 
1135 1157
     // Sets a placeholder variable which can only be access by Modifiers
1158
+
1159
+    /**
1160
+     * @param string $value
1161
+     */
1136 1162
     public function setModifiersVariable($key, $value) {
1137 1163
         if ($key != 'phx' && $key != 'dummy') $this->placeholders[$key] = $value;
1138 1164
     }
Please login to merge, or discard this patch.
Unused Use Statements   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@
 block discarded – undo
1 1
 <?php namespace EvolutionCMS\Legacy;
2 2
 
3
-use EvolutionCMS\Interfaces\ModifiersInterface;
4 3
 use DataGrid;
4
+use EvolutionCMS\Interfaces\ModifiersInterface;
5 5
 
6 6
 class Modifiers implements ModifiersInterface{
7 7
     /**
Please login to merge, or discard this patch.
Spacing   +348 added lines, -348 removed lines patch added patch discarded remove patch
@@ -71,14 +71,14 @@  discard block
 block discarded – undo
71 71
      * @param string $modifiers
72 72
      * @return bool|mixed|string
73 73
      */
74
-    public function phxFilter($key,$value,$modifiers)
74
+    public function phxFilter($key, $value, $modifiers)
75 75
     {
76 76
         $modx = evolutionCMS();
77
-        if(substr($modifiers,0,3)!=='id(') $value = $this->parseDocumentSource($value);
77
+        if (substr($modifiers, 0, 3) !== 'id(') $value = $this->parseDocumentSource($value);
78 78
         $this->srcValue = $value;
79 79
         $modifiers = trim($modifiers);
80
-        $modifiers = ':'.trim($modifiers,':');
81
-        $modifiers = str_replace(array("\r\n","\r"), "\n", $modifiers);
80
+        $modifiers = ':'.trim($modifiers, ':');
81
+        $modifiers = str_replace(array("\r\n", "\r"), "\n", $modifiers);
82 82
         $modifiers = $this->splitEachModifiers($modifiers);
83 83
 
84 84
         $this->placeholders = array();
@@ -86,8 +86,8 @@  discard block
 block discarded – undo
86 86
         $this->placeholders['dummy'] = '';
87 87
         $this->condition = array();
88 88
         $this->vars = array();
89
-        $this->vars['name']    = & $key;
90
-        $value = $this->parsePhx($key,$value,$modifiers);
89
+        $this->vars['name'] = & $key;
90
+        $value = $this->parsePhx($key, $value, $modifiers);
91 91
         $this->vars = array();
92 92
         return $value;
93 93
     }
@@ -97,13 +97,13 @@  discard block
 block discarded – undo
97 97
      * @param string $modifiers
98 98
      * @return bool|string
99 99
      */
100
-    public function _getDelim($mode,$modifiers) {
101
-        $c = substr($modifiers,0,1);
102
-        if(!in_array($c, array('"', "'", '`')) ) return false;
100
+    public function _getDelim($mode, $modifiers){
101
+        $c = substr($modifiers, 0, 1);
102
+        if (!in_array($c, array('"', "'", '`'))) return false;
103 103
 
104
-        $modifiers = substr($modifiers,1);
105
-        $closure = $mode=='(' ? "{$c})" : $c;
106
-        if(strpos($modifiers, $closure)===false) return false;
104
+        $modifiers = substr($modifiers, 1);
105
+        $closure = $mode == '(' ? "{$c})" : $c;
106
+        if (strpos($modifiers, $closure) === false) return false;
107 107
 
108 108
         return  $c;
109 109
     }
@@ -114,101 +114,101 @@  discard block
 block discarded – undo
114 114
      * @param string $modifiers
115 115
      * @return bool|string
116 116
      */
117
-    public function _getOpt($mode,$delim,$modifiers) {
118
-        if($delim) {
119
-            if($mode=='(') return substr($modifiers,1,strpos($modifiers, $delim . ')' )-1);
117
+    public function _getOpt($mode, $delim, $modifiers){
118
+        if ($delim) {
119
+            if ($mode == '(') return substr($modifiers, 1, strpos($modifiers, $delim.')') - 1);
120 120
 
121
-            return substr($modifiers,1,strpos($modifiers,$delim,1)-1);
121
+            return substr($modifiers, 1, strpos($modifiers, $delim, 1) - 1);
122 122
         }
123 123
         else {
124
-            if($mode=='(') return substr($modifiers,0,strpos($modifiers, ')') );
124
+            if ($mode == '(') return substr($modifiers, 0, strpos($modifiers, ')'));
125 125
 
126 126
             $chars = str_split($modifiers);
127
-            $opt='';
128
-            foreach($chars as $c) {
129
-                if($c==':' || $c==')') break;
130
-                $opt .=$c;
127
+            $opt = '';
128
+            foreach ($chars as $c) {
129
+                if ($c == ':' || $c == ')') break;
130
+                $opt .= $c;
131 131
             }
132 132
             return $opt;
133 133
         }
134 134
     }
135
-    public function _getRemainModifiers($mode,$delim,$modifiers) {
136
-        if($delim) {
137
-            if($mode=='(')
138
-                return $this->_fetchContent($modifiers, $delim . ')');
135
+    public function _getRemainModifiers($mode, $delim, $modifiers){
136
+        if ($delim) {
137
+            if ($mode == '(')
138
+                return $this->_fetchContent($modifiers, $delim.')');
139 139
             else {
140 140
                 $modifiers = trim($modifiers);
141
-                $modifiers = substr($modifiers,1);
141
+                $modifiers = substr($modifiers, 1);
142 142
                 return $this->_fetchContent($modifiers, $delim);
143 143
             }
144 144
         }
145 145
         else {
146
-            if($mode=='(') return $this->_fetchContent($modifiers, ')');
146
+            if ($mode == '(') return $this->_fetchContent($modifiers, ')');
147 147
             $chars = str_split($modifiers);
148
-            foreach($chars as $c) {
149
-                if($c==':') return $modifiers;
150
-                else $modifiers = substr($modifiers,1);
148
+            foreach ($chars as $c) {
149
+                if ($c == ':') return $modifiers;
150
+                else $modifiers = substr($modifiers, 1);
151 151
             }
152 152
             return $modifiers;
153 153
         }
154 154
     }
155 155
 
156
-    public function _fetchContent($string,$delim) {
156
+    public function _fetchContent($string, $delim){
157 157
         $len = strlen($delim);
158 158
         $string = $this->parseDocumentSource($string);
159
-        return substr($string,strpos($string, $delim)+$len);
159
+        return substr($string, strpos($string, $delim) + $len);
160 160
     }
161 161
 
162
-    public function splitEachModifiers($modifiers) {
162
+    public function splitEachModifiers($modifiers){
163 163
         $modx = evolutionCMS();
164 164
 
165 165
         $cmd = '';
166 166
         $bt = '';
167 167
         $result = array();
168
-        while($bt!==$modifiers) {
168
+        while ($bt !== $modifiers) {
169 169
             $bt = $modifiers;
170
-            $c = substr($modifiers,0,1);
171
-            $modifiers = substr($modifiers,1);
170
+            $c = substr($modifiers, 0, 1);
171
+            $modifiers = substr($modifiers, 1);
172 172
 
173
-            if($c===':' && preg_match('@^(!?[<>=]{1,2})@', $modifiers, $match)) { // :=, :!=, :<=, :>=, :!<=, :!>=
174
-                $c = substr($modifiers,strlen($match[1]),1);
173
+            if ($c === ':' && preg_match('@^(!?[<>=]{1,2})@', $modifiers, $match)) { // :=, :!=, :<=, :>=, :!<=, :!>=
174
+                $c = substr($modifiers, strlen($match[1]), 1);
175 175
                 $debuginfo = "#i=0 #c=[{$c}] #m=[{$modifiers}]";
176
-                if($c==='(') $modifiers = substr($modifiers,strlen($match[1])+1);
177
-                else         $modifiers = substr($modifiers,strlen($match[1]));
176
+                if ($c === '(') $modifiers = substr($modifiers, strlen($match[1]) + 1);
177
+                else         $modifiers = substr($modifiers, strlen($match[1]));
178 178
 
179
-                $delim     = $this->_getDelim($c,$modifiers);
180
-                $opt       = $this->_getOpt($c,$delim,$modifiers);
181
-                $modifiers = trim($this->_getRemainModifiers($c,$delim,$modifiers));
179
+                $delim     = $this->_getDelim($c, $modifiers);
180
+                $opt       = $this->_getOpt($c, $delim, $modifiers);
181
+                $modifiers = trim($this->_getRemainModifiers($c, $delim, $modifiers));
182 182
 
183
-                $result[]=array('cmd'=>trim($match[1]),'opt'=>$opt,'debuginfo'=>$debuginfo);
183
+                $result[] = array('cmd'=>trim($match[1]), 'opt'=>$opt, 'debuginfo'=>$debuginfo);
184 184
                 $cmd = '';
185 185
             }
186
-            elseif(in_array($c,array('+','-','*','/')) && preg_match('@^[0-9]+@', $modifiers, $match)) { // :+3, :-3, :*3 ...
187
-                $modifiers = substr($modifiers,strlen($match[0]));
188
-                $result[]=array('cmd'=>'math','opt'=>'%s'.$c.$match[0]);
186
+            elseif (in_array($c, array('+', '-', '*', '/')) && preg_match('@^[0-9]+@', $modifiers, $match)) { // :+3, :-3, :*3 ...
187
+                $modifiers = substr($modifiers, strlen($match[0]));
188
+                $result[] = array('cmd'=>'math', 'opt'=>'%s'.$c.$match[0]);
189 189
                 $cmd = '';
190 190
             }
191
-            elseif($c==='(' || $c==='=') {
191
+            elseif ($c === '(' || $c === '=') {
192 192
                 $modifiers = $m1 = trim($modifiers);
193
-                $delim     = $this->_getDelim($c,$modifiers);
194
-                $opt       = $this->_getOpt($c,$delim,$modifiers);
195
-                $modifiers = trim($this->_getRemainModifiers($c,$delim,$modifiers));
193
+                $delim     = $this->_getDelim($c, $modifiers);
194
+                $opt       = $this->_getOpt($c, $delim, $modifiers);
195
+                $modifiers = trim($this->_getRemainModifiers($c, $delim, $modifiers));
196 196
                 $debuginfo = "#i=1 #c=[{$c}] #delim=[{$delim}] #m1=[{$m1}] remainMdf=[{$modifiers}]";
197 197
 
198
-                $result[]=array('cmd'=>trim($cmd),'opt'=>$opt,'debuginfo'=>$debuginfo);
198
+                $result[] = array('cmd'=>trim($cmd), 'opt'=>$opt, 'debuginfo'=>$debuginfo);
199 199
 
200 200
                 $cmd = '';
201 201
             }
202
-            elseif($c==':') {
202
+            elseif ($c == ':') {
203 203
                 $debuginfo = "#i=2 #c=[{$c}] #m=[{$modifiers}]";
204
-                if($cmd!=='') $result[]=array('cmd'=>trim($cmd),'opt'=>'','debuginfo'=>$debuginfo);
204
+                if ($cmd !== '') $result[] = array('cmd'=>trim($cmd), 'opt'=>'', 'debuginfo'=>$debuginfo);
205 205
 
206 206
                 $cmd = '';
207 207
             }
208
-            elseif(trim($modifiers)=='' && trim($cmd)!=='') {
208
+            elseif (trim($modifiers) == '' && trim($cmd) !== '') {
209 209
                 $debuginfo = "#i=3 #c=[{$c}] #m=[{$modifiers}]";
210 210
                 $cmd .= $c;
211
-                $result[]=array('cmd'=>trim($cmd),'opt'=>'','debuginfo'=>$debuginfo);
211
+                $result[] = array('cmd'=>trim($cmd), 'opt'=>'', 'debuginfo'=>$debuginfo);
212 212
 
213 213
                 break;
214 214
             }
@@ -217,65 +217,65 @@  discard block
 block discarded – undo
217 217
             }
218 218
         }
219 219
 
220
-        if(empty($result)) return array();
220
+        if (empty($result)) return array();
221 221
 
222
-        foreach($result as $i=>$a)
222
+        foreach ($result as $i=>$a)
223 223
         {
224 224
             $a['opt'] = $this->parseDocumentSource($a['opt']);
225
-            $result[$i]['opt'] = $modx->mergePlaceholderContent($a['opt'],$this->placeholders);
225
+            $result[$i]['opt'] = $modx->mergePlaceholderContent($a['opt'], $this->placeholders);
226 226
         }
227 227
 
228 228
         return $result;
229 229
     }
230 230
 
231
-    public function parsePhx($key,$value,$modifiers)
231
+    public function parsePhx($key, $value, $modifiers)
232 232
     {
233 233
         $modx = evolutionCMS();
234 234
         $lastKey = '';
235
-        $cacheKey = md5(sprintf('parsePhx#%s#%s#%s',$key,$value,print_r($modifiers,true)));
236
-        if(isset($this->tmpCache[$cacheKey])) return $this->tmpCache[$cacheKey];
237
-        if(empty($modifiers)) return '';
235
+        $cacheKey = md5(sprintf('parsePhx#%s#%s#%s', $key, $value, print_r($modifiers, true)));
236
+        if (isset($this->tmpCache[$cacheKey])) return $this->tmpCache[$cacheKey];
237
+        if (empty($modifiers)) return '';
238 238
 
239
-        foreach($modifiers as $m)
239
+        foreach ($modifiers as $m)
240 240
         {
241 241
             $lastKey = strtolower($m['cmd']);
242 242
         }
243
-        $_ = explode(',',$this->condModifiers);
244
-        if(in_array($lastKey,$_))
243
+        $_ = explode(',', $this->condModifiers);
244
+        if (in_array($lastKey, $_))
245 245
         {
246
-            $modifiers[] = array('cmd'=>'then','opt'=>'1');
247
-            $modifiers[] = array('cmd'=>'else','opt'=>'0');
246
+            $modifiers[] = array('cmd'=>'then', 'opt'=>'1');
247
+            $modifiers[] = array('cmd'=>'else', 'opt'=>'0');
248 248
         }
249 249
 
250
-        foreach($modifiers as $i=>$a)
250
+        foreach ($modifiers as $i=>$a)
251 251
         {
252
-            $value = $this->Filter($key,$value, $a['cmd'], $a['opt']);
252
+            $value = $this->Filter($key, $value, $a['cmd'], $a['opt']);
253 253
         }
254 254
         $this->tmpCache[$cacheKey] = $value;
255 255
         return $value;
256 256
     }
257 257
 
258 258
     // Parser: modifier detection and eXtended processing if needed
259
-    public function Filter($key, $value, $cmd, $opt='')
259
+    public function Filter($key, $value, $cmd, $opt = '')
260 260
     {
261 261
         $modx = evolutionCMS();
262 262
 
263
-        if($key==='documentObject') $value = $modx->documentIdentifier;
263
+        if ($key === 'documentObject') $value = $modx->documentIdentifier;
264 264
         $cmd = $this->parseDocumentSource($cmd);
265
-        if(preg_match('@^[1-9][/0-9]*$@',$cmd))
265
+        if (preg_match('@^[1-9][/0-9]*$@', $cmd))
266 266
         {
267
-            if(strpos($cmd,'/')!==false)
268
-                $cmd = $this->substr($cmd,strrpos($cmd,'/')+1);
267
+            if (strpos($cmd, '/') !== false)
268
+                $cmd = $this->substr($cmd, strrpos($cmd, '/') + 1);
269 269
             $opt = $cmd;
270 270
             $cmd = 'id';
271 271
         }
272 272
 
273
-        if(isset($modx->snippetCache["phx:{$cmd}"]))   $this->elmName = "phx:{$cmd}";
274
-        elseif(isset($modx->chunkCache["phx:{$cmd}"])) $this->elmName = "phx:{$cmd}";
273
+        if (isset($modx->snippetCache["phx:{$cmd}"]))   $this->elmName = "phx:{$cmd}";
274
+        elseif (isset($modx->chunkCache["phx:{$cmd}"])) $this->elmName = "phx:{$cmd}";
275 275
         else                                           $this->elmName = '';
276 276
 
277 277
         $cmd = strtolower($cmd);
278
-        if($this->elmName!=='')
278
+        if ($this->elmName !== '')
279 279
             $value = $this->getValueFromElement($key, $value, $cmd, $opt);
280 280
         else
281 281
             $value = $this->getValueFromPreset($key, $value, $cmd, $opt);
@@ -285,12 +285,12 @@  discard block
 block discarded – undo
285 285
         return $value;
286 286
     }
287 287
 
288
-    public function isEmpty($cmd,$value)
288
+    public function isEmpty($cmd, $value)
289 289
     {
290
-        if($value!=='') return false;
290
+        if ($value !== '') return false;
291 291
 
292
-        $_ = explode(',', $this->condModifiers . ',_default,default,if,input,or,and,show,this,select,switch,then,else,id,ifempty,smart_desc,smart_description,summary');
293
-        if(in_array($cmd,$_)) return false;
292
+        $_ = explode(',', $this->condModifiers.',_default,default,if,input,or,and,show,this,select,switch,then,else,id,ifempty,smart_desc,smart_description,summary');
293
+        if (in_array($cmd, $_)) return false;
294 294
         else                  return true;
295 295
     }
296 296
 
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
     {
299 299
         $modx = evolutionCMS();
300 300
 
301
-        if($this->isEmpty($cmd,$value)) return '';
301
+        if ($this->isEmpty($cmd, $value)) return '';
302 302
 
303 303
         $this->key = $key;
304 304
         $this->value  = $value;
@@ -309,83 +309,83 @@  discard block
 block discarded – undo
309 309
             #####  Conditional Modifiers
310 310
             case 'input':
311 311
             case 'if':
312
-                if(!$opt) return $value;
312
+                if (!$opt) return $value;
313 313
                 return $opt;
314 314
             case '=':
315 315
             case 'eq':
316 316
             case 'is':
317 317
             case 'equals':
318
-                $this->condition[] = (int)($value == $opt); break;
318
+                $this->condition[] = (int) ($value == $opt); break;
319 319
             case 'neq':
320 320
             case 'ne':
321 321
             case 'notequals':
322 322
             case 'isnot':
323 323
             case 'isnt':
324 324
             case 'not':
325
-                $this->condition[] = (int)($value != $opt);break;
325
+                $this->condition[] = (int) ($value != $opt); break;
326 326
             case '%':
327
-                $this->condition[] = (int)($value%$opt==0);break;
327
+                $this->condition[] = (int) ($value % $opt == 0); break;
328 328
             case 'isempty':
329
-                $this->condition[] = (int)(empty($value)); break;
329
+                $this->condition[] = (int) (empty($value)); break;
330 330
             case 'isntempty':
331 331
             case 'isnotempty':
332
-                $this->condition[] = (int)(!empty($value)); break;
332
+                $this->condition[] = (int) (!empty($value)); break;
333 333
             case '>=':
334 334
             case 'gte':
335 335
             case 'eg':
336 336
             case 'isgte':
337
-                $this->condition[] = (int)($value >= $opt);break;
337
+                $this->condition[] = (int) ($value >= $opt); break;
338 338
             case '<=':
339 339
             case 'lte':
340 340
             case 'el':
341 341
             case 'islte':
342
-                $this->condition[] = (int)($value <= $opt);break;
342
+                $this->condition[] = (int) ($value <= $opt); break;
343 343
             case '>':
344 344
             case 'gt':
345 345
             case 'greaterthan':
346 346
             case 'isgreaterthan':
347 347
             case 'isgt':
348
-                $this->condition[] = (int)($value > $opt);break;
348
+                $this->condition[] = (int) ($value > $opt); break;
349 349
             case '<':
350 350
             case 'lt':
351 351
             case 'lowerthan':
352 352
             case 'islowerthan':
353 353
             case 'islt':
354
-                $this->condition[] = (int)($value < $opt);break;
354
+                $this->condition[] = (int) ($value < $opt); break;
355 355
             case 'find':
356
-                $this->condition[] = (int)(strpos($value, $opt)!==false);break;
356
+                $this->condition[] = (int) (strpos($value, $opt) !== false); break;
357 357
             case 'inarray':
358 358
             case 'in_array':
359 359
             case 'in':
360 360
                 $opt = explode(',', $opt);
361
-                $this->condition[] = (int)(in_array($value, $opt)!==false);break;
361
+                $this->condition[] = (int) (in_array($value, $opt) !== false); break;
362 362
             case 'wildcard_match':
363 363
             case 'wcard_match':
364 364
             case 'wildcard':
365 365
             case 'wcard':
366 366
             case 'fnmatch':
367
-                $this->condition[] = (int)(fnmatch($opt, $value)!==false);break;
367
+                $this->condition[] = (int) (fnmatch($opt, $value) !== false); break;
368 368
             case 'is_file':
369 369
             case 'is_dir':
370 370
             case 'file_exists':
371 371
             case 'is_readable':
372 372
             case 'is_writable':
373
-                if(!$opt) $path = $value;
373
+                if (!$opt) $path = $value;
374 374
                 else      $path = $opt;
375
-                if(strpos($path,MODX_MANAGER_PATH)!==false) exit('Can not read core path');
376
-                if(strpos($path,$modx->config['base_path'])===false) $path = ltrim($path,'/');
377
-                $this->condition[] = (int)($cmd($path)!==false);break;
375
+                if (strpos($path, MODX_MANAGER_PATH) !== false) exit('Can not read core path');
376
+                if (strpos($path, $modx->config['base_path']) === false) $path = ltrim($path, '/');
377
+                $this->condition[] = (int) ($cmd($path) !== false); break;
378 378
             case 'is_image':
379
-                if(!$opt) $path = $value;
379
+                if (!$opt) $path = $value;
380 380
                 else      $path = $opt;
381
-                if(!is_file($path)) {$this->condition[]='0';break;}
381
+                if (!is_file($path)) {$this->condition[] = '0'; break; }
382 382
                 $_ = getimagesize($path);
383
-                $this->condition[] = (int)($_[0]);break;
383
+                $this->condition[] = (int) ($_[0]); break;
384 384
             case 'regex':
385 385
             case 'preg':
386 386
             case 'preg_match':
387 387
             case 'isinrole':
388
-                $this->condition[] = (int)(preg_match($opt,$value));break;
388
+                $this->condition[] = (int) (preg_match($opt, $value)); break;
389 389
             case 'ir':
390 390
             case 'memberof':
391 391
             case 'mo':
@@ -393,50 +393,50 @@  discard block
 block discarded – undo
393 393
                 $this->condition[] = $this->includeMdfFile('memberof');
394 394
                 break;
395 395
             case 'or':
396
-                $this->condition[] = '||';break;
396
+                $this->condition[] = '||'; break;
397 397
             case 'and':
398
-                $this->condition[] = '&&';break;
398
+                $this->condition[] = '&&'; break;
399 399
             case 'show':
400 400
             case 'this':
401
-                $conditional = implode(' ',$this->condition);
402
-                $isvalid = (int)(eval("return ({$conditional});"));
401
+                $conditional = implode(' ', $this->condition);
402
+                $isvalid = (int) (eval("return ({$conditional});"));
403 403
                 if ($isvalid) return $this->srcValue;
404 404
                 return NULL;
405 405
             case 'then':
406
-                $conditional = implode(' ',$this->condition);
407
-                $isvalid = (int)eval("return ({$conditional});");
406
+                $conditional = implode(' ', $this->condition);
407
+                $isvalid = (int) eval("return ({$conditional});");
408 408
                 if ($isvalid)  return $opt;
409 409
                 return null;
410 410
             case 'else':
411
-                $conditional = implode(' ',$this->condition);
412
-                $isvalid = (int)eval("return ({$conditional});");
411
+                $conditional = implode(' ', $this->condition);
412
+                $isvalid = (int) eval("return ({$conditional});");
413 413
                 if (!$isvalid) return $opt;
414 414
                 break;
415 415
             case 'select':
416 416
             case 'switch':
417
-                $raw = explode('&',$opt);
417
+                $raw = explode('&', $opt);
418 418
                 $map = array();
419 419
                 $c = count($raw);
420
-                for($m=0; $m<$c; $m++) {
421
-                    $mi = explode('=',$raw[$m],2);
420
+                for ($m = 0; $m < $c; $m++) {
421
+                    $mi = explode('=', $raw[$m], 2);
422 422
                     $map[$mi[0]] = $mi[1];
423 423
                 }
424
-                if(isset($map[$value])) return $map[$value];
424
+                if (isset($map[$value])) return $map[$value];
425 425
                 else                    return '';
426 426
             ##### End of Conditional Modifiers
427 427
 
428 428
             #####  Encode / Decode / Hash / Escape
429 429
             case 'htmlent':
430 430
             case 'htmlentities':
431
-                return htmlentities($value,ENT_QUOTES,$modx->config['modx_charset']);
431
+                return htmlentities($value, ENT_QUOTES, $modx->config['modx_charset']);
432 432
             case 'html_entity_decode':
433 433
             case 'decode_html':
434 434
             case 'html_decode':
435
-                return html_entity_decode($value,ENT_QUOTES,$modx->config['modx_charset']);
435
+                return html_entity_decode($value, ENT_QUOTES, $modx->config['modx_charset']);
436 436
             case 'esc':
437 437
             case 'escape':
438 438
                 $value = preg_replace('/&amp;(#[0-9]+|[a-z]+);/i', '&$1;', htmlspecialchars($value, ENT_QUOTES, $modx->config['modx_charset']));
439
-                return str_replace(array('[', ']', '`'),array('&#91;', '&#93;', '&#96;'),$value);
439
+                return str_replace(array('[', ']', '`'), array('&#91;', '&#93;', '&#96;'), $value);
440 440
             case 'sql_escape':
441 441
             case 'encode_js':
442 442
                 return $modx->getDatabase()->escape($value);
@@ -446,39 +446,39 @@  discard block
 block discarded – undo
446 446
             case 'html_encode':
447 447
                 return preg_replace('/&amp;(#[0-9]+|[a-z]+);/i', '&$1;', htmlspecialchars($value, ENT_QUOTES, $modx->config['modx_charset']));
448 448
             case 'spam_protect':
449
-                return str_replace(array('@','.'),array('&#64;','&#46;'),$value);
449
+                return str_replace(array('@', '.'), array('&#64;', '&#46;'), $value);
450 450
             case 'strip':
451
-                if($opt==='') $opt = ' ';
451
+                if ($opt === '') $opt = ' ';
452 452
                 return preg_replace('/[\n\r\t\s]+/', $opt, $value);
453 453
             case 'strip_linefeeds':
454
-                return str_replace(array("\n","\r"), '', $value);
454
+                return str_replace(array("\n", "\r"), '', $value);
455 455
             case 'notags':
456 456
             case 'strip_tags':
457 457
             case 'remove_html':
458
-                if($opt!=='')
458
+                if ($opt !== '')
459 459
                 {
460 460
                     $param = array();
461
-                    foreach(explode(',',$opt) as $v)
461
+                    foreach (explode(',', $opt) as $v)
462 462
                     {
463
-                        $v = trim($v,'</> ');
463
+                        $v = trim($v, '</> ');
464 464
                         $param[] = "<{$v}>";
465 465
                     }
466
-                    $params = implode(',',$param);
466
+                    $params = implode(',', $param);
467 467
                 }
468 468
                 else $params = '';
469
-                if(!strpos($params,'<br>')===false) {
470
-                    $value = preg_replace('@(<br[ /]*>)\n@','$1',$value);
471
-                    $value = preg_replace('@<br[ /]*>@',"\n",$value);
469
+                if (!strpos($params, '<br>') === false) {
470
+                    $value = preg_replace('@(<br[ /]*>)\n@', '$1', $value);
471
+                    $value = preg_replace('@<br[ /]*>@', "\n", $value);
472 472
                 }
473
-                return $this->strip_tags($value,$params);
473
+                return $this->strip_tags($value, $params);
474 474
             case 'urlencode':
475 475
             case 'url_encode':
476 476
             case 'encode_url':
477 477
                 return urlencode($value);
478 478
             case 'base64_decode':
479
-                if($opt!=='false') $opt = true;
479
+                if ($opt !== 'false') $opt = true;
480 480
                 else               $opt = false;
481
-                return base64_decode($value,$opt);
481
+                return base64_decode($value, $opt);
482 482
             case 'encode_sha1': $cmd = 'sha1';
483 483
             case 'addslashes':
484 484
             case 'urldecode':
@@ -502,18 +502,18 @@  discard block
 block discarded – undo
502 502
             case 'upper_case':
503 503
                 return $this->strtoupper($value);
504 504
             case 'capitalize':
505
-                $_ = explode(' ',$value);
506
-                foreach($_ as $i=>$v)
505
+                $_ = explode(' ', $value);
506
+                foreach ($_ as $i=>$v)
507 507
                 {
508 508
                     $_[$i] = ucfirst($v);
509 509
                 }
510
-                return implode(' ',$_);
510
+                return implode(' ', $_);
511 511
             case 'zenhan':
512
-                if(empty($opt)) $opt='VKas';
513
-                return mb_convert_kana($value,$opt,$modx->config['modx_charset']);
512
+                if (empty($opt)) $opt = 'VKas';
513
+                return mb_convert_kana($value, $opt, $modx->config['modx_charset']);
514 514
             case 'hanzen':
515
-                if(empty($opt)) $opt='VKAS';
516
-                return mb_convert_kana($value,$opt,$modx->config['modx_charset']);
515
+                if (empty($opt)) $opt = 'VKAS';
516
+                return mb_convert_kana($value, $opt, $modx->config['modx_charset']);
517 517
             case 'str_shuffle':
518 518
             case 'shuffle':
519 519
                 return $this->str_shuffle($value);
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
                 return $this->strlen($value);
528 528
             case 'count_words':
529 529
                 $value = trim($value);
530
-                return count(preg_split('/\s+/',$value));
530
+                return count(preg_split('/\s+/', $value));
531 531
             case 'str_word_count':
532 532
             case 'word_count':
533 533
             case 'wordcount':
@@ -535,55 +535,55 @@  discard block
 block discarded – undo
535 535
             case 'count_paragraphs':
536 536
                 $value = trim($value);
537 537
                 $value = preg_replace('/\r/', '', $value);
538
-                return count(preg_split('/\n+/',$value));
538
+                return count(preg_split('/\n+/', $value));
539 539
             case 'strpos':
540
-                if($opt!=0&&empty($opt)) return $value;
541
-                return $this->strpos($value,$opt);
540
+                if ($opt != 0 && empty($opt)) return $value;
541
+                return $this->strpos($value, $opt);
542 542
             case 'wordwrap':
543 543
                 // default: 70
544
-                $wrapat = (int)$opt > 0 ? (int)$opt : 70;
544
+                $wrapat = (int) $opt > 0 ? (int) $opt : 70;
545 545
                 if (version_compare(PHP_VERSION, '5.3.0') >= 0) return $this->includeMdfFile('wordwrap');
546
-                else return preg_replace("@(\b\w+\b)@e","wordwrap('\\1',\$wrapat,' ',1)",$value);
546
+                else return preg_replace("@(\b\w+\b)@e", "wordwrap('\\1',\$wrapat,' ',1)", $value);
547 547
             case 'wrap_text':
548
-                $width = preg_match('/^[1-9][0-9]*$/',$opt) ? $opt : 70;
549
-                if($modx->config['manager_language']==='japanese-utf8') {
548
+                $width = preg_match('/^[1-9][0-9]*$/', $opt) ? $opt : 70;
549
+                if ($modx->config['manager_language'] === 'japanese-utf8') {
550 550
                     $chunk = array();
551
-                    $bt='';
552
-                    while($bt!=$value) {
551
+                    $bt = '';
552
+                    while ($bt != $value) {
553 553
                         $bt = $value;
554
-                        if($this->strlen($value)<$width) {
554
+                        if ($this->strlen($value) < $width) {
555 555
                             $chunk[] = $value;
556 556
                             break;
557 557
                         }
558
-                        $chunk[] = $this->substr($value,0,$width);
559
-                        $value = $this->substr($value,$width);
558
+                        $chunk[] = $this->substr($value, 0, $width);
559
+                        $value = $this->substr($value, $width);
560 560
                     }
561
-                    return implode("\n",$chunk);
561
+                    return implode("\n", $chunk);
562 562
                 }
563 563
                 else
564
-                    return wordwrap($value,$width,"\n",true);
564
+                    return wordwrap($value, $width, "\n", true);
565 565
             case 'substr':
566
-                if(empty($opt)) break;
567
-                if(strpos($opt,',')!==false) {
568
-                    list($b,$e) = explode(',',$opt,2);
569
-                    return $this->substr($value,$b,(int)$e);
566
+                if (empty($opt)) break;
567
+                if (strpos($opt, ',') !== false) {
568
+                    list($b, $e) = explode(',', $opt, 2);
569
+                    return $this->substr($value, $b, (int) $e);
570 570
                 }
571
-                else return $this->substr($value,$opt);
571
+                else return $this->substr($value, $opt);
572 572
             case 'limit':
573 573
             case 'trim_to': // http://www.movabletype.jp/documentation/appendices/modifiers/trim_to.html
574
-                if(strpos($opt,'+')!==false)
575
-                    list($len,$str) = explode('+',$opt,2);
574
+                if (strpos($opt, '+') !== false)
575
+                    list($len, $str) = explode('+', $opt, 2);
576 576
                 else {
577 577
                     $len = $opt;
578 578
                     $str = '';
579 579
                 }
580
-                if($len==='') $len = 100;
581
-                if(abs($len) > $this->strlen($value)) $str ='';
582
-                if(preg_match('/^[1-9][0-9]*$/',$len)) {
583
-                    return $this->substr($value,0,$len) . $str;
580
+                if ($len === '') $len = 100;
581
+                if (abs($len) > $this->strlen($value)) $str = '';
582
+                if (preg_match('/^[1-9][0-9]*$/', $len)) {
583
+                    return $this->substr($value, 0, $len).$str;
584 584
                 }
585
-                elseif(preg_match('/^\-[1-9][0-9]*$/',$len)) {
586
-                    return $str . $this->substr($value,$len);
585
+                elseif (preg_match('/^\-[1-9][0-9]*$/', $len)) {
586
+                    return $str.$this->substr($value, $len);
587 587
                 }
588 588
                 break;
589 589
             case 'summary':
@@ -592,81 +592,81 @@  discard block
 block discarded – undo
592 592
                 return $this->includeMdfFile('summary');
593 593
             case 'replace':
594 594
             case 'str_replace':
595
-                if(empty($opt) || strpos($opt,',')===false) break;
596
-                if    (substr_count($opt, ',') ==1) $delim = ',';
597
-                elseif(substr_count($opt, '|') ==1) $delim = '|';
598
-                elseif(substr_count($opt, '=>')==1) $delim = '=>';
599
-                elseif(substr_count($opt, '/') ==1) $delim = '/';
595
+                if (empty($opt) || strpos($opt, ',') === false) break;
596
+                if (substr_count($opt, ',') == 1) $delim = ',';
597
+                elseif (substr_count($opt, '|') == 1) $delim = '|';
598
+                elseif (substr_count($opt, '=>') == 1) $delim = '=>';
599
+                elseif (substr_count($opt, '/') == 1) $delim = '/';
600 600
                 else break;
601
-                list($s,$r) = explode($delim,$opt);
602
-                if($value!=='') return str_replace($s,$r,$value);
601
+                list($s, $r) = explode($delim, $opt);
602
+                if ($value !== '') return str_replace($s, $r, $value);
603 603
                 break;
604 604
             case 'replace_to':
605 605
             case 'tpl':
606
-                if($value!=='') return str_replace(array('[+value+]','[+output+]','{value}','%s'),$value,$opt);
606
+                if ($value !== '') return str_replace(array('[+value+]', '[+output+]', '{value}', '%s'), $value, $opt);
607 607
                 break;
608 608
             case 'eachtpl':
609
-                $value = explode('||',$value);
609
+                $value = explode('||', $value);
610 610
                 $_ = array();
611
-                foreach($value as $v) {
612
-                    $_[] = str_replace(array('[+value+]','[+output+]','{value}','%s'),$v,$opt);
611
+                foreach ($value as $v) {
612
+                    $_[] = str_replace(array('[+value+]', '[+output+]', '{value}', '%s'), $v, $opt);
613 613
                 }
614 614
                 return implode("\n", $_);
615 615
             case 'array_pop':
616 616
             case 'array_shift':
617
-                if(strpos($value,'||')!==false) $delim = '||';
617
+                if (strpos($value, '||') !== false) $delim = '||';
618 618
                 else                            $delim = ',';
619
-                return $cmd(explode($delim,$value));
619
+                return $cmd(explode($delim, $value));
620 620
             case 'preg_replace':
621 621
             case 'regex_replace':
622
-                if(empty($opt) || strpos($opt,',')===false) break;
623
-                list($s,$r) = explode(',',$opt,2);
624
-                if($value!=='') return preg_replace($s,$r,$value);
622
+                if (empty($opt) || strpos($opt, ',') === false) break;
623
+                list($s, $r) = explode(',', $opt, 2);
624
+                if ($value !== '') return preg_replace($s, $r, $value);
625 625
                 break;
626 626
             case 'cat':
627 627
             case 'concatenate':
628 628
             case '.':
629
-                if($value!=='') return $value . $opt;
629
+                if ($value !== '') return $value.$opt;
630 630
                 break;
631 631
             case 'sprintf':
632 632
             case 'string_format':
633
-                if($value!=='') return sprintf($opt,$value);
633
+                if ($value !== '') return sprintf($opt, $value);
634 634
                 break;
635 635
             case 'number_format':
636
-                if($opt=='') $opt = 0;
637
-                return number_format($value,$opt);
636
+                if ($opt == '') $opt = 0;
637
+                return number_format($value, $opt);
638 638
             case 'money_format':
639
-                setlocale(LC_MONETARY,setlocale(LC_TIME,0));
640
-                if($value!=='') return money_format($opt,(double)$value);
639
+                setlocale(LC_MONETARY, setlocale(LC_TIME, 0));
640
+                if ($value !== '') return money_format($opt, (double) $value);
641 641
                 break;
642 642
             case 'tobool':
643 643
                 return boolval($value);
644 644
             case 'nl2lf':
645
-                if($value!=='') return str_replace(array("\r\n","\n", "\r"), '\n', $value);
645
+                if ($value !== '') return str_replace(array("\r\n", "\n", "\r"), '\n', $value);
646 646
                 break;
647 647
             case 'br2nl':
648 648
                 return preg_replace('@<br[\s/]*>@i', "\n", $value);
649 649
             case 'nl2br':
650 650
                 if (version_compare(PHP_VERSION, '5.3.0', '<'))
651 651
                     return nl2br($value);
652
-                if($opt!=='')
652
+                if ($opt !== '')
653 653
                 {
654 654
                     $opt = trim($opt);
655 655
                     $opt = strtolower($opt);
656
-                    if($opt==='false') $opt = false;
657
-                    elseif($opt==='0') $opt = false;
656
+                    if ($opt === 'false') $opt = false;
657
+                    elseif ($opt === '0') $opt = false;
658 658
                     else               $opt = true;
659 659
                 }
660
-                elseif(isset($modx->config['mce_element_format'])&&$modx->config['mce_element_format']==='html')
660
+                elseif (isset($modx->config['mce_element_format']) && $modx->config['mce_element_format'] === 'html')
661 661
                     $opt = false;
662 662
                 else                   $opt = true;
663
-                return nl2br($value,$opt);
663
+                return nl2br($value, $opt);
664 664
             case 'ltrim':
665 665
             case 'rtrim':
666 666
             case 'trim': // ref http://mblo.info/modifiers/custom-modifiers/rtrim_opt.html
667
-                if($opt==='')
667
+                if ($opt === '')
668 668
                     return $cmd($value);
669
-                else return $cmd($value,$opt);
669
+                else return $cmd($value, $opt);
670 670
             // These are all straight wrappers for PHP functions
671 671
             case 'ucfirst':
672 672
             case 'lcfirst':
@@ -677,58 +677,58 @@  discard block
 block discarded – undo
677 677
             case 'strftime':
678 678
             case 'date':
679 679
             case 'dateformat':
680
-                if(empty($opt)) $opt = $modx->toDateFormat(null, 'formatOnly');
681
-                if(!preg_match('@^[0-9]+$@',$value)) $value = strtotime($value);
682
-                if(strpos($opt,'%')!==false)
683
-                    return strftime($opt,0+$value);
680
+                if (empty($opt)) $opt = $modx->toDateFormat(null, 'formatOnly');
681
+                if (!preg_match('@^[0-9]+$@', $value)) $value = strtotime($value);
682
+                if (strpos($opt, '%') !== false)
683
+                    return strftime($opt, 0 + $value);
684 684
                 else
685
-                    return date($opt,0+$value);
685
+                    return date($opt, 0 + $value);
686 686
             case 'time':
687
-                if(empty($opt)) $opt = '%H:%M';
688
-                if(!preg_match('@^[0-9]+$@',$value)) $value = strtotime($value);
689
-                return strftime($opt,0+$value);
687
+                if (empty($opt)) $opt = '%H:%M';
688
+                if (!preg_match('@^[0-9]+$@', $value)) $value = strtotime($value);
689
+                return strftime($opt, 0 + $value);
690 690
             case 'strtotime':
691 691
                 return strtotime($value);
692 692
             #####  mathematical function
693 693
             case 'toint':
694
-                return (int)$value;
694
+                return (int) $value;
695 695
             case 'tofloat':
696 696
                 return floatval($value);
697 697
             case 'round':
698
-                if(!$opt) $opt = 0;
699
-                return $cmd($value,$opt);
698
+                if (!$opt) $opt = 0;
699
+                return $cmd($value, $opt);
700 700
             case 'max':
701 701
             case 'min':
702
-                return $cmd(explode(',',$value));
702
+                return $cmd(explode(',', $value));
703 703
             case 'floor':
704 704
             case 'ceil':
705 705
             case 'abs':
706 706
                 return $cmd($value);
707 707
             case 'math':
708 708
             case 'calc':
709
-                $value = (int)$value;
710
-                if(empty($value)) $value = '0';
711
-                $filter = str_replace(array('[+value+]','[+output+]','{value}','%s'),'?',$opt);
712
-                $filter = preg_replace('@([a-zA-Z\n\r\t\s])@','',$filter);
713
-                if(strpos($filter,'?')===false) $filter = "?{$filter}";
714
-                $filter = str_replace('?',$value,$filter);
709
+                $value = (int) $value;
710
+                if (empty($value)) $value = '0';
711
+                $filter = str_replace(array('[+value+]', '[+output+]', '{value}', '%s'), '?', $opt);
712
+                $filter = preg_replace('@([a-zA-Z\n\r\t\s])@', '', $filter);
713
+                if (strpos($filter, '?') === false) $filter = "?{$filter}";
714
+                $filter = str_replace('?', $value, $filter);
715 715
                 return eval("return {$filter};");
716 716
             case 'count':
717
-                if($value=='') return 0;
718
-                $value = explode(',',$value);
717
+                if ($value == '') return 0;
718
+                $value = explode(',', $value);
719 719
                 return count($value);
720 720
             case 'sort':
721 721
             case 'rsort':
722
-                if(strpos($value,"\n")!==false) $delim="\n";
722
+                if (strpos($value, "\n") !== false) $delim = "\n";
723 723
                 else $delim = ',';
724
-                $swap = explode($delim,$value);
725
-                if(!$opt) $opt = SORT_REGULAR;
724
+                $swap = explode($delim, $value);
725
+                if (!$opt) $opt = SORT_REGULAR;
726 726
                 else      $opt = constant($opt);
727
-                $cmd($swap,$opt);
728
-                return implode($delim,$swap);
727
+                $cmd($swap, $opt);
728
+                return implode($delim, $swap);
729 729
             #####  Resource fields
730 730
             case 'id':
731
-                if($opt) return $this->getDocumentObject($opt,$key);
731
+                if ($opt) return $this->getDocumentObject($opt, $key);
732 732
                 break;
733 733
             case 'type':
734 734
             case 'contenttype':
@@ -765,36 +765,36 @@  discard block
 block discarded – undo
765 765
             case 'privatemgr':
766 766
             case 'content_dispo':
767 767
             case 'hidemenu':
768
-                if($cmd==='contenttype') $cmd = 'contentType';
769
-                return $this->getDocumentObject($value,$cmd);
768
+                if ($cmd === 'contenttype') $cmd = 'contentType';
769
+                return $this->getDocumentObject($value, $cmd);
770 770
             case 'title':
771
-                $pagetitle = $this->getDocumentObject($value,'pagetitle');
772
-                $longtitle = $this->getDocumentObject($value,'longtitle');
771
+                $pagetitle = $this->getDocumentObject($value, 'pagetitle');
772
+                $longtitle = $this->getDocumentObject($value, 'longtitle');
773 773
                 return $longtitle ? $longtitle : $pagetitle;
774 774
             case 'shorttitle':
775
-                $pagetitle = $this->getDocumentObject($value,'pagetitle');
776
-                $menutitle = $this->getDocumentObject($value,'menutitle');
775
+                $pagetitle = $this->getDocumentObject($value, 'pagetitle');
776
+                $menutitle = $this->getDocumentObject($value, 'menutitle');
777 777
                 return $menutitle ? $menutitle : $pagetitle;
778 778
             case 'templatename':
779
-                $rs = $modx->getDatabase()->select('templatename','[+prefix+]site_templates',"id='{$value}'");
779
+                $rs = $modx->getDatabase()->select('templatename', '[+prefix+]site_templates', "id='{$value}'");
780 780
                 $templateName = $modx->getDatabase()->getValue($rs);
781 781
                 return !$templateName ? '(blank)' : $templateName;
782 782
             case 'getfield':
783
-                if(!$opt) $opt = 'content';
784
-                return $modx->getField($opt,$value);
783
+                if (!$opt) $opt = 'content';
784
+                return $modx->getField($opt, $value);
785 785
             case 'children':
786 786
             case 'childids':
787
-                if($value=='') $value = 0; // 値がない場合はルートと見なす
787
+                if ($value == '') $value = 0; // 値がない場合はルートと見なす
788 788
                 $published = 1;
789
-                if($opt=='') $opt = 'page';
790
-                $_ = explode(',',$opt);
789
+                if ($opt == '') $opt = 'page';
790
+                $_ = explode(',', $opt);
791 791
                 $where = array();
792
-                foreach($_ as $opt) {
793
-                    switch(trim($opt)) {
792
+                foreach ($_ as $opt) {
793
+                    switch (trim($opt)) {
794 794
                         case 'page'; case '!folder'; case '!isfolder': $where[] = 'sc.isfolder=0'; break;
795 795
                         case 'folder'; case 'isfolder':                $where[] = 'sc.isfolder=1'; break;
796
-                        case  'menu';  case  'show_menu':              $where[] = 'sc.hidemenu=0'; break;
797
-                        case '!menu';  case '!show_menu':              $where[] = 'sc.hidemenu=1'; break;
796
+                        case  'menu'; case  'show_menu':              $where[] = 'sc.hidemenu=0'; break;
797
+                        case '!menu'; case '!show_menu':              $where[] = 'sc.hidemenu=1'; break;
798 798
                         case  'published':                             $published = 1; break;
799 799
                         case '!published':                             $published = 0; break;
800 800
                     }
@@ -802,69 +802,69 @@  discard block
 block discarded – undo
802 802
                 $where = implode(' AND ', $where);
803 803
                 $children = $modx->getDocumentChildren($value, $published, '0', 'id', $where);
804 804
                 $result = array();
805
-                foreach((array)$children as $child){
805
+                foreach ((array) $children as $child) {
806 806
                     $result[] = $child['id'];
807 807
                 }
808 808
                 return implode(',', $result);
809 809
             case 'fullurl':
810
-                if(!is_numeric($value)) return $value;
810
+                if (!is_numeric($value)) return $value;
811 811
                 return $modx->makeUrl($value);
812 812
             case 'makeurl':
813
-                if(!is_numeric($value)) return $value;
814
-                if(!$opt) $opt = 'full';
815
-                return $modx->makeUrl($value,'','',$opt);
813
+                if (!is_numeric($value)) return $value;
814
+                if (!$opt) $opt = 'full';
815
+                return $modx->makeUrl($value, '', '', $opt);
816 816
 
817 817
             #####  File system
818 818
             case 'getimageinfo':
819 819
             case 'imageinfo':
820
-                if(!is_file($value)) return '';
820
+                if (!is_file($value)) return '';
821 821
                 $_ = getimagesize($value);
822
-                if(!$_[0]) return '';
822
+                if (!$_[0]) return '';
823 823
                 $info['width']  = $_[0];
824 824
                 $info['height'] = $_[1];
825
-                if    ($_[0] > $_[1]) $info['aspect'] = 'landscape';
826
-                elseif($_[0] < $_[1]) $info['aspect'] = 'portrait';
825
+                if ($_[0] > $_[1]) $info['aspect'] = 'landscape';
826
+                elseif ($_[0] < $_[1]) $info['aspect'] = 'portrait';
827 827
                 else                  $info['aspect'] = 'square';
828
-                switch($_[2]) {
828
+                switch ($_[2]) {
829 829
                     case IMAGETYPE_GIF  : $info['type'] = 'gif'; break;
830 830
                     case IMAGETYPE_JPEG : $info['type'] = 'jpg'; break;
831 831
                     case IMAGETYPE_PNG  : $info['type'] = 'png'; break;
832 832
                     default             : $info['type'] = 'unknown';
833 833
                 }
834 834
                 $info['attrib'] = $_[3];
835
-                switch($opt) {
835
+                switch ($opt) {
836 836
                     case 'width' : return $info['width'];
837 837
                     case 'height': return $info['height'];
838 838
                     case 'aspect': return $info['aspect'];
839 839
                     case 'type'  : return $info['type'];
840 840
                     case 'attrib': return $info['attrib'];
841
-                    default      : return print_r($info,true);
841
+                    default      : return print_r($info, true);
842 842
                 }
843 843
 
844 844
             case 'file_get_contents':
845 845
             case 'readfile':
846
-                if(!is_file($value)) return $value;
846
+                if (!is_file($value)) return $value;
847 847
                 $value = realpath($value);
848
-                if(strpos($value,MODX_MANAGER_PATH)!==false) exit('Can not read core file');
849
-                $ext = strtolower(substr($value,-4));
850
-                if($ext==='.php') exit('Can not read php file');
851
-                if($ext==='.cgi') exit('Can not read cgi file');
848
+                if (strpos($value, MODX_MANAGER_PATH) !== false) exit('Can not read core file');
849
+                $ext = strtolower(substr($value, -4));
850
+                if ($ext === '.php') exit('Can not read php file');
851
+                if ($ext === '.cgi') exit('Can not read cgi file');
852 852
                 return file_get_contents($value);
853 853
             case 'filesize':
854
-                if($value == '') return '';
854
+                if ($value == '') return '';
855 855
                 $filename = $value;
856 856
 
857 857
                 $site_url = $modx->config['site_url'];
858
-                if(strpos($filename,$site_url) === 0)
859
-                    $filename = substr($filename,0,strlen($site_url));
860
-                $filename = trim($filename,'/');
858
+                if (strpos($filename, $site_url) === 0)
859
+                    $filename = substr($filename, 0, strlen($site_url));
860
+                $filename = trim($filename, '/');
861 861
 
862
-                $opt = trim($opt,'/');
863
-                if($opt!=='') $opt .= '/';
862
+                $opt = trim($opt, '/');
863
+                if ($opt !== '') $opt .= '/';
864 864
 
865 865
                 $filename = MODX_BASE_PATH.$opt.$filename;
866 866
 
867
-                if(is_file($filename)){
867
+                if (is_file($filename)) {
868 868
                     clearstatcache();
869 869
                     $size = filesize($filename);
870 870
                     return $size;
@@ -897,10 +897,10 @@  discard block
 block discarded – undo
897 897
                 $this->opt = $cmd;
898 898
                 return $this->includeMdfFile('moduser');
899 899
             case 'userinfo':
900
-                if(empty($opt)) $this->opt = 'username';
900
+                if (empty($opt)) $this->opt = 'username';
901 901
                 return $this->includeMdfFile('moduser');
902 902
             case 'webuserinfo':
903
-                if(empty($opt)) $this->opt = 'username';
903
+                if (empty($opt)) $this->opt = 'username';
904 904
                 $this->value = -$value;
905 905
                 return $this->includeMdfFile('moduser');
906 906
             #####  Special functions
@@ -911,27 +911,27 @@  discard block
 block discarded – undo
911 911
             case 'ifnotempty':
912 912
                 if (!empty($value)) return $opt; break;
913 913
             case 'datagrid':
914
-                include_once(MODX_CORE_PATH . 'controls/datagrid.class.php');
914
+                include_once(MODX_CORE_PATH.'controls/datagrid.class.php');
915 915
                 $grd = new DataGrid(null, trim($value));
916 916
                 $grd->itemStyle = '';
917 917
                 $grd->altItemStyle = '';
918
-                $pos = strpos($value,"\n");
919
-                if($pos) $_ = substr($value,0,$pos);
918
+                $pos = strpos($value, "\n");
919
+                if ($pos) $_ = substr($value, 0, $pos);
920 920
                 else $_ = $pos;
921
-                $grd->cdelim = strpos($_,"\t")!==false ? 'tab' : ',';
921
+                $grd->cdelim = strpos($_, "\t") !== false ? 'tab' : ',';
922 922
                 return $grd->render();
923 923
             case 'rotate':
924 924
             case 'evenodd':
925
-                if(strpos($opt,',')===false) $opt = 'odd,even';
925
+                if (strpos($opt, ',') === false) $opt = 'odd,even';
926 926
                 $_ = explode(',', $opt);
927 927
                 $c = count($_);
928 928
                 $i = $value + $c;
929 929
                 $i = $i % $c;
930 930
                 return $_[$i];
931 931
             case 'takeval':
932
-                $arr = explode(",",$opt);
932
+                $arr = explode(",", $opt);
933 933
                 $idx = $value;
934
-                if(!is_numeric($idx)) return $value;
934
+                if (!is_numeric($idx)) return $value;
935 935
                 return $arr[$idx];
936 936
             case 'getimage':
937 937
                 return $this->includeMdfFile('getimage');
@@ -939,17 +939,17 @@  discard block
 block discarded – undo
939 939
                 return $modx->nicesize($value);
940 940
             case 'googlemap':
941 941
             case 'googlemaps':
942
-                if(empty($opt)) $opt = 'border:none;width:500px;height:350px;';
942
+                if (empty($opt)) $opt = 'border:none;width:500px;height:350px;';
943 943
                 $tpl = '<iframe style="[+style+]" src="https://maps.google.co.jp/maps?ll=[+value+]&output=embed&z=15"></iframe>';
944 944
                 $ph['style'] = $opt;
945 945
                 $ph['value'] = $value;
946
-                return $modx->parseText($tpl,$ph);
946
+                return $modx->parseText($tpl, $ph);
947 947
             case 'youtube':
948 948
             case 'youtube16x9':
949
-                if(empty($opt)) $opt = 560;
950
-                $h = round($opt*0.5625);
949
+                if (empty($opt)) $opt = 560;
950
+                $h = round($opt * 0.5625);
951 951
                 $tpl = '<iframe width="%s" height="%s" src="https://www.youtube.com/embed/%s" frameborder="0" allowfullscreen></iframe>';
952
-                return sprintf($tpl,$opt,$h,$value);
952
+                return sprintf($tpl, $opt, $h, $value);
953 953
             //case 'youtube4x3':%s*0.75+25
954 954
             case 'setvar':
955 955
                 $modx->placeholders[$opt] = $value;
@@ -979,7 +979,7 @@  discard block
 block discarded – undo
979 979
         return $value;
980 980
     }
981 981
 
982
-    public function includeMdfFile($cmd) {
982
+    public function includeMdfFile($cmd){
983 983
         $modx = evolutionCMS();
984 984
         $key = $this->key;
985 985
         $value  = $this->value;
@@ -990,54 +990,54 @@  discard block
 block discarded – undo
990 990
     public function getValueFromElement($key, $value, $cmd, $opt)
991 991
     {
992 992
         $modx = evolutionCMS();
993
-        if( isset($modx->snippetCache[$this->elmName]) )
993
+        if (isset($modx->snippetCache[$this->elmName]))
994 994
         {
995 995
             $php = $modx->snippetCache[$this->elmName];
996 996
         }
997 997
         else
998 998
         {
999 999
             $esc_elmName = $modx->getDatabase()->escape($this->elmName);
1000
-            $result = $modx->getDatabase()->select('snippet','[+prefix+]site_snippets',"name='{$esc_elmName}'");
1000
+            $result = $modx->getDatabase()->select('snippet', '[+prefix+]site_snippets', "name='{$esc_elmName}'");
1001 1001
             $total = $modx->getDatabase()->getRecordCount($result);
1002
-            if($total == 1)
1002
+            if ($total == 1)
1003 1003
             {
1004 1004
                 $row = $modx->getDatabase()->getRow($result);
1005 1005
                 $php = $row['snippet'];
1006 1006
             }
1007
-            elseif($total == 0)
1007
+            elseif ($total == 0)
1008 1008
             {
1009 1009
                 $assets_path = MODX_BASE_PATH.'assets/';
1010
-                if(is_file($assets_path."modifiers/mdf_{$cmd}.inc.php"))
1010
+                if (is_file($assets_path."modifiers/mdf_{$cmd}.inc.php"))
1011 1011
                     $modifiers_path = $assets_path."modifiers/mdf_{$cmd}.inc.php";
1012
-                elseif(is_file($assets_path."plugins/phx/modifiers/{$cmd}.phx.php"))
1012
+                elseif (is_file($assets_path."plugins/phx/modifiers/{$cmd}.phx.php"))
1013 1013
                     $modifiers_path = $assets_path."plugins/phx/modifiers/{$cmd}.phx.php";
1014
-                elseif(is_file(MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php"))
1014
+                elseif (is_file(MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php"))
1015 1015
                     $modifiers_path = MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php";
1016 1016
                 else $modifiers_path = false;
1017 1017
 
1018
-                if($modifiers_path !== false) {
1018
+                if ($modifiers_path !== false) {
1019 1019
                     $php = @file_get_contents($modifiers_path);
1020 1020
                     $php = trim($php);
1021
-                    if(substr($php,0,5)==='<?php') $php = substr($php,6);
1022
-                    if(substr($php,0,2)==='<?')    $php = substr($php,3);
1023
-                    if(substr($php,-2)==='?>')     $php = substr($php,0,-2);
1024
-                    if($this->elmName!=='')
1021
+                    if (substr($php, 0, 5) === '<?php') $php = substr($php, 6);
1022
+                    if (substr($php, 0, 2) === '<?')    $php = substr($php, 3);
1023
+                    if (substr($php, -2) === '?>')     $php = substr($php, 0, -2);
1024
+                    if ($this->elmName !== '')
1025 1025
                         $modx->snippetCache[$this->elmName.'Props'] = '';
1026 1026
                 }
1027 1027
                 else
1028 1028
                     $php = false;
1029 1029
             }
1030 1030
             else $php = false;
1031
-            if($this->elmName!=='') $modx->snippetCache[$this->elmName]= $php;
1031
+            if ($this->elmName !== '') $modx->snippetCache[$this->elmName] = $php;
1032 1032
         }
1033
-        if($php==='') $php=false;
1033
+        if ($php === '') $php = false;
1034 1034
 
1035
-        if($php===false) $html = $modx->getChunk($this->elmName);
1035
+        if ($php === false) $html = $modx->getChunk($this->elmName);
1036 1036
         else             $html = false;
1037 1037
 
1038 1038
         $self = '[+output+]';
1039 1039
 
1040
-        if($php !== false)
1040
+        if ($php !== false)
1041 1041
         {
1042 1042
             ob_start();
1043 1043
             $options = $opt;
@@ -1050,71 +1050,71 @@  discard block
 block discarded – undo
1050 1050
             $this->vars['options'] = & $opt;
1051 1051
             $custom = eval($php);
1052 1052
             $msg = ob_get_contents();
1053
-            if($value===$this->bt) $value = $msg . $custom;
1053
+            if ($value === $this->bt) $value = $msg.$custom;
1054 1054
             ob_end_clean();
1055 1055
         }
1056
-        elseif($html!==false && isset($value) && $value!=='')
1056
+        elseif ($html !== false && isset($value) && $value !== '')
1057 1057
         {
1058
-            $html = str_replace(array($self,'[+value+]'), $value, $html);
1059
-            $value = str_replace(array('[+options+]','[+param+]'), $opt, $html);
1058
+            $html = str_replace(array($self, '[+value+]'), $value, $html);
1059
+            $value = str_replace(array('[+options+]', '[+param+]'), $opt, $html);
1060 1060
         }
1061 1061
         else return false;
1062 1062
 
1063
-        if($php===false && $html===false && $value!==''
1064
-            && (strpos($cmd,'[+value+]')!==false || strpos($cmd,$self)!==false))
1063
+        if ($php === false && $html === false && $value !== ''
1064
+            && (strpos($cmd, '[+value+]') !== false || strpos($cmd, $self) !== false))
1065 1065
         {
1066
-            $value = str_replace(array('[+value+]',$self),$value,$cmd);
1066
+            $value = str_replace(array('[+value+]', $self), $value, $cmd);
1067 1067
         }
1068 1068
         return $value;
1069 1069
     }
1070 1070
 
1071
-    public function parseDocumentSource($content='')
1071
+    public function parseDocumentSource($content = '')
1072 1072
     {
1073 1073
         $modx = evolutionCMS();
1074 1074
 
1075
-        if(strpos($content,'[')===false && strpos($content,'{')===false) return $content;
1075
+        if (strpos($content, '[') === false && strpos($content, '{') === false) return $content;
1076 1076
 
1077
-        if(!$modx->maxParserPasses) $modx->maxParserPasses = 10;
1078
-        $bt='';
1079
-        $i=0;
1080
-        while($bt!==$content)
1077
+        if (!$modx->maxParserPasses) $modx->maxParserPasses = 10;
1078
+        $bt = '';
1079
+        $i = 0;
1080
+        while ($bt !== $content)
1081 1081
         {
1082 1082
             $bt = $content;
1083
-            if(strpos($content,'[*')!==false && $modx->documentIdentifier)
1083
+            if (strpos($content, '[*') !== false && $modx->documentIdentifier)
1084 1084
                 $content = $modx->mergeDocumentContent($content);
1085
-            if(strpos($content,'[(')!==false) $content = $modx->mergeSettingsContent($content);
1086
-            if(strpos($content,'{{')!==false) $content = $modx->mergeChunkContent($content);
1087
-            if(strpos($content,'[!')!==false) $content = str_replace(array('[!','!]'),array('[[',']]'),$content);
1088
-            if(strpos($content,'[[')!==false) $content = $modx->evalSnippets($content);
1085
+            if (strpos($content, '[(') !== false) $content = $modx->mergeSettingsContent($content);
1086
+            if (strpos($content, '{{') !== false) $content = $modx->mergeChunkContent($content);
1087
+            if (strpos($content, '[!') !== false) $content = str_replace(array('[!', '!]'), array('[[', ']]'), $content);
1088
+            if (strpos($content, '[[') !== false) $content = $modx->evalSnippets($content);
1089 1089
 
1090
-            if($content===$bt)              break;
1091
-            if($modx->maxParserPasses < $i) break;
1090
+            if ($content === $bt)              break;
1091
+            if ($modx->maxParserPasses < $i) break;
1092 1092
             $i++;
1093 1093
         }
1094 1094
         return $content;
1095 1095
     }
1096 1096
 
1097
-    public function getDocumentObject($target='',$field='pagetitle')
1097
+    public function getDocumentObject($target = '', $field = 'pagetitle')
1098 1098
     {
1099 1099
         $modx = evolutionCMS();
1100 1100
 
1101 1101
         $target = trim($target);
1102
-        if(empty($target)) $target = $modx->config['site_start'];
1103
-        if(preg_match('@^[1-9][0-9]*$@',$target)) $method='id';
1102
+        if (empty($target)) $target = $modx->config['site_start'];
1103
+        if (preg_match('@^[1-9][0-9]*$@', $target)) $method = 'id';
1104 1104
         else $method = 'alias';
1105 1105
 
1106
-        if(!isset($this->documentObject[$target]))
1106
+        if (!isset($this->documentObject[$target]))
1107 1107
         {
1108
-            $this->documentObject[$target] = $modx->getDocumentObject($method,$target,'direct');
1108
+            $this->documentObject[$target] = $modx->getDocumentObject($method, $target, 'direct');
1109 1109
         }
1110 1110
 
1111
-        if($this->documentObject[$target]['publishedon']==='0')
1111
+        if ($this->documentObject[$target]['publishedon'] === '0')
1112 1112
             return '';
1113
-        elseif(isset($this->documentObject[$target][$field]))
1113
+        elseif (isset($this->documentObject[$target][$field]))
1114 1114
         {
1115
-            if(is_array($this->documentObject[$target][$field]))
1115
+            if (is_array($this->documentObject[$target][$field]))
1116 1116
             {
1117
-                $a = $modx->getTemplateVarOutput($field,$target);
1117
+                $a = $modx->getTemplateVarOutput($field, $target);
1118 1118
                 $this->documentObject[$target][$field] = $a[$field];
1119 1119
             }
1120 1120
         }
@@ -1123,8 +1123,8 @@  discard block
 block discarded – undo
1123 1123
         return $this->documentObject[$target][$field];
1124 1124
     }
1125 1125
 
1126
-    public function setPlaceholders($value = '', $key = '', $path = '') {
1127
-        if($path!=='') $key = "{$path}.{$key}";
1126
+    public function setPlaceholders($value = '', $key = '', $path = ''){
1127
+        if ($path !== '') $key = "{$path}.{$key}";
1128 1128
         if (is_array($value)) {
1129 1129
             foreach ($value as $subkey => $subval) {
1130 1130
                 $this->setPlaceholders($subval, $subkey, $key);
@@ -1134,77 +1134,77 @@  discard block
 block discarded – undo
1134 1134
     }
1135 1135
 
1136 1136
     // Sets a placeholder variable which can only be access by Modifiers
1137
-    public function setModifiersVariable($key, $value) {
1137
+    public function setModifiersVariable($key, $value){
1138 1138
         if ($key != 'phx' && $key != 'dummy') $this->placeholders[$key] = $value;
1139 1139
     }
1140 1140
 
1141 1141
     //mbstring
1142
-    public function substr($str, $s, $l = null) {
1142
+    public function substr($str, $s, $l = null){
1143 1143
         $modx = evolutionCMS();
1144
-        if(is_null($l)) $l = $this->strlen($str);
1144
+        if (is_null($l)) $l = $this->strlen($str);
1145 1145
         if (function_exists('mb_substr'))
1146 1146
         {
1147
-            if(strpos($str,"\r")!==false)
1148
-                $str = str_replace(array("\r\n","\r"), "\n", $str);
1147
+            if (strpos($str, "\r") !== false)
1148
+                $str = str_replace(array("\r\n", "\r"), "\n", $str);
1149 1149
             return mb_substr($str, $s, $l, $modx->config['modx_charset']);
1150 1150
         }
1151 1151
         return substr($str, $s, $l);
1152 1152
     }
1153
-    public function strpos($haystack,$needle,$offset=0) {
1153
+    public function strpos($haystack, $needle, $offset = 0){
1154 1154
         $modx = evolutionCMS();
1155
-        if (function_exists('mb_strpos')) return mb_strpos($haystack,$needle,$offset,$modx->config['modx_charset']);
1156
-        return strpos($haystack,$needle,$offset);
1155
+        if (function_exists('mb_strpos')) return mb_strpos($haystack, $needle, $offset, $modx->config['modx_charset']);
1156
+        return strpos($haystack, $needle, $offset);
1157 1157
     }
1158
-    public function strlen($str) {
1158
+    public function strlen($str){
1159 1159
         $modx = evolutionCMS();
1160
-        if (function_exists('mb_strlen')) return mb_strlen(str_replace("\r\n", "\n", $str),$modx->config['modx_charset']);
1160
+        if (function_exists('mb_strlen')) return mb_strlen(str_replace("\r\n", "\n", $str), $modx->config['modx_charset']);
1161 1161
         return strlen($str);
1162 1162
     }
1163
-    public function strtolower($str) {
1163
+    public function strtolower($str){
1164 1164
         if (function_exists('mb_strtolower')) return mb_strtolower($str);
1165 1165
         return strtolower($str);
1166 1166
     }
1167
-    public function strtoupper($str) {
1167
+    public function strtoupper($str){
1168 1168
         if (function_exists('mb_strtoupper')) return mb_strtoupper($str);
1169 1169
         return strtoupper($str);
1170 1170
     }
1171
-    public function ucfirst($str) {
1171
+    public function ucfirst($str){
1172 1172
         if (function_exists('mb_strtoupper'))
1173 1173
             return mb_strtoupper($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str));
1174 1174
         return ucfirst($str);
1175 1175
     }
1176
-    public function lcfirst($str) {
1176
+    public function lcfirst($str){
1177 1177
         if (function_exists('mb_strtolower'))
1178 1178
             return mb_strtolower($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str));
1179 1179
         return lcfirst($str);
1180 1180
     }
1181
-    public function ucwords($str) {
1181
+    public function ucwords($str){
1182 1182
         if (function_exists('mb_convert_case'))
1183 1183
             return mb_convert_case($str, MB_CASE_TITLE);
1184 1184
         return ucwords($str);
1185 1185
     }
1186
-    public function strrev($str) {
1186
+    public function strrev($str){
1187 1187
         preg_match_all('/./us', $str, $ar);
1188 1188
         return implode(array_reverse($ar[0]));
1189 1189
     }
1190
-    public function str_shuffle($str) {
1190
+    public function str_shuffle($str){
1191 1191
         preg_match_all('/./us', $str, $ar);
1192 1192
         shuffle($ar[0]);
1193 1193
         return implode($ar[0]);
1194 1194
     }
1195
-    public function str_word_count($str) {
1196
-        return count(preg_split('~[^\p{L}\p{N}\']+~u',$str));
1195
+    public function str_word_count($str){
1196
+        return count(preg_split('~[^\p{L}\p{N}\']+~u', $str));
1197 1197
     }
1198
-    public function strip_tags($value,$params='') {
1198
+    public function strip_tags($value, $params = ''){
1199 1199
         $modx = evolutionCMS();
1200 1200
 
1201
-        if(stripos($params,'style')===false && stripos($value,'</style>')!==false) {
1201
+        if (stripos($params, 'style') === false && stripos($value, '</style>') !== false) {
1202 1202
             $value = preg_replace('@<style.*?>.*?</style>@is', '', $value);
1203 1203
         }
1204
-        if(stripos($params,'script')===false && stripos($value,'</script>')!==false) {
1204
+        if (stripos($params, 'script') === false && stripos($value, '</script>') !== false) {
1205 1205
             $value = preg_replace('@<script.*?>.*?</script>@is', '', $value);
1206 1206
         }
1207 1207
 
1208
-        return trim(strip_tags($value,$params));
1208
+        return trim(strip_tags($value, $params));
1209 1209
     }
1210 1210
 }
Please login to merge, or discard this patch.
Braces   +541 added lines, -281 removed lines patch added patch discarded remove patch
@@ -3,7 +3,8 @@  discard block
 block discarded – undo
3 3
 use EvolutionCMS\Interfaces\ModifiersInterface;
4 4
 use DataGrid;
5 5
 
6
-class Modifiers implements ModifiersInterface{
6
+class Modifiers implements ModifiersInterface
7
+{
7 8
     /**
8 9
      * @var array
9 10
      */
@@ -61,7 +62,9 @@  discard block
 block discarded – undo
61 62
     public function __construct()
62 63
     {
63 64
         $modx = evolutionCMS();
64
-        if (function_exists('mb_internal_encoding')) mb_internal_encoding($modx->config['modx_charset']);
65
+        if (function_exists('mb_internal_encoding')) {
66
+            mb_internal_encoding($modx->config['modx_charset']);
67
+        }
65 68
         $this->condModifiers = '=,is,eq,equals,ne,neq,notequals,isnot,isnt,not,%,isempty,isnotempty,isntempty,>=,gte,eg,gte,greaterthan,>,gt,isgreaterthan,isgt,lowerthan,<,lt,<=,lte,islte,islowerthan,islt,el,find,in,inarray,in_array,fnmatch,wcard,wcard_match,wildcard,wildcard_match,is_file,is_dir,file_exists,is_readable,is_writable,is_image,regex,preg,preg_match,memberof,mo,isinrole,ir';
66 69
     }
67 70
 
@@ -74,7 +77,9 @@  discard block
 block discarded – undo
74 77
     public function phxFilter($key,$value,$modifiers)
75 78
     {
76 79
         $modx = evolutionCMS();
77
-        if(substr($modifiers,0,3)!=='id(') $value = $this->parseDocumentSource($value);
80
+        if(substr($modifiers,0,3)!=='id(') {
81
+            $value = $this->parseDocumentSource($value);
82
+        }
78 83
         $this->srcValue = $value;
79 84
         $modifiers = trim($modifiers);
80 85
         $modifiers = ':'.trim($modifiers,':');
@@ -97,13 +102,18 @@  discard block
 block discarded – undo
97 102
      * @param string $modifiers
98 103
      * @return bool|string
99 104
      */
100
-    public function _getDelim($mode,$modifiers) {
105
+    public function _getDelim($mode,$modifiers)
106
+    {
101 107
         $c = substr($modifiers,0,1);
102
-        if(!in_array($c, array('"', "'", '`')) ) return false;
108
+        if(!in_array($c, array('"', "'", '`')) ) {
109
+            return false;
110
+        }
103 111
 
104 112
         $modifiers = substr($modifiers,1);
105 113
         $closure = $mode=='(' ? "{$c})" : $c;
106
-        if(strpos($modifiers, $closure)===false) return false;
114
+        if(strpos($modifiers, $closure)===false) {
115
+            return false;
116
+        }
107 117
 
108 118
         return  $c;
109 119
     }
@@ -114,52 +124,65 @@  discard block
 block discarded – undo
114 124
      * @param string $modifiers
115 125
      * @return bool|string
116 126
      */
117
-    public function _getOpt($mode,$delim,$modifiers) {
127
+    public function _getOpt($mode,$delim,$modifiers)
128
+    {
118 129
         if($delim) {
119
-            if($mode=='(') return substr($modifiers,1,strpos($modifiers, $delim . ')' )-1);
130
+            if($mode=='(') {
131
+                return substr($modifiers,1,strpos($modifiers, $delim . ')' )-1);
132
+            }
120 133
 
121 134
             return substr($modifiers,1,strpos($modifiers,$delim,1)-1);
122
-        }
123
-        else {
124
-            if($mode=='(') return substr($modifiers,0,strpos($modifiers, ')') );
135
+        } else {
136
+            if($mode=='(') {
137
+                return substr($modifiers,0,strpos($modifiers, ')') );
138
+            }
125 139
 
126 140
             $chars = str_split($modifiers);
127 141
             $opt='';
128 142
             foreach($chars as $c) {
129
-                if($c==':' || $c==')') break;
143
+                if($c==':' || $c==')') {
144
+                    break;
145
+                }
130 146
                 $opt .=$c;
131 147
             }
132 148
             return $opt;
133 149
         }
134 150
     }
135
-    public function _getRemainModifiers($mode,$delim,$modifiers) {
151
+    public function _getRemainModifiers($mode,$delim,$modifiers)
152
+    {
136 153
         if($delim) {
137
-            if($mode=='(')
138
-                return $this->_fetchContent($modifiers, $delim . ')');
139
-            else {
154
+            if($mode=='(') {
155
+                            return $this->_fetchContent($modifiers, $delim . ')');
156
+            } else {
140 157
                 $modifiers = trim($modifiers);
141 158
                 $modifiers = substr($modifiers,1);
142 159
                 return $this->_fetchContent($modifiers, $delim);
143 160
             }
144
-        }
145
-        else {
146
-            if($mode=='(') return $this->_fetchContent($modifiers, ')');
161
+        } else {
162
+            if($mode=='(') {
163
+                return $this->_fetchContent($modifiers, ')');
164
+            }
147 165
             $chars = str_split($modifiers);
148 166
             foreach($chars as $c) {
149
-                if($c==':') return $modifiers;
150
-                else $modifiers = substr($modifiers,1);
167
+                if($c==':') {
168
+                    return $modifiers;
169
+                } else {
170
+                    $modifiers = substr($modifiers,1);
171
+                }
151 172
             }
152 173
             return $modifiers;
153 174
         }
154 175
     }
155 176
 
156
-    public function _fetchContent($string,$delim) {
177
+    public function _fetchContent($string,$delim)
178
+    {
157 179
         $len = strlen($delim);
158 180
         $string = $this->parseDocumentSource($string);
159 181
         return substr($string,strpos($string, $delim)+$len);
160 182
     }
161 183
 
162
-    public function splitEachModifiers($modifiers) {
184
+    public function splitEachModifiers($modifiers)
185
+    {
163 186
         $modx = evolutionCMS();
164 187
 
165 188
         $cmd = '';
@@ -170,11 +193,15 @@  discard block
 block discarded – undo
170 193
             $c = substr($modifiers,0,1);
171 194
             $modifiers = substr($modifiers,1);
172 195
 
173
-            if($c===':' && preg_match('@^(!?[<>=]{1,2})@', $modifiers, $match)) { // :=, :!=, :<=, :>=, :!<=, :!>=
196
+            if($c===':' && preg_match('@^(!?[<>=]{1,2})@', $modifiers, $match)) {
197
+// :=, :!=, :<=, :>=, :!<=, :!>=
174 198
                 $c = substr($modifiers,strlen($match[1]),1);
175 199
                 $debuginfo = "#i=0 #c=[{$c}] #m=[{$modifiers}]";
176
-                if($c==='(') $modifiers = substr($modifiers,strlen($match[1])+1);
177
-                else         $modifiers = substr($modifiers,strlen($match[1]));
200
+                if($c==='(') {
201
+                    $modifiers = substr($modifiers,strlen($match[1])+1);
202
+                } else {
203
+                    $modifiers = substr($modifiers,strlen($match[1]));
204
+                }
178 205
 
179 206
                 $delim     = $this->_getDelim($c,$modifiers);
180 207
                 $opt       = $this->_getOpt($c,$delim,$modifiers);
@@ -182,13 +209,12 @@  discard block
 block discarded – undo
182 209
 
183 210
                 $result[]=array('cmd'=>trim($match[1]),'opt'=>$opt,'debuginfo'=>$debuginfo);
184 211
                 $cmd = '';
185
-            }
186
-            elseif(in_array($c,array('+','-','*','/')) && preg_match('@^[0-9]+@', $modifiers, $match)) { // :+3, :-3, :*3 ...
212
+            } elseif(in_array($c,array('+','-','*','/')) && preg_match('@^[0-9]+@', $modifiers, $match)) {
213
+// :+3, :-3, :*3 ...
187 214
                 $modifiers = substr($modifiers,strlen($match[0]));
188 215
                 $result[]=array('cmd'=>'math','opt'=>'%s'.$c.$match[0]);
189 216
                 $cmd = '';
190
-            }
191
-            elseif($c==='(' || $c==='=') {
217
+            } elseif($c==='(' || $c==='=') {
192 218
                 $modifiers = $m1 = trim($modifiers);
193 219
                 $delim     = $this->_getDelim($c,$modifiers);
194 220
                 $opt       = $this->_getOpt($c,$delim,$modifiers);
@@ -198,29 +224,29 @@  discard block
 block discarded – undo
198 224
                 $result[]=array('cmd'=>trim($cmd),'opt'=>$opt,'debuginfo'=>$debuginfo);
199 225
 
200 226
                 $cmd = '';
201
-            }
202
-            elseif($c==':') {
227
+            } elseif($c==':') {
203 228
                 $debuginfo = "#i=2 #c=[{$c}] #m=[{$modifiers}]";
204
-                if($cmd!=='') $result[]=array('cmd'=>trim($cmd),'opt'=>'','debuginfo'=>$debuginfo);
229
+                if($cmd!=='') {
230
+                    $result[]=array('cmd'=>trim($cmd),'opt'=>'','debuginfo'=>$debuginfo);
231
+                }
205 232
 
206 233
                 $cmd = '';
207
-            }
208
-            elseif(trim($modifiers)=='' && trim($cmd)!=='') {
234
+            } elseif(trim($modifiers)=='' && trim($cmd)!=='') {
209 235
                 $debuginfo = "#i=3 #c=[{$c}] #m=[{$modifiers}]";
210 236
                 $cmd .= $c;
211 237
                 $result[]=array('cmd'=>trim($cmd),'opt'=>'','debuginfo'=>$debuginfo);
212 238
 
213 239
                 break;
214
-            }
215
-            else {
240
+            } else {
216 241
                 $cmd .= $c;
217 242
             }
218 243
         }
219 244
 
220
-        if(empty($result)) return array();
245
+        if(empty($result)) {
246
+            return array();
247
+        }
221 248
 
222
-        foreach($result as $i=>$a)
223
-        {
249
+        foreach($result as $i=>$a) {
224 250
             $a['opt'] = $this->parseDocumentSource($a['opt']);
225 251
             $result[$i]['opt'] = $modx->mergePlaceholderContent($a['opt'],$this->placeholders);
226 252
         }
@@ -233,22 +259,23 @@  discard block
 block discarded – undo
233 259
         $modx = evolutionCMS();
234 260
         $lastKey = '';
235 261
         $cacheKey = md5(sprintf('parsePhx#%s#%s#%s',$key,$value,print_r($modifiers,true)));
236
-        if(isset($this->tmpCache[$cacheKey])) return $this->tmpCache[$cacheKey];
237
-        if(empty($modifiers)) return '';
262
+        if(isset($this->tmpCache[$cacheKey])) {
263
+            return $this->tmpCache[$cacheKey];
264
+        }
265
+        if(empty($modifiers)) {
266
+            return '';
267
+        }
238 268
 
239
-        foreach($modifiers as $m)
240
-        {
269
+        foreach($modifiers as $m) {
241 270
             $lastKey = strtolower($m['cmd']);
242 271
         }
243 272
         $_ = explode(',',$this->condModifiers);
244
-        if(in_array($lastKey,$_))
245
-        {
273
+        if(in_array($lastKey,$_)) {
246 274
             $modifiers[] = array('cmd'=>'then','opt'=>'1');
247 275
             $modifiers[] = array('cmd'=>'else','opt'=>'0');
248 276
         }
249 277
 
250
-        foreach($modifiers as $i=>$a)
251
-        {
278
+        foreach($modifiers as $i=>$a) {
252 279
             $value = $this->Filter($key,$value, $a['cmd'], $a['opt']);
253 280
         }
254 281
         $this->tmpCache[$cacheKey] = $value;
@@ -260,25 +287,32 @@  discard block
 block discarded – undo
260 287
     {
261 288
         $modx = evolutionCMS();
262 289
 
263
-        if($key==='documentObject') $value = $modx->documentIdentifier;
290
+        if($key==='documentObject') {
291
+            $value = $modx->documentIdentifier;
292
+        }
264 293
         $cmd = $this->parseDocumentSource($cmd);
265
-        if(preg_match('@^[1-9][/0-9]*$@',$cmd))
266
-        {
267
-            if(strpos($cmd,'/')!==false)
268
-                $cmd = $this->substr($cmd,strrpos($cmd,'/')+1);
294
+        if(preg_match('@^[1-9][/0-9]*$@',$cmd)) {
295
+            if(strpos($cmd,'/')!==false) {
296
+                            $cmd = $this->substr($cmd,strrpos($cmd,'/')+1);
297
+            }
269 298
             $opt = $cmd;
270 299
             $cmd = 'id';
271 300
         }
272 301
 
273
-        if(isset($modx->snippetCache["phx:{$cmd}"]))   $this->elmName = "phx:{$cmd}";
274
-        elseif(isset($modx->chunkCache["phx:{$cmd}"])) $this->elmName = "phx:{$cmd}";
275
-        else                                           $this->elmName = '';
302
+        if(isset($modx->snippetCache["phx:{$cmd}"])) {
303
+            $this->elmName = "phx:{$cmd}";
304
+        } elseif(isset($modx->chunkCache["phx:{$cmd}"])) {
305
+            $this->elmName = "phx:{$cmd}";
306
+        } else {
307
+            $this->elmName = '';
308
+        }
276 309
 
277 310
         $cmd = strtolower($cmd);
278
-        if($this->elmName!=='')
279
-            $value = $this->getValueFromElement($key, $value, $cmd, $opt);
280
-        else
281
-            $value = $this->getValueFromPreset($key, $value, $cmd, $opt);
311
+        if($this->elmName!=='') {
312
+                    $value = $this->getValueFromElement($key, $value, $cmd, $opt);
313
+        } else {
314
+                    $value = $this->getValueFromPreset($key, $value, $cmd, $opt);
315
+        }
282 316
 
283 317
         $value = str_replace('[+key+]', $key, $value);
284 318
 
@@ -287,29 +321,37 @@  discard block
 block discarded – undo
287 321
 
288 322
     public function isEmpty($cmd,$value)
289 323
     {
290
-        if($value!=='') return false;
324
+        if($value!=='') {
325
+            return false;
326
+        }
291 327
 
292 328
         $_ = explode(',', $this->condModifiers . ',_default,default,if,input,or,and,show,this,select,switch,then,else,id,ifempty,smart_desc,smart_description,summary');
293
-        if(in_array($cmd,$_)) return false;
294
-        else                  return true;
329
+        if(in_array($cmd,$_)) {
330
+            return false;
331
+        } else {
332
+            return true;
333
+        }
295 334
     }
296 335
 
297 336
     public function getValueFromPreset($key, $value, $cmd, $opt)
298 337
     {
299 338
         $modx = evolutionCMS();
300 339
 
301
-        if($this->isEmpty($cmd,$value)) return '';
340
+        if($this->isEmpty($cmd,$value)) {
341
+            return '';
342
+        }
302 343
 
303 344
         $this->key = $key;
304 345
         $this->value  = $value;
305 346
         $this->opt    = $opt;
306 347
 
307
-        switch ($cmd)
308
-        {
348
+        switch ($cmd) {
309 349
             #####  Conditional Modifiers
310 350
             case 'input':
311 351
             case 'if':
312
-                if(!$opt) return $value;
352
+                if(!$opt) {
353
+                    return $value;
354
+                }
313 355
                 return $opt;
314 356
             case '=':
315 357
             case 'eq':
@@ -370,14 +412,24 @@  discard block
 block discarded – undo
370 412
             case 'file_exists':
371 413
             case 'is_readable':
372 414
             case 'is_writable':
373
-                if(!$opt) $path = $value;
374
-                else      $path = $opt;
375
-                if(strpos($path,MODX_MANAGER_PATH)!==false) exit('Can not read core path');
376
-                if(strpos($path,$modx->config['base_path'])===false) $path = ltrim($path,'/');
415
+                if(!$opt) {
416
+                    $path = $value;
417
+                } else {
418
+                    $path = $opt;
419
+                }
420
+                if(strpos($path,MODX_MANAGER_PATH)!==false) {
421
+                    exit('Can not read core path');
422
+                }
423
+                if(strpos($path,$modx->config['base_path'])===false) {
424
+                    $path = ltrim($path,'/');
425
+                }
377 426
                 $this->condition[] = (int)($cmd($path)!==false);break;
378 427
             case 'is_image':
379
-                if(!$opt) $path = $value;
380
-                else      $path = $opt;
428
+                if(!$opt) {
429
+                    $path = $value;
430
+                } else {
431
+                    $path = $opt;
432
+                }
381 433
                 if(!is_file($path)) {$this->condition[]='0';break;}
382 434
                 $_ = getimagesize($path);
383 435
                 $this->condition[] = (int)($_[0]);break;
@@ -400,17 +452,23 @@  discard block
 block discarded – undo
400 452
             case 'this':
401 453
                 $conditional = implode(' ',$this->condition);
402 454
                 $isvalid = (int)(eval("return ({$conditional});"));
403
-                if ($isvalid) return $this->srcValue;
455
+                if ($isvalid) {
456
+                    return $this->srcValue;
457
+                }
404 458
                 return NULL;
405 459
             case 'then':
406 460
                 $conditional = implode(' ',$this->condition);
407 461
                 $isvalid = (int)eval("return ({$conditional});");
408
-                if ($isvalid)  return $opt;
462
+                if ($isvalid) {
463
+                    return $opt;
464
+                }
409 465
                 return null;
410 466
             case 'else':
411 467
                 $conditional = implode(' ',$this->condition);
412 468
                 $isvalid = (int)eval("return ({$conditional});");
413
-                if (!$isvalid) return $opt;
469
+                if (!$isvalid) {
470
+                    return $opt;
471
+                }
414 472
                 break;
415 473
             case 'select':
416 474
             case 'switch':
@@ -421,8 +479,11 @@  discard block
 block discarded – undo
421 479
                     $mi = explode('=',$raw[$m],2);
422 480
                     $map[$mi[0]] = $mi[1];
423 481
                 }
424
-                if(isset($map[$value])) return $map[$value];
425
-                else                    return '';
482
+                if(isset($map[$value])) {
483
+                    return $map[$value];
484
+                } else {
485
+                    return '';
486
+                }
426 487
             ##### End of Conditional Modifiers
427 488
 
428 489
             #####  Encode / Decode / Hash / Escape
@@ -448,24 +509,25 @@  discard block
 block discarded – undo
448 509
             case 'spam_protect':
449 510
                 return str_replace(array('@','.'),array('&#64;','&#46;'),$value);
450 511
             case 'strip':
451
-                if($opt==='') $opt = ' ';
512
+                if($opt==='') {
513
+                    $opt = ' ';
514
+                }
452 515
                 return preg_replace('/[\n\r\t\s]+/', $opt, $value);
453 516
             case 'strip_linefeeds':
454 517
                 return str_replace(array("\n","\r"), '', $value);
455 518
             case 'notags':
456 519
             case 'strip_tags':
457 520
             case 'remove_html':
458
-                if($opt!=='')
459
-                {
521
+                if($opt!=='') {
460 522
                     $param = array();
461
-                    foreach(explode(',',$opt) as $v)
462
-                    {
523
+                    foreach(explode(',',$opt) as $v) {
463 524
                         $v = trim($v,'</> ');
464 525
                         $param[] = "<{$v}>";
465 526
                     }
466 527
                     $params = implode(',',$param);
528
+                } else {
529
+                    $params = '';
467 530
                 }
468
-                else $params = '';
469 531
                 if(!strpos($params,'<br>')===false) {
470 532
                     $value = preg_replace('@(<br[ /]*>)\n@','$1',$value);
471 533
                     $value = preg_replace('@<br[ /]*>@',"\n",$value);
@@ -476,8 +538,11 @@  discard block
 block discarded – undo
476 538
             case 'encode_url':
477 539
                 return urlencode($value);
478 540
             case 'base64_decode':
479
-                if($opt!=='false') $opt = true;
480
-                else               $opt = false;
541
+                if($opt!=='false') {
542
+                    $opt = true;
543
+                } else {
544
+                    $opt = false;
545
+                }
481 546
                 return base64_decode($value,$opt);
482 547
             case 'encode_sha1': $cmd = 'sha1';
483 548
             case 'addslashes':
@@ -503,16 +568,19 @@  discard block
 block discarded – undo
503 568
                 return $this->strtoupper($value);
504 569
             case 'capitalize':
505 570
                 $_ = explode(' ',$value);
506
-                foreach($_ as $i=>$v)
507
-                {
571
+                foreach($_ as $i=>$v) {
508 572
                     $_[$i] = ucfirst($v);
509 573
                 }
510 574
                 return implode(' ',$_);
511 575
             case 'zenhan':
512
-                if(empty($opt)) $opt='VKas';
576
+                if(empty($opt)) {
577
+                    $opt='VKas';
578
+                }
513 579
                 return mb_convert_kana($value,$opt,$modx->config['modx_charset']);
514 580
             case 'hanzen':
515
-                if(empty($opt)) $opt='VKAS';
581
+                if(empty($opt)) {
582
+                    $opt='VKAS';
583
+                }
516 584
                 return mb_convert_kana($value,$opt,$modx->config['modx_charset']);
517 585
             case 'str_shuffle':
518 586
             case 'shuffle':
@@ -537,13 +605,18 @@  discard block
 block discarded – undo
537 605
                 $value = preg_replace('/\r/', '', $value);
538 606
                 return count(preg_split('/\n+/',$value));
539 607
             case 'strpos':
540
-                if($opt!=0&&empty($opt)) return $value;
608
+                if($opt!=0&&empty($opt)) {
609
+                    return $value;
610
+                }
541 611
                 return $this->strpos($value,$opt);
542 612
             case 'wordwrap':
543 613
                 // default: 70
544 614
                 $wrapat = (int)$opt > 0 ? (int)$opt : 70;
545
-                if (version_compare(PHP_VERSION, '5.3.0') >= 0) return $this->includeMdfFile('wordwrap');
546
-                else return preg_replace("@(\b\w+\b)@e","wordwrap('\\1',\$wrapat,' ',1)",$value);
615
+                if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
616
+                    return $this->includeMdfFile('wordwrap');
617
+                } else {
618
+                    return preg_replace("@(\b\w+\b)@e","wordwrap('\\1',\$wrapat,' ',1)",$value);
619
+                }
547 620
             case 'wrap_text':
548 621
                 $width = preg_match('/^[1-9][0-9]*$/',$opt) ? $opt : 70;
549 622
                 if($modx->config['manager_language']==='japanese-utf8') {
@@ -559,30 +632,36 @@  discard block
 block discarded – undo
559 632
                         $value = $this->substr($value,$width);
560 633
                     }
561 634
                     return implode("\n",$chunk);
635
+                } else {
636
+                                    return wordwrap($value,$width,"\n",true);
562 637
                 }
563
-                else
564
-                    return wordwrap($value,$width,"\n",true);
565 638
             case 'substr':
566
-                if(empty($opt)) break;
639
+                if(empty($opt)) {
640
+                    break;
641
+                }
567 642
                 if(strpos($opt,',')!==false) {
568 643
                     list($b,$e) = explode(',',$opt,2);
569 644
                     return $this->substr($value,$b,(int)$e);
645
+                } else {
646
+                    return $this->substr($value,$opt);
570 647
                 }
571
-                else return $this->substr($value,$opt);
572 648
             case 'limit':
573 649
             case 'trim_to': // http://www.movabletype.jp/documentation/appendices/modifiers/trim_to.html
574
-                if(strpos($opt,'+')!==false)
575
-                    list($len,$str) = explode('+',$opt,2);
576
-                else {
650
+                if(strpos($opt,'+')!==false) {
651
+                                    list($len,$str) = explode('+',$opt,2);
652
+                } else {
577 653
                     $len = $opt;
578 654
                     $str = '';
579 655
                 }
580
-                if($len==='') $len = 100;
581
-                if(abs($len) > $this->strlen($value)) $str ='';
656
+                if($len==='') {
657
+                    $len = 100;
658
+                }
659
+                if(abs($len) > $this->strlen($value)) {
660
+                    $str ='';
661
+                }
582 662
                 if(preg_match('/^[1-9][0-9]*$/',$len)) {
583 663
                     return $this->substr($value,0,$len) . $str;
584
-                }
585
-                elseif(preg_match('/^\-[1-9][0-9]*$/',$len)) {
664
+                } elseif(preg_match('/^\-[1-9][0-9]*$/',$len)) {
586 665
                     return $str . $this->substr($value,$len);
587 666
                 }
588 667
                 break;
@@ -592,18 +671,30 @@  discard block
 block discarded – undo
592 671
                 return $this->includeMdfFile('summary');
593 672
             case 'replace':
594 673
             case 'str_replace':
595
-                if(empty($opt) || strpos($opt,',')===false) break;
596
-                if    (substr_count($opt, ',') ==1) $delim = ',';
597
-                elseif(substr_count($opt, '|') ==1) $delim = '|';
598
-                elseif(substr_count($opt, '=>')==1) $delim = '=>';
599
-                elseif(substr_count($opt, '/') ==1) $delim = '/';
600
-                else break;
674
+                if(empty($opt) || strpos($opt,',')===false) {
675
+                    break;
676
+                }
677
+                if    (substr_count($opt, ',') ==1) {
678
+                    $delim = ',';
679
+                } elseif(substr_count($opt, '|') ==1) {
680
+                    $delim = '|';
681
+                } elseif(substr_count($opt, '=>')==1) {
682
+                    $delim = '=>';
683
+                } elseif(substr_count($opt, '/') ==1) {
684
+                    $delim = '/';
685
+                } else {
686
+                    break;
687
+                }
601 688
                 list($s,$r) = explode($delim,$opt);
602
-                if($value!=='') return str_replace($s,$r,$value);
689
+                if($value!=='') {
690
+                    return str_replace($s,$r,$value);
691
+                }
603 692
                 break;
604 693
             case 'replace_to':
605 694
             case 'tpl':
606
-                if($value!=='') return str_replace(array('[+value+]','[+output+]','{value}','%s'),$value,$opt);
695
+                if($value!=='') {
696
+                    return str_replace(array('[+value+]','[+output+]','{value}','%s'),$value,$opt);
697
+                }
607 698
                 break;
608 699
             case 'eachtpl':
609 700
                 $value = explode('||',$value);
@@ -614,59 +705,83 @@  discard block
 block discarded – undo
614 705
                 return implode("\n", $_);
615 706
             case 'array_pop':
616 707
             case 'array_shift':
617
-                if(strpos($value,'||')!==false) $delim = '||';
618
-                else                            $delim = ',';
708
+                if(strpos($value,'||')!==false) {
709
+                    $delim = '||';
710
+                } else {
711
+                    $delim = ',';
712
+                }
619 713
                 return $cmd(explode($delim,$value));
620 714
             case 'preg_replace':
621 715
             case 'regex_replace':
622
-                if(empty($opt) || strpos($opt,',')===false) break;
716
+                if(empty($opt) || strpos($opt,',')===false) {
717
+                    break;
718
+                }
623 719
                 list($s,$r) = explode(',',$opt,2);
624
-                if($value!=='') return preg_replace($s,$r,$value);
720
+                if($value!=='') {
721
+                    return preg_replace($s,$r,$value);
722
+                }
625 723
                 break;
626 724
             case 'cat':
627 725
             case 'concatenate':
628 726
             case '.':
629
-                if($value!=='') return $value . $opt;
727
+                if($value!=='') {
728
+                    return $value . $opt;
729
+                }
630 730
                 break;
631 731
             case 'sprintf':
632 732
             case 'string_format':
633
-                if($value!=='') return sprintf($opt,$value);
733
+                if($value!=='') {
734
+                    return sprintf($opt,$value);
735
+                }
634 736
                 break;
635 737
             case 'number_format':
636
-                if($opt=='') $opt = 0;
738
+                if($opt=='') {
739
+                    $opt = 0;
740
+                }
637 741
                 return number_format($value,$opt);
638 742
             case 'money_format':
639 743
                 setlocale(LC_MONETARY,setlocale(LC_TIME,0));
640
-                if($value!=='') return money_format($opt,(double)$value);
744
+                if($value!=='') {
745
+                    return money_format($opt,(double)$value);
746
+                }
641 747
                 break;
642 748
             case 'tobool':
643 749
                 return boolval($value);
644 750
             case 'nl2lf':
645
-                if($value!=='') return str_replace(array("\r\n","\n", "\r"), '\n', $value);
751
+                if($value!=='') {
752
+                    return str_replace(array("\r\n","\n", "\r"), '\n', $value);
753
+                }
646 754
                 break;
647 755
             case 'br2nl':
648 756
                 return preg_replace('@<br[\s/]*>@i', "\n", $value);
649 757
             case 'nl2br':
650
-                if (version_compare(PHP_VERSION, '5.3.0', '<'))
651
-                    return nl2br($value);
652
-                if($opt!=='')
653
-                {
758
+                if (version_compare(PHP_VERSION, '5.3.0', '<')) {
759
+                                    return nl2br($value);
760
+                }
761
+                if($opt!=='') {
654 762
                     $opt = trim($opt);
655 763
                     $opt = strtolower($opt);
656
-                    if($opt==='false') $opt = false;
657
-                    elseif($opt==='0') $opt = false;
658
-                    else               $opt = true;
764
+                    if($opt==='false') {
765
+                        $opt = false;
766
+                    } elseif($opt==='0') {
767
+                        $opt = false;
768
+                    } else {
769
+                        $opt = true;
770
+                    }
771
+                } elseif(isset($modx->config['mce_element_format'])&&$modx->config['mce_element_format']==='html') {
772
+                                    $opt = false;
773
+                } else {
774
+                    $opt = true;
659 775
                 }
660
-                elseif(isset($modx->config['mce_element_format'])&&$modx->config['mce_element_format']==='html')
661
-                    $opt = false;
662
-                else                   $opt = true;
663 776
                 return nl2br($value,$opt);
664 777
             case 'ltrim':
665 778
             case 'rtrim':
666 779
             case 'trim': // ref http://mblo.info/modifiers/custom-modifiers/rtrim_opt.html
667
-                if($opt==='')
668
-                    return $cmd($value);
669
-                else return $cmd($value,$opt);
780
+                if($opt==='') {
781
+                                    return $cmd($value);
782
+                } else {
783
+                    return $cmd($value,$opt);
784
+                }
670 785
             // These are all straight wrappers for PHP functions
671 786
             case 'ucfirst':
672 787
             case 'lcfirst':
@@ -677,15 +792,24 @@  discard block
 block discarded – undo
677 792
             case 'strftime':
678 793
             case 'date':
679 794
             case 'dateformat':
680
-                if(empty($opt)) $opt = $modx->toDateFormat(null, 'formatOnly');
681
-                if(!preg_match('@^[0-9]+$@',$value)) $value = strtotime($value);
682
-                if(strpos($opt,'%')!==false)
683
-                    return strftime($opt,0+$value);
684
-                else
685
-                    return date($opt,0+$value);
795
+                if(empty($opt)) {
796
+                    $opt = $modx->toDateFormat(null, 'formatOnly');
797
+                }
798
+                if(!preg_match('@^[0-9]+$@',$value)) {
799
+                    $value = strtotime($value);
800
+                }
801
+                if(strpos($opt,'%')!==false) {
802
+                                    return strftime($opt,0+$value);
803
+                } else {
804
+                                    return date($opt,0+$value);
805
+                }
686 806
             case 'time':
687
-                if(empty($opt)) $opt = '%H:%M';
688
-                if(!preg_match('@^[0-9]+$@',$value)) $value = strtotime($value);
807
+                if(empty($opt)) {
808
+                    $opt = '%H:%M';
809
+                }
810
+                if(!preg_match('@^[0-9]+$@',$value)) {
811
+                    $value = strtotime($value);
812
+                }
689 813
                 return strftime($opt,0+$value);
690 814
             case 'strtotime':
691 815
                 return strtotime($value);
@@ -695,7 +819,9 @@  discard block
 block discarded – undo
695 819
             case 'tofloat':
696 820
                 return floatval($value);
697 821
             case 'round':
698
-                if(!$opt) $opt = 0;
822
+                if(!$opt) {
823
+                    $opt = 0;
824
+                }
699 825
                 return $cmd($value,$opt);
700 826
             case 'max':
701 827
             case 'min':
@@ -707,28 +833,42 @@  discard block
 block discarded – undo
707 833
             case 'math':
708 834
             case 'calc':
709 835
                 $value = (int)$value;
710
-                if(empty($value)) $value = '0';
836
+                if(empty($value)) {
837
+                    $value = '0';
838
+                }
711 839
                 $filter = str_replace(array('[+value+]','[+output+]','{value}','%s'),'?',$opt);
712 840
                 $filter = preg_replace('@([a-zA-Z\n\r\t\s])@','',$filter);
713
-                if(strpos($filter,'?')===false) $filter = "?{$filter}";
841
+                if(strpos($filter,'?')===false) {
842
+                    $filter = "?{$filter}";
843
+                }
714 844
                 $filter = str_replace('?',$value,$filter);
715 845
                 return eval("return {$filter};");
716 846
             case 'count':
717
-                if($value=='') return 0;
847
+                if($value=='') {
848
+                    return 0;
849
+                }
718 850
                 $value = explode(',',$value);
719 851
                 return count($value);
720 852
             case 'sort':
721 853
             case 'rsort':
722
-                if(strpos($value,"\n")!==false) $delim="\n";
723
-                else $delim = ',';
854
+                if(strpos($value,"\n")!==false) {
855
+                    $delim="\n";
856
+                } else {
857
+                    $delim = ',';
858
+                }
724 859
                 $swap = explode($delim,$value);
725
-                if(!$opt) $opt = SORT_REGULAR;
726
-                else      $opt = constant($opt);
860
+                if(!$opt) {
861
+                    $opt = SORT_REGULAR;
862
+                } else {
863
+                    $opt = constant($opt);
864
+                }
727 865
                 $cmd($swap,$opt);
728 866
                 return implode($delim,$swap);
729 867
             #####  Resource fields
730 868
             case 'id':
731
-                if($opt) return $this->getDocumentObject($opt,$key);
869
+                if($opt) {
870
+                    return $this->getDocumentObject($opt,$key);
871
+                }
732 872
                 break;
733 873
             case 'type':
734 874
             case 'contenttype':
@@ -765,7 +905,9 @@  discard block
 block discarded – undo
765 905
             case 'privatemgr':
766 906
             case 'content_dispo':
767 907
             case 'hidemenu':
768
-                if($cmd==='contenttype') $cmd = 'contentType';
908
+                if($cmd==='contenttype') {
909
+                    $cmd = 'contentType';
910
+                }
769 911
                 return $this->getDocumentObject($value,$cmd);
770 912
             case 'title':
771 913
                 $pagetitle = $this->getDocumentObject($value,'pagetitle');
@@ -780,13 +922,20 @@  discard block
 block discarded – undo
780 922
                 $templateName = $modx->getDatabase()->getValue($rs);
781 923
                 return !$templateName ? '(blank)' : $templateName;
782 924
             case 'getfield':
783
-                if(!$opt) $opt = 'content';
925
+                if(!$opt) {
926
+                    $opt = 'content';
927
+                }
784 928
                 return $modx->getField($opt,$value);
785 929
             case 'children':
786 930
             case 'childids':
787
-                if($value=='') $value = 0; // 値がない場合はルートと見なす
931
+                if($value=='') {
932
+                    $value = 0;
933
+                }
934
+                // 値がない場合はルートと見なす
788 935
                 $published = 1;
789
-                if($opt=='') $opt = 'page';
936
+                if($opt=='') {
937
+                    $opt = 'page';
938
+                }
790 939
                 $_ = explode(',',$opt);
791 940
                 $where = array();
792 941
                 foreach($_ as $opt) {
@@ -802,29 +951,43 @@  discard block
 block discarded – undo
802 951
                 $where = implode(' AND ', $where);
803 952
                 $children = $modx->getDocumentChildren($value, $published, '0', 'id', $where);
804 953
                 $result = array();
805
-                foreach((array)$children as $child){
954
+                foreach((array)$children as $child) {
806 955
                     $result[] = $child['id'];
807 956
                 }
808 957
                 return implode(',', $result);
809 958
             case 'fullurl':
810
-                if(!is_numeric($value)) return $value;
959
+                if(!is_numeric($value)) {
960
+                    return $value;
961
+                }
811 962
                 return $modx->makeUrl($value);
812 963
             case 'makeurl':
813
-                if(!is_numeric($value)) return $value;
814
-                if(!$opt) $opt = 'full';
964
+                if(!is_numeric($value)) {
965
+                    return $value;
966
+                }
967
+                if(!$opt) {
968
+                    $opt = 'full';
969
+                }
815 970
                 return $modx->makeUrl($value,'','',$opt);
816 971
 
817 972
             #####  File system
818 973
             case 'getimageinfo':
819 974
             case 'imageinfo':
820
-                if(!is_file($value)) return '';
975
+                if(!is_file($value)) {
976
+                    return '';
977
+                }
821 978
                 $_ = getimagesize($value);
822
-                if(!$_[0]) return '';
979
+                if(!$_[0]) {
980
+                    return '';
981
+                }
823 982
                 $info['width']  = $_[0];
824 983
                 $info['height'] = $_[1];
825
-                if    ($_[0] > $_[1]) $info['aspect'] = 'landscape';
826
-                elseif($_[0] < $_[1]) $info['aspect'] = 'portrait';
827
-                else                  $info['aspect'] = 'square';
984
+                if    ($_[0] > $_[1]) {
985
+                    $info['aspect'] = 'landscape';
986
+                } elseif($_[0] < $_[1]) {
987
+                    $info['aspect'] = 'portrait';
988
+                } else {
989
+                    $info['aspect'] = 'square';
990
+                }
828 991
                 switch($_[2]) {
829 992
                     case IMAGETYPE_GIF  : $info['type'] = 'gif'; break;
830 993
                     case IMAGETYPE_JPEG : $info['type'] = 'jpg'; break;
@@ -843,33 +1006,47 @@  discard block
 block discarded – undo
843 1006
 
844 1007
             case 'file_get_contents':
845 1008
             case 'readfile':
846
-                if(!is_file($value)) return $value;
1009
+                if(!is_file($value)) {
1010
+                    return $value;
1011
+                }
847 1012
                 $value = realpath($value);
848
-                if(strpos($value,MODX_MANAGER_PATH)!==false) exit('Can not read core file');
1013
+                if(strpos($value,MODX_MANAGER_PATH)!==false) {
1014
+                    exit('Can not read core file');
1015
+                }
849 1016
                 $ext = strtolower(substr($value,-4));
850
-                if($ext==='.php') exit('Can not read php file');
851
-                if($ext==='.cgi') exit('Can not read cgi file');
1017
+                if($ext==='.php') {
1018
+                    exit('Can not read php file');
1019
+                }
1020
+                if($ext==='.cgi') {
1021
+                    exit('Can not read cgi file');
1022
+                }
852 1023
                 return file_get_contents($value);
853 1024
             case 'filesize':
854
-                if($value == '') return '';
1025
+                if($value == '') {
1026
+                    return '';
1027
+                }
855 1028
                 $filename = $value;
856 1029
 
857 1030
                 $site_url = $modx->config['site_url'];
858
-                if(strpos($filename,$site_url) === 0)
859
-                    $filename = substr($filename,0,strlen($site_url));
1031
+                if(strpos($filename,$site_url) === 0) {
1032
+                                    $filename = substr($filename,0,strlen($site_url));
1033
+                }
860 1034
                 $filename = trim($filename,'/');
861 1035
 
862 1036
                 $opt = trim($opt,'/');
863
-                if($opt!=='') $opt .= '/';
1037
+                if($opt!=='') {
1038
+                    $opt .= '/';
1039
+                }
864 1040
 
865 1041
                 $filename = MODX_BASE_PATH.$opt.$filename;
866 1042
 
867
-                if(is_file($filename)){
1043
+                if(is_file($filename)) {
868 1044
                     clearstatcache();
869 1045
                     $size = filesize($filename);
870 1046
                     return $size;
1047
+                } else {
1048
+                    return '';
871 1049
                 }
872
-                else return '';
873 1050
             #####  User info
874 1051
             case 'username':
875 1052
             case 'fullname':
@@ -897,32 +1074,47 @@  discard block
 block discarded – undo
897 1074
                 $this->opt = $cmd;
898 1075
                 return $this->includeMdfFile('moduser');
899 1076
             case 'userinfo':
900
-                if(empty($opt)) $this->opt = 'username';
1077
+                if(empty($opt)) {
1078
+                    $this->opt = 'username';
1079
+                }
901 1080
                 return $this->includeMdfFile('moduser');
902 1081
             case 'webuserinfo':
903
-                if(empty($opt)) $this->opt = 'username';
1082
+                if(empty($opt)) {
1083
+                    $this->opt = 'username';
1084
+                }
904 1085
                 $this->value = -$value;
905 1086
                 return $this->includeMdfFile('moduser');
906 1087
             #####  Special functions
907 1088
             case 'ifempty':
908 1089
             case '_default':
909 1090
             case 'default':
910
-                if (empty($value)) return $opt; break;
1091
+                if (empty($value)) {
1092
+                    return $opt;
1093
+                }
1094
+                break;
911 1095
             case 'ifnotempty':
912
-                if (!empty($value)) return $opt; break;
1096
+                if (!empty($value)) {
1097
+                    return $opt;
1098
+                }
1099
+                break;
913 1100
             case 'datagrid':
914 1101
                 include_once(MODX_CORE_PATH . 'controls/datagrid.class.php');
915 1102
                 $grd = new DataGrid(null, trim($value));
916 1103
                 $grd->itemStyle = '';
917 1104
                 $grd->altItemStyle = '';
918 1105
                 $pos = strpos($value,"\n");
919
-                if($pos) $_ = substr($value,0,$pos);
920
-                else $_ = $pos;
1106
+                if($pos) {
1107
+                    $_ = substr($value,0,$pos);
1108
+                } else {
1109
+                    $_ = $pos;
1110
+                }
921 1111
                 $grd->cdelim = strpos($_,"\t")!==false ? 'tab' : ',';
922 1112
                 return $grd->render();
923 1113
             case 'rotate':
924 1114
             case 'evenodd':
925
-                if(strpos($opt,',')===false) $opt = 'odd,even';
1115
+                if(strpos($opt,',')===false) {
1116
+                    $opt = 'odd,even';
1117
+                }
926 1118
                 $_ = explode(',', $opt);
927 1119
                 $c = count($_);
928 1120
                 $i = $value + $c;
@@ -931,7 +1123,9 @@  discard block
 block discarded – undo
931 1123
             case 'takeval':
932 1124
                 $arr = explode(",",$opt);
933 1125
                 $idx = $value;
934
-                if(!is_numeric($idx)) return $value;
1126
+                if(!is_numeric($idx)) {
1127
+                    return $value;
1128
+                }
935 1129
                 return $arr[$idx];
936 1130
             case 'getimage':
937 1131
                 return $this->includeMdfFile('getimage');
@@ -939,14 +1133,18 @@  discard block
 block discarded – undo
939 1133
                 return $modx->nicesize($value);
940 1134
             case 'googlemap':
941 1135
             case 'googlemaps':
942
-                if(empty($opt)) $opt = 'border:none;width:500px;height:350px;';
1136
+                if(empty($opt)) {
1137
+                    $opt = 'border:none;width:500px;height:350px;';
1138
+                }
943 1139
                 $tpl = '<iframe style="[+style+]" src="https://maps.google.co.jp/maps?ll=[+value+]&output=embed&z=15"></iframe>';
944 1140
                 $ph['style'] = $opt;
945 1141
                 $ph['value'] = $value;
946 1142
                 return $modx->parseText($tpl,$ph);
947 1143
             case 'youtube':
948 1144
             case 'youtube16x9':
949
-                if(empty($opt)) $opt = 560;
1145
+                if(empty($opt)) {
1146
+                    $opt = 560;
1147
+                }
950 1148
                 $h = round($opt*0.5625);
951 1149
                 $tpl = '<iframe width="%s" height="%s" src="https://www.youtube.com/embed/%s" frameborder="0" allowfullscreen></iframe>';
952 1150
                 return sprintf($tpl,$opt,$h,$value);
@@ -979,7 +1177,8 @@  discard block
 block discarded – undo
979 1177
         return $value;
980 1178
     }
981 1179
 
982
-    public function includeMdfFile($cmd) {
1180
+    public function includeMdfFile($cmd)
1181
+    {
983 1182
         $modx = evolutionCMS();
984 1183
         $key = $this->key;
985 1184
         $value  = $this->value;
@@ -990,55 +1189,65 @@  discard block
 block discarded – undo
990 1189
     public function getValueFromElement($key, $value, $cmd, $opt)
991 1190
     {
992 1191
         $modx = evolutionCMS();
993
-        if( isset($modx->snippetCache[$this->elmName]) )
994
-        {
1192
+        if( isset($modx->snippetCache[$this->elmName]) ) {
995 1193
             $php = $modx->snippetCache[$this->elmName];
996
-        }
997
-        else
998
-        {
1194
+        } else {
999 1195
             $esc_elmName = $modx->getDatabase()->escape($this->elmName);
1000 1196
             $result = $modx->getDatabase()->select('snippet','[+prefix+]site_snippets',"name='{$esc_elmName}'");
1001 1197
             $total = $modx->getDatabase()->getRecordCount($result);
1002
-            if($total == 1)
1003
-            {
1198
+            if($total == 1) {
1004 1199
                 $row = $modx->getDatabase()->getRow($result);
1005 1200
                 $php = $row['snippet'];
1006
-            }
1007
-            elseif($total == 0)
1008
-            {
1201
+            } elseif($total == 0) {
1009 1202
                 $assets_path = MODX_BASE_PATH.'assets/';
1010
-                if(is_file($assets_path."modifiers/mdf_{$cmd}.inc.php"))
1011
-                    $modifiers_path = $assets_path."modifiers/mdf_{$cmd}.inc.php";
1012
-                elseif(is_file($assets_path."plugins/phx/modifiers/{$cmd}.phx.php"))
1013
-                    $modifiers_path = $assets_path."plugins/phx/modifiers/{$cmd}.phx.php";
1014
-                elseif(is_file(MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php"))
1015
-                    $modifiers_path = MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php";
1016
-                else $modifiers_path = false;
1203
+                if(is_file($assets_path."modifiers/mdf_{$cmd}.inc.php")) {
1204
+                                    $modifiers_path = $assets_path."modifiers/mdf_{$cmd}.inc.php";
1205
+                } elseif(is_file($assets_path."plugins/phx/modifiers/{$cmd}.phx.php")) {
1206
+                                    $modifiers_path = $assets_path."plugins/phx/modifiers/{$cmd}.phx.php";
1207
+                } elseif(is_file(MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php")) {
1208
+                                    $modifiers_path = MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php";
1209
+                } else {
1210
+                    $modifiers_path = false;
1211
+                }
1017 1212
 
1018 1213
                 if($modifiers_path !== false) {
1019 1214
                     $php = @file_get_contents($modifiers_path);
1020 1215
                     $php = trim($php);
1021
-                    if(substr($php,0,5)==='<?php') $php = substr($php,6);
1022
-                    if(substr($php,0,2)==='<?')    $php = substr($php,3);
1023
-                    if(substr($php,-2)==='?>')     $php = substr($php,0,-2);
1024
-                    if($this->elmName!=='')
1025
-                        $modx->snippetCache[$this->elmName.'Props'] = '';
1026
-                }
1027
-                else
1028
-                    $php = false;
1216
+                    if(substr($php,0,5)==='<?php') {
1217
+                        $php = substr($php,6);
1218
+                    }
1219
+                    if(substr($php,0,2)==='<?') {
1220
+                        $php = substr($php,3);
1221
+                    }
1222
+                    if(substr($php,-2)==='?>') {
1223
+                        $php = substr($php,0,-2);
1224
+                    }
1225
+                    if($this->elmName!=='') {
1226
+                                            $modx->snippetCache[$this->elmName.'Props'] = '';
1227
+                    }
1228
+                } else {
1229
+                                    $php = false;
1230
+                }
1231
+            } else {
1232
+                $php = false;
1233
+            }
1234
+            if($this->elmName!=='') {
1235
+                $modx->snippetCache[$this->elmName]= $php;
1029 1236
             }
1030
-            else $php = false;
1031
-            if($this->elmName!=='') $modx->snippetCache[$this->elmName]= $php;
1032 1237
         }
1033
-        if($php==='') $php=false;
1238
+        if($php==='') {
1239
+            $php=false;
1240
+        }
1034 1241
 
1035
-        if($php===false) $html = $modx->getChunk($this->elmName);
1036
-        else             $html = false;
1242
+        if($php===false) {
1243
+            $html = $modx->getChunk($this->elmName);
1244
+        } else {
1245
+            $html = false;
1246
+        }
1037 1247
 
1038 1248
         $self = '[+output+]';
1039 1249
 
1040
-        if($php !== false)
1041
-        {
1250
+        if($php !== false) {
1042 1251
             ob_start();
1043 1252
             $options = $opt;
1044 1253
             $output = $value;
@@ -1050,19 +1259,19 @@  discard block
 block discarded – undo
1050 1259
             $this->vars['options'] = & $opt;
1051 1260
             $custom = eval($php);
1052 1261
             $msg = ob_get_contents();
1053
-            if($value===$this->bt) $value = $msg . $custom;
1262
+            if($value===$this->bt) {
1263
+                $value = $msg . $custom;
1264
+            }
1054 1265
             ob_end_clean();
1055
-        }
1056
-        elseif($html!==false && isset($value) && $value!=='')
1057
-        {
1266
+        } elseif($html!==false && isset($value) && $value!=='') {
1058 1267
             $html = str_replace(array($self,'[+value+]'), $value, $html);
1059 1268
             $value = str_replace(array('[+options+]','[+param+]'), $opt, $html);
1269
+        } else {
1270
+            return false;
1060 1271
         }
1061
-        else return false;
1062 1272
 
1063 1273
         if($php===false && $html===false && $value!==''
1064
-            && (strpos($cmd,'[+value+]')!==false || strpos($cmd,$self)!==false))
1065
-        {
1274
+            && (strpos($cmd,'[+value+]')!==false || strpos($cmd,$self)!==false)) {
1066 1275
             $value = str_replace(array('[+value+]',$self),$value,$cmd);
1067 1276
         }
1068 1277
         return $value;
@@ -1072,23 +1281,39 @@  discard block
 block discarded – undo
1072 1281
     {
1073 1282
         $modx = evolutionCMS();
1074 1283
 
1075
-        if(strpos($content,'[')===false && strpos($content,'{')===false) return $content;
1284
+        if(strpos($content,'[')===false && strpos($content,'{')===false) {
1285
+            return $content;
1286
+        }
1076 1287
 
1077
-        if(!$modx->maxParserPasses) $modx->maxParserPasses = 10;
1288
+        if(!$modx->maxParserPasses) {
1289
+            $modx->maxParserPasses = 10;
1290
+        }
1078 1291
         $bt='';
1079 1292
         $i=0;
1080
-        while($bt!==$content)
1081
-        {
1293
+        while($bt!==$content) {
1082 1294
             $bt = $content;
1083
-            if(strpos($content,'[*')!==false && $modx->documentIdentifier)
1084
-                $content = $modx->mergeDocumentContent($content);
1085
-            if(strpos($content,'[(')!==false) $content = $modx->mergeSettingsContent($content);
1086
-            if(strpos($content,'{{')!==false) $content = $modx->mergeChunkContent($content);
1087
-            if(strpos($content,'[!')!==false) $content = str_replace(array('[!','!]'),array('[[',']]'),$content);
1088
-            if(strpos($content,'[[')!==false) $content = $modx->evalSnippets($content);
1089
-
1090
-            if($content===$bt)              break;
1091
-            if($modx->maxParserPasses < $i) break;
1295
+            if(strpos($content,'[*')!==false && $modx->documentIdentifier) {
1296
+                            $content = $modx->mergeDocumentContent($content);
1297
+            }
1298
+            if(strpos($content,'[(')!==false) {
1299
+                $content = $modx->mergeSettingsContent($content);
1300
+            }
1301
+            if(strpos($content,'{{')!==false) {
1302
+                $content = $modx->mergeChunkContent($content);
1303
+            }
1304
+            if(strpos($content,'[!')!==false) {
1305
+                $content = str_replace(array('[!','!]'),array('[[',']]'),$content);
1306
+            }
1307
+            if(strpos($content,'[[')!==false) {
1308
+                $content = $modx->evalSnippets($content);
1309
+            }
1310
+
1311
+            if($content===$bt) {
1312
+                break;
1313
+            }
1314
+            if($modx->maxParserPasses < $i) {
1315
+                break;
1316
+            }
1092 1317
             $i++;
1093 1318
         }
1094 1319
         return $content;
@@ -1099,103 +1324,138 @@  discard block
 block discarded – undo
1099 1324
         $modx = evolutionCMS();
1100 1325
 
1101 1326
         $target = trim($target);
1102
-        if(empty($target)) $target = $modx->config['site_start'];
1103
-        if(preg_match('@^[1-9][0-9]*$@',$target)) $method='id';
1104
-        else $method = 'alias';
1327
+        if(empty($target)) {
1328
+            $target = $modx->config['site_start'];
1329
+        }
1330
+        if(preg_match('@^[1-9][0-9]*$@',$target)) {
1331
+            $method='id';
1332
+        } else {
1333
+            $method = 'alias';
1334
+        }
1105 1335
 
1106
-        if(!isset($this->documentObject[$target]))
1107
-        {
1336
+        if(!isset($this->documentObject[$target])) {
1108 1337
             $this->documentObject[$target] = $modx->getDocumentObject($method,$target,'direct');
1109 1338
         }
1110 1339
 
1111
-        if($this->documentObject[$target]['publishedon']==='0')
1112
-            return '';
1113
-        elseif(isset($this->documentObject[$target][$field]))
1114
-        {
1115
-            if(is_array($this->documentObject[$target][$field]))
1116
-            {
1340
+        if($this->documentObject[$target]['publishedon']==='0') {
1341
+                    return '';
1342
+        } elseif(isset($this->documentObject[$target][$field])) {
1343
+            if(is_array($this->documentObject[$target][$field])) {
1117 1344
                 $a = $modx->getTemplateVarOutput($field,$target);
1118 1345
                 $this->documentObject[$target][$field] = $a[$field];
1119 1346
             }
1347
+        } else {
1348
+            $this->documentObject[$target][$field] = false;
1120 1349
         }
1121
-        else $this->documentObject[$target][$field] = false;
1122 1350
 
1123 1351
         return $this->documentObject[$target][$field];
1124 1352
     }
1125 1353
 
1126
-    public function setPlaceholders($value = '', $key = '', $path = '') {
1127
-        if($path!=='') $key = "{$path}.{$key}";
1354
+    public function setPlaceholders($value = '', $key = '', $path = '')
1355
+    {
1356
+        if($path!=='') {
1357
+            $key = "{$path}.{$key}";
1358
+        }
1128 1359
         if (is_array($value)) {
1129 1360
             foreach ($value as $subkey => $subval) {
1130 1361
                 $this->setPlaceholders($subval, $subkey, $key);
1131 1362
             }
1363
+        } else {
1364
+            $this->setModifiersVariable($key, $value);
1132 1365
         }
1133
-        else $this->setModifiersVariable($key, $value);
1134 1366
     }
1135 1367
 
1136 1368
     // Sets a placeholder variable which can only be access by Modifiers
1137
-    public function setModifiersVariable($key, $value) {
1138
-        if ($key != 'phx' && $key != 'dummy') $this->placeholders[$key] = $value;
1369
+    public function setModifiersVariable($key, $value)
1370
+    {
1371
+        if ($key != 'phx' && $key != 'dummy') {
1372
+            $this->placeholders[$key] = $value;
1373
+        }
1139 1374
     }
1140 1375
 
1141 1376
     //mbstring
1142
-    public function substr($str, $s, $l = null) {
1377
+    public function substr($str, $s, $l = null)
1378
+    {
1143 1379
         $modx = evolutionCMS();
1144
-        if(is_null($l)) $l = $this->strlen($str);
1145
-        if (function_exists('mb_substr'))
1146
-        {
1147
-            if(strpos($str,"\r")!==false)
1148
-                $str = str_replace(array("\r\n","\r"), "\n", $str);
1380
+        if(is_null($l)) {
1381
+            $l = $this->strlen($str);
1382
+        }
1383
+        if (function_exists('mb_substr')) {
1384
+            if(strpos($str,"\r")!==false) {
1385
+                            $str = str_replace(array("\r\n","\r"), "\n", $str);
1386
+            }
1149 1387
             return mb_substr($str, $s, $l, $modx->config['modx_charset']);
1150 1388
         }
1151 1389
         return substr($str, $s, $l);
1152 1390
     }
1153
-    public function strpos($haystack,$needle,$offset=0) {
1391
+    public function strpos($haystack,$needle,$offset=0)
1392
+    {
1154 1393
         $modx = evolutionCMS();
1155
-        if (function_exists('mb_strpos')) return mb_strpos($haystack,$needle,$offset,$modx->config['modx_charset']);
1394
+        if (function_exists('mb_strpos')) {
1395
+            return mb_strpos($haystack,$needle,$offset,$modx->config['modx_charset']);
1396
+        }
1156 1397
         return strpos($haystack,$needle,$offset);
1157 1398
     }
1158
-    public function strlen($str) {
1399
+    public function strlen($str)
1400
+    {
1159 1401
         $modx = evolutionCMS();
1160
-        if (function_exists('mb_strlen')) return mb_strlen(str_replace("\r\n", "\n", $str),$modx->config['modx_charset']);
1402
+        if (function_exists('mb_strlen')) {
1403
+            return mb_strlen(str_replace("\r\n", "\n", $str),$modx->config['modx_charset']);
1404
+        }
1161 1405
         return strlen($str);
1162 1406
     }
1163
-    public function strtolower($str) {
1164
-        if (function_exists('mb_strtolower')) return mb_strtolower($str);
1407
+    public function strtolower($str)
1408
+    {
1409
+        if (function_exists('mb_strtolower')) {
1410
+            return mb_strtolower($str);
1411
+        }
1165 1412
         return strtolower($str);
1166 1413
     }
1167
-    public function strtoupper($str) {
1168
-        if (function_exists('mb_strtoupper')) return mb_strtoupper($str);
1414
+    public function strtoupper($str)
1415
+    {
1416
+        if (function_exists('mb_strtoupper')) {
1417
+            return mb_strtoupper($str);
1418
+        }
1169 1419
         return strtoupper($str);
1170 1420
     }
1171
-    public function ucfirst($str) {
1172
-        if (function_exists('mb_strtoupper'))
1173
-            return mb_strtoupper($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str));
1421
+    public function ucfirst($str)
1422
+    {
1423
+        if (function_exists('mb_strtoupper')) {
1424
+                    return mb_strtoupper($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str));
1425
+        }
1174 1426
         return ucfirst($str);
1175 1427
     }
1176
-    public function lcfirst($str) {
1177
-        if (function_exists('mb_strtolower'))
1178
-            return mb_strtolower($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str));
1428
+    public function lcfirst($str)
1429
+    {
1430
+        if (function_exists('mb_strtolower')) {
1431
+                    return mb_strtolower($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str));
1432
+        }
1179 1433
         return lcfirst($str);
1180 1434
     }
1181
-    public function ucwords($str) {
1182
-        if (function_exists('mb_convert_case'))
1183
-            return mb_convert_case($str, MB_CASE_TITLE);
1435
+    public function ucwords($str)
1436
+    {
1437
+        if (function_exists('mb_convert_case')) {
1438
+                    return mb_convert_case($str, MB_CASE_TITLE);
1439
+        }
1184 1440
         return ucwords($str);
1185 1441
     }
1186
-    public function strrev($str) {
1442
+    public function strrev($str)
1443
+    {
1187 1444
         preg_match_all('/./us', $str, $ar);
1188 1445
         return implode(array_reverse($ar[0]));
1189 1446
     }
1190
-    public function str_shuffle($str) {
1447
+    public function str_shuffle($str)
1448
+    {
1191 1449
         preg_match_all('/./us', $str, $ar);
1192 1450
         shuffle($ar[0]);
1193 1451
         return implode($ar[0]);
1194 1452
     }
1195
-    public function str_word_count($str) {
1453
+    public function str_word_count($str)
1454
+    {
1196 1455
         return count(preg_split('~[^\p{L}\p{N}\']+~u',$str));
1197 1456
     }
1198
-    public function strip_tags($value,$params='') {
1457
+    public function strip_tags($value,$params='')
1458
+    {
1199 1459
         $modx = evolutionCMS();
1200 1460
 
1201 1461
         if(stripos($params,'style')===false && stripos($value,'</style>')!==false) {
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -349,7 +349,7 @@
 block discarded – undo
349 349
                 $conditional = implode(' ',$this->condition);
350 350
                 $isvalid = (int)(eval("return ({$conditional});"));
351 351
                 if ($isvalid) return $this->srcValue;
352
-                return NULL;
352
+                return null;
353 353
             case 'then':
354 354
                 $conditional = implode(' ',$this->condition);
355 355
                 $isvalid = (int)eval("return ({$conditional});");
Please login to merge, or discard this patch.
manager/includes/src/Legacy/PhpCompat.php 1 patch
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@
 block discarded – undo
10 10
      * @param int $flags
11 11
      * @param string $encode
12 12
      * @param int $safecount
13
-     * @return string|array
13
+     * @return null|string
14 14
      */
15 15
     public function htmlspecialchars($str = '', $flags = ENT_COMPAT, $encode = '', $safecount = 0)
16 16
     {
Please login to merge, or discard this patch.
manager/includes/src/Mail.php 2 patches
Unused Use Statements   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@
 block discarded – undo
1 1
 <?php namespace EvolutionCMS;
2 2
 
3
-use PHPMailer\PHPMailer\PHPMailer;
4 3
 use PHPMailer\PHPMailer\Exception as PHPMailerException;
4
+use PHPMailer\PHPMailer\PHPMailer;
5 5
 
6 6
 class Mail extends PHPMailer
7 7
 {
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
     {
30 30
         $modx = evolutionCMS();
31 31
         $this->modx = $modx;
32
-        $this->PluginDir = MODX_MANAGER_PATH . 'includes/controls/phpmailer/';
32
+        $this->PluginDir = MODX_MANAGER_PATH.'includes/controls/phpmailer/';
33 33
 
34 34
         switch ($modx->config['email_method']) {
35 35
             case 'smtp':
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
             mb_language($this->mb_language);
96 96
             mb_internal_encoding($modx->config['modx_charset']);
97 97
         }
98
-        $exconf = MODX_MANAGER_PATH . 'includes/controls/phpmailer/config.inc.php';
98
+        $exconf = MODX_MANAGER_PATH.'includes/controls/phpmailer/config.inc.php';
99 99
         if (is_file($exconf)) {
100 100
             include($exconf);
101 101
         }
@@ -163,12 +163,12 @@  discard block
 block discarded – undo
163 163
         }
164 164
 
165 165
         if ($this->modx->debug) {
166
-            $debug_info = 'CharSet = ' . $this->CharSet . "\n";
167
-            $debug_info .= 'Encoding = ' . $this->Encoding . "\n";
168
-            $debug_info .= 'mb_language = ' . $this->mb_language . "\n";
169
-            $debug_info .= 'encode_header_method = ' . $this->encode_header_method . "\n";
166
+            $debug_info = 'CharSet = '.$this->CharSet."\n";
167
+            $debug_info .= 'Encoding = '.$this->Encoding."\n";
168
+            $debug_info .= 'mb_language = '.$this->mb_language."\n";
169
+            $debug_info .= 'encode_header_method = '.$this->encode_header_method."\n";
170 170
             $debug_info .= "send_mode = {$mode}\n";
171
-            $debug_info .= 'Subject = ' . $this->Subject . "\n";
171
+            $debug_info .= 'Subject = '.$this->Subject."\n";
172 172
             $log = "<pre>{$debug_info}\n{$header}\n{$org_body}</pre>";
173 173
             $this->modx->logEvent(1, 1, $log, 'MODxMailer debug information');
174 174
 
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
             ini_set('sendmail_from', $old_from);
235 235
         }
236 236
         if (!$rt) {
237
-            $msg = $this->Lang('instantiate') . "<br />\n";
237
+            $msg = $this->Lang('instantiate')."<br />\n";
238 238
             $msg .= "{$this->Subject}<br />\n";
239 239
             $msg .= "{$this->FromName}&lt;{$this->From}&gt;<br />\n";
240 240
             $msg .= mb_convert_encoding($body, $this->modx->config['modx_charset'], $this->CharSet);
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
         $classDump = call_user_func('get_object_vars', $this);
257 257
         unset($classDump['modx']);
258 258
         $this->modx->config['send_errormail'] = '0';
259
-        $this->modx->logEvent(0, 3, $msg . '<pre>' . print_r($classDump, true) . '</pre>', 'phpmailer');
259
+        $this->modx->logEvent(0, 3, $msg.'<pre>'.print_r($classDump, true).'</pre>', 'phpmailer');
260 260
 
261 261
         return parent::SetError($msg);
262 262
     }
Please login to merge, or discard this patch.
manager/includes/src/Support/DataGrid.php 4 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -207,6 +207,9 @@
 block discarded – undo
207 207
 
208 208
 	// format column values
209 209
 
210
+    /**
211
+     * @param integer $n
212
+     */
210 213
     public function RenderRowFnc($n, $row) {
211 214
 		if($this->_alt == 0) {
212 215
 			$Style = $this->_itemStyle;
Please login to merge, or discard this patch.
Indentation   +223 added lines, -223 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 
14 14
 class DataGrid implements DataGridInterface{
15 15
 
16
-	public $ds; // datasource
16
+    public $ds; // datasource
17 17
     public $id;
18 18
     public $pageSize;            // pager settings
19 19
     public $pageNumber;
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
     public $colWraps;
38 38
     public $colColors;
39 39
     public $colTypes;            // coltype1, coltype2, etc or coltype1:format1, e.g. date:%Y %m
40
-	// data type: integer,float,currency,date
40
+    // data type: integer,float,currency,date
41 41
 
42 42
     public $header;
43 43
     public $footer;
@@ -76,236 +76,236 @@  discard block
 block discarded – undo
76 76
     public static $dataGridCnt;
77 77
 
78 78
     public function __construct($id, $ds, $pageSize = 20, $pageNumber = -1) {
79
-		// set id
80
-		self::$dataGridCnt++;
81
-		$this->id = $this->id ? empty($id) : "dg" . self::$dataGridCnt;
79
+        // set id
80
+        self::$dataGridCnt++;
81
+        $this->id = $this->id ? empty($id) : "dg" . self::$dataGridCnt;
82 82
 
83
-		// set datasource
84
-		$this->ds = $ds;
83
+        // set datasource
84
+        $this->ds = $ds;
85 85
 
86
-		// set pager
87
-		$this->pageSize = $pageSize;
88
-		$this->pageNumber = $pageNumber; // by setting pager to -1 will cause pager to load it's last page number
89
-		$this->pagerLocation = 'top-right';
90
-	}
86
+        // set pager
87
+        $this->pageSize = $pageSize;
88
+        $this->pageNumber = $pageNumber; // by setting pager to -1 will cause pager to load it's last page number
89
+        $this->pagerLocation = 'top-right';
90
+    }
91 91
 
92 92
     public function setDataSource($ds) {
93
-		$this->ds = $ds;
94
-	}
93
+        $this->ds = $ds;
94
+    }
95 95
 
96 96
     public function render() {
97 97
         $modx = evolutionCMS();
98
-		$columnHeaderStyle = ($this->columnHeaderStyle) ? "style='" . $this->columnHeaderStyle . "'" : '';
99
-		$columnHeaderClass = ($this->columnHeaderClass) ? "class='" . $this->columnHeaderClass . "'" : "";
100
-		$cssStyle = ($this->cssStyle) ? "style='" . $this->cssStyle . "'" : '';
101
-		$cssClass = ($this->cssClass) ? "class='" . $this->cssClass . "'" : '';
102
-
103
-		$pagerClass = ($this->pagerClass) ? "class='" . $this->pagerClass . "'" : '';
104
-		$pagerStyle = ($this->pagerStyle) ? "style='" . $this->pagerStyle . "'" : "style='background-color:#ffffff;'";
105
-
106
-		$this->_itemStyle = ($this->itemStyle) ? "style='" . $this->itemStyle . "'" : '';
107
-		$this->_itemClass = ($this->itemClass) ? "class='" . $this->itemClass . "'" : '';
108
-		$this->_altItemStyle = ($this->altItemStyle) ? "style='" . $this->altItemStyle . "'" : '';
109
-		$this->_altItemClass = ($this->altItemClass) ? "class='" . $this->altItemClass . "'" : '';
110
-
111
-		$this->_alt = 0;
112
-		$this->_total = 0;
113
-
114
-		$this->_isDataset = $modx->getDatabase()->isResult($this->ds); // if not dataset then treat as array
115
-
116
-		if(!$cssStyle && !$cssClass) {
117
-			$cssStyle = "style='width:100%;border:1px solid silver;font-family:verdana,arial; font-size:11px;'";
118
-		}
119
-		if(!$columnHeaderStyle && !$columnHeaderClass) {
120
-			$columnHeaderStyle = "style='color:black;background-color:silver'";
121
-		}
122
-		if(!$this->_itemStyle && !$this->_itemClass) {
123
-			$this->_itemStyle = "style='color:black;'";
124
-		}
125
-		if(!$this->_altItemStyle && !$this->_altItemClass) {
126
-			$this->_altItemStyle = "style='color:black;background-color:#eeeeee'";
127
-		}
128
-
129
-		if($this->_isDataset && !$this->columns) {
130
-			$cols = $modx->getDatabase()->numFields($this->ds);
131
-			for($i = 0; $i < $cols; $i++) $this->columns .= ($i ? "," : "") . $modx->getDatabase()->fieldName($this->ds, $i);
132
-		}
133
-
134
-		// start grid
135
-		$tblStart = "<table $cssClass $cssStyle cellpadding='" . (isset($this->cellPadding) ? (int) $this->cellPadding : 1) . "' cellspacing='" . (isset($this->cellSpacing) ? (int) $this->cellSpacing : 1) . "'>";
136
-		$tblEnd = "</table>";
137
-
138
-		// build column header
139
-		$this->_colnames = explode((strstr($this->columns, "||") !== false ? "||" : ","), $this->columns);
140
-		$this->_colwidths = explode((strstr($this->colWidths, "||") !== false ? "||" : ","), $this->colWidths);
141
-		$this->_colaligns = explode((strstr($this->colAligns, "||") !== false ? "||" : ","), $this->colAligns);
142
-		$this->_colwraps = explode((strstr($this->colWraps, "||") !== false ? "||" : ","), $this->colWraps);
143
-		$this->_colcolors = explode((strstr($this->colColors, "||") !== false ? "||" : ","), $this->colColors);
144
-		$this->_coltypes = explode((strstr($this->colTypes, "||") !== false ? "||" : ","), $this->colTypes);
145
-		$this->_colcount = count($this->_colnames);
146
-		if(!$this->_isDataset) {
147
-			$this->ds = explode((strstr($this->ds, "||") !== false ? "||" : ","), $this->ds);
148
-			$this->ds = array_chunk($this->ds, $this->_colcount);
149
-		}
150
-		$tblColHdr = "<thead><tr>";
151
-		for($c = 0; $c < $this->_colcount; $c++) {
152
-			$name = $this->_colnames[$c];
153
-			$width = $this->_colwidths[$c];
154
-			$tblColHdr .= "<td $columnHeaderStyle $columnHeaderClass" . ($width ? " width='$width'" : "") . ">$name</td>";
155
-		}
156
-		$tblColHdr .= "</tr></thead>\n";
157
-
158
-		// build rows
159
-		$rowcount = $this->_isDataset ? $modx->getDatabase()->getRecordCount($this->ds) : count($this->ds);
160
-		$this->_fieldnames = explode(",", $this->fields);
161
-		if($rowcount == 0) {
162
-			$tblRows .= "<tr><td " . $this->_itemStyle . " " . $this->_itemClass . " colspan='" . $this->_colcount . "'>" . $this->noRecordMsg . "</td></tr>\n";
163
-		} else {
164
-			// render grid items
165
-			if($this->pageSize <= 0) {
166
-				for($r = 0; $r < $rowcount; $r++) {
167
-					$row = $this->_isDataset ? $modx->getDatabase()->getRow($this->ds) : $this->ds[$r];
168
-					$tblRows .= $this->RenderRowFnc($r + 1, $row);
169
-				}
170
-			} else {
171
-				if(!$this->pager) {
172
-					$this->pager = new DataSetPager($this->id, $this->ds, $this->pageSize, $this->pageNumber);
173
-					$this->pager->setRenderRowFnc($this); // pass this object
174
-					$this->pager->cssStyle = $pagerStyle;
175
-					$this->pager->cssClass = $pagerClass;
176
-				} else {
177
-					$this->pager->pageSize = $this->pageSize;
178
-					$this->pager->pageNumber = $this->pageNumber;
179
-				}
180
-
181
-				$this->pager->render();
182
-				$tblRows = $this->pager->getRenderedRows();
183
-				$tblPager = $this->pager->getRenderedPager();
184
-			}
185
-		}
186
-
187
-		// setup header,pager and footer
188
-		$o = $tblStart;
189
-		$ptop = (substr($this->pagerLocation, 0, 3) == "top") || (substr($this->pagerLocation, 0, 4) == "both");
190
-		$pbot = (substr($this->pagerLocation, 0, 3) == "bot") || (substr($this->pagerLocation, 0, 4) == "both");
191
-		if($this->header) {
192
-			$o .= "<tr><td bgcolor='#ffffff' colspan='" . $this->_colcount . "'>" . $this->header . "</td></tr>";
193
-		}
194
-		if($tblPager && $ptop) {
195
-			$o .= "<tr><td align='" . (substr($this->pagerLocation, -4) == "left" ? "left" : "right") . "' $pagerClass $pagerStyle colspan='" . $this->_colcount . "'>" . $tblPager . "&nbsp;</td></tr>";
196
-		}
197
-		$o .= $tblColHdr . $tblRows;
198
-		if($tblPager && $pbot) {
199
-			$o .= "<tr><td align='" . (substr($this->pagerLocation, -4) == "left" ? "left" : "right") . "' $pagerClass $pagerStyle colspan='" . $this->_colcount . "'>" . $tblPager . "&nbsp;</td></tr>";
200
-		}
201
-		if($this->footer) {
202
-			$o .= "<tr><td bgcolor='#ffffff' colspan='" . $this->_colcount . "'>" . $this->footer . "</td></tr>";
203
-		}
204
-		$o .= $tblEnd;
205
-		return $o;
206
-	}
207
-
208
-	// format column values
98
+        $columnHeaderStyle = ($this->columnHeaderStyle) ? "style='" . $this->columnHeaderStyle . "'" : '';
99
+        $columnHeaderClass = ($this->columnHeaderClass) ? "class='" . $this->columnHeaderClass . "'" : "";
100
+        $cssStyle = ($this->cssStyle) ? "style='" . $this->cssStyle . "'" : '';
101
+        $cssClass = ($this->cssClass) ? "class='" . $this->cssClass . "'" : '';
102
+
103
+        $pagerClass = ($this->pagerClass) ? "class='" . $this->pagerClass . "'" : '';
104
+        $pagerStyle = ($this->pagerStyle) ? "style='" . $this->pagerStyle . "'" : "style='background-color:#ffffff;'";
105
+
106
+        $this->_itemStyle = ($this->itemStyle) ? "style='" . $this->itemStyle . "'" : '';
107
+        $this->_itemClass = ($this->itemClass) ? "class='" . $this->itemClass . "'" : '';
108
+        $this->_altItemStyle = ($this->altItemStyle) ? "style='" . $this->altItemStyle . "'" : '';
109
+        $this->_altItemClass = ($this->altItemClass) ? "class='" . $this->altItemClass . "'" : '';
110
+
111
+        $this->_alt = 0;
112
+        $this->_total = 0;
113
+
114
+        $this->_isDataset = $modx->getDatabase()->isResult($this->ds); // if not dataset then treat as array
115
+
116
+        if(!$cssStyle && !$cssClass) {
117
+            $cssStyle = "style='width:100%;border:1px solid silver;font-family:verdana,arial; font-size:11px;'";
118
+        }
119
+        if(!$columnHeaderStyle && !$columnHeaderClass) {
120
+            $columnHeaderStyle = "style='color:black;background-color:silver'";
121
+        }
122
+        if(!$this->_itemStyle && !$this->_itemClass) {
123
+            $this->_itemStyle = "style='color:black;'";
124
+        }
125
+        if(!$this->_altItemStyle && !$this->_altItemClass) {
126
+            $this->_altItemStyle = "style='color:black;background-color:#eeeeee'";
127
+        }
128
+
129
+        if($this->_isDataset && !$this->columns) {
130
+            $cols = $modx->getDatabase()->numFields($this->ds);
131
+            for($i = 0; $i < $cols; $i++) $this->columns .= ($i ? "," : "") . $modx->getDatabase()->fieldName($this->ds, $i);
132
+        }
133
+
134
+        // start grid
135
+        $tblStart = "<table $cssClass $cssStyle cellpadding='" . (isset($this->cellPadding) ? (int) $this->cellPadding : 1) . "' cellspacing='" . (isset($this->cellSpacing) ? (int) $this->cellSpacing : 1) . "'>";
136
+        $tblEnd = "</table>";
137
+
138
+        // build column header
139
+        $this->_colnames = explode((strstr($this->columns, "||") !== false ? "||" : ","), $this->columns);
140
+        $this->_colwidths = explode((strstr($this->colWidths, "||") !== false ? "||" : ","), $this->colWidths);
141
+        $this->_colaligns = explode((strstr($this->colAligns, "||") !== false ? "||" : ","), $this->colAligns);
142
+        $this->_colwraps = explode((strstr($this->colWraps, "||") !== false ? "||" : ","), $this->colWraps);
143
+        $this->_colcolors = explode((strstr($this->colColors, "||") !== false ? "||" : ","), $this->colColors);
144
+        $this->_coltypes = explode((strstr($this->colTypes, "||") !== false ? "||" : ","), $this->colTypes);
145
+        $this->_colcount = count($this->_colnames);
146
+        if(!$this->_isDataset) {
147
+            $this->ds = explode((strstr($this->ds, "||") !== false ? "||" : ","), $this->ds);
148
+            $this->ds = array_chunk($this->ds, $this->_colcount);
149
+        }
150
+        $tblColHdr = "<thead><tr>";
151
+        for($c = 0; $c < $this->_colcount; $c++) {
152
+            $name = $this->_colnames[$c];
153
+            $width = $this->_colwidths[$c];
154
+            $tblColHdr .= "<td $columnHeaderStyle $columnHeaderClass" . ($width ? " width='$width'" : "") . ">$name</td>";
155
+        }
156
+        $tblColHdr .= "</tr></thead>\n";
157
+
158
+        // build rows
159
+        $rowcount = $this->_isDataset ? $modx->getDatabase()->getRecordCount($this->ds) : count($this->ds);
160
+        $this->_fieldnames = explode(",", $this->fields);
161
+        if($rowcount == 0) {
162
+            $tblRows .= "<tr><td " . $this->_itemStyle . " " . $this->_itemClass . " colspan='" . $this->_colcount . "'>" . $this->noRecordMsg . "</td></tr>\n";
163
+        } else {
164
+            // render grid items
165
+            if($this->pageSize <= 0) {
166
+                for($r = 0; $r < $rowcount; $r++) {
167
+                    $row = $this->_isDataset ? $modx->getDatabase()->getRow($this->ds) : $this->ds[$r];
168
+                    $tblRows .= $this->RenderRowFnc($r + 1, $row);
169
+                }
170
+            } else {
171
+                if(!$this->pager) {
172
+                    $this->pager = new DataSetPager($this->id, $this->ds, $this->pageSize, $this->pageNumber);
173
+                    $this->pager->setRenderRowFnc($this); // pass this object
174
+                    $this->pager->cssStyle = $pagerStyle;
175
+                    $this->pager->cssClass = $pagerClass;
176
+                } else {
177
+                    $this->pager->pageSize = $this->pageSize;
178
+                    $this->pager->pageNumber = $this->pageNumber;
179
+                }
180
+
181
+                $this->pager->render();
182
+                $tblRows = $this->pager->getRenderedRows();
183
+                $tblPager = $this->pager->getRenderedPager();
184
+            }
185
+        }
186
+
187
+        // setup header,pager and footer
188
+        $o = $tblStart;
189
+        $ptop = (substr($this->pagerLocation, 0, 3) == "top") || (substr($this->pagerLocation, 0, 4) == "both");
190
+        $pbot = (substr($this->pagerLocation, 0, 3) == "bot") || (substr($this->pagerLocation, 0, 4) == "both");
191
+        if($this->header) {
192
+            $o .= "<tr><td bgcolor='#ffffff' colspan='" . $this->_colcount . "'>" . $this->header . "</td></tr>";
193
+        }
194
+        if($tblPager && $ptop) {
195
+            $o .= "<tr><td align='" . (substr($this->pagerLocation, -4) == "left" ? "left" : "right") . "' $pagerClass $pagerStyle colspan='" . $this->_colcount . "'>" . $tblPager . "&nbsp;</td></tr>";
196
+        }
197
+        $o .= $tblColHdr . $tblRows;
198
+        if($tblPager && $pbot) {
199
+            $o .= "<tr><td align='" . (substr($this->pagerLocation, -4) == "left" ? "left" : "right") . "' $pagerClass $pagerStyle colspan='" . $this->_colcount . "'>" . $tblPager . "&nbsp;</td></tr>";
200
+        }
201
+        if($this->footer) {
202
+            $o .= "<tr><td bgcolor='#ffffff' colspan='" . $this->_colcount . "'>" . $this->footer . "</td></tr>";
203
+        }
204
+        $o .= $tblEnd;
205
+        return $o;
206
+    }
207
+
208
+    // format column values
209 209
 
210 210
     public function RenderRowFnc($n, $row) {
211
-		if($this->_alt == 0) {
212
-			$Style = $this->_itemStyle;
213
-			$Class = $this->_itemClass;
214
-			$this->_alt = 1;
215
-		} else {
216
-			$Style = $this->_altItemStyle;
217
-			$Class = $this->_altItemClass;
218
-			$this->_alt = 0;
219
-		}
220
-		$o = "<tr>";
221
-		for($c = 0; $c < $this->_colcount; $c++) {
222
-			$colStyle = $Style;
223
-			$fld = trim($this->_fieldnames[$c]);
224
-			$width = isset($this->_colwidths[$c]) ? $this->_colwidths[$c] : null;
225
-			$align = isset($this->_colaligns[$c]) ? $this->_colaligns[$c] : null;
226
-			$color = isset($this->_colcolors[$c]) ? $this->_colcolors[$c] : null;
227
-			$type = isset($this->_coltypes[$c]) ? $this->_coltypes[$c] : null;
228
-			$nowrap = isset($this->_colwraps[$c]) ? $this->_colwraps[$c] : null;
229
-			$value = $row[($this->_isDataset && $fld ? $fld : $c)];
230
-			if($color && $Style) {
231
-				$colStyle = substr($colStyle, 0, -1) . ";background-color:$color;'";
232
-			}
233
-			$value = $this->formatColumnValue($row, $value, $type, $align);
234
-			$o .= "<td $colStyle $Class" . ($align ? " align='$align'" : "") . ($color ? " bgcolor='$color'" : "") . ($nowrap ? " nowrap='$nowrap'" : "") . ($width ? " width='$width'" : "") . ">$value</td>";
235
-		}
236
-		$o .= "</tr>\n";
237
-		return $o;
238
-	}
211
+        if($this->_alt == 0) {
212
+            $Style = $this->_itemStyle;
213
+            $Class = $this->_itemClass;
214
+            $this->_alt = 1;
215
+        } else {
216
+            $Style = $this->_altItemStyle;
217
+            $Class = $this->_altItemClass;
218
+            $this->_alt = 0;
219
+        }
220
+        $o = "<tr>";
221
+        for($c = 0; $c < $this->_colcount; $c++) {
222
+            $colStyle = $Style;
223
+            $fld = trim($this->_fieldnames[$c]);
224
+            $width = isset($this->_colwidths[$c]) ? $this->_colwidths[$c] : null;
225
+            $align = isset($this->_colaligns[$c]) ? $this->_colaligns[$c] : null;
226
+            $color = isset($this->_colcolors[$c]) ? $this->_colcolors[$c] : null;
227
+            $type = isset($this->_coltypes[$c]) ? $this->_coltypes[$c] : null;
228
+            $nowrap = isset($this->_colwraps[$c]) ? $this->_colwraps[$c] : null;
229
+            $value = $row[($this->_isDataset && $fld ? $fld : $c)];
230
+            if($color && $Style) {
231
+                $colStyle = substr($colStyle, 0, -1) . ";background-color:$color;'";
232
+            }
233
+            $value = $this->formatColumnValue($row, $value, $type, $align);
234
+            $o .= "<td $colStyle $Class" . ($align ? " align='$align'" : "") . ($color ? " bgcolor='$color'" : "") . ($nowrap ? " nowrap='$nowrap'" : "") . ($width ? " width='$width'" : "") . ">$value</td>";
235
+        }
236
+        $o .= "</tr>\n";
237
+        return $o;
238
+    }
239 239
 
240 240
     public function formatColumnValue($row, $value, $type, &$align) {
241
-		if(strpos($type, ":") !== false) {
242
-			list($type, $type_format) = explode(":", $type, 2);
243
-		}
244
-		switch(strtolower($type)) {
245
-			case "integer":
246
-				if($align == "") {
247
-					$align = "right";
248
-				}
249
-				$value = number_format($value);
250
-				break;
251
-
252
-			case "float":
253
-				if($align == "") {
254
-					$align = "right";
255
-				}
256
-				if(!$type_format) {
257
-					$type_format = 2;
258
-				}
259
-				$value = number_format($value, $type_format);
260
-				break;
261
-
262
-			case "currency":
263
-				if($align == "") {
264
-					$align = "right";
265
-				}
266
-				if(!$type_format) {
267
-					$type_format = 2;
268
-				}
269
-				$value = "$" . number_format($value, $type_format);
270
-				break;
271
-
272
-			case "date":
273
-				if($align == "") {
274
-					$align = "right";
275
-				}
276
-				if(!is_numeric($value)) {
277
-					$value = strtotime($value);
278
-				}
279
-				if(!$type_format) {
280
-					$type_format = "%A %d, %B %Y";
281
-				}
282
-				$value = strftime($type_format, $value);
283
-				break;
284
-
285
-			case "boolean":
286
-				if($align == '') {
287
-					$align = "center";
288
-				}
289
-				$value = number_format($value);
290
-				if($value) {
291
-					$value = '&bull;';
292
-				} else {
293
-					$value = '&nbsp;';
294
-				}
295
-				break;
296
-
297
-			case "template":
298
-				// replace [+value+] first
299
-				$value = str_replace("[+value+]", $value, $type_format);
300
-				// replace other [+fields+]
301
-				if(strpos($value, "[+") !== false) {
302
-					foreach($row as $k => $v) {
303
-						$value = str_replace("[+$k+]", $v, $value);
304
-					}
305
-				}
306
-				break;
307
-
308
-		}
309
-		return $value;
310
-	}
241
+        if(strpos($type, ":") !== false) {
242
+            list($type, $type_format) = explode(":", $type, 2);
243
+        }
244
+        switch(strtolower($type)) {
245
+            case "integer":
246
+                if($align == "") {
247
+                    $align = "right";
248
+                }
249
+                $value = number_format($value);
250
+                break;
251
+
252
+            case "float":
253
+                if($align == "") {
254
+                    $align = "right";
255
+                }
256
+                if(!$type_format) {
257
+                    $type_format = 2;
258
+                }
259
+                $value = number_format($value, $type_format);
260
+                break;
261
+
262
+            case "currency":
263
+                if($align == "") {
264
+                    $align = "right";
265
+                }
266
+                if(!$type_format) {
267
+                    $type_format = 2;
268
+                }
269
+                $value = "$" . number_format($value, $type_format);
270
+                break;
271
+
272
+            case "date":
273
+                if($align == "") {
274
+                    $align = "right";
275
+                }
276
+                if(!is_numeric($value)) {
277
+                    $value = strtotime($value);
278
+                }
279
+                if(!$type_format) {
280
+                    $type_format = "%A %d, %B %Y";
281
+                }
282
+                $value = strftime($type_format, $value);
283
+                break;
284
+
285
+            case "boolean":
286
+                if($align == '') {
287
+                    $align = "center";
288
+                }
289
+                $value = number_format($value);
290
+                if($value) {
291
+                    $value = '&bull;';
292
+                } else {
293
+                    $value = '&nbsp;';
294
+                }
295
+                break;
296
+
297
+            case "template":
298
+                // replace [+value+] first
299
+                $value = str_replace("[+value+]", $value, $type_format);
300
+                // replace other [+fields+]
301
+                if(strpos($value, "[+") !== false) {
302
+                    foreach($row as $k => $v) {
303
+                        $value = str_replace("[+$k+]", $v, $value);
304
+                    }
305
+                }
306
+                break;
307
+
308
+        }
309
+        return $value;
310
+    }
311 311
 }
Please login to merge, or discard this patch.
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -15,10 +15,10 @@  discard block
 block discarded – undo
15 15
 
16 16
 	public $ds; // datasource
17 17
     public $id;
18
-    public $pageSize;            // pager settings
18
+    public $pageSize; // pager settings
19 19
     public $pageNumber;
20 20
     public $pager;
21
-    public $pagerLocation;        // top-right, top-left, bottom-left, bottom-right, both-left, both-right
21
+    public $pagerLocation; // top-right, top-left, bottom-left, bottom-right, both-left, both-right
22 22
 
23 23
     public $cssStyle;
24 24
     public $cssClass;
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
     public $colAligns;
37 37
     public $colWraps;
38 38
     public $colColors;
39
-    public $colTypes;            // coltype1, coltype2, etc or coltype1:format1, e.g. date:%Y %m
39
+    public $colTypes; // coltype1, coltype2, etc or coltype1:format1, e.g. date:%Y %m
40 40
 	// data type: integer,float,currency,date
41 41
 
42 42
     public $header;
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
     public $cellPadding;
45 45
     public $cellSpacing;
46 46
 
47
-    public $rowAlign;            // vertical alignment: top, middle, bottom
47
+    public $rowAlign; // vertical alignment: top, middle, bottom
48 48
     public $rowIdField;
49 49
 
50 50
     public $pagerStyle;
@@ -75,10 +75,10 @@  discard block
 block discarded – undo
75 75
 
76 76
     public static $dataGridCnt;
77 77
 
78
-    public function __construct($id, $ds, $pageSize = 20, $pageNumber = -1) {
78
+    public function __construct($id, $ds, $pageSize = 20, $pageNumber = -1){
79 79
 		// set id
80 80
 		self::$dataGridCnt++;
81
-		$this->id = $this->id ? empty($id) : "dg" . self::$dataGridCnt;
81
+		$this->id = $this->id ? empty($id) : "dg".self::$dataGridCnt;
82 82
 
83 83
 		// set datasource
84 84
 		$this->ds = $ds;
@@ -89,50 +89,50 @@  discard block
 block discarded – undo
89 89
 		$this->pagerLocation = 'top-right';
90 90
 	}
91 91
 
92
-    public function setDataSource($ds) {
92
+    public function setDataSource($ds){
93 93
 		$this->ds = $ds;
94 94
 	}
95 95
 
96
-    public function render() {
96
+    public function render(){
97 97
         $modx = evolutionCMS();
98
-		$columnHeaderStyle = ($this->columnHeaderStyle) ? "style='" . $this->columnHeaderStyle . "'" : '';
99
-		$columnHeaderClass = ($this->columnHeaderClass) ? "class='" . $this->columnHeaderClass . "'" : "";
100
-		$cssStyle = ($this->cssStyle) ? "style='" . $this->cssStyle . "'" : '';
101
-		$cssClass = ($this->cssClass) ? "class='" . $this->cssClass . "'" : '';
98
+		$columnHeaderStyle = ($this->columnHeaderStyle) ? "style='".$this->columnHeaderStyle."'" : '';
99
+		$columnHeaderClass = ($this->columnHeaderClass) ? "class='".$this->columnHeaderClass."'" : "";
100
+		$cssStyle = ($this->cssStyle) ? "style='".$this->cssStyle."'" : '';
101
+		$cssClass = ($this->cssClass) ? "class='".$this->cssClass."'" : '';
102 102
 
103
-		$pagerClass = ($this->pagerClass) ? "class='" . $this->pagerClass . "'" : '';
104
-		$pagerStyle = ($this->pagerStyle) ? "style='" . $this->pagerStyle . "'" : "style='background-color:#ffffff;'";
103
+		$pagerClass = ($this->pagerClass) ? "class='".$this->pagerClass."'" : '';
104
+		$pagerStyle = ($this->pagerStyle) ? "style='".$this->pagerStyle."'" : "style='background-color:#ffffff;'";
105 105
 
106
-		$this->_itemStyle = ($this->itemStyle) ? "style='" . $this->itemStyle . "'" : '';
107
-		$this->_itemClass = ($this->itemClass) ? "class='" . $this->itemClass . "'" : '';
108
-		$this->_altItemStyle = ($this->altItemStyle) ? "style='" . $this->altItemStyle . "'" : '';
109
-		$this->_altItemClass = ($this->altItemClass) ? "class='" . $this->altItemClass . "'" : '';
106
+		$this->_itemStyle = ($this->itemStyle) ? "style='".$this->itemStyle."'" : '';
107
+		$this->_itemClass = ($this->itemClass) ? "class='".$this->itemClass."'" : '';
108
+		$this->_altItemStyle = ($this->altItemStyle) ? "style='".$this->altItemStyle."'" : '';
109
+		$this->_altItemClass = ($this->altItemClass) ? "class='".$this->altItemClass."'" : '';
110 110
 
111 111
 		$this->_alt = 0;
112 112
 		$this->_total = 0;
113 113
 
114 114
 		$this->_isDataset = $modx->getDatabase()->isResult($this->ds); // if not dataset then treat as array
115 115
 
116
-		if(!$cssStyle && !$cssClass) {
116
+		if (!$cssStyle && !$cssClass) {
117 117
 			$cssStyle = "style='width:100%;border:1px solid silver;font-family:verdana,arial; font-size:11px;'";
118 118
 		}
119
-		if(!$columnHeaderStyle && !$columnHeaderClass) {
119
+		if (!$columnHeaderStyle && !$columnHeaderClass) {
120 120
 			$columnHeaderStyle = "style='color:black;background-color:silver'";
121 121
 		}
122
-		if(!$this->_itemStyle && !$this->_itemClass) {
122
+		if (!$this->_itemStyle && !$this->_itemClass) {
123 123
 			$this->_itemStyle = "style='color:black;'";
124 124
 		}
125
-		if(!$this->_altItemStyle && !$this->_altItemClass) {
125
+		if (!$this->_altItemStyle && !$this->_altItemClass) {
126 126
 			$this->_altItemStyle = "style='color:black;background-color:#eeeeee'";
127 127
 		}
128 128
 
129
-		if($this->_isDataset && !$this->columns) {
129
+		if ($this->_isDataset && !$this->columns) {
130 130
 			$cols = $modx->getDatabase()->numFields($this->ds);
131
-			for($i = 0; $i < $cols; $i++) $this->columns .= ($i ? "," : "") . $modx->getDatabase()->fieldName($this->ds, $i);
131
+			for ($i = 0; $i < $cols; $i++) $this->columns .= ($i ? "," : "").$modx->getDatabase()->fieldName($this->ds, $i);
132 132
 		}
133 133
 
134 134
 		// start grid
135
-		$tblStart = "<table $cssClass $cssStyle cellpadding='" . (isset($this->cellPadding) ? (int) $this->cellPadding : 1) . "' cellspacing='" . (isset($this->cellSpacing) ? (int) $this->cellSpacing : 1) . "'>";
135
+		$tblStart = "<table $cssClass $cssStyle cellpadding='".(isset($this->cellPadding) ? (int) $this->cellPadding : 1)."' cellspacing='".(isset($this->cellSpacing) ? (int) $this->cellSpacing : 1)."'>";
136 136
 		$tblEnd = "</table>";
137 137
 
138 138
 		// build column header
@@ -143,32 +143,32 @@  discard block
 block discarded – undo
143 143
 		$this->_colcolors = explode((strstr($this->colColors, "||") !== false ? "||" : ","), $this->colColors);
144 144
 		$this->_coltypes = explode((strstr($this->colTypes, "||") !== false ? "||" : ","), $this->colTypes);
145 145
 		$this->_colcount = count($this->_colnames);
146
-		if(!$this->_isDataset) {
146
+		if (!$this->_isDataset) {
147 147
 			$this->ds = explode((strstr($this->ds, "||") !== false ? "||" : ","), $this->ds);
148 148
 			$this->ds = array_chunk($this->ds, $this->_colcount);
149 149
 		}
150 150
 		$tblColHdr = "<thead><tr>";
151
-		for($c = 0; $c < $this->_colcount; $c++) {
151
+		for ($c = 0; $c < $this->_colcount; $c++) {
152 152
 			$name = $this->_colnames[$c];
153 153
 			$width = $this->_colwidths[$c];
154
-			$tblColHdr .= "<td $columnHeaderStyle $columnHeaderClass" . ($width ? " width='$width'" : "") . ">$name</td>";
154
+			$tblColHdr .= "<td $columnHeaderStyle $columnHeaderClass".($width ? " width='$width'" : "").">$name</td>";
155 155
 		}
156 156
 		$tblColHdr .= "</tr></thead>\n";
157 157
 
158 158
 		// build rows
159 159
 		$rowcount = $this->_isDataset ? $modx->getDatabase()->getRecordCount($this->ds) : count($this->ds);
160 160
 		$this->_fieldnames = explode(",", $this->fields);
161
-		if($rowcount == 0) {
162
-			$tblRows .= "<tr><td " . $this->_itemStyle . " " . $this->_itemClass . " colspan='" . $this->_colcount . "'>" . $this->noRecordMsg . "</td></tr>\n";
161
+		if ($rowcount == 0) {
162
+			$tblRows .= "<tr><td ".$this->_itemStyle." ".$this->_itemClass." colspan='".$this->_colcount."'>".$this->noRecordMsg."</td></tr>\n";
163 163
 		} else {
164 164
 			// render grid items
165
-			if($this->pageSize <= 0) {
166
-				for($r = 0; $r < $rowcount; $r++) {
165
+			if ($this->pageSize <= 0) {
166
+				for ($r = 0; $r < $rowcount; $r++) {
167 167
 					$row = $this->_isDataset ? $modx->getDatabase()->getRow($this->ds) : $this->ds[$r];
168 168
 					$tblRows .= $this->RenderRowFnc($r + 1, $row);
169 169
 				}
170 170
 			} else {
171
-				if(!$this->pager) {
171
+				if (!$this->pager) {
172 172
 					$this->pager = new DataSetPager($this->id, $this->ds, $this->pageSize, $this->pageNumber);
173 173
 					$this->pager->setRenderRowFnc($this); // pass this object
174 174
 					$this->pager->cssStyle = $pagerStyle;
@@ -188,18 +188,18 @@  discard block
 block discarded – undo
188 188
 		$o = $tblStart;
189 189
 		$ptop = (substr($this->pagerLocation, 0, 3) == "top") || (substr($this->pagerLocation, 0, 4) == "both");
190 190
 		$pbot = (substr($this->pagerLocation, 0, 3) == "bot") || (substr($this->pagerLocation, 0, 4) == "both");
191
-		if($this->header) {
192
-			$o .= "<tr><td bgcolor='#ffffff' colspan='" . $this->_colcount . "'>" . $this->header . "</td></tr>";
191
+		if ($this->header) {
192
+			$o .= "<tr><td bgcolor='#ffffff' colspan='".$this->_colcount."'>".$this->header."</td></tr>";
193 193
 		}
194
-		if($tblPager && $ptop) {
195
-			$o .= "<tr><td align='" . (substr($this->pagerLocation, -4) == "left" ? "left" : "right") . "' $pagerClass $pagerStyle colspan='" . $this->_colcount . "'>" . $tblPager . "&nbsp;</td></tr>";
194
+		if ($tblPager && $ptop) {
195
+			$o .= "<tr><td align='".(substr($this->pagerLocation, -4) == "left" ? "left" : "right")."' $pagerClass $pagerStyle colspan='".$this->_colcount."'>".$tblPager."&nbsp;</td></tr>";
196 196
 		}
197
-		$o .= $tblColHdr . $tblRows;
198
-		if($tblPager && $pbot) {
199
-			$o .= "<tr><td align='" . (substr($this->pagerLocation, -4) == "left" ? "left" : "right") . "' $pagerClass $pagerStyle colspan='" . $this->_colcount . "'>" . $tblPager . "&nbsp;</td></tr>";
197
+		$o .= $tblColHdr.$tblRows;
198
+		if ($tblPager && $pbot) {
199
+			$o .= "<tr><td align='".(substr($this->pagerLocation, -4) == "left" ? "left" : "right")."' $pagerClass $pagerStyle colspan='".$this->_colcount."'>".$tblPager."&nbsp;</td></tr>";
200 200
 		}
201
-		if($this->footer) {
202
-			$o .= "<tr><td bgcolor='#ffffff' colspan='" . $this->_colcount . "'>" . $this->footer . "</td></tr>";
201
+		if ($this->footer) {
202
+			$o .= "<tr><td bgcolor='#ffffff' colspan='".$this->_colcount."'>".$this->footer."</td></tr>";
203 203
 		}
204 204
 		$o .= $tblEnd;
205 205
 		return $o;
@@ -207,8 +207,8 @@  discard block
 block discarded – undo
207 207
 
208 208
 	// format column values
209 209
 
210
-    public function RenderRowFnc($n, $row) {
211
-		if($this->_alt == 0) {
210
+    public function RenderRowFnc($n, $row){
211
+		if ($this->_alt == 0) {
212 212
 			$Style = $this->_itemStyle;
213 213
 			$Class = $this->_itemClass;
214 214
 			$this->_alt = 1;
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
 			$this->_alt = 0;
219 219
 		}
220 220
 		$o = "<tr>";
221
-		for($c = 0; $c < $this->_colcount; $c++) {
221
+		for ($c = 0; $c < $this->_colcount; $c++) {
222 222
 			$colStyle = $Style;
223 223
 			$fld = trim($this->_fieldnames[$c]);
224 224
 			$width = isset($this->_colwidths[$c]) ? $this->_colwidths[$c] : null;
@@ -227,67 +227,67 @@  discard block
 block discarded – undo
227 227
 			$type = isset($this->_coltypes[$c]) ? $this->_coltypes[$c] : null;
228 228
 			$nowrap = isset($this->_colwraps[$c]) ? $this->_colwraps[$c] : null;
229 229
 			$value = $row[($this->_isDataset && $fld ? $fld : $c)];
230
-			if($color && $Style) {
231
-				$colStyle = substr($colStyle, 0, -1) . ";background-color:$color;'";
230
+			if ($color && $Style) {
231
+				$colStyle = substr($colStyle, 0, -1).";background-color:$color;'";
232 232
 			}
233 233
 			$value = $this->formatColumnValue($row, $value, $type, $align);
234
-			$o .= "<td $colStyle $Class" . ($align ? " align='$align'" : "") . ($color ? " bgcolor='$color'" : "") . ($nowrap ? " nowrap='$nowrap'" : "") . ($width ? " width='$width'" : "") . ">$value</td>";
234
+			$o .= "<td $colStyle $Class".($align ? " align='$align'" : "").($color ? " bgcolor='$color'" : "").($nowrap ? " nowrap='$nowrap'" : "").($width ? " width='$width'" : "").">$value</td>";
235 235
 		}
236 236
 		$o .= "</tr>\n";
237 237
 		return $o;
238 238
 	}
239 239
 
240
-    public function formatColumnValue($row, $value, $type, &$align) {
241
-		if(strpos($type, ":") !== false) {
240
+    public function formatColumnValue($row, $value, $type, &$align){
241
+		if (strpos($type, ":") !== false) {
242 242
 			list($type, $type_format) = explode(":", $type, 2);
243 243
 		}
244
-		switch(strtolower($type)) {
244
+		switch (strtolower($type)) {
245 245
 			case "integer":
246
-				if($align == "") {
246
+				if ($align == "") {
247 247
 					$align = "right";
248 248
 				}
249 249
 				$value = number_format($value);
250 250
 				break;
251 251
 
252 252
 			case "float":
253
-				if($align == "") {
253
+				if ($align == "") {
254 254
 					$align = "right";
255 255
 				}
256
-				if(!$type_format) {
256
+				if (!$type_format) {
257 257
 					$type_format = 2;
258 258
 				}
259 259
 				$value = number_format($value, $type_format);
260 260
 				break;
261 261
 
262 262
 			case "currency":
263
-				if($align == "") {
263
+				if ($align == "") {
264 264
 					$align = "right";
265 265
 				}
266
-				if(!$type_format) {
266
+				if (!$type_format) {
267 267
 					$type_format = 2;
268 268
 				}
269
-				$value = "$" . number_format($value, $type_format);
269
+				$value = "$".number_format($value, $type_format);
270 270
 				break;
271 271
 
272 272
 			case "date":
273
-				if($align == "") {
273
+				if ($align == "") {
274 274
 					$align = "right";
275 275
 				}
276
-				if(!is_numeric($value)) {
276
+				if (!is_numeric($value)) {
277 277
 					$value = strtotime($value);
278 278
 				}
279
-				if(!$type_format) {
279
+				if (!$type_format) {
280 280
 					$type_format = "%A %d, %B %Y";
281 281
 				}
282 282
 				$value = strftime($type_format, $value);
283 283
 				break;
284 284
 
285 285
 			case "boolean":
286
-				if($align == '') {
286
+				if ($align == '') {
287 287
 					$align = "center";
288 288
 				}
289 289
 				$value = number_format($value);
290
-				if($value) {
290
+				if ($value) {
291 291
 					$value = '&bull;';
292 292
 				} else {
293 293
 					$value = '&nbsp;';
@@ -298,8 +298,8 @@  discard block
 block discarded – undo
298 298
 				// replace [+value+] first
299 299
 				$value = str_replace("[+value+]", $value, $type_format);
300 300
 				// replace other [+fields+]
301
-				if(strpos($value, "[+") !== false) {
302
-					foreach($row as $k => $v) {
301
+				if (strpos($value, "[+") !== false) {
302
+					foreach ($row as $k => $v) {
303 303
 						$value = str_replace("[+$k+]", $v, $value);
304 304
 					}
305 305
 				}
Please login to merge, or discard this patch.
Braces   +15 added lines, -7 removed lines patch added patch discarded remove patch
@@ -11,7 +11,8 @@  discard block
 block discarded – undo
11 11
 # -----------------------------------------
12 12
 #
13 13
 
14
-class DataGrid implements DataGridInterface{
14
+class DataGrid implements DataGridInterface
15
+{
15 16
 
16 17
 	public $ds; // datasource
17 18
     public $id;
@@ -75,7 +76,8 @@  discard block
 block discarded – undo
75 76
 
76 77
     public static $dataGridCnt;
77 78
 
78
-    public function __construct($id, $ds, $pageSize = 20, $pageNumber = -1) {
79
+    public function __construct($id, $ds, $pageSize = 20, $pageNumber = -1)
80
+    {
79 81
 		// set id
80 82
 		self::$dataGridCnt++;
81 83
 		$this->id = $this->id ? empty($id) : "dg" . self::$dataGridCnt;
@@ -89,11 +91,13 @@  discard block
 block discarded – undo
89 91
 		$this->pagerLocation = 'top-right';
90 92
 	}
91 93
 
92
-    public function setDataSource($ds) {
94
+    public function setDataSource($ds)
95
+    {
93 96
 		$this->ds = $ds;
94 97
 	}
95 98
 
96
-    public function render() {
99
+    public function render()
100
+    {
97 101
         $modx = evolutionCMS();
98 102
 		$columnHeaderStyle = ($this->columnHeaderStyle) ? "style='" . $this->columnHeaderStyle . "'" : '';
99 103
 		$columnHeaderClass = ($this->columnHeaderClass) ? "class='" . $this->columnHeaderClass . "'" : "";
@@ -128,7 +132,9 @@  discard block
 block discarded – undo
128 132
 
129 133
 		if($this->_isDataset && !$this->columns) {
130 134
 			$cols = $modx->getDatabase()->numFields($this->ds);
131
-			for($i = 0; $i < $cols; $i++) $this->columns .= ($i ? "," : "") . $modx->getDatabase()->fieldName($this->ds, $i);
135
+			for($i = 0; $i < $cols; $i++) {
136
+			    $this->columns .= ($i ? "," : "") . $modx->getDatabase()->fieldName($this->ds, $i);
137
+			}
132 138
 		}
133 139
 
134 140
 		// start grid
@@ -207,7 +213,8 @@  discard block
 block discarded – undo
207 213
 
208 214
 	// format column values
209 215
 
210
-    public function RenderRowFnc($n, $row) {
216
+    public function RenderRowFnc($n, $row)
217
+    {
211 218
 		if($this->_alt == 0) {
212 219
 			$Style = $this->_itemStyle;
213 220
 			$Class = $this->_itemClass;
@@ -237,7 +244,8 @@  discard block
 block discarded – undo
237 244
 		return $o;
238 245
 	}
239 246
 
240
-    public function formatColumnValue($row, $value, $type, &$align) {
247
+    public function formatColumnValue($row, $value, $type, &$align)
248
+    {
241 249
 		if(strpos($type, ":") !== false) {
242 250
 			list($type, $type_format) = explode(":", $type, 2);
243 251
 		}
Please login to merge, or discard this patch.
manager/includes/src/Support/DataSetPager.php 4 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -33,6 +33,9 @@  discard block
 block discarded – undo
33 33
     public $renderPagerFncArgs;
34 34
     public static $dataSetPagerCnt;
35 35
 
36
+    /**
37
+     * @param boolean|string $id
38
+     */
36 39
     public function __construct($id, $ds, $pageSize = 10, $pageNumber = -1) {
37 40
 		global $_PAGE; // use view state object
38 41
 
@@ -77,6 +80,9 @@  discard block
 block discarded – undo
77 80
 		$this->pageSize = $ps;
78 81
 	}
79 82
 
83
+    /**
84
+     * @param DataGrid $fncName
85
+     */
80 86
     public function setRenderRowFnc($fncName, $args = "") {
81 87
 		$this->renderRowFnc = &$fncName;
82 88
 		$this->renderRowFncArgs = $args;    // extra agruments
Please login to merge, or discard this patch.
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -13,18 +13,18 @@  discard block
 block discarded – undo
13 13
 
14 14
 class DataSetPager implements DataSetPagerInterface{
15 15
 
16
-	public $ds; // datasource
16
+    public $ds; // datasource
17 17
     public $pageSize;
18 18
     public $pageNumber;
19 19
     public $rows;
20 20
     public $pager;
21 21
     public $id;
22 22
 
23
-	// normal page
23
+    // normal page
24 24
     public $pageStyle;
25 25
     public $pageClass;
26 26
 
27
-	// selected page
27
+    // selected page
28 28
     public $selPageStyle;
29 29
     public $selPageClass;
30 30
     public $renderRowFnc;
@@ -34,164 +34,164 @@  discard block
 block discarded – undo
34 34
     public static $dataSetPagerCnt;
35 35
 
36 36
     public function __construct($id, $ds, $pageSize = 10, $pageNumber = -1) {
37
-		global $_PAGE; // use view state object
38
-
39
-		// set id
40
-		self::$dataSetPagerCnt++;
41
-		$this->id = !empty($id) ? $id : "dsp" . self::$dataSetPagerCnt;
42
-
43
-		// get pagenumber
44
-		// by setting pager to -1 cause pager to load it's last page number
45
-		if($pageNumber == -1) {
46
-			$pageNumber = 1;
47
-			if(isset($_GET["dpgn" . $this->id])) {
48
-				$pageNumber = $_GET["dpgn" . $this->id];
49
-			} elseif(isset($_PAGE['vs'][$id . '_dpgn'])) {
50
-				$pageNumber = $_PAGE['vs'][$id . '_dpgn'];
51
-			}
52
-		}
53
-		if(!is_numeric($pageNumber)) {
54
-			$pageNumber = 1;
55
-		}
56
-
57
-		$this->ds = $ds; // datasource
58
-		$this->pageSize = $pageSize;
59
-		$this->pageNumber = $pageNumber;
60
-		$this->rows = '';
61
-		$this->pager = '';
62
-	}
37
+        global $_PAGE; // use view state object
38
+
39
+        // set id
40
+        self::$dataSetPagerCnt++;
41
+        $this->id = !empty($id) ? $id : "dsp" . self::$dataSetPagerCnt;
42
+
43
+        // get pagenumber
44
+        // by setting pager to -1 cause pager to load it's last page number
45
+        if($pageNumber == -1) {
46
+            $pageNumber = 1;
47
+            if(isset($_GET["dpgn" . $this->id])) {
48
+                $pageNumber = $_GET["dpgn" . $this->id];
49
+            } elseif(isset($_PAGE['vs'][$id . '_dpgn'])) {
50
+                $pageNumber = $_PAGE['vs'][$id . '_dpgn'];
51
+            }
52
+        }
53
+        if(!is_numeric($pageNumber)) {
54
+            $pageNumber = 1;
55
+        }
56
+
57
+        $this->ds = $ds; // datasource
58
+        $this->pageSize = $pageSize;
59
+        $this->pageNumber = $pageNumber;
60
+        $this->rows = '';
61
+        $this->pager = '';
62
+    }
63 63
 
64 64
     public function getRenderedPager() {
65
-		return $this->pager;
66
-	}
65
+        return $this->pager;
66
+    }
67 67
 
68 68
     public function getRenderedRows() {
69
-		return $this->rows;
70
-	}
69
+        return $this->rows;
70
+    }
71 71
 
72 72
     public function setDataSource($ds) {
73
-		$this->ds = $ds;
74
-	}
73
+        $this->ds = $ds;
74
+    }
75 75
 
76 76
     public function setPageSize($ps) {
77
-		$this->pageSize = $ps;
78
-	}
77
+        $this->pageSize = $ps;
78
+    }
79 79
 
80 80
     public function setRenderRowFnc($fncName, $args = "") {
81
-		$this->renderRowFnc = &$fncName;
82
-		$this->renderRowFncArgs = $args;    // extra agruments
81
+        $this->renderRowFnc = &$fncName;
82
+        $this->renderRowFncArgs = $args;    // extra agruments
83 83
 
84 84
 
85
-	}
85
+    }
86 86
 
87 87
     public function setRenderPagerFnc($fncName, $args = "") {
88
-		$this->renderPagerFnc = $fncName;
89
-		$this->renderPagerFncArgs = $args;    // extra agruments
90
-	}
88
+        $this->renderPagerFnc = $fncName;
89
+        $this->renderPagerFncArgs = $args;    // extra agruments
90
+    }
91 91
 
92 92
     public function render() {
93
-		$modx = evolutionCMS(); global $_PAGE;
94
-
95
-		$isDataset = $modx->getDatabase()->isResult($this->ds);
96
-
97
-		if(!$this->selPageStyle) {
98
-			$this->selPageStyle = "font-weight:bold";
99
-		}
100
-
101
-		// get total number of rows
102
-		$tnr = ($isDataset) ? $modx->getDatabase()->getRecordCount($this->ds) : count($this->ds);
103
-
104
-		// render: no records found
105
-		if($tnr <= 0) {
106
-			$fnc = $this->renderRowFnc;
107
-			$args = $this->renderRowFncArgs;
108
-			if(isset($fnc)) {
109
-				if($args != "") {
110
-					$this->rows .= $fnc(0, null, $args);
111
-				} // if agrs was specified then we will pass three params
112
-				else {
113
-					$this->rows .= $fnc(0, null);
114
-				}                 // otherwise two will be passed
115
-			}
116
-			return;
117
-		}
118
-
119
-		// get total pages
120
-		$tp = ceil($tnr / $this->pageSize);
121
-		if($this->pageNumber > $tp) {
122
-			$this->pageNumber = 1;
123
-		}
124
-
125
-		// get page number
126
-		$p = $this->pageNumber;
127
-
128
-		// save page number to view state if available
129
-		if(isset($_PAGE['vs'])) {
130
-			$_PAGE['vs'][$this->id . '_dpgn'] = $p;
131
-		}
132
-
133
-		// render pager : renderPagerFnc($cuurentPage,$pagerNumber,$arguments="");
134
-		if($tp > 1) {
135
-		    $url = '';
136
-			$fnc = $this->renderPagerFnc;
137
-			$args = $this->renderPagerFncArgs;
138
-			if(!isset($fnc)) {
139
-				if($modx->isFrontend()) {
140
-					$url = $modx->makeUrl($modx->documentIdentifier, '', '', 'full') . '?';
141
-				} else {
142
-					$url = $_SERVER['PHP_SELF'] . '?';
143
-				}
144
-				$i = 0;
145
-				foreach($_GET as $n => $v) if($n != 'dpgn' . $this->id) {
146
-					$i++;
147
-					$url .= (($i > 1) ? "&" : "") . "$n=$v";
148
-				}
149
-				if($i >= 1) {
150
-					$url .= "&";
151
-				}
152
-			}
153
-			for($i = 1; $i <= $tp; $i++) {
154
-				if(isset($fnc)) {
155
-					if($args != "") {
156
-						$this->pager .= $fnc($p, $i, $args);
157
-					} else {
158
-						$this->pager .= $fnc($p, $i);
159
-					}
160
-				} else {
161
-					$this->pager .= ($p == $i) ? " <span class='" . $this->selPageClass . "' style='" . $this->selPageStyle . "'>$i</span> " : " <a href='" . $url . "dpgn" . $this->id . "=$i' class='" . $this->pageClass . "' style='" . $this->pageStyle . "'>$i</a> ";
162
-				}
163
-			}
164
-		}
165
-
166
-		// render row : renderRowFnc($rowNumber,$row,$arguments="")
167
-		$fnc = $this->renderRowFnc;
168
-		$args = $this->renderRowFncArgs;
169
-
170
-		if(isset($fnc)) {
171
-			$i = 1;
172
-			$fncObject = is_object($fnc);
173
-			$minitems = (($p - 1) * $this->pageSize) + 1;
174
-			$maxitems = (($p - 1) * $this->pageSize) + $this->pageSize;
175
-			while($i <= $maxitems && ($row = ($isDataset) ? $modx->getDatabase()->getRow($this->ds) : $this->ds[$i - 1])) {
176
-				if($i >= $minitems && $i <= $maxitems) {
177
-					if($fncObject) {
178
-						if($args != "") {
179
-							$this->rows .= $fnc->RenderRowFnc($i, $row, $args);
180
-						} else {
181
-							$this->rows .= $fnc->RenderRowFnc($i, $row);
182
-						}
183
-					} else {
184
-						if($args != "") {
185
-							$this->rows .= $fnc($i, $row, $args);
186
-						} // if agrs was specified then we wil pass three params
187
-						else {
188
-							$this->rows .= $fnc($i, $row);
189
-						}                 // otherwise two will be passed
190
-					}
191
-
192
-				}
193
-				$i++;
194
-			}
195
-		}
196
-	}
93
+        $modx = evolutionCMS(); global $_PAGE;
94
+
95
+        $isDataset = $modx->getDatabase()->isResult($this->ds);
96
+
97
+        if(!$this->selPageStyle) {
98
+            $this->selPageStyle = "font-weight:bold";
99
+        }
100
+
101
+        // get total number of rows
102
+        $tnr = ($isDataset) ? $modx->getDatabase()->getRecordCount($this->ds) : count($this->ds);
103
+
104
+        // render: no records found
105
+        if($tnr <= 0) {
106
+            $fnc = $this->renderRowFnc;
107
+            $args = $this->renderRowFncArgs;
108
+            if(isset($fnc)) {
109
+                if($args != "") {
110
+                    $this->rows .= $fnc(0, null, $args);
111
+                } // if agrs was specified then we will pass three params
112
+                else {
113
+                    $this->rows .= $fnc(0, null);
114
+                }                 // otherwise two will be passed
115
+            }
116
+            return;
117
+        }
118
+
119
+        // get total pages
120
+        $tp = ceil($tnr / $this->pageSize);
121
+        if($this->pageNumber > $tp) {
122
+            $this->pageNumber = 1;
123
+        }
124
+
125
+        // get page number
126
+        $p = $this->pageNumber;
127
+
128
+        // save page number to view state if available
129
+        if(isset($_PAGE['vs'])) {
130
+            $_PAGE['vs'][$this->id . '_dpgn'] = $p;
131
+        }
132
+
133
+        // render pager : renderPagerFnc($cuurentPage,$pagerNumber,$arguments="");
134
+        if($tp > 1) {
135
+            $url = '';
136
+            $fnc = $this->renderPagerFnc;
137
+            $args = $this->renderPagerFncArgs;
138
+            if(!isset($fnc)) {
139
+                if($modx->isFrontend()) {
140
+                    $url = $modx->makeUrl($modx->documentIdentifier, '', '', 'full') . '?';
141
+                } else {
142
+                    $url = $_SERVER['PHP_SELF'] . '?';
143
+                }
144
+                $i = 0;
145
+                foreach($_GET as $n => $v) if($n != 'dpgn' . $this->id) {
146
+                    $i++;
147
+                    $url .= (($i > 1) ? "&" : "") . "$n=$v";
148
+                }
149
+                if($i >= 1) {
150
+                    $url .= "&";
151
+                }
152
+            }
153
+            for($i = 1; $i <= $tp; $i++) {
154
+                if(isset($fnc)) {
155
+                    if($args != "") {
156
+                        $this->pager .= $fnc($p, $i, $args);
157
+                    } else {
158
+                        $this->pager .= $fnc($p, $i);
159
+                    }
160
+                } else {
161
+                    $this->pager .= ($p == $i) ? " <span class='" . $this->selPageClass . "' style='" . $this->selPageStyle . "'>$i</span> " : " <a href='" . $url . "dpgn" . $this->id . "=$i' class='" . $this->pageClass . "' style='" . $this->pageStyle . "'>$i</a> ";
162
+                }
163
+            }
164
+        }
165
+
166
+        // render row : renderRowFnc($rowNumber,$row,$arguments="")
167
+        $fnc = $this->renderRowFnc;
168
+        $args = $this->renderRowFncArgs;
169
+
170
+        if(isset($fnc)) {
171
+            $i = 1;
172
+            $fncObject = is_object($fnc);
173
+            $minitems = (($p - 1) * $this->pageSize) + 1;
174
+            $maxitems = (($p - 1) * $this->pageSize) + $this->pageSize;
175
+            while($i <= $maxitems && ($row = ($isDataset) ? $modx->getDatabase()->getRow($this->ds) : $this->ds[$i - 1])) {
176
+                if($i >= $minitems && $i <= $maxitems) {
177
+                    if($fncObject) {
178
+                        if($args != "") {
179
+                            $this->rows .= $fnc->RenderRowFnc($i, $row, $args);
180
+                        } else {
181
+                            $this->rows .= $fnc->RenderRowFnc($i, $row);
182
+                        }
183
+                    } else {
184
+                        if($args != "") {
185
+                            $this->rows .= $fnc($i, $row, $args);
186
+                        } // if agrs was specified then we wil pass three params
187
+                        else {
188
+                            $this->rows .= $fnc($i, $row);
189
+                        }                 // otherwise two will be passed
190
+                    }
191
+
192
+                }
193
+                $i++;
194
+            }
195
+        }
196
+    }
197 197
 }
Please login to merge, or discard this patch.
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -33,24 +33,24 @@  discard block
 block discarded – undo
33 33
     public $renderPagerFncArgs;
34 34
     public static $dataSetPagerCnt;
35 35
 
36
-    public function __construct($id, $ds, $pageSize = 10, $pageNumber = -1) {
36
+    public function __construct($id, $ds, $pageSize = 10, $pageNumber = -1){
37 37
 		global $_PAGE; // use view state object
38 38
 
39 39
 		// set id
40 40
 		self::$dataSetPagerCnt++;
41
-		$this->id = !empty($id) ? $id : "dsp" . self::$dataSetPagerCnt;
41
+		$this->id = !empty($id) ? $id : "dsp".self::$dataSetPagerCnt;
42 42
 
43 43
 		// get pagenumber
44 44
 		// by setting pager to -1 cause pager to load it's last page number
45
-		if($pageNumber == -1) {
45
+		if ($pageNumber == -1) {
46 46
 			$pageNumber = 1;
47
-			if(isset($_GET["dpgn" . $this->id])) {
48
-				$pageNumber = $_GET["dpgn" . $this->id];
49
-			} elseif(isset($_PAGE['vs'][$id . '_dpgn'])) {
50
-				$pageNumber = $_PAGE['vs'][$id . '_dpgn'];
47
+			if (isset($_GET["dpgn".$this->id])) {
48
+				$pageNumber = $_GET["dpgn".$this->id];
49
+			} elseif (isset($_PAGE['vs'][$id.'_dpgn'])) {
50
+				$pageNumber = $_PAGE['vs'][$id.'_dpgn'];
51 51
 			}
52 52
 		}
53
-		if(!is_numeric($pageNumber)) {
53
+		if (!is_numeric($pageNumber)) {
54 54
 			$pageNumber = 1;
55 55
 		}
56 56
 
@@ -61,40 +61,40 @@  discard block
 block discarded – undo
61 61
 		$this->pager = '';
62 62
 	}
63 63
 
64
-    public function getRenderedPager() {
64
+    public function getRenderedPager(){
65 65
 		return $this->pager;
66 66
 	}
67 67
 
68
-    public function getRenderedRows() {
68
+    public function getRenderedRows(){
69 69
 		return $this->rows;
70 70
 	}
71 71
 
72
-    public function setDataSource($ds) {
72
+    public function setDataSource($ds){
73 73
 		$this->ds = $ds;
74 74
 	}
75 75
 
76
-    public function setPageSize($ps) {
76
+    public function setPageSize($ps){
77 77
 		$this->pageSize = $ps;
78 78
 	}
79 79
 
80
-    public function setRenderRowFnc($fncName, $args = "") {
80
+    public function setRenderRowFnc($fncName, $args = ""){
81 81
 		$this->renderRowFnc = &$fncName;
82
-		$this->renderRowFncArgs = $args;    // extra agruments
82
+		$this->renderRowFncArgs = $args; // extra agruments
83 83
 
84 84
 
85 85
 	}
86 86
 
87
-    public function setRenderPagerFnc($fncName, $args = "") {
87
+    public function setRenderPagerFnc($fncName, $args = ""){
88 88
 		$this->renderPagerFnc = $fncName;
89
-		$this->renderPagerFncArgs = $args;    // extra agruments
89
+		$this->renderPagerFncArgs = $args; // extra agruments
90 90
 	}
91 91
 
92
-    public function render() {
92
+    public function render(){
93 93
 		$modx = evolutionCMS(); global $_PAGE;
94 94
 
95 95
 		$isDataset = $modx->getDatabase()->isResult($this->ds);
96 96
 
97
-		if(!$this->selPageStyle) {
97
+		if (!$this->selPageStyle) {
98 98
 			$this->selPageStyle = "font-weight:bold";
99 99
 		}
100 100
 
@@ -102,11 +102,11 @@  discard block
 block discarded – undo
102 102
 		$tnr = ($isDataset) ? $modx->getDatabase()->getRecordCount($this->ds) : count($this->ds);
103 103
 
104 104
 		// render: no records found
105
-		if($tnr <= 0) {
105
+		if ($tnr <= 0) {
106 106
 			$fnc = $this->renderRowFnc;
107 107
 			$args = $this->renderRowFncArgs;
108
-			if(isset($fnc)) {
109
-				if($args != "") {
108
+			if (isset($fnc)) {
109
+				if ($args != "") {
110 110
 					$this->rows .= $fnc(0, null, $args);
111 111
 				} // if agrs was specified then we will pass three params
112 112
 				else {
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 
119 119
 		// get total pages
120 120
 		$tp = ceil($tnr / $this->pageSize);
121
-		if($this->pageNumber > $tp) {
121
+		if ($this->pageNumber > $tp) {
122 122
 			$this->pageNumber = 1;
123 123
 		}
124 124
 
@@ -126,39 +126,39 @@  discard block
 block discarded – undo
126 126
 		$p = $this->pageNumber;
127 127
 
128 128
 		// save page number to view state if available
129
-		if(isset($_PAGE['vs'])) {
130
-			$_PAGE['vs'][$this->id . '_dpgn'] = $p;
129
+		if (isset($_PAGE['vs'])) {
130
+			$_PAGE['vs'][$this->id.'_dpgn'] = $p;
131 131
 		}
132 132
 
133 133
 		// render pager : renderPagerFnc($cuurentPage,$pagerNumber,$arguments="");
134
-		if($tp > 1) {
134
+		if ($tp > 1) {
135 135
 		    $url = '';
136 136
 			$fnc = $this->renderPagerFnc;
137 137
 			$args = $this->renderPagerFncArgs;
138
-			if(!isset($fnc)) {
139
-				if($modx->isFrontend()) {
140
-					$url = $modx->makeUrl($modx->documentIdentifier, '', '', 'full') . '?';
138
+			if (!isset($fnc)) {
139
+				if ($modx->isFrontend()) {
140
+					$url = $modx->makeUrl($modx->documentIdentifier, '', '', 'full').'?';
141 141
 				} else {
142
-					$url = $_SERVER['PHP_SELF'] . '?';
142
+					$url = $_SERVER['PHP_SELF'].'?';
143 143
 				}
144 144
 				$i = 0;
145
-				foreach($_GET as $n => $v) if($n != 'dpgn' . $this->id) {
145
+				foreach ($_GET as $n => $v) if ($n != 'dpgn'.$this->id) {
146 146
 					$i++;
147
-					$url .= (($i > 1) ? "&" : "") . "$n=$v";
147
+					$url .= (($i > 1) ? "&" : "")."$n=$v";
148 148
 				}
149
-				if($i >= 1) {
149
+				if ($i >= 1) {
150 150
 					$url .= "&";
151 151
 				}
152 152
 			}
153
-			for($i = 1; $i <= $tp; $i++) {
154
-				if(isset($fnc)) {
155
-					if($args != "") {
153
+			for ($i = 1; $i <= $tp; $i++) {
154
+				if (isset($fnc)) {
155
+					if ($args != "") {
156 156
 						$this->pager .= $fnc($p, $i, $args);
157 157
 					} else {
158 158
 						$this->pager .= $fnc($p, $i);
159 159
 					}
160 160
 				} else {
161
-					$this->pager .= ($p == $i) ? " <span class='" . $this->selPageClass . "' style='" . $this->selPageStyle . "'>$i</span> " : " <a href='" . $url . "dpgn" . $this->id . "=$i' class='" . $this->pageClass . "' style='" . $this->pageStyle . "'>$i</a> ";
161
+					$this->pager .= ($p == $i) ? " <span class='".$this->selPageClass."' style='".$this->selPageStyle."'>$i</span> " : " <a href='".$url."dpgn".$this->id."=$i' class='".$this->pageClass."' style='".$this->pageStyle."'>$i</a> ";
162 162
 				}
163 163
 			}
164 164
 		}
@@ -167,21 +167,21 @@  discard block
 block discarded – undo
167 167
 		$fnc = $this->renderRowFnc;
168 168
 		$args = $this->renderRowFncArgs;
169 169
 
170
-		if(isset($fnc)) {
170
+		if (isset($fnc)) {
171 171
 			$i = 1;
172 172
 			$fncObject = is_object($fnc);
173 173
 			$minitems = (($p - 1) * $this->pageSize) + 1;
174 174
 			$maxitems = (($p - 1) * $this->pageSize) + $this->pageSize;
175
-			while($i <= $maxitems && ($row = ($isDataset) ? $modx->getDatabase()->getRow($this->ds) : $this->ds[$i - 1])) {
176
-				if($i >= $minitems && $i <= $maxitems) {
177
-					if($fncObject) {
178
-						if($args != "") {
175
+			while ($i <= $maxitems && ($row = ($isDataset) ? $modx->getDatabase()->getRow($this->ds) : $this->ds[$i - 1])) {
176
+				if ($i >= $minitems && $i <= $maxitems) {
177
+					if ($fncObject) {
178
+						if ($args != "") {
179 179
 							$this->rows .= $fnc->RenderRowFnc($i, $row, $args);
180 180
 						} else {
181 181
 							$this->rows .= $fnc->RenderRowFnc($i, $row);
182 182
 						}
183 183
 					} else {
184
-						if($args != "") {
184
+						if ($args != "") {
185 185
 							$this->rows .= $fnc($i, $row, $args);
186 186
 						} // if agrs was specified then we wil pass three params
187 187
 						else {
Please login to merge, or discard this patch.
Braces   +21 added lines, -10 removed lines patch added patch discarded remove patch
@@ -11,7 +11,8 @@  discard block
 block discarded – undo
11 11
 # -----------------------------------------
12 12
 #
13 13
 
14
-class DataSetPager implements DataSetPagerInterface{
14
+class DataSetPager implements DataSetPagerInterface
15
+{
15 16
 
16 17
 	public $ds; // datasource
17 18
     public $pageSize;
@@ -33,7 +34,8 @@  discard block
 block discarded – undo
33 34
     public $renderPagerFncArgs;
34 35
     public static $dataSetPagerCnt;
35 36
 
36
-    public function __construct($id, $ds, $pageSize = 10, $pageNumber = -1) {
37
+    public function __construct($id, $ds, $pageSize = 10, $pageNumber = -1)
38
+    {
37 39
 		global $_PAGE; // use view state object
38 40
 
39 41
 		// set id
@@ -61,35 +63,42 @@  discard block
 block discarded – undo
61 63
 		$this->pager = '';
62 64
 	}
63 65
 
64
-    public function getRenderedPager() {
66
+    public function getRenderedPager()
67
+    {
65 68
 		return $this->pager;
66 69
 	}
67 70
 
68
-    public function getRenderedRows() {
71
+    public function getRenderedRows()
72
+    {
69 73
 		return $this->rows;
70 74
 	}
71 75
 
72
-    public function setDataSource($ds) {
76
+    public function setDataSource($ds)
77
+    {
73 78
 		$this->ds = $ds;
74 79
 	}
75 80
 
76
-    public function setPageSize($ps) {
81
+    public function setPageSize($ps)
82
+    {
77 83
 		$this->pageSize = $ps;
78 84
 	}
79 85
 
80
-    public function setRenderRowFnc($fncName, $args = "") {
86
+    public function setRenderRowFnc($fncName, $args = "")
87
+    {
81 88
 		$this->renderRowFnc = &$fncName;
82 89
 		$this->renderRowFncArgs = $args;    // extra agruments
83 90
 
84 91
 
85 92
 	}
86 93
 
87
-    public function setRenderPagerFnc($fncName, $args = "") {
94
+    public function setRenderPagerFnc($fncName, $args = "")
95
+    {
88 96
 		$this->renderPagerFnc = $fncName;
89 97
 		$this->renderPagerFncArgs = $args;    // extra agruments
90 98
 	}
91 99
 
92
-    public function render() {
100
+    public function render()
101
+    {
93 102
 		$modx = evolutionCMS(); global $_PAGE;
94 103
 
95 104
 		$isDataset = $modx->getDatabase()->isResult($this->ds);
@@ -142,8 +151,10 @@  discard block
 block discarded – undo
142 151
 					$url = $_SERVER['PHP_SELF'] . '?';
143 152
 				}
144 153
 				$i = 0;
145
-				foreach($_GET as $n => $v) if($n != 'dpgn' . $this->id) {
154
+				foreach($_GET as $n => $v) {
155
+				    if($n != 'dpgn' . $this->id) {
146 156
 					$i++;
157
+				}
147 158
 					$url .= (($i > 1) ? "&" : "") . "$n=$v";
148 159
 				}
149 160
 				if($i >= 1) {
Please login to merge, or discard this patch.
install/index.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -3,13 +3,13 @@  discard block
 block discarded – undo
3 3
  * EVO Installer
4 4
  */
5 5
 error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);
6
-$base_path = dirname(__DIR__) . '/';
6
+$base_path = dirname(__DIR__).'/';
7 7
 
8
-if (is_file($base_path . 'assets/cache/siteManager.php')) {
9
-    include_once $base_path . 'assets/cache/siteManager.php';
8
+if (is_file($base_path.'assets/cache/siteManager.php')) {
9
+    include_once $base_path.'assets/cache/siteManager.php';
10 10
 }
11
-if (! defined('MGR_DIR')) {
12
-    if (is_dir($base_path . 'manager')) {
11
+if (!defined('MGR_DIR')) {
12
+    if (is_dir($base_path.'manager')) {
13 13
         define('MGR_DIR', 'manager');
14 14
     } else {
15 15
         die('MGR_DIR is not defined');
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 require_once 'src/functions.php';
20 20
 
21 21
 if (empty($_GET['self'])) {
22
-    require_once '../' . MGR_DIR . '/includes/version.inc.php';
22
+    require_once '../'.MGR_DIR.'/includes/version.inc.php';
23 23
 
24 24
     // start session
25 25
     session_start();
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
     install_sessionCheck();
28 28
 
29 29
     $moduleName = 'EVO';
30
-    $moduleVersion = $modx_branch . ' ' . $modx_version;
30
+    $moduleVersion = $modx_branch.' '.$modx_version;
31 31
     $moduleRelease = $modx_release_date;
32 32
     $moduleSQLBaseFile = 'stubs/sql/setup.sql';
33 33
     $moduleSQLDataFile = 'stubs/sql/setup.data.sql';
@@ -68,8 +68,8 @@  discard block
 block discarded – undo
68 68
     $action = isset($_GET['action']) ? trim(strip_tags($_GET['action'])) : 'language';
69 69
     str_replace('.', '', $action);
70 70
 
71
-    $controller = 'src/controllers/' . $action . '.php';
72
-    if (! file_exists($controller)) {
71
+    $controller = 'src/controllers/'.$action.'.php';
72
+    if (!file_exists($controller)) {
73 73
         die("Invalid install action attempted. [action={$action}]");
74 74
     }
75 75
     require $controller;
@@ -81,8 +81,8 @@  discard block
 block discarded – undo
81 81
 } else {
82 82
     $action = isset($_GET['action']) && is_scalar($_GET['action']) ? trim($_GET['action']) : 'language';
83 83
     str_replace('.', '', $action);
84
-    $controller = 'src/controllers/' . $action . '.php';
85
-    if (! file_exists($controller)) {
84
+    $controller = 'src/controllers/'.$action.'.php';
85
+    if (!file_exists($controller)) {
86 86
         die("Invalid install action attempted. [action={$action}]");
87 87
     }
88 88
     require $controller;
Please login to merge, or discard this patch.
manager/includes/secure_mgr_documents.inc.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -20,14 +20,14 @@
 block discarded – undo
20 20
         ($docid > 0 ? "id='$docid'" : "privatemgr = 1"));
21 21
     $rs = $modx->getDatabase()->select(
22 22
         'DISTINCT sc.id',
23
-        $modx->getFullTableName("site_content") . " sc
24
-			LEFT JOIN " . $modx->getFullTableName("document_groups") . " dg ON dg.document = sc.id
25
-			LEFT JOIN " . $modx->getFullTableName("membergroup_access") . " mga ON mga.documentgroup = dg.document_group",
26
-        ($docid > 0 ? " sc.id='{$docid}' AND " : "") . "mga.id>0"
23
+        $modx->getFullTableName("site_content")." sc
24
+			LEFT JOIN " . $modx->getFullTableName("document_groups")." dg ON dg.document = sc.id
25
+			LEFT JOIN " . $modx->getFullTableName("membergroup_access")." mga ON mga.documentgroup = dg.document_group",
26
+        ($docid > 0 ? " sc.id='{$docid}' AND " : "")."mga.id>0"
27 27
     );
28 28
     $ids = $modx->getDatabase()->getColumn("id", $rs);
29 29
     if (count($ids) > 0) {
30 30
         $modx->getDatabase()->update('privatemgr = 1', $modx->getFullTableName("site_content"),
31
-            "id IN (" . implode(", ", $ids) . ")");
31
+            "id IN (".implode(", ", $ids).")");
32 32
     }
33 33
 }
Please login to merge, or discard this patch.
manager/includes/user_settings.inc.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@
 block discarded – undo
14 14
 if (!empty($user_id)) {
15 15
     // Raymond: grab the user settings from the database.
16 16
     $rs = $modx->getDatabase()->select('setting_name, setting_value', $modx->getFullTableName('user_settings'),
17
-        "user=" . $modx->getLoginUserID());
17
+        "user=".$modx->getLoginUserID());
18 18
 
19 19
     $which_browser_default = $which_browser;
20 20
     while ($row = $modx->getDatabase()->getRow($rs)) {
Please login to merge, or discard this patch.
manager/includes/secure_web_documents.inc.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -20,14 +20,14 @@
 block discarded – undo
20 20
         ($docid > 0 ? "id='$docid'" : "privateweb = 1"));
21 21
     $rs = $modx->getDatabase()->select(
22 22
         'DISTINCT sc.id',
23
-        $modx->getFullTableName("site_content") . " sc
24
-			LEFT JOIN " . $modx->getFullTableName("document_groups") . " dg ON dg.document = sc.id
25
-			LEFT JOIN " . $modx->getFullTableName("webgroup_access") . " wga ON wga.documentgroup = dg.document_group",
26
-        ($docid > 0 ? " sc.id='{$docid}' AND " : "") . "wga.id>0"
23
+        $modx->getFullTableName("site_content")." sc
24
+			LEFT JOIN " . $modx->getFullTableName("document_groups")." dg ON dg.document = sc.id
25
+			LEFT JOIN " . $modx->getFullTableName("webgroup_access")." wga ON wga.documentgroup = dg.document_group",
26
+        ($docid > 0 ? " sc.id='{$docid}' AND " : "")."wga.id>0"
27 27
     );
28 28
     $ids = $modx->getDatabase()->getColumn("id", $rs);
29 29
     if (count($ids) > 0) {
30 30
         $modx->getDatabase()->update('privateweb = 1', $modx->getFullTableName("site_content"),
31
-            "id IN (" . implode(", ", $ids) . ")");
31
+            "id IN (".implode(", ", $ids).")");
32 32
     }
33 33
 }
Please login to merge, or discard this patch.