Completed
Push — master ( 0cdf32...8a5449 )
by Agel_Nash
02:54
created
assets/snippets/DLUsers/src/Actions.php 5 patches
Unused Use Statements   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,10 @@
 block discarded – undo
6 6
 include_once(MODX_BASE_PATH . 'assets/snippets/DocLister/lib/DLTemplate.class.php');
7 7
 include_once(MODX_BASE_PATH . 'assets/snippets/DocLister/lib/DLCollection.class.php');
8 8
 
9
-use APIHelpers, DocumentParser, DLCollection, DLTemplate;
9
+use APIHelpers;
10
+use DocumentParser;
11
+use DLCollection;
12
+use DLTemplate;
10 13
 use Helpers\FS;
11 14
 
12 15
 class Actions{
Please login to merge, or discard this patch.
Doc Comments   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -50,6 +50,8 @@  discard block
 block discarded – undo
50 50
     /**
51 51
      * is not allowed to call from outside: private!
52 52
      *
53
+     * @param string $userClass
54
+     * @param boolean $debug
53 55
      */
54 56
     private function __construct(DocumentParser $modx, $userClass, $debug)
55 57
     {
@@ -285,9 +287,9 @@  discard block
 block discarded – undo
285 287
      * @param $emailField
286 288
      * @param $rememberField
287 289
      * @param $backUrl
288
-     * @param $method
289
-     * @param $error
290
-     * @param $errorCode
290
+     * @param string $method
291
+     * @param string $error
292
+     * @param string $errorCode
291 293
      * @param array $params
292 294
      * @return array
293 295
      */
@@ -468,7 +470,7 @@  discard block
 block discarded – undo
468 470
 	}
469 471
 
470 472
     /**
471
-     * @param $name
473
+     * @param string $name
472 474
      * @return string
473 475
      */
474 476
     protected function getTemplate($name){
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -235,7 +235,7 @@
 block discarded – undo
235 235
              */
236 236
             $refer = htmlspecialchars_decode($_SERVER['HTTP_REFERER'], ENT_QUOTES);
237 237
         } else {
238
-             $refer = $this->getBackUrl($request);
238
+                $refer = $this->getBackUrl($request);
239 239
         }
240 240
 
241 241
         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
     public function logout($params)
98 98
     {
99 99
         $LogoutName = APIHelpers::getkey($params, 'LogoutName', 'logout');
100
-        if (is_scalar($LogoutName) && !empty($LogoutName) && isset($_GET[$LogoutName])) {
100
+        if (is_scalar($LogoutName) && ! empty($LogoutName) && isset($_GET[$LogoutName])) {
101 101
             $userID = $this->UserID('web');
102 102
             if ($userID) {
103 103
                 $this->userObj->edit($userID);
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
             $dataTPL = $this->userObj->toArray();
178 178
             $dataTPL['url.logout'] = $this->logoutUrl($params);
179 179
             $homeID = APIHelpers::getkey($params, 'homeID');
180
-            if (!empty($homeID)) {
180
+            if ( ! empty($homeID)) {
181 181
                 $dataTPL['url.profile'] = $this->makeUrl($homeID);
182 182
             }
183 183
         } else {
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
                 'errorCode'  => $errorCode
198 198
             );
199 199
             $authId = APIHelpers::getkey($params, 'authId');
200
-            if (!empty($authId)) {
200
+            if ( ! empty($authId)) {
201 201
                 $dataTPL['authPage'] = $this->makeUrl($authId);
202 202
                 $dataTPL['method'] = strtolower(__CLASS__ . '::' . 'authpage');
203 203
             }
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
         }
229 229
 
230 230
         $request = parse_url($_SERVER['REQUEST_URI']);
231
-        if (!empty($_SERVER['HTTP_REFERER'])) {
231
+        if ( ! empty($_SERVER['HTTP_REFERER'])) {
232 232
             /**
233 233
              * Thank you for super protection against hacking in protect.inc.php:-)
234 234
              */
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 
240 240
         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
241 241
             $backUrl = APIHelpers::getkey($_POST, 'backUrl', $POST['backUrl']);
242
-            if (!is_scalar($backUrl)) {
242
+            if ( ! is_scalar($backUrl)) {
243 243
                 $backUrl = $refer;
244 244
             } else {
245 245
                 $backUrl = urldecode($backUrl);
@@ -248,12 +248,12 @@  discard block
 block discarded – undo
248 248
             $backUrl = $refer;
249 249
         }
250 250
         $backUrl = parse_url($backUrl);
251
-        if (!empty($backUrl['path']) && $request['path'] != $backUrl['path']) {
251
+        if ( ! empty($backUrl['path']) && $request['path'] != $backUrl['path']) {
252 252
             $POST['backUrl'] = $backUrl['path'];
253 253
         } else {
254 254
             $POST['backUrl'] = $this->getBackUrl($backUrl);
255 255
         }
256
-        if (!empty($POST['backUrl'])) {
256
+        if ( ! empty($POST['backUrl'])) {
257 257
             $idURL = $this->moveTo(array(
258 258
                 'url'      => '/' . ltrim($POST['backUrl'], '/'),
259 259
                 'validate' => true
@@ -285,11 +285,11 @@  discard block
 block discarded – undo
285 285
      * @param array $request
286 286
      * @return string
287 287
      */
288
-    protected function getBackUrl(array $request = array()){
288
+    protected function getBackUrl(array $request = array()) {
289 289
         $selfHost = rtrim(str_replace("http://", "", $this->config['site_url']), '/');
290 290
         if (empty($request['host']) || $request['host'] == $selfHost) {
291
-            $query = !empty($request['query']) ? '?' . $request['query'] : '';
292
-            $out = !empty($request['path']) ? $request['path'] . $query : '';
291
+            $query = ! empty($request['query']) ? '?' . $request['query'] : '';
292
+            $out = ! empty($request['path']) ? $request['path'] . $query : '';
293 293
         } else {
294 294
             $out = '';
295 295
         }
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
                 'email'    => APIHelpers::getkey($_POST, $emailField, ''),
328 328
                 'remember' => (bool)((int)APIHelpers::getkey($_POST, $rememberField, 0))
329 329
             ));
330
-            if (!empty($POST['email']) && is_scalar($POST['email']) && !$userObj->emailValidate($POST['email'],
330
+            if ( ! empty($POST['email']) && is_scalar($POST['email']) && ! $userObj->emailValidate($POST['email'],
331 331
                     false)
332 332
             ) {
333 333
                 $userObj->edit($POST['email']);
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
                     "rememberme"   => $POST['remember'],
339 339
                     'userObj'      => $userObj
340 340
                 ));
341
-                if ($userObj->getID() && !$userObj->checkBlock($userObj->getID())) {
341
+                if ($userObj->getID() && ! $userObj->checkBlock($userObj->getID())) {
342 342
                     $pluginFlag = $this->modx->invokeEvent("OnWebAuthentication", array(
343 343
                         "userid"        => $userObj->getID(),
344 344
                         "username"      => $userObj->get('username'),
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
                 $POST['email'] = '';
378 378
             }
379 379
         }
380
-        if (!empty($error)) {
380
+        if ( ! empty($error)) {
381 381
             $errorCode = $error;
382 382
             $error = APIHelpers::getkey($params, $error, '');
383 383
             $error = static::getLangMsg($error, $error);
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
      */
427 427
     public function isGuestGoHome($params)
428 428
     {
429
-        if (!$this->UserID('web')) {
429
+        if ( ! $this->UserID('web')) {
430 430
             /**
431 431
              * @see : http://modx.im/blog/triks/105.html
432 432
              */
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
     {
463 463
         $id = (int)APIHelpers::getkey($params, 'id', 0);
464 464
         $uri = APIHelpers::getkey($params, 'url', '');
465
-        if ((empty($uri) && !empty($id)) || !is_string($uri)) {
465
+        if ((empty($uri) && ! empty($id)) || ! is_string($uri)) {
466 466
             $uri = $this->makeUrl($id);
467 467
         }
468 468
         $code = (int)APIHelpers::getkey($params, 'code', 0);
@@ -530,10 +530,10 @@  discard block
 block discarded – undo
530 530
     protected static function loadLang($lang)
531 531
     {
532 532
         $file = dirname(dirname(__FILE__)) . '/lang/' . $lang . '.php';
533
-        if (!FS::getInstance()->checkFile($file)) {
533
+        if ( ! FS::getInstance()->checkFile($file)) {
534 534
             $file = false;
535 535
         }
536
-        if (!empty($lang) && !isset(static::$langDic[$lang]) && !empty($file)) {
536
+        if ( ! empty($lang) && ! isset(static::$langDic[$lang]) && ! empty($file)) {
537 537
             static::$langDic[$lang] = include_once($file);
538 538
             if (is_array(static::$langDic[$lang])) {
539 539
                 static::$langDic[$lang] = APIHelpers::renameKeyArr(static::$langDic[$lang], $lang);
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
             }
543 543
         }
544 544
 
545
-        return !(empty($lang) || empty(static::$langDic[$lang]));
545
+        return ! (empty($lang) || empty(static::$langDic[$lang]));
546 546
     }
547 547
 
548 548
     /**
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
         }
561 561
         if (class_exists('evoBabel', false) && isset(self::$instance->modx->snippetCache['lang'])) {
562 562
             $msg = self::$instance->modx->runSnippet('lang', array('a' => 'DLUsers.' . $key));
563
-            if (!empty($msg)) {
563
+            if ( ! empty($msg)) {
564 564
                 $out = $msg;
565 565
             }
566 566
         }
Please login to merge, or discard this patch.
Braces   +101 added lines, -100 removed lines patch added patch discarded remove patch
@@ -13,8 +13,8 @@  discard block
 block discarded – undo
13 13
  * Class Actions
14 14
  * @package DLUsers
15 15
  */
16
-class Actions
17
-{
16
+class Actions
17
+{
18 18
     /**
19 19
      * Объект DocumentParser - основной класс MODX
20 20
      * @var \DocumentParser
@@ -40,10 +40,10 @@  discard block
 block discarded – undo
40 40
      *
41 41
      * @return self
42 42
      */
43
-    public static function getInstance(DocumentParser $modx, $lang, $userClass = 'modUsers', $debug = false)
44
-    {
43
+    public static function getInstance(DocumentParser $modx, $lang, $userClass = 'modUsers', $debug = false)
44
+    {
45 45
 
46
-        if (null === self::$instance) {
46
+        if (null === self::$instance) {
47 47
             self::$instance = new self($modx, $userClass, $debug);
48 48
         }
49 49
 
@@ -57,8 +57,8 @@  discard block
 block discarded – undo
57 57
      * is not allowed to call from outside: private!
58 58
      *
59 59
      */
60
-    private function __construct(DocumentParser $modx, $userClass, $debug)
61
-    {
60
+    private function __construct(DocumentParser $modx, $userClass, $debug)
61
+    {
62 62
         $this->modx = $modx;
63 63
         $this->userObj = new $userClass($this->modx, $debug);
64 64
         $this->url = new DLCollection($this->modx);
@@ -76,8 +76,8 @@  discard block
 block discarded – undo
76 76
      *
77 77
      * @return void
78 78
      */
79
-    private function __clone()
80
-    {
79
+    private function __clone()
80
+    {
81 81
 
82 82
     }
83 83
 
@@ -86,23 +86,23 @@  discard block
 block discarded – undo
86 86
      *
87 87
      * @return void
88 88
      */
89
-    private function __wakeup()
90
-    {
89
+    private function __wakeup()
90
+    {
91 91
 
92 92
     }
93 93
 
94 94
     /**
95 95
      * Сброс авторизации и обновление страницы
96 96
      */
97
-    public function logout($params)
98
-    {
97
+    public function logout($params)
98
+    {
99 99
         $LogoutName = APIHelpers::getkey($params, 'LogoutName', 'logout');
100
-        if (is_scalar($LogoutName) && !empty($LogoutName) && isset($_GET[$LogoutName])) {
100
+        if (is_scalar($LogoutName) && !empty($LogoutName) && isset($_GET[$LogoutName])) {
101 101
             $userID = $this->UserID('web');
102
-            if ($userID) {
102
+            if ($userID) {
103 103
                 $this->userObj->edit($userID);
104 104
                 $params = array();
105
-                if ($this->userObj->getID()) {
105
+                if ($this->userObj->getID()) {
106 106
                     $params = array(
107 107
                         "userid"   => $this->userObj->getID(),
108 108
                         "username" => $this->userObj->get('username')
@@ -110,12 +110,12 @@  discard block
 block discarded – undo
110 110
                     $this->modx->invokeEvent("OnBeforeWebLogout", $params);
111 111
                 }
112 112
                 $this->userObj->logOut();
113
-                if ($this->userObj->getID()) {
113
+                if ($this->userObj->getID()) {
114 114
                     $this->modx->invokeEvent("OnWebLogout", $params);
115 115
                 }
116 116
 
117 117
                 $go = APIHelpers::getkey($params, 'url', '');
118
-                if (empty($go)) {
118
+                if (empty($go)) {
119 119
                     $go = str_replace(
120 120
                         array("?" . $LogoutName, "&" . $LogoutName),
121 121
                         array("", ""),
@@ -124,13 +124,13 @@  discard block
 block discarded – undo
124 124
                 }
125 125
 
126 126
                 $start = $this->makeUrl($this->config['site_start']);
127
-                if ($start == $go) {
127
+                if ($start == $go) {
128 128
                     $go = $this->config['site_url'];
129
-                } else {
129
+                } else {
130 130
                     $go = $this->config['site_url'] . ltrim($go, '/');
131 131
                 }
132 132
                 $this->moveTo(array('url' => $go));
133
-            } else {
133
+            } else {
134 134
                 //Если юзер не авторизован, то показываем ему 404 ошибку
135 135
                 $this->modx->sendErrorPage();
136 136
             }
@@ -143,8 +143,8 @@  discard block
 block discarded – undo
143 143
      * Генерация ссылки под кнопку выход
144 144
      * @return string
145 145
      */
146
-    public function logoutUrl($params)
147
-    {
146
+    public function logoutUrl($params)
147
+    {
148 148
         $LogoutName = APIHelpers::getkey($params, 'LogoutName', 'logout');
149 149
         $request = parse_url($_SERVER['REQUEST_URI']);
150 150
 
@@ -159,8 +159,8 @@  discard block
 block discarded – undo
159 159
      *        если указан параметр authId, то данные из формы перекидываются в метод AuthPage
160 160
      *    В противном случае вся работа происходит внутри самого блока
161 161
      */
162
-    public function AuthBlock($params)
163
-    {
162
+    public function AuthBlock($params)
163
+    {
164 164
         $POST = array('backUrl' => $_SERVER['REQUEST_URI']);
165 165
 
166 166
         $error = $errorCode = '';
@@ -169,20 +169,20 @@  discard block
 block discarded – undo
169 169
         $emailField = APIHelpers::getkey($params, 'emailField', 'email');
170 170
         $rememberField = APIHelpers::getkey($params, 'rememberField', 'remember');
171 171
 
172
-        if ($this->UserID('web')) {
172
+        if ($this->UserID('web')) {
173 173
             $tpl = APIHelpers::getkey($params, 'tplProfile', '');
174
-            if (empty($tpl)) {
174
+            if (empty($tpl)) {
175 175
                 $tpl = $this->getTemplate('tplProfile');
176 176
             }
177 177
             $dataTPL = $this->userObj->toArray();
178 178
             $dataTPL['url.logout'] = $this->logoutUrl($params);
179 179
             $homeID = APIHelpers::getkey($params, 'homeID');
180
-            if (!empty($homeID)) {
180
+            if (!empty($homeID)) {
181 181
                 $dataTPL['url.profile'] = $this->makeUrl($homeID);
182 182
             }
183
-        } else {
183
+        } else {
184 184
             $tpl = APIHelpers::getkey($params, 'tplForm', '');
185
-            if (empty($tpl)) {
185
+            if (empty($tpl)) {
186 186
                 $tpl = $this->getTemplate('authForm');
187 187
             }
188 188
             $POST = $this->Auth($pwdField, $emailField, $rememberField, $POST['backUrl'], __METHOD__, $error,
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
                 'errorCode'  => $errorCode
198 198
             );
199 199
             $authId = APIHelpers::getkey($params, 'authId');
200
-            if (!empty($authId)) {
200
+            if (!empty($authId)) {
201 201
                 $dataTPL['authPage'] = $this->makeUrl($authId);
202 202
                 $dataTPL['method'] = strtolower(__CLASS__ . '::' . 'authpage');
203 203
             }
@@ -210,8 +210,8 @@  discard block
 block discarded – undo
210 210
      * Авторизация на сайте со страницы авторизации
211 211
      * [!Auth? &login=`password` &pwdField=`password` &homeID=`72`!]
212 212
      */
213
-    public function AuthPage($params)
214
-    {
213
+    public function AuthPage($params)
214
+    {
215 215
         $homeID = APIHelpers::getkey($params, 'homeID');
216 216
         $this->isAuthGoHome(array('id' => $homeID));
217 217
 
@@ -223,46 +223,46 @@  discard block
 block discarded – undo
223 223
         $rememberField = APIHelpers::getkey($params, 'rememberField', 'remember');
224 224
 
225 225
         $tpl = APIHelpers::getkey($params, 'tpl', '');
226
-        if (empty($tpl)) {
226
+        if (empty($tpl)) {
227 227
             $tpl = $this->getTemplate('authForm');
228 228
         }
229 229
 
230 230
         $request = parse_url($_SERVER['REQUEST_URI']);
231
-        if (!empty($_SERVER['HTTP_REFERER'])) {
231
+        if (!empty($_SERVER['HTTP_REFERER'])) {
232 232
             /**
233 233
              * Thank you for super protection against hacking in protect.inc.php:-)
234 234
              */
235 235
             $refer = htmlspecialchars_decode($_SERVER['HTTP_REFERER'], ENT_QUOTES);
236
-        } else {
236
+        } else {
237 237
              $refer = $this->getBackUrl($request);
238 238
         }
239 239
 
240
-        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
240
+        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
241 241
             $backUrl = APIHelpers::getkey($_POST, 'backUrl', $POST['backUrl']);
242
-            if (!is_scalar($backUrl)) {
242
+            if (!is_scalar($backUrl)) {
243 243
                 $backUrl = $refer;
244
-            } else {
244
+            } else {
245 245
                 $backUrl = urldecode($backUrl);
246 246
             }
247
-        } else {
247
+        } else {
248 248
             $backUrl = $refer;
249 249
         }
250 250
         $backUrl = parse_url($backUrl);
251
-        if (!empty($backUrl['path']) && $request['path'] != $backUrl['path']) {
251
+        if (!empty($backUrl['path']) && $request['path'] != $backUrl['path']) {
252 252
             $POST['backUrl'] = $backUrl['path'];
253
-        } else {
253
+        } else {
254 254
             $POST['backUrl'] = $this->getBackUrl($backUrl);
255 255
         }
256
-        if (!empty($POST['backUrl'])) {
256
+        if (!empty($POST['backUrl'])) {
257 257
             $idURL = $this->moveTo(array(
258 258
                 'url'      => '/' . ltrim($POST['backUrl'], '/'),
259 259
                 'validate' => true
260 260
             ));
261
-        } else {
261
+        } else {
262 262
             $idURL = 0;
263 263
         }
264
-        if (empty($idURL)) {
265
-            if (empty($homeID)) {
264
+        if (empty($idURL)) {
265
+            if (empty($homeID)) {
266 266
                 $homeID = $this->config['site_start'];
267 267
             }
268 268
             $POST['backUrl'] = $this->makeUrl($homeID);
@@ -285,12 +285,13 @@  discard block
 block discarded – undo
285 285
      * @param array $request
286 286
      * @return string
287 287
      */
288
-    protected function getBackUrl(array $request = array()){
288
+    protected function getBackUrl(array $request = array())
289
+    {
289 290
         $selfHost = rtrim(str_replace("http://", "", $this->config['site_url']), '/');
290
-        if (empty($request['host']) || $request['host'] == $selfHost) {
291
+        if (empty($request['host']) || $request['host'] == $selfHost) {
291 292
             $query = !empty($request['query']) ? '?' . $request['query'] : '';
292 293
             $out = !empty($request['path']) ? $request['path'] . $query : '';
293
-        } else {
294
+        } else {
294 295
             $out = '';
295 296
         }
296 297
         return $out;
@@ -316,12 +317,12 @@  discard block
 block discarded – undo
316 317
         &$error,
317 318
         &$errorCode,
318 319
         $params = array()
319
-    ) {
320
+    ) {
320 321
         $POST = array(
321 322
             'backUrl' => urlencode($backUrl)
322 323
         );
323 324
         $userObj = &$this->userObj;
324
-        if ($_SERVER['REQUEST_METHOD'] == 'POST' && APIHelpers::getkey($_POST, 'method', '') == strtolower($method)) {
325
+        if ($_SERVER['REQUEST_METHOD'] == 'POST' && APIHelpers::getkey($_POST, 'method', '') == strtolower($method)) {
325 326
             $POST = array_merge($POST, array(
326 327
                 'password' => APIHelpers::getkey($_POST, $pwdField, ''),
327 328
                 'email'    => APIHelpers::getkey($_POST, $emailField, ''),
@@ -329,7 +330,7 @@  discard block
 block discarded – undo
329 330
             ));
330 331
             if (!empty($POST['email']) && is_scalar($POST['email']) && !$userObj->emailValidate($POST['email'],
331 332
                     false)
332
-            ) {
333
+            ) {
333 334
                 $userObj->edit($POST['email']);
334 335
 
335 336
                 $this->modx->invokeEvent("OnBeforeWebLogin", array(
@@ -338,7 +339,7 @@  discard block
 block discarded – undo
338 339
                     "rememberme"   => $POST['remember'],
339 340
                     'userObj'      => $userObj
340 341
                 ));
341
-                if ($userObj->getID() && !$userObj->checkBlock($userObj->getID())) {
342
+                if ($userObj->getID() && !$userObj->checkBlock($userObj->getID())) {
342 343
                     $pluginFlag = $this->modx->invokeEvent("OnWebAuthentication", array(
343 344
                         "userid"        => $userObj->getID(),
344 345
                         "username"      => $userObj->get('username'),
@@ -350,7 +351,7 @@  discard block
 block discarded – undo
350 351
                         ($pluginFlag === true || $userObj->testAuth($userObj->getID(), $POST['password'], 0))
351 352
                         &&
352 353
                         $userObj->authUser($userObj->getID(), $POST['remember'])
353
-                    ) {
354
+                    ) {
354 355
                         $userObj->set('logincount', (int)$userObj->get('logincount') + 1);
355 356
                         $userObj->set('lastlogin', time());
356 357
                         $userObj->set('failedlogincount', 0);
@@ -363,21 +364,21 @@  discard block
 block discarded – undo
363 364
                             "rememberme"   => $POST['remember'],
364 365
                         ));
365 366
                         $this->moveTo(array('url' => urldecode($POST['backUrl'])));
366
-                    } else {
367
+                    } else {
367 368
                         $userObj->set('failedlogincount', (int)$userObj->get('failedlogincount') + 1);
368 369
                         $userObj->save(false, false);
369 370
 
370 371
                         $error = 'error.incorrect_password';
371 372
                     }
372
-                } else {
373
+                } else {
373 374
                     $error = 'error.no_user';
374 375
                 }
375
-            } else {
376
+            } else {
376 377
                 $error = 'error.incorrect_mail';
377 378
                 $POST['email'] = '';
378 379
             }
379 380
         }
380
-        if (!empty($error)) {
381
+        if (!empty($error)) {
381 382
             $errorCode = $error;
382 383
             $error = APIHelpers::getkey($params, $error, '');
383 384
             $error = static::getLangMsg($error, $error);
@@ -390,17 +391,17 @@  discard block
 block discarded – undo
390 391
      * Информация о пользователе
391 392
      * [!DLUsers? &action=`UserInfo` &field=`fullname` &id=`2`!]
392 393
      */
393
-    public function UserInfo($params)
394
-    {
394
+    public function UserInfo($params)
395
+    {
395 396
         $out = '';
396 397
         $userID = APIHelpers::getkey($params, 'id', 0);
397
-        if (empty($userID)) {
398
+        if (empty($userID)) {
398 399
             $userID = $this->UserID('web');
399 400
         }
400 401
         $field = APIHelpers::getkey($params, 'field', 'username');
401
-        if ($userID > 0) {
402
+        if ($userID > 0) {
402 403
             $this->userObj->edit($userID);
403
-            switch (true) {
404
+            switch (true) {
404 405
                 case ($field == $this->userObj->fieldPKName()):
405 406
                     $out = $this->userObj->getID();
406 407
                     break;
@@ -416,17 +417,17 @@  discard block
 block discarded – undo
416 417
     /**
417 418
      * ID пользователя
418 419
      */
419
-    public function UserID($type = 'web')
420
-    {
420
+    public function UserID($type = 'web')
421
+    {
421 422
         return $this->modx->getLoginUserID($type);
422 423
     }
423 424
 
424 425
     /**
425 426
      * Если не авторизован - то отправить на страницу
426 427
      */
427
-    public function isGuestGoHome($params)
428
-    {
429
-        if (!$this->UserID('web')) {
428
+    public function isGuestGoHome($params)
429
+    {
430
+        if (!$this->UserID('web')) {
430 431
             /**
431 432
              * @see : http://modx.im/blog/triks/105.html
432 433
              */
@@ -441,12 +442,12 @@  discard block
 block discarded – undo
441 442
     /**
442 443
      * Если авторизован - то открыть личный кабинет
443 444
      */
444
-    public function isAuthGoHome($params)
445
-    {
445
+    public function isAuthGoHome($params)
446
+    {
446 447
         $userID = $this->UserID('web');
447
-        if ($userID > 0) {
448
+        if ($userID > 0) {
448 449
             $id = APIHelpers::getkey($params, 'homeID');
449
-            if (empty($id)) {
450
+            if (empty($id)) {
450 451
                 $id = $this->modx->getConfig('login_home', $this->config['site_start']);
451 452
             }
452 453
             $this->moveTo(compact('id'));
@@ -458,28 +459,28 @@  discard block
 block discarded – undo
458 459
     /**
459 460
      * Редирект
460 461
      */
461
-    public function moveTo($params)
462
-    {
462
+    public function moveTo($params)
463
+    {
463 464
         $id = (int)APIHelpers::getkey($params, 'id', 0);
464 465
         $uri = APIHelpers::getkey($params, 'url', '');
465
-        if ((empty($uri) && !empty($id)) || !is_string($uri)) {
466
+        if ((empty($uri) && !empty($id)) || !is_string($uri)) {
466 467
             $uri = $this->makeUrl($id);
467 468
         }
468 469
         $code = (int)APIHelpers::getkey($params, 'code', 0);
469 470
         $addUrl = APIHelpers::getkey($params, 'addUrl', '');
470
-        if (is_scalar($addUrl) && $addUrl != '') {
471
+        if (is_scalar($addUrl) && $addUrl != '') {
471 472
             $uri .= "?" . $addUrl;
472 473
         }
473
-        if (APIHelpers::getkey($params, 'validate', false)) {
474
-            if (isset($this->modx->snippetCache['getPageID'])) {
474
+        if (APIHelpers::getkey($params, 'validate', false)) {
475
+            if (isset($this->modx->snippetCache['getPageID'])) {
475 476
                 $out = $this->modx->runSnippet('getPageID', compact('uri'));
476
-                if (empty($out)) {
477
+                if (empty($out)) {
477 478
                     $uri = '';
478 479
                 }
479
-            } else {
480
+            } else {
480 481
                 $uri = APIhelpers::sanitarTag($uri);
481 482
             }
482
-        } else {
483
+        } else {
483 484
             header("Location: " . $uri, true, ($code > 0 ? $code : 307));
484 485
         }
485 486
 
@@ -492,15 +493,15 @@  discard block
 block discarded – undo
492 493
      * @param  int $id ID документа
493 494
      * @return string
494 495
      */
495
-    protected function makeUrl($id = null)
496
-    {
496
+    protected function makeUrl($id = null)
497
+    {
497 498
         $id = (int)$id;
498
-        if ($id <= 0) {
499
+        if ($id <= 0) {
499 500
             $id = $this->modx->documentObject['id'];
500 501
         }
501
-        if ($this->url->containsKey($id)) {
502
+        if ($this->url->containsKey($id)) {
502 503
             $url = $this->url->get($id);
503
-        } else {
504
+        } else {
504 505
             $url = $this->modx->makeUrl($id);
505 506
             $this->url->set($id, $url);
506 507
         }
@@ -512,11 +513,11 @@  discard block
 block discarded – undo
512 513
      * @param $name
513 514
      * @return string
514 515
      */
515
-    protected function getTemplate($name)
516
-    {
516
+    protected function getTemplate($name)
517
+    {
517 518
         $out = '';
518 519
         $file = dirname(dirname(__FILE__)) . '/tpl/' . $name . '.html';
519
-        if (FS::getInstance()->checkFile($file)) {
520
+        if (FS::getInstance()->checkFile($file)) {
520 521
             $out = '@CODE: ' . file_get_contents($file);
521 522
         }
522 523
 
@@ -527,17 +528,17 @@  discard block
 block discarded – undo
527 528
      * @param $lang
528 529
      * @return bool
529 530
      */
530
-    protected static function loadLang($lang)
531
-    {
531
+    protected static function loadLang($lang)
532
+    {
532 533
         $file = dirname(dirname(__FILE__)) . '/lang/' . $lang . '.php';
533
-        if (!FS::getInstance()->checkFile($file)) {
534
+        if (!FS::getInstance()->checkFile($file)) {
534 535
             $file = false;
535 536
         }
536
-        if (!empty($lang) && !isset(static::$langDic[$lang]) && !empty($file)) {
537
+        if (!empty($lang) && !isset(static::$langDic[$lang]) && !empty($file)) {
537 538
             static::$langDic[$lang] = include_once($file);
538
-            if (is_array(static::$langDic[$lang])) {
539
+            if (is_array(static::$langDic[$lang])) {
539 540
                 static::$langDic[$lang] = APIHelpers::renameKeyArr(static::$langDic[$lang], $lang);
540
-            } else {
541
+            } else {
541 542
                 static::$langDic[$lang] = array();
542 543
             }
543 544
         }
@@ -550,17 +551,17 @@  discard block
 block discarded – undo
550 551
      * @param $default
551 552
      * @return string
552 553
      */
553
-    protected static function getLangMsg($key, $default)
554
-    {
554
+    protected static function getLangMsg($key, $default)
555
+    {
555 556
         $out = $default;
556 557
         $lng = static::$lang;
557 558
         $dic = static::$langDic;
558
-        if (isset($dic[$lng], $dic[$lng][$lng . '.' . $key])) {
559
+        if (isset($dic[$lng], $dic[$lng][$lng . '.' . $key])) {
559 560
             $out = $dic[$lng][$lng . '.' . $key];
560 561
         }
561
-        if (class_exists('evoBabel', false) && isset(self::$instance->modx->snippetCache['lang'])) {
562
+        if (class_exists('evoBabel', false) && isset(self::$instance->modx->snippetCache['lang'])) {
562 563
             $msg = self::$instance->modx->runSnippet('lang', array('a' => 'DLUsers.' . $key));
563
-            if (!empty($msg)) {
564
+            if (!empty($msg)) {
564 565
                 $out = $msg;
565 566
             }
566 567
         }
Please login to merge, or discard this patch.
assets/lib/APIHelpers.class.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
      * @license    GNU General Public License (GPL), http://www.gnu.org/copyleft/gpl.html
74 74
      * @param string $email проверяемый email
75 75
      * @param boolean $dns проверять ли DNS записи
76
-     * @return boolean Результат проверки почтового ящика
76
+     * @return false|string Результат проверки почтового ящика
77 77
      * @author Anton Shevchuk
78 78
      */
79 79
     public static function emailValidate($email, $dns = true)
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
     }
147 147
 
148 148
     /**
149
-     * @param $data
149
+     * @param string $data
150 150
      * @return bool|false|string
151 151
      */
152 152
     private function _getEnv($data)
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
     {
88 88
         if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
89 89
             list(, $domain) = explode("@", $email, 2);
90
-            if (!$dns || ($dns && checkdnsrr($domain, "MX") && checkdnsrr($domain, "A"))) {
90
+            if ( ! $dns || ($dns && checkdnsrr($domain, "MX") && checkdnsrr($domain, "A"))) {
91 91
                 $error = false;
92 92
             } else {
93 93
                 $error = 'dns';
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
             case ($tmp = self::_getEnv('HTTP_X_FORWARDED_FOR')):
219 219
                 $out = $tmp;
220 220
                 break;
221
-            case (!empty($_SERVER['REMOTE_ADDR'])):
221
+            case ( ! empty($_SERVER['REMOTE_ADDR'])):
222 222
                 $out = $_SERVER['REMOTE_ADDR'];
223 223
                 break;
224 224
             default:
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
             }
355 355
             for ($i = 0; $i < $len; $i++) {
356 356
                 $chr = mb_strtoupper(mb_substr($value, $i, 1, 'UTF-8'), 'UTF-8');
357
-                if (!in_array($chr, $data, true)) {
357
+                if ( ! in_array($chr, $data, true)) {
358 358
                     $flag = false;
359 359
                     break;
360 360
                 }
Please login to merge, or discard this patch.
Braces   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -3,16 +3,16 @@  discard block
 block discarded – undo
3 3
 /**
4 4
  * Class APIhelpers
5 5
  */
6
-class APIhelpers
7
-{
6
+class APIhelpers
7
+{
8 8
     /**
9 9
      * Преобразует первый символ в нижний регистр
10 10
      * @param $str
11 11
      * @param string $encoding - кодировка, по-умолчанию UTF-8
12 12
      * @return string
13 13
      */
14
-    public static function mb_lcfirst($str, $encoding = 'UTF-8')
15
-    {
14
+    public static function mb_lcfirst($str, $encoding = 'UTF-8')
15
+    {
16 16
         return mb_strtolower(mb_substr($str, 0, 1, $encoding), $encoding) . mb_substr($str, 1, mb_strlen($str),
17 17
             $encoding);
18 18
     }
@@ -23,8 +23,8 @@  discard block
 block discarded – undo
23 23
      * @param string $encoding - кодировка, по-умолчанию UTF-8
24 24
      * @return string
25 25
      */
26
-    public static function mb_ucfirst($str, $encoding = 'UTF-8')
27
-    {
26
+    public static function mb_ucfirst($str, $encoding = 'UTF-8')
27
+    {
28 28
         $str = mb_ereg_replace('^[\ ]+', '', $str);
29 29
         $str = mb_strtoupper(mb_substr($str, 0, 1, $encoding), $encoding) . mb_substr($str, 1, mb_strlen($str),
30 30
                 $encoding);
@@ -43,13 +43,13 @@  discard block
 block discarded – undo
43 43
      * @param string $encoding кодировка
44 44
      * @return string
45 45
      */
46
-    public static function mb_trim_word($html, $len, $encoding = 'UTF-8')
47
-    {
46
+    public static function mb_trim_word($html, $len, $encoding = 'UTF-8')
47
+    {
48 48
         $text = trim(preg_replace('|\s+|', ' ', strip_tags($html)));
49 49
         $text = mb_substr($text, 0, $len + 1, $encoding);
50
-        if (mb_substr($text, -1, null, $encoding) == ' ') {
50
+        if (mb_substr($text, -1, null, $encoding) == ' ') {
51 51
             $out = trim($text);
52
-        } else {
52
+        } else {
53 53
             $out = mb_substr($text, 0, mb_strripos($text, ' ', null, $encoding), $encoding);
54 54
         }
55 55
 
@@ -62,10 +62,10 @@  discard block
 block discarded – undo
62 62
      * @param mixed $default null
63 63
      * @return mixed
64 64
      */
65
-    public static function getkey($data, $key, $default = null)
66
-    {
65
+    public static function getkey($data, $key, $default = null)
66
+    {
67 67
         $out = $default;
68
-        if (is_array($data) && (is_int($key) || is_string($key)) && $key !== '' && array_key_exists($key, $data)) {
68
+        if (is_array($data) && (is_int($key) || is_string($key)) && $key !== '' && array_key_exists($key, $data)) {
69 69
             $out = $data[$key];
70 70
         }
71 71
 
@@ -83,16 +83,16 @@  discard block
 block discarded – undo
83 83
      * @return boolean Результат проверки почтового ящика
84 84
      * @author Anton Shevchuk
85 85
      */
86
-    public static function emailValidate($email, $dns = true)
87
-    {
88
-        if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
86
+    public static function emailValidate($email, $dns = true)
87
+    {
88
+        if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
89 89
             list(, $domain) = explode("@", $email, 2);
90
-            if (!$dns || ($dns && checkdnsrr($domain, "MX") && checkdnsrr($domain, "A"))) {
90
+            if (!$dns || ($dns && checkdnsrr($domain, "MX") && checkdnsrr($domain, "A"))) {
91 91
                 $error = false;
92
-            } else {
92
+            } else {
93 93
                 $error = 'dns';
94 94
             }
95
-        } else {
95
+        } else {
96 96
             $error = 'format';
97 97
         }
98 98
 
@@ -125,16 +125,16 @@  discard block
 block discarded – undo
125 125
      * $this->genPass(20,"."); //AMV,>&?J)v55,(^g}Z06
126 126
      * $this->genPass(20,"aaa0aaa.A"); //rtvKja5xb0\KpdiRR1if
127 127
      */
128
-    public static function genPass($len, $data = '')
129
-    {
130
-        if ($data == '') {
128
+    public static function genPass($len, $data = '')
129
+    {
130
+        if ($data == '') {
131 131
             $data = 'Aa0.';
132 132
         }
133 133
         $opt = strlen($data);
134 134
         $pass = array();
135 135
 
136
-        for ($i = $len; $i > 0; $i--) {
137
-            switch ($data[rand(0, ($opt - 1))]) {
136
+        for ($i = $len; $i > 0; $i--) {
137
+            switch ($data[rand(0, ($opt - 1))]) {
138 138
                 case 'A':
139 139
                     $tmp = rand(65, 90);
140 140
                     break;
@@ -158,9 +158,9 @@  discard block
 block discarded – undo
158 158
      * @param $data
159 159
      * @return bool|false|string
160 160
      */
161
-    private function _getEnv($data)
162
-    {
163
-        switch (true) {
161
+    private function _getEnv($data)
162
+    {
163
+        switch (true) {
164 164
             case (isset($_SERVER[$data])):
165 165
                 $out = $_SERVER[$data];
166 166
                 break;
@@ -193,10 +193,10 @@  discard block
 block discarded – undo
193 193
      *
194 194
      * @see http://stackoverflow.com/questions/5036443/php-how-to-block-proxies-from-my-site
195 195
      */
196
-    public static function getUserIP($default = '127.0.0.1')
197
-    {
196
+    public static function getUserIP($default = '127.0.0.1')
197
+    {
198 198
         //Порядок условий зависит от приоритетов
199
-        switch (true) {
199
+        switch (true) {
200 200
             case ($tmp = self::_getEnv('HTTP_COMING_FROM')):
201 201
                 $out = $tmp;
202 202
                 break;
@@ -250,8 +250,8 @@  discard block
 block discarded – undo
250 250
             '`'   => '&#96;',
251 251
             '%60' => '&#96;'
252 252
         )
253
-    ) {
254
-        switch (true) {
253
+    ) {
254
+        switch (true) {
255 255
             case is_scalar($data):
256 256
                 $out = str_replace(
257 257
                     array_keys($chars),
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
                 break;
262 262
             case is_array($data):
263 263
                 $out = $data;
264
-                foreach ($out as $key => &$val) {
264
+                foreach ($out as $key => &$val) {
265 265
                     $val = self::sanitarTag($val, $charset, $chars);
266 266
                 }
267 267
                 break;
@@ -277,8 +277,8 @@  discard block
 block discarded – undo
277 277
      * @param string $charset
278 278
      * @return string
279 279
      */
280
-    public static function e($text, $charset = 'UTF-8')
281
-    {
280
+    public static function e($text, $charset = 'UTF-8')
281
+    {
282 282
         return is_scalar($text) ? htmlspecialchars($text, ENT_QUOTES, $charset, false) : '';
283 283
     }
284 284
 
@@ -293,17 +293,17 @@  discard block
 block discarded – undo
293 293
      * @param array $mixArray Примесь символов, которые так же могут использоваться в строке
294 294
      * @return bool
295 295
      */
296
-    public static function checkString($value, $minLen = 1, $alph = array(), $mixArray = array())
297
-    {
296
+    public static function checkString($value, $minLen = 1, $alph = array(), $mixArray = array())
297
+    {
298 298
         $flag = true;
299 299
         $len = mb_strlen($value, 'UTF-8');
300 300
         $value = trim($value);
301
-        if (mb_strlen($value, 'UTF-8') == $len) {
301
+        if (mb_strlen($value, 'UTF-8') == $len) {
302 302
             $data = is_array($mixArray) ? $mixArray : array();
303 303
             $alph = is_array($alph) ? array_unique($alph) : array();
304
-            foreach ($alph as $item) {
304
+            foreach ($alph as $item) {
305 305
                 $item = strtolower($item);
306
-                switch ($item) {
306
+                switch ($item) {
307 307
                     case 'rus':
308 308
                         $data = array_merge($data, array(
309 309
                             'А',
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
                         break;
344 344
                     case 'num':
345 345
                         $tmp = range('0', '9');
346
-                        foreach ($tmp as $t) {
346
+                        foreach ($tmp as $t) {
347 347
                             $data[] = (string)$t;
348 348
                         }
349 349
                         break;
@@ -352,15 +352,15 @@  discard block
 block discarded – undo
352 352
                         break;
353 353
                 }
354 354
             }
355
-            for ($i = 0; $i < $len; $i++) {
355
+            for ($i = 0; $i < $len; $i++) {
356 356
                 $chr = mb_strtoupper(mb_substr($value, $i, 1, 'UTF-8'), 'UTF-8');
357
-                if (!in_array($chr, $data, true)) {
357
+                if (!in_array($chr, $data, true)) {
358 358
                     $flag = false;
359 359
                     break;
360 360
                 }
361 361
             }
362 362
             $flag = ($flag && $len >= $minLen);
363
-        } else {
363
+        } else {
364 364
             $flag = false;
365 365
         }
366 366
 
@@ -377,18 +377,18 @@  discard block
 block discarded – undo
377 377
      * @param string $sep разделитель ключей при склейке многомерных массивов
378 378
      * @return array массив с переименованными ключами
379 379
      */
380
-    public static function renameKeyArr($data, $prefix = '', $suffix = '', $addPS = '.', $sep = '.')
381
-    {
380
+    public static function renameKeyArr($data, $prefix = '', $suffix = '', $addPS = '.', $sep = '.')
381
+    {
382 382
         $out = array();
383
-        if ($prefix == '' && $suffix == '') {
383
+        if ($prefix == '' && $suffix == '') {
384 384
             $out = $data;
385
-        } else {
385
+        } else {
386 386
             $InsertPrefix = ($prefix != '') ? ($prefix . $addPS) : '';
387 387
             $InsertSuffix = ($suffix != '') ? ($addPS . $suffix) : '';
388
-            foreach ($data as $key => $item) {
388
+            foreach ($data as $key => $item) {
389 389
                 $key = $InsertPrefix . $key;
390 390
                 $val = null;
391
-                switch (true) {
391
+                switch (true) {
392 392
                     case is_scalar($item):
393 393
                         $val = $item;
394 394
                         break;
Please login to merge, or discard this patch.
assets/lib/Formatter/SqlFormatter.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -330,8 +330,8 @@
 block discarded – undo
330 330
     }
331 331
 
332 332
     /**
333
-     * @param $string
334
-     * @return null
333
+     * @param string $string
334
+     * @return string|null
335 335
      */
336 336
     protected static function getQuotedString($string)
337 337
     {
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -862,7 +862,7 @@  discard block
 block discarded – undo
862 862
 
863 863
         // A reserved word cannot be preceded by a '.'
864 864
         // this makes it so in "mytable.from", "from" is not considered a reserved word
865
-        if (!$previous || !isset($previous[self::TOKEN_VALUE]) || $previous[self::TOKEN_VALUE] !== '.') {
865
+        if ( ! $previous || ! isset($previous[self::TOKEN_VALUE]) || $previous[self::TOKEN_VALUE] !== '.') {
866 866
             $upper = strtoupper($string);
867 867
             // Top Level Reserved Word
868 868
             if (preg_match('/^(' . self::$regex_reserved_toplevel . ')($|\s|' . self::$regex_boundaries . ')/', $upper,
@@ -1118,7 +1118,7 @@  discard block
 block discarded – undo
1118 1118
                 $length = 0;
1119 1119
                 for ($j = 1; $j <= 250; $j++) {
1120 1120
                     // Reached end of string
1121
-                    if (!isset($tokens[$i + $j])) {
1121
+                    if ( ! isset($tokens[$i + $j])) {
1122 1122
                         break;
1123 1123
                     }
1124 1124
 
@@ -1156,7 +1156,7 @@  discard block
 block discarded – undo
1156 1156
                     $return = rtrim($return, ' ');
1157 1157
                 }
1158 1158
 
1159
-                if (!$inline_parentheses) {
1159
+                if ( ! $inline_parentheses) {
1160 1160
                     $increase_block_indent = true;
1161 1161
                     // Add a newline after the parentheses
1162 1162
                     $newline = true;
@@ -1189,7 +1189,7 @@  discard block
 block discarded – undo
1189 1189
                 }
1190 1190
 
1191 1191
                 // Add a newline before the closing parentheses (if not already added)
1192
-                if (!$added_newline) {
1192
+                if ( ! $added_newline) {
1193 1193
                     $return .= "\n" . str_repeat($tab, $indent_level);
1194 1194
                 }
1195 1195
             } // Top level reserved words start a new line and increase the special indent level
@@ -1206,7 +1206,7 @@  discard block
 block discarded – undo
1206 1206
                 // Add a newline after the top level reserved word
1207 1207
                 $newline = true;
1208 1208
                 // Add a newline before the top level reserved word (if not already added)
1209
-                if (!$added_newline) {
1209
+                if ( ! $added_newline) {
1210 1210
                     $return .= "\n" . str_repeat($tab, $indent_level);
1211 1211
                 } // If we already added a newline, redo the indentation since it may be different now
1212 1212
                 else {
@@ -1220,14 +1220,14 @@  discard block
 block discarded – undo
1220 1220
                     $highlighted = preg_replace('/\s+/', ' ', $highlighted);
1221 1221
                 }
1222 1222
                 //if SQL 'LIMIT' clause, start variable to reset newline
1223
-                if ($token[self::TOKEN_VALUE] === 'LIMIT' && !$inline_parentheses) {
1223
+                if ($token[self::TOKEN_VALUE] === 'LIMIT' && ! $inline_parentheses) {
1224 1224
                     $clause_limit = true;
1225 1225
                 }
1226 1226
             } // Checks if we are out of the limit clause
1227 1227
             elseif ($clause_limit && $token[self::TOKEN_VALUE] !== "," && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_NUMBER && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
1228 1228
                 $clause_limit = false;
1229 1229
             } // Commas start a new line (unless within inline parentheses or SQL 'LIMIT' clause)
1230
-            elseif ($token[self::TOKEN_VALUE] === ',' && !$inline_parentheses) {
1230
+            elseif ($token[self::TOKEN_VALUE] === ',' && ! $inline_parentheses) {
1231 1231
                 //If the previous TOKEN_VALUE is 'LIMIT', resets new line
1232 1232
                 if ($clause_limit === true) {
1233 1233
                     $newline = false;
@@ -1239,7 +1239,7 @@  discard block
 block discarded – undo
1239 1239
             } // Newline reserved words start a new line
1240 1240
             elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE) {
1241 1241
                 // Add a newline before the reserved word (if not already added)
1242
-                if (!$added_newline) {
1242
+                if ( ! $added_newline) {
1243 1243
                     $return .= "\n" . str_repeat($tab, $indent_level);
1244 1244
                 }
1245 1245
 
@@ -1333,7 +1333,7 @@  discard block
 block discarded – undo
1333 1333
         foreach ($tokens as $token) {
1334 1334
             // If this is a query separator
1335 1335
             if ($token[self::TOKEN_VALUE] === ';') {
1336
-                if (!$empty) {
1336
+                if ( ! $empty) {
1337 1337
                     $queries[] = $current_query . ';';
1338 1338
                 }
1339 1339
                 $current_query = '';
@@ -1349,7 +1349,7 @@  discard block
 block discarded – undo
1349 1349
             $current_query .= $token[self::TOKEN_VALUE];
1350 1350
         }
1351 1351
 
1352
-        if (!$empty) {
1352
+        if ( ! $empty) {
1353 1353
             $queries[] = trim($current_query);
1354 1354
         }
1355 1355
 
@@ -1643,7 +1643,7 @@  discard block
 block discarded – undo
1643 1643
             return $string . "\n";
1644 1644
         } else {
1645 1645
             $string = trim($string);
1646
-            if (!self::$use_pre) {
1646
+            if ( ! self::$use_pre) {
1647 1647
                 return $string;
1648 1648
             }
1649 1649
 
Please login to merge, or discard this patch.
Braces   +184 added lines, -182 removed lines patch added patch discarded remove patch
@@ -12,8 +12,8 @@  discard block
 block discarded – undo
12 12
  * @link       http://github.com/jdorn/sql-formatter
13 13
  * @version    1.2.18
14 14
  */
15
-class SqlFormatter
16
-{
15
+class SqlFormatter
16
+{
17 17
     // Constants for token types
18 18
     const TOKEN_TYPE_WHITESPACE = 0;
19 19
     const TOKEN_TYPE_WORD = 1;
@@ -732,8 +732,8 @@  discard block
 block discarded – undo
732 732
      * Get stats about the token cache
733 733
      * @return Array An array containing the keys 'hits', 'misses', 'entries', and 'size' in bytes
734 734
      */
735
-    public static function getCacheStats()
736
-    {
735
+    public static function getCacheStats()
736
+    {
737 737
         return array(
738 738
             'hits'    => self::$cache_hits,
739 739
             'misses'  => self::$cache_misses,
@@ -745,9 +745,9 @@  discard block
 block discarded – undo
745 745
     /**
746 746
      * Stuff that only needs to be done once.  Builds regular expressions and sorts the reserved words.
747 747
      */
748
-    protected static function init()
749
-    {
750
-        if (self::$init) {
748
+    protected static function init()
749
+    {
750
+        if (self::$init) {
751 751
             return;
752 752
         }
753 753
 
@@ -779,10 +779,10 @@  discard block
 block discarded – undo
779 779
      *
780 780
      * @return Array An associative array containing the type and value of the token.
781 781
      */
782
-    protected static function getNextToken($string, $previous = null)
783
-    {
782
+    protected static function getNextToken($string, $previous = null)
783
+    {
784 784
         // Whitespace
785
-        if (preg_match('/^\s+/', $string, $matches)) {
785
+        if (preg_match('/^\s+/', $string, $matches)) {
786 786
             return array(
787 787
                 self::TOKEN_VALUE => $matches[0],
788 788
                 self::TOKEN_TYPE  => self::TOKEN_TYPE_WHITESPACE
@@ -790,17 +790,18 @@  discard block
 block discarded – undo
790 790
         }
791 791
 
792 792
         // Comment
793
-        if ($string[0] === '#' || (isset($string[1]) && ($string[0] === '-' && $string[1] === '-') || ($string[0] === '/' && $string[1] === '*'))) {
793
+        if ($string[0] === '#' || (isset($string[1]) && ($string[0] === '-' && $string[1] === '-') || ($string[0] === '/' && $string[1] === '*'))) {
794 794
             // Comment until end of line
795
-            if ($string[0] === '-' || $string[0] === '#') {
795
+            if ($string[0] === '-' || $string[0] === '#') {
796 796
                 $last = strpos($string, "\n");
797 797
                 $type = self::TOKEN_TYPE_COMMENT;
798
-            } else { // Comment until closing comment tag
798
+            } else {
799
+// Comment until closing comment tag
799 800
                 $last = strpos($string, "*/", 2) + 2;
800 801
                 $type = self::TOKEN_TYPE_BLOCK_COMMENT;
801 802
             }
802 803
 
803
-            if ($last === false) {
804
+            if ($last === false) {
804 805
                 $last = strlen($string);
805 806
             }
806 807
 
@@ -811,7 +812,7 @@  discard block
 block discarded – undo
811 812
         }
812 813
 
813 814
         // Quoted String
814
-        if ($string[0] === '"' || $string[0] === '\'' || $string[0] === '`' || $string[0] === '[') {
815
+        if ($string[0] === '"' || $string[0] === '\'' || $string[0] === '`' || $string[0] === '[') {
815 816
             $return = array(
816 817
                 self::TOKEN_TYPE  => (($string[0] === '`' || $string[0] === '[') ? self::TOKEN_TYPE_BACKTICK_QUOTE : self::TOKEN_TYPE_QUOTE),
817 818
                 self::TOKEN_VALUE => self::getQuotedString($string)
@@ -821,31 +822,31 @@  discard block
 block discarded – undo
821 822
         }
822 823
 
823 824
         // User-defined Variable
824
-        if (($string[0] === '@' || $string[0] === ':') && isset($string[1])) {
825
+        if (($string[0] === '@' || $string[0] === ':') && isset($string[1])) {
825 826
             $ret = array(
826 827
                 self::TOKEN_VALUE => null,
827 828
                 self::TOKEN_TYPE  => self::TOKEN_TYPE_VARIABLE
828 829
             );
829 830
 
830 831
             // If the variable name is quoted
831
-            if ($string[1] === '"' || $string[1] === '\'' || $string[1] === '`') {
832
+            if ($string[1] === '"' || $string[1] === '\'' || $string[1] === '`') {
832 833
                 $ret[self::TOKEN_VALUE] = $string[0] . self::getQuotedString(substr($string, 1));
833 834
             } // Non-quoted variable name
834
-            else {
835
+            else {
835 836
                 preg_match('/^(' . $string[0] . '[a-zA-Z0-9\._\$]+)/', $string, $matches);
836
-                if ($matches) {
837
+                if ($matches) {
837 838
                     $ret[self::TOKEN_VALUE] = $matches[1];
838 839
                 }
839 840
             }
840 841
 
841
-            if ($ret[self::TOKEN_VALUE] !== null) {
842
+            if ($ret[self::TOKEN_VALUE] !== null) {
842 843
                 return $ret;
843 844
             }
844 845
         }
845 846
 
846 847
         // Number (decimal, binary, or hex)
847 848
         if (preg_match('/^([0-9]+(\.[0-9]+)?|0x[0-9a-fA-F]+|0b[01]+)($|\s|"\'`|' . self::$regex_boundaries . ')/',
848
-            $string, $matches)) {
849
+            $string, $matches)) {
849 850
             return array(
850 851
                 self::TOKEN_VALUE => $matches[1],
851 852
                 self::TOKEN_TYPE  => self::TOKEN_TYPE_NUMBER
@@ -853,7 +854,7 @@  discard block
 block discarded – undo
853 854
         }
854 855
 
855 856
         // Boundary Character (punctuation and symbols)
856
-        if (preg_match('/^(' . self::$regex_boundaries . ')/', $string, $matches)) {
857
+        if (preg_match('/^(' . self::$regex_boundaries . ')/', $string, $matches)) {
857 858
             return array(
858 859
                 self::TOKEN_VALUE => $matches[1],
859 860
                 self::TOKEN_TYPE  => self::TOKEN_TYPE_BOUNDARY
@@ -862,11 +863,11 @@  discard block
 block discarded – undo
862 863
 
863 864
         // A reserved word cannot be preceded by a '.'
864 865
         // this makes it so in "mytable.from", "from" is not considered a reserved word
865
-        if (!$previous || !isset($previous[self::TOKEN_VALUE]) || $previous[self::TOKEN_VALUE] !== '.') {
866
+        if (!$previous || !isset($previous[self::TOKEN_VALUE]) || $previous[self::TOKEN_VALUE] !== '.') {
866 867
             $upper = strtoupper($string);
867 868
             // Top Level Reserved Word
868 869
             if (preg_match('/^(' . self::$regex_reserved_toplevel . ')($|\s|' . self::$regex_boundaries . ')/', $upper,
869
-                $matches)) {
870
+                $matches)) {
870 871
                 return array(
871 872
                     self::TOKEN_TYPE  => self::TOKEN_TYPE_RESERVED_TOPLEVEL,
872 873
                     self::TOKEN_VALUE => substr($string, 0, strlen($matches[1]))
@@ -874,7 +875,7 @@  discard block
 block discarded – undo
874 875
             }
875 876
             // Newline Reserved Word
876 877
             if (preg_match('/^(' . self::$regex_reserved_newline . ')($|\s|' . self::$regex_boundaries . ')/', $upper,
877
-                $matches)) {
878
+                $matches)) {
878 879
                 return array(
879 880
                     self::TOKEN_TYPE  => self::TOKEN_TYPE_RESERVED_NEWLINE,
880 881
                     self::TOKEN_VALUE => substr($string, 0, strlen($matches[1]))
@@ -882,7 +883,7 @@  discard block
 block discarded – undo
882 883
             }
883 884
             // Other Reserved Word
884 885
             if (preg_match('/^(' . self::$regex_reserved . ')($|\s|' . self::$regex_boundaries . ')/', $upper,
885
-                $matches)) {
886
+                $matches)) {
886 887
                 return array(
887 888
                     self::TOKEN_TYPE  => self::TOKEN_TYPE_RESERVED,
888 889
                     self::TOKEN_VALUE => substr($string, 0, strlen($matches[1]))
@@ -894,7 +895,7 @@  discard block
 block discarded – undo
894 895
         // this makes it so "count(" is considered a function, but "count" alone is not
895 896
         $upper = strtoupper($string);
896 897
         // function
897
-        if (preg_match('/^(' . self::$regex_function . '[(]|\s|[)])/', $upper, $matches)) {
898
+        if (preg_match('/^(' . self::$regex_function . '[(]|\s|[)])/', $upper, $matches)) {
898 899
             return array(
899 900
                 self::TOKEN_TYPE  => self::TOKEN_TYPE_RESERVED,
900 901
                 self::TOKEN_VALUE => substr($string, 0, strlen($matches[1]) - 1)
@@ -914,8 +915,8 @@  discard block
 block discarded – undo
914 915
      * @param $string
915 916
      * @return null
916 917
      */
917
-    protected static function getQuotedString($string)
918
-    {
918
+    protected static function getQuotedString($string)
919
+    {
919 920
         $ret = null;
920 921
 
921 922
         // This checks for the following patterns:
@@ -924,7 +925,7 @@  discard block
 block discarded – undo
924 925
         // 3. double quoted string using "" or \" to escape
925 926
         // 4. single quoted string using '' or \' to escape
926 927
         if (preg_match('/^(((`[^`]*($|`))+)|((\[[^\]]*($|\]))(\][^\]]*($|\]))*)|(("[^"\\\\]*(?:\\\\.[^"\\\\]*)*("|$))+)|((\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*(\'|$))+))/s',
927
-            $string, $matches)) {
928
+            $string, $matches)) {
928 929
             $ret = $matches[1];
929 930
         }
930 931
 
@@ -939,8 +940,8 @@  discard block
 block discarded – undo
939 940
      *
940 941
      * @return Array An array of tokens.
941 942
      */
942
-    protected static function tokenize($string)
943
-    {
943
+    protected static function tokenize($string)
944
+    {
944 945
         self::init();
945 946
 
946 947
         $tokens = array();
@@ -953,9 +954,9 @@  discard block
 block discarded – undo
953 954
         $current_length = strlen($string);
954 955
 
955 956
         // Keep processing the string until it is empty
956
-        while ($current_length) {
957
+        while ($current_length) {
957 958
             // If the string stopped shrinking, there was a problem
958
-            if ($old_string_len <= $current_length) {
959
+            if ($old_string_len <= $current_length) {
959 960
                 $tokens[] = array(
960 961
                     self::TOKEN_VALUE => $string,
961 962
                     self::TOKEN_TYPE  => self::TOKEN_TYPE_ERROR
@@ -966,26 +967,26 @@  discard block
 block discarded – undo
966 967
             $old_string_len = $current_length;
967 968
 
968 969
             // Determine if we can use caching
969
-            if ($current_length >= self::$max_cachekey_size) {
970
+            if ($current_length >= self::$max_cachekey_size) {
970 971
                 $cacheKey = substr($string, 0, self::$max_cachekey_size);
971
-            } else {
972
+            } else {
972 973
                 $cacheKey = false;
973 974
             }
974 975
 
975 976
             // See if the token is already cached
976
-            if ($cacheKey && isset(self::$token_cache[$cacheKey])) {
977
+            if ($cacheKey && isset(self::$token_cache[$cacheKey])) {
977 978
                 // Retrieve from cache
978 979
                 $token = self::$token_cache[$cacheKey];
979 980
                 $token_length = strlen($token[self::TOKEN_VALUE]);
980 981
                 self::$cache_hits++;
981
-            } else {
982
+            } else {
982 983
                 // Get the next token and the token type
983 984
                 $token = self::getNextToken($string, $token);
984 985
                 $token_length = strlen($token[self::TOKEN_VALUE]);
985 986
                 self::$cache_misses++;
986 987
 
987 988
                 // If the token is shorter than the max length, store it in cache
988
-                if ($cacheKey && $token_length < self::$max_cachekey_size) {
989
+                if ($cacheKey && $token_length < self::$max_cachekey_size) {
989 990
                     self::$token_cache[$cacheKey] = $token;
990 991
                 }
991 992
             }
@@ -1009,8 +1010,8 @@  discard block
 block discarded – undo
1009 1010
      *
1010 1011
      * @return String The SQL string with HTML styles and formatting wrapped in a <pre> tag
1011 1012
      */
1012
-    public static function format($string, $highlight = true)
1013
-    {
1013
+    public static function format($string, $highlight = true)
1014
+    {
1014 1015
         // This variable will be populated with formatted html
1015 1016
         $return = '';
1016 1017
 
@@ -1032,47 +1033,48 @@  discard block
 block discarded – undo
1032 1033
 
1033 1034
         // Remove existing whitespace
1034 1035
         $tokens = array();
1035
-        foreach ($original_tokens as $i => $token) {
1036
-            if ($token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
1036
+        foreach ($original_tokens as $i => $token) {
1037
+            if ($token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
1037 1038
                 $token['i'] = $i;
1038 1039
                 $tokens[] = $token;
1039 1040
             }
1040 1041
         }
1041 1042
 
1042 1043
         // Format token by token
1043
-        foreach ($tokens as $i => $token) {
1044
+        foreach ($tokens as $i => $token) {
1044 1045
             // Get highlighted token if doing syntax highlighting
1045
-            if ($highlight) {
1046
+            if ($highlight) {
1046 1047
                 $highlighted = self::highlightToken($token);
1047
-            } else { // If returning raw text
1048
+            } else {
1049
+// If returning raw text
1048 1050
                 $highlighted = $token[self::TOKEN_VALUE];
1049 1051
             }
1050 1052
 
1051 1053
             // If we are increasing the special indent level now
1052
-            if ($increase_special_indent) {
1054
+            if ($increase_special_indent) {
1053 1055
                 $indent_level++;
1054 1056
                 $increase_special_indent = false;
1055 1057
                 array_unshift($indent_types, 'special');
1056 1058
             }
1057 1059
             // If we are increasing the block indent level now
1058
-            if ($increase_block_indent) {
1060
+            if ($increase_block_indent) {
1059 1061
                 $indent_level++;
1060 1062
                 $increase_block_indent = false;
1061 1063
                 array_unshift($indent_types, 'block');
1062 1064
             }
1063 1065
 
1064 1066
             // If we need a new line before the token
1065
-            if ($newline) {
1067
+            if ($newline) {
1066 1068
                 $return .= "\n" . str_repeat($tab, $indent_level);
1067 1069
                 $newline = false;
1068 1070
                 $added_newline = true;
1069
-            } else {
1071
+            } else {
1070 1072
                 $added_newline = false;
1071 1073
             }
1072 1074
 
1073 1075
             // Display comments directly where they appear in the source
1074
-            if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
1075
-                if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
1076
+            if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
1077
+                if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
1076 1078
                     $indent = str_repeat($tab, $indent_level);
1077 1079
                     $return .= "\n" . $indent;
1078 1080
                     $highlighted = str_replace("\n", "\n" . $indent, $highlighted);
@@ -1083,12 +1085,12 @@  discard block
 block discarded – undo
1083 1085
                 continue;
1084 1086
             }
1085 1087
 
1086
-            if ($inline_parentheses) {
1088
+            if ($inline_parentheses) {
1087 1089
                 // End of inline parentheses
1088
-                if ($token[self::TOKEN_VALUE] === ')') {
1090
+                if ($token[self::TOKEN_VALUE] === ')') {
1089 1091
                     $return = rtrim($return, ' ');
1090 1092
 
1091
-                    if ($inline_indented) {
1093
+                    if ($inline_indented) {
1092 1094
                         array_shift($indent_types);
1093 1095
                         $indent_level--;
1094 1096
                         $return .= "\n" . str_repeat($tab, $indent_level);
@@ -1100,8 +1102,8 @@  discard block
 block discarded – undo
1100 1102
                     continue;
1101 1103
                 }
1102 1104
 
1103
-                if ($token[self::TOKEN_VALUE] === ',') {
1104
-                    if ($inline_count >= 30) {
1105
+                if ($token[self::TOKEN_VALUE] === ',') {
1106
+                    if ($inline_count >= 30) {
1105 1107
                         $inline_count = 0;
1106 1108
                         $newline = true;
1107 1109
                     }
@@ -1111,21 +1113,21 @@  discard block
 block discarded – undo
1111 1113
             }
1112 1114
 
1113 1115
             // Opening parentheses increase the block indent level and start a new line
1114
-            if ($token[self::TOKEN_VALUE] === '(') {
1116
+            if ($token[self::TOKEN_VALUE] === '(') {
1115 1117
                 // First check if this should be an inline parentheses block
1116 1118
                 // Examples are "NOW()", "COUNT(*)", "int(10)", key(`somecolumn`), DECIMAL(7,2)
1117 1119
                 // Allow up to 3 non-whitespace tokens inside inline parentheses
1118 1120
                 $length = 0;
1119
-                for ($j = 1; $j <= 250; $j++) {
1121
+                for ($j = 1; $j <= 250; $j++) {
1120 1122
                     // Reached end of string
1121
-                    if (!isset($tokens[$i + $j])) {
1123
+                    if (!isset($tokens[$i + $j])) {
1122 1124
                         break;
1123 1125
                     }
1124 1126
 
1125 1127
                     $next = $tokens[$i + $j];
1126 1128
 
1127 1129
                     // Reached closing parentheses, able to inline it
1128
-                    if ($next[self::TOKEN_VALUE] === ')') {
1130
+                    if ($next[self::TOKEN_VALUE] === ')') {
1129 1131
                         $inline_parentheses = true;
1130 1132
                         $inline_count = 0;
1131 1133
                         $inline_indented = false;
@@ -1133,72 +1135,72 @@  discard block
 block discarded – undo
1133 1135
                     }
1134 1136
 
1135 1137
                     // Reached an invalid token for inline parentheses
1136
-                    if ($next[self::TOKEN_VALUE] === ';' || $next[self::TOKEN_VALUE] === '(') {
1138
+                    if ($next[self::TOKEN_VALUE] === ';' || $next[self::TOKEN_VALUE] === '(') {
1137 1139
                         break;
1138 1140
                     }
1139 1141
 
1140 1142
                     // Reached an invalid token type for inline parentheses
1141
-                    if ($next[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_TOPLEVEL || $next[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE || $next[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $next[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
1143
+                    if ($next[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_TOPLEVEL || $next[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE || $next[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $next[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
1142 1144
                         break;
1143 1145
                     }
1144 1146
 
1145 1147
                     $length += strlen($next[self::TOKEN_VALUE]);
1146 1148
                 }
1147 1149
 
1148
-                if ($inline_parentheses && $length > 30) {
1150
+                if ($inline_parentheses && $length > 30) {
1149 1151
                     $increase_block_indent = true;
1150 1152
                     $inline_indented = true;
1151 1153
                     $newline = true;
1152 1154
                 }
1153 1155
 
1154 1156
                 // Take out the preceding space unless there was whitespace there in the original query
1155
-                if (isset($original_tokens[$token['i'] - 1]) && $original_tokens[$token['i'] - 1][self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
1157
+                if (isset($original_tokens[$token['i'] - 1]) && $original_tokens[$token['i'] - 1][self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
1156 1158
                     $return = rtrim($return, ' ');
1157 1159
                 }
1158 1160
 
1159
-                if (!$inline_parentheses) {
1161
+                if (!$inline_parentheses) {
1160 1162
                     $increase_block_indent = true;
1161 1163
                     // Add a newline after the parentheses
1162 1164
                     $newline = true;
1163 1165
                 }
1164 1166
 
1165 1167
             } // Closing parentheses decrease the block indent level
1166
-            elseif ($token[self::TOKEN_VALUE] === ')') {
1168
+            elseif ($token[self::TOKEN_VALUE] === ')') {
1167 1169
                 // Remove whitespace before the closing parentheses
1168 1170
                 $return = rtrim($return, ' ');
1169 1171
 
1170 1172
                 $indent_level--;
1171 1173
 
1172 1174
                 // Reset indent level
1173
-                while ($j = array_shift($indent_types)) {
1174
-                    if ($j === 'special') {
1175
+                while ($j = array_shift($indent_types)) {
1176
+                    if ($j === 'special') {
1175 1177
                         $indent_level--;
1176
-                    } else {
1178
+                    } else {
1177 1179
                         break;
1178 1180
                     }
1179 1181
                 }
1180 1182
 
1181
-                if ($indent_level < 0) {
1183
+                if ($indent_level < 0) {
1182 1184
                     // This is an error
1183 1185
                     $indent_level = 0;
1184 1186
 
1185
-                    if ($highlight) {
1187
+                    if ($highlight) {
1186 1188
                         $return .= "\n" . self::highlightError($token[self::TOKEN_VALUE]);
1187 1189
                         continue;
1188 1190
                     }
1189 1191
                 }
1190 1192
 
1191 1193
                 // Add a newline before the closing parentheses (if not already added)
1192
-                if (!$added_newline) {
1194
+                if (!$added_newline) {
1193 1195
                     $return .= "\n" . str_repeat($tab, $indent_level);
1194 1196
                 }
1195 1197
             } // Top level reserved words start a new line and increase the special indent level
1196
-            elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_TOPLEVEL) {
1198
+            elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_TOPLEVEL) {
1197 1199
                 $increase_special_indent = true;
1198 1200
 
1199 1201
                 // If the last indent type was 'special', decrease the special indent for this round
1200 1202
                 reset($indent_types);
1201
-                if (current($indent_types) === 'special') {
1203
+                if (current($indent_types) === 'special') {
1202 1204
                     $indent_level--;
1203 1205
                     array_shift($indent_types);
1204 1206
                 }
@@ -1206,88 +1208,88 @@  discard block
 block discarded – undo
1206 1208
                 // Add a newline after the top level reserved word
1207 1209
                 $newline = true;
1208 1210
                 // Add a newline before the top level reserved word (if not already added)
1209
-                if (!$added_newline) {
1211
+                if (!$added_newline) {
1210 1212
                     $return .= "\n" . str_repeat($tab, $indent_level);
1211 1213
                 } // If we already added a newline, redo the indentation since it may be different now
1212
-                else {
1214
+                else {
1213 1215
                     $return = rtrim($return, $tab) . str_repeat($tab, $indent_level);
1214 1216
                 }
1215 1217
 
1216 1218
                 // If the token may have extra whitespace
1217 1219
                 if (strpos($token[self::TOKEN_VALUE], ' ') !== false || strpos($token[self::TOKEN_VALUE],
1218 1220
                         "\n") !== false || strpos($token[self::TOKEN_VALUE], "\t") !== false
1219
-                ) {
1221
+                ) {
1220 1222
                     $highlighted = preg_replace('/\s+/', ' ', $highlighted);
1221 1223
                 }
1222 1224
                 //if SQL 'LIMIT' clause, start variable to reset newline
1223
-                if ($token[self::TOKEN_VALUE] === 'LIMIT' && !$inline_parentheses) {
1225
+                if ($token[self::TOKEN_VALUE] === 'LIMIT' && !$inline_parentheses) {
1224 1226
                     $clause_limit = true;
1225 1227
                 }
1226 1228
             } // Checks if we are out of the limit clause
1227
-            elseif ($clause_limit && $token[self::TOKEN_VALUE] !== "," && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_NUMBER && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
1229
+            elseif ($clause_limit && $token[self::TOKEN_VALUE] !== "," && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_NUMBER && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
1228 1230
                 $clause_limit = false;
1229 1231
             } // Commas start a new line (unless within inline parentheses or SQL 'LIMIT' clause)
1230
-            elseif ($token[self::TOKEN_VALUE] === ',' && !$inline_parentheses) {
1232
+            elseif ($token[self::TOKEN_VALUE] === ',' && !$inline_parentheses) {
1231 1233
                 //If the previous TOKEN_VALUE is 'LIMIT', resets new line
1232
-                if ($clause_limit === true) {
1234
+                if ($clause_limit === true) {
1233 1235
                     $newline = false;
1234 1236
                     $clause_limit = false;
1235 1237
                 } // All other cases of commas
1236
-                else {
1238
+                else {
1237 1239
                     $newline = true;
1238 1240
                 }
1239 1241
             } // Newline reserved words start a new line
1240
-            elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE) {
1242
+            elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE) {
1241 1243
                 // Add a newline before the reserved word (if not already added)
1242
-                if (!$added_newline) {
1244
+                if (!$added_newline) {
1243 1245
                     $return .= "\n" . str_repeat($tab, $indent_level);
1244 1246
                 }
1245 1247
 
1246 1248
                 // If the token may have extra whitespace
1247 1249
                 if (strpos($token[self::TOKEN_VALUE], ' ') !== false || strpos($token[self::TOKEN_VALUE],
1248 1250
                         "\n") !== false || strpos($token[self::TOKEN_VALUE], "\t") !== false
1249
-                ) {
1251
+                ) {
1250 1252
                     $highlighted = preg_replace('/\s+/', ' ', $highlighted);
1251 1253
                 }
1252 1254
             } // Multiple boundary characters in a row should not have spaces between them (not including parentheses)
1253
-            elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BOUNDARY) {
1254
-                if (isset($tokens[$i - 1]) && $tokens[$i - 1][self::TOKEN_TYPE] === self::TOKEN_TYPE_BOUNDARY) {
1255
-                    if (isset($original_tokens[$token['i'] - 1]) && $original_tokens[$token['i'] - 1][self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
1255
+            elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BOUNDARY) {
1256
+                if (isset($tokens[$i - 1]) && $tokens[$i - 1][self::TOKEN_TYPE] === self::TOKEN_TYPE_BOUNDARY) {
1257
+                    if (isset($original_tokens[$token['i'] - 1]) && $original_tokens[$token['i'] - 1][self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
1256 1258
                         $return = rtrim($return, ' ');
1257 1259
                     }
1258 1260
                 }
1259 1261
             }
1260 1262
 
1261 1263
             // If the token shouldn't have a space before it
1262
-            if ($token[self::TOKEN_VALUE] === '.' || $token[self::TOKEN_VALUE] === ',' || $token[self::TOKEN_VALUE] === ';') {
1264
+            if ($token[self::TOKEN_VALUE] === '.' || $token[self::TOKEN_VALUE] === ',' || $token[self::TOKEN_VALUE] === ';') {
1263 1265
                 $return = rtrim($return, ' ');
1264 1266
             }
1265 1267
 
1266 1268
             $return .= $highlighted . ' ';
1267 1269
 
1268 1270
             // If the token shouldn't have a space after it
1269
-            if ($token[self::TOKEN_VALUE] === '(' || $token[self::TOKEN_VALUE] === '.') {
1271
+            if ($token[self::TOKEN_VALUE] === '(' || $token[self::TOKEN_VALUE] === '.') {
1270 1272
                 $return = rtrim($return, ' ');
1271 1273
             }
1272 1274
 
1273 1275
             // If this is the "-" of a negative number, it shouldn't have a space after it
1274
-            if ($token[self::TOKEN_VALUE] === '-' && isset($tokens[$i + 1]) && $tokens[$i + 1][self::TOKEN_TYPE] === self::TOKEN_TYPE_NUMBER && isset($tokens[$i - 1])) {
1276
+            if ($token[self::TOKEN_VALUE] === '-' && isset($tokens[$i + 1]) && $tokens[$i + 1][self::TOKEN_TYPE] === self::TOKEN_TYPE_NUMBER && isset($tokens[$i - 1])) {
1275 1277
                 $prev = $tokens[$i - 1][self::TOKEN_TYPE];
1276
-                if ($prev !== self::TOKEN_TYPE_QUOTE && $prev !== self::TOKEN_TYPE_BACKTICK_QUOTE && $prev !== self::TOKEN_TYPE_WORD && $prev !== self::TOKEN_TYPE_NUMBER) {
1278
+                if ($prev !== self::TOKEN_TYPE_QUOTE && $prev !== self::TOKEN_TYPE_BACKTICK_QUOTE && $prev !== self::TOKEN_TYPE_WORD && $prev !== self::TOKEN_TYPE_NUMBER) {
1277 1279
                     $return = rtrim($return, ' ');
1278 1280
                 }
1279 1281
             }
1280 1282
         }
1281 1283
 
1282 1284
         // If there are unmatched parentheses
1283
-        if ($highlight && array_search('block', $indent_types) !== false) {
1285
+        if ($highlight && array_search('block', $indent_types) !== false) {
1284 1286
             $return .= "\n" . self::highlightError("WARNING: unclosed parentheses or section");
1285 1287
         }
1286 1288
 
1287 1289
         // Replace tab characters with the configuration tab character
1288 1290
         $return = trim(str_replace("\t", self::$tab, $return));
1289 1291
 
1290
-        if ($highlight) {
1292
+        if ($highlight) {
1291 1293
             $return = self::output($return);
1292 1294
         }
1293 1295
 
@@ -1301,13 +1303,13 @@  discard block
 block discarded – undo
1301 1303
      *
1302 1304
      * @return String The SQL string with HTML styles applied
1303 1305
      */
1304
-    public static function highlight($string)
1305
-    {
1306
+    public static function highlight($string)
1307
+    {
1306 1308
         $tokens = self::tokenize($string);
1307 1309
 
1308 1310
         $return = '';
1309 1311
 
1310
-        foreach ($tokens as $token) {
1312
+        foreach ($tokens as $token) {
1311 1313
             $return .= self::highlightToken($token);
1312 1314
         }
1313 1315
 
@@ -1322,18 +1324,18 @@  discard block
 block discarded – undo
1322 1324
      *
1323 1325
      * @return Array An array of individual query strings without trailing semicolons
1324 1326
      */
1325
-    public static function splitQuery($string)
1326
-    {
1327
+    public static function splitQuery($string)
1328
+    {
1327 1329
         $queries = array();
1328 1330
         $current_query = '';
1329 1331
         $empty = true;
1330 1332
 
1331 1333
         $tokens = self::tokenize($string);
1332 1334
 
1333
-        foreach ($tokens as $token) {
1335
+        foreach ($tokens as $token) {
1334 1336
             // If this is a query separator
1335
-            if ($token[self::TOKEN_VALUE] === ';') {
1336
-                if (!$empty) {
1337
+            if ($token[self::TOKEN_VALUE] === ';') {
1338
+                if (!$empty) {
1337 1339
                     $queries[] = $current_query . ';';
1338 1340
                 }
1339 1341
                 $current_query = '';
@@ -1342,14 +1344,14 @@  discard block
 block discarded – undo
1342 1344
             }
1343 1345
 
1344 1346
             // If this is a non-empty character
1345
-            if ($token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_COMMENT && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_BLOCK_COMMENT) {
1347
+            if ($token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_COMMENT && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_BLOCK_COMMENT) {
1346 1348
                 $empty = false;
1347 1349
             }
1348 1350
 
1349 1351
             $current_query .= $token[self::TOKEN_VALUE];
1350 1352
         }
1351 1353
 
1352
-        if (!$empty) {
1354
+        if (!$empty) {
1353 1355
             $queries[] = trim($current_query);
1354 1356
         }
1355 1357
 
@@ -1363,15 +1365,15 @@  discard block
 block discarded – undo
1363 1365
      *
1364 1366
      * @return String The SQL string without comments
1365 1367
      */
1366
-    public static function removeComments($string)
1367
-    {
1368
+    public static function removeComments($string)
1369
+    {
1368 1370
         $result = '';
1369 1371
 
1370 1372
         $tokens = self::tokenize($string);
1371 1373
 
1372
-        foreach ($tokens as $token) {
1374
+        foreach ($tokens as $token) {
1373 1375
             // Skip comment tokens
1374
-            if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
1376
+            if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
1375 1377
                 continue;
1376 1378
             }
1377 1379
 
@@ -1389,32 +1391,32 @@  discard block
 block discarded – undo
1389 1391
      *
1390 1392
      * @return String The SQL string without comments
1391 1393
      */
1392
-    public static function compress($string)
1393
-    {
1394
+    public static function compress($string)
1395
+    {
1394 1396
         $result = '';
1395 1397
 
1396 1398
         $tokens = self::tokenize($string);
1397 1399
 
1398 1400
         $whitespace = true;
1399
-        foreach ($tokens as $token) {
1401
+        foreach ($tokens as $token) {
1400 1402
             // Skip comment tokens
1401
-            if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
1403
+            if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
1402 1404
                 continue;
1403 1405
             } // Remove extra whitespace in reserved words (e.g "OUTER     JOIN" becomes "OUTER JOIN")
1404
-            elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_TOPLEVEL) {
1406
+            elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_TOPLEVEL) {
1405 1407
                 $token[self::TOKEN_VALUE] = preg_replace('/\s+/', ' ', $token[self::TOKEN_VALUE]);
1406 1408
             }
1407 1409
 
1408
-            if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_WHITESPACE) {
1410
+            if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_WHITESPACE) {
1409 1411
                 // If the last token was whitespace, don't add another one
1410
-                if ($whitespace) {
1412
+                if ($whitespace) {
1411 1413
                     continue;
1412
-                } else {
1414
+                } else {
1413 1415
                     $whitespace = true;
1414 1416
                     // Convert all whitespace to a single space
1415 1417
                     $token[self::TOKEN_VALUE] = ' ';
1416 1418
                 }
1417
-            } else {
1419
+            } else {
1418 1420
                 $whitespace = false;
1419 1421
             }
1420 1422
 
@@ -1431,39 +1433,39 @@  discard block
 block discarded – undo
1431 1433
      *
1432 1434
      * @return String HTML code of the highlighted token.
1433 1435
      */
1434
-    protected static function highlightToken($token)
1435
-    {
1436
+    protected static function highlightToken($token)
1437
+    {
1436 1438
         $type = $token[self::TOKEN_TYPE];
1437 1439
 
1438
-        if (self::is_cli()) {
1440
+        if (self::is_cli()) {
1439 1441
             $token = $token[self::TOKEN_VALUE];
1440
-        } else {
1441
-            if (defined('ENT_IGNORE')) {
1442
+        } else {
1443
+            if (defined('ENT_IGNORE')) {
1442 1444
                 $token = htmlentities($token[self::TOKEN_VALUE], ENT_COMPAT | ENT_IGNORE, 'UTF-8');
1443
-            } else {
1445
+            } else {
1444 1446
                 $token = htmlentities($token[self::TOKEN_VALUE], ENT_COMPAT, 'UTF-8');
1445 1447
             }
1446 1448
         }
1447 1449
 
1448
-        if ($type === self::TOKEN_TYPE_BOUNDARY) {
1450
+        if ($type === self::TOKEN_TYPE_BOUNDARY) {
1449 1451
             return self::highlightBoundary($token);
1450
-        } elseif ($type === self::TOKEN_TYPE_WORD) {
1452
+        } elseif ($type === self::TOKEN_TYPE_WORD) {
1451 1453
             return self::highlightWord($token);
1452
-        } elseif ($type === self::TOKEN_TYPE_BACKTICK_QUOTE) {
1454
+        } elseif ($type === self::TOKEN_TYPE_BACKTICK_QUOTE) {
1453 1455
             return self::highlightBacktickQuote($token);
1454
-        } elseif ($type === self::TOKEN_TYPE_QUOTE) {
1456
+        } elseif ($type === self::TOKEN_TYPE_QUOTE) {
1455 1457
             return self::highlightQuote($token);
1456
-        } elseif ($type === self::TOKEN_TYPE_RESERVED) {
1458
+        } elseif ($type === self::TOKEN_TYPE_RESERVED) {
1457 1459
             return self::highlightReservedWord($token);
1458
-        } elseif ($type === self::TOKEN_TYPE_RESERVED_TOPLEVEL) {
1460
+        } elseif ($type === self::TOKEN_TYPE_RESERVED_TOPLEVEL) {
1459 1461
             return self::highlightReservedWord($token);
1460
-        } elseif ($type === self::TOKEN_TYPE_RESERVED_NEWLINE) {
1462
+        } elseif ($type === self::TOKEN_TYPE_RESERVED_NEWLINE) {
1461 1463
             return self::highlightReservedWord($token);
1462
-        } elseif ($type === self::TOKEN_TYPE_NUMBER) {
1464
+        } elseif ($type === self::TOKEN_TYPE_NUMBER) {
1463 1465
             return self::highlightNumber($token);
1464
-        } elseif ($type === self::TOKEN_TYPE_VARIABLE) {
1466
+        } elseif ($type === self::TOKEN_TYPE_VARIABLE) {
1465 1467
             return self::highlightVariable($token);
1466
-        } elseif ($type === self::TOKEN_TYPE_COMMENT || $type === self::TOKEN_TYPE_BLOCK_COMMENT) {
1468
+        } elseif ($type === self::TOKEN_TYPE_COMMENT || $type === self::TOKEN_TYPE_BLOCK_COMMENT) {
1467 1469
             return self::highlightComment($token);
1468 1470
         }
1469 1471
 
@@ -1477,11 +1479,11 @@  discard block
 block discarded – undo
1477 1479
      *
1478 1480
      * @return String HTML code of the highlighted token.
1479 1481
      */
1480
-    protected static function highlightQuote($value)
1481
-    {
1482
-        if (self::is_cli()) {
1482
+    protected static function highlightQuote($value)
1483
+    {
1484
+        if (self::is_cli()) {
1483 1485
             return self::$cli_quote . $value . "\x1b[0m";
1484
-        } else {
1486
+        } else {
1485 1487
             return '<span ' . self::$quote_attributes . '>' . $value . '</span>';
1486 1488
         }
1487 1489
     }
@@ -1493,11 +1495,11 @@  discard block
 block discarded – undo
1493 1495
      *
1494 1496
      * @return String HTML code of the highlighted token.
1495 1497
      */
1496
-    protected static function highlightBacktickQuote($value)
1497
-    {
1498
-        if (self::is_cli()) {
1498
+    protected static function highlightBacktickQuote($value)
1499
+    {
1500
+        if (self::is_cli()) {
1499 1501
             return self::$cli_backtick_quote . $value . "\x1b[0m";
1500
-        } else {
1502
+        } else {
1501 1503
             return '<span ' . self::$backtick_quote_attributes . '>' . $value . '</span>';
1502 1504
         }
1503 1505
     }
@@ -1509,11 +1511,11 @@  discard block
 block discarded – undo
1509 1511
      *
1510 1512
      * @return String HTML code of the highlighted token.
1511 1513
      */
1512
-    protected static function highlightReservedWord($value)
1513
-    {
1514
-        if (self::is_cli()) {
1514
+    protected static function highlightReservedWord($value)
1515
+    {
1516
+        if (self::is_cli()) {
1515 1517
             return self::$cli_reserved . $value . "\x1b[0m";
1516
-        } else {
1518
+        } else {
1517 1519
             return '<span ' . self::$reserved_attributes . '>' . $value . '</span>';
1518 1520
         }
1519 1521
     }
@@ -1525,15 +1527,15 @@  discard block
 block discarded – undo
1525 1527
      *
1526 1528
      * @return String HTML code of the highlighted token.
1527 1529
      */
1528
-    protected static function highlightBoundary($value)
1529
-    {
1530
-        if ($value === '(' || $value === ')') {
1530
+    protected static function highlightBoundary($value)
1531
+    {
1532
+        if ($value === '(' || $value === ')') {
1531 1533
             return $value;
1532 1534
         }
1533 1535
 
1534
-        if (self::is_cli()) {
1536
+        if (self::is_cli()) {
1535 1537
             return self::$cli_boundary . $value . "\x1b[0m";
1536
-        } else {
1538
+        } else {
1537 1539
             return '<span ' . self::$boundary_attributes . '>' . $value . '</span>';
1538 1540
         }
1539 1541
     }
@@ -1545,11 +1547,11 @@  discard block
 block discarded – undo
1545 1547
      *
1546 1548
      * @return String HTML code of the highlighted token.
1547 1549
      */
1548
-    protected static function highlightNumber($value)
1549
-    {
1550
-        if (self::is_cli()) {
1550
+    protected static function highlightNumber($value)
1551
+    {
1552
+        if (self::is_cli()) {
1551 1553
             return self::$cli_number . $value . "\x1b[0m";
1552
-        } else {
1554
+        } else {
1553 1555
             return '<span ' . self::$number_attributes . '>' . $value . '</span>';
1554 1556
         }
1555 1557
     }
@@ -1561,11 +1563,11 @@  discard block
 block discarded – undo
1561 1563
      *
1562 1564
      * @return String HTML code of the highlighted token.
1563 1565
      */
1564
-    protected static function highlightError($value)
1565
-    {
1566
-        if (self::is_cli()) {
1566
+    protected static function highlightError($value)
1567
+    {
1568
+        if (self::is_cli()) {
1567 1569
             return self::$cli_error . $value . "\x1b[0m";
1568
-        } else {
1570
+        } else {
1569 1571
             return '<span ' . self::$error_attributes . '>' . $value . '</span>';
1570 1572
         }
1571 1573
     }
@@ -1577,11 +1579,11 @@  discard block
 block discarded – undo
1577 1579
      *
1578 1580
      * @return String HTML code of the highlighted token.
1579 1581
      */
1580
-    protected static function highlightComment($value)
1581
-    {
1582
-        if (self::is_cli()) {
1582
+    protected static function highlightComment($value)
1583
+    {
1584
+        if (self::is_cli()) {
1583 1585
             return self::$cli_comment . $value . "\x1b[0m";
1584
-        } else {
1586
+        } else {
1585 1587
             return '<span ' . self::$comment_attributes . '>' . $value . '</span>';
1586 1588
         }
1587 1589
     }
@@ -1593,11 +1595,11 @@  discard block
 block discarded – undo
1593 1595
      *
1594 1596
      * @return String HTML code of the highlighted token.
1595 1597
      */
1596
-    protected static function highlightWord($value)
1597
-    {
1598
-        if (self::is_cli()) {
1598
+    protected static function highlightWord($value)
1599
+    {
1600
+        if (self::is_cli()) {
1599 1601
             return self::$cli_word . $value . "\x1b[0m";
1600
-        } else {
1602
+        } else {
1601 1603
             return '<span ' . self::$word_attributes . '>' . $value . '</span>';
1602 1604
         }
1603 1605
     }
@@ -1609,11 +1611,11 @@  discard block
 block discarded – undo
1609 1611
      *
1610 1612
      * @return String HTML code of the highlighted token.
1611 1613
      */
1612
-    protected static function highlightVariable($value)
1613
-    {
1614
-        if (self::is_cli()) {
1614
+    protected static function highlightVariable($value)
1615
+    {
1616
+        if (self::is_cli()) {
1615 1617
             return self::$cli_variable . $value . "\x1b[0m";
1616
-        } else {
1618
+        } else {
1617 1619
             return '<span ' . self::$variable_attributes . '>' . $value . '</span>';
1618 1620
         }
1619 1621
     }
@@ -1625,8 +1627,8 @@  discard block
 block discarded – undo
1625 1627
      *
1626 1628
      * @return String The quoted string
1627 1629
      */
1628
-    private static function quote_regex($a)
1629
-    {
1630
+    private static function quote_regex($a)
1631
+    {
1630 1632
         return preg_quote($a, '/');
1631 1633
     }
1632 1634
 
@@ -1637,13 +1639,13 @@  discard block
 block discarded – undo
1637 1639
      *
1638 1640
      * @return String The quoted string
1639 1641
      */
1640
-    private static function output($string)
1641
-    {
1642
-        if (self::is_cli()) {
1642
+    private static function output($string)
1643
+    {
1644
+        if (self::is_cli()) {
1643 1645
             return $string . "\n";
1644
-        } else {
1646
+        } else {
1645 1647
             $string = trim($string);
1646
-            if (!self::$use_pre) {
1648
+            if (!self::$use_pre) {
1647 1649
                 return $string;
1648 1650
             }
1649 1651
 
@@ -1654,11 +1656,11 @@  discard block
 block discarded – undo
1654 1656
     /**
1655 1657
      * @return bool
1656 1658
      */
1657
-    private static function is_cli()
1658
-    {
1659
-        if (isset(self::$cli)) {
1659
+    private static function is_cli()
1660
+    {
1661
+        if (isset(self::$cli)) {
1660 1662
             return self::$cli;
1661
-        } else {
1663
+        } else {
1662 1664
             return php_sapi_name() === 'cli';
1663 1665
         }
1664 1666
     }
Please login to merge, or discard this patch.
assets/lib/Helpers/PHPThumb.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -23,8 +23,8 @@  discard block
 block discarded – undo
23 23
     }
24 24
 
25 25
     /**
26
-     * @param $inputFile
27
-     * @param $outputFile
26
+     * @param string $inputFile
27
+     * @param string $outputFile
28 28
      * @param $options
29 29
      * @return bool
30 30
      */
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
     }
67 67
 
68 68
     /**
69
-     * @param $options
69
+     * @param string $options
70 70
      */
71 71
     private function setOptions($options) {
72 72
         $options = strtr($options, Array("," => "&", "_" => "=", '{' => '[', '}' => ']'));
Please login to merge, or discard this patch.
Braces   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -7,8 +7,8 @@  discard block
 block discarded – undo
7 7
  * Class PHPThumb
8 8
  * @package Helpers
9 9
  */
10
-class PHPThumb
11
-{
10
+class PHPThumb
11
+{
12 12
 
13 13
     private $thumb = null;
14 14
     protected $fs = null;
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
     /**
18 18
      * PHPThumb constructor.
19 19
      */
20
-    public function __construct()
21
-    {
20
+    public function __construct()
21
+    {
22 22
         $this->thumb = new \phpthumb();
23 23
         $this->fs = FS::getInstance();
24 24
     }
@@ -29,16 +29,16 @@  discard block
 block discarded – undo
29 29
      * @param $options
30 30
      * @return bool
31 31
      */
32
-    public function create($inputFile, $outputFile, $options)
33
-    {
32
+    public function create($inputFile, $outputFile, $options)
33
+    {
34 34
         $this->thumb->sourceFilename = $inputFile;
35 35
         $ext = explode('.', $inputFile);
36 36
         $ext = str_replace('jpeg', 'jpg', strtolower(array_pop($ext)));
37 37
         $options = 'f=' . $ext . '&' . $options;
38 38
         $this->setOptions($options);
39
-        if ($this->thumb->GenerateThumbnail() && $this->thumb->RenderToFile($outputFile)) {
39
+        if ($this->thumb->GenerateThumbnail() && $this->thumb->RenderToFile($outputFile)) {
40 40
             return true;
41
-        } else {
41
+        } else {
42 42
             $this->debugMessages = implode('<br/>', $this->thumb->debugmessages);
43 43
 
44 44
             return false;
@@ -49,17 +49,17 @@  discard block
 block discarded – undo
49 49
      * @param $file
50 50
      * @param string $type
51 51
      */
52
-    public function optimize($file, $type = 'jpg')
53
-    {
54
-        switch ($type) {
52
+    public function optimize($file, $type = 'jpg')
53
+    {
54
+        switch ($type) {
55 55
             case 'jpg':
56 56
                 $ext = $this->fs->takeFileExt($file);
57
-                if ($ext == 'jpeg' || $ext == 'jpg') {
57
+                if ($ext == 'jpeg' || $ext == 'jpg') {
58 58
                     $cmd = '/usr/bin/jpegtran -optimize -progressive -copy none -outfile ' . escapeshellarg($file . '_') . ' ' . escapeshellarg($file);
59 59
                     exec($cmd, $result, $return_var);
60
-                    if ($this->fs->fileSize($file) > $this->fs->fileSize($file . '_')) {
60
+                    if ($this->fs->fileSize($file) > $this->fs->fileSize($file . '_')) {
61 61
                         $this->fs->moveFile($file . '_', $file);
62
-                    } else {
62
+                    } else {
63 63
                         $this->fs->unlink($file . '_');
64 64
                     }
65 65
                 }
@@ -72,11 +72,11 @@  discard block
 block discarded – undo
72 72
     /**
73 73
      * @param $options
74 74
      */
75
-    private function setOptions($options)
76
-    {
75
+    private function setOptions($options)
76
+    {
77 77
         $options = strtr($options, Array("," => "&", "_" => "=", '{' => '[', '}' => ']'));
78 78
         parse_str($options, $params);
79
-        foreach ($params as $key => $value) {
79
+        foreach ($params as $key => $value) {
80 80
             $this->thumb->setParameter($key, $value);
81 81
         }
82 82
     }
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@
 block discarded – undo
74 74
      */
75 75
     private function setOptions($options)
76 76
     {
77
-        $options = strtr($options, Array("," => "&", "_" => "=", '{' => '[', '}' => ']'));
77
+        $options = strtr($options, array("," => "&", "_" => "=", '{' => '[', '}' => ']'));
78 78
         parse_str($options, $params);
79 79
         foreach ($params as $key => $value) {
80 80
             $this->thumb->setParameter($key, $value);
Please login to merge, or discard this patch.
assets/snippets/DocLister/core/controller/site_content.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -440,8 +440,8 @@
 block discarded – undo
440 440
     }
441 441
 
442 442
     /**
443
-     * @param $table
444
-     * @param $sort
443
+     * @param string $table
444
+     * @param string $sort
445 445
      * @return array
446 446
      */
447 447
     protected function injectSortByTV($table, $sort)
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (!defined('MODX_BASE_PATH')) {
2
+if ( ! defined('MODX_BASE_PATH')) {
3 3
     die('HACK???');
4 4
 }
5 5
 
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
         $this->_docs = ($type == 'parents') ? $this->getChildrenList() : $this->getDocList();
59 59
         if ($tvlist != '' && count($this->_docs) > 0) {
60 60
             $tv = $this->extTV->getTVList(array_keys($this->_docs), $tvlist);
61
-            if (!is_array($tv)) {
61
+            if ( ! is_array($tv)) {
62 62
                 $tv = array();
63 63
             }
64 64
             foreach ($tv as $docID => $TVitem) {
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 
279 279
             $where = "WHERE {$where}";
280 280
             $whereArr = array();
281
-            if (!$this->getCFGDef('showNoPublish', 0)) {
281
+            if ( ! $this->getCFGDef('showNoPublish', 0)) {
282 282
                 $whereArr[] = "c.deleted=0 AND c.published=1";
283 283
             }
284 284
 
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
     protected function injectSortByTV($table, $sort)
432 432
     {
433 433
         $out = $this->getExtender('tv', true, true)->injectSortByTV($table, $sort);
434
-        if (!is_array($out) || empty($out)) {
434
+        if ( ! is_array($out) || empty($out)) {
435 435
             $out = array($table, $sort);
436 436
         }
437 437
 
@@ -448,12 +448,12 @@  discard block
 block discarded – undo
448 448
 
449 449
         $tmpWhere = $this->getCFGDef('addWhereList', '');
450 450
         $tmpWhere = sqlHelper::trimLogicalOp($tmpWhere);
451
-        if (!empty($tmpWhere)) {
451
+        if ( ! empty($tmpWhere)) {
452 452
             $where[] = $tmpWhere;
453 453
         }
454 454
 
455 455
         $tmpWhere = sqlHelper::trimLogicalOp($this->_filters['where']);
456
-        if (!empty($tmpWhere)) {
456
+        if ( ! empty($tmpWhere)) {
457 457
             $where[] = $tmpWhere;
458 458
         }
459 459
 
@@ -486,13 +486,13 @@  discard block
 block discarded – undo
486 486
                 $tmpWhere = "((" . $tmpWhere . ") OR c.id IN({$addDocs}))";
487 487
             }
488 488
         }
489
-        if (!empty($tmpWhere)) {
489
+        if ( ! empty($tmpWhere)) {
490 490
             $where[] = $tmpWhere;
491 491
         }
492
-        if (!$this->getCFGDef('showNoPublish', 0)) {
492
+        if ( ! $this->getCFGDef('showNoPublish', 0)) {
493 493
             $where[] = "c.deleted=0 AND c.published=1";
494 494
         }
495
-        if (!empty($where)) {
495
+        if ( ! empty($where)) {
496 496
             $where = "WHERE " . implode(" AND ", $where);
497 497
         } else {
498 498
             $where = '';
Please login to merge, or discard this patch.
Braces   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (!defined('MODX_BASE_PATH')) {
2
+if (!defined('MODX_BASE_PATH')) {
3 3
     die('HACK???');
4 4
 }
5 5
 
@@ -11,8 +11,8 @@  discard block
 block discarded – undo
11 11
  * @license GNU General Public License (GPL), http://www.gnu.org/copyleft/gpl.html
12 12
  * @author Agel_Nash <[email protected]>, kabachello <[email protected]>
13 13
  */
14
-class site_contentDocLister extends DocLister
15
-{
14
+class site_contentDocLister extends DocLister
15
+{
16 16
     /**
17 17
      * Экземпляр экстендера TV
18 18
      *
@@ -32,8 +32,8 @@  discard block
 block discarded – undo
32 32
      * @param array $cfg
33 33
      * @param null $startTime
34 34
      */
35
-    public function __construct($modx, $cfg = array(), $startTime = null)
36
-    {
35
+    public function __construct($modx, $cfg = array(), $startTime = null)
36
+    {
37 37
         parent::__construct($modx, $cfg, $startTime);
38 38
         $this->extTV = $this->getExtender('tv', true, true);
39 39
     }
@@ -41,35 +41,35 @@  discard block
 block discarded – undo
41 41
     /**
42 42
      * @absctract
43 43
      */
44
-    public function getDocs($tvlist = '')
45
-    {
46
-        if ($tvlist == '') {
44
+    public function getDocs($tvlist = '')
45
+    {
46
+        if ($tvlist == '') {
47 47
             $tvlist = $this->getCFGDef('tvList', '');
48 48
         }
49 49
 
50 50
         $this->extTV->getAllTV_Name();
51 51
 
52
-        if ($this->extPaginate = $this->getExtender('paginate')) {
52
+        if ($this->extPaginate = $this->getExtender('paginate')) {
53 53
             $this->extPaginate->init($this);
54
-        } else {
54
+        } else {
55 55
             $this->setConfig(array('start' => 0));
56 56
         }
57 57
         $type = $this->getCFGDef('idType', 'parents');
58 58
         $this->_docs = ($type == 'parents') ? $this->getChildrenList() : $this->getDocList();
59
-        if ($tvlist != '' && count($this->_docs) > 0) {
59
+        if ($tvlist != '' && count($this->_docs) > 0) {
60 60
             $tv = $this->extTV->getTVList(array_keys($this->_docs), $tvlist);
61
-            if (!is_array($tv)) {
61
+            if (!is_array($tv)) {
62 62
                 $tv = array();
63 63
             }
64
-            foreach ($tv as $docID => $TVitem) {
65
-                if (isset($this->_docs[$docID]) && is_array($this->_docs[$docID])) {
64
+            foreach ($tv as $docID => $TVitem) {
65
+                if (isset($this->_docs[$docID]) && is_array($this->_docs[$docID])) {
66 66
                     $this->_docs[$docID] = array_merge($this->_docs[$docID], $TVitem);
67
-                } else {
67
+                } else {
68 68
                     unset($this->_docs[$docID]);
69 69
                 }
70 70
             }
71 71
         }
72
-        if (1 == $this->getCFGDef('tree', '0')) {
72
+        if (1 == $this->getCFGDef('tree', '0')) {
73 73
             $this->treeBuild('id', 'parent');
74 74
         }
75 75
 
@@ -80,24 +80,24 @@  discard block
 block discarded – undo
80 80
      * @param string $tpl
81 81
      * @return string
82 82
      */
83
-    public function _render($tpl = '')
84
-    {
83
+    public function _render($tpl = '')
84
+    {
85 85
         $out = '';
86
-        if ($tpl == '') {
86
+        if ($tpl == '') {
87 87
             $tpl = $this->getCFGDef('tpl', '@CODE:<a href="[+url+]">[+pagetitle+]</a><br />');
88 88
         }
89
-        if ($tpl != '') {
89
+        if ($tpl != '') {
90 90
             $date = $this->getCFGDef('dateSource', 'pub_date');
91 91
 
92 92
             $this->toPlaceholders(count($this->_docs), 1, "display"); // [+display+] - сколько показано на странице.
93 93
 
94 94
             $i = 1;
95 95
             $sysPlh = $this->renameKeyArr($this->_plh, $this->getCFGDef("sysKey", "dl"));
96
-            if (count($this->_docs) > 0) {
96
+            if (count($this->_docs) > 0) {
97 97
                 /**
98 98
                  * @var $extUser user_DL_Extender
99 99
                  */
100
-                if ($extUser = $this->getExtender('user')) {
100
+                if ($extUser = $this->getExtender('user')) {
101 101
                     $extUser->init($this, array('fields' => $this->getCFGDef("userFields", "")));
102 102
                 }
103 103
 
@@ -116,20 +116,20 @@  discard block
 block discarded – undo
116 116
                  */
117 117
                 $extJotCount = $this->getCFGdef('jotcount', 0) ? $this->getExtender('jotcount', true) : null;
118 118
 
119
-                if ($extJotCount) {
119
+                if ($extJotCount) {
120 120
                     $comments = $extJotCount->countComments(array_keys($this->_docs));
121 121
                 }
122 122
 
123 123
                 $this->skippedDocs = 0;
124
-                foreach ($this->_docs as $item) {
124
+                foreach ($this->_docs as $item) {
125 125
                     $this->renderTPL = $tpl;
126
-                    if ($extUser) {
126
+                    if ($extUser) {
127 127
                         $item = $extUser->setUserData($item); //[+user.id.createdby+], [+user.fullname.publishedby+], [+dl.user.publishedby+]....
128 128
                     }
129 129
 
130 130
                     $item['summary'] = $extSummary ? $this->getSummary($item, $extSummary, 'introtext', 'content') : '';
131 131
 
132
-                    if ($extJotCount) {
132
+                    if ($extJotCount) {
133 133
                         $item['jotcount'] = APIHelpers::getkey($comments, $item['id'], 0);
134 134
                     }
135 135
 
@@ -139,53 +139,53 @@  discard block
 block discarded – undo
139 139
 
140 140
                     $item['title'] = ($item['menutitle'] == '' ? $item['pagetitle'] : $item['menutitle']);
141 141
 
142
-                    if ($this->getCFGDef('makeUrl', 1)) {
143
-                        if ($item['type'] == 'reference') {
142
+                    if ($this->getCFGDef('makeUrl', 1)) {
143
+                        if ($item['type'] == 'reference') {
144 144
                             $item['url'] = is_numeric($item['content']) ? $this->modx->makeUrl($item['content'], '', '',
145 145
                                 $this->getCFGDef('urlScheme', '')) : $item['content'];
146
-                        } else {
146
+                        } else {
147 147
                             $item['url'] = $this->modx->makeUrl($item['id'], '', '', $this->getCFGDef('urlScheme', ''));
148 148
                         }
149 149
                     }
150 150
 
151 151
                     $item['date'] = (isset($item[$date]) && $date != 'createdon' && $item[$date] != 0 && $item[$date] == (int)$item[$date]) ? $item[$date] : $item['createdon'];
152 152
                     $item['date'] = $item['date'] + $this->modx->config['server_offset_time'];
153
-                    if ($this->getCFGDef('dateFormat', '%d.%b.%y %H:%M') != '') {
153
+                    if ($this->getCFGDef('dateFormat', '%d.%b.%y %H:%M') != '') {
154 154
                         $item['date'] = strftime($this->getCFGDef('dateFormat', '%d.%b.%y %H:%M'), $item['date']);
155 155
                     }
156 156
 
157 157
                     $findTpl = $this->renderTPL;
158 158
                     $tmp = $this->uniformPrepare($item, $i);
159 159
                     extract($tmp, EXTR_SKIP);
160
-                    if ($this->renderTPL == '') {
160
+                    if ($this->renderTPL == '') {
161 161
                         $this->renderTPL = $findTpl;
162 162
                     }
163 163
 
164
-                    if ($extPrepare) {
164
+                    if ($extPrepare) {
165 165
                         $item = $extPrepare->init($this, array(
166 166
                             'data'      => $item,
167 167
                             'nameParam' => 'prepare'
168 168
                         ));
169
-                        if (is_bool($item) && $item === false) {
169
+                        if (is_bool($item) && $item === false) {
170 170
                             $this->skippedDocs++;
171 171
                             continue;
172 172
                         }
173 173
                     }
174 174
                     $tmp = $this->parseChunk($this->renderTPL, $item);
175 175
 
176
-                    if ($this->getCFGDef('contentPlaceholder', 0) !== 0) {
176
+                    if ($this->getCFGDef('contentPlaceholder', 0) !== 0) {
177 177
                         $this->toPlaceholders($tmp, 1,
178 178
                             "item[" . $i . "]"); // [+item[x]+] – individual placeholder for each iteration documents on this page
179 179
                     }
180 180
                     $out .= $tmp;
181 181
                     $i++;
182 182
                 }
183
-            } else {
183
+            } else {
184 184
                 $noneTPL = $this->getCFGDef("noneTPL", "");
185 185
                 $out = ($noneTPL != '') ? $this->parseChunk($noneTPL, $sysPlh) : '';
186 186
             }
187 187
             $out = $this->renderWrap($out);
188
-        } else {
188
+        } else {
189 189
             $out = 'no template';
190 190
         }
191 191
 
@@ -198,8 +198,8 @@  discard block
 block discarded – undo
198 198
      * @param array $array
199 199
      * @return string
200 200
      */
201
-    public function getJSON($data, $fields, $array = array())
202
-    {
201
+    public function getJSON($data, $fields, $array = array())
202
+    {
203 203
         $out = array();
204 204
         $fields = is_array($fields) ? $fields : explode(",", $fields);
205 205
         $date = $this->getCFGDef('dateSource', 'pub_date');
@@ -219,38 +219,38 @@  discard block
 block discarded – undo
219 219
          */
220 220
         $extE = $this->getExtender('e', true, true);
221 221
 
222
-        foreach ($data as $num => $item) {
222
+        foreach ($data as $num => $item) {
223 223
             $row = $item;
224
-            if ((array('1') == $fields || in_array('summary', $fields)) && $extSummary) {
224
+            if ((array('1') == $fields || in_array('summary', $fields)) && $extSummary) {
225 225
                 $row['summary'] = $this->getSummary($this->_docs[$num], $extSummary, 'introtext', 'content');
226 226
             }
227
-            if (array('1') == $fields || in_array('date', $fields)) {
227
+            if (array('1') == $fields || in_array('date', $fields)) {
228 228
                 $tmp = (isset($this->_docs[$num][$date]) && $date != 'createdon' && $this->_docs[$num][$date] != 0 && $this->_docs[$num][$date] == (int)$this->_docs[$num][$date]) ? $this->_docs[$num][$date] : $this->_docs[$num]['createdon'];
229 229
                 $row['date'] = strftime($this->getCFGDef('dateFormat', '%d.%b.%y %H:%M'),
230 230
                     $tmp + $this->modx->config['server_offset_time']);
231 231
             }
232
-            if (array('1') == $fields || in_array(array('menutitle', 'pagetitle'), $fields)) {
232
+            if (array('1') == $fields || in_array(array('menutitle', 'pagetitle'), $fields)) {
233 233
                 $row['title'] = ($row['menutitle'] == '' ? $row['pagetitle'] : $row['menutitle']);
234 234
             }
235 235
             if ((bool)$this->getCFGDef('makeUrl', 1) && (array('1') == $fields || in_array(array('content', 'type'),
236 236
                         $fields))
237
-            ) {
238
-                if ($row['type'] == 'reference') {
237
+            ) {
238
+                if ($row['type'] == 'reference') {
239 239
                     $row['url'] = is_numeric($row['content']) ? $this->modx->makeUrl($row['content'], '', '',
240 240
                         $this->getCFGDef('urlScheme', '')) : $row['content'];
241
-                } else {
241
+                } else {
242 242
                     $row['url'] = $this->modx->makeUrl($row['id'], '', '', $this->getCFGDef('urlScheme', ''));
243 243
                 }
244 244
             }
245
-            if ($extE && $tmp = $extE->init($this, array('data' => $row))) {
246
-                if (is_array($tmp)) {
245
+            if ($extE && $tmp = $extE->init($this, array('data' => $row))) {
246
+                if (is_array($tmp)) {
247 247
                     $row = $tmp;
248 248
                 }
249 249
             }
250 250
 
251
-            if ($extPrepare) {
251
+            if ($extPrepare) {
252 252
                 $row = $extPrepare->init($this, array('data' => $row));
253
-                if (is_bool($row) && $row === false) {
253
+                if (is_bool($row) && $row === false) {
254 254
                     continue;
255 255
                 }
256 256
             }
@@ -263,31 +263,31 @@  discard block
 block discarded – undo
263 263
     /**
264 264
      * @abstract
265 265
      */
266
-    public function getChildrenCount()
267
-    {
266
+    public function getChildrenCount()
267
+    {
268 268
         $out = 0;
269 269
         $sanitarInIDs = $this->sanitarIn($this->IDs);
270
-        if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) {
270
+        if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) {
271 271
             $where = $this->getCFGDef('addWhereList', '');
272 272
             $where = sqlHelper::trimLogicalOp($where);
273 273
             $where = ($where ? $where . ' AND ' : '') . $this->_filters['where'];
274
-            if ($where != '' && $this->_filters['where'] != '') {
274
+            if ($where != '' && $this->_filters['where'] != '') {
275 275
                 $where .= " AND ";
276 276
             }
277 277
             $where = sqlHelper::trimLogicalOp($where);
278 278
 
279 279
             $where = "WHERE {$where}";
280 280
             $whereArr = array();
281
-            if (!$this->getCFGDef('showNoPublish', 0)) {
281
+            if (!$this->getCFGDef('showNoPublish', 0)) {
282 282
                 $whereArr[] = "c.deleted=0 AND c.published=1";
283 283
             }
284 284
 
285 285
             $tbl_site_content = $this->getTable('site_content', 'c');
286 286
 
287
-            if ($sanitarInIDs != "''") {
288
-                switch ($this->getCFGDef('idType', 'parents')) {
287
+            if ($sanitarInIDs != "''") {
288
+                switch ($this->getCFGDef('idType', 'parents')) {
289 289
                     case 'parents':
290
-                        switch ($this->getCFGDef('showParent', '0')) {
290
+                        switch ($this->getCFGDef('showParent', '0')) {
291 291
                             case '-1':
292 292
                                 $tmpWhere = "c.parent IN (" . $sanitarInIDs . ")";
293 293
                                 break;
@@ -299,10 +299,10 @@  discard block
 block discarded – undo
299 299
                                 $tmpWhere = "(c.parent IN ({$sanitarInIDs}) OR c.id IN({$sanitarInIDs}))";
300 300
                                 break;
301 301
                         }
302
-                        if (($addDocs = $this->getCFGDef('documents', '')) != '') {
302
+                        if (($addDocs = $this->getCFGDef('documents', '')) != '') {
303 303
                             $addDocs = $this->sanitarIn($this->cleanIDs($addDocs));
304 304
                             $whereArr[] = "((" . $tmpWhere . ") OR c.id IN({$addDocs}))";
305
-                        } else {
305
+                        } else {
306 306
                             $whereArr[] = $tmpWhere;
307 307
                         }
308 308
 
@@ -315,14 +315,14 @@  discard block
 block discarded – undo
315 315
             $from = $tbl_site_content . " " . $this->_filters['join'];
316 316
             $where = sqlHelper::trimLogicalOp($where);
317 317
 
318
-            if (trim($where) != 'WHERE') {
318
+            if (trim($where) != 'WHERE') {
319 319
                 $where .= " AND ";
320 320
             }
321 321
 
322 322
             $where .= implode(" AND ", $whereArr);
323 323
             $where = sqlHelper::trimLogicalOp($where);
324 324
 
325
-            if (trim($where) == 'WHERE') {
325
+            if (trim($where) == 'WHERE') {
326 326
                 $where = '';
327 327
             }
328 328
             $group = $this->getGroupSQL($this->getCFGDef('groupBy', 'c.id'));
@@ -339,11 +339,11 @@  discard block
 block discarded – undo
339 339
     /**
340 340
      * @return array
341 341
      */
342
-    protected function getDocList()
343
-    {
342
+    protected function getDocList()
343
+    {
344 344
         $out = array();
345 345
         $sanitarInIDs = $this->sanitarIn($this->IDs);
346
-        if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) {
346
+        if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) {
347 347
             $where = $this->getCFGDef('addWhereList', '');
348 348
             $where = sqlHelper::trimLogicalOp($where);
349 349
 
@@ -351,21 +351,21 @@  discard block
 block discarded – undo
351 351
             $where = sqlHelper::trimLogicalOp($where);
352 352
 
353 353
             $tbl_site_content = $this->getTable('site_content', 'c');
354
-            if ($sanitarInIDs != "''") {
354
+            if ($sanitarInIDs != "''") {
355 355
                 $where .= ($where ? " AND " : "") . "c.id IN ({$sanitarInIDs}) AND";
356 356
             }
357 357
             $where = sqlHelper::trimLogicalOp($where);
358 358
 
359
-            if ($this->getCFGDef('showNoPublish', 0)) {
360
-                if ($where != '') {
359
+            if ($this->getCFGDef('showNoPublish', 0)) {
360
+                if ($where != '') {
361 361
                     $where = "WHERE {$where}";
362
-                } else {
362
+                } else {
363 363
                     $where = '';
364 364
                 }
365
-            } else {
366
-                if ($where != '') {
365
+            } else {
366
+                if ($where != '') {
367 367
                     $where = "WHERE {$where} AND ";
368
-                } else {
368
+                } else {
369 369
                     $where = "WHERE {$where} ";
370 370
                 }
371 371
                 $where .= "c.deleted=0 AND c.published=1";
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
 
385 385
             $rows = $this->modx->db->makeArray($rs);
386 386
 
387
-            foreach ($rows as $item) {
387
+            foreach ($rows as $item) {
388 388
                 $out[$item['id']] = $item;
389 389
             }
390 390
         }
@@ -396,19 +396,19 @@  discard block
 block discarded – undo
396 396
      * @param string $id
397 397
      * @return array
398 398
      */
399
-    public function getChildrenFolder($id)
400
-    {
399
+    public function getChildrenFolder($id)
400
+    {
401 401
         $where = $this->getCFGDef('addWhereFolder', '');
402 402
         $where = sqlHelper::trimLogicalOp($where);
403
-        if ($where != '') {
403
+        if ($where != '') {
404 404
             $where .= " AND ";
405 405
         }
406 406
 
407 407
         $tbl_site_content = $this->getTable('site_content', 'c');
408 408
         $sanitarInIDs = $this->sanitarIn($id);
409
-        if ($this->getCFGDef('showNoPublish', 0)) {
409
+        if ($this->getCFGDef('showNoPublish', 0)) {
410 410
             $where = "WHERE {$where} c.parent IN ({$sanitarInIDs}) AND c.isfolder=1";
411
-        } else {
411
+        } else {
412 412
             $where = "WHERE {$where} c.parent IN ({$sanitarInIDs}) AND c.deleted=0 AND c.published=1 AND c.isfolder=1";
413 413
         }
414 414
 
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
 
417 417
         $rows = $this->modx->db->makeArray($rs);
418 418
         $out = array();
419
-        foreach ($rows as $item) {
419
+        foreach ($rows as $item) {
420 420
             $out[] = $item['id'];
421 421
         }
422 422
 
@@ -428,10 +428,10 @@  discard block
 block discarded – undo
428 428
      * @param $sort
429 429
      * @return array
430 430
      */
431
-    protected function injectSortByTV($table, $sort)
432
-    {
431
+    protected function injectSortByTV($table, $sort)
432
+    {
433 433
         $out = $this->getExtender('tv', true, true)->injectSortByTV($table, $sort);
434
-        if (!is_array($out) || empty($out)) {
434
+        if (!is_array($out) || empty($out)) {
435 435
             $out = array($table, $sort);
436 436
         }
437 437
 
@@ -441,19 +441,19 @@  discard block
 block discarded – undo
441 441
     /**
442 442
      * @return array
443 443
      */
444
-    protected function getChildrenList()
445
-    {
444
+    protected function getChildrenList()
445
+    {
446 446
         $where = array();
447 447
         $out = array();
448 448
 
449 449
         $tmpWhere = $this->getCFGDef('addWhereList', '');
450 450
         $tmpWhere = sqlHelper::trimLogicalOp($tmpWhere);
451
-        if (!empty($tmpWhere)) {
451
+        if (!empty($tmpWhere)) {
452 452
             $where[] = $tmpWhere;
453 453
         }
454 454
 
455 455
         $tmpWhere = sqlHelper::trimLogicalOp($this->_filters['where']);
456
-        if (!empty($tmpWhere)) {
456
+        if (!empty($tmpWhere)) {
457 457
             $where[] = $tmpWhere;
458 458
         }
459 459
 
@@ -464,8 +464,8 @@  discard block
 block discarded – undo
464 464
         $sanitarInIDs = $this->sanitarIn($this->IDs);
465 465
 
466 466
         $tmpWhere = null;
467
-        if ($sanitarInIDs != "''") {
468
-            switch ($this->getCFGDef('showParent', '0')) {
467
+        if ($sanitarInIDs != "''") {
468
+            switch ($this->getCFGDef('showParent', '0')) {
469 469
                 case '-1':
470 470
                     $tmpWhere = "c.parent IN (" . $sanitarInIDs . ")";
471 471
                     break;
@@ -478,29 +478,29 @@  discard block
 block discarded – undo
478 478
                     break;
479 479
             }
480 480
         }
481
-        if (($addDocs = $this->getCFGDef('documents', '')) != '') {
481
+        if (($addDocs = $this->getCFGDef('documents', '')) != '') {
482 482
             $addDocs = $this->sanitarIn($this->cleanIDs($addDocs));
483
-            if (empty($tmpWhere)) {
483
+            if (empty($tmpWhere)) {
484 484
                 $tmpWhere = "c.id IN({$addDocs})";
485
-            } else {
485
+            } else {
486 486
                 $tmpWhere = "((" . $tmpWhere . ") OR c.id IN({$addDocs}))";
487 487
             }
488 488
         }
489
-        if (!empty($tmpWhere)) {
489
+        if (!empty($tmpWhere)) {
490 490
             $where[] = $tmpWhere;
491 491
         }
492
-        if (!$this->getCFGDef('showNoPublish', 0)) {
492
+        if (!$this->getCFGDef('showNoPublish', 0)) {
493 493
             $where[] = "c.deleted=0 AND c.published=1";
494 494
         }
495
-        if (!empty($where)) {
495
+        if (!empty($where)) {
496 496
             $where = "WHERE " . implode(" AND ", $where);
497
-        } else {
497
+        } else {
498 498
             $where = '';
499 499
         }
500 500
         $fields = $this->getCFGDef('selectFields', 'c.*');
501 501
         $group = $this->getGroupSQL($this->getCFGDef('groupBy', 'c.id'));
502 502
 
503
-        if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) {
503
+        if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) {
504 504
             $sql = $this->dbQuery("SELECT {$fields} FROM " . $from . " " . $where . " " .
505 505
                 $group . " " .
506 506
                 $sort . " " .
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
 
510 510
             $rows = $this->modx->db->makeArray($sql);
511 511
 
512
-            foreach ($rows as $item) {
512
+            foreach ($rows as $item) {
513 513
                 $out[$item['id']] = $item;
514 514
             }
515 515
         }
@@ -522,10 +522,10 @@  discard block
 block discarded – undo
522 522
      * @param string $type
523 523
      * @return string
524 524
      */
525
-    public function changeSortType($field, $type)
526
-    {
525
+    public function changeSortType($field, $type)
526
+    {
527 527
         $type = trim($type);
528
-        switch (strtoupper($type)) {
528
+        switch (strtoupper($type)) {
529 529
             case 'TVDATETIME':
530 530
                 $field = "STR_TO_DATE(" . $field . ",'%d-%m-%Y %H:%i:%s')";
531 531
                 break;
Please login to merge, or discard this patch.
Upper-Lower-Casing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
             }
277 277
             $where = sqlHelper::trimLogicalOp($where);
278 278
 
279
-            $where = "WHERE {$where}";
279
+            $where = "where {$where}";
280 280
             $whereArr = array();
281 281
             if (!$this->getCFGDef('showNoPublish', 0)) {
282 282
                 $whereArr[] = "c.deleted=0 AND c.published=1";
@@ -358,15 +358,15 @@  discard block
 block discarded – undo
358 358
 
359 359
             if ($this->getCFGDef('showNoPublish', 0)) {
360 360
                 if ($where != '') {
361
-                    $where = "WHERE {$where}";
361
+                    $where = "where {$where}";
362 362
                 } else {
363 363
                     $where = '';
364 364
                 }
365 365
             } else {
366 366
                 if ($where != '') {
367
-                    $where = "WHERE {$where} AND ";
367
+                    $where = "where {$where} AND ";
368 368
                 } else {
369
-                    $where = "WHERE {$where} ";
369
+                    $where = "where {$where} ";
370 370
                 }
371 371
                 $where .= "c.deleted=0 AND c.published=1";
372 372
             }
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
 
381 381
             $limit = $this->LimitSQL($this->getCFGDef('queryLimit', 0));
382 382
 
383
-            $rs = $this->dbQuery("SELECT {$fields} FROM {$tbl_site_content} {$where} {$group} {$sort} {$limit}");
383
+            $rs = $this->dbQuery("select {$fields} FROM {$tbl_site_content} {$where} {$group} {$sort} {$limit}");
384 384
 
385 385
             $rows = $this->modx->db->makeArray($rs);
386 386
 
@@ -407,9 +407,9 @@  discard block
 block discarded – undo
407 407
         $tbl_site_content = $this->getTable('site_content', 'c');
408 408
         $sanitarInIDs = $this->sanitarIn($id);
409 409
         if ($this->getCFGDef('showNoPublish', 0)) {
410
-            $where = "WHERE {$where} c.parent IN ({$sanitarInIDs}) AND c.isfolder=1";
410
+            $where = "where {$where} c.parent IN ({$sanitarInIDs}) AND c.isfolder=1";
411 411
         } else {
412
-            $where = "WHERE {$where} c.parent IN ({$sanitarInIDs}) AND c.deleted=0 AND c.published=1 AND c.isfolder=1";
412
+            $where = "where {$where} c.parent IN ({$sanitarInIDs}) AND c.deleted=0 AND c.published=1 AND c.isfolder=1";
413 413
         }
414 414
 
415 415
         $rs = $this->dbQuery("SELECT id FROM {$tbl_site_content} {$where}");
@@ -501,7 +501,7 @@  discard block
 block discarded – undo
501 501
         $group = $this->getGroupSQL($this->getCFGDef('groupBy', 'c.id'));
502 502
 
503 503
         if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) {
504
-            $sql = $this->dbQuery("SELECT {$fields} FROM " . $from . " " . $where . " " .
504
+            $sql = $this->dbQuery("select {$fields} FROM " . $from . " " . $where . " " .
505 505
                 $group . " " .
506 506
                 $sort . " " .
507 507
                 $this->LimitSQL($this->getCFGDef('queryLimit', 0))
Please login to merge, or discard this patch.
assets/snippets/DocLister/core/extender/prepare.extender.inc 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
     private $_store = array();
17 17
 
18 18
     /**
19
-     * @param $name
19
+     * @param string $name
20 20
      * @param $val
21 21
      */
22 22
     public function setStore($name,$val){
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
     }
25 25
 
26 26
     /**
27
-     * @param $name
27
+     * @param string $name
28 28
      * @return mixed
29 29
      */
30 30
     public function getStore($name){
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (!defined('MODX_BASE_PATH')) {
2
+if ( ! defined('MODX_BASE_PATH')) {
3 3
     die('HACK???');
4 4
 }
5 5
 
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
             $out = $params['data'];
60 60
         }
61 61
 
62
-        return (!empty($ret) && is_scalar($ret) && isset($out[$ret])) ? $out[$ret] : $out;
62
+        return ( ! empty($ret) && is_scalar($ret) && isset($out[$ret])) ? $out[$ret] : $out;
63 63
     }
64 64
 
65 65
     /**
Please login to merge, or discard this patch.
assets/snippets/DocLister/lib/DLpaginate.class.php 3 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
     private $pagination;
53 53
 
54 54
     /**
55
-     * @param $mode
55
+     * @param string $mode
56 56
      * @param array $config
57 57
      * @return $this
58 58
      */
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 
65 65
     #Total items
66 66
     /**
67
-     * @param $value
67
+     * @param integer $value
68 68
      * @return $this
69 69
      */
70 70
     public function items($value) {
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 
95 95
     #Current page
96 96
     /**
97
-     * @param $value
97
+     * @param integer $value
98 98
      * @return $this
99 99
      */
100 100
     public function currentPage($value) {
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 
239 239
     /**
240 240
      * @param $id
241
-     * @return mixed|string
241
+     * @return string
242 242
      */
243 243
     public function get_pagenum_link($id) {
244 244
         $flag = (strpos($this->target, '?') === false);
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
     }
368 368
 
369 369
     /**
370
-     * @param $tpl
370
+     * @param string $tpl
371 371
      * @param $num
372 372
      * @return mixed
373 373
      */
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
     public function getOutput()
252 252
     {
253 253
         $out = '';
254
-        if (!$this->calculate && $this->calculate() && !empty($this->pagination)) {
254
+        if ( ! $this->calculate && $this->calculate() && ! empty($this->pagination)) {
255 255
             $out = str_replace(array("[+class+]", "[+wrap+]"), array($this->className, $this->pagination),
256 256
                     $this->mainTpl) . "\n";
257 257
         }
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
         if ($this->total_pages < 0) {
320 320
             $error = true;
321 321
         }
322
-        if (!is_int($this->limit)) {
322
+        if ( ! is_int($this->limit)) {
323 323
             $error = true;
324 324
         }
325 325
         if ($error) {
Please login to merge, or discard this patch.
Braces   +74 added lines, -72 removed lines patch added patch discarded remove patch
@@ -3,8 +3,8 @@  discard block
 block discarded – undo
3 3
 /**
4 4
  * Class DLpaginate
5 5
  */
6
-class DLpaginate
7
-{
6
+class DLpaginate
7
+{
8 8
     /**
9 9
      * Script Name: *Digg Style Paginator Class
10 10
      * Script URI: http://www.mis-algoritmos.com/2007/05/27/digg-style-pagination-class/
@@ -57,8 +57,8 @@  discard block
 block discarded – undo
57 57
      * @param array $config
58 58
      * @return $this
59 59
      */
60
-    public function setMode($mode, array $config = array())
61
-    {
60
+    public function setMode($mode, array $config = array())
61
+    {
62 62
         $this->mode = $mode;
63 63
         $this->modeConfig = $config;
64 64
 
@@ -71,8 +71,8 @@  discard block
 block discarded – undo
71 71
      * @param $value
72 72
      * @return $this
73 73
      */
74
-    public function items($value)
75
-    {
74
+    public function items($value)
75
+    {
76 76
         $this->total_pages = (int)$value;
77 77
 
78 78
         return $this;
@@ -84,8 +84,8 @@  discard block
 block discarded – undo
84 84
      * @param $value
85 85
      * @return $this
86 86
      */
87
-    public function limit($value)
88
-    {
87
+    public function limit($value)
88
+    {
89 89
         $this->limit = (int)$value;
90 90
 
91 91
         return $this;
@@ -97,8 +97,8 @@  discard block
 block discarded – undo
97 97
      * @param $value
98 98
      * @return $this
99 99
      */
100
-    public function target($value)
101
-    {
100
+    public function target($value)
101
+    {
102 102
         $this->target = $value;
103 103
 
104 104
         return $this;
@@ -110,8 +110,8 @@  discard block
 block discarded – undo
110 110
      * @param $value
111 111
      * @return $this
112 112
      */
113
-    public function currentPage($value)
114
-    {
113
+    public function currentPage($value)
114
+    {
115 115
         $this->page = (int)$value;
116 116
 
117 117
         return $this;
@@ -123,8 +123,8 @@  discard block
 block discarded – undo
123 123
      * @param $value
124 124
      * @return $this
125 125
      */
126
-    public function adjacents($value)
127
-    {
126
+    public function adjacents($value)
127
+    {
128 128
         $this->adjacents = (int)$value;
129 129
 
130 130
         return $this;
@@ -136,8 +136,8 @@  discard block
 block discarded – undo
136 136
      * @param string $value
137 137
      * @return $this
138 138
      */
139
-    public function showCounter($value = "")
140
-    {
139
+    public function showCounter($value = "")
140
+    {
141 141
         $this->showCounter = ($value === true) ? true : false;
142 142
 
143 143
         return $this;
@@ -149,8 +149,8 @@  discard block
 block discarded – undo
149 149
      * @param string $value
150 150
      * @return $this
151 151
      */
152
-    public function changeClass($value = "")
153
-    {
152
+    public function changeClass($value = "")
153
+    {
154 154
         $this->className = $value;
155 155
 
156 156
         return $this;
@@ -160,8 +160,8 @@  discard block
 block discarded – undo
160 160
      * @param $value
161 161
      * @return $this
162 162
      */
163
-    public function mainTpl($value)
164
-    {
163
+    public function mainTpl($value)
164
+    {
165 165
         $this->mainTpl = $value;
166 166
 
167 167
         return $this;
@@ -171,8 +171,8 @@  discard block
 block discarded – undo
171 171
      * @param $value
172 172
      * @return $this
173 173
      */
174
-    public function nextLabel($value)
175
-    {
174
+    public function nextLabel($value)
175
+    {
176 176
         $this->nextT = $value;
177 177
 
178 178
         return $this;
@@ -182,8 +182,8 @@  discard block
 block discarded – undo
182 182
      * @param $value
183 183
      * @return $this
184 184
      */
185
-    public function nextIcon($value)
186
-    {
185
+    public function nextIcon($value)
186
+    {
187 187
         $this->nextI = $value;
188 188
 
189 189
         return $this;
@@ -193,8 +193,8 @@  discard block
 block discarded – undo
193 193
      * @param $value
194 194
      * @return $this
195 195
      */
196
-    public function prevLabel($value)
197
-    {
196
+    public function prevLabel($value)
197
+    {
198 198
         $this->prevT = $value;
199 199
 
200 200
         return $this;
@@ -204,8 +204,8 @@  discard block
 block discarded – undo
204 204
      * @param $value
205 205
      * @return $this
206 206
      */
207
-    public function prevIcon($value)
208
-    {
207
+    public function prevIcon($value)
208
+    {
209 209
         $this->prevI = $value;
210 210
 
211 211
         return $this;
@@ -217,8 +217,8 @@  discard block
 block discarded – undo
217 217
      * @param string $value
218 218
      * @return $this
219 219
      */
220
-    public function parameterName($value = "")
221
-    {
220
+    public function parameterName($value = "")
221
+    {
222 222
         $this->parameterName = $value;
223 223
 
224 224
         return $this;
@@ -230,9 +230,9 @@  discard block
 block discarded – undo
230 230
      * @param string $value
231 231
      * @return $this
232 232
      */
233
-    public function urlFriendly($value = "%")
234
-    {
235
-        if (preg_match('/^\s/', $value)) {
233
+    public function urlFriendly($value = "%")
234
+    {
235
+        if (preg_match('/^\s/', $value)) {
236 236
             $this->urlF = false;
237 237
         }
238 238
         $this->urlF = $value;
@@ -240,18 +240,18 @@  discard block
 block discarded – undo
240 240
         return $this;
241 241
     }
242 242
 
243
-    public function show()
244
-    {
243
+    public function show()
244
+    {
245 245
         echo $this->getOutput();
246 246
     }
247 247
 
248 248
     /**
249 249
      * @return string
250 250
      */
251
-    public function getOutput()
252
-    {
251
+    public function getOutput()
252
+    {
253 253
         $out = '';
254
-        if (!$this->calculate && $this->calculate() && !empty($this->pagination)) {
254
+        if (!$this->calculate && $this->calculate() && !empty($this->pagination)) {
255 255
             $out = str_replace(array("[+class+]", "[+wrap+]"), array($this->className, $this->pagination),
256 256
                     $this->mainTpl) . "\n";
257 257
         }
@@ -263,9 +263,9 @@  discard block
 block discarded – undo
263 263
      * @param $page
264 264
      * @return int|mixed
265 265
      */
266
-    protected function getPageQuery($page)
267
-    {
268
-        switch ($this->mode) {
266
+    protected function getPageQuery($page)
267
+    {
268
+        switch ($this->mode) {
269 269
             case 'offset':
270 270
                 $display = isset($this->modeConfig['display']) ? $this->modeConfig['display'] : 0;
271 271
                 $out = $display * ($page - 1);
@@ -284,15 +284,15 @@  discard block
 block discarded – undo
284 284
      * @param $id
285 285
      * @return mixed|string
286 286
      */
287
-    public function get_pagenum_link($id)
288
-    {
287
+    public function get_pagenum_link($id)
288
+    {
289 289
         $flag = (strpos($this->target, '?') === false);
290 290
         $value = $this->getPageQuery($id);
291
-        if ($flag && $this->urlF) {
291
+        if ($flag && $this->urlF) {
292 292
             $out = str_replace($this->urlF, $value, $this->target);
293
-        } else {
293
+        } else {
294 294
             $out = $this->target;
295
-            if ($id > 1) {
295
+            if ($id > 1) {
296 296
                 $out .= ($flag ? "?" : "&") . $this->parameterName . "=" . $value;
297 297
             }
298 298
         }
@@ -303,26 +303,26 @@  discard block
 block discarded – undo
303 303
     /**
304 304
      * @return bool
305 305
      */
306
-    public function calculate()
307
-    {
306
+    public function calculate()
307
+    {
308 308
         $this->pagination = "";
309 309
         $this->calculate = true;
310 310
         $error = false;
311 311
 
312
-        if ($this->urlF && $this->urlF != '%' && strpos($this->target, $this->urlF) === false) {
312
+        if ($this->urlF && $this->urlF != '%' && strpos($this->target, $this->urlF) === false) {
313 313
             //Es necesario especificar el comodin para sustituir
314 314
             $error = true;
315
-        } elseif ($this->urlF && $this->urlF == '%' && strpos($this->target, $this->urlF) === false) {
315
+        } elseif ($this->urlF && $this->urlF == '%' && strpos($this->target, $this->urlF) === false) {
316 316
             $error = true;
317 317
         }
318 318
 
319
-        if ($this->total_pages < 0) {
319
+        if ($this->total_pages < 0) {
320 320
             $error = true;
321 321
         }
322
-        if (!is_int($this->limit)) {
322
+        if (!is_int($this->limit)) {
323 323
             $error = true;
324 324
         }
325
-        if ($error) {
325
+        if ($error) {
326 326
             return false;
327 327
         }
328 328
 
@@ -338,26 +338,28 @@  discard block
 block discarded – undo
338 338
                 Now we apply our rules and draw the pagination object.
339 339
                 We're actually saving the code to a variable in case we want to draw it more than once.
340 340
         */
341
-        if ($lastpage > 1) {
342
-            if ($this->page) {
343
-                if ($this->page > 1) {
341
+        if ($lastpage > 1) {
342
+            if ($this->page) {
343
+                if ($this->page > 1) {
344 344
                     $this->pagination .= $this->firstT ? $this->renderItemTPL($this->firstT, 0) : '';
345 345
                     $this->pagination .= $this->prevT ? $this->renderItemTPL($this->prevT, $prev) : '';
346
-                } else {
346
+                } else {
347 347
                     $this->pagination .= $this->firstI ? $this->renderItemTPL($this->firstI, 0) : '';
348 348
                     $this->pagination .= $this->prevI ? $this->renderItemTPL($this->prevI, $prev) : '';
349 349
                 }
350 350
             }
351 351
             //pages
352
-            if ($lastpage < 7 + ($this->adjacents * 2)) { //not enough pages to bother breaking it up
353
-                for ($counter = 1; $counter <= $lastpage; $counter++) {
352
+            if ($lastpage < 7 + ($this->adjacents * 2)) {
353
+//not enough pages to bother breaking it up
354
+                for ($counter = 1; $counter <= $lastpage; $counter++) {
354 355
                     $tpl = ($counter == $this->page) ? $this->currentT : $this->numberT;
355 356
                     $this->pagination .= $this->renderItemTPL($tpl, $counter);
356 357
                 }
357
-            } elseif ($lastpage > 5 + ($this->adjacents * 2)) { //enough pages to hide some
358
+            } elseif ($lastpage > 5 + ($this->adjacents * 2)) {
359
+//enough pages to hide some
358 360
                 //close to beginning; only hide later pages
359
-                if ($this->page < 1 + ($this->adjacents * 2)) {
360
-                    for ($counter = 1; $counter < 4 + ($this->adjacents * 2); $counter++) {
361
+                if ($this->page < 1 + ($this->adjacents * 2)) {
362
+                    for ($counter = 1; $counter < 4 + ($this->adjacents * 2); $counter++) {
361 363
                         $tpl = ($counter == $this->page) ? $this->currentT : $this->numberT;
362 364
                         $this->pagination .= $this->renderItemTPL($tpl, $counter);
363 365
                     }
@@ -365,12 +367,12 @@  discard block
 block discarded – undo
365 367
                     $this->pagination .= $this->renderItemTPL($this->numberT, $lpm1);
366 368
                     $this->pagination .= $this->renderItemTPL($this->numberT, $lastpage);
367 369
                 } //in middle; hide some front and some back
368
-                elseif ($lastpage - ($this->adjacents * 2) > $this->page && $this->page > ($this->adjacents * 2)) {
370
+                elseif ($lastpage - ($this->adjacents * 2) > $this->page && $this->page > ($this->adjacents * 2)) {
369 371
                     $this->pagination .= $this->renderItemTPL($this->numberT, 1);
370 372
                     $this->pagination .= $this->renderItemTPL($this->numberT, 2);
371 373
                     $this->pagination .= $this->renderItemTPL($this->dotsT, 3);
372 374
 
373
-                    for ($counter = $this->page - $this->adjacents; $counter <= $this->page + $this->adjacents; $counter++) {
375
+                    for ($counter = $this->page - $this->adjacents; $counter <= $this->page + $this->adjacents; $counter++) {
374 376
                         $tpl = ($counter == $this->page) ? $this->currentT : $this->numberT;
375 377
                         $this->pagination .= $this->renderItemTPL($tpl, $counter);
376 378
                     }
@@ -378,27 +380,27 @@  discard block
 block discarded – undo
378 380
                     $this->pagination .= $this->renderItemTPL($this->numberT, $lpm1);
379 381
                     $this->pagination .= $this->renderItemTPL($this->numberT, $lastpage);
380 382
                 } //close to end; only hide early pages
381
-                else {
383
+                else {
382 384
                     $this->pagination .= $this->renderItemTPL($this->numberT, 1);
383 385
                     $this->pagination .= $this->renderItemTPL($this->numberT, 2);
384 386
                     $this->pagination .= $this->renderItemTPL($this->dotsT, 3);
385 387
 
386
-                    for ($counter = $lastpage - (2 + ($this->adjacents * 2)); $counter <= $lastpage; $counter++) {
388
+                    for ($counter = $lastpage - (2 + ($this->adjacents * 2)); $counter <= $lastpage; $counter++) {
387 389
                         $tpl = ($counter == $this->page) ? $this->currentT : $this->numberT;
388 390
                         $this->pagination .= $this->renderItemTPL($tpl, $counter);
389 391
                     }
390 392
                 }
391 393
             }
392
-            if ($this->page) {
393
-                if ($this->page < $counter - 1) {
394
+            if ($this->page) {
395
+                if ($this->page < $counter - 1) {
394 396
                     $this->pagination .= $this->nextT ? $this->renderItemTPL($this->nextT, $next) : '';
395 397
                     $this->pagination .= $this->lastT ? $this->renderItemTPL($this->lastT, $lastpage) : '';
396
-                } else {
398
+                } else {
397 399
                     $this->pagination .= $this->nextI ? $this->renderItemTPL($this->nextI, $next) : '';
398 400
                     $this->pagination .= $this->lastI ? $this->renderItemTPL($this->lastI, $lastpage) : '';
399 401
                 }
400 402
 
401
-                if ($this->showCounter) {
403
+                if ($this->showCounter) {
402 404
                     $this->pagination .= "<div class=\"pagination_data\">($this->total_pages Pages)</div>";
403 405
                 }
404 406
             }
@@ -412,8 +414,8 @@  discard block
 block discarded – undo
412 414
      * @param $num
413 415
      * @return mixed
414 416
      */
415
-    protected function renderItemTPL($tpl, $num)
416
-    {
417
+    protected function renderItemTPL($tpl, $num)
418
+    {
417 419
         return str_replace(array('[+num+]', '[+link+]'), array($num, $this->get_pagenum_link($num)), $tpl);
418 420
     }
419 421
 }
Please login to merge, or discard this patch.
assets/snippets/DocLister/lib/DLphx.class.php 3 patches
Doc Comments   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
     // Parser: Preparation, cleaning and checkup
74 74
     /**
75 75
      * @param string $template
76
-     * @return mixed|string
76
+     * @return string
77 77
      */
78 78
     public function Parse($template = '')
79 79
     {
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
     // Parser: modifier detection and eXtended processing if needed
222 222
     /**
223 223
      * @param $input
224
-     * @param $modifiers
224
+     * @param string $modifiers
225 225
      * @return mixed|null|string
226 226
      */
227 227
     public function Filter($input, $modifiers)
@@ -553,8 +553,8 @@  discard block
 block discarded – undo
553 553
     // positive userid = manager, negative integer = webuser
554 554
     /**
555 555
      * @param $userid
556
-     * @param $field
557
-     * @return mixed
556
+     * @param string $field
557
+     * @return string
558 558
      */
559 559
     public function ModUser($userid, $field)
560 560
     {
@@ -609,7 +609,7 @@  discard block
 block discarded – undo
609 609
 
610 610
     // Returns the value of a PHx/MODx placeholder.
611 611
     /**
612
-     * @param $name
612
+     * @param string $name
613 613
      * @return mixed
614 614
      */
615 615
     public function getPHxVariable($name)
@@ -627,8 +627,8 @@  discard block
 block discarded – undo
627 627
 
628 628
     // Sets a placeholder variable which can only be access by PHx
629 629
     /**
630
-     * @param $name
631
-     * @param $value
630
+     * @param string $name
631
+     * @param string $value
632 632
      */
633 633
     public function setPHxVariable($name, $value)
634 634
     {
@@ -637,9 +637,9 @@  discard block
 block discarded – undo
637 637
 
638 638
     //mbstring
639 639
     /**
640
-     * @param $str
641
-     * @param $s
642
-     * @param null $l
640
+     * @param string $str
641
+     * @param integer $s
642
+     * @param integer $l
643 643
      * @return string
644 644
      */
645 645
     public function substr($str, $s, $l = null)
@@ -649,7 +649,7 @@  discard block
 block discarded – undo
649 649
     }
650 650
 
651 651
     /**
652
-     * @param $str
652
+     * @param string $str
653 653
      * @return int
654 654
      */
655 655
     public function strlen($str)
@@ -659,7 +659,7 @@  discard block
 block discarded – undo
659 659
     }
660 660
 
661 661
     /**
662
-     * @param $str
662
+     * @param string $str
663 663
      * @return string
664 664
      */
665 665
     public function strtolower($str)
@@ -669,7 +669,7 @@  discard block
 block discarded – undo
669 669
     }
670 670
 
671 671
     /**
672
-     * @param $str
672
+     * @param string $str
673 673
      * @return string
674 674
      */
675 675
     public function strtoupper($str)
@@ -679,7 +679,7 @@  discard block
 block discarded – undo
679 679
     }
680 680
 
681 681
     /**
682
-     * @param $str
682
+     * @param string $str
683 683
      * @return string
684 684
      */
685 685
     public function ucfirst($str)
@@ -690,7 +690,7 @@  discard block
 block discarded – undo
690 690
     }
691 691
 
692 692
     /**
693
-     * @param $str
693
+     * @param string $str
694 694
      * @return string
695 695
      */
696 696
     public function lcfirst($str)
@@ -701,7 +701,7 @@  discard block
 block discarded – undo
701 701
     }
702 702
 
703 703
     /**
704
-     * @param $str
704
+     * @param string $str
705 705
      * @return string
706 706
      */
707 707
     public function ucwords($str)
@@ -712,7 +712,7 @@  discard block
 block discarded – undo
712 712
     }
713 713
 
714 714
     /**
715
-     * @param $str
715
+     * @param string $str
716 716
      * @return string
717 717
      */
718 718
     public function strrev($str)
@@ -722,7 +722,7 @@  discard block
 block discarded – undo
722 722
     }
723 723
 
724 724
     /**
725
-     * @param $str
725
+     * @param string $str
726 726
      * @return string
727 727
      */
728 728
     public function str_shuffle($str)
@@ -733,7 +733,7 @@  discard block
 block discarded – undo
733 733
     }
734 734
 
735 735
     /**
736
-     * @param $str
736
+     * @param string $str
737 737
      * @return int
738 738
      */
739 739
     public function str_word_count($str)
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
                     default:
201 201
                         $this->Log("MODx / PHx placeholder variable: " . $input);
202 202
                         // Check if placeholder is set
203
-                        if (!array_key_exists($input, $this->placeholders) && !array_key_exists($input,
203
+                        if ( ! array_key_exists($input, $this->placeholders) && ! array_key_exists($input,
204 204
                                 $modx->placeholders)
205 205
                         ) {
206 206
                             // not set so try again later.
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
                     case "show":
310 310
                         $conditional = implode(' ', $condition);
311 311
                         $isvalid = intval(eval("return (" . $conditional . ");"));
312
-                        if (!$isvalid) {
312
+                        if ( ! $isvalid) {
313 313
                             $output = null;
314 314
                         }
315 315
                         break;
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
                     case "else":
326 326
                         $conditional = implode(' ', $condition);
327 327
                         $isvalid = intval(eval("return (" . $conditional . ");"));
328
-                        if (!$isvalid) {
328
+                        if ( ! $isvalid) {
329 329
                             $output = $modifier_value[$i];
330 330
                         }
331 331
                         break;
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
                         $output = eval("return " . $filter . ";");
415 415
                         break;
416 416
                     case "isnotempty":
417
-                        if (!empty($output)) {
417
+                        if ( ! empty($output)) {
418 418
                             $output = $modifier_value[$i];
419 419
                         }
420 420
                         break;
@@ -493,7 +493,7 @@  discard block
 block discarded – undo
493 493
                         $cm = $snippet;
494 494
                         // end //
495 495
 
496
-                        if (!empty($cm)) {
496
+                        if ( ! empty($cm)) {
497 497
                             ob_start();
498 498
                             $options = $modifier_value[$i];
499 499
                             $custom = eval($cm);
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
      */
522 522
     public function createEventLog()
523 523
     {
524
-        if (!empty($this->console)) {
524
+        if ( ! empty($this->console)) {
525 525
             $console = implode("\n", $this->console);
526 526
             $this->console = array();
527 527
 
@@ -594,7 +594,7 @@  discard block
 block discarded – undo
594 594
     public function ModUser($userid, $field)
595 595
     {
596 596
         global $modx;
597
-        if (!array_key_exists($userid, $this->cache["ui"])) {
597
+        if ( ! array_key_exists($userid, $this->cache["ui"])) {
598 598
             if (intval($userid) < 0) {
599 599
                 $user = $modx->getWebUserInfo(-($userid));
600 600
             } else {
@@ -619,7 +619,7 @@  discard block
 block discarded – undo
619 619
         global $modx;
620 620
 
621 621
         // if $groupNames is not an array return false
622
-        if (!is_array($groupNames)) {
622
+        if ( ! is_array($groupNames)) {
623 623
             return false;
624 624
         }
625 625
 
@@ -629,7 +629,7 @@  discard block
 block discarded – undo
629 629
         }
630 630
 
631 631
         // Creates an array with all webgroups the user id is in
632
-        if (!array_key_exists($userid, $this->cache["mo"])) {
632
+        if ( ! array_key_exists($userid, $this->cache["mo"])) {
633 633
             $tbl = $modx->getFullTableName("webgroup_names");
634 634
             $tbl2 = $modx->getFullTableName("web_groups");
635 635
             $sql = "SELECT wgn.name FROM $tbl wgn INNER JOIN $tbl2 wg ON wg.webgroup=wgn.id AND wg.webuser='" . $userid . "'";
Please login to merge, or discard this patch.
Braces   +119 added lines, -117 removed lines patch added patch discarded remove patch
@@ -15,8 +15,8 @@  discard block
 block discarded – undo
15 15
 /**
16 16
  * Class DLphx
17 17
  */
18
-class DLphx
19
-{
18
+class DLphx
19
+{
20 20
     public $placeholders = array();
21 21
     public $name = 'PHx';
22 22
     public $version = '2.2.0';
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
      * @param int $debug
44 44
      * @param int $maxpass
45 45
      */
46
-    public function __construct($debug = 0, $maxpass = 50)
47
-    {
46
+    public function __construct($debug = 0, $maxpass = 50)
47
+    {
48 48
         global $modx;
49 49
         $this->user["mgrid"] = isset($_SESSION['mgrInternalKey']) ? intval($_SESSION['mgrInternalKey']) : 0;
50 50
         $this->user["usrid"] = isset($_SESSION['webInternalKey']) ? intval($_SESSION['webInternalKey']) : 0;
@@ -55,14 +55,14 @@  discard block
 block discarded – undo
55 55
         $this->maxPasses = ($maxpass != '') ? $maxpass : 50;
56 56
 
57 57
         $modx->setPlaceholder("phx", "&_PHX_INTERNAL_&");
58
-        if (function_exists('mb_internal_encoding')) {
58
+        if (function_exists('mb_internal_encoding')) {
59 59
             mb_internal_encoding($modx->config['modx_charset']);
60 60
         }
61 61
     }
62 62
 
63 63
     // Plugin event hook for MODx
64
-    public function OnParseDocument()
65
-    {
64
+    public function OnParseDocument()
65
+    {
66 66
         global $modx;
67 67
         // Get document output from MODx
68 68
         $template = $modx->documentOutput;
@@ -77,11 +77,11 @@  discard block
 block discarded – undo
77 77
      * @param string $template
78 78
      * @return mixed|string
79 79
      */
80
-    public function Parse($template = '')
81
-    {
80
+    public function Parse($template = '')
81
+    {
82 82
         global $modx;
83 83
         // If we already reached max passes don't get at it again.
84
-        if ($this->curPass == $this->maxPasses) {
84
+        if ($this->curPass == $this->maxPasses) {
85 85
             return $template;
86 86
         }
87 87
         // Set template pre-process hash
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
         $template = $this->ParseValues($template);
93 93
         // clean up unused placeholders that have modifiers attached (MODx can't clean them)
94 94
         preg_match_all('~(?:=`[^`@]*?)(\[\+([^:\+\[\]]+)([^\[\]]*?)\+\])~s', $template, $matches);
95
-        if ($matches[0]) {
95
+        if ($matches[0]) {
96 96
             $template = str_replace($matches[1], '', $template);
97 97
             $this->Log("Cleaning unsolved tags: \n" . implode("\n", $matches[2]));
98 98
         }
@@ -101,11 +101,11 @@  discard block
 block discarded – undo
101 101
         // Set template post-process hash
102 102
         $et = md5($template);
103 103
         // If template has changed, parse it once more...
104
-        if ($st != $et) {
104
+        if ($st != $et) {
105 105
             $template = $this->Parse($template);
106 106
         }
107 107
         // Write an event log if debugging is enabled and there is something to log
108
-        if ($this->debug && $this->debugLog) {
108
+        if ($this->debug && $this->debugLog) {
109 109
             $modx->logEvent($this->curPass, 1, $this->createEventLog(), $this->name . ' ' . $this->version);
110 110
             $this->debugLog = false;
111 111
         }
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
      * @param string $template
120 120
      * @return mixed|string
121 121
      */
122
-    public function ParseValues($template = '')
123
-    {
122
+    public function ParseValues($template = '')
123
+    {
124 124
         global $modx;
125 125
 
126 126
         $this->curPass = $this->curPass + 1;
@@ -129,12 +129,12 @@  discard block
 block discarded – undo
129 129
         $this->LogPass();
130 130
 
131 131
         // MODX Chunks
132
-        if (preg_match_all('~(?<!(?:then|else)=`){{([^:\+{}]+)([^{}]*?)}}~s', $template, $matches)) {
132
+        if (preg_match_all('~(?<!(?:then|else)=`){{([^:\+{}]+)([^{}]*?)}}~s', $template, $matches)) {
133 133
             $this->Log('MODX Chunks -> Merging all chunk tags');
134 134
             $count = count($matches[0]);
135 135
             $var_search = array();
136 136
             $var_replace = array();
137
-            for ($i = 0; $i < $count; $i++) {
137
+            for ($i = 0; $i < $count; $i++) {
138 138
                 $var_search[] = $matches[0][$i];
139 139
                 $input = $matches[1][$i];
140 140
                 $this->Log('MODX Chunk: ' . $input);
@@ -146,13 +146,13 @@  discard block
 block discarded – undo
146 146
 
147 147
         // MODx Snippets
148 148
         //if ( preg_match_all('~\[(\[|!)([^\[]*?)(!|\])\]~s',$template, $matches)) {
149
-        if (preg_match_all('~(?<!(?:then|else)=`)\[(\[)([^\[]*?)(\])\]~s', $template, $matches)) {
149
+        if (preg_match_all('~(?<!(?:then|else)=`)\[(\[)([^\[]*?)(\])\]~s', $template, $matches)) {
150 150
             $count = count($matches[0]);
151 151
             $var_search = array();
152 152
             $var_replace = array();
153 153
 
154 154
             // for each detected snippet
155
-            for ($i = 0; $i < $count; $i++) {
155
+            for ($i = 0; $i < $count; $i++) {
156 156
                 $snippet = $matches[2][$i]; // snippet call
157 157
                 $this->Log("MODx Snippet -> " . $snippet);
158 158
 
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
         }
169 169
 
170 170
         // PHx / MODx Tags
171
-        if (preg_match_all('~\[(\+|\*|\()([^:\+\[\]]+)([^\[\]]*?)(\1|\))\]~s', $template, $matches)) {
171
+        if (preg_match_all('~\[(\+|\*|\()([^:\+\[\]]+)([^\[\]]*?)(\1|\))\]~s', $template, $matches)) {
172 172
 
173 173
             //$matches[0] // Complete string that's need to be replaced
174 174
             //$matches[1] // Type
@@ -179,11 +179,11 @@  discard block
 block discarded – undo
179 179
             $count = count($matches[0]);
180 180
             $var_search = array();
181 181
             $var_replace = array();
182
-            for ($i = 0; $i < $count; $i++) {
182
+            for ($i = 0; $i < $count; $i++) {
183 183
                 $input = $matches[2][$i];
184 184
                 $modifiers = $matches[3][$i];
185 185
                 $var_search[] = $matches[0][$i];
186
-                switch ($matches[1][$i]) {
186
+                switch ($matches[1][$i]) {
187 187
                     // Document / Template Variable eXtended
188 188
                     case "*":
189 189
                         $this->Log("MODx TV/DV: " . $input);
@@ -202,10 +202,10 @@  discard block
 block discarded – undo
202 202
                         // Check if placeholder is set
203 203
                         if (!array_key_exists($input, $this->placeholders) && !array_key_exists($input,
204 204
                                 $modx->placeholders)
205
-                        ) {
205
+                        ) {
206 206
                             // not set so try again later.
207 207
                             $input = '';
208
-                        } else {
208
+                        } else {
209 209
                             // is set, get value and run filter
210 210
                             $input = $this->getPHxVariable($input);
211 211
                         }
@@ -219,11 +219,11 @@  discard block
 block discarded – undo
219 219
         $et = md5($template); // Post-process template hash
220 220
 
221 221
         // Log an event if this was the maximum pass
222
-        if ($this->curPass == $this->maxPasses) {
222
+        if ($this->curPass == $this->maxPasses) {
223 223
             $this->Log("Max passes reached. infinite loop protection so exiting.\n If you need the extra passes set the max passes to the highest count of nested tags in your template.");
224 224
         }
225 225
         // If this pass is not at maximum passes and the template hash is not the same, get at it again.
226
-        if (($this->curPass < $this->maxPasses) && ($st != $et)) {
226
+        if (($this->curPass < $this->maxPasses) && ($st != $et)) {
227 227
             $template = $this->ParseValues($template);
228 228
         }
229 229
 
@@ -236,23 +236,23 @@  discard block
 block discarded – undo
236 236
      * @param $modifiers
237 237
      * @return mixed|null|string
238 238
      */
239
-    public function Filter($input, $modifiers)
240
-    {
239
+    public function Filter($input, $modifiers)
240
+    {
241 241
         global $modx;
242 242
         $output = $input;
243 243
         $this->Log("  |--- Input = '" . $output . "'");
244
-        if (preg_match_all('~:([^:=]+)(?:=`(.*?)`(?=:[^:=]+|$))?~s', $modifiers, $matches)) {
244
+        if (preg_match_all('~:([^:=]+)(?:=`(.*?)`(?=:[^:=]+|$))?~s', $modifiers, $matches)) {
245 245
             $modifier_cmd = $matches[1]; // modifier command
246 246
             $modifier_value = $matches[2]; // modifier value
247 247
             $count = count($modifier_cmd);
248 248
             $condition = array();
249
-            for ($i = 0; $i < $count; $i++) {
249
+            for ($i = 0; $i < $count; $i++) {
250 250
                 $output = trim($output);
251 251
                 $this->Log("  |--- Modifier = '" . $modifier_cmd[$i] . "'");
252
-                if ($modifier_value[$i] != '') {
252
+                if ($modifier_value[$i] != '') {
253 253
                     $this->Log("  |--- Options = '" . $modifier_value[$i] . "'");
254 254
                 }
255
-                switch ($modifier_cmd[$i]) {
255
+                switch ($modifier_cmd[$i]) {
256 256
                     #####  Conditional Modifiers
257 257
                     case "input":
258 258
                     case "if":
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
                     case "ir":
295 295
                     case "memberof":
296 296
                     case "mo": // Is Member Of  (same as inrole but this one can be stringed as a conditional)
297
-                        if ($output == "&_PHX_INTERNAL_&") {
297
+                        if ($output == "&_PHX_INTERNAL_&") {
298 298
                             $output = $this->user["id"];
299 299
                         }
300 300
                         $grps = ($this->strlen($modifier_value[$i]) > 0) ? explode(",", $modifier_value[$i]) : array();
@@ -309,23 +309,23 @@  discard block
 block discarded – undo
309 309
                     case "show":
310 310
                         $conditional = implode(' ', $condition);
311 311
                         $isvalid = intval(eval("return (" . $conditional . ");"));
312
-                        if (!$isvalid) {
312
+                        if (!$isvalid) {
313 313
                             $output = null;
314 314
                         }
315 315
                         break;
316 316
                     case "then":
317 317
                         $conditional = implode(' ', $condition);
318 318
                         $isvalid = intval(eval("return (" . $conditional . ");"));
319
-                        if ($isvalid) {
319
+                        if ($isvalid) {
320 320
                             $output = $modifier_value[$i];
321
-                        } else {
321
+                        } else {
322 322
                             $output = null;
323 323
                         }
324 324
                         break;
325 325
                     case "else":
326 326
                         $conditional = implode(' ', $condition);
327 327
                         $isvalid = intval(eval("return (" . $conditional . ");"));
328
-                        if (!$isvalid) {
328
+                        if (!$isvalid) {
329 329
                             $output = $modifier_value[$i];
330 330
                         }
331 331
                         break;
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
                         $raw = explode("&", $modifier_value[$i]);
334 334
                         $map = array();
335 335
                         $count = count($raw);
336
-                        for ($m = 0; $m < $count; $m++) {
336
+                        for ($m = 0; $m < $count; $m++) {
337 337
                             $mi = explode("=", $raw[$m]);
338 338
                             $map[$mi[0]] = $mi[1];
339 339
                         }
@@ -414,13 +414,13 @@  discard block
 block discarded – undo
414 414
                         $output = eval("return " . $filter . ";");
415 415
                         break;
416 416
                     case "isnotempty":
417
-                        if (!empty($output)) {
417
+                        if (!empty($output)) {
418 418
                             $output = $modifier_value[$i];
419 419
                         }
420 420
                         break;
421 421
                     case "isempty":
422 422
                     case "ifempty":
423
-                        if (empty($output)) {
423
+                        if (empty($output)) {
424 424
                             $output = $modifier_value[$i];
425 425
                         }
426 426
                         break;
@@ -432,12 +432,12 @@  discard block
 block discarded – undo
432 432
                         break;
433 433
                     case "set":
434 434
                         $c = $i + 1;
435
-                        if ($count > $c && $modifier_cmd[$c] == "value") {
435
+                        if ($count > $c && $modifier_cmd[$c] == "value") {
436 436
                             $output = preg_replace("~([^a-zA-Z0-9])~", "", $modifier_value[$i]);
437 437
                         }
438 438
                         break;
439 439
                     case "value":
440
-                        if ($i > 0 && $modifier_cmd[$i - 1] == "set") {
440
+                        if ($i > 0 && $modifier_cmd[$i - 1] == "set") {
441 441
                             $modx->SetPlaceholder("phx." . $output, $modifier_value[$i]);
442 442
                         }
443 443
                         $output = null;
@@ -446,13 +446,13 @@  discard block
 block discarded – undo
446 446
                         $output = md5($output);
447 447
                         break;
448 448
                     case "userinfo":
449
-                        if ($output == "&_PHX_INTERNAL_&") {
449
+                        if ($output == "&_PHX_INTERNAL_&") {
450 450
                             $output = $this->user["id"];
451 451
                         }
452 452
                         $output = $this->ModUser($output, $modifier_value[$i]);
453 453
                         break;
454 454
                     case "inrole": // deprecated
455
-                        if ($output == "&_PHX_INTERNAL_&") {
455
+                        if ($output == "&_PHX_INTERNAL_&") {
456 456
                             $output = $this->user["id"];
457 457
                         }
458 458
                         $grps = ($this->strlen($modifier_value[$i]) > 0) ? explode(",", $modifier_value[$i]) : array();
@@ -464,19 +464,21 @@  discard block
 block discarded – undo
464 464
                         $snippet = '';
465 465
                         // modified by Anton Kuzmin (23.06.2010) //
466 466
                         $snippetName = 'phx:' . $modifier_cmd[$i];
467
-                        if (isset($modx->snippetCache[$snippetName])) {
467
+                        if (isset($modx->snippetCache[$snippetName])) {
468 468
                             $snippet = $modx->snippetCache[$snippetName];
469
-                        } else { // not in cache so let's check the db
469
+                        } else {
470
+// not in cache so let's check the db
470 471
                             $sql = "SELECT snippet FROM " . $modx->getFullTableName("site_snippets") . " WHERE " . $modx->getFullTableName("site_snippets") . ".name='" . $modx->db->escape($snippetName) . "';";
471 472
                             $result = $modx->dbQuery($sql);
472
-                            if ($modx->recordCount($result) == 1) {
473
+                            if ($modx->recordCount($result) == 1) {
473 474
                                 $row = $modx->fetchRow($result);
474 475
                                 $snippet = $modx->snippetCache[$row['name']] = $row['snippet'];
475 476
                                 $this->Log("  |--- DB -> Custom Modifier");
476
-                            } else {
477
-                                if ($modx->recordCount($result) == 0) { // If snippet not found, look in the modifiers folder
477
+                            } else {
478
+                                if ($modx->recordCount($result) == 0) {
479
+// If snippet not found, look in the modifiers folder
478 480
                                     $filename = $modx->config['rb_base_dir'] . 'plugins/phx/modifiers/' . $modifier_cmd[$i] . '.phx.php';
479
-                                    if (@file_exists($filename)) {
481
+                                    if (@file_exists($filename)) {
480 482
                                         $file_contents = @file_get_contents($filename);
481 483
                                         $file_contents = str_replace('<' . '?php', '', $file_contents);
482 484
                                         $file_contents = str_replace('?' . '>', '', $file_contents);
@@ -484,7 +486,7 @@  discard block
 block discarded – undo
484 486
                                         $snippet = $modx->snippetCache[$snippetName] = $file_contents;
485 487
                                         $modx->snippetCache[$snippetName . 'Props'] = '';
486 488
                                         $this->Log("  |--- File ($filename) -> Custom Modifier");
487
-                                    } else {
489
+                                    } else {
488 490
                                         $this->Log("  |--- PHX Error:  {$modifier_cmd[$i]} could not be found");
489 491
                                     }
490 492
                                 }
@@ -493,19 +495,19 @@  discard block
 block discarded – undo
493 495
                         $cm = $snippet;
494 496
                         // end //
495 497
 
496
-                        if (!empty($cm)) {
498
+                        if (!empty($cm)) {
497 499
                             ob_start();
498 500
                             $options = $modifier_value[$i];
499 501
                             $custom = eval($cm);
500 502
                             $msg = ob_get_contents();
501 503
                             $output = $msg . $custom;
502 504
                             ob_end_clean();
503
-                        } else {
505
+                        } else {
504 506
                             $output = '';
505 507
                         }
506 508
                         break;
507 509
                 }
508
-                if (count($condition)) {
510
+                if (count($condition)) {
509 511
                     $this->Log("  |--- Condition = '" . $condition[count($condition) - 1] . "'");
510 512
                 }
511 513
                 $this->Log("  |--- Output = '" . $output . "'");
@@ -519,9 +521,9 @@  discard block
 block discarded – undo
519 521
     /**
520 522
      * @return string
521 523
      */
522
-    public function createEventLog()
523
-    {
524
-        if (!empty($this->console)) {
524
+    public function createEventLog()
525
+    {
526
+        if (!empty($this->console)) {
525 527
             $console = implode("\n", $this->console);
526 528
             $this->console = array();
527 529
 
@@ -534,8 +536,8 @@  discard block
 block discarded – undo
534 536
      * @param $string
535 537
      * @return array|mixed|string
536 538
      */
537
-    public function LogClean($string)
538
-    {
539
+    public function LogClean($string)
540
+    {
539 541
         $string = preg_replace("/&amp;(#[0-9]+|[a-z]+);/i", "&$1;", $string);
540 542
         $string = APIHelpers::sanitarTag($string);
541 543
 
@@ -546,9 +548,9 @@  discard block
 block discarded – undo
546 548
     /**
547 549
      * @param $string
548 550
      */
549
-    public function Log($string)
550
-    {
551
-        if ($this->debug) {
551
+    public function Log($string)
552
+    {
553
+        if ($this->debug) {
552 554
             $this->debugLog = true;
553 555
             $this->console[] = (count($this->console) + 1 - $this->curPass) . " [" . strftime("%H:%M:%S",
554 556
                     time()) . "] " . $this->LogClean($string);
@@ -559,9 +561,9 @@  discard block
 block discarded – undo
559 561
     /**
560 562
      * @param $string
561 563
      */
562
-    public function LogSnippet($string)
563
-    {
564
-        if ($this->debug) {
564
+    public function LogSnippet($string)
565
+    {
566
+        if ($this->debug) {
565 567
             $this->debugLog = true;
566 568
             $this->console[] = (count($this->console) + 1 - $this->curPass) . " [" . strftime("%H:%M:%S",
567 569
                     time()) . "] " . "  |--- Returns: <div style='margin: 10px;'>" . $this->LogClean($string) . "</div>";
@@ -569,8 +571,8 @@  discard block
 block discarded – undo
569 571
     }
570 572
 
571 573
     // Log pass
572
-    public function LogPass()
573
-    {
574
+    public function LogPass()
575
+    {
574 576
         $this->console[] = "<div style='margin: 2px;margin-top: 5px;border-bottom: 1px solid black;'>Pass " . $this->curPass . "</div>";
575 577
     }
576 578
 
@@ -578,8 +580,8 @@  discard block
 block discarded – undo
578 580
     /**
579 581
      * @param $string
580 582
      */
581
-    public function LogSource($string)
582
-    {
583
+    public function LogSource($string)
584
+    {
583 585
         $this->console[] = "<div style='margin: 2px;margin-top: 5px;border-bottom: 1px solid black;'>Source:</div>" . $this->LogClean($string);
584 586
     }
585 587
 
@@ -591,17 +593,17 @@  discard block
 block discarded – undo
591 593
      * @param $field
592 594
      * @return mixed
593 595
      */
594
-    public function ModUser($userid, $field)
595
-    {
596
+    public function ModUser($userid, $field)
597
+    {
596 598
         global $modx;
597
-        if (!array_key_exists($userid, $this->cache["ui"])) {
598
-            if (intval($userid) < 0) {
599
+        if (!array_key_exists($userid, $this->cache["ui"])) {
600
+            if (intval($userid) < 0) {
599 601
                 $user = $modx->getWebUserInfo(-($userid));
600
-            } else {
602
+            } else {
601 603
                 $user = $modx->getUserInfo($userid);
602 604
             }
603 605
             $this->cache["ui"][$userid] = $user;
604
-        } else {
606
+        } else {
605 607
             $user = $this->cache["ui"][$userid];
606 608
         }
607 609
 
@@ -614,32 +616,32 @@  discard block
 block discarded – undo
614 616
      * @param array $groupNames
615 617
      * @return bool
616 618
      */
617
-    public function isMemberOfWebGroupByUserId($userid = 0, $groupNames = array())
618
-    {
619
+    public function isMemberOfWebGroupByUserId($userid = 0, $groupNames = array())
620
+    {
619 621
         global $modx;
620 622
 
621 623
         // if $groupNames is not an array return false
622
-        if (!is_array($groupNames)) {
624
+        if (!is_array($groupNames)) {
623 625
             return false;
624 626
         }
625 627
 
626 628
         // if the user id is a negative number make it positive
627
-        if (intval($userid) < 0) {
629
+        if (intval($userid) < 0) {
628 630
             $userid = -($userid);
629 631
         }
630 632
 
631 633
         // Creates an array with all webgroups the user id is in
632
-        if (!array_key_exists($userid, $this->cache["mo"])) {
634
+        if (!array_key_exists($userid, $this->cache["mo"])) {
633 635
             $tbl = $modx->getFullTableName("webgroup_names");
634 636
             $tbl2 = $modx->getFullTableName("web_groups");
635 637
             $sql = "SELECT wgn.name FROM $tbl wgn INNER JOIN $tbl2 wg ON wg.webgroup=wgn.id AND wg.webuser='" . $userid . "'";
636 638
             $this->cache["mo"][$userid] = $grpNames = $modx->db->getColumn("name", $sql);
637
-        } else {
639
+        } else {
638 640
             $grpNames = $this->cache["mo"][$userid];
639 641
         }
640 642
         // Check if a supplied group matches a webgroup from the array we just created
641
-        foreach ($groupNames as $k => $v) {
642
-            if (in_array(trim($v), $grpNames)) {
643
+        foreach ($groupNames as $k => $v) {
644
+            if (in_array(trim($v), $grpNames)) {
643 645
                 return true;
644 646
             }
645 647
         }
@@ -653,14 +655,14 @@  discard block
 block discarded – undo
653 655
      * @param $name
654 656
      * @return mixed|string
655 657
      */
656
-    public function getPHxVariable($name)
657
-    {
658
+    public function getPHxVariable($name)
659
+    {
658 660
         global $modx;
659 661
         // Check if this variable is created by PHx
660
-        if (array_key_exists($name, $this->placeholders)) {
662
+        if (array_key_exists($name, $this->placeholders)) {
661 663
             // Return the value from PHx
662 664
             return $this->placeholders[$name];
663
-        } else {
665
+        } else {
664 666
             // Return the value from MODx
665 667
             return $modx->getPlaceholder($name);
666 668
         }
@@ -671,9 +673,9 @@  discard block
 block discarded – undo
671 673
      * @param $name
672 674
      * @param $value
673 675
      */
674
-    public function setPHxVariable($name, $value)
675
-    {
676
-        if ($name != "phx") {
676
+    public function setPHxVariable($name, $value)
677
+    {
678
+        if ($name != "phx") {
677 679
             $this->placeholders[$name] = $value;
678 680
         }
679 681
     }
@@ -685,9 +687,9 @@  discard block
 block discarded – undo
685 687
      * @param null $l
686 688
      * @return string
687 689
      */
688
-    public function substr($str, $s, $l = null)
689
-    {
690
-        if (function_exists('mb_substr')) {
690
+    public function substr($str, $s, $l = null)
691
+    {
692
+        if (function_exists('mb_substr')) {
691 693
             return mb_substr($str, $s, $l);
692 694
         }
693 695
 
@@ -698,9 +700,9 @@  discard block
 block discarded – undo
698 700
      * @param $str
699 701
      * @return int
700 702
      */
701
-    public function strlen($str)
702
-    {
703
-        if (function_exists('mb_strlen')) {
703
+    public function strlen($str)
704
+    {
705
+        if (function_exists('mb_strlen')) {
704 706
             return mb_strlen($str);
705 707
         }
706 708
 
@@ -711,9 +713,9 @@  discard block
 block discarded – undo
711 713
      * @param $str
712 714
      * @return string
713 715
      */
714
-    public function strtolower($str)
715
-    {
716
-        if (function_exists('mb_strtolower')) {
716
+    public function strtolower($str)
717
+    {
718
+        if (function_exists('mb_strtolower')) {
717 719
             return mb_strtolower($str);
718 720
         }
719 721
 
@@ -724,9 +726,9 @@  discard block
 block discarded – undo
724 726
      * @param $str
725 727
      * @return string
726 728
      */
727
-    public function strtoupper($str)
728
-    {
729
-        if (function_exists('mb_strtoupper')) {
729
+    public function strtoupper($str)
730
+    {
731
+        if (function_exists('mb_strtoupper')) {
730 732
             return mb_strtoupper($str);
731 733
         }
732 734
 
@@ -737,9 +739,9 @@  discard block
 block discarded – undo
737 739
      * @param $str
738 740
      * @return string
739 741
      */
740
-    public function ucfirst($str)
741
-    {
742
-        if (function_exists('mb_strtoupper') && function_exists('mb_substr') && function_exists('mb_strlen')) {
742
+    public function ucfirst($str)
743
+    {
744
+        if (function_exists('mb_strtoupper') && function_exists('mb_substr') && function_exists('mb_strlen')) {
743 745
             return mb_strtoupper(mb_substr($str, 0, 1)) . mb_substr($str, 1, mb_strlen($str));
744 746
         }
745 747
 
@@ -750,9 +752,9 @@  discard block
 block discarded – undo
750 752
      * @param $str
751 753
      * @return string
752 754
      */
753
-    public function lcfirst($str)
754
-    {
755
-        if (function_exists('mb_strtolower') && function_exists('mb_substr') && function_exists('mb_strlen')) {
755
+    public function lcfirst($str)
756
+    {
757
+        if (function_exists('mb_strtolower') && function_exists('mb_substr') && function_exists('mb_strlen')) {
756 758
             return mb_strtolower(mb_substr($str, 0, 1)) . mb_substr($str, 1, mb_strlen($str));
757 759
         }
758 760
 
@@ -763,9 +765,9 @@  discard block
 block discarded – undo
763 765
      * @param $str
764 766
      * @return string
765 767
      */
766
-    public function ucwords($str)
767
-    {
768
-        if (function_exists('mb_convert_case')) {
768
+    public function ucwords($str)
769
+    {
770
+        if (function_exists('mb_convert_case')) {
769 771
             return mb_convert_case($str, MB_CASE_TITLE);
770 772
         }
771 773
 
@@ -776,8 +778,8 @@  discard block
 block discarded – undo
776 778
      * @param $str
777 779
      * @return string
778 780
      */
779
-    public function strrev($str)
780
-    {
781
+    public function strrev($str)
782
+    {
781 783
         preg_match_all('/./us', $str, $ar);
782 784
 
783 785
         return implode(array_reverse($ar[0]));
@@ -787,8 +789,8 @@  discard block
 block discarded – undo
787 789
      * @param $str
788 790
      * @return string
789 791
      */
790
-    public function str_shuffle($str)
791
-    {
792
+    public function str_shuffle($str)
793
+    {
792 794
         preg_match_all('/./us', $str, $ar);
793 795
         shuffle($ar[0]);
794 796
 
@@ -799,8 +801,8 @@  discard block
 block discarded – undo
799 801
      * @param $str
800 802
      * @return int
801 803
      */
802
-    public function str_word_count($str)
803
-    {
804
+    public function str_word_count($str)
805
+    {
804 806
         return count(preg_split('~[^\p{L}\p{N}\']+~u', $str));
805 807
     }
806 808
 }
Please login to merge, or discard this patch.
assets/lib/class.summary.php 3 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
     }
70 70
 
71 71
     /**
72
-     * @return mixed
72
+     * @return string
73 73
      */
74 74
     public function getCut()
75 75
     {
@@ -149,8 +149,8 @@  discard block
 block discarded – undo
149 149
     /**
150 150
      * @param $resource
151 151
      * @param $truncLen
152
-     * @param $truncOffset
153
-     * @param $truncChars
152
+     * @param integer $truncOffset
153
+     * @param boolean $truncChars
154 154
      * @param string $splitter
155 155
      * @return array|mixed|string
156 156
      */
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
      */
243 243
     /**
244 244
      * @param $string
245
-     * @param $limit
245
+     * @param integer $limit
246 246
      * @param string $break
247 247
      * @return string
248 248
      */
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
     }
266 266
 
267 267
     /**
268
-     * @param $str
268
+     * @param string $str
269 269
      * @return mixed
270 270
      */
271 271
     protected function rTriming($str)
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -83,10 +83,10 @@  discard block
 block discarded – undo
83 83
      */
84 84
     protected function dotted($scheme = 0)
85 85
     {
86
-        if (($scheme == 1 && ($this->_useCut || $this->_useSubstr)) || ($scheme == 2 && $this->_useSubstr && !$this->_useCut)) {
86
+        if (($scheme == 1 && ($this->_useCut || $this->_useSubstr)) || ($scheme == 2 && $this->_useSubstr && ! $this->_useCut)) {
87 87
             $this->_cfg['content'] .= '&hellip;'; //...
88 88
         } else {
89
-            if ($scheme && (!$this->_useCut || $scheme != 2)) {
89
+            if ($scheme && ( ! $this->_useCut || $scheme != 2)) {
90 90
                 $this->_cfg['content'] .= '.';
91 91
             }
92 92
         }
@@ -115,13 +115,13 @@  discard block
 block discarded – undo
115 115
                         $this->_cfg['content'] = APIhelpers::sanitarTag($this->_cfg['content']);
116 116
                         break;
117 117
                     case 'chars':
118
-                        if (!(isset($process[1]) && $process[1] > 0)) {
118
+                        if ( ! (isset($process[1]) && $process[1] > 0)) {
119 119
                             $process[1] = 200;
120 120
                         }
121 121
                         $this->_cfg['content'] = APIhelpers::mb_trim_word($this->_cfg['content'], $process[1]);
122 122
                         break;
123 123
                     case 'len':
124
-                        if (!(isset($process[1]) && $process[1] > 0)) {
124
+                        if ( ! (isset($process[1]) && $process[1] > 0)) {
125 125
                             $process[1] = 200;
126 126
                         }
127 127
                         $this->_cfg['content'] = $this->summary($this->_cfg['content'], $process[1], 50, true,
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
                 } else {
209 209
                     $next_char = "";
210 210
                 }
211
-                if (!$quotes_on) {
211
+                if ( ! $quotes_on) {
212 212
                     // Check if it's a tag
213 213
                     // On a "<" add 3 if it's an opening tag (like <a href...)
214 214
                     // or add only 1 if it's an ending tag (like </a>)
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
     protected function rTriming($str)
296 296
     {
297 297
         $str = preg_replace('/[\r\n]++/', ' ', $str);
298
-        if (!$this->_useCut || $this->_dotted != 2) {
298
+        if ( ! $this->_useCut || $this->_dotted != 2) {
299 299
             $str = preg_replace("/(([\.,\-:!?;\s])|(&\w+;))+$/ui", "", $str);
300 300
         }
301 301
 
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
                 if (mb_strstr($tag, ' ', 'UTF-8')) {
349 349
                     $tag = mb_substr($tag, 0, strpos($tag, ' '), 'UTF-8');
350 350
                 }
351
-                if (!mb_stristr($tag, 'br', 'UTF-8') && !mb_stristr($tag, 'img', 'UTF-8') && !empty ($tag)) {
351
+                if ( ! mb_stristr($tag, 'br', 'UTF-8') && ! mb_stristr($tag, 'img', 'UTF-8') && ! empty ($tag)) {
352 352
                     $endTags .= '</' . $tag . '>';
353 353
                 }
354 354
             }
Please login to merge, or discard this patch.
Braces   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
 /**
18 18
  * Class SummaryText
19 19
  */
20
-class SummaryText
21
-{
20
+class SummaryText
21
+{
22 22
     /**
23 23
      * @var array
24 24
      */
@@ -45,8 +45,8 @@  discard block
 block discarded – undo
45 45
      * @param $action
46 46
      * @param null $break
47 47
      */
48
-    public function __construct($text, $action, $break = null)
49
-    {
48
+    public function __construct($text, $action, $break = null)
49
+    {
50 50
         $this->_cfg['content'] = is_scalar($text) ? $text : '';
51 51
         $this->_cfg['original'] = $this->_cfg['content'];
52 52
         $this->_cfg['summary'] = is_scalar($action) ? $action : '';
@@ -57,12 +57,12 @@  discard block
 block discarded – undo
57 57
      * @param $cut
58 58
      * @return bool
59 59
      */
60
-    public function setCut($cut)
61
-    {
62
-        if (is_scalar($cut) && $cut != '') {
60
+    public function setCut($cut)
61
+    {
62
+        if (is_scalar($cut) && $cut != '') {
63 63
             $this->_cfg['cut'] = $cut;
64 64
             $flag = true;
65
-        } else {
65
+        } else {
66 66
             $flag = false;
67 67
         }
68 68
 
@@ -72,8 +72,8 @@  discard block
 block discarded – undo
72 72
     /**
73 73
      * @return mixed
74 74
      */
75
-    public function getCut()
76
-    {
75
+    public function getCut()
76
+    {
77 77
         return \APIHelpers::getkey($this->_cfg, 'cut', '<cut/>');
78 78
     }
79 79
 
@@ -81,12 +81,12 @@  discard block
 block discarded – undo
81 81
      * @param int $scheme
82 82
      * @return mixed
83 83
      */
84
-    protected function dotted($scheme = 0)
85
-    {
86
-        if (($scheme == 1 && ($this->_useCut || $this->_useSubstr)) || ($scheme == 2 && $this->_useSubstr && !$this->_useCut)) {
84
+    protected function dotted($scheme = 0)
85
+    {
86
+        if (($scheme == 1 && ($this->_useCut || $this->_useSubstr)) || ($scheme == 2 && $this->_useSubstr && !$this->_useCut)) {
87 87
             $this->_cfg['content'] .= '&hellip;'; //...
88
-        } else {
89
-            if ($scheme && (!$this->_useCut || $scheme != 2)) {
88
+        } else {
89
+            if ($scheme && (!$this->_useCut || $scheme != 2)) {
90 90
                 $this->_cfg['content'] .= '.';
91 91
             }
92 92
         }
@@ -98,16 +98,16 @@  discard block
 block discarded – undo
98 98
      * @param int $dotted
99 99
      * @return mixed
100 100
      */
101
-    public function run($dotted = 0)
102
-    {
101
+    public function run($dotted = 0)
102
+    {
103 103
         $this->_dotted = $dotted;
104
-        if (isset($this->_cfg['content'], $this->_cfg['summary']) && $this->_cfg['summary'] != '' && $this->_cfg['content'] != '') {
104
+        if (isset($this->_cfg['content'], $this->_cfg['summary']) && $this->_cfg['summary'] != '' && $this->_cfg['content'] != '') {
105 105
             $param = explode(",", $this->_cfg['summary']);
106 106
             $this->_cfg['content'] = $this->beforeCut($this->_cfg['content'], $this->getCut());
107
-            foreach ($param as $doing) {
107
+            foreach ($param as $doing) {
108 108
 
109 109
                 $process = explode(":", $doing);
110
-                switch ($process[0]) {
110
+                switch ($process[0]) {
111 111
                     case 'notags':
112 112
                         $this->_cfg['content'] = strip_tags($this->_cfg['content']);
113 113
                         break;
@@ -115,13 +115,13 @@  discard block
 block discarded – undo
115 115
                         $this->_cfg['content'] = APIhelpers::sanitarTag($this->_cfg['content']);
116 116
                         break;
117 117
                     case 'chars':
118
-                        if (!(isset($process[1]) && $process[1] > 0)) {
118
+                        if (!(isset($process[1]) && $process[1] > 0)) {
119 119
                             $process[1] = 200;
120 120
                         }
121 121
                         $this->_cfg['content'] = APIhelpers::mb_trim_word($this->_cfg['content'], $process[1]);
122 122
                         break;
123 123
                     case 'len':
124
-                        if (!(isset($process[1]) && $process[1] > 0)) {
124
+                        if (!(isset($process[1]) && $process[1] > 0)) {
125 125
                             $process[1] = 200;
126 126
                         }
127 127
                         $this->_cfg['content'] = $this->summary($this->_cfg['content'], $process[1], 50, true,
@@ -139,15 +139,15 @@  discard block
 block discarded – undo
139 139
      * @param string $splitter
140 140
      * @return array|mixed
141 141
      */
142
-    protected function beforeCut($resource, $splitter = '')
143
-    {
144
-        if ($splitter !== '') {
142
+    protected function beforeCut($resource, $splitter = '')
143
+    {
144
+        if ($splitter !== '') {
145 145
             $summary = str_replace('<p>' . $splitter . '</p>', $splitter,
146 146
                 $resource); // For TinyMCE or if it isn't wrapped inside paragraph tags
147 147
             $summary = explode($splitter, $summary, 2);
148 148
             $this->_useCut = isset($summary[1]);
149 149
             $summary = $summary['0'];
150
-        } else {
150
+        } else {
151 151
             $summary = $resource;
152 152
         }
153 153
 
@@ -162,18 +162,18 @@  discard block
 block discarded – undo
162 162
      * @param string $splitter
163 163
      * @return array|mixed|string
164 164
      */
165
-    protected function summary($resource, $truncLen, $truncOffset, $truncChars, $splitter = '')
166
-    {
167
-        if (isset($this->_useCut) && $splitter != '' && mb_strstr($resource, $splitter, 'UTF-8')) {
165
+    protected function summary($resource, $truncLen, $truncOffset, $truncChars, $splitter = '')
166
+    {
167
+        if (isset($this->_useCut) && $splitter != '' && mb_strstr($resource, $splitter, 'UTF-8')) {
168 168
             $summary = $this->beforeCut($resource, $splitter);
169
-        } else {
170
-            if ($this->_useCut !== true && (mb_strlen($resource, 'UTF-8') > $truncLen)) {
169
+        } else {
170
+            if ($this->_useCut !== true && (mb_strlen($resource, 'UTF-8') > $truncLen)) {
171 171
 
172 172
                 $summary = $this->html_substr($resource, $truncLen, $truncOffset, $truncChars);
173
-                if ($resource != $summary) {
173
+                if ($resource != $summary) {
174 174
                     $this->_useSubstr = true;
175 175
                 }
176
-            } else {
176
+            } else {
177 177
                 $summary = $resource;
178 178
             }
179 179
         }
@@ -194,60 +194,60 @@  discard block
 block discarded – undo
194 194
      * @param bool $truncChars
195 195
      * @return string
196 196
      */
197
-    protected function html_substr($posttext, $minimum_length = 200, $length_offset = 100, $truncChars = false)
198
-    {
197
+    protected function html_substr($posttext, $minimum_length = 200, $length_offset = 100, $truncChars = false)
198
+    {
199 199
         $tag_counter = 0;
200 200
         $quotes_on = false;
201
-        if (mb_strlen($posttext) > $minimum_length && $truncChars !== true) {
201
+        if (mb_strlen($posttext) > $minimum_length && $truncChars !== true) {
202 202
             $c = 0;
203 203
             $len = mb_strlen($posttext, 'UTF-8');
204
-            for ($i = 0; $i < $len; $i++) {
204
+            for ($i = 0; $i < $len; $i++) {
205 205
                 $current_char = mb_substr($posttext, $i, 1, 'UTF-8');
206
-                if ($i < mb_strlen($posttext, 'UTF-8') - 1) {
206
+                if ($i < mb_strlen($posttext, 'UTF-8') - 1) {
207 207
                     $next_char = mb_substr($posttext, $i + 1, 1, 'UTF-8');
208
-                } else {
208
+                } else {
209 209
                     $next_char = "";
210 210
                 }
211
-                if (!$quotes_on) {
211
+                if (!$quotes_on) {
212 212
                     // Check if it's a tag
213 213
                     // On a "<" add 3 if it's an opening tag (like <a href...)
214 214
                     // or add only 1 if it's an ending tag (like </a>)
215
-                    if ($current_char == '<') {
216
-                        if ($next_char == '/') {
215
+                    if ($current_char == '<') {
216
+                        if ($next_char == '/') {
217 217
                             $tag_counter += 1;
218
-                        } else {
218
+                        } else {
219 219
                             $tag_counter += 3;
220 220
                         }
221 221
                     }
222 222
                     // Slash signifies an ending (like </a> or ... />)
223 223
                     // substract 2
224
-                    if ($current_char == '/' && $tag_counter <> 0) {
224
+                    if ($current_char == '/' && $tag_counter <> 0) {
225 225
                         $tag_counter -= 2;
226 226
                     }
227 227
                     // On a ">" substract 1
228
-                    if ($current_char == '>') {
228
+                    if ($current_char == '>') {
229 229
                         $tag_counter -= 1;
230 230
                     }
231 231
                     // If quotes are encountered, start ignoring the tags
232 232
                     // (for directory slashes)
233
-                    if ($current_char == '"') {
233
+                    if ($current_char == '"') {
234 234
                         $quotes_on = true;
235 235
                     }
236
-                } else {
236
+                } else {
237 237
                     // IF quotes are encountered again, turn it back off
238
-                    if ($current_char == '"') {
238
+                    if ($current_char == '"') {
239 239
                         $quotes_on = false;
240 240
                     }
241 241
                 }
242 242
 
243 243
                 // Count only the chars outside html tags
244
-                if ($tag_counter == 2 || $tag_counter == 0) {
244
+                if ($tag_counter == 2 || $tag_counter == 0) {
245 245
                     $c++;
246 246
                 }
247 247
 
248 248
                 // Check if the counter has reached the minimum length yet,
249 249
                 // then wait for the tag_counter to become 0, and chop the string there
250
-                if ($c > $minimum_length - $length_offset && $tag_counter == 0) {
250
+                if ($c > $minimum_length - $length_offset && $tag_counter == 0) {
251 251
                     $posttext = mb_substr($posttext, 0, $i + 1, 'UTF-8');
252 252
 
253 253
                     return $posttext;
@@ -267,20 +267,20 @@  discard block
 block discarded – undo
267 267
      * @param string $break
268 268
      * @return string
269 269
      */
270
-    protected function textTrunc($string, $limit, $break = ". ")
271
-    {
270
+    protected function textTrunc($string, $limit, $break = ". ")
271
+    {
272 272
         // Original PHP code from The Art of Web: www.the-art-of-web.com
273 273
 
274 274
         // return with no change if string is shorter than $limit
275
-        if (mb_strlen($string, 'UTF-8') < $limit) {
275
+        if (mb_strlen($string, 'UTF-8') < $limit) {
276 276
             return $string;
277 277
         }
278 278
 
279 279
         $string = mb_substr($string, 0, $limit, 'UTF-8');
280
-        if (false !== ($breakpoint = mb_strrpos($string, $break, 'UTF-8'))) {
280
+        if (false !== ($breakpoint = mb_strrpos($string, $break, 'UTF-8'))) {
281 281
             $string = mb_substr($string, 0, $breakpoint + 1, 'UTF-8');
282
-        } else {
283
-            if ($break != ' ') {
282
+        } else {
283
+            if ($break != ' ') {
284 284
                 $string = $this->textTrunc($string, $limit, " ");
285 285
             }
286 286
         }
@@ -292,10 +292,10 @@  discard block
 block discarded – undo
292 292
      * @param $str
293 293
      * @return mixed
294 294
      */
295
-    protected function rTriming($str)
296
-    {
295
+    protected function rTriming($str)
296
+    {
297 297
         $str = preg_replace('/[\r\n]++/', ' ', $str);
298
-        if (!$this->_useCut || $this->_dotted != 2) {
298
+        if (!$this->_useCut || $this->_dotted != 2) {
299 299
             $str = preg_replace("/(([\.,\-:!?;\s])|(&\w+;))+$/ui", "", $str);
300 300
         }
301 301
 
@@ -308,8 +308,8 @@  discard block
 block discarded – undo
308 308
      * @param $text
309 309
      * @return string
310 310
      */
311
-    private function closeTags($text)
312
-    {
311
+    private function closeTags($text)
312
+    {
313 313
         $openPattern = "/<([^\/].*?)>/";
314 314
         $closePattern = "/<\/(.*?)>/";
315 315
         $endTags = '';
@@ -319,15 +319,15 @@  discard block
 block discarded – undo
319 319
 
320 320
         $c = 0;
321 321
         $loopCounter = count($closeTags[1]); //used to prevent an infinite loop if the html is malformed
322
-        while ($c < count($closeTags[1]) && $loopCounter) {
322
+        while ($c < count($closeTags[1]) && $loopCounter) {
323 323
             $i = 0;
324
-            while ($i < count($openTags[1])) {
324
+            while ($i < count($openTags[1])) {
325 325
                 $tag = trim($openTags[1][$i]);
326 326
 
327
-                if (mb_strstr($tag, ' ', 'UTF-8')) {
327
+                if (mb_strstr($tag, ' ', 'UTF-8')) {
328 328
                     $tag = mb_substr($tag, 0, strpos($tag, ' '), 'UTF-8');
329 329
                 }
330
-                if ($tag == $closeTags[1][$c]) {
330
+                if ($tag == $closeTags[1][$c]) {
331 331
                     $openTags[1][$i] = '';
332 332
                     $c++;
333 333
                     break;
@@ -339,16 +339,16 @@  discard block
 block discarded – undo
339 339
 
340 340
         $results = $openTags[1];
341 341
 
342
-        if (is_array($results)) {
342
+        if (is_array($results)) {
343 343
             $results = array_reverse($results);
344 344
 
345
-            foreach ($results as $tag) {
345
+            foreach ($results as $tag) {
346 346
                 $tag = trim($tag);
347 347
 
348
-                if (mb_strstr($tag, ' ', 'UTF-8')) {
348
+                if (mb_strstr($tag, ' ', 'UTF-8')) {
349 349
                     $tag = mb_substr($tag, 0, strpos($tag, ' '), 'UTF-8');
350 350
                 }
351
-                if (!mb_stristr($tag, 'br', 'UTF-8') && !mb_stristr($tag, 'img', 'UTF-8') && !empty ($tag)) {
351
+                if (!mb_stristr($tag, 'br', 'UTF-8') && !mb_stristr($tag, 'img', 'UTF-8') && !empty ($tag)) {
352 352
                     $endTags .= '</' . $tag . '>';
353 353
                 }
354 354
             }
Please login to merge, or discard this patch.