Completed
Push — master ( 1c95fe...5490fd )
by
unknown
02:43
created
assets/snippets/DocLister/core/DocLister.abstract.php 1 patch
Braces   +285 added lines, -279 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
 /**
@@ -20,8 +20,8 @@  discard block
 block discarded – undo
20 20
 /**
21 21
  * Class DocLister
22 22
  */
23
-abstract class DocLister
24
-{
23
+abstract class DocLister
24
+{
25 25
     /**
26 26
      * Ключ в массиве $_REQUEST в котором находится алиас запрашиваемого документа
27 27
      */
@@ -182,48 +182,48 @@  discard block
 block discarded – undo
182 182
      * @param int $startTime время запуска сниппета
183 183
      * @throws Exception
184 184
      */
185
-    public function __construct($modx, $cfg = array(), $startTime = null)
186
-    {
185
+    public function __construct($modx, $cfg = array(), $startTime = null)
186
+    {
187 187
         $this->setTimeStart($startTime);
188 188
 
189
-        if (extension_loaded('mbstring')) {
189
+        if (extension_loaded('mbstring')) {
190 190
             mb_internal_encoding("UTF-8");
191
-        } else {
191
+        } else {
192 192
             throw new Exception('Not found php extension mbstring');
193 193
         }
194 194
 
195
-        if ($modx instanceof DocumentParser) {
195
+        if ($modx instanceof DocumentParser) {
196 196
             $this->modx = $modx;
197 197
             $this->setDebug(1);
198 198
 
199
-            if (!is_array($cfg) || empty($cfg)) {
199
+            if (!is_array($cfg) || empty($cfg)) {
200 200
                 $cfg = $this->modx->Event->params;
201 201
             }
202
-        } else {
202
+        } else {
203 203
             throw new Exception('MODX var is not instaceof DocumentParser');
204 204
         }
205 205
 
206 206
         $this->FS = \Helpers\FS::getInstance();
207 207
         $this->config = new \Helpers\Config($cfg);
208 208
 
209
-        if (isset($cfg['config'])) {
209
+        if (isset($cfg['config'])) {
210 210
             $this->config->setPath(dirname(__DIR__))->loadConfig($cfg['config']);
211 211
         }
212 212
 
213
-        if ($this->config->setConfig($cfg) === false) {
213
+        if ($this->config->setConfig($cfg) === false) {
214 214
             throw new Exception('no parameters to run DocLister');
215 215
         }
216 216
 
217 217
         $this->loadLang(array('core', 'json'));
218 218
         $this->setDebug($this->getCFGDef('debug', 0));
219 219
 
220
-        if ($this->checkDL()) {
220
+        if ($this->checkDL()) {
221 221
             $cfg = array();
222 222
             $idType = $this->getCFGDef('idType', '');
223
-            if (empty($idType) && $this->getCFGDef('documents', '') != '') {
223
+            if (empty($idType) && $this->getCFGDef('documents', '') != '') {
224 224
                 $idType = 'documents';
225 225
             }
226
-            switch ($idType) {
226
+            switch ($idType) {
227 227
                 case 'documents':
228 228
                     $IDs = $this->getCFGDef('documents');
229 229
                     $cfg['idType'] = "documents";
@@ -231,14 +231,14 @@  discard block
 block discarded – undo
231 231
                 case 'parents':
232 232
                 default:
233 233
                     $cfg['idType'] = "parents";
234
-                    if (($IDs = $this->getCFGDef('parents')) === null) {
234
+                    if (($IDs = $this->getCFGDef('parents')) === null) {
235 235
                         $IDs = $this->getCurrentMODXPageID();
236 236
                     }
237 237
                     break;
238 238
             }
239 239
             $this->config->setConfig($cfg);
240 240
 
241
-            if (empty($this->table)) {
241
+            if (empty($this->table)) {
242 242
                 $this->table = $this->getTable($this->getCFGDef('table', 'site_content'));
243 243
             }
244 244
             $this->idField = $this->getCFGDef('idField', 'id');
@@ -249,12 +249,12 @@  discard block
 block discarded – undo
249 249
 
250 250
         $this->setLocate();
251 251
 
252
-        if ($this->getCFGDef("customLang")) {
252
+        if ($this->getCFGDef("customLang")) {
253 253
             $this->getCustomLang();
254 254
         }
255 255
         $this->loadExtender($this->getCFGDef("extender", ""));
256 256
 
257
-        if ($this->checkExtender('request')) {
257
+        if ($this->checkExtender('request')) {
258 258
             $this->extender['request']->init($this, $this->getCFGDef("requestActive", ""));
259 259
         }
260 260
         $this->_filters = $this->getFilters($this->getCFGDef('filters', ''));
@@ -266,21 +266,21 @@  discard block
 block discarded – undo
266 266
      * @param string $str строка с фильтром
267 267
      * @return array массив субфильтров
268 268
      */
269
-    public function smartSplit($str)
270
-    {
269
+    public function smartSplit($str)
270
+    {
271 271
         $res = array();
272 272
         $cur = '';
273 273
         $open = 0;
274 274
         $strlen = mb_strlen($str, 'UTF-8');
275
-        for ($i = 0; $i <= $strlen; $i++) {
275
+        for ($i = 0; $i <= $strlen; $i++) {
276 276
             $e = mb_substr($str, $i, 1, 'UTF-8');
277
-            switch ($e) {
277
+            switch ($e) {
278 278
                 case ')':
279 279
                     $open--;
280
-                    if ($open == 0) {
280
+                    if ($open == 0) {
281 281
                         $res[] = $cur . ')';
282 282
                         $cur = '';
283
-                    } else {
283
+                    } else {
284 284
                         $cur .= $e;
285 285
                     }
286 286
                     break;
@@ -289,10 +289,10 @@  discard block
 block discarded – undo
289 289
                     $cur .= $e;
290 290
                     break;
291 291
                 case ';':
292
-                    if ($open == 0) {
292
+                    if ($open == 0) {
293 293
                         $res[] = $cur;
294 294
                         $cur = '';
295
-                    } else {
295
+                    } else {
296 296
                         $cur .= $e;
297 297
                     }
298 298
                     break;
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
             }
302 302
         }
303 303
         $cur = preg_replace("/(\))$/u", '', $cur);
304
-        if ($cur != '') {
304
+        if ($cur != '') {
305 305
             $res[] = $cur;
306 306
         }
307 307
 
@@ -312,8 +312,8 @@  discard block
 block discarded – undo
312 312
      * Трансформация объекта в строку
313 313
      * @return string последний ответ от DocLister'а
314 314
      */
315
-    public function __toString()
316
-    {
315
+    public function __toString()
316
+    {
317 317
         return $this->outData;
318 318
     }
319 319
 
@@ -321,8 +321,8 @@  discard block
 block discarded – undo
321 321
      * Установить время запуска сниппета
322 322
      * @param float|null $time
323 323
      */
324
-    public function setTimeStart($time = null)
325
-    {
324
+    public function setTimeStart($time = null)
325
+    {
326 326
         $this->_timeStart = is_null($time) ? microtime(true) : $time;
327 327
     }
328 328
 
@@ -331,8 +331,8 @@  discard block
 block discarded – undo
331 331
      *
332 332
      * @return int
333 333
      */
334
-    public function getTimeStart()
335
-    {
334
+    public function getTimeStart()
335
+    {
336 336
         return $this->_timeStart;
337 337
     }
338 338
 
@@ -340,27 +340,27 @@  discard block
 block discarded – undo
340 340
      * Установка режима отладки
341 341
      * @param int $flag режим отладки
342 342
      */
343
-    public function setDebug($flag = 0)
344
-    {
343
+    public function setDebug($flag = 0)
344
+    {
345 345
         $flag = abs((int)$flag);
346
-        if ($this->_debugMode != $flag) {
346
+        if ($this->_debugMode != $flag) {
347 347
             $this->_debugMode = $flag;
348 348
             $this->debug = null;
349
-            if ($this->_debugMode > 0) {
350
-                if (isset($_SESSION['usertype']) && $_SESSION['usertype'] == 'manager') {
349
+            if ($this->_debugMode > 0) {
350
+                if (isset($_SESSION['usertype']) && $_SESSION['usertype'] == 'manager') {
351 351
                     error_reporting(E_ALL ^ E_NOTICE);
352 352
                     ini_set('display_errors', 1);
353 353
                 }
354 354
                 $dir = dirname(dirname(__FILE__));
355
-                if (file_exists($dir . "/lib/DLdebug.class.php")) {
355
+                if (file_exists($dir . "/lib/DLdebug.class.php")) {
356 356
                     include_once($dir . "/lib/DLdebug.class.php");
357
-                    if (class_exists("DLdebug", false)) {
357
+                    if (class_exists("DLdebug", false)) {
358 358
                         $this->debug = new DLdebug($this);
359 359
                     }
360 360
                 }
361 361
             }
362 362
 
363
-            if (is_null($this->debug)) {
363
+            if (is_null($this->debug)) {
364 364
                 $this->debug = new xNop();
365 365
                 $this->_debugMode = 0;
366 366
                 error_reporting(0);
@@ -372,8 +372,8 @@  discard block
 block discarded – undo
372 372
     /**
373 373
      * Информация о режиме отладки
374 374
      */
375
-    public function getDebug()
376
-    {
375
+    public function getDebug()
376
+    {
377 377
         return $this->_debugMode;
378 378
     }
379 379
 
@@ -384,13 +384,13 @@  discard block
 block discarded – undo
384 384
      * @param string $alias желаемый алиас таблицы
385 385
      * @return string имя таблицы с префиксом и алиасом
386 386
      */
387
-    public function getTable($name, $alias = '')
388
-    {
389
-        if (!isset($this->_table[$name])) {
387
+    public function getTable($name, $alias = '')
388
+    {
389
+        if (!isset($this->_table[$name])) {
390 390
             $this->_table[$name] = $this->modx->getFullTableName($name);
391 391
         }
392 392
         $table = $this->_table[$name];
393
-        if (!empty($alias) && is_scalar($alias)) {
393
+        if (!empty($alias) && is_scalar($alias)) {
394 394
             $table .= " as `" . $alias . "`";
395 395
         }
396 396
 
@@ -403,9 +403,9 @@  discard block
 block discarded – undo
403 403
      * @param $alias
404 404
      * @return mixed
405 405
      */
406
-    public function TableAlias($name, $table, $alias)
407
-    {
408
-        if (!$this->checkTableAlias($name, $table)) {
406
+    public function TableAlias($name, $table, $alias)
407
+    {
408
+        if (!$this->checkTableAlias($name, $table)) {
409 409
             $this->AddTable[$table][$name] = $alias;
410 410
         }
411 411
 
@@ -417,8 +417,8 @@  discard block
 block discarded – undo
417 417
      * @param $table
418 418
      * @return bool
419 419
      */
420
-    public function checkTableAlias($name, $table)
421
-    {
420
+    public function checkTableAlias($name, $table)
421
+    {
422 422
         return isset($this->AddTable[$table][$name]);
423 423
     }
424 424
 
@@ -430,8 +430,8 @@  discard block
 block discarded – undo
430 430
      * @param bool $nop создавать ли пустой объект запрашиваемого типа
431 431
      * @return array|mixed|xNop
432 432
      */
433
-    public function jsonDecode($json, $config = array(), $nop = false)
434
-    {
433
+    public function jsonDecode($json, $config = array(), $nop = false)
434
+    {
435 435
         $this->debug->debug('Decode JSON: ' . $this->debug->dumpData($json) . "\r\nwith config: " . $this->debug->dumpData($config),
436 436
             'jsonDecode', 2);
437 437
         $config = jsonHelper::jsonDecode($json, $config, $nop);
@@ -447,10 +447,10 @@  discard block
 block discarded – undo
447 447
      * @param $json string строка с JSON для записи в лог при отладке
448 448
      * @return bool|string
449 449
      */
450
-    public function isErrorJSON($json)
451
-    {
450
+    public function isErrorJSON($json)
451
+    {
452 452
         $error = jsonHelper::json_last_error_msg();
453
-        if (!in_array($error, array('error_none', 'other'))) {
453
+        if (!in_array($error, array('error_none', 'other'))) {
454 454
             $this->debug->error($this->getMsg('json.' . $error) . ": " . $this->debug->dumpData($json, 'code'), 'JSON');
455 455
             $error = true;
456 456
         }
@@ -462,20 +462,20 @@  discard block
 block discarded – undo
462 462
      * Проверка параметров и загрузка необходимых экстендеров
463 463
      * return boolean статус загрузки
464 464
      */
465
-    public function checkDL()
466
-    {
465
+    public function checkDL()
466
+    {
467 467
         $this->debug->debug('Check DocLister parameters', 'checkDL', 2);
468 468
         $flag = true;
469 469
         $extenders = $this->getCFGDef('extender', '');
470 470
         $extenders = explode(",", $extenders);
471 471
         $tmp = $this->getCFGDef('requestActive', '') != '' || in_array('request', $extenders);
472
-        if ($tmp && !$this->_loadExtender('request')) {
472
+        if ($tmp && !$this->_loadExtender('request')) {
473 473
             //OR request in extender's parameter
474 474
             throw new Exception('Error load request extender');
475 475
         }
476 476
 
477 477
         $tmp = $this->getCFGDef('summary', '') != '' || in_array('summary', $extenders);
478
-        if ($tmp && !$this->_loadExtender('summary')) {
478
+        if ($tmp && !$this->_loadExtender('summary')) {
479 479
             //OR summary in extender's parameter
480 480
             throw new Exception('Error load summary extender');
481 481
         }
@@ -488,15 +488,15 @@  discard block
 block discarded – undo
488 488
                 $this->getCFGDef('pageLimit', '') != '' || $this->getCFGDef('pageAdjacents', '') != '' ||
489 489
                 $this->getCFGDef('PaginateClass', '') != '' || $this->getCFGDef('TplNextP', '') != ''
490 490
             ) && !$this->_loadExtender('paginate')
491
-        ) {
491
+        ) {
492 492
             throw new Exception('Error load paginate extender');
493
-        } else {
494
-            if ((int)$this->getCFGDef('display', 0) == 0) {
493
+        } else {
494
+            if ((int)$this->getCFGDef('display', 0) == 0) {
495 495
                 $extenders = $this->unsetArrayVal($extenders, 'paginate');
496 496
             }
497 497
         }
498 498
 
499
-        if ($this->getCFGDef('prepare', '') != '' || $this->getCFGDef('prepareWrap') != '') {
499
+        if ($this->getCFGDef('prepare', '') != '' || $this->getCFGDef('prepareWrap') != '') {
500 500
             $this->_loadExtender('prepare');
501 501
         }
502 502
 
@@ -513,14 +513,14 @@  discard block
 block discarded – undo
513 513
      * @param mixed $val значение которые необходимо удалить из массива
514 514
      * @return array отчищеный массив с данными
515 515
      */
516
-    private function unsetArrayVal($data, $val)
517
-    {
516
+    private function unsetArrayVal($data, $val)
517
+    {
518 518
         $out = array();
519
-        if (is_array($data)) {
520
-            foreach ($data as $item) {
521
-                if ($item != $val) {
519
+        if (is_array($data)) {
520
+            foreach ($data as $item) {
521
+                if ($item != $val) {
522 522
                     $out[] = $item;
523
-                } else {
523
+                } else {
524 524
                     continue;
525 525
                 }
526 526
             }
@@ -535,14 +535,14 @@  discard block
 block discarded – undo
535 535
      * @param int $id уникальный идентификатор страницы
536 536
      * @return string URL страницы
537 537
      */
538
-    public function getUrl($id = 0)
539
-    {
538
+    public function getUrl($id = 0)
539
+    {
540 540
         $id = ((int)$id > 0) ? (int)$id : $this->getCurrentMODXPageID();
541 541
 
542 542
         $link = $this->checkExtender('request') ? $this->extender['request']->getLink() : $this->getRequest();
543
-        if ($id == $this->modx->config['site_start']) {
543
+        if ($id == $this->modx->config['site_start']) {
544 544
             $url = $this->modx->config['site_url'] . ($link != '' ? "?{$link}" : "");
545
-        } else {
545
+        } else {
546 546
             $url = $this->modx->makeUrl($id, '', $link, $this->getCFGDef('urlScheme', ''));
547 547
         }
548 548
 
@@ -570,16 +570,16 @@  discard block
 block discarded – undo
570 570
      * @param string $tpl шаблон
571 571
      * @return string
572 572
      */
573
-    public function render($tpl = '')
574
-    {
573
+    public function render($tpl = '')
574
+    {
575 575
         $this->debug->debug(array('Render data with template ' => $tpl), 'render', 2, array('html'));
576 576
         $out = '';
577
-        if (1 == $this->getCFGDef('tree', '0')) {
578
-            foreach ($this->_tree as $item) {
577
+        if (1 == $this->getCFGDef('tree', '0')) {
578
+            foreach ($this->_tree as $item) {
579 579
                 $out .= $this->renderTree($item);
580 580
             }
581 581
             $out = $this->renderWrap($out);
582
-        } else {
582
+        } else {
583 583
             $out = $this->_render($tpl);
584 584
         }
585 585
 
@@ -598,8 +598,8 @@  discard block
 block discarded – undo
598 598
      *
599 599
      * @return int
600 600
      */
601
-    public function getCurrentMODXPageID()
602
-    {
601
+    public function getCurrentMODXPageID()
602
+    {
603 603
         $id = isset($this->modx->documentIdentifier) ? (int)$this->modx->documentIdentifier : 0;
604 604
         $docData = isset($this->modx->documentObject) ? $this->modx->documentObject : array();
605 605
 
@@ -615,9 +615,9 @@  discard block
 block discarded – undo
615 615
      * @param integer $line error on line
616 616
      * @param array $trace stack trace
617 617
      */
618
-    public function ErrorLogger($message, $code, $file, $line, $trace)
619
-    {
620
-        if (abs($this->getCFGDef('debug', '0')) == '1') {
618
+    public function ErrorLogger($message, $code, $file, $line, $trace)
619
+    {
620
+        if (abs($this->getCFGDef('debug', '0')) == '1') {
621 621
             $out = "CODE #" . $code . "<br />";
622 622
             $out .= "on file: " . $file . ":" . $line . "<br />";
623 623
             $out .= "<pre>";
@@ -634,8 +634,8 @@  discard block
 block discarded – undo
634 634
      *
635 635
      * @return DocumentParser
636 636
      */
637
-    public function getMODX()
638
-    {
637
+    public function getMODX()
638
+    {
639 639
         return $this->modx;
640 640
     }
641 641
 
@@ -646,13 +646,13 @@  discard block
 block discarded – undo
646 646
      * @return boolean status load extenders
647 647
      * @throws Exception
648 648
      */
649
-    public function loadExtender($ext = '')
650
-    {
649
+    public function loadExtender($ext = '')
650
+    {
651 651
         $out = true;
652
-        if ($ext != '') {
652
+        if ($ext != '') {
653 653
             $ext = explode(",", $ext);
654
-            foreach ($ext as $item) {
655
-                if ($item != '' && !$this->_loadExtender($item)) {
654
+            foreach ($ext as $item) {
655
+                if ($item != '' && !$this->_loadExtender($item)) {
656 656
                     throw new Exception('Error load ' . APIHelpers::e($item) . ' extender');
657 657
                 }
658 658
             }
@@ -668,8 +668,8 @@  discard block
 block discarded – undo
668 668
      * @param mixed $def значение по умолчанию, если в конфиге нет искомого параметра
669 669
      * @return mixed значение из конфига
670 670
      */
671
-    public function getCFGDef($name, $def = null)
672
-    {
671
+    public function getCFGDef($name, $def = null)
672
+    {
673 673
         return $this->config->getCFGDef($name, $def);
674 674
     }
675 675
 
@@ -681,15 +681,15 @@  discard block
 block discarded – undo
681 681
      * @param string $key ключ локального плейсхолдера
682 682
      * @return string
683 683
      */
684
-    public function toPlaceholders($data, $set = 0, $key = 'contentPlaceholder')
685
-    {
684
+    public function toPlaceholders($data, $set = 0, $key = 'contentPlaceholder')
685
+    {
686 686
         $this->debug->debug(null, 'toPlaceholders', 2);
687
-        if ($set == 0) {
687
+        if ($set == 0) {
688 688
             $set = $this->getCFGDef('contentPlaceholder', 0);
689 689
         }
690 690
         $this->_plh[$key] = $data;
691 691
         $id = $this->getCFGDef('id', '');
692
-        if ($id != '') {
692
+        if ($id != '') {
693 693
             $id .= ".";
694 694
         }
695 695
         $out = DLTemplate::getInstance($this->getMODX())->toPlaceholders($data, $set, $key, $id);
@@ -711,14 +711,14 @@  discard block
 block discarded – undo
711 711
      * @param boolean $quote заключать ли данные на выходе в кавычки
712 712
      * @return string обработанная строка
713 713
      */
714
-    public function sanitarIn($data, $sep = ',', $quote = true)
715
-    {
716
-        if (!is_array($data)) {
714
+    public function sanitarIn($data, $sep = ',', $quote = true)
715
+    {
716
+        if (!is_array($data)) {
717 717
             $data = explode($sep, $data);
718 718
         }
719 719
         $out = array();
720
-        foreach ($data as $item) {
721
-            if ($item !== '') {
720
+        foreach ($data as $item) {
721
+            if ($item !== '') {
722 722
                 $out[] = $this->modx->db->escape($item);
723 723
             }
724 724
         }
@@ -739,12 +739,12 @@  discard block
 block discarded – undo
739 739
      * @param string $lang имя языкового пакета
740 740
      * @return array
741 741
      */
742
-    public function getCustomLang($lang = '')
743
-    {
744
-        if (empty($lang)) {
742
+    public function getCustomLang($lang = '')
743
+    {
744
+        if (empty($lang)) {
745 745
             $lang = $this->getCFGDef('lang', $this->modx->config['manager_language']);
746 746
         }
747
-        if (file_exists(dirname(dirname(__FILE__)) . "/lang/" . $lang . ".php")) {
747
+        if (file_exists(dirname(dirname(__FILE__)) . "/lang/" . $lang . ".php")) {
748 748
             $tmp = include(dirname(__FILE__) . "/lang/" . $lang . ".php");
749 749
             $this->_customLang = is_array($tmp) ? $tmp : array();
750 750
         }
@@ -760,25 +760,25 @@  discard block
 block discarded – undo
760 760
      * @param boolean $rename Переименовывать ли элементы массива
761 761
      * @return array массив с лексиконом
762 762
      */
763
-    public function loadLang($name = 'core', $lang = '', $rename = true)
764
-    {
765
-        if (empty($lang)) {
763
+    public function loadLang($name = 'core', $lang = '', $rename = true)
764
+    {
765
+        if (empty($lang)) {
766 766
             $lang = $this->getCFGDef('lang', $this->modx->config['manager_language']);
767 767
         }
768 768
 
769 769
         $this->debug->debug('Load language ' . $this->debug->dumpData($name) . "." . $this->debug->dumpData($lang),
770 770
             'loadlang', 2);
771
-        if (is_scalar($name)) {
771
+        if (is_scalar($name)) {
772 772
             $name = array($name);
773 773
         }
774
-        foreach ($name as $n) {
775
-            if (file_exists(dirname(__FILE__) . "/lang/" . $lang . "/" . $n . ".inc.php")) {
774
+        foreach ($name as $n) {
775
+            if (file_exists(dirname(__FILE__) . "/lang/" . $lang . "/" . $n . ".inc.php")) {
776 776
                 $tmp = include(dirname(__FILE__) . "/lang/" . $lang . "/" . $n . ".inc.php");
777
-                if (is_array($tmp)) {
777
+                if (is_array($tmp)) {
778 778
                     /**
779 779
                      * Переименовыываем элементы массива из array('test'=>'data') в array('name.test'=>'data')
780 780
                      */
781
-                    if ($rename) {
781
+                    if ($rename) {
782 782
                         $tmp = $this->renameKeyArr($tmp, $n, '', '.');
783 783
                     }
784 784
                     $this->_lang = array_merge($this->_lang, $tmp);
@@ -797,11 +797,11 @@  discard block
 block discarded – undo
797 797
      * @param string $def Строка по умолчанию, если запись в языковом пакете не будет обнаружена
798 798
      * @return string строка в соответствии с текущими языковыми настройками
799 799
      */
800
-    public function getMsg($name, $def = '')
801
-    {
802
-        if (isset($this->_customLang[$name])) {
800
+    public function getMsg($name, $def = '')
801
+    {
802
+        if (isset($this->_customLang[$name])) {
803 803
             $say = $this->_customLang[$name];
804
-        } else {
804
+        } else {
805 805
             $say = \APIHelpers::getkey($this->_lang, $name, $def);
806 806
         }
807 807
 
@@ -817,8 +817,8 @@  discard block
 block discarded – undo
817 817
      * @param string $sep разделитель суффиксов, префиксов и ключей массива
818 818
      * @return array массив с переименованными ключами
819 819
      */
820
-    public function renameKeyArr($data, $prefix = '', $suffix = '', $sep = '.')
821
-    {
820
+    public function renameKeyArr($data, $prefix = '', $suffix = '', $sep = '.')
821
+    {
822 822
         return \APIHelpers::renameKeyArr($data, $prefix, $suffix, $sep);
823 823
     }
824 824
 
@@ -828,12 +828,12 @@  discard block
 block discarded – undo
828 828
      * @param string $locale локаль
829 829
      * @return string имя установленной локали
830 830
      */
831
-    public function setLocate($locale = '')
832
-    {
833
-        if ('' == $locale) {
831
+    public function setLocate($locale = '')
832
+    {
833
+        if ('' == $locale) {
834 834
             $locale = $this->getCFGDef('locale', '');
835 835
         }
836
-        if ('' != $locale) {
836
+        if ('' != $locale) {
837 837
             setlocale(LC_ALL, $locale);
838 838
         }
839 839
 
@@ -847,11 +847,11 @@  discard block
 block discarded – undo
847 847
      * @param array $data массив сформированный как дерево
848 848
      * @return string строка для отображения пользователю
849 849
      */
850
-    protected function renderTree($data)
851
-    {
850
+    protected function renderTree($data)
851
+    {
852 852
         $out = '';
853
-        if (!empty($data['#childNodes'])) {
854
-            foreach ($data['#childNodes'] as $item) {
853
+        if (!empty($data['#childNodes'])) {
854
+            foreach ($data['#childNodes'] as $item) {
855 855
                 $out .= $this->renderTree($item);
856 856
             }
857 857
         }
@@ -868,8 +868,8 @@  discard block
 block discarded – undo
868 868
      * @param string $name Template: chunk name || @CODE: template || @FILE: file with template
869 869
      * @return string html template with placeholders without data
870 870
      */
871
-    private function _getChunk($name)
872
-    {
871
+    private function _getChunk($name)
872
+    {
873 873
         $this->debug->debug(array('Get chunk by name' => $name), "getChunk", 2, array('html'));
874 874
         //without trim
875 875
         $tpl = DLTemplate::getInstance($this->getMODX())->getChunk($name);
@@ -886,18 +886,18 @@  discard block
 block discarded – undo
886 886
      * @param string $tpl HTML шаблон
887 887
      * @return string
888 888
      */
889
-    public function parseLang($tpl)
890
-    {
889
+    public function parseLang($tpl)
890
+    {
891 891
         $this->debug->debug(array("parseLang" => $tpl), "parseLang", 2, array('html'));
892
-        if (is_scalar($tpl) && !empty($tpl)) {
893
-            if (preg_match_all("/\[\%([a-zA-Z0-9\.\_\-]+)\%\]/", $tpl, $match)) {
892
+        if (is_scalar($tpl) && !empty($tpl)) {
893
+            if (preg_match_all("/\[\%([a-zA-Z0-9\.\_\-]+)\%\]/", $tpl, $match)) {
894 894
                 $langVal = array();
895
-                foreach ($match[1] as $item) {
895
+                foreach ($match[1] as $item) {
896 896
                     $langVal[] = $this->getMsg($item);
897 897
                 }
898 898
                 $tpl = str_replace($match[0], $langVal, $tpl);
899 899
             }
900
-        } else {
900
+        } else {
901 901
             $tpl = '';
902 902
         }
903 903
         $this->debug->debugEnd("parseLang");
@@ -913,20 +913,24 @@  discard block
 block discarded – undo
913 913
      * @param bool $parseDocumentSource render html template via DocumentParser::parseDocumentSource()
914 914
      * @return string html template with data without placeholders
915 915
      */
916
-    public function parseChunk($name, $data, $parseDocumentSource = false)
917
-    {
916
+    public function parseChunk($name, $data, $parseDocumentSource = false)
917
+    {
918 918
         $this->debug->debug(
919 919
             array("parseChunk" => $name, "With data" => print_r($data, 1)),
920 920
             "parseChunk",
921 921
             2, array('html', null)
922 922
         );
923 923
         $DLTemplate = DLTemplate::getInstance($this->getMODX());
924
-        if ($path = $this->getCFGDef('templatePath')) $DLTemplate->setTemplatePath($path);
925
-        if ($ext = $this->getCFGDef('templateExtension')) $DLTemplate->setTemplateExtension($ext);
924
+        if ($path = $this->getCFGDef('templatePath')) {
925
+            $DLTemplate->setTemplatePath($path);
926
+        }
927
+        if ($ext = $this->getCFGDef('templateExtension')) {
928
+            $DLTemplate->setTemplateExtension($ext);
929
+        }
926 930
         $DLTemplate->setTwigTemplateVars(array('DocLister'=>$this));
927 931
         $out = $DLTemplate->parseChunk($name, $data, $parseDocumentSource);
928 932
         $out = $this->parseLang($out);
929
-        if (empty($out)) {
933
+        if (empty($out)) {
930 934
             $this->debug->debug("Empty chunk: " . $this->debug->dumpData($name), '', 2);
931 935
         }
932 936
         $this->debug->debugEnd("parseChunk");
@@ -942,8 +946,8 @@  discard block
 block discarded – undo
942 946
      *
943 947
      * @return string html template from parameter
944 948
      */
945
-    public function getChunkByParam($name, $val = '')
946
-    {
949
+    public function getChunkByParam($name, $val = '')
950
+    {
947 951
         $data = $this->getCFGDef($name, $val);
948 952
         $data = $this->_getChunk($data);
949 953
 
@@ -956,11 +960,11 @@  discard block
 block discarded – undo
956 960
      * @param string $data html код который нужно обернуть в ownerTPL
957 961
      * @return string результатирующий html код
958 962
      */
959
-    public function renderWrap($data)
960
-    {
963
+    public function renderWrap($data)
964
+    {
961 965
         $out = $data;
962 966
         $docs = count($this->_docs) - $this->skippedDocs;
963
-        if ((($this->getCFGDef("noneWrapOuter", "1") && $docs == 0) || $docs > 0) && !empty($this->ownerTPL)) {
967
+        if ((($this->getCFGDef("noneWrapOuter", "1") && $docs == 0) || $docs > 0) && !empty($this->ownerTPL)) {
964 968
             $this->debug->debug("", "renderWrapTPL", 2);
965 969
             $parse = true;
966 970
             $plh = array($this->getCFGDef("sysKey", "dl") . ".wrap" => $data);
@@ -968,7 +972,7 @@  discard block
 block discarded – undo
968 972
              * @var $extPrepare prepare_DL_Extender
969 973
              */
970 974
             $extPrepare = $this->getExtender('prepare');
971
-            if ($extPrepare) {
975
+            if ($extPrepare) {
972 976
                 $params = $extPrepare->init($this, array(
973 977
                     'data'      => array(
974 978
                         'docs'         => $this->_docs,
@@ -977,13 +981,13 @@  discard block
 block discarded – undo
977 981
                     'nameParam' => 'prepareWrap',
978 982
                     'return'    => 'placeholders'
979 983
                 ));
980
-                if (is_bool($params) && $params === false) {
984
+                if (is_bool($params) && $params === false) {
981 985
                     $out = $data;
982 986
                     $parse = false;
983 987
                 }
984 988
                 $plh = $params;
985 989
             }
986
-            if ($parse && !empty($this->ownerTPL)) {
990
+            if ($parse && !empty($this->ownerTPL)) {
987 991
                 $this->debug->updateMessage(
988 992
                     array("render ownerTPL" => $this->ownerTPL, "With data" => print_r($plh, 1)),
989 993
                     "renderWrapTPL",
@@ -991,7 +995,7 @@  discard block
 block discarded – undo
991 995
                 );
992 996
                 $out = $this->parseChunk($this->ownerTPL, $plh);
993 997
             }
994
-            if (empty($this->ownerTPL)) {
998
+            if (empty($this->ownerTPL)) {
995 999
                 $this->debug->updateMessage("empty ownerTPL", "renderWrapTPL");
996 1000
             }
997 1001
             $this->debug->debugEnd("renderWrapTPL");
@@ -1007,8 +1011,8 @@  discard block
 block discarded – undo
1007 1011
      * @param int $i номер итерации в цикле
1008 1012
      * @return array массив с данными которые можно использовать в цикле render метода
1009 1013
      */
1010
-    protected function uniformPrepare(&$data, $i = 0)
1011
-    {
1014
+    protected function uniformPrepare(&$data, $i = 0)
1015
+    {
1012 1016
         $class = array();
1013 1017
 
1014 1018
         $iterationName = ($i % 2 == 1) ? 'Odd' : 'Even';
@@ -1022,20 +1026,20 @@  discard block
 block discarded – undo
1022 1026
             "dl") . '.full_iteration'] = ($this->extPaginate) ? ($i + $this->getCFGDef('display',
1023 1027
                 0) * ($this->extPaginate->currentPage() - 1)) : $i;
1024 1028
 
1025
-        if ($i == 1) {
1029
+        if ($i == 1) {
1026 1030
             $this->renderTPL = $this->getCFGDef('tplFirst', $this->renderTPL);
1027 1031
             $class[] = $this->getCFGDef('firstClass', 'first');
1028 1032
         }
1029
-        if ($i == (count($this->_docs) - $this->skippedDocs)) {
1033
+        if ($i == (count($this->_docs) - $this->skippedDocs)) {
1030 1034
             $this->renderTPL = $this->getCFGDef('tplLast', $this->renderTPL);
1031 1035
             $class[] = $this->getCFGDef('lastClass', 'last');
1032 1036
         }
1033
-        if ($this->modx->documentIdentifier == $data['id']) {
1037
+        if ($this->modx->documentIdentifier == $data['id']) {
1034 1038
             $this->renderTPL = $this->getCFGDef('tplCurrent', $this->renderTPL);
1035 1039
             $data[$this->getCFGDef("sysKey",
1036 1040
                 "dl") . '.active'] = 1; //[+active+] - 1 if $modx->documentIdentifer equal ID this element
1037 1041
             $class[] = $this->getCFGDef('currentClass', 'current');
1038
-        } else {
1042
+        } else {
1039 1043
             $data[$this->getCFGDef("sysKey", "dl") . '.active'] = 0;
1040 1044
         }
1041 1045
 
@@ -1046,8 +1050,8 @@  discard block
 block discarded – undo
1046 1050
          * @var $extE e_DL_Extender
1047 1051
          */
1048 1052
         $extE = $this->getExtender('e', true, true);
1049
-        if ($out = $extE->init($this, compact('data'))) {
1050
-            if (is_array($out)) {
1053
+        if ($out = $extE->init($this, compact('data'))) {
1054
+            if (is_array($out)) {
1051 1055
                 $data = $out;
1052 1056
             }
1053 1057
         }
@@ -1063,42 +1067,43 @@  discard block
 block discarded – undo
1063 1067
      * @param array $array данные которые необходимо примешать к ответу на каждой записи $data
1064 1068
      * @return string JSON строка
1065 1069
      */
1066
-    public function getJSON($data, $fields, $array = array())
1067
-    {
1070
+    public function getJSON($data, $fields, $array = array())
1071
+    {
1068 1072
         $out = array();
1069 1073
         $fields = is_array($fields) ? $fields : explode(",", $fields);
1070
-        if (is_array($array) && count($array) > 0) {
1074
+        if (is_array($array) && count($array) > 0) {
1071 1075
             $tmp = array();
1072
-            foreach ($data as $i => $v) { //array_merge not valid work with integer index key
1076
+            foreach ($data as $i => $v) {
1077
+//array_merge not valid work with integer index key
1073 1078
                 $tmp[$i] = (isset($array[$i]) ? array_merge($v, $array[$i]) : $v);
1074 1079
             }
1075 1080
             $data = $tmp;
1076 1081
         }
1077 1082
 
1078
-        foreach ($data as $num => $doc) {
1083
+        foreach ($data as $num => $doc) {
1079 1084
             $tmp = array();
1080
-            foreach ($doc as $name => $value) {
1081
-                if (in_array($name, $fields) || (isset($fields[0]) && $fields[0] == '1')) {
1085
+            foreach ($doc as $name => $value) {
1086
+                if (in_array($name, $fields) || (isset($fields[0]) && $fields[0] == '1')) {
1082 1087
                     $tmp[str_replace(".", "_", $name)] = $value; //JSON element name without dot
1083 1088
                 }
1084 1089
             }
1085 1090
             $out[$num] = $tmp;
1086 1091
         }
1087 1092
 
1088
-        if ('new' == $this->getCFGDef('JSONformat', 'old')) {
1093
+        if ('new' == $this->getCFGDef('JSONformat', 'old')) {
1089 1094
             $return = array();
1090 1095
 
1091 1096
             $return['rows'] = array();
1092
-            foreach ($out as $key => $item) {
1097
+            foreach ($out as $key => $item) {
1093 1098
                 $return['rows'][] = APIHelpers::getkey($item, $key, $item);
1094 1099
             }
1095 1100
             $return['total'] = $this->getChildrenCount();
1096
-        }elseif ('simple' == $this->getCFGDef('JSONformat', 'old')) {
1101
+        } elseif ('simple' == $this->getCFGDef('JSONformat', 'old')) {
1097 1102
             $return = array();
1098
-            foreach ($out as $key => $item) {
1103
+            foreach ($out as $key => $item) {
1099 1104
                 $return[] = APIHelpers::getkey($item, $key, $item);
1100 1105
             }
1101
-        } else {
1106
+        } else {
1102 1107
             $return = $out;
1103 1108
         }
1104 1109
         $this->outData = json_encode($return);
@@ -1114,11 +1119,11 @@  discard block
 block discarded – undo
1114 1119
      * @param string $contentField
1115 1120
      * @return mixed|string
1116 1121
      */
1117
-    protected function getSummary(array $item = array(), $extSummary = null, $introField = '', $contentField = '')
1118
-    {
1122
+    protected function getSummary(array $item = array(), $extSummary = null, $introField = '', $contentField = '')
1123
+    {
1119 1124
         $out = '';
1120 1125
 
1121
-        if (is_null($extSummary)) {
1126
+        if (is_null($extSummary)) {
1122 1127
             /**
1123 1128
              * @var $extSummary summary_DL_Extender
1124 1129
              */
@@ -1127,10 +1132,10 @@  discard block
 block discarded – undo
1127 1132
         $introField = $this->getCFGDef("introField", $introField);
1128 1133
         $contentField = $this->getCFGDef("contentField", $contentField);
1129 1134
 
1130
-        if (!empty($introField) && !empty($item[$introField]) && mb_strlen($item[$introField], 'UTF-8') > 0) {
1135
+        if (!empty($introField) && !empty($item[$introField]) && mb_strlen($item[$introField], 'UTF-8') > 0) {
1131 1136
             $out = $item[$introField];
1132
-        } else {
1133
-            if (!empty($contentField) && !empty($item[$contentField]) && mb_strlen($item[$contentField], 'UTF-8') > 0) {
1137
+        } else {
1138
+            if (!empty($contentField) && !empty($item[$contentField]) && mb_strlen($item[$contentField], 'UTF-8') > 0) {
1134 1139
                 $out = $extSummary->init($this, array(
1135 1140
                     "content"      => $item[$contentField],
1136 1141
                     "action"       => $this->getCFGDef("summary", ""),
@@ -1148,8 +1153,8 @@  discard block
 block discarded – undo
1148 1153
      * @param string $name extender name
1149 1154
      * @return boolean status extender load
1150 1155
      */
1151
-    public function checkExtender($name)
1152
-    {
1156
+    public function checkExtender($name)
1157
+    {
1153 1158
         return (isset($this->extender[$name]) && $this->extender[$name] instanceof $name . "_DL_Extender");
1154 1159
     }
1155 1160
 
@@ -1157,8 +1162,8 @@  discard block
 block discarded – undo
1157 1162
      * @param $name
1158 1163
      * @param $obj
1159 1164
      */
1160
-    public function setExtender($name, $obj)
1161
-    {
1165
+    public function setExtender($name, $obj)
1166
+    {
1162 1167
         $this->extender[$name] = $obj;
1163 1168
     }
1164 1169
 
@@ -1170,13 +1175,13 @@  discard block
 block discarded – undo
1170 1175
      * @param bool $nop если экстендер не загружен, то загружать ли xNop
1171 1176
      * @return null|xNop
1172 1177
      */
1173
-    public function getExtender($name, $autoload = false, $nop = false)
1174
-    {
1178
+    public function getExtender($name, $autoload = false, $nop = false)
1179
+    {
1175 1180
         $out = null;
1176
-        if ((is_scalar($name) && $this->checkExtender($name)) || ($autoload && $this->_loadExtender($name))) {
1181
+        if ((is_scalar($name) && $this->checkExtender($name)) || ($autoload && $this->_loadExtender($name))) {
1177 1182
             $out = $this->extender[$name];
1178 1183
         }
1179
-        if ($nop && is_null($out)) {
1184
+        if ($nop && is_null($out)) {
1180 1185
             $out = new xNop();
1181 1186
         }
1182 1187
 
@@ -1189,27 +1194,27 @@  discard block
 block discarded – undo
1189 1194
      * @param string $name name extender
1190 1195
      * @return boolean $flag status load extender
1191 1196
      */
1192
-    protected function _loadExtender($name)
1193
-    {
1197
+    protected function _loadExtender($name)
1198
+    {
1194 1199
         $this->debug->debug('Load Extender ' . $this->debug->dumpData($name), 'LoadExtender', 2);
1195 1200
         $flag = false;
1196 1201
 
1197 1202
         $classname = ($name != '') ? $name . "_DL_Extender" : "";
1198
-        if ($classname != '' && isset($this->extender[$name]) && $this->extender[$name] instanceof $classname) {
1203
+        if ($classname != '' && isset($this->extender[$name]) && $this->extender[$name] instanceof $classname) {
1199 1204
             $flag = true;
1200 1205
 
1201
-        } else {
1202
-            if (!class_exists($classname, false) && $classname != '') {
1203
-                if (file_exists(dirname(__FILE__) . "/extender/" . $name . ".extender.inc")) {
1206
+        } else {
1207
+            if (!class_exists($classname, false) && $classname != '') {
1208
+                if (file_exists(dirname(__FILE__) . "/extender/" . $name . ".extender.inc")) {
1204 1209
                     include_once(dirname(__FILE__) . "/extender/" . $name . ".extender.inc");
1205 1210
                 }
1206 1211
             }
1207
-            if (class_exists($classname, false) && $classname != '') {
1212
+            if (class_exists($classname, false) && $classname != '') {
1208 1213
                 $this->extender[$name] = new $classname($this, $name);
1209 1214
                 $flag = true;
1210 1215
             }
1211 1216
         }
1212
-        if (!$flag) {
1217
+        if (!$flag) {
1213 1218
             $this->debug->debug("Error load Extender " . $this->debug->dumpData($name));
1214 1219
         }
1215 1220
         $this->debug->debugEnd('LoadExtender');
@@ -1227,16 +1232,16 @@  discard block
 block discarded – undo
1227 1232
      * @param mixed $IDs список id документов по которым необходима выборка
1228 1233
      * @return array очищенный массив
1229 1234
      */
1230
-    public function setIDs($IDs)
1231
-    {
1235
+    public function setIDs($IDs)
1236
+    {
1232 1237
         $this->debug->debug('set ID list ' . $this->debug->dumpData($IDs), 'setIDs', 2);
1233 1238
         $IDs = $this->cleanIDs($IDs);
1234 1239
         $type = $this->getCFGDef('idType', 'parents');
1235 1240
         $depth = $this->getCFGDef('depth', '');
1236
-        if ($type == 'parents' && $depth > 0) {
1241
+        if ($type == 'parents' && $depth > 0) {
1237 1242
             $tmp = $IDs;
1238
-            do {
1239
-                if (count($tmp) > 0) {
1243
+            do {
1244
+                if (count($tmp) > 0) {
1240 1245
                     $tmp = $this->getChildrenFolder($tmp);
1241 1246
                     $IDs = array_merge($IDs, $tmp);
1242 1247
                 }
@@ -1250,8 +1255,8 @@  discard block
 block discarded – undo
1250 1255
     /**
1251 1256
      * @return int
1252 1257
      */
1253
-    public function getIDs()
1254
-    {
1258
+    public function getIDs()
1259
+    {
1255 1260
         return $this->IDs;
1256 1261
     }
1257 1262
 
@@ -1262,17 +1267,18 @@  discard block
 block discarded – undo
1262 1267
      * @param string $sep разделитель
1263 1268
      * @return array очищенный массив с данными
1264 1269
      */
1265
-    public function cleanIDs($IDs, $sep = ',')
1266
-    {
1270
+    public function cleanIDs($IDs, $sep = ',')
1271
+    {
1267 1272
         $this->debug->debug('clean IDs ' . $this->debug->dumpData($IDs) . ' with separator ' . $this->debug->dumpData($sep),
1268 1273
             'cleanIDs', 2);
1269 1274
         $out = array();
1270
-        if (!is_array($IDs)) {
1275
+        if (!is_array($IDs)) {
1271 1276
             $IDs = explode($sep, $IDs);
1272 1277
         }
1273
-        foreach ($IDs as $item) {
1278
+        foreach ($IDs as $item) {
1274 1279
             $item = trim($item);
1275
-            if (is_numeric($item) && (int)$item >= 0) { //Fix 0xfffffffff
1280
+            if (is_numeric($item) && (int)$item >= 0) {
1281
+//Fix 0xfffffffff
1276 1282
                 $out[] = (int)$item;
1277 1283
             }
1278 1284
         }
@@ -1286,8 +1292,8 @@  discard block
 block discarded – undo
1286 1292
      * Проверка массива с id-шниками документов для выборки
1287 1293
      * @return boolean пригодны ли данные для дальнейшего использования
1288 1294
      */
1289
-    protected function checkIDs()
1290
-    {
1295
+    protected function checkIDs()
1296
+    {
1291 1297
         return (is_array($this->IDs) && count($this->IDs) > 0) ? true : false;
1292 1298
     }
1293 1299
 
@@ -1299,11 +1305,11 @@  discard block
 block discarded – undo
1299 1305
      * @global array $_docs all documents
1300 1306
      * @return array all field values
1301 1307
      */
1302
-    public function getOneField($userField, $uniq = false)
1303
-    {
1308
+    public function getOneField($userField, $uniq = false)
1309
+    {
1304 1310
         $out = array();
1305
-        foreach ($this->_docs as $doc => $val) {
1306
-            if (isset($val[$userField]) && (($uniq && !in_array($val[$userField], $out)) || !$uniq)) {
1311
+        foreach ($this->_docs as $doc => $val) {
1312
+            if (isset($val[$userField]) && (($uniq && !in_array($val[$userField], $out)) || !$uniq)) {
1307 1313
                 $out[$doc] = $val[$userField];
1308 1314
             }
1309 1315
         }
@@ -1314,8 +1320,8 @@  discard block
 block discarded – undo
1314 1320
     /**
1315 1321
      * @return DLCollection
1316 1322
      */
1317
-    public function docsCollection()
1318
-    {
1323
+    public function docsCollection()
1324
+    {
1319 1325
         return new DLCollection($this->modx, $this->_docs);
1320 1326
     }
1321 1327
 
@@ -1343,10 +1349,10 @@  discard block
 block discarded – undo
1343 1349
      * @param string $group
1344 1350
      * @return string
1345 1351
      */
1346
-    protected function getGroupSQL($group = '')
1347
-    {
1352
+    protected function getGroupSQL($group = '')
1353
+    {
1348 1354
         $out = '';
1349
-        if ($group != '') {
1355
+        if ($group != '') {
1350 1356
             $out = 'GROUP BY ' . $group;
1351 1357
         }
1352 1358
 
@@ -1365,12 +1371,12 @@  discard block
 block discarded – undo
1365 1371
      *
1366 1372
      * @return string Order by for SQL
1367 1373
      */
1368
-    protected function SortOrderSQL($sortName, $orderDef = 'DESC')
1369
-    {
1374
+    protected function SortOrderSQL($sortName, $orderDef = 'DESC')
1375
+    {
1370 1376
         $this->debug->debug('', 'sortORDER', 2);
1371 1377
 
1372 1378
         $sort = '';
1373
-        switch ($this->getCFGDef('sortType', '')) {
1379
+        switch ($this->getCFGDef('sortType', '')) {
1374 1380
             case 'none':
1375 1381
                 break;
1376 1382
             case 'doclist':
@@ -1381,10 +1387,10 @@  discard block
 block discarded – undo
1381 1387
                 break;
1382 1388
             default:
1383 1389
                 $out = array('orderBy' => '', 'order' => '', 'sortBy' => '');
1384
-                if (($tmp = $this->getCFGDef('orderBy', '')) != '') {
1390
+                if (($tmp = $this->getCFGDef('orderBy', '')) != '') {
1385 1391
                     $out['orderBy'] = $tmp;
1386
-                } else {
1387
-                    switch (true) {
1392
+                } else {
1393
+                    switch (true) {
1388 1394
                         case ('' != ($tmp = $this->getCFGDef('sortDir', ''))): //higher priority than order
1389 1395
                             $out['order'] = $tmp;
1390 1396
                         // no break
@@ -1392,7 +1398,7 @@  discard block
 block discarded – undo
1392 1398
                             $out['order'] = $tmp;
1393 1399
                         // no break
1394 1400
                     }
1395
-                    if ('' == $out['order'] || !in_array(strtoupper($out['order']), array('ASC', 'DESC'))) {
1401
+                    if ('' == $out['order'] || !in_array(strtoupper($out['order']), array('ASC', 'DESC'))) {
1396 1402
                         $out['order'] = $orderDef; //Default
1397 1403
                     }
1398 1404
 
@@ -1413,26 +1419,26 @@  discard block
 block discarded – undo
1413 1419
      *
1414 1420
      * @return string LIMIT вставка в SQL запрос
1415 1421
      */
1416
-    protected function LimitSQL($limit = 0, $offset = 0)
1417
-    {
1422
+    protected function LimitSQL($limit = 0, $offset = 0)
1423
+    {
1418 1424
         $this->debug->debug('', 'limitSQL', 2);
1419 1425
         $ret = '';
1420
-        if ($limit == 0) {
1426
+        if ($limit == 0) {
1421 1427
             $limit = $this->getCFGDef('display', 0);
1422 1428
         }
1423
-        if ($offset == 0) {
1429
+        if ($offset == 0) {
1424 1430
             $offset = $this->getCFGDef('offset', 0);
1425 1431
         }
1426 1432
         $offset += $this->getCFGDef('start', 0);
1427 1433
         $total = $this->getCFGDef('total', 0);
1428
-        if ($limit < ($total - $limit)) {
1434
+        if ($limit < ($total - $limit)) {
1429 1435
             $limit = $total - $offset;
1430 1436
         }
1431 1437
 
1432
-        if ($limit != 0) {
1438
+        if ($limit != 0) {
1433 1439
             $ret = "LIMIT " . (int)$offset . "," . (int)$limit;
1434
-        } else {
1435
-            if ($offset != 0) {
1440
+        } else {
1441
+            if ($offset != 0) {
1436 1442
                 /**
1437 1443
                  * To retrieve all rows from a certain offset up to the end of the result set, you can use some large number for the second parameter
1438 1444
                  * @see http://dev.mysql.com/doc/refman/5.0/en/select.html
@@ -1452,8 +1458,8 @@  discard block
 block discarded – undo
1452 1458
      * @param string $charset
1453 1459
      * @return string Clear string
1454 1460
      */
1455
-    public function sanitarData($data, $charset = 'UTF-8')
1456
-    {
1461
+    public function sanitarData($data, $charset = 'UTF-8')
1462
+    {
1457 1463
         return APIHelpers::sanitarTag($data, $charset);
1458 1464
     }
1459 1465
 
@@ -1464,8 +1470,8 @@  discard block
 block discarded – undo
1464 1470
      * @param string $parentField default name parent field
1465 1471
      * @return array
1466 1472
      */
1467
-    public function treeBuild($idField = 'id', $parentField = 'parent')
1468
-    {
1473
+    public function treeBuild($idField = 'id', $parentField = 'parent')
1474
+    {
1469 1475
         return $this->_treeBuild($this->_docs, $this->getCFGDef('idField', $idField),
1470 1476
             $this->getCFGDef('parentField', $parentField));
1471 1477
     }
@@ -1478,16 +1484,16 @@  discard block
 block discarded – undo
1478 1484
      * @param string $pidName name parent field in associative data array
1479 1485
      * @return array
1480 1486
      */
1481
-    private function _treeBuild($data, $idName, $pidName)
1482
-    {
1487
+    private function _treeBuild($data, $idName, $pidName)
1488
+    {
1483 1489
         $children = array(); // children of each ID
1484 1490
         $ids = array();
1485
-        foreach ($data as $i => $r) {
1491
+        foreach ($data as $i => $r) {
1486 1492
             $row =& $data[$i];
1487 1493
             $id = $row[$idName];
1488 1494
             $pid = $row[$pidName];
1489 1495
             $children[$pid][$id] =& $row;
1490
-            if (!isset($children[$id])) {
1496
+            if (!isset($children[$id])) {
1491 1497
                 $children[$id] = array();
1492 1498
             }
1493 1499
             $row['#childNodes'] =& $children[$id];
@@ -1495,9 +1501,9 @@  discard block
 block discarded – undo
1495 1501
         }
1496 1502
         // Root elements are elements with non-found PIDs.
1497 1503
         $this->_tree = array();
1498
-        foreach ($data as $i => $r) {
1504
+        foreach ($data as $i => $r) {
1499 1505
             $row =& $data[$i];
1500
-            if (!isset($ids[$row[$pidName]])) {
1506
+            if (!isset($ids[$row[$pidName]])) {
1501 1507
                 $this->_tree[$row[$idName]] = $row;
1502 1508
             }
1503 1509
         }
@@ -1511,8 +1517,8 @@  discard block
 block discarded – undo
1511 1517
      *
1512 1518
      * @return string PrimaryKey основной таблицы
1513 1519
      */
1514
-    public function getPK()
1515
-    {
1520
+    public function getPK()
1521
+    {
1516 1522
         return isset($this->idField) ? $this->idField : 'id';
1517 1523
     }
1518 1524
 
@@ -1521,8 +1527,8 @@  discard block
 block discarded – undo
1521 1527
      * По умолчанию это parent. Переопределить можно в контроллере присвоив другое значение переменной parentField
1522 1528
      * @return string Parent Key основной таблицы
1523 1529
      */
1524
-    public function getParentField()
1525
-    {
1530
+    public function getParentField()
1531
+    {
1526 1532
         return isset($this->parentField) ? $this->parentField : '';
1527 1533
     }
1528 1534
 
@@ -1533,31 +1539,31 @@  discard block
 block discarded – undo
1533 1539
      * @param string $filter_string строка со всеми фильтрами
1534 1540
      * @return mixed результат разбора фильтров
1535 1541
      */
1536
-    protected function getFilters($filter_string)
1537
-    {
1542
+    protected function getFilters($filter_string)
1543
+    {
1538 1544
         $this->debug->debug("getFilters: " . $this->debug->dumpData($filter_string), 'getFilter', 1);
1539 1545
         // the filter parameter tells us, which filters can be used in this query
1540 1546
         $filter_string = trim($filter_string, ' ;');
1541
-        if (!$filter_string) {
1547
+        if (!$filter_string) {
1542 1548
             return;
1543 1549
         }
1544 1550
         $output = array('join' => '', 'where' => '');
1545 1551
         $logic_op_found = false;
1546 1552
         $joins = $wheres = array();
1547
-        foreach ($this->_logic_ops as $op => $sql) {
1548
-            if (strpos($filter_string, $op) === 0) {
1553
+        foreach ($this->_logic_ops as $op => $sql) {
1554
+            if (strpos($filter_string, $op) === 0) {
1549 1555
                 $logic_op_found = true;
1550 1556
                 $subfilters = mb_substr($filter_string, strlen($op) + 1, mb_strlen($filter_string, "UTF-8"), "UTF-8");
1551 1557
                 $subfilters = $this->smartSplit($subfilters);
1552
-                foreach ($subfilters as $subfilter) {
1558
+                foreach ($subfilters as $subfilter) {
1553 1559
                     $subfilter = $this->getFilters(trim($subfilter));
1554
-                    if (!$subfilter) {
1560
+                    if (!$subfilter) {
1555 1561
                         continue;
1556 1562
                     }
1557
-                    if ($subfilter['join']) {
1563
+                    if ($subfilter['join']) {
1558 1564
                         $joins[] = $subfilter['join'];
1559 1565
                     }
1560
-                    if ($subfilter['where']) {
1566
+                    if ($subfilter['where']) {
1561 1567
                         $wheres[] = $subfilter['where'];
1562 1568
                     }
1563 1569
                 }
@@ -1566,12 +1572,12 @@  discard block
 block discarded – undo
1566 1572
             }
1567 1573
         }
1568 1574
 
1569
-        if (!$logic_op_found) {
1575
+        if (!$logic_op_found) {
1570 1576
             $filter = $this->loadFilter($filter_string);
1571
-            if (!$filter) {
1577
+            if (!$filter) {
1572 1578
                 $this->debug->warning('Error while loading DocLister filter "' . $this->debug->dumpData($filter_string) . '": check syntax!');
1573 1579
                 $output = false;
1574
-            } else {
1580
+            } else {
1575 1581
                 $output['join'] = $filter->get_join();
1576 1582
                 $output['where'] = $filter->get_where();
1577 1583
             }
@@ -1584,16 +1590,16 @@  discard block
 block discarded – undo
1584 1590
     /**
1585 1591
      * @return mixed
1586 1592
      */
1587
-    public function filtersWhere()
1588
-    {
1593
+    public function filtersWhere()
1594
+    {
1589 1595
         return APIHelpers::getkey($this->_filters, 'where', '');
1590 1596
     }
1591 1597
 
1592 1598
     /**
1593 1599
      * @return mixed
1594 1600
      */
1595
-    public function filtersJoin()
1596
-    {
1601
+    public function filtersJoin()
1602
+    {
1597 1603
         return APIHelpers::getkey($this->_filters, 'join', '');
1598 1604
     }
1599 1605
 
@@ -1604,10 +1610,10 @@  discard block
 block discarded – undo
1604 1610
      * @param $type string тип фильтрации
1605 1611
      * @return string имя поля с учетом приведения типа
1606 1612
      */
1607
-    public function changeSortType($field, $type)
1608
-    {
1613
+    public function changeSortType($field, $type)
1614
+    {
1609 1615
         $type = trim($type);
1610
-        switch (strtoupper($type)) {
1616
+        switch (strtoupper($type)) {
1611 1617
             case 'DECIMAL':
1612 1618
                 $field = 'CAST(' . $field . ' as DECIMAL(10,2))';
1613 1619
                 break;
@@ -1633,14 +1639,14 @@  discard block
 block discarded – undo
1633 1639
      * @param string $filter срока с параметрами фильтрации
1634 1640
      * @return bool
1635 1641
      */
1636
-    protected function loadFilter($filter)
1637
-    {
1642
+    protected function loadFilter($filter)
1643
+    {
1638 1644
         $this->debug->debug('Load filter ' . $this->debug->dumpData($filter), 'loadFilter', 2);
1639 1645
         $out = false;
1640 1646
         $fltr_params = explode(':', $filter, 2);
1641 1647
         $fltr = APIHelpers::getkey($fltr_params, 0, null);
1642 1648
         // check if the filter is implemented
1643
-        if (!is_null($fltr) && file_exists(dirname(__FILE__) . '/filter/' . $fltr . '.filter.php')) {
1649
+        if (!is_null($fltr) && file_exists(dirname(__FILE__) . '/filter/' . $fltr . '.filter.php')) {
1644 1650
             require_once dirname(__FILE__) . '/filter/' . $fltr . '.filter.php';
1645 1651
             /**
1646 1652
              * @var tv_DL_filter|content_DL_filter $fltr_class
@@ -1648,12 +1654,12 @@  discard block
 block discarded – undo
1648 1654
             $fltr_class = $fltr . '_DL_filter';
1649 1655
             $this->totalFilters++;
1650 1656
             $fltr_obj = new $fltr_class();
1651
-            if ($fltr_obj->init($this, $filter)) {
1657
+            if ($fltr_obj->init($this, $filter)) {
1652 1658
                 $out = $fltr_obj;
1653
-            } else {
1659
+            } else {
1654 1660
                 $this->debug->error("Wrong filter parameter: '{$this->debug->dumpData($filter)}'", 'Filter');
1655 1661
             }
1656
-        } else {
1662
+        } else {
1657 1663
             $this->debug->error("Error load Filter: '{$this->debug->dumpData($filter)}'", 'Filter');
1658 1664
         }
1659 1665
         $this->debug->debugEnd("loadFilter");
@@ -1665,8 +1671,8 @@  discard block
 block discarded – undo
1665 1671
      * Общее число фильтров
1666 1672
      * @return int
1667 1673
      */
1668
-    public function getCountFilters()
1669
-    {
1674
+    public function getCountFilters()
1675
+    {
1670 1676
         return (int)$this->totalFilters;
1671 1677
     }
1672 1678
 
@@ -1674,8 +1680,8 @@  discard block
 block discarded – undo
1674 1680
      * Выполнить SQL запрос
1675 1681
      * @param string $q SQL запрос
1676 1682
      */
1677
-    public function dbQuery($q)
1678
-    {
1683
+    public function dbQuery($q)
1684
+    {
1679 1685
         $this->debug->debug($q, "query", 1, 'sql');
1680 1686
         $out = $this->modx->db->query($q);
1681 1687
         $this->debug->debugEnd("query");
@@ -1693,8 +1699,8 @@  discard block
 block discarded – undo
1693 1699
      * @param string $tpl шаблон подстановки значения в SQL запрос
1694 1700
      * @return string строка для подстановки в SQL запрос
1695 1701
      */
1696
-    public function LikeEscape($field, $value, $escape = '=', $tpl = '%[+value+]%')
1697
-    {
1702
+    public function LikeEscape($field, $value, $escape = '=', $tpl = '%[+value+]%')
1703
+    {
1698 1704
         return sqlHelper::LikeEscape($this->modx, $field, $value, $escape, $tpl);
1699 1705
     }
1700 1706
 
@@ -1702,8 +1708,8 @@  discard block
 block discarded – undo
1702 1708
      * Получение REQUEST_URI без GET-ключа с
1703 1709
      * @return string
1704 1710
      */
1705
-    public function getRequest()
1706
-    {
1711
+    public function getRequest()
1712
+    {
1707 1713
         $URL = null;
1708 1714
         parse_str(parse_url(MODX_SITE_URL . $_SERVER['REQUEST_URI'], PHP_URL_QUERY), $URL);
1709 1715
 
Please login to merge, or discard this patch.