Completed
Push — master ( 9ef07f...c58502 )
by
unknown
14s
created
assets/snippets/DocLister/core/DocLister.abstract.php 1 patch
Braces   +294 added lines, -291 removed lines patch added patch discarded remove patch
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
 /**
18 18
  * Class DocLister
19 19
  */
20
-abstract class DocLister
21
-{
20
+abstract class DocLister
21
+{
22 22
     /**
23 23
      * Ключ в массиве $_REQUEST в котором находится алиас запрашиваемого документа
24 24
      */
@@ -181,48 +181,48 @@  discard block
 block discarded – undo
181 181
      * @param int $startTime время запуска сниппета
182 182
      * @throws Exception
183 183
      */
184
-    public function __construct($modx, $cfg = array(), $startTime = null)
185
-    {
184
+    public function __construct($modx, $cfg = array(), $startTime = null)
185
+    {
186 186
         $this->setTimeStart($startTime);
187 187
 
188
-        if (extension_loaded('mbstring')) {
188
+        if (extension_loaded('mbstring')) {
189 189
             mb_internal_encoding("UTF-8");
190
-        } else {
190
+        } else {
191 191
             throw new Exception('Not found php extension mbstring');
192 192
         }
193 193
 
194
-        if ($modx instanceof DocumentParser) {
194
+        if ($modx instanceof DocumentParser) {
195 195
             $this->modx = $modx;
196 196
             $this->setDebug(1);
197 197
 
198
-            if (!is_array($cfg) || empty($cfg)) {
198
+            if (!is_array($cfg) || empty($cfg)) {
199 199
                 $cfg = $this->modx->Event->params;
200 200
             }
201
-        } else {
201
+        } else {
202 202
             throw new Exception('MODX var is not instaceof DocumentParser');
203 203
         }
204 204
 
205 205
         $this->FS = \Helpers\FS::getInstance();
206 206
         $this->config = new \Helpers\Config($cfg);
207 207
 
208
-        if (isset($cfg['config'])) {
208
+        if (isset($cfg['config'])) {
209 209
             $this->config->setPath(dirname(__DIR__))->loadConfig($cfg['config']);
210 210
         }
211 211
 
212
-        if ($this->config->setConfig($cfg) === false) {
212
+        if ($this->config->setConfig($cfg) === false) {
213 213
             throw new Exception('no parameters to run DocLister');
214 214
         }
215 215
 
216 216
         $this->loadLang(array('core', 'json'));
217 217
         $this->setDebug($this->getCFGDef('debug', 0));
218 218
 
219
-        if ($this->checkDL()) {
219
+        if ($this->checkDL()) {
220 220
             $cfg = array();
221 221
             $idType = $this->getCFGDef('idType', '');
222
-            if (empty($idType) && $this->getCFGDef('documents', '') != '') {
222
+            if (empty($idType) && $this->getCFGDef('documents', '') != '') {
223 223
                 $idType = 'documents';
224 224
             }
225
-            switch ($idType) {
225
+            switch ($idType) {
226 226
                 case 'documents':
227 227
                     $IDs = $this->getCFGDef('documents');
228 228
                     $cfg['idType'] = "documents";
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
                 case 'parents':
231 231
                 default:
232 232
                     $cfg['idType'] = "parents";
233
-                    if (($IDs = $this->getCFGDef('parents', '')) === '') {
233
+                    if (($IDs = $this->getCFGDef('parents', '')) === '') {
234 234
                         $IDs = $this->getCurrentMODXPageID();
235 235
                     }
236 236
                     break;
@@ -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,25 +266,25 @@  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
                     $cur .= $e;
280 280
                     $cur .= mb_substr($str, ++$i, 1, 'UTF-8');
281 281
                     break;
282 282
                 case ')':
283 283
                     $open--;
284
-                    if ($open == 0) {
284
+                    if ($open == 0) {
285 285
                         $res[] = $cur . ')';
286 286
                         $cur = '';
287
-                    } else {
287
+                    } else {
288 288
                         $cur .= $e;
289 289
                     }
290 290
                     break;
@@ -293,10 +293,10 @@  discard block
 block discarded – undo
293 293
                     $cur .= $e;
294 294
                     break;
295 295
                 case ';':
296
-                    if ($open == 0) {
296
+                    if ($open == 0) {
297 297
                         $res[] = $cur;
298 298
                         $cur = '';
299
-                    } else {
299
+                    } else {
300 300
                         $cur .= $e;
301 301
                     }
302 302
                     break;
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
             }
306 306
         }
307 307
         $cur = preg_replace("/(\))$/u", '', $cur);
308
-        if ($cur != '') {
308
+        if ($cur != '') {
309 309
             $res[] = $cur;
310 310
         }
311 311
 
@@ -316,8 +316,8 @@  discard block
 block discarded – undo
316 316
      * Трансформация объекта в строку
317 317
      * @return string последний ответ от DocLister'а
318 318
      */
319
-    public function __toString()
320
-    {
319
+    public function __toString()
320
+    {
321 321
         return $this->outData;
322 322
     }
323 323
 
@@ -325,8 +325,8 @@  discard block
 block discarded – undo
325 325
      * Установить время запуска сниппета
326 326
      * @param float|null $time
327 327
      */
328
-    public function setTimeStart($time = null)
329
-    {
328
+    public function setTimeStart($time = null)
329
+    {
330 330
         $this->_timeStart = is_null($time) ? microtime(true) : $time;
331 331
     }
332 332
 
@@ -335,8 +335,8 @@  discard block
 block discarded – undo
335 335
      *
336 336
      * @return int
337 337
      */
338
-    public function getTimeStart()
339
-    {
338
+    public function getTimeStart()
339
+    {
340 340
         return $this->_timeStart;
341 341
     }
342 342
 
@@ -344,27 +344,27 @@  discard block
 block discarded – undo
344 344
      * Установка режима отладки
345 345
      * @param int $flag режим отладки
346 346
      */
347
-    public function setDebug($flag = 0)
348
-    {
347
+    public function setDebug($flag = 0)
348
+    {
349 349
         $flag = abs((int)$flag);
350
-        if ($this->_debugMode != $flag) {
350
+        if ($this->_debugMode != $flag) {
351 351
             $this->_debugMode = $flag;
352 352
             $this->debug = null;
353
-            if ($this->_debugMode > 0) {
354
-                if (isset($_SESSION['usertype']) && $_SESSION['usertype'] == 'manager') {
353
+            if ($this->_debugMode > 0) {
354
+                if (isset($_SESSION['usertype']) && $_SESSION['usertype'] == 'manager') {
355 355
                     error_reporting(E_ALL ^ E_NOTICE);
356 356
                     ini_set('display_errors', 1);
357 357
                 }
358 358
                 $dir = dirname(dirname(__FILE__));
359
-                if (file_exists($dir . "/lib/DLdebug.class.php")) {
359
+                if (file_exists($dir . "/lib/DLdebug.class.php")) {
360 360
                     include_once($dir . "/lib/DLdebug.class.php");
361
-                    if (class_exists("DLdebug", false)) {
361
+                    if (class_exists("DLdebug", false)) {
362 362
                         $this->debug = new DLdebug($this);
363 363
                     }
364 364
                 }
365 365
             }
366 366
 
367
-            if (is_null($this->debug)) {
367
+            if (is_null($this->debug)) {
368 368
                 $this->debug = new xNop();
369 369
                 $this->_debugMode = 0;
370 370
                 error_reporting(0);
@@ -376,8 +376,8 @@  discard block
 block discarded – undo
376 376
     /**
377 377
      * Информация о режиме отладки
378 378
      */
379
-    public function getDebug()
380
-    {
379
+    public function getDebug()
380
+    {
381 381
         return $this->_debugMode;
382 382
     }
383 383
 
@@ -388,13 +388,13 @@  discard block
 block discarded – undo
388 388
      * @param string $alias желаемый алиас таблицы
389 389
      * @return string имя таблицы с префиксом и алиасом
390 390
      */
391
-    public function getTable($name, $alias = '')
392
-    {
393
-        if (!isset($this->_table[$name])) {
391
+    public function getTable($name, $alias = '')
392
+    {
393
+        if (!isset($this->_table[$name])) {
394 394
             $this->_table[$name] = $this->modx->getFullTableName($name);
395 395
         }
396 396
         $table = $this->_table[$name];
397
-        if (!empty($alias) && is_scalar($alias)) {
397
+        if (!empty($alias) && is_scalar($alias)) {
398 398
             $table .= " as `" . $alias . "`";
399 399
         }
400 400
 
@@ -407,9 +407,9 @@  discard block
 block discarded – undo
407 407
      * @param $alias
408 408
      * @return mixed
409 409
      */
410
-    public function TableAlias($name, $table, $alias)
411
-    {
412
-        if (!$this->checkTableAlias($name, $table)) {
410
+    public function TableAlias($name, $table, $alias)
411
+    {
412
+        if (!$this->checkTableAlias($name, $table)) {
413 413
             $this->AddTable[$table][$name] = $alias;
414 414
         }
415 415
 
@@ -421,8 +421,8 @@  discard block
 block discarded – undo
421 421
      * @param $table
422 422
      * @return bool
423 423
      */
424
-    public function checkTableAlias($name, $table)
425
-    {
424
+    public function checkTableAlias($name, $table)
425
+    {
426 426
         return isset($this->AddTable[$table][$name]);
427 427
     }
428 428
 
@@ -434,8 +434,8 @@  discard block
 block discarded – undo
434 434
      * @param bool $nop создавать ли пустой объект запрашиваемого типа
435 435
      * @return array|mixed|xNop
436 436
      */
437
-    public function jsonDecode($json, $config = array(), $nop = false)
438
-    {
437
+    public function jsonDecode($json, $config = array(), $nop = false)
438
+    {
439 439
         $this->debug->debug('Decode JSON: ' . $this->debug->dumpData($json) . "\r\nwith config: " . $this->debug->dumpData($config),
440 440
             'jsonDecode', 2);
441 441
         $config = jsonHelper::jsonDecode($json, $config, $nop);
@@ -451,10 +451,10 @@  discard block
 block discarded – undo
451 451
      * @param $json string строка с JSON для записи в лог при отладке
452 452
      * @return bool|string
453 453
      */
454
-    public function isErrorJSON($json)
455
-    {
454
+    public function isErrorJSON($json)
455
+    {
456 456
         $error = jsonHelper::json_last_error_msg();
457
-        if (!in_array($error, array('error_none', 'other'))) {
457
+        if (!in_array($error, array('error_none', 'other'))) {
458 458
             $this->debug->error($this->getMsg('json.' . $error) . ": " . $this->debug->dumpData($json, 'code'), 'JSON');
459 459
             $error = true;
460 460
         }
@@ -466,20 +466,20 @@  discard block
 block discarded – undo
466 466
      * Проверка параметров и загрузка необходимых экстендеров
467 467
      * return boolean статус загрузки
468 468
      */
469
-    public function checkDL()
470
-    {
469
+    public function checkDL()
470
+    {
471 471
         $this->debug->debug('Check DocLister parameters', 'checkDL', 2);
472 472
         $flag = true;
473 473
         $extenders = $this->getCFGDef('extender', '');
474 474
         $extenders = explode(",", $extenders);
475 475
         $tmp = $this->getCFGDef('requestActive', '') != '' || in_array('request', $extenders);
476
-        if ($tmp && !$this->_loadExtender('request')) {
476
+        if ($tmp && !$this->_loadExtender('request')) {
477 477
             //OR request in extender's parameter
478 478
             throw new Exception('Error load request extender');
479 479
         }
480 480
 
481 481
         $tmp = $this->getCFGDef('summary', '') != '' || in_array('summary', $extenders);
482
-        if ($tmp && !$this->_loadExtender('summary')) {
482
+        if ($tmp && !$this->_loadExtender('summary')) {
483 483
             //OR summary in extender's parameter
484 484
             throw new Exception('Error load summary extender');
485 485
         }
@@ -492,15 +492,15 @@  discard block
 block discarded – undo
492 492
                 $this->getCFGDef('pageLimit', '') != '' || $this->getCFGDef('pageAdjacents', '') != '' ||
493 493
                 $this->getCFGDef('PaginateClass', '') != '' || $this->getCFGDef('TplNextP', '') != ''
494 494
             ) && !$this->_loadExtender('paginate')
495
-        ) {
495
+        ) {
496 496
             throw new Exception('Error load paginate extender');
497
-        } else {
498
-            if ((int)$this->getCFGDef('display', 0) == 0) {
497
+        } else {
498
+            if ((int)$this->getCFGDef('display', 0) == 0) {
499 499
                 $extenders = $this->unsetArrayVal($extenders, 'paginate');
500 500
             }
501 501
         }
502 502
 
503
-        if ($this->getCFGDef('prepare', '') != '' || $this->getCFGDef('prepareWrap') != '') {
503
+        if ($this->getCFGDef('prepare', '') != '' || $this->getCFGDef('prepareWrap') != '') {
504 504
             $this->_loadExtender('prepare');
505 505
         }
506 506
 
@@ -517,14 +517,14 @@  discard block
 block discarded – undo
517 517
      * @param mixed $val значение которые необходимо удалить из массива
518 518
      * @return array отчищеный массив с данными
519 519
      */
520
-    private function unsetArrayVal($data, $val)
521
-    {
520
+    private function unsetArrayVal($data, $val)
521
+    {
522 522
         $out = array();
523
-        if (is_array($data)) {
524
-            foreach ($data as $item) {
525
-                if ($item != $val) {
523
+        if (is_array($data)) {
524
+            foreach ($data as $item) {
525
+                if ($item != $val) {
526 526
                     $out[] = $item;
527
-                } else {
527
+                } else {
528 528
                     continue;
529 529
                 }
530 530
             }
@@ -539,14 +539,14 @@  discard block
 block discarded – undo
539 539
      * @param int $id уникальный идентификатор страницы
540 540
      * @return string URL страницы
541 541
      */
542
-    public function getUrl($id = 0)
543
-    {
542
+    public function getUrl($id = 0)
543
+    {
544 544
         $id = ((int)$id > 0) ? (int)$id : $this->getCurrentMODXPageID();
545 545
 
546 546
         $link = $this->checkExtender('request') ? $this->extender['request']->getLink() : $this->getRequest();
547
-        if ($id == $this->modx->config['site_start']) {
547
+        if ($id == $this->modx->config['site_start']) {
548 548
             $url = $this->modx->config['site_url'] . ($link != '' ? "?{$link}" : "");
549
-        } else {
549
+        } else {
550 550
             $url = $this->modx->makeUrl($id, '', $link, $this->getCFGDef('urlScheme', ''));
551 551
         }
552 552
 
@@ -574,20 +574,20 @@  discard block
 block discarded – undo
574 574
      * @param string $tpl шаблон
575 575
      * @return string
576 576
      */
577
-    public function render($tpl = '')
578
-    {
577
+    public function render($tpl = '')
578
+    {
579 579
         $this->debug->debug(array('Render data with template ' => $tpl), 'render', 2, array('html'));
580 580
         $out = '';
581
-        if (1 == $this->getCFGDef('tree', '0')) {
582
-            foreach ($this->_tree as $item) {
581
+        if (1 == $this->getCFGDef('tree', '0')) {
582
+            foreach ($this->_tree as $item) {
583 583
                 $out .= $this->renderTree($item);
584 584
             }
585 585
             $out = $this->renderWrap($out);
586
-        } else {
586
+        } else {
587 587
             $out = $this->_render($tpl);
588 588
         }
589 589
 
590
-        if ($out) {
590
+        if ($out) {
591 591
             $this->outData = DLTemplate::getInstance($this->modx)->parseDocumentSource($out);
592 592
         }
593 593
         $this->debug->debugEnd('render');
@@ -604,8 +604,8 @@  discard block
 block discarded – undo
604 604
      *
605 605
      * @return int
606 606
      */
607
-    public function getCurrentMODXPageID()
608
-    {
607
+    public function getCurrentMODXPageID()
608
+    {
609 609
         $id = isset($this->modx->documentIdentifier) ? (int)$this->modx->documentIdentifier : 0;
610 610
         $docData = isset($this->modx->documentObject) ? $this->modx->documentObject : array();
611 611
 
@@ -621,9 +621,9 @@  discard block
 block discarded – undo
621 621
      * @param integer $line error on line
622 622
      * @param array $trace stack trace
623 623
      */
624
-    public function ErrorLogger($message, $code, $file, $line, $trace)
625
-    {
626
-        if (abs($this->getCFGDef('debug', '0')) == '1') {
624
+    public function ErrorLogger($message, $code, $file, $line, $trace)
625
+    {
626
+        if (abs($this->getCFGDef('debug', '0')) == '1') {
627 627
             $out = "CODE #" . $code . "<br />";
628 628
             $out .= "on file: " . $file . ":" . $line . "<br />";
629 629
             $out .= "<pre>";
@@ -640,8 +640,8 @@  discard block
 block discarded – undo
640 640
      *
641 641
      * @return DocumentParser
642 642
      */
643
-    public function getMODX()
644
-    {
643
+    public function getMODX()
644
+    {
645 645
         return $this->modx;
646 646
     }
647 647
 
@@ -652,13 +652,13 @@  discard block
 block discarded – undo
652 652
      * @return boolean status load extenders
653 653
      * @throws Exception
654 654
      */
655
-    public function loadExtender($ext = '')
656
-    {
655
+    public function loadExtender($ext = '')
656
+    {
657 657
         $out = true;
658
-        if ($ext != '') {
658
+        if ($ext != '') {
659 659
             $ext = explode(",", $ext);
660
-            foreach ($ext as $item) {
661
-                if ($item != '' && !$this->_loadExtender($item)) {
660
+            foreach ($ext as $item) {
661
+                if ($item != '' && !$this->_loadExtender($item)) {
662 662
                     throw new Exception('Error load ' . APIHelpers::e($item) . ' extender');
663 663
                 }
664 664
             }
@@ -674,8 +674,8 @@  discard block
 block discarded – undo
674 674
      * @param mixed $def значение по умолчанию, если в конфиге нет искомого параметра
675 675
      * @return mixed значение из конфига
676 676
      */
677
-    public function getCFGDef($name, $def = null)
678
-    {
677
+    public function getCFGDef($name, $def = null)
678
+    {
679 679
         return $this->config->getCFGDef($name, $def);
680 680
     }
681 681
 
@@ -687,15 +687,15 @@  discard block
 block discarded – undo
687 687
      * @param string $key ключ локального плейсхолдера
688 688
      * @return string
689 689
      */
690
-    public function toPlaceholders($data, $set = 0, $key = 'contentPlaceholder')
691
-    {
690
+    public function toPlaceholders($data, $set = 0, $key = 'contentPlaceholder')
691
+    {
692 692
         $this->debug->debug(null, 'toPlaceholders', 2);
693
-        if ($set == 0) {
693
+        if ($set == 0) {
694 694
             $set = $this->getCFGDef('contentPlaceholder', 0);
695 695
         }
696 696
         $this->_plh[$key] = $data;
697 697
         $id = $this->getCFGDef('id', '');
698
-        if ($id != '') {
698
+        if ($id != '') {
699 699
             $id .= ".";
700 700
         }
701 701
         $out = DLTemplate::getInstance($this->getMODX())->toPlaceholders($data, $set, $key, $id);
@@ -717,14 +717,14 @@  discard block
 block discarded – undo
717 717
      * @param boolean $quote заключать ли данные на выходе в кавычки
718 718
      * @return string обработанная строка
719 719
      */
720
-    public function sanitarIn($data, $sep = ',', $quote = true)
721
-    {
722
-        if (!is_array($data)) {
720
+    public function sanitarIn($data, $sep = ',', $quote = true)
721
+    {
722
+        if (!is_array($data)) {
723 723
             $data = explode($sep, $data);
724 724
         }
725 725
         $out = array();
726
-        foreach ($data as $item) {
727
-            if ($item !== '') {
726
+        foreach ($data as $item) {
727
+            if ($item !== '') {
728 728
                 $out[] = $this->modx->db->escape($item);
729 729
             }
730 730
         }
@@ -745,12 +745,12 @@  discard block
 block discarded – undo
745 745
      * @param string $lang имя языкового пакета
746 746
      * @return array
747 747
      */
748
-    public function getCustomLang($lang = '')
749
-    {
750
-        if (empty($lang)) {
748
+    public function getCustomLang($lang = '')
749
+    {
750
+        if (empty($lang)) {
751 751
             $lang = $this->getCFGDef('lang', $this->modx->config['manager_language']);
752 752
         }
753
-        if (file_exists(dirname(dirname(__FILE__)) . "/lang/" . $lang . ".php")) {
753
+        if (file_exists(dirname(dirname(__FILE__)) . "/lang/" . $lang . ".php")) {
754 754
             $tmp = include(dirname(__FILE__) . "/lang/" . $lang . ".php");
755 755
             $this->_customLang = is_array($tmp) ? $tmp : array();
756 756
         }
@@ -766,25 +766,25 @@  discard block
 block discarded – undo
766 766
      * @param boolean $rename Переименовывать ли элементы массива
767 767
      * @return array массив с лексиконом
768 768
      */
769
-    public function loadLang($name = 'core', $lang = '', $rename = true)
770
-    {
771
-        if (empty($lang)) {
769
+    public function loadLang($name = 'core', $lang = '', $rename = true)
770
+    {
771
+        if (empty($lang)) {
772 772
             $lang = $this->getCFGDef('lang', $this->modx->config['manager_language']);
773 773
         }
774 774
 
775 775
         $this->debug->debug('Load language ' . $this->debug->dumpData($name) . "." . $this->debug->dumpData($lang),
776 776
             'loadlang', 2);
777
-        if (is_scalar($name)) {
777
+        if (is_scalar($name)) {
778 778
             $name = array($name);
779 779
         }
780
-        foreach ($name as $n) {
781
-            if (file_exists(dirname(__FILE__) . "/lang/" . $lang . "/" . $n . ".inc.php")) {
780
+        foreach ($name as $n) {
781
+            if (file_exists(dirname(__FILE__) . "/lang/" . $lang . "/" . $n . ".inc.php")) {
782 782
                 $tmp = include(dirname(__FILE__) . "/lang/" . $lang . "/" . $n . ".inc.php");
783
-                if (is_array($tmp)) {
783
+                if (is_array($tmp)) {
784 784
                     /**
785 785
                      * Переименовыываем элементы массива из array('test'=>'data') в array('name.test'=>'data')
786 786
                      */
787
-                    if ($rename) {
787
+                    if ($rename) {
788 788
                         $tmp = $this->renameKeyArr($tmp, $n, '', '.');
789 789
                     }
790 790
                     $this->_lang = array_merge($this->_lang, $tmp);
@@ -803,11 +803,11 @@  discard block
 block discarded – undo
803 803
      * @param string $def Строка по умолчанию, если запись в языковом пакете не будет обнаружена
804 804
      * @return string строка в соответствии с текущими языковыми настройками
805 805
      */
806
-    public function getMsg($name, $def = '')
807
-    {
808
-        if (isset($this->_customLang[$name])) {
806
+    public function getMsg($name, $def = '')
807
+    {
808
+        if (isset($this->_customLang[$name])) {
809 809
             $say = $this->_customLang[$name];
810
-        } else {
810
+        } else {
811 811
             $say = \APIHelpers::getkey($this->_lang, $name, $def);
812 812
         }
813 813
 
@@ -823,8 +823,8 @@  discard block
 block discarded – undo
823 823
      * @param string $sep разделитель суффиксов, префиксов и ключей массива
824 824
      * @return array массив с переименованными ключами
825 825
      */
826
-    public function renameKeyArr($data, $prefix = '', $suffix = '', $sep = '.')
827
-    {
826
+    public function renameKeyArr($data, $prefix = '', $suffix = '', $sep = '.')
827
+    {
828 828
         return \APIHelpers::renameKeyArr($data, $prefix, $suffix, $sep);
829 829
     }
830 830
 
@@ -834,12 +834,12 @@  discard block
 block discarded – undo
834 834
      * @param string $locale локаль
835 835
      * @return string имя установленной локали
836 836
      */
837
-    public function setLocate($locale = '')
838
-    {
839
-        if ('' == $locale) {
837
+    public function setLocate($locale = '')
838
+    {
839
+        if ('' == $locale) {
840 840
             $locale = $this->getCFGDef('locale', '');
841 841
         }
842
-        if ('' != $locale) {
842
+        if ('' != $locale) {
843 843
             setlocale(LC_ALL, $locale);
844 844
         }
845 845
 
@@ -853,11 +853,11 @@  discard block
 block discarded – undo
853 853
      * @param array $data массив сформированный как дерево
854 854
      * @return string строка для отображения пользователю
855 855
      */
856
-    protected function renderTree($data)
857
-    {
856
+    protected function renderTree($data)
857
+    {
858 858
         $out = '';
859
-        if (!empty($data['#childNodes'])) {
860
-            foreach ($data['#childNodes'] as $item) {
859
+        if (!empty($data['#childNodes'])) {
860
+            foreach ($data['#childNodes'] as $item) {
861 861
                 $out .= $this->renderTree($item);
862 862
             }
863 863
         }
@@ -874,8 +874,8 @@  discard block
 block discarded – undo
874 874
      * @param string $name Template: chunk name || @CODE: template || @FILE: file with template
875 875
      * @return string html template with placeholders without data
876 876
      */
877
-    private function _getChunk($name)
878
-    {
877
+    private function _getChunk($name)
878
+    {
879 879
         $this->debug->debug(array('Get chunk by name' => $name), "getChunk", 2, array('html'));
880 880
         //without trim
881 881
         $tpl = DLTemplate::getInstance($this->getMODX())->getChunk($name);
@@ -892,18 +892,18 @@  discard block
 block discarded – undo
892 892
      * @param string $tpl HTML шаблон
893 893
      * @return string
894 894
      */
895
-    public function parseLang($tpl)
896
-    {
895
+    public function parseLang($tpl)
896
+    {
897 897
         $this->debug->debug(array("parseLang" => $tpl), "parseLang", 2, array('html'));
898
-        if (is_scalar($tpl) && !empty($tpl)) {
899
-            if (preg_match_all("/\[\%([a-zA-Z0-9\.\_\-]+)\%\]/", $tpl, $match)) {
898
+        if (is_scalar($tpl) && !empty($tpl)) {
899
+            if (preg_match_all("/\[\%([a-zA-Z0-9\.\_\-]+)\%\]/", $tpl, $match)) {
900 900
                 $langVal = array();
901
-                foreach ($match[1] as $item) {
901
+                foreach ($match[1] as $item) {
902 902
                     $langVal[] = $this->getMsg($item);
903 903
                 }
904 904
                 $tpl = str_replace($match[0], $langVal, $tpl);
905 905
             }
906
-        } else {
906
+        } else {
907 907
             $tpl = '';
908 908
         }
909 909
         $this->debug->debugEnd("parseLang");
@@ -919,24 +919,24 @@  discard block
 block discarded – undo
919 919
      * @param bool $parseDocumentSource render html template via DocumentParser::parseDocumentSource()
920 920
      * @return string html template with data without placeholders
921 921
      */
922
-    public function parseChunk($name, $data, $parseDocumentSource = false)
923
-    {
922
+    public function parseChunk($name, $data, $parseDocumentSource = false)
923
+    {
924 924
         $this->debug->debug(
925 925
             array("parseChunk" => $name, "With data" => print_r($data, 1)),
926 926
             "parseChunk",
927 927
             2, array('html', null)
928 928
         );
929 929
         $DLTemplate = DLTemplate::getInstance($this->getMODX());
930
-        if ($path = $this->getCFGDef('templatePath')) {
930
+        if ($path = $this->getCFGDef('templatePath')) {
931 931
             $DLTemplate->setTemplatePath($path);
932 932
         }
933
-        if ($ext = $this->getCFGDef('templateExtension')) {
933
+        if ($ext = $this->getCFGDef('templateExtension')) {
934 934
             $DLTemplate->setTemplateExtension($ext);
935 935
         }
936 936
         $DLTemplate->setTwigTemplateVars(array('DocLister' => $this));
937 937
         $out = $DLTemplate->parseChunk($name, $data, $parseDocumentSource);
938 938
         $out = $this->parseLang($out);
939
-        if (empty($out)) {
939
+        if (empty($out)) {
940 940
             $this->debug->debug("Empty chunk: " . $this->debug->dumpData($name), '', 2);
941 941
         }
942 942
         $this->debug->debugEnd("parseChunk");
@@ -952,8 +952,8 @@  discard block
 block discarded – undo
952 952
      *
953 953
      * @return string html template from parameter
954 954
      */
955
-    public function getChunkByParam($name, $val = '')
956
-    {
955
+    public function getChunkByParam($name, $val = '')
956
+    {
957 957
         $data = $this->getCFGDef($name, $val);
958 958
         $data = $this->_getChunk($data);
959 959
 
@@ -966,11 +966,11 @@  discard block
 block discarded – undo
966 966
      * @param string $data html код который нужно обернуть в ownerTPL
967 967
      * @return string результатирующий html код
968 968
      */
969
-    public function renderWrap($data)
970
-    {
969
+    public function renderWrap($data)
970
+    {
971 971
         $out = $data;
972 972
         $docs = count($this->_docs) - $this->skippedDocs;
973
-        if ((($this->getCFGDef("noneWrapOuter", "1") && $docs == 0) || $docs > 0) && !empty($this->ownerTPL)) {
973
+        if ((($this->getCFGDef("noneWrapOuter", "1") && $docs == 0) || $docs > 0) && !empty($this->ownerTPL)) {
974 974
             $this->debug->debug("", "renderWrapTPL", 2);
975 975
             $parse = true;
976 976
             $plh = array($this->getCFGDef("sysKey", "dl") . ".wrap" => $data);
@@ -978,7 +978,7 @@  discard block
 block discarded – undo
978 978
              * @var $extPrepare prepare_DL_Extender
979 979
              */
980 980
             $extPrepare = $this->getExtender('prepare');
981
-            if ($extPrepare) {
981
+            if ($extPrepare) {
982 982
                 $params = $extPrepare->init($this, array(
983 983
                     'data'      => array(
984 984
                         'docs'         => $this->_docs,
@@ -987,13 +987,13 @@  discard block
 block discarded – undo
987 987
                     'nameParam' => 'prepareWrap',
988 988
                     'return'    => 'placeholders'
989 989
                 ));
990
-                if (is_bool($params) && $params === false) {
990
+                if (is_bool($params) && $params === false) {
991 991
                     $out = $data;
992 992
                     $parse = false;
993 993
                 }
994 994
                 $plh = $params;
995 995
             }
996
-            if ($parse && !empty($this->ownerTPL)) {
996
+            if ($parse && !empty($this->ownerTPL)) {
997 997
                 $this->debug->updateMessage(
998 998
                     array("render ownerTPL" => $this->ownerTPL, "With data" => print_r($plh, 1)),
999 999
                     "renderWrapTPL",
@@ -1001,7 +1001,7 @@  discard block
 block discarded – undo
1001 1001
                 );
1002 1002
                 $out = $this->parseChunk($this->ownerTPL, $plh);
1003 1003
             }
1004
-            if (empty($this->ownerTPL)) {
1004
+            if (empty($this->ownerTPL)) {
1005 1005
                 $this->debug->updateMessage("empty ownerTPL", "renderWrapTPL");
1006 1006
             }
1007 1007
             $this->debug->debugEnd("renderWrapTPL");
@@ -1017,8 +1017,8 @@  discard block
 block discarded – undo
1017 1017
      * @param int $i номер итерации в цикле
1018 1018
      * @return array массив с данными которые можно использовать в цикле render метода
1019 1019
      */
1020
-    protected function uniformPrepare(&$data, $i = 0)
1021
-    {
1020
+    protected function uniformPrepare(&$data, $i = 0)
1021
+    {
1022 1022
         $class = array();
1023 1023
 
1024 1024
         $iterationName = ($i % 2 == 1) ? 'Odd' : 'Even';
@@ -1029,13 +1029,13 @@  discard block
 block discarded – undo
1029 1029
         $this->renderTPL = $this->getCFGDef('tpl' . $iterationName, $this->renderTPL);
1030 1030
         $iteration = $i;
1031 1031
 
1032
-        if ($this->extPaginate) {
1032
+        if ($this->extPaginate) {
1033 1033
             $offset = $this->getCFGDef('reversePagination',
1034 1034
                 0) && $this->extPaginate->currentPage() > 1 ? $this->extPaginate->totalPage() * $this->getCFGDef('display',
1035 1035
                     0) - $this->extPaginate->totalDocs() : 0;
1036 1036
             if ($this->getCFGDef('maxDocs', 0) && !$this->getCFGDef('reversePagination',
1037 1037
                     0) && $this->extPaginate->currentPage() == $this->extPaginate->totalPage()
1038
-            ) {
1038
+            ) {
1039 1039
                 $iteration += $this->getCFGDef('display', 0);
1040 1040
             }
1041 1041
             $iteration += $this->getCFGDef('display',
@@ -1045,20 +1045,20 @@  discard block
 block discarded – undo
1045 1045
         $data[$this->getCFGDef("sysKey",
1046 1046
             "dl") . '.full_iteration'] = $iteration;
1047 1047
 
1048
-        if ($i == 1) {
1048
+        if ($i == 1) {
1049 1049
             $this->renderTPL = $this->getCFGDef('tplFirst', $this->renderTPL);
1050 1050
             $class[] = $this->getCFGDef('firstClass', 'first');
1051 1051
         }
1052
-        if ($i == (count($this->_docs) - $this->skippedDocs)) {
1052
+        if ($i == (count($this->_docs) - $this->skippedDocs)) {
1053 1053
             $this->renderTPL = $this->getCFGDef('tplLast', $this->renderTPL);
1054 1054
             $class[] = $this->getCFGDef('lastClass', 'last');
1055 1055
         }
1056
-        if ($this->modx->documentIdentifier == $data['id']) {
1056
+        if ($this->modx->documentIdentifier == $data['id']) {
1057 1057
             $this->renderTPL = $this->getCFGDef('tplCurrent', $this->renderTPL);
1058 1058
             $data[$this->getCFGDef("sysKey",
1059 1059
                 "dl") . '.active'] = 1; //[+active+] - 1 if $modx->documentIdentifer equal ID this element
1060 1060
             $class[] = $this->getCFGDef('currentClass', 'current');
1061
-        } else {
1061
+        } else {
1062 1062
             $data[$this->getCFGDef("sysKey", "dl") . '.active'] = 0;
1063 1063
         }
1064 1064
 
@@ -1069,8 +1069,8 @@  discard block
 block discarded – undo
1069 1069
          * @var $extE e_DL_Extender
1070 1070
          */
1071 1071
         $extE = $this->getExtender('e', true, true);
1072
-        if ($out = $extE->init($this, compact('data'))) {
1073
-            if (is_array($out)) {
1072
+        if ($out = $extE->init($this, compact('data'))) {
1073
+            if (is_array($out)) {
1074 1074
                 $data = $out;
1075 1075
             }
1076 1076
         }
@@ -1086,42 +1086,43 @@  discard block
 block discarded – undo
1086 1086
      * @param array $array данные которые необходимо примешать к ответу на каждой записи $data
1087 1087
      * @return string JSON строка
1088 1088
      */
1089
-    public function getJSON($data, $fields, $array = array())
1090
-    {
1089
+    public function getJSON($data, $fields, $array = array())
1090
+    {
1091 1091
         $out = array();
1092 1092
         $fields = is_array($fields) ? $fields : explode(",", $fields);
1093
-        if (is_array($array) && count($array) > 0) {
1093
+        if (is_array($array) && count($array) > 0) {
1094 1094
             $tmp = array();
1095
-            foreach ($data as $i => $v) { //array_merge not valid work with integer index key
1095
+            foreach ($data as $i => $v) {
1096
+//array_merge not valid work with integer index key
1096 1097
                 $tmp[$i] = (isset($array[$i]) ? array_merge($v, $array[$i]) : $v);
1097 1098
             }
1098 1099
             $data = $tmp;
1099 1100
         }
1100 1101
 
1101
-        foreach ($data as $num => $doc) {
1102
+        foreach ($data as $num => $doc) {
1102 1103
             $tmp = array();
1103
-            foreach ($doc as $name => $value) {
1104
-                if (in_array($name, $fields) || (isset($fields[0]) && $fields[0] == '1')) {
1104
+            foreach ($doc as $name => $value) {
1105
+                if (in_array($name, $fields) || (isset($fields[0]) && $fields[0] == '1')) {
1105 1106
                     $tmp[str_replace(".", "_", $name)] = $value; //JSON element name without dot
1106 1107
                 }
1107 1108
             }
1108 1109
             $out[$num] = $tmp;
1109 1110
         }
1110 1111
 
1111
-        if ('new' == $this->getCFGDef('JSONformat', 'old')) {
1112
+        if ('new' == $this->getCFGDef('JSONformat', 'old')) {
1112 1113
             $return = array();
1113 1114
 
1114 1115
             $return['rows'] = array();
1115
-            foreach ($out as $key => $item) {
1116
+            foreach ($out as $key => $item) {
1116 1117
                 $return['rows'][] = $item;
1117 1118
             }
1118 1119
             $return['total'] = $this->getChildrenCount();
1119
-        } elseif ('simple' == $this->getCFGDef('JSONformat', 'old')) {
1120
+        } elseif ('simple' == $this->getCFGDef('JSONformat', 'old')) {
1120 1121
             $return = array();
1121
-            foreach ($out as $key => $item) {
1122
+            foreach ($out as $key => $item) {
1122 1123
                 $return[] = $item;
1123 1124
             }
1124
-        } else {
1125
+        } else {
1125 1126
             $return = $out;
1126 1127
         }
1127 1128
         $this->outData = json_encode($return);
@@ -1137,11 +1138,11 @@  discard block
 block discarded – undo
1137 1138
      * @param string $contentField
1138 1139
      * @return mixed|string
1139 1140
      */
1140
-    protected function getSummary(array $item = array(), $extSummary = null, $introField = '', $contentField = '')
1141
-    {
1141
+    protected function getSummary(array $item = array(), $extSummary = null, $introField = '', $contentField = '')
1142
+    {
1142 1143
         $out = '';
1143 1144
 
1144
-        if (is_null($extSummary)) {
1145
+        if (is_null($extSummary)) {
1145 1146
             /**
1146 1147
              * @var $extSummary summary_DL_Extender
1147 1148
              */
@@ -1150,10 +1151,10 @@  discard block
 block discarded – undo
1150 1151
         $introField = $this->getCFGDef("introField", $introField);
1151 1152
         $contentField = $this->getCFGDef("contentField", $contentField);
1152 1153
 
1153
-        if (!empty($introField) && !empty($item[$introField]) && mb_strlen($item[$introField], 'UTF-8') > 0) {
1154
+        if (!empty($introField) && !empty($item[$introField]) && mb_strlen($item[$introField], 'UTF-8') > 0) {
1154 1155
             $out = $item[$introField];
1155
-        } else {
1156
-            if (!empty($contentField) && !empty($item[$contentField]) && mb_strlen($item[$contentField], 'UTF-8') > 0) {
1156
+        } else {
1157
+            if (!empty($contentField) && !empty($item[$contentField]) && mb_strlen($item[$contentField], 'UTF-8') > 0) {
1157 1158
                 $out = $extSummary->init($this, array(
1158 1159
                     "content"      => $item[$contentField],
1159 1160
                     "action"       => $this->getCFGDef("summary", ""),
@@ -1171,8 +1172,8 @@  discard block
 block discarded – undo
1171 1172
      * @param string $name extender name
1172 1173
      * @return boolean status extender load
1173 1174
      */
1174
-    public function checkExtender($name)
1175
-    {
1175
+    public function checkExtender($name)
1176
+    {
1176 1177
         return (isset($this->extender[$name]) && $this->extender[$name] instanceof $name . "_DL_Extender");
1177 1178
     }
1178 1179
 
@@ -1180,8 +1181,8 @@  discard block
 block discarded – undo
1180 1181
      * @param $name
1181 1182
      * @param $obj
1182 1183
      */
1183
-    public function setExtender($name, $obj)
1184
-    {
1184
+    public function setExtender($name, $obj)
1185
+    {
1185 1186
         $this->extender[$name] = $obj;
1186 1187
     }
1187 1188
 
@@ -1193,13 +1194,13 @@  discard block
 block discarded – undo
1193 1194
      * @param bool $nop если экстендер не загружен, то загружать ли xNop
1194 1195
      * @return null|xNop
1195 1196
      */
1196
-    public function getExtender($name, $autoload = false, $nop = false)
1197
-    {
1197
+    public function getExtender($name, $autoload = false, $nop = false)
1198
+    {
1198 1199
         $out = null;
1199
-        if ((is_scalar($name) && $this->checkExtender($name)) || ($autoload && $this->_loadExtender($name))) {
1200
+        if ((is_scalar($name) && $this->checkExtender($name)) || ($autoload && $this->_loadExtender($name))) {
1200 1201
             $out = $this->extender[$name];
1201 1202
         }
1202
-        if ($nop && is_null($out)) {
1203
+        if ($nop && is_null($out)) {
1203 1204
             $out = new xNop();
1204 1205
         }
1205 1206
 
@@ -1212,27 +1213,27 @@  discard block
 block discarded – undo
1212 1213
      * @param string $name name extender
1213 1214
      * @return boolean $flag status load extender
1214 1215
      */
1215
-    protected function _loadExtender($name)
1216
-    {
1216
+    protected function _loadExtender($name)
1217
+    {
1217 1218
         $this->debug->debug('Load Extender ' . $this->debug->dumpData($name), 'LoadExtender', 2);
1218 1219
         $flag = false;
1219 1220
 
1220 1221
         $classname = ($name != '') ? $name . "_DL_Extender" : "";
1221
-        if ($classname != '' && isset($this->extender[$name]) && $this->extender[$name] instanceof $classname) {
1222
+        if ($classname != '' && isset($this->extender[$name]) && $this->extender[$name] instanceof $classname) {
1222 1223
             $flag = true;
1223 1224
 
1224
-        } else {
1225
-            if (!class_exists($classname, false) && $classname != '') {
1226
-                if (file_exists(dirname(__FILE__) . "/extender/" . $name . ".extender.inc")) {
1225
+        } else {
1226
+            if (!class_exists($classname, false) && $classname != '') {
1227
+                if (file_exists(dirname(__FILE__) . "/extender/" . $name . ".extender.inc")) {
1227 1228
                     include_once(dirname(__FILE__) . "/extender/" . $name . ".extender.inc");
1228 1229
                 }
1229 1230
             }
1230
-            if (class_exists($classname, false) && $classname != '') {
1231
+            if (class_exists($classname, false) && $classname != '') {
1231 1232
                 $this->extender[$name] = new $classname($this, $name);
1232 1233
                 $flag = true;
1233 1234
             }
1234 1235
         }
1235
-        if (!$flag) {
1236
+        if (!$flag) {
1236 1237
             $this->debug->debug("Error load Extender " . $this->debug->dumpData($name));
1237 1238
         }
1238 1239
         $this->debug->debugEnd('LoadExtender');
@@ -1250,16 +1251,16 @@  discard block
 block discarded – undo
1250 1251
      * @param mixed $IDs список id документов по которым необходима выборка
1251 1252
      * @return array очищенный массив
1252 1253
      */
1253
-    public function setIDs($IDs)
1254
-    {
1254
+    public function setIDs($IDs)
1255
+    {
1255 1256
         $this->debug->debug('set ID list ' . $this->debug->dumpData($IDs), 'setIDs', 2);
1256 1257
         $IDs = $this->cleanIDs($IDs);
1257 1258
         $type = $this->getCFGDef('idType', 'parents');
1258 1259
         $depth = $this->getCFGDef('depth', '');
1259
-        if ($type == 'parents' && $depth > 0) {
1260
+        if ($type == 'parents' && $depth > 0) {
1260 1261
             $tmp = $IDs;
1261
-            do {
1262
-                if (count($tmp) > 0) {
1262
+            do {
1263
+                if (count($tmp) > 0) {
1263 1264
                     $tmp = $this->getChildrenFolder($tmp);
1264 1265
                     $IDs = array_merge($IDs, $tmp);
1265 1266
                 }
@@ -1273,8 +1274,8 @@  discard block
 block discarded – undo
1273 1274
     /**
1274 1275
      * @return int
1275 1276
      */
1276
-    public function getIDs()
1277
-    {
1277
+    public function getIDs()
1278
+    {
1278 1279
         return $this->IDs;
1279 1280
     }
1280 1281
 
@@ -1285,17 +1286,18 @@  discard block
 block discarded – undo
1285 1286
      * @param string $sep разделитель
1286 1287
      * @return array очищенный массив с данными
1287 1288
      */
1288
-    public function cleanIDs($IDs, $sep = ',')
1289
-    {
1289
+    public function cleanIDs($IDs, $sep = ',')
1290
+    {
1290 1291
         $this->debug->debug('clean IDs ' . $this->debug->dumpData($IDs) . ' with separator ' . $this->debug->dumpData($sep),
1291 1292
             'cleanIDs', 2);
1292 1293
         $out = array();
1293
-        if (!is_array($IDs)) {
1294
+        if (!is_array($IDs)) {
1294 1295
             $IDs = explode($sep, $IDs);
1295 1296
         }
1296
-        foreach ($IDs as $item) {
1297
+        foreach ($IDs as $item) {
1297 1298
             $item = trim($item);
1298
-            if (is_numeric($item) && (int)$item >= 0) { //Fix 0xfffffffff
1299
+            if (is_numeric($item) && (int)$item >= 0) {
1300
+//Fix 0xfffffffff
1299 1301
                 $out[] = (int)$item;
1300 1302
             }
1301 1303
         }
@@ -1309,8 +1311,8 @@  discard block
 block discarded – undo
1309 1311
      * Проверка массива с id-шниками документов для выборки
1310 1312
      * @return boolean пригодны ли данные для дальнейшего использования
1311 1313
      */
1312
-    protected function checkIDs()
1313
-    {
1314
+    protected function checkIDs()
1315
+    {
1314 1316
         return (is_array($this->IDs) && count($this->IDs) > 0) ? true : false;
1315 1317
     }
1316 1318
 
@@ -1322,11 +1324,11 @@  discard block
 block discarded – undo
1322 1324
      * @global array $_docs all documents
1323 1325
      * @return array all field values
1324 1326
      */
1325
-    public function getOneField($userField, $uniq = false)
1326
-    {
1327
+    public function getOneField($userField, $uniq = false)
1328
+    {
1327 1329
         $out = array();
1328
-        foreach ($this->_docs as $doc => $val) {
1329
-            if (isset($val[$userField]) && (($uniq && !in_array($val[$userField], $out)) || !$uniq)) {
1330
+        foreach ($this->_docs as $doc => $val) {
1331
+            if (isset($val[$userField]) && (($uniq && !in_array($val[$userField], $out)) || !$uniq)) {
1330 1332
                 $out[$doc] = $val[$userField];
1331 1333
             }
1332 1334
         }
@@ -1337,8 +1339,8 @@  discard block
 block discarded – undo
1337 1339
     /**
1338 1340
      * @return DLCollection
1339 1341
      */
1340
-    public function docsCollection()
1341
-    {
1342
+    public function docsCollection()
1343
+    {
1342 1344
         return new DLCollection($this->modx, $this->_docs);
1343 1345
     }
1344 1346
 
@@ -1366,10 +1368,10 @@  discard block
 block discarded – undo
1366 1368
      * @param string $group
1367 1369
      * @return string
1368 1370
      */
1369
-    protected function getGroupSQL($group = '')
1370
-    {
1371
+    protected function getGroupSQL($group = '')
1372
+    {
1371 1373
         $out = '';
1372
-        if ($group != '') {
1374
+        if ($group != '') {
1373 1375
             $out = 'GROUP BY ' . $group;
1374 1376
         }
1375 1377
 
@@ -1388,12 +1390,12 @@  discard block
 block discarded – undo
1388 1390
      *
1389 1391
      * @return string Order by for SQL
1390 1392
      */
1391
-    protected function SortOrderSQL($sortName, $orderDef = 'DESC')
1392
-    {
1393
+    protected function SortOrderSQL($sortName, $orderDef = 'DESC')
1394
+    {
1393 1395
         $this->debug->debug('', 'sortORDER', 2);
1394 1396
 
1395 1397
         $sort = '';
1396
-        switch ($this->getCFGDef('sortType', '')) {
1398
+        switch ($this->getCFGDef('sortType', '')) {
1397 1399
             case 'none':
1398 1400
                 break;
1399 1401
             case 'doclist':
@@ -1404,10 +1406,10 @@  discard block
 block discarded – undo
1404 1406
                 break;
1405 1407
             default:
1406 1408
                 $out = array('orderBy' => '', 'order' => '', 'sortBy' => '');
1407
-                if (($tmp = $this->getCFGDef('orderBy', '')) != '') {
1409
+                if (($tmp = $this->getCFGDef('orderBy', '')) != '') {
1408 1410
                     $out['orderBy'] = $tmp;
1409
-                } else {
1410
-                    switch (true) {
1411
+                } else {
1412
+                    switch (true) {
1411 1413
                         case ('' != ($tmp = $this->getCFGDef('sortDir', ''))): //higher priority than order
1412 1414
                             $out['order'] = $tmp;
1413 1415
                         // no break
@@ -1415,7 +1417,7 @@  discard block
 block discarded – undo
1415 1417
                             $out['order'] = $tmp;
1416 1418
                         // no break
1417 1419
                     }
1418
-                    if ('' == $out['order'] || !in_array(strtoupper($out['order']), array('ASC', 'DESC'))) {
1420
+                    if ('' == $out['order'] || !in_array(strtoupper($out['order']), array('ASC', 'DESC'))) {
1419 1421
                         $out['order'] = $orderDef; //Default
1420 1422
                     }
1421 1423
 
@@ -1436,30 +1438,30 @@  discard block
 block discarded – undo
1436 1438
      *
1437 1439
      * @return string LIMIT вставка в SQL запрос
1438 1440
      */
1439
-    protected function LimitSQL($limit = 0, $offset = 0)
1440
-    {
1441
+    protected function LimitSQL($limit = 0, $offset = 0)
1442
+    {
1441 1443
         $this->debug->debug('', 'limitSQL', 2);
1442 1444
         $ret = '';
1443
-        if ($limit == 0) {
1445
+        if ($limit == 0) {
1444 1446
             $limit = $this->getCFGDef('display', 0);
1445 1447
         }
1446 1448
         $maxDocs = $this->getCFGDef('maxDocs', 0);
1447
-        if ($maxDocs > 0 && $limit > $maxDocs) {
1449
+        if ($maxDocs > 0 && $limit > $maxDocs) {
1448 1450
             $limit = $maxDocs;
1449 1451
         }
1450
-        if ($offset == 0) {
1452
+        if ($offset == 0) {
1451 1453
             $offset = $this->getCFGDef('offset', 0);
1452 1454
         }
1453 1455
         $offset += $this->getCFGDef('start', 0);
1454 1456
         $total = $this->getCFGDef('total', 0);
1455
-        if ($limit < ($total - $limit)) {
1457
+        if ($limit < ($total - $limit)) {
1456 1458
             $limit = $total - $offset;
1457 1459
         }
1458 1460
 
1459
-        if ($limit != 0) {
1461
+        if ($limit != 0) {
1460 1462
             $ret = "LIMIT " . (int)$offset . "," . (int)$limit;
1461
-        } else {
1462
-            if ($offset != 0) {
1463
+        } else {
1464
+            if ($offset != 0) {
1463 1465
                 /**
1464 1466
                  * 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
1465 1467
                  * @see http://dev.mysql.com/doc/refman/5.0/en/select.html
@@ -1479,8 +1481,8 @@  discard block
 block discarded – undo
1479 1481
      * @param string $charset
1480 1482
      * @return string Clear string
1481 1483
      */
1482
-    public function sanitarData($data, $charset = 'UTF-8')
1483
-    {
1484
+    public function sanitarData($data, $charset = 'UTF-8')
1485
+    {
1484 1486
         return APIHelpers::sanitarTag($data, $charset);
1485 1487
     }
1486 1488
 
@@ -1491,8 +1493,8 @@  discard block
 block discarded – undo
1491 1493
      * @param string $parentField default name parent field
1492 1494
      * @return array
1493 1495
      */
1494
-    public function treeBuild($idField = 'id', $parentField = 'parent')
1495
-    {
1496
+    public function treeBuild($idField = 'id', $parentField = 'parent')
1497
+    {
1496 1498
         return $this->_treeBuild($this->_docs, $this->getCFGDef('idField', $idField),
1497 1499
             $this->getCFGDef('parentField', $parentField));
1498 1500
     }
@@ -1505,16 +1507,16 @@  discard block
 block discarded – undo
1505 1507
      * @param string $pidName name parent field in associative data array
1506 1508
      * @return array
1507 1509
      */
1508
-    private function _treeBuild($data, $idName, $pidName)
1509
-    {
1510
+    private function _treeBuild($data, $idName, $pidName)
1511
+    {
1510 1512
         $children = array(); // children of each ID
1511 1513
         $ids = array();
1512
-        foreach ($data as $i => $r) {
1514
+        foreach ($data as $i => $r) {
1513 1515
             $row =& $data[$i];
1514 1516
             $id = $row[$idName];
1515 1517
             $pid = $row[$pidName];
1516 1518
             $children[$pid][$id] =& $row;
1517
-            if (!isset($children[$id])) {
1519
+            if (!isset($children[$id])) {
1518 1520
                 $children[$id] = array();
1519 1521
             }
1520 1522
             $row['#childNodes'] =& $children[$id];
@@ -1522,9 +1524,9 @@  discard block
 block discarded – undo
1522 1524
         }
1523 1525
         // Root elements are elements with non-found PIDs.
1524 1526
         $this->_tree = array();
1525
-        foreach ($data as $i => $r) {
1527
+        foreach ($data as $i => $r) {
1526 1528
             $row =& $data[$i];
1527
-            if (!isset($ids[$row[$pidName]])) {
1529
+            if (!isset($ids[$row[$pidName]])) {
1528 1530
                 $this->_tree[$row[$idName]] = $row;
1529 1531
             }
1530 1532
         }
@@ -1538,12 +1540,12 @@  discard block
 block discarded – undo
1538 1540
      * @param bool $full если true то возвращается значение для подстановки в запрос
1539 1541
      * @return string PrimaryKey основной таблицы
1540 1542
      */
1541
-    public function getPK($full = true)
1542
-    {
1543
+    public function getPK($full = true)
1544
+    {
1543 1545
         $idField = isset($this->idField) ? $this->idField: 'id';
1544
-        if ($full) {
1546
+        if ($full) {
1545 1547
             $idField = '`' . $idField . '`';
1546
-            if (!empty($this->alias)) {
1548
+            if (!empty($this->alias)) {
1547 1549
                 $idField = '`' . $this->alias . '`.' . $idField;
1548 1550
             }
1549 1551
         }
@@ -1557,12 +1559,12 @@  discard block
 block discarded – undo
1557 1559
      * @param bool $full если true то возвращается значение для подстановки в запрос
1558 1560
      * @return string Parent Key основной таблицы
1559 1561
      */
1560
-    public function getParentField($full = true)
1561
-    {
1562
+    public function getParentField($full = true)
1563
+    {
1562 1564
         $parentField = isset($this->parentField) ? $this->parentField : '';
1563
-        if ($full && !empty($parentField)) {
1565
+        if ($full && !empty($parentField)) {
1564 1566
             $parentField = '`' . $parentField . '`';
1565
-            if (!empty($this->alias)) {
1567
+            if (!empty($this->alias)) {
1566 1568
                 $parentField = '`' . $this->alias . '`.' . $parentField;
1567 1569
             }
1568 1570
         }
@@ -1577,31 +1579,31 @@  discard block
 block discarded – undo
1577 1579
      * @param string $filter_string строка со всеми фильтрами
1578 1580
      * @return mixed результат разбора фильтров
1579 1581
      */
1580
-    protected function getFilters($filter_string)
1581
-    {
1582
+    protected function getFilters($filter_string)
1583
+    {
1582 1584
         $this->debug->debug("getFilters: " . $this->debug->dumpData($filter_string), 'getFilter', 1);
1583 1585
         // the filter parameter tells us, which filters can be used in this query
1584 1586
         $filter_string = trim($filter_string, ' ;');
1585
-        if (!$filter_string) {
1587
+        if (!$filter_string) {
1586 1588
             return;
1587 1589
         }
1588 1590
         $output = array('join' => '', 'where' => '');
1589 1591
         $logic_op_found = false;
1590 1592
         $joins = $wheres = array();
1591
-        foreach ($this->_logic_ops as $op => $sql) {
1592
-            if (strpos($filter_string, $op) === 0) {
1593
+        foreach ($this->_logic_ops as $op => $sql) {
1594
+            if (strpos($filter_string, $op) === 0) {
1593 1595
                 $logic_op_found = true;
1594 1596
                 $subfilters = mb_substr($filter_string, strlen($op) + 1, mb_strlen($filter_string, "UTF-8"), "UTF-8");
1595 1597
                 $subfilters = $this->smartSplit($subfilters);
1596
-                foreach ($subfilters as $subfilter) {
1598
+                foreach ($subfilters as $subfilter) {
1597 1599
                     $subfilter = $this->getFilters(trim($subfilter));
1598
-                    if (!$subfilter) {
1600
+                    if (!$subfilter) {
1599 1601
                         continue;
1600 1602
                     }
1601
-                    if ($subfilter['join']) {
1603
+                    if ($subfilter['join']) {
1602 1604
                         $joins[] = $subfilter['join'];
1603 1605
                     }
1604
-                    if ($subfilter['where']) {
1606
+                    if ($subfilter['where']) {
1605 1607
                         $wheres[] = $subfilter['where'];
1606 1608
                     }
1607 1609
                 }
@@ -1610,12 +1612,12 @@  discard block
 block discarded – undo
1610 1612
             }
1611 1613
         }
1612 1614
 
1613
-        if (!$logic_op_found) {
1615
+        if (!$logic_op_found) {
1614 1616
             $filter = $this->loadFilter($filter_string);
1615
-            if (!$filter) {
1617
+            if (!$filter) {
1616 1618
                 $this->debug->warning('Error while loading DocLister filter "' . $this->debug->dumpData($filter_string) . '": check syntax!');
1617 1619
                 $output = false;
1618
-            } else {
1620
+            } else {
1619 1621
                 $output['join'] = $filter->get_join();
1620 1622
                 $output['where'] = stripslashes($filter->get_where());
1621 1623
             }
@@ -1628,16 +1630,16 @@  discard block
 block discarded – undo
1628 1630
     /**
1629 1631
      * @return mixed
1630 1632
      */
1631
-    public function filtersWhere()
1632
-    {
1633
+    public function filtersWhere()
1634
+    {
1633 1635
         return APIHelpers::getkey($this->_filters, 'where', '');
1634 1636
     }
1635 1637
 
1636 1638
     /**
1637 1639
      * @return mixed
1638 1640
      */
1639
-    public function filtersJoin()
1640
-    {
1641
+    public function filtersJoin()
1642
+    {
1641 1643
         return APIHelpers::getkey($this->_filters, 'join', '');
1642 1644
     }
1643 1645
 
@@ -1645,11 +1647,12 @@  discard block
 block discarded – undo
1645 1647
      * @param string $join
1646 1648
      * @return $this
1647 1649
      */
1648
-    public function setFiltersJoin($join = '') {
1649
-        if (!empty($join)) {
1650
-            if (!empty($this->_filters['join'])) {
1650
+    public function setFiltersJoin($join = '')
1651
+    {
1652
+        if (!empty($join)) {
1653
+            if (!empty($this->_filters['join'])) {
1651 1654
                 $this->_filters['join'] .= ' ' . $join;
1652
-            } else {
1655
+            } else {
1653 1656
                 $this->_filters['join'] = $join;
1654 1657
             }
1655 1658
         }
@@ -1664,10 +1667,10 @@  discard block
 block discarded – undo
1664 1667
      * @param $type string тип фильтрации
1665 1668
      * @return string имя поля с учетом приведения типа
1666 1669
      */
1667
-    public function changeSortType($field, $type)
1668
-    {
1670
+    public function changeSortType($field, $type)
1671
+    {
1669 1672
         $type = trim($type);
1670
-        switch (strtoupper($type)) {
1673
+        switch (strtoupper($type)) {
1671 1674
             case 'DECIMAL':
1672 1675
                 $field = 'CAST(' . $field . ' as DECIMAL(10,2))';
1673 1676
                 break;
@@ -1693,8 +1696,8 @@  discard block
 block discarded – undo
1693 1696
      * @param string $filter срока с параметрами фильтрации
1694 1697
      * @return bool
1695 1698
      */
1696
-    protected function loadFilter($filter)
1697
-    {
1699
+    protected function loadFilter($filter)
1700
+    {
1698 1701
         $this->debug->debug('Load filter ' . $this->debug->dumpData($filter), 'loadFilter', 2);
1699 1702
         $out = false;
1700 1703
         $fltr_params = explode(':', $filter, 2);
@@ -1704,21 +1707,21 @@  discard block
 block discarded – undo
1704 1707
         */
1705 1708
         $fltr_class = $fltr . '_DL_filter';
1706 1709
         // check if the filter is implemented
1707
-        if (!is_null($fltr)) {
1708
-            if (!class_exists($fltr_class) && file_exists(__DIR__ . '/filter/' . $fltr . '.filter.php')) {
1710
+        if (!is_null($fltr)) {
1711
+            if (!class_exists($fltr_class) && file_exists(__DIR__ . '/filter/' . $fltr . '.filter.php')) {
1709 1712
                 require_once dirname(__FILE__) . '/filter/' . $fltr . '.filter.php';
1710 1713
             }
1711
-            if (class_exists($fltr_class)) {
1714
+            if (class_exists($fltr_class)) {
1712 1715
                 $this->totalFilters++;
1713 1716
                 $fltr_obj = new $fltr_class();
1714
-                if ($fltr_obj->init($this, $filter)) {
1717
+                if ($fltr_obj->init($this, $filter)) {
1715 1718
                     $out = $fltr_obj;
1716
-                } else {
1719
+                } else {
1717 1720
                     $this->debug->error("Wrong filter parameter: '{$this->debug->dumpData($filter)}'", 'Filter');
1718 1721
                 }
1719 1722
             }
1720 1723
         }
1721
-        if (!$out) {
1724
+        if (!$out) {
1722 1725
             $this->debug->error("Error load Filter: '{$this->debug->dumpData($filter)}'", 'Filter');
1723 1726
         }
1724 1727
             
@@ -1731,8 +1734,8 @@  discard block
 block discarded – undo
1731 1734
      * Общее число фильтров
1732 1735
      * @return int
1733 1736
      */
1734
-    public function getCountFilters()
1735
-    {
1737
+    public function getCountFilters()
1738
+    {
1736 1739
         return (int)$this->totalFilters;
1737 1740
     }
1738 1741
 
@@ -1740,8 +1743,8 @@  discard block
 block discarded – undo
1740 1743
      * Выполнить SQL запрос
1741 1744
      * @param string $q SQL запрос
1742 1745
      */
1743
-    public function dbQuery($q)
1744
-    {
1746
+    public function dbQuery($q)
1747
+    {
1745 1748
         $this->debug->debug($q, "query", 1, 'sql');
1746 1749
         $out = $this->modx->db->query($q);
1747 1750
         $this->debug->debugEnd("query");
@@ -1759,8 +1762,8 @@  discard block
 block discarded – undo
1759 1762
      * @param string $tpl шаблон подстановки значения в SQL запрос
1760 1763
      * @return string строка для подстановки в SQL запрос
1761 1764
      */
1762
-    public function LikeEscape($field, $value, $escape = '=', $tpl = '%[+value+]%')
1763
-    {
1765
+    public function LikeEscape($field, $value, $escape = '=', $tpl = '%[+value+]%')
1766
+    {
1764 1767
         return sqlHelper::LikeEscape($this->modx, $field, $value, $escape, $tpl);
1765 1768
     }
1766 1769
 
@@ -1768,8 +1771,8 @@  discard block
 block discarded – undo
1768 1771
      * Получение REQUEST_URI без GET-ключа с
1769 1772
      * @return string
1770 1773
      */
1771
-    public function getRequest()
1772
-    {
1774
+    public function getRequest()
1775
+    {
1773 1776
         $URL = null;
1774 1777
         parse_str(parse_url(MODX_SITE_URL . $_SERVER['REQUEST_URI'], PHP_URL_QUERY), $URL);
1775 1778
 
Please login to merge, or discard this patch.