Completed
Push — master ( cd3a16...b37efc )
by
unknown
02:24
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
      */
@@ -188,48 +188,48 @@  discard block
 block discarded – undo
188 188
      * @param int $startTime время запуска сниппета
189 189
      * @throws Exception
190 190
      */
191
-    public function __construct($modx, $cfg = array(), $startTime = null)
192
-    {
191
+    public function __construct($modx, $cfg = array(), $startTime = null)
192
+    {
193 193
         $this->setTimeStart($startTime);
194 194
 
195
-        if (extension_loaded('mbstring')) {
195
+        if (extension_loaded('mbstring')) {
196 196
             mb_internal_encoding("UTF-8");
197
-        } else {
197
+        } else {
198 198
             throw new Exception('Not found php extension mbstring');
199 199
         }
200 200
 
201
-        if ($modx instanceof DocumentParser) {
201
+        if ($modx instanceof DocumentParser) {
202 202
             $this->modx = $modx;
203 203
             $this->setDebug(1);
204 204
 
205
-            if (!is_array($cfg) || empty($cfg)) {
205
+            if (!is_array($cfg) || empty($cfg)) {
206 206
                 $cfg = $this->modx->Event->params;
207 207
             }
208
-        } else {
208
+        } else {
209 209
             throw new Exception('MODX var is not instaceof DocumentParser');
210 210
         }
211 211
 
212 212
         $this->FS = \Helpers\FS::getInstance();
213 213
         $this->config = new \Helpers\Config($cfg);
214 214
 
215
-        if (isset($cfg['config'])) {
215
+        if (isset($cfg['config'])) {
216 216
             $this->config->setPath(dirname(__DIR__))->loadConfig($cfg['config']);
217 217
         }
218 218
 
219
-        if ($this->config->setConfig($cfg) === false) {
219
+        if ($this->config->setConfig($cfg) === false) {
220 220
             throw new Exception('no parameters to run DocLister');
221 221
         }
222 222
 
223 223
         $this->loadLang(array('core', 'json'));
224 224
         $this->setDebug($this->getCFGDef('debug', 0));
225 225
 
226
-        if ($this->checkDL()) {
226
+        if ($this->checkDL()) {
227 227
             $cfg = array();
228 228
             $idType = $this->getCFGDef('idType', '');
229
-            if (empty($idType) && $this->getCFGDef('documents', '') != '') {
229
+            if (empty($idType) && $this->getCFGDef('documents', '') != '') {
230 230
                 $idType = 'documents';
231 231
             }
232
-            switch ($idType) {
232
+            switch ($idType) {
233 233
                 case 'documents':
234 234
                     $IDs = $this->getCFGDef('documents');
235 235
                     $cfg['idType'] = "documents";
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
                 case 'parents':
238 238
                 default:
239 239
                     $cfg['idType'] = "parents";
240
-                    if (($IDs = $this->getCFGDef('parents', '')) === '') {
240
+                    if (($IDs = $this->getCFGDef('parents', '')) === '') {
241 241
                         $IDs = $this->getCurrentMODXPageID();
242 242
                     }
243 243
                     break;
@@ -256,21 +256,21 @@  discard block
 block discarded – undo
256 256
 
257 257
         $this->setLocate();
258 258
 
259
-        if ($this->getCFGDef("customLang")) {
259
+        if ($this->getCFGDef("customLang")) {
260 260
             $this->getCustomLang();
261 261
         }
262 262
         $this->loadExtender($this->getCFGDef("extender", ""));
263 263
 
264
-        if ($this->checkExtender('request')) {
264
+        if ($this->checkExtender('request')) {
265 265
             $this->extender['request']->init($this, $this->getCFGDef("requestActive", ""));
266 266
         }
267 267
         $this->_filters = $this->getFilters($this->getCFGDef('filters', ''));
268 268
         $this->ownerTPL = $this->getCFGDef("ownerTPL", "");
269 269
         $DLTemplate = DLTemplate::getInstance($modx);
270
-        if ($path = $this->getCFGDef('templatePath')) {
270
+        if ($path = $this->getCFGDef('templatePath')) {
271 271
             $DLTemplate->setTemplatePath($path);
272 272
         }
273
-        if ($ext = $this->getCFGDef('templateExtension')) {
273
+        if ($ext = $this->getCFGDef('templateExtension')) {
274 274
             $DLTemplate->setTemplateExtension($ext);
275 275
         }
276 276
         $DLTemplate->setTwigTemplateVars(array('DocLister' => $this));
@@ -282,25 +282,25 @@  discard block
 block discarded – undo
282 282
      * @param string $str строка с фильтром
283 283
      * @return array массив субфильтров
284 284
      */
285
-    public function smartSplit($str)
286
-    {
285
+    public function smartSplit($str)
286
+    {
287 287
         $res = array();
288 288
         $cur = '';
289 289
         $open = 0;
290 290
         $strlen = mb_strlen($str, 'UTF-8');
291
-        for ($i = 0; $i <= $strlen; $i++) {
291
+        for ($i = 0; $i <= $strlen; $i++) {
292 292
             $e = mb_substr($str, $i, 1, 'UTF-8');
293
-            switch ($e) {
293
+            switch ($e) {
294 294
                 case '\\':
295 295
                     $cur .= $e;
296 296
                     $cur .= mb_substr($str, ++$i, 1, 'UTF-8');
297 297
                     break;
298 298
                 case ')':
299 299
                     $open--;
300
-                    if ($open == 0) {
300
+                    if ($open == 0) {
301 301
                         $res[] = $cur . ')';
302 302
                         $cur = '';
303
-                    } else {
303
+                    } else {
304 304
                         $cur .= $e;
305 305
                     }
306 306
                     break;
@@ -309,10 +309,10 @@  discard block
 block discarded – undo
309 309
                     $cur .= $e;
310 310
                     break;
311 311
                 case ';':
312
-                    if ($open == 0) {
312
+                    if ($open == 0) {
313 313
                         $res[] = $cur;
314 314
                         $cur = '';
315
-                    } else {
315
+                    } else {
316 316
                         $cur .= $e;
317 317
                     }
318 318
                     break;
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
             }
322 322
         }
323 323
         $cur = preg_replace("/(\))$/u", '', $cur);
324
-        if ($cur != '') {
324
+        if ($cur != '') {
325 325
             $res[] = $cur;
326 326
         }
327 327
 
@@ -332,8 +332,8 @@  discard block
 block discarded – undo
332 332
      * Трансформация объекта в строку
333 333
      * @return string последний ответ от DocLister'а
334 334
      */
335
-    public function __toString()
336
-    {
335
+    public function __toString()
336
+    {
337 337
         return $this->outData;
338 338
     }
339 339
 
@@ -341,8 +341,8 @@  discard block
 block discarded – undo
341 341
      * Установить время запуска сниппета
342 342
      * @param float|null $time
343 343
      */
344
-    public function setTimeStart($time = null)
345
-    {
344
+    public function setTimeStart($time = null)
345
+    {
346 346
         $this->_timeStart = is_null($time) ? microtime(true) : $time;
347 347
     }
348 348
 
@@ -351,8 +351,8 @@  discard block
 block discarded – undo
351 351
      *
352 352
      * @return int
353 353
      */
354
-    public function getTimeStart()
355
-    {
354
+    public function getTimeStart()
355
+    {
356 356
         return $this->_timeStart;
357 357
     }
358 358
 
@@ -360,27 +360,27 @@  discard block
 block discarded – undo
360 360
      * Установка режима отладки
361 361
      * @param int $flag режим отладки
362 362
      */
363
-    public function setDebug($flag = 0)
364
-    {
363
+    public function setDebug($flag = 0)
364
+    {
365 365
         $flag = abs((int)$flag);
366
-        if ($this->_debugMode != $flag) {
366
+        if ($this->_debugMode != $flag) {
367 367
             $this->_debugMode = $flag;
368 368
             $this->debug = null;
369
-            if ($this->_debugMode > 0) {
370
-                if (isset($_SESSION['usertype']) && $_SESSION['usertype'] == 'manager') {
369
+            if ($this->_debugMode > 0) {
370
+                if (isset($_SESSION['usertype']) && $_SESSION['usertype'] == 'manager') {
371 371
                     error_reporting(E_ALL ^ E_NOTICE);
372 372
                     ini_set('display_errors', 1);
373 373
                 }
374 374
                 $dir = dirname(dirname(__FILE__));
375
-                if (file_exists($dir . "/lib/DLdebug.class.php")) {
375
+                if (file_exists($dir . "/lib/DLdebug.class.php")) {
376 376
                     include_once($dir . "/lib/DLdebug.class.php");
377
-                    if (class_exists("DLdebug", false)) {
377
+                    if (class_exists("DLdebug", false)) {
378 378
                         $this->debug = new DLdebug($this);
379 379
                     }
380 380
                 }
381 381
             }
382 382
 
383
-            if (is_null($this->debug)) {
383
+            if (is_null($this->debug)) {
384 384
                 $this->debug = new xNop();
385 385
                 $this->_debugMode = 0;
386 386
                 error_reporting(0);
@@ -392,8 +392,8 @@  discard block
 block discarded – undo
392 392
     /**
393 393
      * Информация о режиме отладки
394 394
      */
395
-    public function getDebug()
396
-    {
395
+    public function getDebug()
396
+    {
397 397
         return $this->_debugMode;
398 398
     }
399 399
 
@@ -404,13 +404,13 @@  discard block
 block discarded – undo
404 404
      * @param string $alias желаемый алиас таблицы
405 405
      * @return string имя таблицы с префиксом и алиасом
406 406
      */
407
-    public function getTable($name, $alias = '')
408
-    {
409
-        if (!isset($this->_table[$name])) {
407
+    public function getTable($name, $alias = '')
408
+    {
409
+        if (!isset($this->_table[$name])) {
410 410
             $this->_table[$name] = $this->modx->getFullTableName($name);
411 411
         }
412 412
         $table = $this->_table[$name];
413
-        if (!empty($alias) && is_scalar($alias)) {
413
+        if (!empty($alias) && is_scalar($alias)) {
414 414
             $table .= " as `" . $alias . "`";
415 415
         }
416 416
 
@@ -423,9 +423,9 @@  discard block
 block discarded – undo
423 423
      * @param $alias
424 424
      * @return mixed
425 425
      */
426
-    public function TableAlias($name, $table, $alias)
427
-    {
428
-        if (!$this->checkTableAlias($name, $table)) {
426
+    public function TableAlias($name, $table, $alias)
427
+    {
428
+        if (!$this->checkTableAlias($name, $table)) {
429 429
             $this->AddTable[$table][$name] = $alias;
430 430
         }
431 431
 
@@ -437,8 +437,8 @@  discard block
 block discarded – undo
437 437
      * @param $table
438 438
      * @return bool
439 439
      */
440
-    public function checkTableAlias($name, $table)
441
-    {
440
+    public function checkTableAlias($name, $table)
441
+    {
442 442
         return isset($this->AddTable[$table][$name]);
443 443
     }
444 444
 
@@ -450,8 +450,8 @@  discard block
 block discarded – undo
450 450
      * @param bool $nop создавать ли пустой объект запрашиваемого типа
451 451
      * @return array|mixed|xNop
452 452
      */
453
-    public function jsonDecode($json, $config = array(), $nop = false)
454
-    {
453
+    public function jsonDecode($json, $config = array(), $nop = false)
454
+    {
455 455
         $this->debug->debug('Decode JSON: ' . $this->debug->dumpData($json) . "\r\nwith config: " . $this->debug->dumpData($config),
456 456
             'jsonDecode', 2);
457 457
         $config = jsonHelper::jsonDecode($json, $config, $nop);
@@ -467,10 +467,10 @@  discard block
 block discarded – undo
467 467
      * @param $json string строка с JSON для записи в лог при отладке
468 468
      * @return bool|string
469 469
      */
470
-    public function isErrorJSON($json)
471
-    {
470
+    public function isErrorJSON($json)
471
+    {
472 472
         $error = jsonHelper::json_last_error_msg();
473
-        if (!in_array($error, array('error_none', 'other'))) {
473
+        if (!in_array($error, array('error_none', 'other'))) {
474 474
             $this->debug->error($this->getMsg('json.' . $error) . ": " . $this->debug->dumpData($json, 'code'), 'JSON');
475 475
             $error = true;
476 476
         }
@@ -482,20 +482,20 @@  discard block
 block discarded – undo
482 482
      * Проверка параметров и загрузка необходимых экстендеров
483 483
      * return boolean статус загрузки
484 484
      */
485
-    public function checkDL()
486
-    {
485
+    public function checkDL()
486
+    {
487 487
         $this->debug->debug('Check DocLister parameters', 'checkDL', 2);
488 488
         $flag = true;
489 489
         $extenders = $this->getCFGDef('extender', '');
490 490
         $extenders = explode(",", $extenders);
491 491
         $tmp = $this->getCFGDef('requestActive', '') != '' || in_array('request', $extenders);
492
-        if ($tmp && !$this->_loadExtender('request')) {
492
+        if ($tmp && !$this->_loadExtender('request')) {
493 493
             //OR request in extender's parameter
494 494
             throw new Exception('Error load request extender');
495 495
         }
496 496
 
497 497
         $tmp = $this->getCFGDef('summary', '') != '' || in_array('summary', $extenders);
498
-        if ($tmp && !$this->_loadExtender('summary')) {
498
+        if ($tmp && !$this->_loadExtender('summary')) {
499 499
             //OR summary in extender's parameter
500 500
             throw new Exception('Error load summary extender');
501 501
         }
@@ -508,15 +508,15 @@  discard block
 block discarded – undo
508 508
                 $this->getCFGDef('pageLimit', '') != '' || $this->getCFGDef('pageAdjacents', '') != '' ||
509 509
                 $this->getCFGDef('PaginateClass', '') != '' || $this->getCFGDef('TplNextP', '') != ''
510 510
             ) && !$this->_loadExtender('paginate')
511
-        ) {
511
+        ) {
512 512
             throw new Exception('Error load paginate extender');
513
-        } else {
514
-            if ((int)$this->getCFGDef('display', 0) == 0) {
513
+        } else {
514
+            if ((int)$this->getCFGDef('display', 0) == 0) {
515 515
                 $extenders = $this->unsetArrayVal($extenders, 'paginate');
516 516
             }
517 517
         }
518 518
 
519
-        if ($this->getCFGDef('prepare', '') != '' || $this->getCFGDef('prepareWrap') != '') {
519
+        if ($this->getCFGDef('prepare', '') != '' || $this->getCFGDef('prepareWrap') != '') {
520 520
             $this->_loadExtender('prepare');
521 521
         }
522 522
 
@@ -533,14 +533,14 @@  discard block
 block discarded – undo
533 533
      * @param mixed $val значение которые необходимо удалить из массива
534 534
      * @return array отчищеный массив с данными
535 535
      */
536
-    private function unsetArrayVal($data, $val)
537
-    {
536
+    private function unsetArrayVal($data, $val)
537
+    {
538 538
         $out = array();
539
-        if (is_array($data)) {
540
-            foreach ($data as $item) {
541
-                if ($item != $val) {
539
+        if (is_array($data)) {
540
+            foreach ($data as $item) {
541
+                if ($item != $val) {
542 542
                     $out[] = $item;
543
-                } else {
543
+                } else {
544 544
                     continue;
545 545
                 }
546 546
             }
@@ -555,14 +555,14 @@  discard block
 block discarded – undo
555 555
      * @param int $id уникальный идентификатор страницы
556 556
      * @return string URL страницы
557 557
      */
558
-    public function getUrl($id = 0)
559
-    {
558
+    public function getUrl($id = 0)
559
+    {
560 560
         $id = ((int)$id > 0) ? (int)$id : $this->getCurrentMODXPageID();
561 561
 
562 562
         $link = $this->checkExtender('request') ? $this->extender['request']->getLink() : $this->getRequest();
563
-        if ($id == $this->modx->config['site_start']) {
563
+        if ($id == $this->modx->config['site_start']) {
564 564
             $url = $this->modx->config['site_url'] . ($link != '' ? "?{$link}" : "");
565
-        } else {
565
+        } else {
566 566
             $url = $this->modx->makeUrl($id, '', $link, $this->getCFGDef('urlScheme', ''));
567 567
         }
568 568
 
@@ -590,20 +590,20 @@  discard block
 block discarded – undo
590 590
      * @param string $tpl шаблон
591 591
      * @return string
592 592
      */
593
-    public function render($tpl = '')
594
-    {
593
+    public function render($tpl = '')
594
+    {
595 595
         $this->debug->debug(array('Render data with template ' => $tpl), 'render', 2, array('html'));
596 596
         $out = '';
597
-        if (1 == $this->getCFGDef('tree', '0')) {
598
-            foreach ($this->_tree as $item) {
597
+        if (1 == $this->getCFGDef('tree', '0')) {
598
+            foreach ($this->_tree as $item) {
599 599
                 $out .= $this->renderTree($item);
600 600
             }
601 601
             $out = $this->renderWrap($out);
602
-        } else {
602
+        } else {
603 603
             $out = $this->_render($tpl);
604 604
         }
605 605
 
606
-        if ($out) {
606
+        if ($out) {
607 607
             $this->outData = DLTemplate::getInstance($this->modx)->parseDocumentSource($out);
608 608
         }
609 609
         $this->debug->debugEnd('render');
@@ -620,8 +620,8 @@  discard block
 block discarded – undo
620 620
      *
621 621
      * @return int
622 622
      */
623
-    public function getCurrentMODXPageID()
624
-    {
623
+    public function getCurrentMODXPageID()
624
+    {
625 625
         $id = isset($this->modx->documentIdentifier) ? (int)$this->modx->documentIdentifier : 0;
626 626
         $docData = isset($this->modx->documentObject) ? $this->modx->documentObject : array();
627 627
 
@@ -637,9 +637,9 @@  discard block
 block discarded – undo
637 637
      * @param integer $line error on line
638 638
      * @param array $trace stack trace
639 639
      */
640
-    public function ErrorLogger($message, $code, $file, $line, $trace)
641
-    {
642
-        if (abs($this->getCFGDef('debug', '0')) == '1') {
640
+    public function ErrorLogger($message, $code, $file, $line, $trace)
641
+    {
642
+        if (abs($this->getCFGDef('debug', '0')) == '1') {
643 643
             $out = "CODE #" . $code . "<br />";
644 644
             $out .= "on file: " . $file . ":" . $line . "<br />";
645 645
             $out .= "<pre>";
@@ -656,8 +656,8 @@  discard block
 block discarded – undo
656 656
      *
657 657
      * @return DocumentParser
658 658
      */
659
-    public function getMODX()
660
-    {
659
+    public function getMODX()
660
+    {
661 661
         return $this->modx;
662 662
     }
663 663
 
@@ -668,13 +668,13 @@  discard block
 block discarded – undo
668 668
      * @return boolean status load extenders
669 669
      * @throws Exception
670 670
      */
671
-    public function loadExtender($ext = '')
672
-    {
671
+    public function loadExtender($ext = '')
672
+    {
673 673
         $out = true;
674
-        if ($ext != '') {
674
+        if ($ext != '') {
675 675
             $ext = explode(",", $ext);
676
-            foreach ($ext as $item) {
677
-                if ($item != '' && !$this->_loadExtender($item)) {
676
+            foreach ($ext as $item) {
677
+                if ($item != '' && !$this->_loadExtender($item)) {
678 678
                     throw new Exception('Error load ' . APIHelpers::e($item) . ' extender');
679 679
                 }
680 680
             }
@@ -690,8 +690,8 @@  discard block
 block discarded – undo
690 690
      * @param mixed $def значение по умолчанию, если в конфиге нет искомого параметра
691 691
      * @return mixed значение из конфига
692 692
      */
693
-    public function getCFGDef($name, $def = null)
694
-    {
693
+    public function getCFGDef($name, $def = null)
694
+    {
695 695
         return $this->config->getCFGDef($name, $def);
696 696
     }
697 697
 
@@ -703,15 +703,15 @@  discard block
 block discarded – undo
703 703
      * @param string $key ключ локального плейсхолдера
704 704
      * @return string
705 705
      */
706
-    public function toPlaceholders($data, $set = 0, $key = 'contentPlaceholder')
707
-    {
706
+    public function toPlaceholders($data, $set = 0, $key = 'contentPlaceholder')
707
+    {
708 708
         $this->debug->debug(null, 'toPlaceholders', 2);
709
-        if ($set == 0) {
709
+        if ($set == 0) {
710 710
             $set = $this->getCFGDef('contentPlaceholder', 0);
711 711
         }
712 712
         $this->_plh[$key] = $data;
713 713
         $id = $this->getCFGDef('id', '');
714
-        if ($id != '') {
714
+        if ($id != '') {
715 715
             $id .= ".";
716 716
         }
717 717
         $out = DLTemplate::getInstance($this->getMODX())->toPlaceholders($data, $set, $key, $id);
@@ -733,14 +733,14 @@  discard block
 block discarded – undo
733 733
      * @param boolean $quote заключать ли данные на выходе в кавычки
734 734
      * @return string обработанная строка
735 735
      */
736
-    public function sanitarIn($data, $sep = ',', $quote = true)
737
-    {
738
-        if (!is_array($data)) {
736
+    public function sanitarIn($data, $sep = ',', $quote = true)
737
+    {
738
+        if (!is_array($data)) {
739 739
             $data = explode($sep, $data);
740 740
         }
741 741
         $out = array();
742
-        foreach ($data as $item) {
743
-            if ($item !== '') {
742
+        foreach ($data as $item) {
743
+            if ($item !== '') {
744 744
                 $out[] = $this->modx->db->escape($item);
745 745
             }
746 746
         }
@@ -761,12 +761,12 @@  discard block
 block discarded – undo
761 761
      * @param string $lang имя языкового пакета
762 762
      * @return array
763 763
      */
764
-    public function getCustomLang($lang = '')
765
-    {
766
-        if (empty($lang)) {
764
+    public function getCustomLang($lang = '')
765
+    {
766
+        if (empty($lang)) {
767 767
             $lang = $this->getCFGDef('lang', $this->modx->config['manager_language']);
768 768
         }
769
-        if (file_exists(dirname(dirname(__FILE__)) . "/lang/" . $lang . ".php")) {
769
+        if (file_exists(dirname(dirname(__FILE__)) . "/lang/" . $lang . ".php")) {
770 770
             $tmp = include(dirname(__FILE__) . "/lang/" . $lang . ".php");
771 771
             $this->_customLang = is_array($tmp) ? $tmp : array();
772 772
         }
@@ -782,25 +782,25 @@  discard block
 block discarded – undo
782 782
      * @param boolean $rename Переименовывать ли элементы массива
783 783
      * @return array массив с лексиконом
784 784
      */
785
-    public function loadLang($name = 'core', $lang = '', $rename = true)
786
-    {
787
-        if (empty($lang)) {
785
+    public function loadLang($name = 'core', $lang = '', $rename = true)
786
+    {
787
+        if (empty($lang)) {
788 788
             $lang = $this->getCFGDef('lang', $this->modx->config['manager_language']);
789 789
         }
790 790
 
791 791
         $this->debug->debug('Load language ' . $this->debug->dumpData($name) . "." . $this->debug->dumpData($lang),
792 792
             'loadlang', 2);
793
-        if (is_scalar($name)) {
793
+        if (is_scalar($name)) {
794 794
             $name = array($name);
795 795
         }
796
-        foreach ($name as $n) {
797
-            if (file_exists(dirname(__FILE__) . "/lang/" . $lang . "/" . $n . ".inc.php")) {
796
+        foreach ($name as $n) {
797
+            if (file_exists(dirname(__FILE__) . "/lang/" . $lang . "/" . $n . ".inc.php")) {
798 798
                 $tmp = include(dirname(__FILE__) . "/lang/" . $lang . "/" . $n . ".inc.php");
799
-                if (is_array($tmp)) {
799
+                if (is_array($tmp)) {
800 800
                     /**
801 801
                      * Переименовыываем элементы массива из array('test'=>'data') в array('name.test'=>'data')
802 802
                      */
803
-                    if ($rename) {
803
+                    if ($rename) {
804 804
                         $tmp = $this->renameKeyArr($tmp, $n, '', '.');
805 805
                     }
806 806
                     $this->_lang = array_merge($this->_lang, $tmp);
@@ -819,11 +819,11 @@  discard block
 block discarded – undo
819 819
      * @param string $def Строка по умолчанию, если запись в языковом пакете не будет обнаружена
820 820
      * @return string строка в соответствии с текущими языковыми настройками
821 821
      */
822
-    public function getMsg($name, $def = '')
823
-    {
824
-        if (isset($this->_customLang[$name])) {
822
+    public function getMsg($name, $def = '')
823
+    {
824
+        if (isset($this->_customLang[$name])) {
825 825
             $say = $this->_customLang[$name];
826
-        } else {
826
+        } else {
827 827
             $say = \APIHelpers::getkey($this->_lang, $name, $def);
828 828
         }
829 829
 
@@ -839,8 +839,8 @@  discard block
 block discarded – undo
839 839
      * @param string $sep разделитель суффиксов, префиксов и ключей массива
840 840
      * @return array массив с переименованными ключами
841 841
      */
842
-    public function renameKeyArr($data, $prefix = '', $suffix = '', $sep = '.')
843
-    {
842
+    public function renameKeyArr($data, $prefix = '', $suffix = '', $sep = '.')
843
+    {
844 844
         return \APIHelpers::renameKeyArr($data, $prefix, $suffix, $sep);
845 845
     }
846 846
 
@@ -850,12 +850,12 @@  discard block
 block discarded – undo
850 850
      * @param string $locale локаль
851 851
      * @return string имя установленной локали
852 852
      */
853
-    public function setLocate($locale = '')
854
-    {
855
-        if ('' == $locale) {
853
+    public function setLocate($locale = '')
854
+    {
855
+        if ('' == $locale) {
856 856
             $locale = $this->getCFGDef('locale', '');
857 857
         }
858
-        if ('' != $locale) {
858
+        if ('' != $locale) {
859 859
             setlocale(LC_ALL, $locale);
860 860
         }
861 861
 
@@ -869,11 +869,11 @@  discard block
 block discarded – undo
869 869
      * @param array $data массив сформированный как дерево
870 870
      * @return string строка для отображения пользователю
871 871
      */
872
-    protected function renderTree($data)
873
-    {
872
+    protected function renderTree($data)
873
+    {
874 874
         $out = '';
875
-        if (!empty($data['#childNodes'])) {
876
-            foreach ($data['#childNodes'] as $item) {
875
+        if (!empty($data['#childNodes'])) {
876
+            foreach ($data['#childNodes'] as $item) {
877 877
                 $out .= $this->renderTree($item);
878 878
             }
879 879
         }
@@ -890,8 +890,8 @@  discard block
 block discarded – undo
890 890
      * @param string $name Template: chunk name || @CODE: template || @FILE: file with template
891 891
      * @return string html template with placeholders without data
892 892
      */
893
-    private function _getChunk($name)
894
-    {
893
+    private function _getChunk($name)
894
+    {
895 895
         $this->debug->debug(array('Get chunk by name' => $name), "getChunk", 2, array('html'));
896 896
         //without trim
897 897
         $tpl = DLTemplate::getInstance($this->getMODX())->getChunk($name);
@@ -908,18 +908,18 @@  discard block
 block discarded – undo
908 908
      * @param string $tpl HTML шаблон
909 909
      * @return string
910 910
      */
911
-    public function parseLang($tpl)
912
-    {
911
+    public function parseLang($tpl)
912
+    {
913 913
         $this->debug->debug(array("parseLang" => $tpl), "parseLang", 2, array('html'));
914
-        if (is_scalar($tpl) && !empty($tpl)) {
915
-            if (preg_match_all("/\[\%([a-zA-Z0-9\.\_\-]+)\%\]/", $tpl, $match)) {
914
+        if (is_scalar($tpl) && !empty($tpl)) {
915
+            if (preg_match_all("/\[\%([a-zA-Z0-9\.\_\-]+)\%\]/", $tpl, $match)) {
916 916
                 $langVal = array();
917
-                foreach ($match[1] as $item) {
917
+                foreach ($match[1] as $item) {
918 918
                     $langVal[] = $this->getMsg($item);
919 919
                 }
920 920
                 $tpl = str_replace($match[0], $langVal, $tpl);
921 921
             }
922
-        } else {
922
+        } else {
923 923
             $tpl = '';
924 924
         }
925 925
         $this->debug->debugEnd("parseLang");
@@ -935,8 +935,8 @@  discard block
 block discarded – undo
935 935
      * @param bool $parseDocumentSource render html template via DocumentParser::parseDocumentSource()
936 936
      * @return string html template with data without placeholders
937 937
      */
938
-    public function parseChunk($name, $data, $parseDocumentSource = false)
939
-    {
938
+    public function parseChunk($name, $data, $parseDocumentSource = false)
939
+    {
940 940
         $this->debug->debug(
941 941
             array("parseChunk" => $name, "With data" => print_r($data, 1)),
942 942
             "parseChunk",
@@ -945,7 +945,7 @@  discard block
 block discarded – undo
945 945
 
946 946
         $out = $this->DLTemplate->parseChunk($name, $data, $parseDocumentSource);
947 947
         $out = $this->parseLang($out);
948
-        if (empty($out)) {
948
+        if (empty($out)) {
949 949
             $this->debug->debug("Empty chunk: " . $this->debug->dumpData($name), '', 2);
950 950
         }
951 951
         $this->debug->debugEnd("parseChunk");
@@ -961,8 +961,8 @@  discard block
 block discarded – undo
961 961
      *
962 962
      * @return string html template from parameter
963 963
      */
964
-    public function getChunkByParam($name, $val = '')
965
-    {
964
+    public function getChunkByParam($name, $val = '')
965
+    {
966 966
         $data = $this->getCFGDef($name, $val);
967 967
         $data = $this->_getChunk($data);
968 968
 
@@ -975,11 +975,11 @@  discard block
 block discarded – undo
975 975
      * @param string $data html код который нужно обернуть в ownerTPL
976 976
      * @return string результатирующий html код
977 977
      */
978
-    public function renderWrap($data)
979
-    {
978
+    public function renderWrap($data)
979
+    {
980 980
         $out = $data;
981 981
         $docs = count($this->_docs) - $this->skippedDocs;
982
-        if ((($this->getCFGDef("noneWrapOuter", "1") && $docs == 0) || $docs > 0) && !empty($this->ownerTPL)) {
982
+        if ((($this->getCFGDef("noneWrapOuter", "1") && $docs == 0) || $docs > 0) && !empty($this->ownerTPL)) {
983 983
             $this->debug->debug("", "renderWrapTPL", 2);
984 984
             $parse = true;
985 985
             $plh = array($this->getCFGDef("sysKey", "dl") . ".wrap" => $data);
@@ -987,7 +987,7 @@  discard block
 block discarded – undo
987 987
              * @var $extPrepare prepare_DL_Extender
988 988
              */
989 989
             $extPrepare = $this->getExtender('prepare');
990
-            if ($extPrepare) {
990
+            if ($extPrepare) {
991 991
                 $params = $extPrepare->init($this, array(
992 992
                     'data'      => array(
993 993
                         'docs'         => $this->_docs,
@@ -996,13 +996,13 @@  discard block
 block discarded – undo
996 996
                     'nameParam' => 'prepareWrap',
997 997
                     'return'    => 'placeholders'
998 998
                 ));
999
-                if (is_bool($params) && $params === false) {
999
+                if (is_bool($params) && $params === false) {
1000 1000
                     $out = $data;
1001 1001
                     $parse = false;
1002 1002
                 }
1003 1003
                 $plh = $params;
1004 1004
             }
1005
-            if ($parse && !empty($this->ownerTPL)) {
1005
+            if ($parse && !empty($this->ownerTPL)) {
1006 1006
                 $this->debug->updateMessage(
1007 1007
                     array("render ownerTPL" => $this->ownerTPL, "With data" => print_r($plh, 1)),
1008 1008
                     "renderWrapTPL",
@@ -1010,7 +1010,7 @@  discard block
 block discarded – undo
1010 1010
                 );
1011 1011
                 $out = $this->parseChunk($this->ownerTPL, $plh);
1012 1012
             }
1013
-            if (empty($this->ownerTPL)) {
1013
+            if (empty($this->ownerTPL)) {
1014 1014
                 $this->debug->updateMessage("empty ownerTPL", "renderWrapTPL");
1015 1015
             }
1016 1016
             $this->debug->debugEnd("renderWrapTPL");
@@ -1026,8 +1026,8 @@  discard block
 block discarded – undo
1026 1026
      * @param int $i номер итерации в цикле
1027 1027
      * @return array массив с данными которые можно использовать в цикле render метода
1028 1028
      */
1029
-    protected function uniformPrepare(&$data, $i = 0)
1030
-    {
1029
+    protected function uniformPrepare(&$data, $i = 0)
1030
+    {
1031 1031
         $class = array();
1032 1032
 
1033 1033
         $iterationName = ($i % 2 == 1) ? 'Odd' : 'Even';
@@ -1038,13 +1038,13 @@  discard block
 block discarded – undo
1038 1038
         $this->renderTPL = $this->getCFGDef('tpl' . $iterationName, $this->renderTPL);
1039 1039
         $iteration = $i;
1040 1040
 
1041
-        if ($this->extPaginate) {
1041
+        if ($this->extPaginate) {
1042 1042
             $offset = $this->getCFGDef('reversePagination',
1043 1043
                 0) && $this->extPaginate->currentPage() > 1 ? $this->extPaginate->totalPage() * $this->getCFGDef('display',
1044 1044
                     0) - $this->extPaginate->totalDocs() : 0;
1045 1045
             if ($this->getCFGDef('maxDocs', 0) && !$this->getCFGDef('reversePagination',
1046 1046
                     0) && $this->extPaginate->currentPage() == $this->extPaginate->totalPage()
1047
-            ) {
1047
+            ) {
1048 1048
                 $iteration += $this->getCFGDef('display', 0);
1049 1049
             }
1050 1050
             $iteration += $this->getCFGDef('display',
@@ -1054,20 +1054,20 @@  discard block
 block discarded – undo
1054 1054
         $data[$this->getCFGDef("sysKey",
1055 1055
             "dl") . '.full_iteration'] = $iteration;
1056 1056
 
1057
-        if ($i == 1) {
1057
+        if ($i == 1) {
1058 1058
             $this->renderTPL = $this->getCFGDef('tplFirst', $this->renderTPL);
1059 1059
             $class[] = $this->getCFGDef('firstClass', 'first');
1060 1060
         }
1061
-        if ($i == (count($this->_docs) - $this->skippedDocs)) {
1061
+        if ($i == (count($this->_docs) - $this->skippedDocs)) {
1062 1062
             $this->renderTPL = $this->getCFGDef('tplLast', $this->renderTPL);
1063 1063
             $class[] = $this->getCFGDef('lastClass', 'last');
1064 1064
         }
1065
-        if ($this->modx->documentIdentifier == $data['id']) {
1065
+        if ($this->modx->documentIdentifier == $data['id']) {
1066 1066
             $this->renderTPL = $this->getCFGDef('tplCurrent', $this->renderTPL);
1067 1067
             $data[$this->getCFGDef("sysKey",
1068 1068
                 "dl") . '.active'] = 1; //[+active+] - 1 if $modx->documentIdentifer equal ID this element
1069 1069
             $class[] = $this->getCFGDef('currentClass', 'current');
1070
-        } else {
1070
+        } else {
1071 1071
             $data[$this->getCFGDef("sysKey", "dl") . '.active'] = 0;
1072 1072
         }
1073 1073
 
@@ -1078,8 +1078,8 @@  discard block
 block discarded – undo
1078 1078
          * @var $extE e_DL_Extender
1079 1079
          */
1080 1080
         $extE = $this->getExtender('e', true, true);
1081
-        if ($out = $extE->init($this, compact('data'))) {
1082
-            if (is_array($out)) {
1081
+        if ($out = $extE->init($this, compact('data'))) {
1082
+            if (is_array($out)) {
1083 1083
                 $data = $out;
1084 1084
             }
1085 1085
         }
@@ -1095,42 +1095,43 @@  discard block
 block discarded – undo
1095 1095
      * @param array $array данные которые необходимо примешать к ответу на каждой записи $data
1096 1096
      * @return string JSON строка
1097 1097
      */
1098
-    public function getJSON($data, $fields, $array = array())
1099
-    {
1098
+    public function getJSON($data, $fields, $array = array())
1099
+    {
1100 1100
         $out = array();
1101 1101
         $fields = is_array($fields) ? $fields : explode(",", $fields);
1102
-        if (is_array($array) && count($array) > 0) {
1102
+        if (is_array($array) && count($array) > 0) {
1103 1103
             $tmp = array();
1104
-            foreach ($data as $i => $v) { //array_merge not valid work with integer index key
1104
+            foreach ($data as $i => $v) {
1105
+//array_merge not valid work with integer index key
1105 1106
                 $tmp[$i] = (isset($array[$i]) ? array_merge($v, $array[$i]) : $v);
1106 1107
             }
1107 1108
             $data = $tmp;
1108 1109
         }
1109 1110
 
1110
-        foreach ($data as $num => $doc) {
1111
+        foreach ($data as $num => $doc) {
1111 1112
             $tmp = array();
1112
-            foreach ($doc as $name => $value) {
1113
-                if (in_array($name, $fields) || (isset($fields[0]) && $fields[0] == '1')) {
1113
+            foreach ($doc as $name => $value) {
1114
+                if (in_array($name, $fields) || (isset($fields[0]) && $fields[0] == '1')) {
1114 1115
                     $tmp[str_replace(".", "_", $name)] = $value; //JSON element name without dot
1115 1116
                 }
1116 1117
             }
1117 1118
             $out[$num] = $tmp;
1118 1119
         }
1119 1120
 
1120
-        if ('new' == $this->getCFGDef('JSONformat', 'old')) {
1121
+        if ('new' == $this->getCFGDef('JSONformat', 'old')) {
1121 1122
             $return = array();
1122 1123
 
1123 1124
             $return['rows'] = array();
1124
-            foreach ($out as $key => $item) {
1125
+            foreach ($out as $key => $item) {
1125 1126
                 $return['rows'][] = $item;
1126 1127
             }
1127 1128
             $return['total'] = $this->getChildrenCount();
1128
-        } elseif ('simple' == $this->getCFGDef('JSONformat', 'old')) {
1129
+        } elseif ('simple' == $this->getCFGDef('JSONformat', 'old')) {
1129 1130
             $return = array();
1130
-            foreach ($out as $key => $item) {
1131
+            foreach ($out as $key => $item) {
1131 1132
                 $return[] = $item;
1132 1133
             }
1133
-        } else {
1134
+        } else {
1134 1135
             $return = $out;
1135 1136
         }
1136 1137
         $this->outData = json_encode($return);
@@ -1146,11 +1147,11 @@  discard block
 block discarded – undo
1146 1147
      * @param string $contentField
1147 1148
      * @return mixed|string
1148 1149
      */
1149
-    protected function getSummary(array $item = array(), $extSummary = null, $introField = '', $contentField = '')
1150
-    {
1150
+    protected function getSummary(array $item = array(), $extSummary = null, $introField = '', $contentField = '')
1151
+    {
1151 1152
         $out = '';
1152 1153
 
1153
-        if (is_null($extSummary)) {
1154
+        if (is_null($extSummary)) {
1154 1155
             /**
1155 1156
              * @var $extSummary summary_DL_Extender
1156 1157
              */
@@ -1159,10 +1160,10 @@  discard block
 block discarded – undo
1159 1160
         $introField = $this->getCFGDef("introField", $introField);
1160 1161
         $contentField = $this->getCFGDef("contentField", $contentField);
1161 1162
 
1162
-        if (!empty($introField) && !empty($item[$introField]) && mb_strlen($item[$introField], 'UTF-8') > 0) {
1163
+        if (!empty($introField) && !empty($item[$introField]) && mb_strlen($item[$introField], 'UTF-8') > 0) {
1163 1164
             $out = $item[$introField];
1164
-        } else {
1165
-            if (!empty($contentField) && !empty($item[$contentField]) && mb_strlen($item[$contentField], 'UTF-8') > 0) {
1165
+        } else {
1166
+            if (!empty($contentField) && !empty($item[$contentField]) && mb_strlen($item[$contentField], 'UTF-8') > 0) {
1166 1167
                 $out = $extSummary->init($this, array(
1167 1168
                     "content"      => $item[$contentField],
1168 1169
                     "action"       => $this->getCFGDef("summary", ""),
@@ -1180,8 +1181,8 @@  discard block
 block discarded – undo
1180 1181
      * @param string $name extender name
1181 1182
      * @return boolean status extender load
1182 1183
      */
1183
-    public function checkExtender($name)
1184
-    {
1184
+    public function checkExtender($name)
1185
+    {
1185 1186
         return (isset($this->extender[$name]) && $this->extender[$name] instanceof $name . "_DL_Extender");
1186 1187
     }
1187 1188
 
@@ -1189,8 +1190,8 @@  discard block
 block discarded – undo
1189 1190
      * @param $name
1190 1191
      * @param $obj
1191 1192
      */
1192
-    public function setExtender($name, $obj)
1193
-    {
1193
+    public function setExtender($name, $obj)
1194
+    {
1194 1195
         $this->extender[$name] = $obj;
1195 1196
     }
1196 1197
 
@@ -1202,13 +1203,13 @@  discard block
 block discarded – undo
1202 1203
      * @param bool $nop если экстендер не загружен, то загружать ли xNop
1203 1204
      * @return null|xNop
1204 1205
      */
1205
-    public function getExtender($name, $autoload = false, $nop = false)
1206
-    {
1206
+    public function getExtender($name, $autoload = false, $nop = false)
1207
+    {
1207 1208
         $out = null;
1208
-        if ((is_scalar($name) && $this->checkExtender($name)) || ($autoload && $this->_loadExtender($name))) {
1209
+        if ((is_scalar($name) && $this->checkExtender($name)) || ($autoload && $this->_loadExtender($name))) {
1209 1210
             $out = $this->extender[$name];
1210 1211
         }
1211
-        if ($nop && is_null($out)) {
1212
+        if ($nop && is_null($out)) {
1212 1213
             $out = new xNop();
1213 1214
         }
1214 1215
 
@@ -1221,27 +1222,27 @@  discard block
 block discarded – undo
1221 1222
      * @param string $name name extender
1222 1223
      * @return boolean $flag status load extender
1223 1224
      */
1224
-    protected function _loadExtender($name)
1225
-    {
1225
+    protected function _loadExtender($name)
1226
+    {
1226 1227
         $this->debug->debug('Load Extender ' . $this->debug->dumpData($name), 'LoadExtender', 2);
1227 1228
         $flag = false;
1228 1229
 
1229 1230
         $classname = ($name != '') ? $name . "_DL_Extender" : "";
1230
-        if ($classname != '' && isset($this->extender[$name]) && $this->extender[$name] instanceof $classname) {
1231
+        if ($classname != '' && isset($this->extender[$name]) && $this->extender[$name] instanceof $classname) {
1231 1232
             $flag = true;
1232 1233
 
1233
-        } else {
1234
-            if (!class_exists($classname, false) && $classname != '') {
1235
-                if (file_exists(dirname(__FILE__) . "/extender/" . $name . ".extender.inc")) {
1234
+        } else {
1235
+            if (!class_exists($classname, false) && $classname != '') {
1236
+                if (file_exists(dirname(__FILE__) . "/extender/" . $name . ".extender.inc")) {
1236 1237
                     include_once(dirname(__FILE__) . "/extender/" . $name . ".extender.inc");
1237 1238
                 }
1238 1239
             }
1239
-            if (class_exists($classname, false) && $classname != '') {
1240
+            if (class_exists($classname, false) && $classname != '') {
1240 1241
                 $this->extender[$name] = new $classname($this, $name);
1241 1242
                 $flag = true;
1242 1243
             }
1243 1244
         }
1244
-        if (!$flag) {
1245
+        if (!$flag) {
1245 1246
             $this->debug->debug("Error load Extender " . $this->debug->dumpData($name));
1246 1247
         }
1247 1248
         $this->debug->debugEnd('LoadExtender');
@@ -1259,16 +1260,16 @@  discard block
 block discarded – undo
1259 1260
      * @param mixed $IDs список id документов по которым необходима выборка
1260 1261
      * @return array очищенный массив
1261 1262
      */
1262
-    public function setIDs($IDs)
1263
-    {
1263
+    public function setIDs($IDs)
1264
+    {
1264 1265
         $this->debug->debug('set ID list ' . $this->debug->dumpData($IDs), 'setIDs', 2);
1265 1266
         $IDs = $this->cleanIDs($IDs);
1266 1267
         $type = $this->getCFGDef('idType', 'parents');
1267 1268
         $depth = $this->getCFGDef('depth', '');
1268
-        if ($type == 'parents' && $depth > 0) {
1269
+        if ($type == 'parents' && $depth > 0) {
1269 1270
             $tmp = $IDs;
1270
-            do {
1271
-                if (count($tmp) > 0) {
1271
+            do {
1272
+                if (count($tmp) > 0) {
1272 1273
                     $tmp = $this->getChildrenFolder($tmp);
1273 1274
                     $IDs = array_merge($IDs, $tmp);
1274 1275
                 }
@@ -1282,8 +1283,8 @@  discard block
 block discarded – undo
1282 1283
     /**
1283 1284
      * @return int
1284 1285
      */
1285
-    public function getIDs()
1286
-    {
1286
+    public function getIDs()
1287
+    {
1287 1288
         return $this->IDs;
1288 1289
     }
1289 1290
 
@@ -1294,17 +1295,18 @@  discard block
 block discarded – undo
1294 1295
      * @param string $sep разделитель
1295 1296
      * @return array очищенный массив с данными
1296 1297
      */
1297
-    public function cleanIDs($IDs, $sep = ',')
1298
-    {
1298
+    public function cleanIDs($IDs, $sep = ',')
1299
+    {
1299 1300
         $this->debug->debug('clean IDs ' . $this->debug->dumpData($IDs) . ' with separator ' . $this->debug->dumpData($sep),
1300 1301
             'cleanIDs', 2);
1301 1302
         $out = array();
1302
-        if (!is_array($IDs)) {
1303
+        if (!is_array($IDs)) {
1303 1304
             $IDs = explode($sep, $IDs);
1304 1305
         }
1305
-        foreach ($IDs as $item) {
1306
+        foreach ($IDs as $item) {
1306 1307
             $item = trim($item);
1307
-            if (is_numeric($item) && (int)$item >= 0) { //Fix 0xfffffffff
1308
+            if (is_numeric($item) && (int)$item >= 0) {
1309
+//Fix 0xfffffffff
1308 1310
                 $out[] = (int)$item;
1309 1311
             }
1310 1312
         }
@@ -1318,8 +1320,8 @@  discard block
 block discarded – undo
1318 1320
      * Проверка массива с id-шниками документов для выборки
1319 1321
      * @return boolean пригодны ли данные для дальнейшего использования
1320 1322
      */
1321
-    protected function checkIDs()
1322
-    {
1323
+    protected function checkIDs()
1324
+    {
1323 1325
         return (is_array($this->IDs) && count($this->IDs) > 0) ? true : false;
1324 1326
     }
1325 1327
 
@@ -1331,11 +1333,11 @@  discard block
 block discarded – undo
1331 1333
      * @global array $_docs all documents
1332 1334
      * @return array all field values
1333 1335
      */
1334
-    public function getOneField($userField, $uniq = false)
1335
-    {
1336
+    public function getOneField($userField, $uniq = false)
1337
+    {
1336 1338
         $out = array();
1337
-        foreach ($this->_docs as $doc => $val) {
1338
-            if (isset($val[$userField]) && (($uniq && !in_array($val[$userField], $out)) || !$uniq)) {
1339
+        foreach ($this->_docs as $doc => $val) {
1340
+            if (isset($val[$userField]) && (($uniq && !in_array($val[$userField], $out)) || !$uniq)) {
1339 1341
                 $out[$doc] = $val[$userField];
1340 1342
             }
1341 1343
         }
@@ -1346,8 +1348,8 @@  discard block
 block discarded – undo
1346 1348
     /**
1347 1349
      * @return DLCollection
1348 1350
      */
1349
-    public function docsCollection()
1350
-    {
1351
+    public function docsCollection()
1352
+    {
1351 1353
         return new DLCollection($this->modx, $this->_docs);
1352 1354
     }
1353 1355
 
@@ -1375,10 +1377,10 @@  discard block
 block discarded – undo
1375 1377
      * @param string $group
1376 1378
      * @return string
1377 1379
      */
1378
-    protected function getGroupSQL($group = '')
1379
-    {
1380
+    protected function getGroupSQL($group = '')
1381
+    {
1380 1382
         $out = '';
1381
-        if ($group != '') {
1383
+        if ($group != '') {
1382 1384
             $out = 'GROUP BY ' . $group;
1383 1385
         }
1384 1386
 
@@ -1397,12 +1399,12 @@  discard block
 block discarded – undo
1397 1399
      *
1398 1400
      * @return string Order by for SQL
1399 1401
      */
1400
-    protected function SortOrderSQL($sortName, $orderDef = 'DESC')
1401
-    {
1402
+    protected function SortOrderSQL($sortName, $orderDef = 'DESC')
1403
+    {
1402 1404
         $this->debug->debug('', 'sortORDER', 2);
1403 1405
 
1404 1406
         $sort = '';
1405
-        switch ($this->getCFGDef('sortType', '')) {
1407
+        switch ($this->getCFGDef('sortType', '')) {
1406 1408
             case 'none':
1407 1409
                 break;
1408 1410
             case 'doclist':
@@ -1413,10 +1415,10 @@  discard block
 block discarded – undo
1413 1415
                 break;
1414 1416
             default:
1415 1417
                 $out = array('orderBy' => '', 'order' => '', 'sortBy' => '');
1416
-                if (($tmp = $this->getCFGDef('orderBy', '')) != '') {
1418
+                if (($tmp = $this->getCFGDef('orderBy', '')) != '') {
1417 1419
                     $out['orderBy'] = $tmp;
1418
-                } else {
1419
-                    switch (true) {
1420
+                } else {
1421
+                    switch (true) {
1420 1422
                         case ('' != ($tmp = $this->getCFGDef('sortDir', ''))): //higher priority than order
1421 1423
                             $out['order'] = $tmp;
1422 1424
                         // no break
@@ -1424,7 +1426,7 @@  discard block
 block discarded – undo
1424 1426
                             $out['order'] = $tmp;
1425 1427
                         // no break
1426 1428
                     }
1427
-                    if ('' == $out['order'] || !in_array(strtoupper($out['order']), array('ASC', 'DESC'))) {
1429
+                    if ('' == $out['order'] || !in_array(strtoupper($out['order']), array('ASC', 'DESC'))) {
1428 1430
                         $out['order'] = $orderDef; //Default
1429 1431
                     }
1430 1432
 
@@ -1445,30 +1447,30 @@  discard block
 block discarded – undo
1445 1447
      *
1446 1448
      * @return string LIMIT вставка в SQL запрос
1447 1449
      */
1448
-    protected function LimitSQL($limit = 0, $offset = 0)
1449
-    {
1450
+    protected function LimitSQL($limit = 0, $offset = 0)
1451
+    {
1450 1452
         $this->debug->debug('', 'limitSQL', 2);
1451 1453
         $ret = '';
1452
-        if ($limit == 0) {
1454
+        if ($limit == 0) {
1453 1455
             $limit = $this->getCFGDef('display', 0);
1454 1456
         }
1455 1457
         $maxDocs = $this->getCFGDef('maxDocs', 0);
1456
-        if ($maxDocs > 0 && $limit > $maxDocs) {
1458
+        if ($maxDocs > 0 && $limit > $maxDocs) {
1457 1459
             $limit = $maxDocs;
1458 1460
         }
1459
-        if ($offset == 0) {
1461
+        if ($offset == 0) {
1460 1462
             $offset = $this->getCFGDef('offset', 0);
1461 1463
         }
1462 1464
         $offset += $this->getCFGDef('start', 0);
1463 1465
         $total = $this->getCFGDef('total', 0);
1464
-        if ($limit < ($total - $limit)) {
1466
+        if ($limit < ($total - $limit)) {
1465 1467
             $limit = $total - $offset;
1466 1468
         }
1467 1469
 
1468
-        if ($limit != 0) {
1470
+        if ($limit != 0) {
1469 1471
             $ret = "LIMIT " . (int)$offset . "," . (int)$limit;
1470
-        } else {
1471
-            if ($offset != 0) {
1472
+        } else {
1473
+            if ($offset != 0) {
1472 1474
                 /**
1473 1475
                  * 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
1474 1476
                  * @see http://dev.mysql.com/doc/refman/5.0/en/select.html
@@ -1488,8 +1490,8 @@  discard block
 block discarded – undo
1488 1490
      * @param string $charset
1489 1491
      * @return string Clear string
1490 1492
      */
1491
-    public function sanitarData($data, $charset = 'UTF-8')
1492
-    {
1493
+    public function sanitarData($data, $charset = 'UTF-8')
1494
+    {
1493 1495
         return APIHelpers::sanitarTag($data, $charset);
1494 1496
     }
1495 1497
 
@@ -1500,8 +1502,8 @@  discard block
 block discarded – undo
1500 1502
      * @param string $parentField default name parent field
1501 1503
      * @return array
1502 1504
      */
1503
-    public function treeBuild($idField = 'id', $parentField = 'parent')
1504
-    {
1505
+    public function treeBuild($idField = 'id', $parentField = 'parent')
1506
+    {
1505 1507
         return $this->_treeBuild($this->_docs, $this->getCFGDef('idField', $idField),
1506 1508
             $this->getCFGDef('parentField', $parentField));
1507 1509
     }
@@ -1514,16 +1516,16 @@  discard block
 block discarded – undo
1514 1516
      * @param string $pidName name parent field in associative data array
1515 1517
      * @return array
1516 1518
      */
1517
-    private function _treeBuild($data, $idName, $pidName)
1518
-    {
1519
+    private function _treeBuild($data, $idName, $pidName)
1520
+    {
1519 1521
         $children = array(); // children of each ID
1520 1522
         $ids = array();
1521
-        foreach ($data as $i => $r) {
1523
+        foreach ($data as $i => $r) {
1522 1524
             $row =& $data[$i];
1523 1525
             $id = $row[$idName];
1524 1526
             $pid = $row[$pidName];
1525 1527
             $children[$pid][$id] =& $row;
1526
-            if (!isset($children[$id])) {
1528
+            if (!isset($children[$id])) {
1527 1529
                 $children[$id] = array();
1528 1530
             }
1529 1531
             $row['#childNodes'] =& $children[$id];
@@ -1531,9 +1533,9 @@  discard block
 block discarded – undo
1531 1533
         }
1532 1534
         // Root elements are elements with non-found PIDs.
1533 1535
         $this->_tree = array();
1534
-        foreach ($data as $i => $r) {
1536
+        foreach ($data as $i => $r) {
1535 1537
             $row =& $data[$i];
1536
-            if (!isset($ids[$row[$pidName]])) {
1538
+            if (!isset($ids[$row[$pidName]])) {
1537 1539
                 $this->_tree[$row[$idName]] = $row;
1538 1540
             }
1539 1541
         }
@@ -1547,12 +1549,12 @@  discard block
 block discarded – undo
1547 1549
      * @param bool $full если true то возвращается значение для подстановки в запрос
1548 1550
      * @return string PrimaryKey основной таблицы
1549 1551
      */
1550
-    public function getPK($full = true)
1551
-    {
1552
+    public function getPK($full = true)
1553
+    {
1552 1554
         $idField = isset($this->idField) ? $this->idField: 'id';
1553
-        if ($full) {
1555
+        if ($full) {
1554 1556
             $idField = '`' . $idField . '`';
1555
-            if (!empty($this->alias)) {
1557
+            if (!empty($this->alias)) {
1556 1558
                 $idField = '`' . $this->alias . '`.' . $idField;
1557 1559
             }
1558 1560
         }
@@ -1566,12 +1568,12 @@  discard block
 block discarded – undo
1566 1568
      * @param bool $full если true то возвращается значение для подстановки в запрос
1567 1569
      * @return string Parent Key основной таблицы
1568 1570
      */
1569
-    public function getParentField($full = true)
1570
-    {
1571
+    public function getParentField($full = true)
1572
+    {
1571 1573
         $parentField = isset($this->parentField) ? $this->parentField : '';
1572
-        if ($full && !empty($parentField)) {
1574
+        if ($full && !empty($parentField)) {
1573 1575
             $parentField = '`' . $parentField . '`';
1574
-            if (!empty($this->alias)) {
1576
+            if (!empty($this->alias)) {
1575 1577
                 $parentField = '`' . $this->alias . '`.' . $parentField;
1576 1578
             }
1577 1579
         }
@@ -1586,31 +1588,31 @@  discard block
 block discarded – undo
1586 1588
      * @param string $filter_string строка со всеми фильтрами
1587 1589
      * @return mixed результат разбора фильтров
1588 1590
      */
1589
-    protected function getFilters($filter_string)
1590
-    {
1591
+    protected function getFilters($filter_string)
1592
+    {
1591 1593
         $this->debug->debug("getFilters: " . $this->debug->dumpData($filter_string), 'getFilter', 1);
1592 1594
         // the filter parameter tells us, which filters can be used in this query
1593 1595
         $filter_string = trim($filter_string, ' ;');
1594
-        if (!$filter_string) {
1596
+        if (!$filter_string) {
1595 1597
             return;
1596 1598
         }
1597 1599
         $output = array('join' => '', 'where' => '');
1598 1600
         $logic_op_found = false;
1599 1601
         $joins = $wheres = array();
1600
-        foreach ($this->_logic_ops as $op => $sql) {
1601
-            if (strpos($filter_string, $op) === 0) {
1602
+        foreach ($this->_logic_ops as $op => $sql) {
1603
+            if (strpos($filter_string, $op) === 0) {
1602 1604
                 $logic_op_found = true;
1603 1605
                 $subfilters = mb_substr($filter_string, strlen($op) + 1, mb_strlen($filter_string, "UTF-8"), "UTF-8");
1604 1606
                 $subfilters = $this->smartSplit($subfilters);
1605
-                foreach ($subfilters as $subfilter) {
1607
+                foreach ($subfilters as $subfilter) {
1606 1608
                     $subfilter = $this->getFilters(trim($subfilter));
1607
-                    if (!$subfilter) {
1609
+                    if (!$subfilter) {
1608 1610
                         continue;
1609 1611
                     }
1610
-                    if ($subfilter['join']) {
1612
+                    if ($subfilter['join']) {
1611 1613
                         $joins[] = $subfilter['join'];
1612 1614
                     }
1613
-                    if ($subfilter['where']) {
1615
+                    if ($subfilter['where']) {
1614 1616
                         $wheres[] = $subfilter['where'];
1615 1617
                     }
1616 1618
                 }
@@ -1619,12 +1621,12 @@  discard block
 block discarded – undo
1619 1621
             }
1620 1622
         }
1621 1623
 
1622
-        if (!$logic_op_found) {
1624
+        if (!$logic_op_found) {
1623 1625
             $filter = $this->loadFilter($filter_string);
1624
-            if (!$filter) {
1626
+            if (!$filter) {
1625 1627
                 $this->debug->warning('Error while loading DocLister filter "' . $this->debug->dumpData($filter_string) . '": check syntax!');
1626 1628
                 $output = false;
1627
-            } else {
1629
+            } else {
1628 1630
                 $output['join'] = $filter->get_join();
1629 1631
                 $output['where'] = stripslashes($filter->get_where());
1630 1632
             }
@@ -1637,16 +1639,16 @@  discard block
 block discarded – undo
1637 1639
     /**
1638 1640
      * @return mixed
1639 1641
      */
1640
-    public function filtersWhere()
1641
-    {
1642
+    public function filtersWhere()
1643
+    {
1642 1644
         return APIHelpers::getkey($this->_filters, 'where', '');
1643 1645
     }
1644 1646
 
1645 1647
     /**
1646 1648
      * @return mixed
1647 1649
      */
1648
-    public function filtersJoin()
1649
-    {
1650
+    public function filtersJoin()
1651
+    {
1650 1652
         return APIHelpers::getkey($this->_filters, 'join', '');
1651 1653
     }
1652 1654
 
@@ -1654,11 +1656,12 @@  discard block
 block discarded – undo
1654 1656
      * @param string $join
1655 1657
      * @return $this
1656 1658
      */
1657
-    public function setFiltersJoin($join = '') {
1658
-        if (!empty($join)) {
1659
-            if (!empty($this->_filters['join'])) {
1659
+    public function setFiltersJoin($join = '')
1660
+    {
1661
+        if (!empty($join)) {
1662
+            if (!empty($this->_filters['join'])) {
1660 1663
                 $this->_filters['join'] .= ' ' . $join;
1661
-            } else {
1664
+            } else {
1662 1665
                 $this->_filters['join'] = $join;
1663 1666
             }
1664 1667
         }
@@ -1673,10 +1676,10 @@  discard block
 block discarded – undo
1673 1676
      * @param $type string тип фильтрации
1674 1677
      * @return string имя поля с учетом приведения типа
1675 1678
      */
1676
-    public function changeSortType($field, $type)
1677
-    {
1679
+    public function changeSortType($field, $type)
1680
+    {
1678 1681
         $type = trim($type);
1679
-        switch (strtoupper($type)) {
1682
+        switch (strtoupper($type)) {
1680 1683
             case 'DECIMAL':
1681 1684
                 $field = 'CAST(' . $field . ' as DECIMAL(10,2))';
1682 1685
                 break;
@@ -1702,8 +1705,8 @@  discard block
 block discarded – undo
1702 1705
      * @param string $filter срока с параметрами фильтрации
1703 1706
      * @return bool
1704 1707
      */
1705
-    protected function loadFilter($filter)
1706
-    {
1708
+    protected function loadFilter($filter)
1709
+    {
1707 1710
         $this->debug->debug('Load filter ' . $this->debug->dumpData($filter), 'loadFilter', 2);
1708 1711
         $out = false;
1709 1712
         $fltr_params = explode(':', $filter, 2);
@@ -1713,21 +1716,21 @@  discard block
 block discarded – undo
1713 1716
         */
1714 1717
         $fltr_class = $fltr . '_DL_filter';
1715 1718
         // check if the filter is implemented
1716
-        if (!is_null($fltr)) {
1717
-            if (!class_exists($fltr_class) && file_exists(__DIR__ . '/filter/' . $fltr . '.filter.php')) {
1719
+        if (!is_null($fltr)) {
1720
+            if (!class_exists($fltr_class) && file_exists(__DIR__ . '/filter/' . $fltr . '.filter.php')) {
1718 1721
                 require_once dirname(__FILE__) . '/filter/' . $fltr . '.filter.php';
1719 1722
             }
1720
-            if (class_exists($fltr_class)) {
1723
+            if (class_exists($fltr_class)) {
1721 1724
                 $this->totalFilters++;
1722 1725
                 $fltr_obj = new $fltr_class();
1723
-                if ($fltr_obj->init($this, $filter)) {
1726
+                if ($fltr_obj->init($this, $filter)) {
1724 1727
                     $out = $fltr_obj;
1725
-                } else {
1728
+                } else {
1726 1729
                     $this->debug->error("Wrong filter parameter: '{$this->debug->dumpData($filter)}'", 'Filter');
1727 1730
                 }
1728 1731
             }
1729 1732
         }
1730
-        if (!$out) {
1733
+        if (!$out) {
1731 1734
             $this->debug->error("Error load Filter: '{$this->debug->dumpData($filter)}'", 'Filter');
1732 1735
         }
1733 1736
             
@@ -1740,8 +1743,8 @@  discard block
 block discarded – undo
1740 1743
      * Общее число фильтров
1741 1744
      * @return int
1742 1745
      */
1743
-    public function getCountFilters()
1744
-    {
1746
+    public function getCountFilters()
1747
+    {
1745 1748
         return (int)$this->totalFilters;
1746 1749
     }
1747 1750
 
@@ -1749,8 +1752,8 @@  discard block
 block discarded – undo
1749 1752
      * Выполнить SQL запрос
1750 1753
      * @param string $q SQL запрос
1751 1754
      */
1752
-    public function dbQuery($q)
1753
-    {
1755
+    public function dbQuery($q)
1756
+    {
1754 1757
         $this->debug->debug($q, "query", 1, 'sql');
1755 1758
         $out = $this->modx->db->query($q);
1756 1759
         $this->debug->debugEnd("query");
@@ -1768,8 +1771,8 @@  discard block
 block discarded – undo
1768 1771
      * @param string $tpl шаблон подстановки значения в SQL запрос
1769 1772
      * @return string строка для подстановки в SQL запрос
1770 1773
      */
1771
-    public function LikeEscape($field, $value, $escape = '=', $tpl = '%[+value+]%')
1772
-    {
1774
+    public function LikeEscape($field, $value, $escape = '=', $tpl = '%[+value+]%')
1775
+    {
1773 1776
         return sqlHelper::LikeEscape($this->modx, $field, $value, $escape, $tpl);
1774 1777
     }
1775 1778
 
@@ -1777,8 +1780,8 @@  discard block
 block discarded – undo
1777 1780
      * Получение REQUEST_URI без GET-ключа с
1778 1781
      * @return string
1779 1782
      */
1780
-    public function getRequest()
1781
-    {
1783
+    public function getRequest()
1784
+    {
1782 1785
         $URL = null;
1783 1786
         parse_str(parse_url(MODX_SITE_URL . $_SERVER['REQUEST_URI'], PHP_URL_QUERY), $URL);
1784 1787
 
Please login to merge, or discard this patch.