@@ -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,20 +568,22 @@ 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 | |
584 | - if ($out) $this->outData = DLTemplate::getInstance($this->modx)->parseDocumentSource($out); |
|
584 | + if ($out) { |
|
585 | + $this->outData = DLTemplate::getInstance($this->modx)->parseDocumentSource($out); |
|
586 | + } |
|
585 | 587 | $this->debug->debugEnd('render'); |
586 | 588 | |
587 | 589 | return $this->outData; |
@@ -596,8 +598,8 @@ discard block |
||
596 | 598 | * |
597 | 599 | * @return int |
598 | 600 | */ |
599 | - public function getCurrentMODXPageID() |
|
600 | - { |
|
601 | + public function getCurrentMODXPageID() |
|
602 | + { |
|
601 | 603 | $id = isset($this->modx->documentIdentifier) ? (int)$this->modx->documentIdentifier : 0; |
602 | 604 | $docData = isset($this->modx->documentObject) ? $this->modx->documentObject : array(); |
603 | 605 | |
@@ -613,9 +615,9 @@ discard block |
||
613 | 615 | * @param integer $line error on line |
614 | 616 | * @param array $trace stack trace |
615 | 617 | */ |
616 | - public function ErrorLogger($message, $code, $file, $line, $trace) |
|
617 | - { |
|
618 | - if (abs($this->getCFGDef('debug', '0')) == '1') { |
|
618 | + public function ErrorLogger($message, $code, $file, $line, $trace) |
|
619 | + { |
|
620 | + if (abs($this->getCFGDef('debug', '0')) == '1') { |
|
619 | 621 | $out = "CODE #" . $code . "<br />"; |
620 | 622 | $out .= "on file: " . $file . ":" . $line . "<br />"; |
621 | 623 | $out .= "<pre>"; |
@@ -632,8 +634,8 @@ discard block |
||
632 | 634 | * |
633 | 635 | * @return DocumentParser |
634 | 636 | */ |
635 | - public function getMODX() |
|
636 | - { |
|
637 | + public function getMODX() |
|
638 | + { |
|
637 | 639 | return $this->modx; |
638 | 640 | } |
639 | 641 | |
@@ -644,13 +646,13 @@ discard block |
||
644 | 646 | * @return boolean status load extenders |
645 | 647 | * @throws Exception |
646 | 648 | */ |
647 | - public function loadExtender($ext = '') |
|
648 | - { |
|
649 | + public function loadExtender($ext = '') |
|
650 | + { |
|
649 | 651 | $out = true; |
650 | - if ($ext != '') { |
|
652 | + if ($ext != '') { |
|
651 | 653 | $ext = explode(",", $ext); |
652 | - foreach ($ext as $item) { |
|
653 | - if ($item != '' && !$this->_loadExtender($item)) { |
|
654 | + foreach ($ext as $item) { |
|
655 | + if ($item != '' && !$this->_loadExtender($item)) { |
|
654 | 656 | throw new Exception('Error load ' . APIHelpers::e($item) . ' extender'); |
655 | 657 | } |
656 | 658 | } |
@@ -666,8 +668,8 @@ discard block |
||
666 | 668 | * @param mixed $def значение по умолчанию, если в конфиге нет искомого параметра |
667 | 669 | * @return mixed значение из конфига |
668 | 670 | */ |
669 | - public function getCFGDef($name, $def = null) |
|
670 | - { |
|
671 | + public function getCFGDef($name, $def = null) |
|
672 | + { |
|
671 | 673 | return $this->config->getCFGDef($name, $def); |
672 | 674 | } |
673 | 675 | |
@@ -679,15 +681,15 @@ discard block |
||
679 | 681 | * @param string $key ключ локального плейсхолдера |
680 | 682 | * @return string |
681 | 683 | */ |
682 | - public function toPlaceholders($data, $set = 0, $key = 'contentPlaceholder') |
|
683 | - { |
|
684 | + public function toPlaceholders($data, $set = 0, $key = 'contentPlaceholder') |
|
685 | + { |
|
684 | 686 | $this->debug->debug(null, 'toPlaceholders', 2); |
685 | - if ($set == 0) { |
|
687 | + if ($set == 0) { |
|
686 | 688 | $set = $this->getCFGDef('contentPlaceholder', 0); |
687 | 689 | } |
688 | 690 | $this->_plh[$key] = $data; |
689 | 691 | $id = $this->getCFGDef('id', ''); |
690 | - if ($id != '') { |
|
692 | + if ($id != '') { |
|
691 | 693 | $id .= "."; |
692 | 694 | } |
693 | 695 | $out = DLTemplate::getInstance($this->getMODX())->toPlaceholders($data, $set, $key, $id); |
@@ -709,14 +711,14 @@ discard block |
||
709 | 711 | * @param boolean $quote заключать ли данные на выходе в кавычки |
710 | 712 | * @return string обработанная строка |
711 | 713 | */ |
712 | - public function sanitarIn($data, $sep = ',', $quote = true) |
|
713 | - { |
|
714 | - if (!is_array($data)) { |
|
714 | + public function sanitarIn($data, $sep = ',', $quote = true) |
|
715 | + { |
|
716 | + if (!is_array($data)) { |
|
715 | 717 | $data = explode($sep, $data); |
716 | 718 | } |
717 | 719 | $out = array(); |
718 | - foreach ($data as $item) { |
|
719 | - if ($item !== '') { |
|
720 | + foreach ($data as $item) { |
|
721 | + if ($item !== '') { |
|
720 | 722 | $out[] = $this->modx->db->escape($item); |
721 | 723 | } |
722 | 724 | } |
@@ -737,12 +739,12 @@ discard block |
||
737 | 739 | * @param string $lang имя языкового пакета |
738 | 740 | * @return array |
739 | 741 | */ |
740 | - public function getCustomLang($lang = '') |
|
741 | - { |
|
742 | - if (empty($lang)) { |
|
742 | + public function getCustomLang($lang = '') |
|
743 | + { |
|
744 | + if (empty($lang)) { |
|
743 | 745 | $lang = $this->getCFGDef('lang', $this->modx->config['manager_language']); |
744 | 746 | } |
745 | - if (file_exists(dirname(dirname(__FILE__)) . "/lang/" . $lang . ".php")) { |
|
747 | + if (file_exists(dirname(dirname(__FILE__)) . "/lang/" . $lang . ".php")) { |
|
746 | 748 | $tmp = include(dirname(__FILE__) . "/lang/" . $lang . ".php"); |
747 | 749 | $this->_customLang = is_array($tmp) ? $tmp : array(); |
748 | 750 | } |
@@ -758,25 +760,25 @@ discard block |
||
758 | 760 | * @param boolean $rename Переименовывать ли элементы массива |
759 | 761 | * @return array массив с лексиконом |
760 | 762 | */ |
761 | - public function loadLang($name = 'core', $lang = '', $rename = true) |
|
762 | - { |
|
763 | - if (empty($lang)) { |
|
763 | + public function loadLang($name = 'core', $lang = '', $rename = true) |
|
764 | + { |
|
765 | + if (empty($lang)) { |
|
764 | 766 | $lang = $this->getCFGDef('lang', $this->modx->config['manager_language']); |
765 | 767 | } |
766 | 768 | |
767 | 769 | $this->debug->debug('Load language ' . $this->debug->dumpData($name) . "." . $this->debug->dumpData($lang), |
768 | 770 | 'loadlang', 2); |
769 | - if (is_scalar($name)) { |
|
771 | + if (is_scalar($name)) { |
|
770 | 772 | $name = array($name); |
771 | 773 | } |
772 | - foreach ($name as $n) { |
|
773 | - if (file_exists(dirname(__FILE__) . "/lang/" . $lang . "/" . $n . ".inc.php")) { |
|
774 | + foreach ($name as $n) { |
|
775 | + if (file_exists(dirname(__FILE__) . "/lang/" . $lang . "/" . $n . ".inc.php")) { |
|
774 | 776 | $tmp = include(dirname(__FILE__) . "/lang/" . $lang . "/" . $n . ".inc.php"); |
775 | - if (is_array($tmp)) { |
|
777 | + if (is_array($tmp)) { |
|
776 | 778 | /** |
777 | 779 | * Переименовыываем элементы массива из array('test'=>'data') в array('name.test'=>'data') |
778 | 780 | */ |
779 | - if ($rename) { |
|
781 | + if ($rename) { |
|
780 | 782 | $tmp = $this->renameKeyArr($tmp, $n, '', '.'); |
781 | 783 | } |
782 | 784 | $this->_lang = array_merge($this->_lang, $tmp); |
@@ -795,11 +797,11 @@ discard block |
||
795 | 797 | * @param string $def Строка по умолчанию, если запись в языковом пакете не будет обнаружена |
796 | 798 | * @return string строка в соответствии с текущими языковыми настройками |
797 | 799 | */ |
798 | - public function getMsg($name, $def = '') |
|
799 | - { |
|
800 | - if (isset($this->_customLang[$name])) { |
|
800 | + public function getMsg($name, $def = '') |
|
801 | + { |
|
802 | + if (isset($this->_customLang[$name])) { |
|
801 | 803 | $say = $this->_customLang[$name]; |
802 | - } else { |
|
804 | + } else { |
|
803 | 805 | $say = \APIHelpers::getkey($this->_lang, $name, $def); |
804 | 806 | } |
805 | 807 | |
@@ -815,8 +817,8 @@ discard block |
||
815 | 817 | * @param string $sep разделитель суффиксов, префиксов и ключей массива |
816 | 818 | * @return array массив с переименованными ключами |
817 | 819 | */ |
818 | - public function renameKeyArr($data, $prefix = '', $suffix = '', $sep = '.') |
|
819 | - { |
|
820 | + public function renameKeyArr($data, $prefix = '', $suffix = '', $sep = '.') |
|
821 | + { |
|
820 | 822 | return \APIHelpers::renameKeyArr($data, $prefix, $suffix, $sep); |
821 | 823 | } |
822 | 824 | |
@@ -826,12 +828,12 @@ discard block |
||
826 | 828 | * @param string $locale локаль |
827 | 829 | * @return string имя установленной локали |
828 | 830 | */ |
829 | - public function setLocate($locale = '') |
|
830 | - { |
|
831 | - if ('' == $locale) { |
|
831 | + public function setLocate($locale = '') |
|
832 | + { |
|
833 | + if ('' == $locale) { |
|
832 | 834 | $locale = $this->getCFGDef('locale', ''); |
833 | 835 | } |
834 | - if ('' != $locale) { |
|
836 | + if ('' != $locale) { |
|
835 | 837 | setlocale(LC_ALL, $locale); |
836 | 838 | } |
837 | 839 | |
@@ -845,11 +847,11 @@ discard block |
||
845 | 847 | * @param array $data массив сформированный как дерево |
846 | 848 | * @return string строка для отображения пользователю |
847 | 849 | */ |
848 | - protected function renderTree($data) |
|
849 | - { |
|
850 | + protected function renderTree($data) |
|
851 | + { |
|
850 | 852 | $out = ''; |
851 | - if (!empty($data['#childNodes'])) { |
|
852 | - foreach ($data['#childNodes'] as $item) { |
|
853 | + if (!empty($data['#childNodes'])) { |
|
854 | + foreach ($data['#childNodes'] as $item) { |
|
853 | 855 | $out .= $this->renderTree($item); |
854 | 856 | } |
855 | 857 | } |
@@ -866,8 +868,8 @@ discard block |
||
866 | 868 | * @param string $name Template: chunk name || @CODE: template || @FILE: file with template |
867 | 869 | * @return string html template with placeholders without data |
868 | 870 | */ |
869 | - private function _getChunk($name) |
|
870 | - { |
|
871 | + private function _getChunk($name) |
|
872 | + { |
|
871 | 873 | $this->debug->debug(array('Get chunk by name' => $name), "getChunk", 2, array('html')); |
872 | 874 | //without trim |
873 | 875 | $tpl = DLTemplate::getInstance($this->getMODX())->getChunk($name); |
@@ -884,18 +886,18 @@ discard block |
||
884 | 886 | * @param string $tpl HTML шаблон |
885 | 887 | * @return string |
886 | 888 | */ |
887 | - public function parseLang($tpl) |
|
888 | - { |
|
889 | + public function parseLang($tpl) |
|
890 | + { |
|
889 | 891 | $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)) { |
|
892 | + if (is_scalar($tpl) && !empty($tpl)) { |
|
893 | + if (preg_match_all("/\[\%([a-zA-Z0-9\.\_\-]+)\%\]/", $tpl, $match)) { |
|
892 | 894 | $langVal = array(); |
893 | - foreach ($match[1] as $item) { |
|
895 | + foreach ($match[1] as $item) { |
|
894 | 896 | $langVal[] = $this->getMsg($item); |
895 | 897 | } |
896 | 898 | $tpl = str_replace($match[0], $langVal, $tpl); |
897 | 899 | } |
898 | - } else { |
|
900 | + } else { |
|
899 | 901 | $tpl = ''; |
900 | 902 | } |
901 | 903 | $this->debug->debugEnd("parseLang"); |
@@ -911,20 +913,24 @@ discard block |
||
911 | 913 | * @param bool $parseDocumentSource render html template via DocumentParser::parseDocumentSource() |
912 | 914 | * @return string html template with data without placeholders |
913 | 915 | */ |
914 | - public function parseChunk($name, $data, $parseDocumentSource = false) |
|
915 | - { |
|
916 | + public function parseChunk($name, $data, $parseDocumentSource = false) |
|
917 | + { |
|
916 | 918 | $this->debug->debug( |
917 | 919 | array("parseChunk" => $name, "With data" => print_r($data, 1)), |
918 | 920 | "parseChunk", |
919 | 921 | 2, array('html', null) |
920 | 922 | ); |
921 | 923 | $DLTemplate = DLTemplate::getInstance($this->getMODX()); |
922 | - if ($path = $this->getCFGDef('templatePath')) $DLTemplate->setTemplatePath($path); |
|
923 | - if ($ext = $this->getCFGDef('templateExtension')) $DLTemplate->setTemplateExtension($ext); |
|
924 | + if ($path = $this->getCFGDef('templatePath')) { |
|
925 | + $DLTemplate->setTemplatePath($path); |
|
926 | + } |
|
927 | + if ($ext = $this->getCFGDef('templateExtension')) { |
|
928 | + $DLTemplate->setTemplateExtension($ext); |
|
929 | + } |
|
924 | 930 | $DLTemplate->setTwigTemplateVars(array('DocLister'=>$this)); |
925 | 931 | $out = $DLTemplate->parseChunk($name, $data, $parseDocumentSource); |
926 | 932 | $out = $this->parseLang($out); |
927 | - if (empty($out)) { |
|
933 | + if (empty($out)) { |
|
928 | 934 | $this->debug->debug("Empty chunk: " . $this->debug->dumpData($name), '', 2); |
929 | 935 | } |
930 | 936 | $this->debug->debugEnd("parseChunk"); |
@@ -940,8 +946,8 @@ discard block |
||
940 | 946 | * |
941 | 947 | * @return string html template from parameter |
942 | 948 | */ |
943 | - public function getChunkByParam($name, $val = '') |
|
944 | - { |
|
949 | + public function getChunkByParam($name, $val = '') |
|
950 | + { |
|
945 | 951 | $data = $this->getCFGDef($name, $val); |
946 | 952 | $data = $this->_getChunk($data); |
947 | 953 | |
@@ -954,11 +960,11 @@ discard block |
||
954 | 960 | * @param string $data html код который нужно обернуть в ownerTPL |
955 | 961 | * @return string результатирующий html код |
956 | 962 | */ |
957 | - public function renderWrap($data) |
|
958 | - { |
|
963 | + public function renderWrap($data) |
|
964 | + { |
|
959 | 965 | $out = $data; |
960 | 966 | $docs = count($this->_docs) - $this->skippedDocs; |
961 | - if ((($this->getCFGDef("noneWrapOuter", "1") && $docs == 0) || $docs > 0) && !empty($this->ownerTPL)) { |
|
967 | + if ((($this->getCFGDef("noneWrapOuter", "1") && $docs == 0) || $docs > 0) && !empty($this->ownerTPL)) { |
|
962 | 968 | $this->debug->debug("", "renderWrapTPL", 2); |
963 | 969 | $parse = true; |
964 | 970 | $plh = array($this->getCFGDef("sysKey", "dl") . ".wrap" => $data); |
@@ -966,7 +972,7 @@ discard block |
||
966 | 972 | * @var $extPrepare prepare_DL_Extender |
967 | 973 | */ |
968 | 974 | $extPrepare = $this->getExtender('prepare'); |
969 | - if ($extPrepare) { |
|
975 | + if ($extPrepare) { |
|
970 | 976 | $params = $extPrepare->init($this, array( |
971 | 977 | 'data' => array( |
972 | 978 | 'docs' => $this->_docs, |
@@ -975,13 +981,13 @@ discard block |
||
975 | 981 | 'nameParam' => 'prepareWrap', |
976 | 982 | 'return' => 'placeholders' |
977 | 983 | )); |
978 | - if (is_bool($params) && $params === false) { |
|
984 | + if (is_bool($params) && $params === false) { |
|
979 | 985 | $out = $data; |
980 | 986 | $parse = false; |
981 | 987 | } |
982 | 988 | $plh = $params; |
983 | 989 | } |
984 | - if ($parse && !empty($this->ownerTPL)) { |
|
990 | + if ($parse && !empty($this->ownerTPL)) { |
|
985 | 991 | $this->debug->updateMessage( |
986 | 992 | array("render ownerTPL" => $this->ownerTPL, "With data" => print_r($plh, 1)), |
987 | 993 | "renderWrapTPL", |
@@ -989,7 +995,7 @@ discard block |
||
989 | 995 | ); |
990 | 996 | $out = $this->parseChunk($this->ownerTPL, $plh); |
991 | 997 | } |
992 | - if (empty($this->ownerTPL)) { |
|
998 | + if (empty($this->ownerTPL)) { |
|
993 | 999 | $this->debug->updateMessage("empty ownerTPL", "renderWrapTPL"); |
994 | 1000 | } |
995 | 1001 | $this->debug->debugEnd("renderWrapTPL"); |
@@ -1005,8 +1011,8 @@ discard block |
||
1005 | 1011 | * @param int $i номер итерации в цикле |
1006 | 1012 | * @return array массив с данными которые можно использовать в цикле render метода |
1007 | 1013 | */ |
1008 | - protected function uniformPrepare(&$data, $i = 0) |
|
1009 | - { |
|
1014 | + protected function uniformPrepare(&$data, $i = 0) |
|
1015 | + { |
|
1010 | 1016 | $class = array(); |
1011 | 1017 | |
1012 | 1018 | $iterationName = ($i % 2 == 1) ? 'Odd' : 'Even'; |
@@ -1020,20 +1026,20 @@ discard block |
||
1020 | 1026 | "dl") . '.full_iteration'] = ($this->extPaginate) ? ($i + $this->getCFGDef('display', |
1021 | 1027 | 0) * ($this->extPaginate->currentPage() - 1)) : $i; |
1022 | 1028 | |
1023 | - if ($i == 1) { |
|
1029 | + if ($i == 1) { |
|
1024 | 1030 | $this->renderTPL = $this->getCFGDef('tplFirst', $this->renderTPL); |
1025 | 1031 | $class[] = $this->getCFGDef('firstClass', 'first'); |
1026 | 1032 | } |
1027 | - if ($i == (count($this->_docs) - $this->skippedDocs)) { |
|
1033 | + if ($i == (count($this->_docs) - $this->skippedDocs)) { |
|
1028 | 1034 | $this->renderTPL = $this->getCFGDef('tplLast', $this->renderTPL); |
1029 | 1035 | $class[] = $this->getCFGDef('lastClass', 'last'); |
1030 | 1036 | } |
1031 | - if ($this->modx->documentIdentifier == $data['id']) { |
|
1037 | + if ($this->modx->documentIdentifier == $data['id']) { |
|
1032 | 1038 | $this->renderTPL = $this->getCFGDef('tplCurrent', $this->renderTPL); |
1033 | 1039 | $data[$this->getCFGDef("sysKey", |
1034 | 1040 | "dl") . '.active'] = 1; //[+active+] - 1 if $modx->documentIdentifer equal ID this element |
1035 | 1041 | $class[] = $this->getCFGDef('currentClass', 'current'); |
1036 | - } else { |
|
1042 | + } else { |
|
1037 | 1043 | $data[$this->getCFGDef("sysKey", "dl") . '.active'] = 0; |
1038 | 1044 | } |
1039 | 1045 | |
@@ -1044,8 +1050,8 @@ discard block |
||
1044 | 1050 | * @var $extE e_DL_Extender |
1045 | 1051 | */ |
1046 | 1052 | $extE = $this->getExtender('e', true, true); |
1047 | - if ($out = $extE->init($this, compact('data'))) { |
|
1048 | - if (is_array($out)) { |
|
1053 | + if ($out = $extE->init($this, compact('data'))) { |
|
1054 | + if (is_array($out)) { |
|
1049 | 1055 | $data = $out; |
1050 | 1056 | } |
1051 | 1057 | } |
@@ -1061,42 +1067,43 @@ discard block |
||
1061 | 1067 | * @param array $array данные которые необходимо примешать к ответу на каждой записи $data |
1062 | 1068 | * @return string JSON строка |
1063 | 1069 | */ |
1064 | - public function getJSON($data, $fields, $array = array()) |
|
1065 | - { |
|
1070 | + public function getJSON($data, $fields, $array = array()) |
|
1071 | + { |
|
1066 | 1072 | $out = array(); |
1067 | 1073 | $fields = is_array($fields) ? $fields : explode(",", $fields); |
1068 | - if (is_array($array) && count($array) > 0) { |
|
1074 | + if (is_array($array) && count($array) > 0) { |
|
1069 | 1075 | $tmp = array(); |
1070 | - foreach ($data as $i => $v) { //array_merge not valid work with integer index key |
|
1076 | + foreach ($data as $i => $v) { |
|
1077 | +//array_merge not valid work with integer index key |
|
1071 | 1078 | $tmp[$i] = (isset($array[$i]) ? array_merge($v, $array[$i]) : $v); |
1072 | 1079 | } |
1073 | 1080 | $data = $tmp; |
1074 | 1081 | } |
1075 | 1082 | |
1076 | - foreach ($data as $num => $doc) { |
|
1083 | + foreach ($data as $num => $doc) { |
|
1077 | 1084 | $tmp = array(); |
1078 | - foreach ($doc as $name => $value) { |
|
1079 | - if (in_array($name, $fields) || (isset($fields[0]) && $fields[0] == '1')) { |
|
1085 | + foreach ($doc as $name => $value) { |
|
1086 | + if (in_array($name, $fields) || (isset($fields[0]) && $fields[0] == '1')) { |
|
1080 | 1087 | $tmp[str_replace(".", "_", $name)] = $value; //JSON element name without dot |
1081 | 1088 | } |
1082 | 1089 | } |
1083 | 1090 | $out[$num] = $tmp; |
1084 | 1091 | } |
1085 | 1092 | |
1086 | - if ('new' == $this->getCFGDef('JSONformat', 'old')) { |
|
1093 | + if ('new' == $this->getCFGDef('JSONformat', 'old')) { |
|
1087 | 1094 | $return = array(); |
1088 | 1095 | |
1089 | 1096 | $return['rows'] = array(); |
1090 | - foreach ($out as $key => $item) { |
|
1097 | + foreach ($out as $key => $item) { |
|
1091 | 1098 | $return['rows'][] = APIHelpers::getkey($item, $key, $item); |
1092 | 1099 | } |
1093 | 1100 | $return['total'] = $this->getChildrenCount(); |
1094 | - }elseif ('simple' == $this->getCFGDef('JSONformat', 'old')) { |
|
1101 | + } elseif ('simple' == $this->getCFGDef('JSONformat', 'old')) { |
|
1095 | 1102 | $return = array(); |
1096 | - foreach ($out as $key => $item) { |
|
1103 | + foreach ($out as $key => $item) { |
|
1097 | 1104 | $return[] = APIHelpers::getkey($item, $key, $item); |
1098 | 1105 | } |
1099 | - } else { |
|
1106 | + } else { |
|
1100 | 1107 | $return = $out; |
1101 | 1108 | } |
1102 | 1109 | $this->outData = json_encode($return); |
@@ -1112,11 +1119,11 @@ discard block |
||
1112 | 1119 | * @param string $contentField |
1113 | 1120 | * @return mixed|string |
1114 | 1121 | */ |
1115 | - protected function getSummary(array $item = array(), $extSummary = null, $introField = '', $contentField = '') |
|
1116 | - { |
|
1122 | + protected function getSummary(array $item = array(), $extSummary = null, $introField = '', $contentField = '') |
|
1123 | + { |
|
1117 | 1124 | $out = ''; |
1118 | 1125 | |
1119 | - if (is_null($extSummary)) { |
|
1126 | + if (is_null($extSummary)) { |
|
1120 | 1127 | /** |
1121 | 1128 | * @var $extSummary summary_DL_Extender |
1122 | 1129 | */ |
@@ -1125,10 +1132,10 @@ discard block |
||
1125 | 1132 | $introField = $this->getCFGDef("introField", $introField); |
1126 | 1133 | $contentField = $this->getCFGDef("contentField", $contentField); |
1127 | 1134 | |
1128 | - if (!empty($introField) && !empty($item[$introField]) && mb_strlen($item[$introField], 'UTF-8') > 0) { |
|
1135 | + if (!empty($introField) && !empty($item[$introField]) && mb_strlen($item[$introField], 'UTF-8') > 0) { |
|
1129 | 1136 | $out = $item[$introField]; |
1130 | - } else { |
|
1131 | - if (!empty($contentField) && !empty($item[$contentField]) && mb_strlen($item[$contentField], 'UTF-8') > 0) { |
|
1137 | + } else { |
|
1138 | + if (!empty($contentField) && !empty($item[$contentField]) && mb_strlen($item[$contentField], 'UTF-8') > 0) { |
|
1132 | 1139 | $out = $extSummary->init($this, array( |
1133 | 1140 | "content" => $item[$contentField], |
1134 | 1141 | "action" => $this->getCFGDef("summary", ""), |
@@ -1146,8 +1153,8 @@ discard block |
||
1146 | 1153 | * @param string $name extender name |
1147 | 1154 | * @return boolean status extender load |
1148 | 1155 | */ |
1149 | - public function checkExtender($name) |
|
1150 | - { |
|
1156 | + public function checkExtender($name) |
|
1157 | + { |
|
1151 | 1158 | return (isset($this->extender[$name]) && $this->extender[$name] instanceof $name . "_DL_Extender"); |
1152 | 1159 | } |
1153 | 1160 | |
@@ -1155,8 +1162,8 @@ discard block |
||
1155 | 1162 | * @param $name |
1156 | 1163 | * @param $obj |
1157 | 1164 | */ |
1158 | - public function setExtender($name, $obj) |
|
1159 | - { |
|
1165 | + public function setExtender($name, $obj) |
|
1166 | + { |
|
1160 | 1167 | $this->extender[$name] = $obj; |
1161 | 1168 | } |
1162 | 1169 | |
@@ -1168,13 +1175,13 @@ discard block |
||
1168 | 1175 | * @param bool $nop если экстендер не загружен, то загружать ли xNop |
1169 | 1176 | * @return null|xNop |
1170 | 1177 | */ |
1171 | - public function getExtender($name, $autoload = false, $nop = false) |
|
1172 | - { |
|
1178 | + public function getExtender($name, $autoload = false, $nop = false) |
|
1179 | + { |
|
1173 | 1180 | $out = null; |
1174 | - if ((is_scalar($name) && $this->checkExtender($name)) || ($autoload && $this->_loadExtender($name))) { |
|
1181 | + if ((is_scalar($name) && $this->checkExtender($name)) || ($autoload && $this->_loadExtender($name))) { |
|
1175 | 1182 | $out = $this->extender[$name]; |
1176 | 1183 | } |
1177 | - if ($nop && is_null($out)) { |
|
1184 | + if ($nop && is_null($out)) { |
|
1178 | 1185 | $out = new xNop(); |
1179 | 1186 | } |
1180 | 1187 | |
@@ -1187,27 +1194,27 @@ discard block |
||
1187 | 1194 | * @param string $name name extender |
1188 | 1195 | * @return boolean $flag status load extender |
1189 | 1196 | */ |
1190 | - protected function _loadExtender($name) |
|
1191 | - { |
|
1197 | + protected function _loadExtender($name) |
|
1198 | + { |
|
1192 | 1199 | $this->debug->debug('Load Extender ' . $this->debug->dumpData($name), 'LoadExtender', 2); |
1193 | 1200 | $flag = false; |
1194 | 1201 | |
1195 | 1202 | $classname = ($name != '') ? $name . "_DL_Extender" : ""; |
1196 | - if ($classname != '' && isset($this->extender[$name]) && $this->extender[$name] instanceof $classname) { |
|
1203 | + if ($classname != '' && isset($this->extender[$name]) && $this->extender[$name] instanceof $classname) { |
|
1197 | 1204 | $flag = true; |
1198 | 1205 | |
1199 | - } else { |
|
1200 | - if (!class_exists($classname, false) && $classname != '') { |
|
1201 | - if (file_exists(dirname(__FILE__) . "/extender/" . $name . ".extender.inc")) { |
|
1206 | + } else { |
|
1207 | + if (!class_exists($classname, false) && $classname != '') { |
|
1208 | + if (file_exists(dirname(__FILE__) . "/extender/" . $name . ".extender.inc")) { |
|
1202 | 1209 | include_once(dirname(__FILE__) . "/extender/" . $name . ".extender.inc"); |
1203 | 1210 | } |
1204 | 1211 | } |
1205 | - if (class_exists($classname, false) && $classname != '') { |
|
1212 | + if (class_exists($classname, false) && $classname != '') { |
|
1206 | 1213 | $this->extender[$name] = new $classname($this, $name); |
1207 | 1214 | $flag = true; |
1208 | 1215 | } |
1209 | 1216 | } |
1210 | - if (!$flag) { |
|
1217 | + if (!$flag) { |
|
1211 | 1218 | $this->debug->debug("Error load Extender " . $this->debug->dumpData($name)); |
1212 | 1219 | } |
1213 | 1220 | $this->debug->debugEnd('LoadExtender'); |
@@ -1225,16 +1232,16 @@ discard block |
||
1225 | 1232 | * @param mixed $IDs список id документов по которым необходима выборка |
1226 | 1233 | * @return array очищенный массив |
1227 | 1234 | */ |
1228 | - public function setIDs($IDs) |
|
1229 | - { |
|
1235 | + public function setIDs($IDs) |
|
1236 | + { |
|
1230 | 1237 | $this->debug->debug('set ID list ' . $this->debug->dumpData($IDs), 'setIDs', 2); |
1231 | 1238 | $IDs = $this->cleanIDs($IDs); |
1232 | 1239 | $type = $this->getCFGDef('idType', 'parents'); |
1233 | 1240 | $depth = $this->getCFGDef('depth', ''); |
1234 | - if ($type == 'parents' && $depth > 0) { |
|
1241 | + if ($type == 'parents' && $depth > 0) { |
|
1235 | 1242 | $tmp = $IDs; |
1236 | - do { |
|
1237 | - if (count($tmp) > 0) { |
|
1243 | + do { |
|
1244 | + if (count($tmp) > 0) { |
|
1238 | 1245 | $tmp = $this->getChildrenFolder($tmp); |
1239 | 1246 | $IDs = array_merge($IDs, $tmp); |
1240 | 1247 | } |
@@ -1248,8 +1255,8 @@ discard block |
||
1248 | 1255 | /** |
1249 | 1256 | * @return int |
1250 | 1257 | */ |
1251 | - public function getIDs() |
|
1252 | - { |
|
1258 | + public function getIDs() |
|
1259 | + { |
|
1253 | 1260 | return $this->IDs; |
1254 | 1261 | } |
1255 | 1262 | |
@@ -1260,17 +1267,18 @@ discard block |
||
1260 | 1267 | * @param string $sep разделитель |
1261 | 1268 | * @return array очищенный массив с данными |
1262 | 1269 | */ |
1263 | - public function cleanIDs($IDs, $sep = ',') |
|
1264 | - { |
|
1270 | + public function cleanIDs($IDs, $sep = ',') |
|
1271 | + { |
|
1265 | 1272 | $this->debug->debug('clean IDs ' . $this->debug->dumpData($IDs) . ' with separator ' . $this->debug->dumpData($sep), |
1266 | 1273 | 'cleanIDs', 2); |
1267 | 1274 | $out = array(); |
1268 | - if (!is_array($IDs)) { |
|
1275 | + if (!is_array($IDs)) { |
|
1269 | 1276 | $IDs = explode($sep, $IDs); |
1270 | 1277 | } |
1271 | - foreach ($IDs as $item) { |
|
1278 | + foreach ($IDs as $item) { |
|
1272 | 1279 | $item = trim($item); |
1273 | - if (is_numeric($item) && (int)$item >= 0) { //Fix 0xfffffffff |
|
1280 | + if (is_numeric($item) && (int)$item >= 0) { |
|
1281 | +//Fix 0xfffffffff |
|
1274 | 1282 | $out[] = (int)$item; |
1275 | 1283 | } |
1276 | 1284 | } |
@@ -1284,8 +1292,8 @@ discard block |
||
1284 | 1292 | * Проверка массива с id-шниками документов для выборки |
1285 | 1293 | * @return boolean пригодны ли данные для дальнейшего использования |
1286 | 1294 | */ |
1287 | - protected function checkIDs() |
|
1288 | - { |
|
1295 | + protected function checkIDs() |
|
1296 | + { |
|
1289 | 1297 | return (is_array($this->IDs) && count($this->IDs) > 0) ? true : false; |
1290 | 1298 | } |
1291 | 1299 | |
@@ -1297,11 +1305,11 @@ discard block |
||
1297 | 1305 | * @global array $_docs all documents |
1298 | 1306 | * @return array all field values |
1299 | 1307 | */ |
1300 | - public function getOneField($userField, $uniq = false) |
|
1301 | - { |
|
1308 | + public function getOneField($userField, $uniq = false) |
|
1309 | + { |
|
1302 | 1310 | $out = array(); |
1303 | - foreach ($this->_docs as $doc => $val) { |
|
1304 | - if (isset($val[$userField]) && (($uniq && !in_array($val[$userField], $out)) || !$uniq)) { |
|
1311 | + foreach ($this->_docs as $doc => $val) { |
|
1312 | + if (isset($val[$userField]) && (($uniq && !in_array($val[$userField], $out)) || !$uniq)) { |
|
1305 | 1313 | $out[$doc] = $val[$userField]; |
1306 | 1314 | } |
1307 | 1315 | } |
@@ -1312,8 +1320,8 @@ discard block |
||
1312 | 1320 | /** |
1313 | 1321 | * @return DLCollection |
1314 | 1322 | */ |
1315 | - public function docsCollection() |
|
1316 | - { |
|
1323 | + public function docsCollection() |
|
1324 | + { |
|
1317 | 1325 | return new DLCollection($this->modx, $this->_docs); |
1318 | 1326 | } |
1319 | 1327 | |
@@ -1341,10 +1349,10 @@ discard block |
||
1341 | 1349 | * @param string $group |
1342 | 1350 | * @return string |
1343 | 1351 | */ |
1344 | - protected function getGroupSQL($group = '') |
|
1345 | - { |
|
1352 | + protected function getGroupSQL($group = '') |
|
1353 | + { |
|
1346 | 1354 | $out = ''; |
1347 | - if ($group != '') { |
|
1355 | + if ($group != '') { |
|
1348 | 1356 | $out = 'GROUP BY ' . $group; |
1349 | 1357 | } |
1350 | 1358 | |
@@ -1363,12 +1371,12 @@ discard block |
||
1363 | 1371 | * |
1364 | 1372 | * @return string Order by for SQL |
1365 | 1373 | */ |
1366 | - protected function SortOrderSQL($sortName, $orderDef = 'DESC') |
|
1367 | - { |
|
1374 | + protected function SortOrderSQL($sortName, $orderDef = 'DESC') |
|
1375 | + { |
|
1368 | 1376 | $this->debug->debug('', 'sortORDER', 2); |
1369 | 1377 | |
1370 | 1378 | $sort = ''; |
1371 | - switch ($this->getCFGDef('sortType', '')) { |
|
1379 | + switch ($this->getCFGDef('sortType', '')) { |
|
1372 | 1380 | case 'none': |
1373 | 1381 | break; |
1374 | 1382 | case 'doclist': |
@@ -1379,10 +1387,10 @@ discard block |
||
1379 | 1387 | break; |
1380 | 1388 | default: |
1381 | 1389 | $out = array('orderBy' => '', 'order' => '', 'sortBy' => ''); |
1382 | - if (($tmp = $this->getCFGDef('orderBy', '')) != '') { |
|
1390 | + if (($tmp = $this->getCFGDef('orderBy', '')) != '') { |
|
1383 | 1391 | $out['orderBy'] = $tmp; |
1384 | - } else { |
|
1385 | - switch (true) { |
|
1392 | + } else { |
|
1393 | + switch (true) { |
|
1386 | 1394 | case ('' != ($tmp = $this->getCFGDef('sortDir', ''))): //higher priority than order |
1387 | 1395 | $out['order'] = $tmp; |
1388 | 1396 | // no break |
@@ -1390,7 +1398,7 @@ discard block |
||
1390 | 1398 | $out['order'] = $tmp; |
1391 | 1399 | // no break |
1392 | 1400 | } |
1393 | - if ('' == $out['order'] || !in_array(strtoupper($out['order']), array('ASC', 'DESC'))) { |
|
1401 | + if ('' == $out['order'] || !in_array(strtoupper($out['order']), array('ASC', 'DESC'))) { |
|
1394 | 1402 | $out['order'] = $orderDef; //Default |
1395 | 1403 | } |
1396 | 1404 | |
@@ -1411,26 +1419,26 @@ discard block |
||
1411 | 1419 | * |
1412 | 1420 | * @return string LIMIT вставка в SQL запрос |
1413 | 1421 | */ |
1414 | - protected function LimitSQL($limit = 0, $offset = 0) |
|
1415 | - { |
|
1422 | + protected function LimitSQL($limit = 0, $offset = 0) |
|
1423 | + { |
|
1416 | 1424 | $this->debug->debug('', 'limitSQL', 2); |
1417 | 1425 | $ret = ''; |
1418 | - if ($limit == 0) { |
|
1426 | + if ($limit == 0) { |
|
1419 | 1427 | $limit = $this->getCFGDef('display', 0); |
1420 | 1428 | } |
1421 | - if ($offset == 0) { |
|
1429 | + if ($offset == 0) { |
|
1422 | 1430 | $offset = $this->getCFGDef('offset', 0); |
1423 | 1431 | } |
1424 | 1432 | $offset += $this->getCFGDef('start', 0); |
1425 | 1433 | $total = $this->getCFGDef('total', 0); |
1426 | - if ($limit < ($total - $limit)) { |
|
1434 | + if ($limit < ($total - $limit)) { |
|
1427 | 1435 | $limit = $total - $offset; |
1428 | 1436 | } |
1429 | 1437 | |
1430 | - if ($limit != 0) { |
|
1438 | + if ($limit != 0) { |
|
1431 | 1439 | $ret = "LIMIT " . (int)$offset . "," . (int)$limit; |
1432 | - } else { |
|
1433 | - if ($offset != 0) { |
|
1440 | + } else { |
|
1441 | + if ($offset != 0) { |
|
1434 | 1442 | /** |
1435 | 1443 | * To retrieve all rows from a certain offset up to the end of the result set, you can use some large number for the second parameter |
1436 | 1444 | * @see http://dev.mysql.com/doc/refman/5.0/en/select.html |
@@ -1450,8 +1458,8 @@ discard block |
||
1450 | 1458 | * @param string $charset |
1451 | 1459 | * @return string Clear string |
1452 | 1460 | */ |
1453 | - public function sanitarData($data, $charset = 'UTF-8') |
|
1454 | - { |
|
1461 | + public function sanitarData($data, $charset = 'UTF-8') |
|
1462 | + { |
|
1455 | 1463 | return APIHelpers::sanitarTag($data, $charset); |
1456 | 1464 | } |
1457 | 1465 | |
@@ -1462,8 +1470,8 @@ discard block |
||
1462 | 1470 | * @param string $parentField default name parent field |
1463 | 1471 | * @return array |
1464 | 1472 | */ |
1465 | - public function treeBuild($idField = 'id', $parentField = 'parent') |
|
1466 | - { |
|
1473 | + public function treeBuild($idField = 'id', $parentField = 'parent') |
|
1474 | + { |
|
1467 | 1475 | return $this->_treeBuild($this->_docs, $this->getCFGDef('idField', $idField), |
1468 | 1476 | $this->getCFGDef('parentField', $parentField)); |
1469 | 1477 | } |
@@ -1476,16 +1484,16 @@ discard block |
||
1476 | 1484 | * @param string $pidName name parent field in associative data array |
1477 | 1485 | * @return array |
1478 | 1486 | */ |
1479 | - private function _treeBuild($data, $idName, $pidName) |
|
1480 | - { |
|
1487 | + private function _treeBuild($data, $idName, $pidName) |
|
1488 | + { |
|
1481 | 1489 | $children = array(); // children of each ID |
1482 | 1490 | $ids = array(); |
1483 | - foreach ($data as $i => $r) { |
|
1491 | + foreach ($data as $i => $r) { |
|
1484 | 1492 | $row =& $data[$i]; |
1485 | 1493 | $id = $row[$idName]; |
1486 | 1494 | $pid = $row[$pidName]; |
1487 | 1495 | $children[$pid][$id] =& $row; |
1488 | - if (!isset($children[$id])) { |
|
1496 | + if (!isset($children[$id])) { |
|
1489 | 1497 | $children[$id] = array(); |
1490 | 1498 | } |
1491 | 1499 | $row['#childNodes'] =& $children[$id]; |
@@ -1493,9 +1501,9 @@ discard block |
||
1493 | 1501 | } |
1494 | 1502 | // Root elements are elements with non-found PIDs. |
1495 | 1503 | $this->_tree = array(); |
1496 | - foreach ($data as $i => $r) { |
|
1504 | + foreach ($data as $i => $r) { |
|
1497 | 1505 | $row =& $data[$i]; |
1498 | - if (!isset($ids[$row[$pidName]])) { |
|
1506 | + if (!isset($ids[$row[$pidName]])) { |
|
1499 | 1507 | $this->_tree[$row[$idName]] = $row; |
1500 | 1508 | } |
1501 | 1509 | } |
@@ -1509,8 +1517,8 @@ discard block |
||
1509 | 1517 | * |
1510 | 1518 | * @return string PrimaryKey основной таблицы |
1511 | 1519 | */ |
1512 | - public function getPK() |
|
1513 | - { |
|
1520 | + public function getPK() |
|
1521 | + { |
|
1514 | 1522 | return isset($this->idField) ? $this->idField : 'id'; |
1515 | 1523 | } |
1516 | 1524 | |
@@ -1519,8 +1527,8 @@ discard block |
||
1519 | 1527 | * По умолчанию это parent. Переопределить можно в контроллере присвоив другое значение переменной parentField |
1520 | 1528 | * @return string Parent Key основной таблицы |
1521 | 1529 | */ |
1522 | - public function getParentField() |
|
1523 | - { |
|
1530 | + public function getParentField() |
|
1531 | + { |
|
1524 | 1532 | return isset($this->parentField) ? $this->parentField : ''; |
1525 | 1533 | } |
1526 | 1534 | |
@@ -1531,31 +1539,31 @@ discard block |
||
1531 | 1539 | * @param string $filter_string строка со всеми фильтрами |
1532 | 1540 | * @return mixed результат разбора фильтров |
1533 | 1541 | */ |
1534 | - protected function getFilters($filter_string) |
|
1535 | - { |
|
1542 | + protected function getFilters($filter_string) |
|
1543 | + { |
|
1536 | 1544 | $this->debug->debug("getFilters: " . $this->debug->dumpData($filter_string), 'getFilter', 1); |
1537 | 1545 | // the filter parameter tells us, which filters can be used in this query |
1538 | 1546 | $filter_string = trim($filter_string, ' ;'); |
1539 | - if (!$filter_string) { |
|
1547 | + if (!$filter_string) { |
|
1540 | 1548 | return; |
1541 | 1549 | } |
1542 | 1550 | $output = array('join' => '', 'where' => ''); |
1543 | 1551 | $logic_op_found = false; |
1544 | 1552 | $joins = $wheres = array(); |
1545 | - foreach ($this->_logic_ops as $op => $sql) { |
|
1546 | - if (strpos($filter_string, $op) === 0) { |
|
1553 | + foreach ($this->_logic_ops as $op => $sql) { |
|
1554 | + if (strpos($filter_string, $op) === 0) { |
|
1547 | 1555 | $logic_op_found = true; |
1548 | 1556 | $subfilters = mb_substr($filter_string, strlen($op) + 1, mb_strlen($filter_string, "UTF-8"), "UTF-8"); |
1549 | 1557 | $subfilters = $this->smartSplit($subfilters); |
1550 | - foreach ($subfilters as $subfilter) { |
|
1558 | + foreach ($subfilters as $subfilter) { |
|
1551 | 1559 | $subfilter = $this->getFilters(trim($subfilter)); |
1552 | - if (!$subfilter) { |
|
1560 | + if (!$subfilter) { |
|
1553 | 1561 | continue; |
1554 | 1562 | } |
1555 | - if ($subfilter['join']) { |
|
1563 | + if ($subfilter['join']) { |
|
1556 | 1564 | $joins[] = $subfilter['join']; |
1557 | 1565 | } |
1558 | - if ($subfilter['where']) { |
|
1566 | + if ($subfilter['where']) { |
|
1559 | 1567 | $wheres[] = $subfilter['where']; |
1560 | 1568 | } |
1561 | 1569 | } |
@@ -1564,12 +1572,12 @@ discard block |
||
1564 | 1572 | } |
1565 | 1573 | } |
1566 | 1574 | |
1567 | - if (!$logic_op_found) { |
|
1575 | + if (!$logic_op_found) { |
|
1568 | 1576 | $filter = $this->loadFilter($filter_string); |
1569 | - if (!$filter) { |
|
1577 | + if (!$filter) { |
|
1570 | 1578 | $this->debug->warning('Error while loading DocLister filter "' . $this->debug->dumpData($filter_string) . '": check syntax!'); |
1571 | 1579 | $output = false; |
1572 | - } else { |
|
1580 | + } else { |
|
1573 | 1581 | $output['join'] = $filter->get_join(); |
1574 | 1582 | $output['where'] = $filter->get_where(); |
1575 | 1583 | } |
@@ -1582,16 +1590,16 @@ discard block |
||
1582 | 1590 | /** |
1583 | 1591 | * @return mixed |
1584 | 1592 | */ |
1585 | - public function filtersWhere() |
|
1586 | - { |
|
1593 | + public function filtersWhere() |
|
1594 | + { |
|
1587 | 1595 | return APIHelpers::getkey($this->_filters, 'where', ''); |
1588 | 1596 | } |
1589 | 1597 | |
1590 | 1598 | /** |
1591 | 1599 | * @return mixed |
1592 | 1600 | */ |
1593 | - public function filtersJoin() |
|
1594 | - { |
|
1601 | + public function filtersJoin() |
|
1602 | + { |
|
1595 | 1603 | return APIHelpers::getkey($this->_filters, 'join', ''); |
1596 | 1604 | } |
1597 | 1605 | |
@@ -1602,10 +1610,10 @@ discard block |
||
1602 | 1610 | * @param $type string тип фильтрации |
1603 | 1611 | * @return string имя поля с учетом приведения типа |
1604 | 1612 | */ |
1605 | - public function changeSortType($field, $type) |
|
1606 | - { |
|
1613 | + public function changeSortType($field, $type) |
|
1614 | + { |
|
1607 | 1615 | $type = trim($type); |
1608 | - switch (strtoupper($type)) { |
|
1616 | + switch (strtoupper($type)) { |
|
1609 | 1617 | case 'DECIMAL': |
1610 | 1618 | $field = 'CAST(' . $field . ' as DECIMAL(10,2))'; |
1611 | 1619 | break; |
@@ -1631,14 +1639,14 @@ discard block |
||
1631 | 1639 | * @param string $filter срока с параметрами фильтрации |
1632 | 1640 | * @return bool |
1633 | 1641 | */ |
1634 | - protected function loadFilter($filter) |
|
1635 | - { |
|
1642 | + protected function loadFilter($filter) |
|
1643 | + { |
|
1636 | 1644 | $this->debug->debug('Load filter ' . $this->debug->dumpData($filter), 'loadFilter', 2); |
1637 | 1645 | $out = false; |
1638 | 1646 | $fltr_params = explode(':', $filter, 2); |
1639 | 1647 | $fltr = APIHelpers::getkey($fltr_params, 0, null); |
1640 | 1648 | // check if the filter is implemented |
1641 | - if (!is_null($fltr) && file_exists(dirname(__FILE__) . '/filter/' . $fltr . '.filter.php')) { |
|
1649 | + if (!is_null($fltr) && file_exists(dirname(__FILE__) . '/filter/' . $fltr . '.filter.php')) { |
|
1642 | 1650 | require_once dirname(__FILE__) . '/filter/' . $fltr . '.filter.php'; |
1643 | 1651 | /** |
1644 | 1652 | * @var tv_DL_filter|content_DL_filter $fltr_class |
@@ -1646,12 +1654,12 @@ discard block |
||
1646 | 1654 | $fltr_class = $fltr . '_DL_filter'; |
1647 | 1655 | $this->totalFilters++; |
1648 | 1656 | $fltr_obj = new $fltr_class(); |
1649 | - if ($fltr_obj->init($this, $filter)) { |
|
1657 | + if ($fltr_obj->init($this, $filter)) { |
|
1650 | 1658 | $out = $fltr_obj; |
1651 | - } else { |
|
1659 | + } else { |
|
1652 | 1660 | $this->debug->error("Wrong filter parameter: '{$this->debug->dumpData($filter)}'", 'Filter'); |
1653 | 1661 | } |
1654 | - } else { |
|
1662 | + } else { |
|
1655 | 1663 | $this->debug->error("Error load Filter: '{$this->debug->dumpData($filter)}'", 'Filter'); |
1656 | 1664 | } |
1657 | 1665 | $this->debug->debugEnd("loadFilter"); |
@@ -1663,8 +1671,8 @@ discard block |
||
1663 | 1671 | * Общее число фильтров |
1664 | 1672 | * @return int |
1665 | 1673 | */ |
1666 | - public function getCountFilters() |
|
1667 | - { |
|
1674 | + public function getCountFilters() |
|
1675 | + { |
|
1668 | 1676 | return (int)$this->totalFilters; |
1669 | 1677 | } |
1670 | 1678 | |
@@ -1672,8 +1680,8 @@ discard block |
||
1672 | 1680 | * Выполнить SQL запрос |
1673 | 1681 | * @param string $q SQL запрос |
1674 | 1682 | */ |
1675 | - public function dbQuery($q) |
|
1676 | - { |
|
1683 | + public function dbQuery($q) |
|
1684 | + { |
|
1677 | 1685 | $this->debug->debug($q, "query", 1, 'sql'); |
1678 | 1686 | $out = $this->modx->db->query($q); |
1679 | 1687 | $this->debug->debugEnd("query"); |
@@ -1691,8 +1699,8 @@ discard block |
||
1691 | 1699 | * @param string $tpl шаблон подстановки значения в SQL запрос |
1692 | 1700 | * @return string строка для подстановки в SQL запрос |
1693 | 1701 | */ |
1694 | - public function LikeEscape($field, $value, $escape = '=', $tpl = '%[+value+]%') |
|
1695 | - { |
|
1702 | + public function LikeEscape($field, $value, $escape = '=', $tpl = '%[+value+]%') |
|
1703 | + { |
|
1696 | 1704 | return sqlHelper::LikeEscape($this->modx, $field, $value, $escape, $tpl); |
1697 | 1705 | } |
1698 | 1706 | |
@@ -1700,8 +1708,8 @@ discard block |
||
1700 | 1708 | * Получение REQUEST_URI без GET-ключа с |
1701 | 1709 | * @return string |
1702 | 1710 | */ |
1703 | - public function getRequest() |
|
1704 | - { |
|
1711 | + public function getRequest() |
|
1712 | + { |
|
1705 | 1713 | $URL = null; |
1706 | 1714 | parse_str(parse_url(MODX_SITE_URL . $_SERVER['REQUEST_URI'], PHP_URL_QUERY), $URL); |
1707 | 1715 |
@@ -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 | |
@@ -11,8 +11,8 @@ discard block |
||
11 | 11 | * @license GNU General Public License (GPL), http://www.gnu.org/copyleft/gpl.html |
12 | 12 | * @author Agel_Nash <[email protected]>, kabachello <[email protected]> |
13 | 13 | */ |
14 | -class site_contentDocLister extends DocLister |
|
15 | -{ |
|
14 | +class site_contentDocLister extends DocLister |
|
15 | +{ |
|
16 | 16 | /** |
17 | 17 | * Экземпляр экстендера TV |
18 | 18 | * |
@@ -32,8 +32,8 @@ discard block |
||
32 | 32 | * @param array $cfg |
33 | 33 | * @param null $startTime |
34 | 34 | */ |
35 | - public function __construct($modx, $cfg = array(), $startTime = null) |
|
36 | - { |
|
35 | + public function __construct($modx, $cfg = array(), $startTime = null) |
|
36 | + { |
|
37 | 37 | parent::__construct($modx, $cfg, $startTime); |
38 | 38 | $this->extTV = $this->getExtender('tv', true, true); |
39 | 39 | } |
@@ -41,35 +41,35 @@ discard block |
||
41 | 41 | /** |
42 | 42 | * @absctract |
43 | 43 | */ |
44 | - public function getDocs($tvlist = '') |
|
45 | - { |
|
46 | - if ($tvlist == '') { |
|
44 | + public function getDocs($tvlist = '') |
|
45 | + { |
|
46 | + if ($tvlist == '') { |
|
47 | 47 | $tvlist = $this->getCFGDef('tvList', ''); |
48 | 48 | } |
49 | 49 | |
50 | 50 | $this->extTV->getAllTV_Name(); |
51 | 51 | |
52 | - if ($this->extPaginate = $this->getExtender('paginate')) { |
|
52 | + if ($this->extPaginate = $this->getExtender('paginate')) { |
|
53 | 53 | $this->extPaginate->init($this); |
54 | - } else { |
|
54 | + } else { |
|
55 | 55 | $this->config->setConfig(array('start' => 0)); |
56 | 56 | } |
57 | 57 | $type = $this->getCFGDef('idType', 'parents'); |
58 | 58 | $this->_docs = ($type == 'parents') ? $this->getChildrenList() : $this->getDocList(); |
59 | - if ($tvlist != '' && count($this->_docs) > 0) { |
|
59 | + if ($tvlist != '' && count($this->_docs) > 0) { |
|
60 | 60 | $tv = $this->extTV->getTVList(array_keys($this->_docs), $tvlist); |
61 | - if (!is_array($tv)) { |
|
61 | + if (!is_array($tv)) { |
|
62 | 62 | $tv = array(); |
63 | 63 | } |
64 | - foreach ($tv as $docID => $TVitem) { |
|
65 | - if (isset($this->_docs[$docID]) && is_array($this->_docs[$docID])) { |
|
64 | + foreach ($tv as $docID => $TVitem) { |
|
65 | + if (isset($this->_docs[$docID]) && is_array($this->_docs[$docID])) { |
|
66 | 66 | $this->_docs[$docID] = array_merge($this->_docs[$docID], $TVitem); |
67 | - } else { |
|
67 | + } else { |
|
68 | 68 | unset($this->_docs[$docID]); |
69 | 69 | } |
70 | 70 | } |
71 | 71 | } |
72 | - if (1 == $this->getCFGDef('tree', '0')) { |
|
72 | + if (1 == $this->getCFGDef('tree', '0')) { |
|
73 | 73 | $this->treeBuild('id', 'parent'); |
74 | 74 | } |
75 | 75 | |
@@ -80,24 +80,24 @@ discard block |
||
80 | 80 | * @param string $tpl |
81 | 81 | * @return string |
82 | 82 | */ |
83 | - public function _render($tpl = '') |
|
84 | - { |
|
83 | + public function _render($tpl = '') |
|
84 | + { |
|
85 | 85 | $out = ''; |
86 | - if ($tpl == '') { |
|
86 | + if ($tpl == '') { |
|
87 | 87 | $tpl = $this->getCFGDef('tpl', '@CODE:<a href="[+url+]">[+pagetitle+]</a><br />'); |
88 | 88 | } |
89 | - if ($tpl != '') { |
|
89 | + if ($tpl != '') { |
|
90 | 90 | $date = $this->getCFGDef('dateSource', 'pub_date'); |
91 | 91 | |
92 | 92 | $this->toPlaceholders(count($this->_docs), 1, "display"); // [+display+] - сколько показано на странице. |
93 | 93 | |
94 | 94 | $i = 1; |
95 | 95 | $sysPlh = $this->renameKeyArr($this->_plh, $this->getCFGDef("sysKey", "dl")); |
96 | - if (count($this->_docs) > 0) { |
|
96 | + if (count($this->_docs) > 0) { |
|
97 | 97 | /** |
98 | 98 | * @var $extUser user_DL_Extender |
99 | 99 | */ |
100 | - if ($extUser = $this->getExtender('user')) { |
|
100 | + if ($extUser = $this->getExtender('user')) { |
|
101 | 101 | $extUser->init($this, array('fields' => $this->getCFGDef("userFields", ""))); |
102 | 102 | } |
103 | 103 | |
@@ -116,20 +116,20 @@ discard block |
||
116 | 116 | */ |
117 | 117 | $extJotCount = $this->getCFGdef('jotcount', 0) ? $this->getExtender('jotcount', true) : null; |
118 | 118 | |
119 | - if ($extJotCount) { |
|
119 | + if ($extJotCount) { |
|
120 | 120 | $comments = $extJotCount->countComments(array_keys($this->_docs)); |
121 | 121 | } |
122 | 122 | |
123 | 123 | $this->skippedDocs = 0; |
124 | - foreach ($this->_docs as $item) { |
|
124 | + foreach ($this->_docs as $item) { |
|
125 | 125 | $this->renderTPL = $tpl; |
126 | - if ($extUser) { |
|
126 | + if ($extUser) { |
|
127 | 127 | $item = $extUser->setUserData($item); //[+user.id.createdby+], [+user.fullname.publishedby+], [+dl.user.publishedby+].... |
128 | 128 | } |
129 | 129 | |
130 | 130 | $item['summary'] = $extSummary ? $this->getSummary($item, $extSummary, 'introtext', 'content') : ''; |
131 | 131 | |
132 | - if ($extJotCount) { |
|
132 | + if ($extJotCount) { |
|
133 | 133 | $item['jotcount'] = APIHelpers::getkey($comments, $item['id'], 0); |
134 | 134 | } |
135 | 135 | |
@@ -139,20 +139,20 @@ discard block |
||
139 | 139 | |
140 | 140 | $item['title'] = ($item['menutitle'] == '' ? $item['pagetitle'] : $item['menutitle']); |
141 | 141 | |
142 | - if ($this->getCFGDef('makeUrl', 1)) { |
|
143 | - if ($item['type'] == 'reference') { |
|
142 | + if ($this->getCFGDef('makeUrl', 1)) { |
|
143 | + if ($item['type'] == 'reference') { |
|
144 | 144 | $item['url'] = is_numeric($item['content']) ? $this->modx->makeUrl($item['content'], '', '', |
145 | 145 | $this->getCFGDef('urlScheme', '')) : $item['content']; |
146 | - } else { |
|
146 | + } else { |
|
147 | 147 | $item['url'] = $this->modx->makeUrl($item['id'], '', '', $this->getCFGDef('urlScheme', '')); |
148 | 148 | } |
149 | 149 | } |
150 | 150 | |
151 | - if (isset($item[$date])) { |
|
151 | + if (isset($item[$date])) { |
|
152 | 152 | $_date = is_numeric($item[$date]) && $item[$date] == (int)$item[$date] ? $item[$date] : strtotime($item[$date]); |
153 | - if ($_date !== false) { |
|
153 | + if ($_date !== false) { |
|
154 | 154 | $_date = $_date + $this->modx->config['server_offset_time']; |
155 | - if ($this->getCFGDef('dateFormat', '%d.%b.%y %H:%M') != '') { |
|
155 | + if ($this->getCFGDef('dateFormat', '%d.%b.%y %H:%M') != '') { |
|
156 | 156 | $item['date'] = strftime($this->getCFGDef('dateFormat', '%d.%b.%y %H:%M'), $_date); |
157 | 157 | } |
158 | 158 | } |
@@ -161,30 +161,30 @@ discard block |
||
161 | 161 | $findTpl = $this->renderTPL; |
162 | 162 | $tmp = $this->uniformPrepare($item, $i); |
163 | 163 | extract($tmp, EXTR_SKIP); |
164 | - if ($this->renderTPL == '') { |
|
164 | + if ($this->renderTPL == '') { |
|
165 | 165 | $this->renderTPL = $findTpl; |
166 | 166 | } |
167 | 167 | |
168 | - if ($extPrepare) { |
|
168 | + if ($extPrepare) { |
|
169 | 169 | $item = $extPrepare->init($this, array( |
170 | 170 | 'data' => $item, |
171 | 171 | 'nameParam' => 'prepare' |
172 | 172 | )); |
173 | - if (is_bool($item) && $item === false) { |
|
173 | + if (is_bool($item) && $item === false) { |
|
174 | 174 | $this->skippedDocs++; |
175 | 175 | continue; |
176 | 176 | } |
177 | 177 | } |
178 | 178 | $tmp = $this->parseChunk($this->renderTPL, $item); |
179 | 179 | |
180 | - if ($this->getCFGDef('contentPlaceholder', 0) !== 0) { |
|
180 | + if ($this->getCFGDef('contentPlaceholder', 0) !== 0) { |
|
181 | 181 | $this->toPlaceholders($tmp, 1, |
182 | 182 | "item[" . $i . "]"); // [+item[x]+] – individual placeholder for each iteration documents on this page |
183 | 183 | } |
184 | 184 | $out .= $tmp; |
185 | 185 | $i++; |
186 | 186 | } |
187 | - } else { |
|
187 | + } else { |
|
188 | 188 | $noneTPL = $this->getCFGDef("noneTPL", ""); |
189 | 189 | $out = ($noneTPL != '') ? $this->parseChunk($noneTPL, $sysPlh) : ''; |
190 | 190 | } |
@@ -200,8 +200,8 @@ discard block |
||
200 | 200 | * @param array $array |
201 | 201 | * @return string |
202 | 202 | */ |
203 | - public function getJSON($data, $fields, $array = array()) |
|
204 | - { |
|
203 | + public function getJSON($data, $fields, $array = array()) |
|
204 | + { |
|
205 | 205 | $out = array(); |
206 | 206 | $fields = is_array($fields) ? $fields : explode(",", $fields); |
207 | 207 | $date = $this->getCFGDef('dateSource', 'pub_date'); |
@@ -221,44 +221,44 @@ discard block |
||
221 | 221 | */ |
222 | 222 | $extE = $this->getExtender('e', true, true); |
223 | 223 | |
224 | - foreach ($data as $num => $item) { |
|
224 | + foreach ($data as $num => $item) { |
|
225 | 225 | $row = $item; |
226 | - if ((array('1') == $fields || in_array('summary', $fields)) && $extSummary) { |
|
226 | + if ((array('1') == $fields || in_array('summary', $fields)) && $extSummary) { |
|
227 | 227 | $row['summary'] = $this->getSummary($this->_docs[$num], $extSummary, 'introtext', 'content'); |
228 | 228 | } |
229 | - if (array('1') == $fields || in_array('date', $fields)) { |
|
230 | - if (isset($this->_docs[$num][$date])) { |
|
229 | + if (array('1') == $fields || in_array('date', $fields)) { |
|
230 | + if (isset($this->_docs[$num][$date])) { |
|
231 | 231 | $_date = is_numeric($this->_docs[$num][$date]) && $this->_docs[$num][$date] == (int)$this->_docs[$num][$date] ? $this->_docs[$num][$date] : strtotime($this->_docs[$num][$date]); |
232 | - if ($_date !== false) { |
|
232 | + if ($_date !== false) { |
|
233 | 233 | $_date = $_date + $this->modx->config['server_offset_time']; |
234 | - if ($this->getCFGDef('dateFormat', '%d.%b.%y %H:%M') != '') { |
|
234 | + if ($this->getCFGDef('dateFormat', '%d.%b.%y %H:%M') != '') { |
|
235 | 235 | $row['date'] = strftime($this->getCFGDef('dateFormat', '%d.%b.%y %H:%M'), $_date); |
236 | 236 | } |
237 | 237 | } |
238 | 238 | } |
239 | 239 | } |
240 | - if (array('1') == $fields || in_array(array('menutitle', 'pagetitle'), $fields)) { |
|
240 | + if (array('1') == $fields || in_array(array('menutitle', 'pagetitle'), $fields)) { |
|
241 | 241 | $row['title'] = ($row['menutitle'] == '' ? $row['pagetitle'] : $row['menutitle']); |
242 | 242 | } |
243 | 243 | if ((bool)$this->getCFGDef('makeUrl', 1) && (array('1') == $fields || in_array(array('content', 'type'), |
244 | 244 | $fields)) |
245 | - ) { |
|
246 | - if ($row['type'] == 'reference') { |
|
245 | + ) { |
|
246 | + if ($row['type'] == 'reference') { |
|
247 | 247 | $row['url'] = is_numeric($row['content']) ? $this->modx->makeUrl($row['content'], '', '', |
248 | 248 | $this->getCFGDef('urlScheme', '')) : $row['content']; |
249 | - } else { |
|
249 | + } else { |
|
250 | 250 | $row['url'] = $this->modx->makeUrl($row['id'], '', '', $this->getCFGDef('urlScheme', '')); |
251 | 251 | } |
252 | 252 | } |
253 | - if ($extE && $tmp = $extE->init($this, array('data' => $row))) { |
|
254 | - if (is_array($tmp)) { |
|
253 | + if ($extE && $tmp = $extE->init($this, array('data' => $row))) { |
|
254 | + if (is_array($tmp)) { |
|
255 | 255 | $row = $tmp; |
256 | 256 | } |
257 | 257 | } |
258 | 258 | |
259 | - if ($extPrepare) { |
|
259 | + if ($extPrepare) { |
|
260 | 260 | $row = $extPrepare->init($this, array('data' => $row)); |
261 | - if (is_bool($row) && $row === false) { |
|
261 | + if (is_bool($row) && $row === false) { |
|
262 | 262 | continue; |
263 | 263 | } |
264 | 264 | } |
@@ -271,36 +271,35 @@ discard block |
||
271 | 271 | /** |
272 | 272 | * @abstract |
273 | 273 | */ |
274 | - public function getChildrenCount() |
|
275 | - { |
|
274 | + public function getChildrenCount() |
|
275 | + { |
|
276 | 276 | $out = 0; |
277 | 277 | $sanitarInIDs = $this->sanitarIn($this->IDs); |
278 | - if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
|
278 | + if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
|
279 | 279 | $q_true = $this->getCFGDef('ignoreEmpty', '0'); |
280 | 280 | $q_true = $q_true ? $q_true : $this->getCFGDef('idType', 'parents') == 'parents'; |
281 | 281 | $where = $this->getCFGDef('addWhereList', ''); |
282 | 282 | $where = sqlHelper::trimLogicalOp($where); |
283 | 283 | $where = ($where ? $where . ' AND ' : '') . $this->_filters['where']; |
284 | - if ($where != '' && $this->_filters['where'] != '') { |
|
284 | + if ($where != '' && $this->_filters['where'] != '') { |
|
285 | 285 | $where .= " AND "; |
286 | 286 | } |
287 | 287 | $where = sqlHelper::trimLogicalOp($where); |
288 | 288 | |
289 | 289 | $where = "WHERE {$where}"; |
290 | 290 | $whereArr = array(); |
291 | - if (!$this->getCFGDef('showNoPublish', 0)) { |
|
291 | + if (!$this->getCFGDef('showNoPublish', 0)) { |
|
292 | 292 | $whereArr[] = "c.deleted=0 AND c.published=1"; |
293 | - } |
|
294 | - else{ |
|
293 | + } else { |
|
295 | 294 | $q_true = 1; |
296 | 295 | } |
297 | 296 | |
298 | 297 | $tbl_site_content = $this->getTable('site_content', 'c'); |
299 | 298 | |
300 | - if ($sanitarInIDs != "''") { |
|
301 | - switch ($this->getCFGDef('idType', 'parents')) { |
|
299 | + if ($sanitarInIDs != "''") { |
|
300 | + switch ($this->getCFGDef('idType', 'parents')) { |
|
302 | 301 | case 'parents': |
303 | - switch ($this->getCFGDef('showParent', '0')) { |
|
302 | + switch ($this->getCFGDef('showParent', '0')) { |
|
304 | 303 | case '-1': |
305 | 304 | $tmpWhere = "c.parent IN (" . $sanitarInIDs . ")"; |
306 | 305 | break; |
@@ -312,10 +311,10 @@ discard block |
||
312 | 311 | $tmpWhere = "(c.parent IN ({$sanitarInIDs}) OR c.id IN({$sanitarInIDs}))"; |
313 | 312 | break; |
314 | 313 | } |
315 | - if (($addDocs = $this->getCFGDef('documents', '')) != '') { |
|
314 | + if (($addDocs = $this->getCFGDef('documents', '')) != '') { |
|
316 | 315 | $addDocs = $this->sanitarIn($this->cleanIDs($addDocs)); |
317 | 316 | $whereArr[] = "((" . $tmpWhere . ") OR c.id IN({$addDocs}))"; |
318 | - } else { |
|
317 | + } else { |
|
319 | 318 | $whereArr[] = $tmpWhere; |
320 | 319 | } |
321 | 320 | |
@@ -330,14 +329,14 @@ discard block |
||
330 | 329 | |
331 | 330 | $q_true = $q_true ? $q_true : trim($where) != 'WHERE'; |
332 | 331 | |
333 | - if (trim($where) != 'WHERE') { |
|
332 | + if (trim($where) != 'WHERE') { |
|
334 | 333 | $where .= " AND "; |
335 | 334 | } |
336 | 335 | |
337 | 336 | $where .= implode(" AND ", $whereArr); |
338 | 337 | $where = sqlHelper::trimLogicalOp($where); |
339 | 338 | |
340 | - if (trim($where) == 'WHERE') { |
|
339 | + if (trim($where) == 'WHERE') { |
|
341 | 340 | $where = ''; |
342 | 341 | } |
343 | 342 | $group = $this->getGroupSQL($this->getCFGDef('groupBy', 'c.id')); |
@@ -346,11 +345,10 @@ discard block |
||
346 | 345 | |
347 | 346 | $q_true = $q_true ? $q_true : $group != 'GROUP BY c.id'; |
348 | 347 | |
349 | - if ( $q_true ){ |
|
348 | + if ( $q_true ) { |
|
350 | 349 | $rs = $this->dbQuery("SELECT count(*) FROM (SELECT count(*) FROM {$from} {$where} {$group}) as `tmp`"); |
351 | 350 | $out = $this->modx->db->getValue($rs); |
352 | - } |
|
353 | - else { |
|
351 | + } else { |
|
354 | 352 | $out = count($this->IDs); |
355 | 353 | } |
356 | 354 | } |
@@ -361,11 +359,11 @@ discard block |
||
361 | 359 | /** |
362 | 360 | * @return array |
363 | 361 | */ |
364 | - protected function getDocList() |
|
365 | - { |
|
362 | + protected function getDocList() |
|
363 | + { |
|
366 | 364 | $out = array(); |
367 | 365 | $sanitarInIDs = $this->sanitarIn($this->IDs); |
368 | - if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
|
366 | + if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
|
369 | 367 | $where = $this->getCFGDef('addWhereList', ''); |
370 | 368 | $where = sqlHelper::trimLogicalOp($where); |
371 | 369 | |
@@ -373,21 +371,21 @@ discard block |
||
373 | 371 | $where = sqlHelper::trimLogicalOp($where); |
374 | 372 | |
375 | 373 | $tbl_site_content = $this->getTable('site_content', 'c'); |
376 | - if ($sanitarInIDs != "''") { |
|
374 | + if ($sanitarInIDs != "''") { |
|
377 | 375 | $where .= ($where ? " AND " : "") . "c.id IN ({$sanitarInIDs}) AND"; |
378 | 376 | } |
379 | 377 | $where = sqlHelper::trimLogicalOp($where); |
380 | 378 | |
381 | - if ($this->getCFGDef('showNoPublish', 0)) { |
|
382 | - if ($where != '') { |
|
379 | + if ($this->getCFGDef('showNoPublish', 0)) { |
|
380 | + if ($where != '') { |
|
383 | 381 | $where = "WHERE {$where}"; |
384 | - } else { |
|
382 | + } else { |
|
385 | 383 | $where = ''; |
386 | 384 | } |
387 | - } else { |
|
388 | - if ($where != '') { |
|
385 | + } else { |
|
386 | + if ($where != '') { |
|
389 | 387 | $where = "WHERE {$where} AND "; |
390 | - } else { |
|
388 | + } else { |
|
391 | 389 | $where = "WHERE {$where} "; |
392 | 390 | } |
393 | 391 | $where .= "c.deleted=0 AND c.published=1"; |
@@ -406,7 +404,7 @@ discard block |
||
406 | 404 | |
407 | 405 | $rows = $this->modx->db->makeArray($rs); |
408 | 406 | |
409 | - foreach ($rows as $item) { |
|
407 | + foreach ($rows as $item) { |
|
410 | 408 | $out[$item['id']] = $item; |
411 | 409 | } |
412 | 410 | } |
@@ -418,19 +416,19 @@ discard block |
||
418 | 416 | * @param string $id |
419 | 417 | * @return array |
420 | 418 | */ |
421 | - public function getChildrenFolder($id) |
|
422 | - { |
|
419 | + public function getChildrenFolder($id) |
|
420 | + { |
|
423 | 421 | $where = $this->getCFGDef('addWhereFolder', ''); |
424 | 422 | $where = sqlHelper::trimLogicalOp($where); |
425 | - if ($where != '') { |
|
423 | + if ($where != '') { |
|
426 | 424 | $where .= " AND "; |
427 | 425 | } |
428 | 426 | |
429 | 427 | $tbl_site_content = $this->getTable('site_content', 'c'); |
430 | 428 | $sanitarInIDs = $this->sanitarIn($id); |
431 | - if ($this->getCFGDef('showNoPublish', 0)) { |
|
429 | + if ($this->getCFGDef('showNoPublish', 0)) { |
|
432 | 430 | $where = "WHERE {$where} c.parent IN ({$sanitarInIDs}) AND c.isfolder=1"; |
433 | - } else { |
|
431 | + } else { |
|
434 | 432 | $where = "WHERE {$where} c.parent IN ({$sanitarInIDs}) AND c.deleted=0 AND c.published=1 AND c.isfolder=1"; |
435 | 433 | } |
436 | 434 | |
@@ -438,7 +436,7 @@ discard block |
||
438 | 436 | |
439 | 437 | $rows = $this->modx->db->makeArray($rs); |
440 | 438 | $out = array(); |
441 | - foreach ($rows as $item) { |
|
439 | + foreach ($rows as $item) { |
|
442 | 440 | $out[] = $item['id']; |
443 | 441 | } |
444 | 442 | |
@@ -450,10 +448,10 @@ discard block |
||
450 | 448 | * @param $sort |
451 | 449 | * @return array |
452 | 450 | */ |
453 | - protected function injectSortByTV($table, $sort) |
|
454 | - { |
|
451 | + protected function injectSortByTV($table, $sort) |
|
452 | + { |
|
455 | 453 | $out = $this->getExtender('tv', true, true)->injectSortByTV($table, $sort); |
456 | - if (!is_array($out) || empty($out)) { |
|
454 | + if (!is_array($out) || empty($out)) { |
|
457 | 455 | $out = array($table, $sort); |
458 | 456 | } |
459 | 457 | |
@@ -463,19 +461,19 @@ discard block |
||
463 | 461 | /** |
464 | 462 | * @return array |
465 | 463 | */ |
466 | - protected function getChildrenList() |
|
467 | - { |
|
464 | + protected function getChildrenList() |
|
465 | + { |
|
468 | 466 | $where = array(); |
469 | 467 | $out = array(); |
470 | 468 | |
471 | 469 | $tmpWhere = $this->getCFGDef('addWhereList', ''); |
472 | 470 | $tmpWhere = sqlHelper::trimLogicalOp($tmpWhere); |
473 | - if (!empty($tmpWhere)) { |
|
471 | + if (!empty($tmpWhere)) { |
|
474 | 472 | $where[] = $tmpWhere; |
475 | 473 | } |
476 | 474 | |
477 | 475 | $tmpWhere = sqlHelper::trimLogicalOp($this->_filters['where']); |
478 | - if (!empty($tmpWhere)) { |
|
476 | + if (!empty($tmpWhere)) { |
|
479 | 477 | $where[] = $tmpWhere; |
480 | 478 | } |
481 | 479 | |
@@ -486,8 +484,8 @@ discard block |
||
486 | 484 | $sanitarInIDs = $this->sanitarIn($this->IDs); |
487 | 485 | |
488 | 486 | $tmpWhere = null; |
489 | - if ($sanitarInIDs != "''") { |
|
490 | - switch ($this->getCFGDef('showParent', '0')) { |
|
487 | + if ($sanitarInIDs != "''") { |
|
488 | + switch ($this->getCFGDef('showParent', '0')) { |
|
491 | 489 | case '-1': |
492 | 490 | $tmpWhere = "c.parent IN (" . $sanitarInIDs . ")"; |
493 | 491 | break; |
@@ -500,29 +498,29 @@ discard block |
||
500 | 498 | break; |
501 | 499 | } |
502 | 500 | } |
503 | - if (($addDocs = $this->getCFGDef('documents', '')) != '') { |
|
501 | + if (($addDocs = $this->getCFGDef('documents', '')) != '') { |
|
504 | 502 | $addDocs = $this->sanitarIn($this->cleanIDs($addDocs)); |
505 | - if (empty($tmpWhere)) { |
|
503 | + if (empty($tmpWhere)) { |
|
506 | 504 | $tmpWhere = "c.id IN({$addDocs})"; |
507 | - } else { |
|
505 | + } else { |
|
508 | 506 | $tmpWhere = "((" . $tmpWhere . ") OR c.id IN({$addDocs}))"; |
509 | 507 | } |
510 | 508 | } |
511 | - if (!empty($tmpWhere)) { |
|
509 | + if (!empty($tmpWhere)) { |
|
512 | 510 | $where[] = $tmpWhere; |
513 | 511 | } |
514 | - if (!$this->getCFGDef('showNoPublish', 0)) { |
|
512 | + if (!$this->getCFGDef('showNoPublish', 0)) { |
|
515 | 513 | $where[] = "c.deleted=0 AND c.published=1"; |
516 | 514 | } |
517 | - if (!empty($where)) { |
|
515 | + if (!empty($where)) { |
|
518 | 516 | $where = "WHERE " . implode(" AND ", $where); |
519 | - } else { |
|
517 | + } else { |
|
520 | 518 | $where = ''; |
521 | 519 | } |
522 | 520 | $fields = $this->getCFGDef('selectFields', 'c.*'); |
523 | 521 | $group = $this->getGroupSQL($this->getCFGDef('groupBy', 'c.id')); |
524 | 522 | |
525 | - if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
|
523 | + if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
|
526 | 524 | $sql = $this->dbQuery("SELECT {$fields} FROM " . $from . " " . $where . " " . |
527 | 525 | $group . " " . |
528 | 526 | $sort . " " . |
@@ -531,7 +529,7 @@ discard block |
||
531 | 529 | |
532 | 530 | $rows = $this->modx->db->makeArray($sql); |
533 | 531 | |
534 | - foreach ($rows as $item) { |
|
532 | + foreach ($rows as $item) { |
|
535 | 533 | $out[$item['id']] = $item; |
536 | 534 | } |
537 | 535 | } |
@@ -544,10 +542,10 @@ discard block |
||
544 | 542 | * @param string $type |
545 | 543 | * @return string |
546 | 544 | */ |
547 | - public function changeSortType($field, $type) |
|
548 | - { |
|
545 | + public function changeSortType($field, $type) |
|
546 | + { |
|
549 | 547 | $type = trim($type); |
550 | - switch (strtoupper($type)) { |
|
548 | + switch (strtoupper($type)) { |
|
551 | 549 | case 'TVDATETIME': |
552 | 550 | $field = "STR_TO_DATE(" . $field . ",'%d-%m-%Y %H:%i:%s')"; |
553 | 551 | break; |
@@ -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 | |
@@ -16,16 +16,16 @@ discard block |
||
16 | 16 | /** |
17 | 17 | * Class shopkeeperDocLister |
18 | 18 | */ |
19 | -class shopkeeperDocLister extends site_contentDocLister |
|
20 | -{ |
|
19 | +class shopkeeperDocLister extends site_contentDocLister |
|
20 | +{ |
|
21 | 21 | /** |
22 | 22 | * shopkeeperDocLister constructor. |
23 | 23 | * @param $modx |
24 | 24 | * @param array $cfg |
25 | 25 | * @param null $startTime |
26 | 26 | */ |
27 | - public function __construct($modx, $cfg = array(), $startTime = null) |
|
28 | - { |
|
27 | + public function __construct($modx, $cfg = array(), $startTime = null) |
|
28 | + { |
|
29 | 29 | $cfg = array_merge(array('tvValuesTable' => 'catalog_tmplvar_contentvalues'), $cfg); |
30 | 30 | parent::__construct($modx, $cfg, $startTime); |
31 | 31 | } |
@@ -34,22 +34,22 @@ discard block |
||
34 | 34 | * @param string $tpl |
35 | 35 | * @return string |
36 | 36 | */ |
37 | - public function _render($tpl = '') |
|
38 | - { |
|
37 | + public function _render($tpl = '') |
|
38 | + { |
|
39 | 39 | $out = ''; |
40 | - if ($tpl == '') { |
|
40 | + if ($tpl == '') { |
|
41 | 41 | $tpl = $this->getCFGDef('tpl', '@CODE:<a href="[+url+]">[+pagetitle+]</a><br />'); |
42 | 42 | } |
43 | - if ($tpl != '') { |
|
43 | + if ($tpl != '') { |
|
44 | 44 | $this->toPlaceholders(count($this->_docs), 1, "display"); // [+display+] - сколько показано на странице. |
45 | 45 | |
46 | 46 | $i = 1; |
47 | 47 | $sysPlh = $this->renameKeyArr($this->_plh, $this->getCFGDef("sysKey", "dl")); |
48 | - if (count($this->_docs) > 0) { |
|
48 | + if (count($this->_docs) > 0) { |
|
49 | 49 | /** |
50 | 50 | * @var $extUser user_DL_Extender |
51 | 51 | */ |
52 | - if ($extUser = $this->getExtender('user')) { |
|
52 | + if ($extUser = $this->getExtender('user')) { |
|
53 | 53 | $extUser->init($this, array('fields' => $this->getCFGDef("userFields", ""))); |
54 | 54 | } |
55 | 55 | |
@@ -68,20 +68,20 @@ discard block |
||
68 | 68 | */ |
69 | 69 | $extJotCount = $this->getCFGdef('jotcount', 0) ? $this->getExtender('jotcount', true) : null; |
70 | 70 | |
71 | - if ($extJotCount) { |
|
71 | + if ($extJotCount) { |
|
72 | 72 | $comments = $extJotCount->countComments(array_keys($this->_docs)); |
73 | 73 | } |
74 | 74 | |
75 | 75 | $this->skippedDocs = 0; |
76 | - foreach ($this->_docs as $item) { |
|
76 | + foreach ($this->_docs as $item) { |
|
77 | 77 | $this->renderTPL = $tpl; |
78 | - if ($extUser) { |
|
78 | + if ($extUser) { |
|
79 | 79 | $item = $extUser->setUserData($item); //[+user.id.createdby+], [+user.fullname.publishedby+], [+dl.user.publishedby+].... |
80 | 80 | } |
81 | 81 | |
82 | 82 | $item['summary'] = $extSummary ? $this->getSummary($item, $extSummary, '', 'content') : ''; |
83 | 83 | |
84 | - if ($extJotCount) { |
|
84 | + if ($extJotCount) { |
|
85 | 85 | $item['jotcount'] = APIHelpers::getkey($comments, $item['id'], 0); |
86 | 86 | } |
87 | 87 | |
@@ -89,47 +89,47 @@ discard block |
||
89 | 89 | $sysPlh); //inside the chunks available all placeholders set via $modx->toPlaceholders with prefix id, and with prefix sysKey |
90 | 90 | $item['iteration'] = $i; //[+iteration+] - Number element. Starting from zero |
91 | 91 | |
92 | - if ($this->getCFGDef('makeUrl', 1)) { |
|
93 | - if ($item['type'] == 'reference') { |
|
92 | + if ($this->getCFGDef('makeUrl', 1)) { |
|
93 | + if ($item['type'] == 'reference') { |
|
94 | 94 | $item['url'] = is_numeric($item['content']) ? $this->modx->makeUrl($item['content'], '', '', |
95 | 95 | $this->getCFGDef('urlScheme', '')) : $item['content']; |
96 | - } else { |
|
96 | + } else { |
|
97 | 97 | $item['url'] = $this->modx->makeUrl($item['id'], '', '', $this->getCFGDef('urlScheme', '')); |
98 | 98 | } |
99 | 99 | } |
100 | 100 | |
101 | 101 | $item['date'] = $item['createdon'] + $this->modx->config['server_offset_time']; |
102 | - if ($this->getCFGDef('dateFormat', '%d.%b.%y %H:%M') != '') { |
|
102 | + if ($this->getCFGDef('dateFormat', '%d.%b.%y %H:%M') != '') { |
|
103 | 103 | $item['date'] = strftime($this->getCFGDef('dateFormat', '%d.%b.%y %H:%M'), $item['date']); |
104 | 104 | } |
105 | 105 | |
106 | 106 | $findTpl = $this->renderTPL; |
107 | 107 | $tmp = $this->uniformPrepare($item, $i); |
108 | 108 | extract($tmp, EXTR_SKIP); |
109 | - if ($this->renderTPL == '') { |
|
109 | + if ($this->renderTPL == '') { |
|
110 | 110 | $this->renderTPL = $findTpl; |
111 | 111 | } |
112 | 112 | |
113 | - if ($extPrepare) { |
|
113 | + if ($extPrepare) { |
|
114 | 114 | $item = $extPrepare->init($this, array( |
115 | 115 | 'data' => $item, |
116 | 116 | 'nameParam' => 'prepare' |
117 | 117 | )); |
118 | - if (is_bool($item) && $item === false) { |
|
118 | + if (is_bool($item) && $item === false) { |
|
119 | 119 | $this->skippedDocs++; |
120 | 120 | continue; |
121 | 121 | } |
122 | 122 | } |
123 | 123 | $tmp = $this->parseChunk($this->renderTPL, $item); |
124 | 124 | |
125 | - if ($this->getCFGDef('contentPlaceholder', 0) !== 0) { |
|
125 | + if ($this->getCFGDef('contentPlaceholder', 0) !== 0) { |
|
126 | 126 | $this->toPlaceholders($tmp, 1, |
127 | 127 | "item[" . $i . "]"); // [+item[x]+] – individual placeholder for each iteration documents on this page |
128 | 128 | } |
129 | 129 | $out .= $tmp; |
130 | 130 | $i++; |
131 | 131 | } |
132 | - } else { |
|
132 | + } else { |
|
133 | 133 | $noneTPL = $this->getCFGDef("noneTPL", ""); |
134 | 134 | $out = ($noneTPL != '') ? $this->parseChunk($noneTPL, $sysPlh) : ''; |
135 | 135 | } |
@@ -142,31 +142,31 @@ discard block |
||
142 | 142 | /** |
143 | 143 | * @absctract |
144 | 144 | */ |
145 | - public function getChildrenCount() |
|
146 | - { |
|
145 | + public function getChildrenCount() |
|
146 | + { |
|
147 | 147 | $out = 0; |
148 | 148 | $sanitarInIDs = $this->sanitarIn($this->IDs); |
149 | - if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
|
149 | + if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
|
150 | 150 | $where = $this->getCFGDef('addWhereList', ''); |
151 | 151 | $where = sqlHelper::trimLogicalOp($where); |
152 | 152 | $where = ($where ? $where . ' AND ' : '') . $this->_filters['where']; |
153 | - if ($where != '' && $this->_filters['where'] != '') { |
|
153 | + if ($where != '' && $this->_filters['where'] != '') { |
|
154 | 154 | $where .= " AND "; |
155 | 155 | } |
156 | 156 | $where = sqlHelper::trimLogicalOp($where); |
157 | 157 | |
158 | 158 | $where = "WHERE {$where}"; |
159 | 159 | $whereArr = array(); |
160 | - if (!$this->getCFGDef('showNoPublish', 0)) { |
|
160 | + if (!$this->getCFGDef('showNoPublish', 0)) { |
|
161 | 161 | $whereArr[] = "c.published=1"; |
162 | 162 | } |
163 | 163 | |
164 | 164 | $tbl_site_content = $this->getTable('catalog', 'c'); |
165 | 165 | |
166 | - if ($sanitarInIDs != "''") { |
|
167 | - switch ($this->getCFGDef('idType', 'parents')) { |
|
166 | + if ($sanitarInIDs != "''") { |
|
167 | + switch ($this->getCFGDef('idType', 'parents')) { |
|
168 | 168 | case 'parents': |
169 | - switch ($this->getCFGDef('showParent', '0')) { |
|
169 | + switch ($this->getCFGDef('showParent', '0')) { |
|
170 | 170 | case '-1': |
171 | 171 | $tmpWhere = "c.parent IN (" . $sanitarInIDs . ")"; |
172 | 172 | break; |
@@ -178,10 +178,10 @@ discard block |
||
178 | 178 | $tmpWhere = "(c.parent IN ({$sanitarInIDs}) OR c.id IN({$sanitarInIDs}))"; |
179 | 179 | break; |
180 | 180 | } |
181 | - if (($addDocs = $this->getCFGDef('documents', '')) != '') { |
|
181 | + if (($addDocs = $this->getCFGDef('documents', '')) != '') { |
|
182 | 182 | $addDocs = $this->sanitarIn($this->cleanIDs($addDocs)); |
183 | 183 | $whereArr[] = "((" . $tmpWhere . ") OR c.id IN({$addDocs}))"; |
184 | - } else { |
|
184 | + } else { |
|
185 | 185 | $whereArr[] = $tmpWhere; |
186 | 186 | } |
187 | 187 | break; |
@@ -193,14 +193,14 @@ discard block |
||
193 | 193 | $from = $tbl_site_content . " " . $this->_filters['join']; |
194 | 194 | $where = sqlHelper::trimLogicalOp($where); |
195 | 195 | |
196 | - if (trim($where) != 'WHERE') { |
|
196 | + if (trim($where) != 'WHERE') { |
|
197 | 197 | $where .= " AND "; |
198 | 198 | } |
199 | 199 | |
200 | 200 | $where .= implode(" AND ", $whereArr); |
201 | 201 | $where = sqlHelper::trimLogicalOp($where); |
202 | 202 | |
203 | - if (trim($where) == 'WHERE') { |
|
203 | + if (trim($where) == 'WHERE') { |
|
204 | 204 | $where = ''; |
205 | 205 | } |
206 | 206 | $group = $this->getGroupSQL($this->getCFGDef('groupBy', 'c.id')); |
@@ -217,11 +217,11 @@ discard block |
||
217 | 217 | /** |
218 | 218 | * @return array |
219 | 219 | */ |
220 | - protected function getDocList() |
|
221 | - { |
|
220 | + protected function getDocList() |
|
221 | + { |
|
222 | 222 | $out = array(); |
223 | 223 | $sanitarInIDs = $this->sanitarIn($this->IDs); |
224 | - if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
|
224 | + if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
|
225 | 225 | $where = $this->getCFGDef('addWhereList', ''); |
226 | 226 | $where = sqlHelper::trimLogicalOp($where); |
227 | 227 | |
@@ -229,21 +229,21 @@ discard block |
||
229 | 229 | $where = sqlHelper::trimLogicalOp($where); |
230 | 230 | |
231 | 231 | $tbl_site_content = $this->getTable('catalog', 'c'); |
232 | - if ($sanitarInIDs != "''") { |
|
232 | + if ($sanitarInIDs != "''") { |
|
233 | 233 | $where .= ($where ? " AND " : "") . "c.id IN ({$sanitarInIDs}) AND"; |
234 | 234 | } |
235 | 235 | $where = sqlHelper::trimLogicalOp($where); |
236 | 236 | |
237 | - if ($this->getCFGDef('showNoPublish', 0)) { |
|
238 | - if ($where != '') { |
|
237 | + if ($this->getCFGDef('showNoPublish', 0)) { |
|
238 | + if ($where != '') { |
|
239 | 239 | $where = "WHERE {$where}"; |
240 | - } else { |
|
240 | + } else { |
|
241 | 241 | $where = ''; |
242 | 242 | } |
243 | - } else { |
|
244 | - if ($where != '') { |
|
243 | + } else { |
|
244 | + if ($where != '') { |
|
245 | 245 | $where = "WHERE {$where} AND "; |
246 | - } else { |
|
246 | + } else { |
|
247 | 247 | $where = "WHERE {$where} "; |
248 | 248 | } |
249 | 249 | $where .= "c.published=1"; |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | |
263 | 263 | $rows = $this->modx->db->makeArray($rs); |
264 | 264 | |
265 | - foreach ($rows as $item) { |
|
265 | + foreach ($rows as $item) { |
|
266 | 266 | $out[$item['id']] = $item; |
267 | 267 | } |
268 | 268 | } |
@@ -274,19 +274,19 @@ discard block |
||
274 | 274 | * @param $id |
275 | 275 | * @return array |
276 | 276 | */ |
277 | - public function getChildrenFolder($id) |
|
278 | - { |
|
277 | + public function getChildrenFolder($id) |
|
278 | + { |
|
279 | 279 | $where = $this->getCFGDef('addWhereFolder', ''); |
280 | 280 | $where = sqlHelper::trimLogicalOp($where); |
281 | - if ($where != '') { |
|
281 | + if ($where != '') { |
|
282 | 282 | $where .= " AND "; |
283 | 283 | } |
284 | 284 | |
285 | 285 | $tbl_site_content = $this->getTable('site_content', 'c'); |
286 | 286 | $sanitarInIDs = $this->sanitarIn($id); |
287 | - if ($this->getCFGDef('showNoPublish', 0)) { |
|
287 | + if ($this->getCFGDef('showNoPublish', 0)) { |
|
288 | 288 | $where = "WHERE {$where} c.parent IN ({$sanitarInIDs}"; |
289 | - } else { |
|
289 | + } else { |
|
290 | 290 | $where = "WHERE {$where} c.parent IN ({$sanitarInIDs}) AND c.deleted=0 AND c.published=1"; |
291 | 291 | } |
292 | 292 | |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | |
296 | 296 | $rows = $this->modx->db->makeArray($rs); |
297 | 297 | $out = array(); |
298 | - foreach ($rows as $item) { |
|
298 | + foreach ($rows as $item) { |
|
299 | 299 | $out[] = $item['id']; |
300 | 300 | } |
301 | 301 | |
@@ -305,19 +305,19 @@ discard block |
||
305 | 305 | /** |
306 | 306 | * @return array |
307 | 307 | */ |
308 | - protected function getChildrenList() |
|
309 | - { |
|
308 | + protected function getChildrenList() |
|
309 | + { |
|
310 | 310 | $where = array(); |
311 | 311 | $out = array(); |
312 | 312 | |
313 | 313 | $tmpWhere = $this->getCFGDef('addWhereList', ''); |
314 | 314 | $tmpWhere = sqlHelper::trimLogicalOp($tmpWhere); |
315 | - if (!empty($tmpWhere)) { |
|
315 | + if (!empty($tmpWhere)) { |
|
316 | 316 | $where[] = $tmpWhere; |
317 | 317 | } |
318 | 318 | |
319 | 319 | $tmpWhere = sqlHelper::trimLogicalOp($this->_filters['where']); |
320 | - if (!empty($tmpWhere)) { |
|
320 | + if (!empty($tmpWhere)) { |
|
321 | 321 | $where[] = $tmpWhere; |
322 | 322 | } |
323 | 323 | |
@@ -329,8 +329,8 @@ discard block |
||
329 | 329 | |
330 | 330 | $tmpWhere = null; |
331 | 331 | |
332 | - if ($sanitarInIDs != "''") { |
|
333 | - switch ($this->getCFGDef('showParent', '0')) { |
|
332 | + if ($sanitarInIDs != "''") { |
|
333 | + switch ($this->getCFGDef('showParent', '0')) { |
|
334 | 334 | case '-1': |
335 | 335 | $tmpWhere = "c.parent IN (" . $sanitarInIDs . ")"; |
336 | 336 | break; |
@@ -343,28 +343,28 @@ discard block |
||
343 | 343 | break; |
344 | 344 | } |
345 | 345 | } |
346 | - if (($addDocs = $this->getCFGDef('documents', '')) != '') { |
|
346 | + if (($addDocs = $this->getCFGDef('documents', '')) != '') { |
|
347 | 347 | $addDocs = $this->sanitarIn($this->cleanIDs($addDocs)); |
348 | - if (empty($tmpWhere)) { |
|
348 | + if (empty($tmpWhere)) { |
|
349 | 349 | $tmpWhere = "c.id IN({$addDocs})"; |
350 | - } else { |
|
350 | + } else { |
|
351 | 351 | $tmpWhere = "((" . $tmpWhere . ") OR c.id IN({$addDocs}))"; |
352 | 352 | } |
353 | 353 | } |
354 | - if (!empty($tmpWhere)) { |
|
354 | + if (!empty($tmpWhere)) { |
|
355 | 355 | $where[] = $tmpWhere; |
356 | 356 | } |
357 | - if (!$this->getCFGDef('showNoPublish', 0)) { |
|
357 | + if (!$this->getCFGDef('showNoPublish', 0)) { |
|
358 | 358 | $where[] = "c.published=1"; |
359 | 359 | } |
360 | - if (!empty($where)) { |
|
360 | + if (!empty($where)) { |
|
361 | 361 | $where = "WHERE " . implode(" AND ", $where); |
362 | - } else { |
|
362 | + } else { |
|
363 | 363 | $where = ''; |
364 | 364 | } |
365 | 365 | $fields = $this->getCFGDef('selectFields', 'c.*'); |
366 | 366 | $group = $this->getGroupSQL($this->getCFGDef('groupBy', 'c.id')); |
367 | - if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
|
367 | + if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
|
368 | 368 | $sql = $this->dbQuery("SELECT {$fields} FROM " . $from . " " . $where . " " . |
369 | 369 | $group . " " . |
370 | 370 | $sort . " " . |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | ); |
373 | 373 | |
374 | 374 | $rows = $this->modx->db->makeArray($sql); |
375 | - foreach ($rows as $item) { |
|
375 | + foreach ($rows as $item) { |
|
376 | 376 | $out[$item['id']] = $item; |
377 | 377 | } |
378 | 378 | } |
@@ -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 | |
@@ -14,8 +14,8 @@ discard block |
||
14 | 14 | * @param contentField =`description` //content |
15 | 15 | * @param table =`` //table name |
16 | 16 | */ |
17 | -class onetableDocLister extends DocLister |
|
18 | -{ |
|
17 | +class onetableDocLister extends DocLister |
|
18 | +{ |
|
19 | 19 | /** |
20 | 20 | * @var string |
21 | 21 | */ |
@@ -34,11 +34,11 @@ discard block |
||
34 | 34 | /** |
35 | 35 | * @absctract |
36 | 36 | */ |
37 | - public function getDocs($tvlist = '') |
|
38 | - { |
|
39 | - if ($this->checkExtender('paginate')) { |
|
37 | + public function getDocs($tvlist = '') |
|
38 | + { |
|
39 | + if ($this->checkExtender('paginate')) { |
|
40 | 40 | $this->extender['paginate']->init($this); |
41 | - } else { |
|
41 | + } else { |
|
42 | 42 | $this->config->setConfig(array('start' => 0)); |
43 | 43 | } |
44 | 44 | $type = $this->getCFGDef('idType', 'parents'); |
@@ -51,25 +51,25 @@ discard block |
||
51 | 51 | * @param string $tpl |
52 | 52 | * @return string |
53 | 53 | */ |
54 | - public function _render($tpl = '') |
|
55 | - { |
|
54 | + public function _render($tpl = '') |
|
55 | + { |
|
56 | 56 | $out = ''; |
57 | - if ($tpl == '') { |
|
57 | + if ($tpl == '') { |
|
58 | 58 | $tpl = $this->getCFGDef('tpl', ''); |
59 | 59 | } |
60 | - if ($tpl != '') { |
|
60 | + if ($tpl != '') { |
|
61 | 61 | $this->toPlaceholders(count($this->_docs), 1, "display"); // [+display+] - сколько показано на странице. |
62 | 62 | |
63 | 63 | $i = 1; |
64 | 64 | $sysPlh = $this->renameKeyArr($this->_plh, $this->getCFGDef("sysKey", "dl")); |
65 | 65 | $noneTPL = $this->getCFGDef("noneTPL", ""); |
66 | - if (count($this->_docs) == 0 && $noneTPL != '') { |
|
66 | + if (count($this->_docs) == 0 && $noneTPL != '') { |
|
67 | 67 | $out = $this->parseChunk($noneTPL, $sysPlh); |
68 | - } else { |
|
68 | + } else { |
|
69 | 69 | /** |
70 | 70 | * @var $extUser user_DL_Extender |
71 | 71 | */ |
72 | - if ($extUser = $this->getExtender('user')) { |
|
72 | + if ($extUser = $this->getExtender('user')) { |
|
73 | 73 | $extUser->init($this, array('fields' => $this->getCFGDef("userFields", ""))); |
74 | 74 | } |
75 | 75 | |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | */ |
84 | 84 | $extPrepare = $this->getExtender('prepare'); |
85 | 85 | $this->skippedDocs = 0; |
86 | - foreach ($this->_docs as $item) { |
|
86 | + foreach ($this->_docs as $item) { |
|
87 | 87 | $this->renderTPL = $tpl; |
88 | - if ($extUser) { |
|
88 | + if ($extUser) { |
|
89 | 89 | $item = $extUser->setUserData($item); //[+user.id.createdby+], [+user.fullname.publishedby+], [+dl.user.publishedby+].... |
90 | 90 | } |
91 | 91 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | |
100 | 100 | $date = $this->getCFGDef('dateSource', 'pub_date'); |
101 | 101 | $date = isset($item[$date]) ? $item[$date] + $this->modx->config['server_offset_time'] : ''; |
102 | - if ($date != '' && $this->getCFGDef('dateFormat', '%d.%b.%y %H:%M') != '') { |
|
102 | + if ($date != '' && $this->getCFGDef('dateFormat', '%d.%b.%y %H:%M') != '') { |
|
103 | 103 | $item[$this->getCFGDef("sysKey", "dl") . '.date'] = strftime($this->getCFGDef('dateFormat', |
104 | 104 | '%d.%b.%y %H:%M'), $date); |
105 | 105 | } |
@@ -107,22 +107,22 @@ discard block |
||
107 | 107 | $findTpl = $this->renderTPL; |
108 | 108 | $tmp = $this->uniformPrepare($item, $i); |
109 | 109 | extract($tmp, EXTR_SKIP); |
110 | - if ($this->renderTPL == '') { |
|
110 | + if ($this->renderTPL == '') { |
|
111 | 111 | $this->renderTPL = $findTpl; |
112 | 112 | } |
113 | 113 | |
114 | - if ($extPrepare) { |
|
114 | + if ($extPrepare) { |
|
115 | 115 | $item = $extPrepare->init($this, array( |
116 | 116 | 'data' => $item, |
117 | 117 | 'nameParam' => 'prepare' |
118 | 118 | )); |
119 | - if (is_bool($item) && $item === false) { |
|
119 | + if (is_bool($item) && $item === false) { |
|
120 | 120 | $this->skippedDocs++; |
121 | 121 | continue; |
122 | 122 | } |
123 | 123 | } |
124 | 124 | $tmp = $this->parseChunk($this->renderTPL, $item); |
125 | - if ($this->getCFGDef('contentPlaceholder', 0) !== 0) { |
|
125 | + if ($this->getCFGDef('contentPlaceholder', 0) !== 0) { |
|
126 | 126 | $this->toPlaceholders($tmp, 1, |
127 | 127 | "item[" . $i . "]"); // [+item[x]+] – individual placeholder for each iteration documents on this page |
128 | 128 | } |
@@ -142,8 +142,8 @@ discard block |
||
142 | 142 | * @param array $array |
143 | 143 | * @return string |
144 | 144 | */ |
145 | - public function getJSON($data, $fields, $array = array()) |
|
146 | - { |
|
145 | + public function getJSON($data, $fields, $array = array()) |
|
146 | + { |
|
147 | 147 | $out = array(); |
148 | 148 | $fields = is_array($fields) ? $fields : explode(",", $fields); |
149 | 149 | $date = $this->getCFGDef('dateSource', 'pub_date'); |
@@ -163,10 +163,10 @@ discard block |
||
163 | 163 | */ |
164 | 164 | $extE = $this->getExtender('e', true, true); |
165 | 165 | |
166 | - foreach ($data as $num => $item) { |
|
166 | + foreach ($data as $num => $item) { |
|
167 | 167 | $row = $item; |
168 | 168 | |
169 | - switch (true) { |
|
169 | + switch (true) { |
|
170 | 170 | case ((array('1') == $fields || in_array('summary', $fields)) && $extSummary): |
171 | 171 | $row['summary'] = $this->getSummary($this->_docs[$num], $extSummary, 'introtext'); |
172 | 172 | //without break |
@@ -177,15 +177,15 @@ discard block |
||
177 | 177 | // no break |
178 | 178 | } |
179 | 179 | |
180 | - if ($extE && $tmp = $extE->init($this, array('data' => $row))) { |
|
181 | - if (is_array($tmp)) { |
|
180 | + if ($extE && $tmp = $extE->init($this, array('data' => $row))) { |
|
181 | + if (is_array($tmp)) { |
|
182 | 182 | $row = $tmp; |
183 | 183 | } |
184 | 184 | } |
185 | 185 | |
186 | - if ($extPrepare) { |
|
186 | + if ($extPrepare) { |
|
187 | 187 | $row = $extPrepare->init($this, array('data' => $row)); |
188 | - if (is_bool($row) && $row === false) { |
|
188 | + if (is_bool($row) && $row === false) { |
|
189 | 189 | continue; |
190 | 190 | } |
191 | 191 | } |
@@ -198,20 +198,20 @@ discard block |
||
198 | 198 | /** |
199 | 199 | * @return array |
200 | 200 | */ |
201 | - protected function getDocList() |
|
202 | - { |
|
201 | + protected function getDocList() |
|
202 | + { |
|
203 | 203 | $out = array(); |
204 | 204 | $sanitarInIDs = $this->sanitarIn($this->IDs); |
205 | - if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
|
205 | + if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
|
206 | 206 | $where = $this->getCFGDef('addWhereList', ''); |
207 | - if ($where != '') { |
|
207 | + if ($where != '') { |
|
208 | 208 | $where = array($where); |
209 | 209 | } |
210 | - if ($sanitarInIDs != "''") { |
|
210 | + if ($sanitarInIDs != "''") { |
|
211 | 211 | $where[] = "`{$this->getPK()}` IN ({$sanitarInIDs})"; |
212 | 212 | } |
213 | 213 | |
214 | - if (!empty($where)) { |
|
214 | + if (!empty($where)) { |
|
215 | 215 | $where = "WHERE " . implode(" AND ", $where); |
216 | 216 | } |
217 | 217 | $limit = $this->LimitSQL($this->getCFGDef('queryLimit', 0)); |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | |
222 | 222 | $rows = $this->modx->db->makeArray($rs); |
223 | 223 | $out = array(); |
224 | - foreach ($rows as $item) { |
|
224 | + foreach ($rows as $item) { |
|
225 | 225 | $out[$item[$this->getPK()]] = $item; |
226 | 226 | } |
227 | 227 | } |
@@ -232,22 +232,22 @@ discard block |
||
232 | 232 | /** |
233 | 233 | * @return array |
234 | 234 | */ |
235 | - protected function getChildrenList() |
|
236 | - { |
|
235 | + protected function getChildrenList() |
|
236 | + { |
|
237 | 237 | $where = array(); |
238 | 238 | $out = array(); |
239 | 239 | |
240 | 240 | $tmpWhere = $this->getCFGDef('addWhereList', ''); |
241 | 241 | $tmpWhere = sqlHelper::trimLogicalOp($tmpWhere); |
242 | - if (!empty($tmpWhere)) { |
|
242 | + if (!empty($tmpWhere)) { |
|
243 | 243 | $where[] = $tmpWhere; |
244 | 244 | } |
245 | 245 | $sanitarInIDs = $this->sanitarIn($this->IDs); |
246 | 246 | |
247 | 247 | $tmpWhere = null; |
248 | - if ($sanitarInIDs != "''") { |
|
248 | + if ($sanitarInIDs != "''") { |
|
249 | 249 | $tmpWhere = "(`{$this->getParentField()}` IN (" . $sanitarInIDs . ")"; |
250 | - switch ($this->getCFGDef('showParent', '0')) { |
|
250 | + switch ($this->getCFGDef('showParent', '0')) { |
|
251 | 251 | case -1: |
252 | 252 | $tmpWhere .= ")"; |
253 | 253 | break; |
@@ -260,32 +260,32 @@ discard block |
||
260 | 260 | break; |
261 | 261 | } |
262 | 262 | } |
263 | - if (($addDocs = $this->getCFGDef('documents', '')) != '') { |
|
263 | + if (($addDocs = $this->getCFGDef('documents', '')) != '') { |
|
264 | 264 | $addDocs = $this->sanitarIn($this->cleanIDs($addDocs)); |
265 | - if (empty($tmpWhere)) { |
|
265 | + if (empty($tmpWhere)) { |
|
266 | 266 | $tmpWhere = $this->getPK() . " IN({$addDocs})"; |
267 | - } else { |
|
267 | + } else { |
|
268 | 268 | $tmpWhere = "((" . $tmpWhere . ") OR {$this->getPK()} IN({$addDocs}))"; |
269 | 269 | } |
270 | 270 | } |
271 | - if (!empty($tmpWhere)) { |
|
271 | + if (!empty($tmpWhere)) { |
|
272 | 272 | $where[] = $tmpWhere; |
273 | 273 | } |
274 | - if (!empty($where)) { |
|
274 | + if (!empty($where)) { |
|
275 | 275 | $where = "WHERE " . implode(" AND ", $where); |
276 | - } else { |
|
276 | + } else { |
|
277 | 277 | $where = ''; |
278 | 278 | } |
279 | 279 | $fields = $this->getCFGDef('selectFields', '*'); |
280 | 280 | $group = $this->getGroupSQL($this->getCFGDef('groupBy', "`{$this->getPK()}`")); |
281 | - if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
|
281 | + if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
|
282 | 282 | $sql = $this->dbQuery("SELECT {$fields} FROM " . $this->table . " " . $where . " " . |
283 | 283 | $group . " " . |
284 | 284 | $this->SortOrderSQL($this->getPK()) . " " . |
285 | 285 | $this->LimitSQL($this->getCFGDef('queryLimit', 0)) |
286 | 286 | ); |
287 | 287 | $rows = $this->modx->db->makeArray($sql); |
288 | - foreach ($rows as $item) { |
|
288 | + foreach ($rows as $item) { |
|
289 | 289 | $out[$item[$this->getPK()]] = $item; |
290 | 290 | } |
291 | 291 | } |
@@ -296,22 +296,22 @@ discard block |
||
296 | 296 | /** |
297 | 297 | * @absctract |
298 | 298 | */ |
299 | - public function getChildrenCount() |
|
300 | - { |
|
299 | + public function getChildrenCount() |
|
300 | + { |
|
301 | 301 | $out = 0; |
302 | 302 | $sanitarInIDs = $this->sanitarIn($this->IDs); |
303 | - if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
|
303 | + if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
|
304 | 304 | $where = $this->getCFGDef('addWhereList', ''); |
305 | - if ($where != '') { |
|
305 | + if ($where != '') { |
|
306 | 306 | $where = array($where); |
307 | - } else { |
|
307 | + } else { |
|
308 | 308 | $where = array(); |
309 | 309 | } |
310 | - if ($sanitarInIDs != "''") { |
|
311 | - if ($sanitarInIDs != "''") { |
|
312 | - switch ($this->getCFGDef('idType', 'parents')) { |
|
310 | + if ($sanitarInIDs != "''") { |
|
311 | + if ($sanitarInIDs != "''") { |
|
312 | + switch ($this->getCFGDef('idType', 'parents')) { |
|
313 | 313 | case 'parents': |
314 | - switch ($this->getCFGDef('showParent', '0')) { |
|
314 | + switch ($this->getCFGDef('showParent', '0')) { |
|
315 | 315 | case '-1': |
316 | 316 | $tmpWhere = "`{$this->getParentField()}` IN ({$sanitarInIDs})"; |
317 | 317 | break; |
@@ -323,10 +323,10 @@ discard block |
||
323 | 323 | $tmpWhere = "(`{$this->getParentField()}` IN ({$sanitarInIDs}) OR `{$this->getPK()}` IN({$sanitarInIDs}))"; |
324 | 324 | break; |
325 | 325 | } |
326 | - if (($addDocs = $this->getCFGDef('documents', '')) != '') { |
|
326 | + if (($addDocs = $this->getCFGDef('documents', '')) != '') { |
|
327 | 327 | $addDocs = $this->sanitarIn($this->cleanIDs($addDocs)); |
328 | 328 | $where[] = "((" . $tmpWhere . ") OR `{$this->getPK()}` IN({$addDocs}))"; |
329 | - } else { |
|
329 | + } else { |
|
330 | 330 | $where[] = $tmpWhere; |
331 | 331 | } |
332 | 332 | break; |
@@ -336,9 +336,9 @@ discard block |
||
336 | 336 | } |
337 | 337 | } |
338 | 338 | } |
339 | - if (!empty($where)) { |
|
339 | + if (!empty($where)) { |
|
340 | 340 | $where = "WHERE " . implode(" AND ", $where); |
341 | - } else { |
|
341 | + } else { |
|
342 | 342 | $where = ''; |
343 | 343 | } |
344 | 344 | |
@@ -355,13 +355,13 @@ discard block |
||
355 | 355 | * @param string $id |
356 | 356 | * @return array |
357 | 357 | */ |
358 | - public function getChildrenFolder($id) |
|
359 | - { |
|
358 | + public function getChildrenFolder($id) |
|
359 | + { |
|
360 | 360 | $sanitarInIDs = $this->sanitarIn($id); |
361 | 361 | |
362 | 362 | $tmp = $this->getCFGDef('addWhereFolder', ''); |
363 | 363 | $where = "`{$this->getParentField()}` IN ({$sanitarInIDs})"; |
364 | - if (!empty($tmp)) { |
|
364 | + if (!empty($tmp)) { |
|
365 | 365 | $where .= " AND " . $tmp; |
366 | 366 | } |
367 | 367 | |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | |
370 | 370 | $rows = $this->modx->db->makeArray($rs); |
371 | 371 | $out = array(); |
372 | - foreach ($rows as $item) { |
|
372 | + foreach ($rows as $item) { |
|
373 | 373 | $out[] = $item[$this->getPK()]; |
374 | 374 | } |
375 | 375 |