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