@@ -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 | */ |
@@ -184,48 +184,48 @@ discard block |
||
| 184 | 184 | * @param int $startTime время запуска сниппета |
| 185 | 185 | * @throws Exception |
| 186 | 186 | */ |
| 187 | - public function __construct($modx, $cfg = array(), $startTime = null) |
|
| 188 | - { |
|
| 187 | + public function __construct($modx, $cfg = array(), $startTime = null) |
|
| 188 | + {
|
|
| 189 | 189 | $this->setTimeStart($startTime); |
| 190 | 190 | |
| 191 | - if (extension_loaded('mbstring')) { |
|
| 191 | + if (extension_loaded('mbstring')) {
|
|
| 192 | 192 | mb_internal_encoding("UTF-8"); |
| 193 | - } else { |
|
| 193 | + } else {
|
|
| 194 | 194 | throw new Exception('Not found php extension mbstring'); |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - if ($modx instanceof DocumentParser) { |
|
| 197 | + if ($modx instanceof DocumentParser) {
|
|
| 198 | 198 | $this->modx = $modx; |
| 199 | 199 | $this->setDebug(1); |
| 200 | 200 | |
| 201 | - if (!is_array($cfg) || empty($cfg)) { |
|
| 201 | + if (!is_array($cfg) || empty($cfg)) {
|
|
| 202 | 202 | $cfg = $this->modx->Event->params; |
| 203 | 203 | } |
| 204 | - } else { |
|
| 204 | + } else {
|
|
| 205 | 205 | throw new Exception('MODX var is not instaceof DocumentParser'); |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | $this->FS = \Helpers\FS::getInstance(); |
| 209 | 209 | $this->config = new \Helpers\Config($cfg); |
| 210 | 210 | |
| 211 | - if (isset($cfg['config'])) { |
|
| 211 | + if (isset($cfg['config'])) {
|
|
| 212 | 212 | $this->config->setPath(dirname(__DIR__))->loadConfig($cfg['config']); |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | - if ($this->config->setConfig($cfg) === false) { |
|
| 215 | + if ($this->config->setConfig($cfg) === false) {
|
|
| 216 | 216 | throw new Exception('no parameters to run DocLister'); |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | $this->loadLang(array('core', 'json')); |
| 220 | 220 | $this->setDebug($this->getCFGDef('debug', 0)); |
| 221 | 221 | |
| 222 | - if ($this->checkDL()) { |
|
| 222 | + if ($this->checkDL()) {
|
|
| 223 | 223 | $cfg = array(); |
| 224 | 224 | $idType = $this->getCFGDef('idType', ''); |
| 225 | - if (empty($idType) && $this->getCFGDef('documents', '') != '') { |
|
| 225 | + if (empty($idType) && $this->getCFGDef('documents', '') != '') {
|
|
| 226 | 226 | $idType = 'documents'; |
| 227 | 227 | } |
| 228 | - switch ($idType) { |
|
| 228 | + switch ($idType) {
|
|
| 229 | 229 | case 'documents': |
| 230 | 230 | $IDs = $this->getCFGDef('documents'); |
| 231 | 231 | $cfg['idType'] = "documents"; |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | case 'parents': |
| 234 | 234 | default: |
| 235 | 235 | $cfg['idType'] = "parents"; |
| 236 | - if (($IDs = $this->getCFGDef('parents')) === null) { |
|
| 236 | + if (($IDs = $this->getCFGDef('parents')) === null) {
|
|
| 237 | 237 | $IDs = $this->getCurrentMODXPageID(); |
| 238 | 238 | } |
| 239 | 239 | break; |
@@ -252,12 +252,12 @@ discard block |
||
| 252 | 252 | |
| 253 | 253 | $this->setLocate(); |
| 254 | 254 | |
| 255 | - if ($this->getCFGDef("customLang")) { |
|
| 255 | + if ($this->getCFGDef("customLang")) {
|
|
| 256 | 256 | $this->getCustomLang(); |
| 257 | 257 | } |
| 258 | 258 | $this->loadExtender($this->getCFGDef("extender", "")); |
| 259 | 259 | |
| 260 | - if ($this->checkExtender('request')) { |
|
| 260 | + if ($this->checkExtender('request')) {
|
|
| 261 | 261 | $this->extender['request']->init($this, $this->getCFGDef("requestActive", "")); |
| 262 | 262 | } |
| 263 | 263 | $this->_filters = $this->getFilters($this->getCFGDef('filters', '')); |
@@ -269,25 +269,25 @@ discard block |
||
| 269 | 269 | * @param string $str строка с фильтром |
| 270 | 270 | * @return array массив субфильтров |
| 271 | 271 | */ |
| 272 | - public function smartSplit($str) |
|
| 273 | - { |
|
| 272 | + public function smartSplit($str) |
|
| 273 | + {
|
|
| 274 | 274 | $res = array(); |
| 275 | 275 | $cur = ''; |
| 276 | 276 | $open = 0; |
| 277 | 277 | $strlen = mb_strlen($str, 'UTF-8'); |
| 278 | - for ($i = 0; $i <= $strlen; $i++) { |
|
| 278 | + for ($i = 0; $i <= $strlen; $i++) {
|
|
| 279 | 279 | $e = mb_substr($str, $i, 1, 'UTF-8'); |
| 280 | - switch ($e) { |
|
| 280 | + switch ($e) {
|
|
| 281 | 281 | case '\\': |
| 282 | 282 | $cur .= $e; |
| 283 | 283 | $cur .= mb_substr($str, ++$i, 1, 'UTF-8'); |
| 284 | 284 | break; |
| 285 | 285 | case ')': |
| 286 | 286 | $open--; |
| 287 | - if ($open == 0) { |
|
| 287 | + if ($open == 0) {
|
|
| 288 | 288 | $res[] = $cur . ')'; |
| 289 | 289 | $cur = ''; |
| 290 | - } else { |
|
| 290 | + } else {
|
|
| 291 | 291 | $cur .= $e; |
| 292 | 292 | } |
| 293 | 293 | break; |
@@ -296,10 +296,10 @@ discard block |
||
| 296 | 296 | $cur .= $e; |
| 297 | 297 | break; |
| 298 | 298 | case ';': |
| 299 | - if ($open == 0) { |
|
| 299 | + if ($open == 0) {
|
|
| 300 | 300 | $res[] = $cur; |
| 301 | 301 | $cur = ''; |
| 302 | - } else { |
|
| 302 | + } else {
|
|
| 303 | 303 | $cur .= $e; |
| 304 | 304 | } |
| 305 | 305 | break; |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | } |
| 309 | 309 | } |
| 310 | 310 | $cur = preg_replace("/(\))$/u", '', $cur); |
| 311 | - if ($cur != '') { |
|
| 311 | + if ($cur != '') {
|
|
| 312 | 312 | $res[] = $cur; |
| 313 | 313 | } |
| 314 | 314 | |
@@ -319,8 +319,8 @@ discard block |
||
| 319 | 319 | * Трансформация объекта в строку |
| 320 | 320 | * @return string последний ответ от DocLister'а |
| 321 | 321 | */ |
| 322 | - public function __toString() |
|
| 323 | - { |
|
| 322 | + public function __toString() |
|
| 323 | + {
|
|
| 324 | 324 | return $this->outData; |
| 325 | 325 | } |
| 326 | 326 | |
@@ -328,8 +328,8 @@ discard block |
||
| 328 | 328 | * Установить время запуска сниппета |
| 329 | 329 | * @param float|null $time |
| 330 | 330 | */ |
| 331 | - public function setTimeStart($time = null) |
|
| 332 | - { |
|
| 331 | + public function setTimeStart($time = null) |
|
| 332 | + {
|
|
| 333 | 333 | $this->_timeStart = is_null($time) ? microtime(true) : $time; |
| 334 | 334 | } |
| 335 | 335 | |
@@ -338,8 +338,8 @@ discard block |
||
| 338 | 338 | * |
| 339 | 339 | * @return int |
| 340 | 340 | */ |
| 341 | - public function getTimeStart() |
|
| 342 | - { |
|
| 341 | + public function getTimeStart() |
|
| 342 | + {
|
|
| 343 | 343 | return $this->_timeStart; |
| 344 | 344 | } |
| 345 | 345 | |
@@ -347,27 +347,27 @@ discard block |
||
| 347 | 347 | * Установка режима отладки |
| 348 | 348 | * @param int $flag режим отладки |
| 349 | 349 | */ |
| 350 | - public function setDebug($flag = 0) |
|
| 351 | - { |
|
| 350 | + public function setDebug($flag = 0) |
|
| 351 | + {
|
|
| 352 | 352 | $flag = abs((int)$flag); |
| 353 | - if ($this->_debugMode != $flag) { |
|
| 353 | + if ($this->_debugMode != $flag) {
|
|
| 354 | 354 | $this->_debugMode = $flag; |
| 355 | 355 | $this->debug = null; |
| 356 | - if ($this->_debugMode > 0) { |
|
| 357 | - if (isset($_SESSION['usertype']) && $_SESSION['usertype'] == 'manager') { |
|
| 356 | + if ($this->_debugMode > 0) {
|
|
| 357 | + if (isset($_SESSION['usertype']) && $_SESSION['usertype'] == 'manager') {
|
|
| 358 | 358 | error_reporting(E_ALL ^ E_NOTICE); |
| 359 | 359 | ini_set('display_errors', 1); |
| 360 | 360 | } |
| 361 | 361 | $dir = dirname(dirname(__FILE__)); |
| 362 | - if (file_exists($dir . "/lib/DLdebug.class.php")) { |
|
| 362 | + if (file_exists($dir . "/lib/DLdebug.class.php")) {
|
|
| 363 | 363 | include_once($dir . "/lib/DLdebug.class.php"); |
| 364 | - if (class_exists("DLdebug", false)) { |
|
| 364 | + if (class_exists("DLdebug", false)) {
|
|
| 365 | 365 | $this->debug = new DLdebug($this); |
| 366 | 366 | } |
| 367 | 367 | } |
| 368 | 368 | } |
| 369 | 369 | |
| 370 | - if (is_null($this->debug)) { |
|
| 370 | + if (is_null($this->debug)) {
|
|
| 371 | 371 | $this->debug = new xNop(); |
| 372 | 372 | $this->_debugMode = 0; |
| 373 | 373 | error_reporting(0); |
@@ -379,8 +379,8 @@ discard block |
||
| 379 | 379 | /** |
| 380 | 380 | * Информация о режиме отладки |
| 381 | 381 | */ |
| 382 | - public function getDebug() |
|
| 383 | - { |
|
| 382 | + public function getDebug() |
|
| 383 | + {
|
|
| 384 | 384 | return $this->_debugMode; |
| 385 | 385 | } |
| 386 | 386 | |
@@ -391,13 +391,13 @@ discard block |
||
| 391 | 391 | * @param string $alias желаемый алиас таблицы |
| 392 | 392 | * @return string имя таблицы с префиксом и алиасом |
| 393 | 393 | */ |
| 394 | - public function getTable($name, $alias = '') |
|
| 395 | - { |
|
| 396 | - if (!isset($this->_table[$name])) { |
|
| 394 | + public function getTable($name, $alias = '') |
|
| 395 | + {
|
|
| 396 | + if (!isset($this->_table[$name])) {
|
|
| 397 | 397 | $this->_table[$name] = $this->modx->getFullTableName($name); |
| 398 | 398 | } |
| 399 | 399 | $table = $this->_table[$name]; |
| 400 | - if (!empty($alias) && is_scalar($alias)) { |
|
| 400 | + if (!empty($alias) && is_scalar($alias)) {
|
|
| 401 | 401 | $table .= " as `" . $alias . "`"; |
| 402 | 402 | } |
| 403 | 403 | |
@@ -410,9 +410,9 @@ discard block |
||
| 410 | 410 | * @param $alias |
| 411 | 411 | * @return mixed |
| 412 | 412 | */ |
| 413 | - public function TableAlias($name, $table, $alias) |
|
| 414 | - { |
|
| 415 | - if (!$this->checkTableAlias($name, $table)) { |
|
| 413 | + public function TableAlias($name, $table, $alias) |
|
| 414 | + {
|
|
| 415 | + if (!$this->checkTableAlias($name, $table)) {
|
|
| 416 | 416 | $this->AddTable[$table][$name] = $alias; |
| 417 | 417 | } |
| 418 | 418 | |
@@ -424,8 +424,8 @@ discard block |
||
| 424 | 424 | * @param $table |
| 425 | 425 | * @return bool |
| 426 | 426 | */ |
| 427 | - public function checkTableAlias($name, $table) |
|
| 428 | - { |
|
| 427 | + public function checkTableAlias($name, $table) |
|
| 428 | + {
|
|
| 429 | 429 | return isset($this->AddTable[$table][$name]); |
| 430 | 430 | } |
| 431 | 431 | |
@@ -437,8 +437,8 @@ discard block |
||
| 437 | 437 | * @param bool $nop создавать ли пустой объект запрашиваемого типа |
| 438 | 438 | * @return array|mixed|xNop |
| 439 | 439 | */ |
| 440 | - public function jsonDecode($json, $config = array(), $nop = false) |
|
| 441 | - { |
|
| 440 | + public function jsonDecode($json, $config = array(), $nop = false) |
|
| 441 | + {
|
|
| 442 | 442 | $this->debug->debug('Decode JSON: ' . $this->debug->dumpData($json) . "\r\nwith config: " . $this->debug->dumpData($config), |
| 443 | 443 | 'jsonDecode', 2); |
| 444 | 444 | $config = jsonHelper::jsonDecode($json, $config, $nop); |
@@ -454,10 +454,10 @@ discard block |
||
| 454 | 454 | * @param $json string строка с JSON для записи в лог при отладке |
| 455 | 455 | * @return bool|string |
| 456 | 456 | */ |
| 457 | - public function isErrorJSON($json) |
|
| 458 | - { |
|
| 457 | + public function isErrorJSON($json) |
|
| 458 | + {
|
|
| 459 | 459 | $error = jsonHelper::json_last_error_msg(); |
| 460 | - if (!in_array($error, array('error_none', 'other'))) { |
|
| 460 | + if (!in_array($error, array('error_none', 'other'))) {
|
|
| 461 | 461 | $this->debug->error($this->getMsg('json.' . $error) . ": " . $this->debug->dumpData($json, 'code'), 'JSON'); |
| 462 | 462 | $error = true; |
| 463 | 463 | } |
@@ -469,20 +469,20 @@ discard block |
||
| 469 | 469 | * Проверка параметров и загрузка необходимых экстендеров |
| 470 | 470 | * return boolean статус загрузки |
| 471 | 471 | */ |
| 472 | - public function checkDL() |
|
| 473 | - { |
|
| 472 | + public function checkDL() |
|
| 473 | + {
|
|
| 474 | 474 | $this->debug->debug('Check DocLister parameters', 'checkDL', 2); |
| 475 | 475 | $flag = true; |
| 476 | 476 | $extenders = $this->getCFGDef('extender', ''); |
| 477 | 477 | $extenders = explode(",", $extenders); |
| 478 | 478 | $tmp = $this->getCFGDef('requestActive', '') != '' || in_array('request', $extenders); |
| 479 | - if ($tmp && !$this->_loadExtender('request')) { |
|
| 479 | + if ($tmp && !$this->_loadExtender('request')) {
|
|
| 480 | 480 | //OR request in extender's parameter |
| 481 | 481 | throw new Exception('Error load request extender'); |
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | $tmp = $this->getCFGDef('summary', '') != '' || in_array('summary', $extenders); |
| 485 | - if ($tmp && !$this->_loadExtender('summary')) { |
|
| 485 | + if ($tmp && !$this->_loadExtender('summary')) {
|
|
| 486 | 486 | //OR summary in extender's parameter |
| 487 | 487 | throw new Exception('Error load summary extender'); |
| 488 | 488 | } |
@@ -495,15 +495,15 @@ discard block |
||
| 495 | 495 | $this->getCFGDef('pageLimit', '') != '' || $this->getCFGDef('pageAdjacents', '') != '' || |
| 496 | 496 | $this->getCFGDef('PaginateClass', '') != '' || $this->getCFGDef('TplNextP', '') != '' |
| 497 | 497 | ) && !$this->_loadExtender('paginate') |
| 498 | - ) { |
|
| 498 | + ) {
|
|
| 499 | 499 | throw new Exception('Error load paginate extender'); |
| 500 | - } else { |
|
| 501 | - if ((int)$this->getCFGDef('display', 0) == 0) { |
|
| 500 | + } else {
|
|
| 501 | + if ((int)$this->getCFGDef('display', 0) == 0) {
|
|
| 502 | 502 | $extenders = $this->unsetArrayVal($extenders, 'paginate'); |
| 503 | 503 | } |
| 504 | 504 | } |
| 505 | 505 | |
| 506 | - if ($this->getCFGDef('prepare', '') != '' || $this->getCFGDef('prepareWrap') != '') { |
|
| 506 | + if ($this->getCFGDef('prepare', '') != '' || $this->getCFGDef('prepareWrap') != '') {
|
|
| 507 | 507 | $this->_loadExtender('prepare'); |
| 508 | 508 | } |
| 509 | 509 | |
@@ -520,14 +520,14 @@ discard block |
||
| 520 | 520 | * @param mixed $val значение которые необходимо удалить из массива |
| 521 | 521 | * @return array отчищеный массив с данными |
| 522 | 522 | */ |
| 523 | - private function unsetArrayVal($data, $val) |
|
| 524 | - { |
|
| 523 | + private function unsetArrayVal($data, $val) |
|
| 524 | + {
|
|
| 525 | 525 | $out = array(); |
| 526 | - if (is_array($data)) { |
|
| 527 | - foreach ($data as $item) { |
|
| 528 | - if ($item != $val) { |
|
| 526 | + if (is_array($data)) {
|
|
| 527 | + foreach ($data as $item) {
|
|
| 528 | + if ($item != $val) {
|
|
| 529 | 529 | $out[] = $item; |
| 530 | - } else { |
|
| 530 | + } else {
|
|
| 531 | 531 | continue; |
| 532 | 532 | } |
| 533 | 533 | } |
@@ -542,14 +542,14 @@ discard block |
||
| 542 | 542 | * @param int $id уникальный идентификатор страницы |
| 543 | 543 | * @return string URL страницы |
| 544 | 544 | */ |
| 545 | - public function getUrl($id = 0) |
|
| 546 | - { |
|
| 545 | + public function getUrl($id = 0) |
|
| 546 | + {
|
|
| 547 | 547 | $id = ((int)$id > 0) ? (int)$id : $this->getCurrentMODXPageID(); |
| 548 | 548 | |
| 549 | 549 | $link = $this->checkExtender('request') ? $this->extender['request']->getLink() : $this->getRequest(); |
| 550 | - if ($id == $this->modx->config['site_start']) { |
|
| 550 | + if ($id == $this->modx->config['site_start']) {
|
|
| 551 | 551 | $url = $this->modx->config['site_url'] . ($link != '' ? "?{$link}" : ""); |
| 552 | - } else { |
|
| 552 | + } else {
|
|
| 553 | 553 | $url = $this->modx->makeUrl($id, '', $link, $this->getCFGDef('urlScheme', '')); |
| 554 | 554 | } |
| 555 | 555 | |
@@ -577,20 +577,20 @@ discard block |
||
| 577 | 577 | * @param string $tpl шаблон |
| 578 | 578 | * @return string |
| 579 | 579 | */ |
| 580 | - public function render($tpl = '') |
|
| 581 | - { |
|
| 580 | + public function render($tpl = '') |
|
| 581 | + {
|
|
| 582 | 582 | $this->debug->debug(array('Render data with template ' => $tpl), 'render', 2, array('html')); |
| 583 | 583 | $out = ''; |
| 584 | - if (1 == $this->getCFGDef('tree', '0')) { |
|
| 585 | - foreach ($this->_tree as $item) { |
|
| 584 | + if (1 == $this->getCFGDef('tree', '0')) {
|
|
| 585 | + foreach ($this->_tree as $item) {
|
|
| 586 | 586 | $out .= $this->renderTree($item); |
| 587 | 587 | } |
| 588 | 588 | $out = $this->renderWrap($out); |
| 589 | - } else { |
|
| 589 | + } else {
|
|
| 590 | 590 | $out = $this->_render($tpl); |
| 591 | 591 | } |
| 592 | 592 | |
| 593 | - if ($out) { |
|
| 593 | + if ($out) {
|
|
| 594 | 594 | $this->outData = DLTemplate::getInstance($this->modx)->parseDocumentSource($out); |
| 595 | 595 | } |
| 596 | 596 | $this->debug->debugEnd('render'); |
@@ -607,8 +607,8 @@ discard block |
||
| 607 | 607 | * |
| 608 | 608 | * @return int |
| 609 | 609 | */ |
| 610 | - public function getCurrentMODXPageID() |
|
| 611 | - { |
|
| 610 | + public function getCurrentMODXPageID() |
|
| 611 | + {
|
|
| 612 | 612 | $id = isset($this->modx->documentIdentifier) ? (int)$this->modx->documentIdentifier : 0; |
| 613 | 613 | $docData = isset($this->modx->documentObject) ? $this->modx->documentObject : array(); |
| 614 | 614 | |
@@ -624,9 +624,9 @@ discard block |
||
| 624 | 624 | * @param integer $line error on line |
| 625 | 625 | * @param array $trace stack trace |
| 626 | 626 | */ |
| 627 | - public function ErrorLogger($message, $code, $file, $line, $trace) |
|
| 628 | - { |
|
| 629 | - if (abs($this->getCFGDef('debug', '0')) == '1') { |
|
| 627 | + public function ErrorLogger($message, $code, $file, $line, $trace) |
|
| 628 | + {
|
|
| 629 | + if (abs($this->getCFGDef('debug', '0')) == '1') {
|
|
| 630 | 630 | $out = "CODE #" . $code . "<br />"; |
| 631 | 631 | $out .= "on file: " . $file . ":" . $line . "<br />"; |
| 632 | 632 | $out .= "<pre>"; |
@@ -643,8 +643,8 @@ discard block |
||
| 643 | 643 | * |
| 644 | 644 | * @return DocumentParser |
| 645 | 645 | */ |
| 646 | - public function getMODX() |
|
| 647 | - { |
|
| 646 | + public function getMODX() |
|
| 647 | + {
|
|
| 648 | 648 | return $this->modx; |
| 649 | 649 | } |
| 650 | 650 | |
@@ -655,13 +655,13 @@ discard block |
||
| 655 | 655 | * @return boolean status load extenders |
| 656 | 656 | * @throws Exception |
| 657 | 657 | */ |
| 658 | - public function loadExtender($ext = '') |
|
| 659 | - { |
|
| 658 | + public function loadExtender($ext = '') |
|
| 659 | + {
|
|
| 660 | 660 | $out = true; |
| 661 | - if ($ext != '') { |
|
| 661 | + if ($ext != '') {
|
|
| 662 | 662 | $ext = explode(",", $ext); |
| 663 | - foreach ($ext as $item) { |
|
| 664 | - if ($item != '' && !$this->_loadExtender($item)) { |
|
| 663 | + foreach ($ext as $item) {
|
|
| 664 | + if ($item != '' && !$this->_loadExtender($item)) {
|
|
| 665 | 665 | throw new Exception('Error load ' . APIHelpers::e($item) . ' extender'); |
| 666 | 666 | } |
| 667 | 667 | } |
@@ -677,8 +677,8 @@ discard block |
||
| 677 | 677 | * @param mixed $def значение по умолчанию, если в конфиге нет искомого параметра |
| 678 | 678 | * @return mixed значение из конфига |
| 679 | 679 | */ |
| 680 | - public function getCFGDef($name, $def = null) |
|
| 681 | - { |
|
| 680 | + public function getCFGDef($name, $def = null) |
|
| 681 | + {
|
|
| 682 | 682 | return $this->config->getCFGDef($name, $def); |
| 683 | 683 | } |
| 684 | 684 | |
@@ -690,15 +690,15 @@ discard block |
||
| 690 | 690 | * @param string $key ключ локального плейсхолдера |
| 691 | 691 | * @return string |
| 692 | 692 | */ |
| 693 | - public function toPlaceholders($data, $set = 0, $key = 'contentPlaceholder') |
|
| 694 | - { |
|
| 693 | + public function toPlaceholders($data, $set = 0, $key = 'contentPlaceholder') |
|
| 694 | + {
|
|
| 695 | 695 | $this->debug->debug(null, 'toPlaceholders', 2); |
| 696 | - if ($set == 0) { |
|
| 696 | + if ($set == 0) {
|
|
| 697 | 697 | $set = $this->getCFGDef('contentPlaceholder', 0); |
| 698 | 698 | } |
| 699 | 699 | $this->_plh[$key] = $data; |
| 700 | 700 | $id = $this->getCFGDef('id', ''); |
| 701 | - if ($id != '') { |
|
| 701 | + if ($id != '') {
|
|
| 702 | 702 | $id .= "."; |
| 703 | 703 | } |
| 704 | 704 | $out = DLTemplate::getInstance($this->getMODX())->toPlaceholders($data, $set, $key, $id); |
@@ -720,14 +720,14 @@ discard block |
||
| 720 | 720 | * @param boolean $quote заключать ли данные на выходе в кавычки |
| 721 | 721 | * @return string обработанная строка |
| 722 | 722 | */ |
| 723 | - public function sanitarIn($data, $sep = ',', $quote = true) |
|
| 724 | - { |
|
| 725 | - if (!is_array($data)) { |
|
| 723 | + public function sanitarIn($data, $sep = ',', $quote = true) |
|
| 724 | + {
|
|
| 725 | + if (!is_array($data)) {
|
|
| 726 | 726 | $data = explode($sep, $data); |
| 727 | 727 | } |
| 728 | 728 | $out = array(); |
| 729 | - foreach ($data as $item) { |
|
| 730 | - if ($item !== '') { |
|
| 729 | + foreach ($data as $item) {
|
|
| 730 | + if ($item !== '') {
|
|
| 731 | 731 | $out[] = $this->modx->db->escape($item); |
| 732 | 732 | } |
| 733 | 733 | } |
@@ -748,12 +748,12 @@ discard block |
||
| 748 | 748 | * @param string $lang имя языкового пакета |
| 749 | 749 | * @return array |
| 750 | 750 | */ |
| 751 | - public function getCustomLang($lang = '') |
|
| 752 | - { |
|
| 753 | - if (empty($lang)) { |
|
| 751 | + public function getCustomLang($lang = '') |
|
| 752 | + {
|
|
| 753 | + if (empty($lang)) {
|
|
| 754 | 754 | $lang = $this->getCFGDef('lang', $this->modx->config['manager_language']); |
| 755 | 755 | } |
| 756 | - if (file_exists(dirname(dirname(__FILE__)) . "/lang/" . $lang . ".php")) { |
|
| 756 | + if (file_exists(dirname(dirname(__FILE__)) . "/lang/" . $lang . ".php")) {
|
|
| 757 | 757 | $tmp = include(dirname(__FILE__) . "/lang/" . $lang . ".php"); |
| 758 | 758 | $this->_customLang = is_array($tmp) ? $tmp : array(); |
| 759 | 759 | } |
@@ -769,25 +769,25 @@ discard block |
||
| 769 | 769 | * @param boolean $rename Переименовывать ли элементы массива |
| 770 | 770 | * @return array массив с лексиконом |
| 771 | 771 | */ |
| 772 | - public function loadLang($name = 'core', $lang = '', $rename = true) |
|
| 773 | - { |
|
| 774 | - if (empty($lang)) { |
|
| 772 | + public function loadLang($name = 'core', $lang = '', $rename = true) |
|
| 773 | + {
|
|
| 774 | + if (empty($lang)) {
|
|
| 775 | 775 | $lang = $this->getCFGDef('lang', $this->modx->config['manager_language']); |
| 776 | 776 | } |
| 777 | 777 | |
| 778 | 778 | $this->debug->debug('Load language ' . $this->debug->dumpData($name) . "." . $this->debug->dumpData($lang), |
| 779 | 779 | 'loadlang', 2); |
| 780 | - if (is_scalar($name)) { |
|
| 780 | + if (is_scalar($name)) {
|
|
| 781 | 781 | $name = array($name); |
| 782 | 782 | } |
| 783 | - foreach ($name as $n) { |
|
| 784 | - if (file_exists(dirname(__FILE__) . "/lang/" . $lang . "/" . $n . ".inc.php")) { |
|
| 783 | + foreach ($name as $n) {
|
|
| 784 | + if (file_exists(dirname(__FILE__) . "/lang/" . $lang . "/" . $n . ".inc.php")) {
|
|
| 785 | 785 | $tmp = include(dirname(__FILE__) . "/lang/" . $lang . "/" . $n . ".inc.php"); |
| 786 | - if (is_array($tmp)) { |
|
| 786 | + if (is_array($tmp)) {
|
|
| 787 | 787 | /** |
| 788 | 788 | * Переименовыываем элементы массива из array('test'=>'data') в array('name.test'=>'data') |
| 789 | 789 | */ |
| 790 | - if ($rename) { |
|
| 790 | + if ($rename) {
|
|
| 791 | 791 | $tmp = $this->renameKeyArr($tmp, $n, '', '.'); |
| 792 | 792 | } |
| 793 | 793 | $this->_lang = array_merge($this->_lang, $tmp); |
@@ -806,11 +806,11 @@ discard block |
||
| 806 | 806 | * @param string $def Строка по умолчанию, если запись в языковом пакете не будет обнаружена |
| 807 | 807 | * @return string строка в соответствии с текущими языковыми настройками |
| 808 | 808 | */ |
| 809 | - public function getMsg($name, $def = '') |
|
| 810 | - { |
|
| 811 | - if (isset($this->_customLang[$name])) { |
|
| 809 | + public function getMsg($name, $def = '') |
|
| 810 | + {
|
|
| 811 | + if (isset($this->_customLang[$name])) {
|
|
| 812 | 812 | $say = $this->_customLang[$name]; |
| 813 | - } else { |
|
| 813 | + } else {
|
|
| 814 | 814 | $say = \APIHelpers::getkey($this->_lang, $name, $def); |
| 815 | 815 | } |
| 816 | 816 | |
@@ -826,8 +826,8 @@ discard block |
||
| 826 | 826 | * @param string $sep разделитель суффиксов, префиксов и ключей массива |
| 827 | 827 | * @return array массив с переименованными ключами |
| 828 | 828 | */ |
| 829 | - public function renameKeyArr($data, $prefix = '', $suffix = '', $sep = '.') |
|
| 830 | - { |
|
| 829 | + public function renameKeyArr($data, $prefix = '', $suffix = '', $sep = '.') |
|
| 830 | + {
|
|
| 831 | 831 | return \APIHelpers::renameKeyArr($data, $prefix, $suffix, $sep); |
| 832 | 832 | } |
| 833 | 833 | |
@@ -837,12 +837,12 @@ discard block |
||
| 837 | 837 | * @param string $locale локаль |
| 838 | 838 | * @return string имя установленной локали |
| 839 | 839 | */ |
| 840 | - public function setLocate($locale = '') |
|
| 841 | - { |
|
| 842 | - if ('' == $locale) { |
|
| 840 | + public function setLocate($locale = '') |
|
| 841 | + {
|
|
| 842 | + if ('' == $locale) {
|
|
| 843 | 843 | $locale = $this->getCFGDef('locale', ''); |
| 844 | 844 | } |
| 845 | - if ('' != $locale) { |
|
| 845 | + if ('' != $locale) {
|
|
| 846 | 846 | setlocale(LC_ALL, $locale); |
| 847 | 847 | } |
| 848 | 848 | |
@@ -856,11 +856,11 @@ discard block |
||
| 856 | 856 | * @param array $data массив сформированный как дерево |
| 857 | 857 | * @return string строка для отображения пользователю |
| 858 | 858 | */ |
| 859 | - protected function renderTree($data) |
|
| 860 | - { |
|
| 859 | + protected function renderTree($data) |
|
| 860 | + {
|
|
| 861 | 861 | $out = ''; |
| 862 | - if (!empty($data['#childNodes'])) { |
|
| 863 | - foreach ($data['#childNodes'] as $item) { |
|
| 862 | + if (!empty($data['#childNodes'])) {
|
|
| 863 | + foreach ($data['#childNodes'] as $item) {
|
|
| 864 | 864 | $out .= $this->renderTree($item); |
| 865 | 865 | } |
| 866 | 866 | } |
@@ -877,8 +877,8 @@ discard block |
||
| 877 | 877 | * @param string $name Template: chunk name || @CODE: template || @FILE: file with template |
| 878 | 878 | * @return string html template with placeholders without data |
| 879 | 879 | */ |
| 880 | - private function _getChunk($name) |
|
| 881 | - { |
|
| 880 | + private function _getChunk($name) |
|
| 881 | + {
|
|
| 882 | 882 | $this->debug->debug(array('Get chunk by name' => $name), "getChunk", 2, array('html')); |
| 883 | 883 | //without trim |
| 884 | 884 | $tpl = DLTemplate::getInstance($this->getMODX())->getChunk($name); |
@@ -895,18 +895,18 @@ discard block |
||
| 895 | 895 | * @param string $tpl HTML шаблон |
| 896 | 896 | * @return string |
| 897 | 897 | */ |
| 898 | - public function parseLang($tpl) |
|
| 899 | - { |
|
| 898 | + public function parseLang($tpl) |
|
| 899 | + {
|
|
| 900 | 900 | $this->debug->debug(array("parseLang" => $tpl), "parseLang", 2, array('html')); |
| 901 | - if (is_scalar($tpl) && !empty($tpl)) { |
|
| 902 | - if (preg_match_all("/\[\%([a-zA-Z0-9\.\_\-]+)\%\]/", $tpl, $match)) { |
|
| 901 | + if (is_scalar($tpl) && !empty($tpl)) {
|
|
| 902 | + if (preg_match_all("/\[\%([a-zA-Z0-9\.\_\-]+)\%\]/", $tpl, $match)) {
|
|
| 903 | 903 | $langVal = array(); |
| 904 | - foreach ($match[1] as $item) { |
|
| 904 | + foreach ($match[1] as $item) {
|
|
| 905 | 905 | $langVal[] = $this->getMsg($item); |
| 906 | 906 | } |
| 907 | 907 | $tpl = str_replace($match[0], $langVal, $tpl); |
| 908 | 908 | } |
| 909 | - } else { |
|
| 909 | + } else {
|
|
| 910 | 910 | $tpl = ''; |
| 911 | 911 | } |
| 912 | 912 | $this->debug->debugEnd("parseLang"); |
@@ -922,24 +922,24 @@ discard block |
||
| 922 | 922 | * @param bool $parseDocumentSource render html template via DocumentParser::parseDocumentSource() |
| 923 | 923 | * @return string html template with data without placeholders |
| 924 | 924 | */ |
| 925 | - public function parseChunk($name, $data, $parseDocumentSource = false) |
|
| 926 | - { |
|
| 925 | + public function parseChunk($name, $data, $parseDocumentSource = false) |
|
| 926 | + {
|
|
| 927 | 927 | $this->debug->debug( |
| 928 | 928 | array("parseChunk" => $name, "With data" => print_r($data, 1)), |
| 929 | 929 | "parseChunk", |
| 930 | 930 | 2, array('html', null) |
| 931 | 931 | ); |
| 932 | 932 | $DLTemplate = DLTemplate::getInstance($this->getMODX()); |
| 933 | - if ($path = $this->getCFGDef('templatePath')) { |
|
| 933 | + if ($path = $this->getCFGDef('templatePath')) {
|
|
| 934 | 934 | $DLTemplate->setTemplatePath($path); |
| 935 | 935 | } |
| 936 | - if ($ext = $this->getCFGDef('templateExtension')) { |
|
| 936 | + if ($ext = $this->getCFGDef('templateExtension')) {
|
|
| 937 | 937 | $DLTemplate->setTemplateExtension($ext); |
| 938 | 938 | } |
| 939 | 939 | $DLTemplate->setTwigTemplateVars(array('DocLister' => $this)); |
| 940 | 940 | $out = $DLTemplate->parseChunk($name, $data, $parseDocumentSource); |
| 941 | 941 | $out = $this->parseLang($out); |
| 942 | - if (empty($out)) { |
|
| 942 | + if (empty($out)) {
|
|
| 943 | 943 | $this->debug->debug("Empty chunk: " . $this->debug->dumpData($name), '', 2); |
| 944 | 944 | } |
| 945 | 945 | $this->debug->debugEnd("parseChunk"); |
@@ -955,8 +955,8 @@ discard block |
||
| 955 | 955 | * |
| 956 | 956 | * @return string html template from parameter |
| 957 | 957 | */ |
| 958 | - public function getChunkByParam($name, $val = '') |
|
| 959 | - { |
|
| 958 | + public function getChunkByParam($name, $val = '') |
|
| 959 | + {
|
|
| 960 | 960 | $data = $this->getCFGDef($name, $val); |
| 961 | 961 | $data = $this->_getChunk($data); |
| 962 | 962 | |
@@ -969,11 +969,11 @@ discard block |
||
| 969 | 969 | * @param string $data html код который нужно обернуть в ownerTPL |
| 970 | 970 | * @return string результатирующий html код |
| 971 | 971 | */ |
| 972 | - public function renderWrap($data) |
|
| 973 | - { |
|
| 972 | + public function renderWrap($data) |
|
| 973 | + {
|
|
| 974 | 974 | $out = $data; |
| 975 | 975 | $docs = count($this->_docs) - $this->skippedDocs; |
| 976 | - if ((($this->getCFGDef("noneWrapOuter", "1") && $docs == 0) || $docs > 0) && !empty($this->ownerTPL)) { |
|
| 976 | + if ((($this->getCFGDef("noneWrapOuter", "1") && $docs == 0) || $docs > 0) && !empty($this->ownerTPL)) {
|
|
| 977 | 977 | $this->debug->debug("", "renderWrapTPL", 2); |
| 978 | 978 | $parse = true; |
| 979 | 979 | $plh = array($this->getCFGDef("sysKey", "dl") . ".wrap" => $data); |
@@ -981,7 +981,7 @@ discard block |
||
| 981 | 981 | * @var $extPrepare prepare_DL_Extender |
| 982 | 982 | */ |
| 983 | 983 | $extPrepare = $this->getExtender('prepare'); |
| 984 | - if ($extPrepare) { |
|
| 984 | + if ($extPrepare) {
|
|
| 985 | 985 | $params = $extPrepare->init($this, array( |
| 986 | 986 | 'data' => array( |
| 987 | 987 | 'docs' => $this->_docs, |
@@ -990,13 +990,13 @@ discard block |
||
| 990 | 990 | 'nameParam' => 'prepareWrap', |
| 991 | 991 | 'return' => 'placeholders' |
| 992 | 992 | )); |
| 993 | - if (is_bool($params) && $params === false) { |
|
| 993 | + if (is_bool($params) && $params === false) {
|
|
| 994 | 994 | $out = $data; |
| 995 | 995 | $parse = false; |
| 996 | 996 | } |
| 997 | 997 | $plh = $params; |
| 998 | 998 | } |
| 999 | - if ($parse && !empty($this->ownerTPL)) { |
|
| 999 | + if ($parse && !empty($this->ownerTPL)) {
|
|
| 1000 | 1000 | $this->debug->updateMessage( |
| 1001 | 1001 | array("render ownerTPL" => $this->ownerTPL, "With data" => print_r($plh, 1)), |
| 1002 | 1002 | "renderWrapTPL", |
@@ -1004,7 +1004,7 @@ discard block |
||
| 1004 | 1004 | ); |
| 1005 | 1005 | $out = $this->parseChunk($this->ownerTPL, $plh); |
| 1006 | 1006 | } |
| 1007 | - if (empty($this->ownerTPL)) { |
|
| 1007 | + if (empty($this->ownerTPL)) {
|
|
| 1008 | 1008 | $this->debug->updateMessage("empty ownerTPL", "renderWrapTPL"); |
| 1009 | 1009 | } |
| 1010 | 1010 | $this->debug->debugEnd("renderWrapTPL"); |
@@ -1020,8 +1020,8 @@ discard block |
||
| 1020 | 1020 | * @param int $i номер итерации в цикле |
| 1021 | 1021 | * @return array массив с данными которые можно использовать в цикле render метода |
| 1022 | 1022 | */ |
| 1023 | - protected function uniformPrepare(&$data, $i = 0) |
|
| 1024 | - { |
|
| 1023 | + protected function uniformPrepare(&$data, $i = 0) |
|
| 1024 | + {
|
|
| 1025 | 1025 | $class = array(); |
| 1026 | 1026 | |
| 1027 | 1027 | $iterationName = ($i % 2 == 1) ? 'Odd' : 'Even'; |
@@ -1032,13 +1032,13 @@ discard block |
||
| 1032 | 1032 | $this->renderTPL = $this->getCFGDef('tpl' . $iterationName, $this->renderTPL); |
| 1033 | 1033 | $iteration = $i; |
| 1034 | 1034 | |
| 1035 | - if ($this->extPaginate) { |
|
| 1035 | + if ($this->extPaginate) {
|
|
| 1036 | 1036 | $offset = $this->getCFGDef('reversePagination', |
| 1037 | 1037 | 0) && $this->extPaginate->currentPage() > 1 ? $this->extPaginate->totalPage() * $this->getCFGDef('display', |
| 1038 | 1038 | 0) - $this->extPaginate->totalDocs() : 0; |
| 1039 | 1039 | if ($this->getCFGDef('maxDocs', 0) && !$this->getCFGDef('reversePagination', |
| 1040 | 1040 | 0) && $this->extPaginate->currentPage() == $this->extPaginate->totalPage() |
| 1041 | - ) { |
|
| 1041 | + ) {
|
|
| 1042 | 1042 | $iteration += $this->getCFGDef('display', 0); |
| 1043 | 1043 | } |
| 1044 | 1044 | $iteration += $this->getCFGDef('display', |
@@ -1048,20 +1048,20 @@ discard block |
||
| 1048 | 1048 | $data[$this->getCFGDef("sysKey", |
| 1049 | 1049 | "dl") . '.full_iteration'] = $iteration; |
| 1050 | 1050 | |
| 1051 | - if ($i == 1) { |
|
| 1051 | + if ($i == 1) {
|
|
| 1052 | 1052 | $this->renderTPL = $this->getCFGDef('tplFirst', $this->renderTPL); |
| 1053 | 1053 | $class[] = $this->getCFGDef('firstClass', 'first'); |
| 1054 | 1054 | } |
| 1055 | - if ($i == (count($this->_docs) - $this->skippedDocs)) { |
|
| 1055 | + if ($i == (count($this->_docs) - $this->skippedDocs)) {
|
|
| 1056 | 1056 | $this->renderTPL = $this->getCFGDef('tplLast', $this->renderTPL); |
| 1057 | 1057 | $class[] = $this->getCFGDef('lastClass', 'last'); |
| 1058 | 1058 | } |
| 1059 | - if ($this->modx->documentIdentifier == $data['id']) { |
|
| 1059 | + if ($this->modx->documentIdentifier == $data['id']) {
|
|
| 1060 | 1060 | $this->renderTPL = $this->getCFGDef('tplCurrent', $this->renderTPL); |
| 1061 | 1061 | $data[$this->getCFGDef("sysKey", |
| 1062 | 1062 | "dl") . '.active'] = 1; //[+active+] - 1 if $modx->documentIdentifer equal ID this element |
| 1063 | 1063 | $class[] = $this->getCFGDef('currentClass', 'current'); |
| 1064 | - } else { |
|
| 1064 | + } else {
|
|
| 1065 | 1065 | $data[$this->getCFGDef("sysKey", "dl") . '.active'] = 0; |
| 1066 | 1066 | } |
| 1067 | 1067 | |
@@ -1072,8 +1072,8 @@ discard block |
||
| 1072 | 1072 | * @var $extE e_DL_Extender |
| 1073 | 1073 | */ |
| 1074 | 1074 | $extE = $this->getExtender('e', true, true); |
| 1075 | - if ($out = $extE->init($this, compact('data'))) { |
|
| 1076 | - if (is_array($out)) { |
|
| 1075 | + if ($out = $extE->init($this, compact('data'))) {
|
|
| 1076 | + if (is_array($out)) {
|
|
| 1077 | 1077 | $data = $out; |
| 1078 | 1078 | } |
| 1079 | 1079 | } |
@@ -1089,42 +1089,43 @@ discard block |
||
| 1089 | 1089 | * @param array $array данные которые необходимо примешать к ответу на каждой записи $data |
| 1090 | 1090 | * @return string JSON строка |
| 1091 | 1091 | */ |
| 1092 | - public function getJSON($data, $fields, $array = array()) |
|
| 1093 | - { |
|
| 1092 | + public function getJSON($data, $fields, $array = array()) |
|
| 1093 | + {
|
|
| 1094 | 1094 | $out = array(); |
| 1095 | 1095 | $fields = is_array($fields) ? $fields : explode(",", $fields); |
| 1096 | - if (is_array($array) && count($array) > 0) { |
|
| 1096 | + if (is_array($array) && count($array) > 0) {
|
|
| 1097 | 1097 | $tmp = array(); |
| 1098 | - foreach ($data as $i => $v) { //array_merge not valid work with integer index key |
|
| 1098 | + foreach ($data as $i => $v) {
|
|
| 1099 | +//array_merge not valid work with integer index key |
|
| 1099 | 1100 | $tmp[$i] = (isset($array[$i]) ? array_merge($v, $array[$i]) : $v); |
| 1100 | 1101 | } |
| 1101 | 1102 | $data = $tmp; |
| 1102 | 1103 | } |
| 1103 | 1104 | |
| 1104 | - foreach ($data as $num => $doc) { |
|
| 1105 | + foreach ($data as $num => $doc) {
|
|
| 1105 | 1106 | $tmp = array(); |
| 1106 | - foreach ($doc as $name => $value) { |
|
| 1107 | - if (in_array($name, $fields) || (isset($fields[0]) && $fields[0] == '1')) { |
|
| 1107 | + foreach ($doc as $name => $value) {
|
|
| 1108 | + if (in_array($name, $fields) || (isset($fields[0]) && $fields[0] == '1')) {
|
|
| 1108 | 1109 | $tmp[str_replace(".", "_", $name)] = $value; //JSON element name without dot |
| 1109 | 1110 | } |
| 1110 | 1111 | } |
| 1111 | 1112 | $out[$num] = $tmp; |
| 1112 | 1113 | } |
| 1113 | 1114 | |
| 1114 | - if ('new' == $this->getCFGDef('JSONformat', 'old')) { |
|
| 1115 | + if ('new' == $this->getCFGDef('JSONformat', 'old')) {
|
|
| 1115 | 1116 | $return = array(); |
| 1116 | 1117 | |
| 1117 | 1118 | $return['rows'] = array(); |
| 1118 | - foreach ($out as $key => $item) { |
|
| 1119 | + foreach ($out as $key => $item) {
|
|
| 1119 | 1120 | $return['rows'][] = $item; |
| 1120 | 1121 | } |
| 1121 | 1122 | $return['total'] = $this->getChildrenCount(); |
| 1122 | - } elseif ('simple' == $this->getCFGDef('JSONformat', 'old')) { |
|
| 1123 | + } elseif ('simple' == $this->getCFGDef('JSONformat', 'old')) {
|
|
| 1123 | 1124 | $return = array(); |
| 1124 | - foreach ($out as $key => $item) { |
|
| 1125 | + foreach ($out as $key => $item) {
|
|
| 1125 | 1126 | $return[] = $item; |
| 1126 | 1127 | } |
| 1127 | - } else { |
|
| 1128 | + } else {
|
|
| 1128 | 1129 | $return = $out; |
| 1129 | 1130 | } |
| 1130 | 1131 | $this->outData = json_encode($return); |
@@ -1140,11 +1141,11 @@ discard block |
||
| 1140 | 1141 | * @param string $contentField |
| 1141 | 1142 | * @return mixed|string |
| 1142 | 1143 | */ |
| 1143 | - protected function getSummary(array $item = array(), $extSummary = null, $introField = '', $contentField = '') |
|
| 1144 | - { |
|
| 1144 | + protected function getSummary(array $item = array(), $extSummary = null, $introField = '', $contentField = '') |
|
| 1145 | + {
|
|
| 1145 | 1146 | $out = ''; |
| 1146 | 1147 | |
| 1147 | - if (is_null($extSummary)) { |
|
| 1148 | + if (is_null($extSummary)) {
|
|
| 1148 | 1149 | /** |
| 1149 | 1150 | * @var $extSummary summary_DL_Extender |
| 1150 | 1151 | */ |
@@ -1153,10 +1154,10 @@ discard block |
||
| 1153 | 1154 | $introField = $this->getCFGDef("introField", $introField); |
| 1154 | 1155 | $contentField = $this->getCFGDef("contentField", $contentField); |
| 1155 | 1156 | |
| 1156 | - if (!empty($introField) && !empty($item[$introField]) && mb_strlen($item[$introField], 'UTF-8') > 0) { |
|
| 1157 | + if (!empty($introField) && !empty($item[$introField]) && mb_strlen($item[$introField], 'UTF-8') > 0) {
|
|
| 1157 | 1158 | $out = $item[$introField]; |
| 1158 | - } else { |
|
| 1159 | - if (!empty($contentField) && !empty($item[$contentField]) && mb_strlen($item[$contentField], 'UTF-8') > 0) { |
|
| 1159 | + } else {
|
|
| 1160 | + if (!empty($contentField) && !empty($item[$contentField]) && mb_strlen($item[$contentField], 'UTF-8') > 0) {
|
|
| 1160 | 1161 | $out = $extSummary->init($this, array( |
| 1161 | 1162 | "content" => $item[$contentField], |
| 1162 | 1163 | "action" => $this->getCFGDef("summary", ""), |
@@ -1174,8 +1175,8 @@ discard block |
||
| 1174 | 1175 | * @param string $name extender name |
| 1175 | 1176 | * @return boolean status extender load |
| 1176 | 1177 | */ |
| 1177 | - public function checkExtender($name) |
|
| 1178 | - { |
|
| 1178 | + public function checkExtender($name) |
|
| 1179 | + {
|
|
| 1179 | 1180 | return (isset($this->extender[$name]) && $this->extender[$name] instanceof $name . "_DL_Extender"); |
| 1180 | 1181 | } |
| 1181 | 1182 | |
@@ -1183,8 +1184,8 @@ discard block |
||
| 1183 | 1184 | * @param $name |
| 1184 | 1185 | * @param $obj |
| 1185 | 1186 | */ |
| 1186 | - public function setExtender($name, $obj) |
|
| 1187 | - { |
|
| 1187 | + public function setExtender($name, $obj) |
|
| 1188 | + {
|
|
| 1188 | 1189 | $this->extender[$name] = $obj; |
| 1189 | 1190 | } |
| 1190 | 1191 | |
@@ -1196,13 +1197,13 @@ discard block |
||
| 1196 | 1197 | * @param bool $nop если экстендер не загружен, то загружать ли xNop |
| 1197 | 1198 | * @return null|xNop |
| 1198 | 1199 | */ |
| 1199 | - public function getExtender($name, $autoload = false, $nop = false) |
|
| 1200 | - { |
|
| 1200 | + public function getExtender($name, $autoload = false, $nop = false) |
|
| 1201 | + {
|
|
| 1201 | 1202 | $out = null; |
| 1202 | - if ((is_scalar($name) && $this->checkExtender($name)) || ($autoload && $this->_loadExtender($name))) { |
|
| 1203 | + if ((is_scalar($name) && $this->checkExtender($name)) || ($autoload && $this->_loadExtender($name))) {
|
|
| 1203 | 1204 | $out = $this->extender[$name]; |
| 1204 | 1205 | } |
| 1205 | - if ($nop && is_null($out)) { |
|
| 1206 | + if ($nop && is_null($out)) {
|
|
| 1206 | 1207 | $out = new xNop(); |
| 1207 | 1208 | } |
| 1208 | 1209 | |
@@ -1215,27 +1216,27 @@ discard block |
||
| 1215 | 1216 | * @param string $name name extender |
| 1216 | 1217 | * @return boolean $flag status load extender |
| 1217 | 1218 | */ |
| 1218 | - protected function _loadExtender($name) |
|
| 1219 | - { |
|
| 1219 | + protected function _loadExtender($name) |
|
| 1220 | + {
|
|
| 1220 | 1221 | $this->debug->debug('Load Extender ' . $this->debug->dumpData($name), 'LoadExtender', 2); |
| 1221 | 1222 | $flag = false; |
| 1222 | 1223 | |
| 1223 | 1224 | $classname = ($name != '') ? $name . "_DL_Extender" : ""; |
| 1224 | - if ($classname != '' && isset($this->extender[$name]) && $this->extender[$name] instanceof $classname) { |
|
| 1225 | + if ($classname != '' && isset($this->extender[$name]) && $this->extender[$name] instanceof $classname) {
|
|
| 1225 | 1226 | $flag = true; |
| 1226 | 1227 | |
| 1227 | - } else { |
|
| 1228 | - if (!class_exists($classname, false) && $classname != '') { |
|
| 1229 | - if (file_exists(dirname(__FILE__) . "/extender/" . $name . ".extender.inc")) { |
|
| 1228 | + } else {
|
|
| 1229 | + if (!class_exists($classname, false) && $classname != '') {
|
|
| 1230 | + if (file_exists(dirname(__FILE__) . "/extender/" . $name . ".extender.inc")) {
|
|
| 1230 | 1231 | include_once(dirname(__FILE__) . "/extender/" . $name . ".extender.inc"); |
| 1231 | 1232 | } |
| 1232 | 1233 | } |
| 1233 | - if (class_exists($classname, false) && $classname != '') { |
|
| 1234 | + if (class_exists($classname, false) && $classname != '') {
|
|
| 1234 | 1235 | $this->extender[$name] = new $classname($this, $name); |
| 1235 | 1236 | $flag = true; |
| 1236 | 1237 | } |
| 1237 | 1238 | } |
| 1238 | - if (!$flag) { |
|
| 1239 | + if (!$flag) {
|
|
| 1239 | 1240 | $this->debug->debug("Error load Extender " . $this->debug->dumpData($name)); |
| 1240 | 1241 | } |
| 1241 | 1242 | $this->debug->debugEnd('LoadExtender'); |
@@ -1253,16 +1254,16 @@ discard block |
||
| 1253 | 1254 | * @param mixed $IDs список id документов по которым необходима выборка |
| 1254 | 1255 | * @return array очищенный массив |
| 1255 | 1256 | */ |
| 1256 | - public function setIDs($IDs) |
|
| 1257 | - { |
|
| 1257 | + public function setIDs($IDs) |
|
| 1258 | + {
|
|
| 1258 | 1259 | $this->debug->debug('set ID list ' . $this->debug->dumpData($IDs), 'setIDs', 2); |
| 1259 | 1260 | $IDs = $this->cleanIDs($IDs); |
| 1260 | 1261 | $type = $this->getCFGDef('idType', 'parents'); |
| 1261 | 1262 | $depth = $this->getCFGDef('depth', ''); |
| 1262 | - if ($type == 'parents' && $depth > 0) { |
|
| 1263 | + if ($type == 'parents' && $depth > 0) {
|
|
| 1263 | 1264 | $tmp = $IDs; |
| 1264 | - do { |
|
| 1265 | - if (count($tmp) > 0) { |
|
| 1265 | + do {
|
|
| 1266 | + if (count($tmp) > 0) {
|
|
| 1266 | 1267 | $tmp = $this->getChildrenFolder($tmp); |
| 1267 | 1268 | $IDs = array_merge($IDs, $tmp); |
| 1268 | 1269 | } |
@@ -1276,8 +1277,8 @@ discard block |
||
| 1276 | 1277 | /** |
| 1277 | 1278 | * @return int |
| 1278 | 1279 | */ |
| 1279 | - public function getIDs() |
|
| 1280 | - { |
|
| 1280 | + public function getIDs() |
|
| 1281 | + {
|
|
| 1281 | 1282 | return $this->IDs; |
| 1282 | 1283 | } |
| 1283 | 1284 | |
@@ -1288,17 +1289,18 @@ discard block |
||
| 1288 | 1289 | * @param string $sep разделитель |
| 1289 | 1290 | * @return array очищенный массив с данными |
| 1290 | 1291 | */ |
| 1291 | - public function cleanIDs($IDs, $sep = ',') |
|
| 1292 | - { |
|
| 1292 | + public function cleanIDs($IDs, $sep = ',') |
|
| 1293 | + {
|
|
| 1293 | 1294 | $this->debug->debug('clean IDs ' . $this->debug->dumpData($IDs) . ' with separator ' . $this->debug->dumpData($sep), |
| 1294 | 1295 | 'cleanIDs', 2); |
| 1295 | 1296 | $out = array(); |
| 1296 | - if (!is_array($IDs)) { |
|
| 1297 | + if (!is_array($IDs)) {
|
|
| 1297 | 1298 | $IDs = explode($sep, $IDs); |
| 1298 | 1299 | } |
| 1299 | - foreach ($IDs as $item) { |
|
| 1300 | + foreach ($IDs as $item) {
|
|
| 1300 | 1301 | $item = trim($item); |
| 1301 | - if (is_numeric($item) && (int)$item >= 0) { //Fix 0xfffffffff |
|
| 1302 | + if (is_numeric($item) && (int)$item >= 0) {
|
|
| 1303 | +//Fix 0xfffffffff |
|
| 1302 | 1304 | $out[] = (int)$item; |
| 1303 | 1305 | } |
| 1304 | 1306 | } |
@@ -1312,8 +1314,8 @@ discard block |
||
| 1312 | 1314 | * Проверка массива с id-шниками документов для выборки |
| 1313 | 1315 | * @return boolean пригодны ли данные для дальнейшего использования |
| 1314 | 1316 | */ |
| 1315 | - protected function checkIDs() |
|
| 1316 | - { |
|
| 1317 | + protected function checkIDs() |
|
| 1318 | + {
|
|
| 1317 | 1319 | return (is_array($this->IDs) && count($this->IDs) > 0) ? true : false; |
| 1318 | 1320 | } |
| 1319 | 1321 | |
@@ -1325,11 +1327,11 @@ discard block |
||
| 1325 | 1327 | * @global array $_docs all documents |
| 1326 | 1328 | * @return array all field values |
| 1327 | 1329 | */ |
| 1328 | - public function getOneField($userField, $uniq = false) |
|
| 1329 | - { |
|
| 1330 | + public function getOneField($userField, $uniq = false) |
|
| 1331 | + {
|
|
| 1330 | 1332 | $out = array(); |
| 1331 | - foreach ($this->_docs as $doc => $val) { |
|
| 1332 | - if (isset($val[$userField]) && (($uniq && !in_array($val[$userField], $out)) || !$uniq)) { |
|
| 1333 | + foreach ($this->_docs as $doc => $val) {
|
|
| 1334 | + if (isset($val[$userField]) && (($uniq && !in_array($val[$userField], $out)) || !$uniq)) {
|
|
| 1333 | 1335 | $out[$doc] = $val[$userField]; |
| 1334 | 1336 | } |
| 1335 | 1337 | } |
@@ -1340,8 +1342,8 @@ discard block |
||
| 1340 | 1342 | /** |
| 1341 | 1343 | * @return DLCollection |
| 1342 | 1344 | */ |
| 1343 | - public function docsCollection() |
|
| 1344 | - { |
|
| 1345 | + public function docsCollection() |
|
| 1346 | + {
|
|
| 1345 | 1347 | return new DLCollection($this->modx, $this->_docs); |
| 1346 | 1348 | } |
| 1347 | 1349 | |
@@ -1369,10 +1371,10 @@ discard block |
||
| 1369 | 1371 | * @param string $group |
| 1370 | 1372 | * @return string |
| 1371 | 1373 | */ |
| 1372 | - protected function getGroupSQL($group = '') |
|
| 1373 | - { |
|
| 1374 | + protected function getGroupSQL($group = '') |
|
| 1375 | + {
|
|
| 1374 | 1376 | $out = ''; |
| 1375 | - if ($group != '') { |
|
| 1377 | + if ($group != '') {
|
|
| 1376 | 1378 | $out = 'GROUP BY ' . $group; |
| 1377 | 1379 | } |
| 1378 | 1380 | |
@@ -1391,12 +1393,12 @@ discard block |
||
| 1391 | 1393 | * |
| 1392 | 1394 | * @return string Order by for SQL |
| 1393 | 1395 | */ |
| 1394 | - protected function SortOrderSQL($sortName, $orderDef = 'DESC') |
|
| 1395 | - { |
|
| 1396 | + protected function SortOrderSQL($sortName, $orderDef = 'DESC') |
|
| 1397 | + {
|
|
| 1396 | 1398 | $this->debug->debug('', 'sortORDER', 2); |
| 1397 | 1399 | |
| 1398 | 1400 | $sort = ''; |
| 1399 | - switch ($this->getCFGDef('sortType', '')) { |
|
| 1401 | + switch ($this->getCFGDef('sortType', '')) {
|
|
| 1400 | 1402 | case 'none': |
| 1401 | 1403 | break; |
| 1402 | 1404 | case 'doclist': |
@@ -1407,10 +1409,10 @@ discard block |
||
| 1407 | 1409 | break; |
| 1408 | 1410 | default: |
| 1409 | 1411 | $out = array('orderBy' => '', 'order' => '', 'sortBy' => ''); |
| 1410 | - if (($tmp = $this->getCFGDef('orderBy', '')) != '') { |
|
| 1412 | + if (($tmp = $this->getCFGDef('orderBy', '')) != '') {
|
|
| 1411 | 1413 | $out['orderBy'] = $tmp; |
| 1412 | - } else { |
|
| 1413 | - switch (true) { |
|
| 1414 | + } else {
|
|
| 1415 | + switch (true) {
|
|
| 1414 | 1416 | case ('' != ($tmp = $this->getCFGDef('sortDir', ''))): //higher priority than order |
| 1415 | 1417 | $out['order'] = $tmp; |
| 1416 | 1418 | // no break |
@@ -1418,7 +1420,7 @@ discard block |
||
| 1418 | 1420 | $out['order'] = $tmp; |
| 1419 | 1421 | // no break |
| 1420 | 1422 | } |
| 1421 | - if ('' == $out['order'] || !in_array(strtoupper($out['order']), array('ASC', 'DESC'))) { |
|
| 1423 | + if ('' == $out['order'] || !in_array(strtoupper($out['order']), array('ASC', 'DESC'))) {
|
|
| 1422 | 1424 | $out['order'] = $orderDef; //Default |
| 1423 | 1425 | } |
| 1424 | 1426 | |
@@ -1439,30 +1441,30 @@ discard block |
||
| 1439 | 1441 | * |
| 1440 | 1442 | * @return string LIMIT вставка в SQL запрос |
| 1441 | 1443 | */ |
| 1442 | - protected function LimitSQL($limit = 0, $offset = 0) |
|
| 1443 | - { |
|
| 1444 | + protected function LimitSQL($limit = 0, $offset = 0) |
|
| 1445 | + {
|
|
| 1444 | 1446 | $this->debug->debug('', 'limitSQL', 2); |
| 1445 | 1447 | $ret = ''; |
| 1446 | - if ($limit == 0) { |
|
| 1448 | + if ($limit == 0) {
|
|
| 1447 | 1449 | $limit = $this->getCFGDef('display', 0); |
| 1448 | 1450 | } |
| 1449 | 1451 | $maxDocs = $this->getCFGDef('maxDocs', 0); |
| 1450 | - if ($maxDocs > 0 && $limit > $maxDocs) { |
|
| 1452 | + if ($maxDocs > 0 && $limit > $maxDocs) {
|
|
| 1451 | 1453 | $limit = $maxDocs; |
| 1452 | 1454 | } |
| 1453 | - if ($offset == 0) { |
|
| 1455 | + if ($offset == 0) {
|
|
| 1454 | 1456 | $offset = $this->getCFGDef('offset', 0); |
| 1455 | 1457 | } |
| 1456 | 1458 | $offset += $this->getCFGDef('start', 0); |
| 1457 | 1459 | $total = $this->getCFGDef('total', 0); |
| 1458 | - if ($limit < ($total - $limit)) { |
|
| 1460 | + if ($limit < ($total - $limit)) {
|
|
| 1459 | 1461 | $limit = $total - $offset; |
| 1460 | 1462 | } |
| 1461 | 1463 | |
| 1462 | - if ($limit != 0) { |
|
| 1464 | + if ($limit != 0) {
|
|
| 1463 | 1465 | $ret = "LIMIT " . (int)$offset . "," . (int)$limit; |
| 1464 | - } else { |
|
| 1465 | - if ($offset != 0) { |
|
| 1466 | + } else {
|
|
| 1467 | + if ($offset != 0) {
|
|
| 1466 | 1468 | /** |
| 1467 | 1469 | * 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 |
| 1468 | 1470 | * @see http://dev.mysql.com/doc/refman/5.0/en/select.html |
@@ -1482,8 +1484,8 @@ discard block |
||
| 1482 | 1484 | * @param string $charset |
| 1483 | 1485 | * @return string Clear string |
| 1484 | 1486 | */ |
| 1485 | - public function sanitarData($data, $charset = 'UTF-8') |
|
| 1486 | - { |
|
| 1487 | + public function sanitarData($data, $charset = 'UTF-8') |
|
| 1488 | + {
|
|
| 1487 | 1489 | return APIHelpers::sanitarTag($data, $charset); |
| 1488 | 1490 | } |
| 1489 | 1491 | |
@@ -1494,8 +1496,8 @@ discard block |
||
| 1494 | 1496 | * @param string $parentField default name parent field |
| 1495 | 1497 | * @return array |
| 1496 | 1498 | */ |
| 1497 | - public function treeBuild($idField = 'id', $parentField = 'parent') |
|
| 1498 | - { |
|
| 1499 | + public function treeBuild($idField = 'id', $parentField = 'parent') |
|
| 1500 | + {
|
|
| 1499 | 1501 | return $this->_treeBuild($this->_docs, $this->getCFGDef('idField', $idField), |
| 1500 | 1502 | $this->getCFGDef('parentField', $parentField)); |
| 1501 | 1503 | } |
@@ -1508,16 +1510,16 @@ discard block |
||
| 1508 | 1510 | * @param string $pidName name parent field in associative data array |
| 1509 | 1511 | * @return array |
| 1510 | 1512 | */ |
| 1511 | - private function _treeBuild($data, $idName, $pidName) |
|
| 1512 | - { |
|
| 1513 | + private function _treeBuild($data, $idName, $pidName) |
|
| 1514 | + {
|
|
| 1513 | 1515 | $children = array(); // children of each ID |
| 1514 | 1516 | $ids = array(); |
| 1515 | - foreach ($data as $i => $r) { |
|
| 1517 | + foreach ($data as $i => $r) {
|
|
| 1516 | 1518 | $row =& $data[$i]; |
| 1517 | 1519 | $id = $row[$idName]; |
| 1518 | 1520 | $pid = $row[$pidName]; |
| 1519 | 1521 | $children[$pid][$id] =& $row; |
| 1520 | - if (!isset($children[$id])) { |
|
| 1522 | + if (!isset($children[$id])) {
|
|
| 1521 | 1523 | $children[$id] = array(); |
| 1522 | 1524 | } |
| 1523 | 1525 | $row['#childNodes'] =& $children[$id]; |
@@ -1525,9 +1527,9 @@ discard block |
||
| 1525 | 1527 | } |
| 1526 | 1528 | // Root elements are elements with non-found PIDs. |
| 1527 | 1529 | $this->_tree = array(); |
| 1528 | - foreach ($data as $i => $r) { |
|
| 1530 | + foreach ($data as $i => $r) {
|
|
| 1529 | 1531 | $row =& $data[$i]; |
| 1530 | - if (!isset($ids[$row[$pidName]])) { |
|
| 1532 | + if (!isset($ids[$row[$pidName]])) {
|
|
| 1531 | 1533 | $this->_tree[$row[$idName]] = $row; |
| 1532 | 1534 | } |
| 1533 | 1535 | } |
@@ -1541,12 +1543,12 @@ discard block |
||
| 1541 | 1543 | * @param bool $full если true то возвращается значение для подстановки в запрос |
| 1542 | 1544 | * @return string PrimaryKey основной таблицы |
| 1543 | 1545 | */ |
| 1544 | - public function getPK($full = true) |
|
| 1545 | - { |
|
| 1546 | + public function getPK($full = true) |
|
| 1547 | + {
|
|
| 1546 | 1548 | $idField = isset($this->idField) ? $this->idField: 'id'; |
| 1547 | - if ($full) { |
|
| 1549 | + if ($full) {
|
|
| 1548 | 1550 | $idField = '`' . $idField . '`'; |
| 1549 | - if (!empty($this->alias)) { |
|
| 1551 | + if (!empty($this->alias)) {
|
|
| 1550 | 1552 | $idField = '`' . $this->alias . '`.' . $idField; |
| 1551 | 1553 | } |
| 1552 | 1554 | } |
@@ -1560,12 +1562,12 @@ discard block |
||
| 1560 | 1562 | * @param bool $full если true то возвращается значение для подстановки в запрос |
| 1561 | 1563 | * @return string Parent Key основной таблицы |
| 1562 | 1564 | */ |
| 1563 | - public function getParentField($full = true) |
|
| 1564 | - { |
|
| 1565 | + public function getParentField($full = true) |
|
| 1566 | + {
|
|
| 1565 | 1567 | $parentField = isset($this->parentField) ? $this->parentField : ''; |
| 1566 | - if ($full && !empty($parentField)) { |
|
| 1568 | + if ($full && !empty($parentField)) {
|
|
| 1567 | 1569 | $parentField = '`' . $parentField . '`'; |
| 1568 | - if (!empty($this->alias)) { |
|
| 1570 | + if (!empty($this->alias)) {
|
|
| 1569 | 1571 | $parentField = '`' . $this->alias . '`.' . $parentField; |
| 1570 | 1572 | } |
| 1571 | 1573 | } |
@@ -1580,31 +1582,31 @@ discard block |
||
| 1580 | 1582 | * @param string $filter_string строка со всеми фильтрами |
| 1581 | 1583 | * @return mixed результат разбора фильтров |
| 1582 | 1584 | */ |
| 1583 | - protected function getFilters($filter_string) |
|
| 1584 | - { |
|
| 1585 | + protected function getFilters($filter_string) |
|
| 1586 | + {
|
|
| 1585 | 1587 | $this->debug->debug("getFilters: " . $this->debug->dumpData($filter_string), 'getFilter', 1); |
| 1586 | 1588 | // the filter parameter tells us, which filters can be used in this query |
| 1587 | 1589 | $filter_string = trim($filter_string, ' ;'); |
| 1588 | - if (!$filter_string) { |
|
| 1590 | + if (!$filter_string) {
|
|
| 1589 | 1591 | return; |
| 1590 | 1592 | } |
| 1591 | 1593 | $output = array('join' => '', 'where' => ''); |
| 1592 | 1594 | $logic_op_found = false; |
| 1593 | 1595 | $joins = $wheres = array(); |
| 1594 | - foreach ($this->_logic_ops as $op => $sql) { |
|
| 1595 | - if (strpos($filter_string, $op) === 0) { |
|
| 1596 | + foreach ($this->_logic_ops as $op => $sql) {
|
|
| 1597 | + if (strpos($filter_string, $op) === 0) {
|
|
| 1596 | 1598 | $logic_op_found = true; |
| 1597 | 1599 | $subfilters = mb_substr($filter_string, strlen($op) + 1, mb_strlen($filter_string, "UTF-8"), "UTF-8"); |
| 1598 | 1600 | $subfilters = $this->smartSplit($subfilters); |
| 1599 | - foreach ($subfilters as $subfilter) { |
|
| 1601 | + foreach ($subfilters as $subfilter) {
|
|
| 1600 | 1602 | $subfilter = $this->getFilters(trim($subfilter)); |
| 1601 | - if (!$subfilter) { |
|
| 1603 | + if (!$subfilter) {
|
|
| 1602 | 1604 | continue; |
| 1603 | 1605 | } |
| 1604 | - if ($subfilter['join']) { |
|
| 1606 | + if ($subfilter['join']) {
|
|
| 1605 | 1607 | $joins[] = $subfilter['join']; |
| 1606 | 1608 | } |
| 1607 | - if ($subfilter['where']) { |
|
| 1609 | + if ($subfilter['where']) {
|
|
| 1608 | 1610 | $wheres[] = $subfilter['where']; |
| 1609 | 1611 | } |
| 1610 | 1612 | } |
@@ -1613,12 +1615,12 @@ discard block |
||
| 1613 | 1615 | } |
| 1614 | 1616 | } |
| 1615 | 1617 | |
| 1616 | - if (!$logic_op_found) { |
|
| 1618 | + if (!$logic_op_found) {
|
|
| 1617 | 1619 | $filter = $this->loadFilter($filter_string); |
| 1618 | - if (!$filter) { |
|
| 1620 | + if (!$filter) {
|
|
| 1619 | 1621 | $this->debug->warning('Error while loading DocLister filter "' . $this->debug->dumpData($filter_string) . '": check syntax!'); |
| 1620 | 1622 | $output = false; |
| 1621 | - } else { |
|
| 1623 | + } else {
|
|
| 1622 | 1624 | $output['join'] = $filter->get_join(); |
| 1623 | 1625 | $output['where'] = stripslashes($filter->get_where()); |
| 1624 | 1626 | } |
@@ -1631,16 +1633,16 @@ discard block |
||
| 1631 | 1633 | /** |
| 1632 | 1634 | * @return mixed |
| 1633 | 1635 | */ |
| 1634 | - public function filtersWhere() |
|
| 1635 | - { |
|
| 1636 | + public function filtersWhere() |
|
| 1637 | + {
|
|
| 1636 | 1638 | return APIHelpers::getkey($this->_filters, 'where', ''); |
| 1637 | 1639 | } |
| 1638 | 1640 | |
| 1639 | 1641 | /** |
| 1640 | 1642 | * @return mixed |
| 1641 | 1643 | */ |
| 1642 | - public function filtersJoin() |
|
| 1643 | - { |
|
| 1644 | + public function filtersJoin() |
|
| 1645 | + {
|
|
| 1644 | 1646 | return APIHelpers::getkey($this->_filters, 'join', ''); |
| 1645 | 1647 | } |
| 1646 | 1648 | |
@@ -1648,11 +1650,12 @@ discard block |
||
| 1648 | 1650 | * @param string $join |
| 1649 | 1651 | * @return $this |
| 1650 | 1652 | */ |
| 1651 | - public function setFiltersJoin($join = '') { |
|
| 1652 | - if (!empty($join)) { |
|
| 1653 | - if (!empty($this->_filters['join'])) { |
|
| 1653 | + public function setFiltersJoin($join = '') |
|
| 1654 | + {
|
|
| 1655 | + if (!empty($join)) {
|
|
| 1656 | + if (!empty($this->_filters['join'])) {
|
|
| 1654 | 1657 | $this->_filters['join'] .= ' ' . $join; |
| 1655 | - } else { |
|
| 1658 | + } else {
|
|
| 1656 | 1659 | $this->_filters['join'] = $join; |
| 1657 | 1660 | } |
| 1658 | 1661 | } |
@@ -1667,10 +1670,10 @@ discard block |
||
| 1667 | 1670 | * @param $type string тип фильтрации |
| 1668 | 1671 | * @return string имя поля с учетом приведения типа |
| 1669 | 1672 | */ |
| 1670 | - public function changeSortType($field, $type) |
|
| 1671 | - { |
|
| 1673 | + public function changeSortType($field, $type) |
|
| 1674 | + {
|
|
| 1672 | 1675 | $type = trim($type); |
| 1673 | - switch (strtoupper($type)) { |
|
| 1676 | + switch (strtoupper($type)) {
|
|
| 1674 | 1677 | case 'DECIMAL': |
| 1675 | 1678 | $field = 'CAST(' . $field . ' as DECIMAL(10,2))'; |
| 1676 | 1679 | break; |
@@ -1696,14 +1699,14 @@ discard block |
||
| 1696 | 1699 | * @param string $filter срока с параметрами фильтрации |
| 1697 | 1700 | * @return bool |
| 1698 | 1701 | */ |
| 1699 | - protected function loadFilter($filter) |
|
| 1700 | - { |
|
| 1702 | + protected function loadFilter($filter) |
|
| 1703 | + {
|
|
| 1701 | 1704 | $this->debug->debug('Load filter ' . $this->debug->dumpData($filter), 'loadFilter', 2); |
| 1702 | 1705 | $out = false; |
| 1703 | 1706 | $fltr_params = explode(':', $filter, 2); |
| 1704 | 1707 | $fltr = APIHelpers::getkey($fltr_params, 0, null); |
| 1705 | 1708 | // check if the filter is implemented |
| 1706 | - if (!is_null($fltr) && file_exists(dirname(__FILE__) . '/filter/' . $fltr . '.filter.php')) { |
|
| 1709 | + if (!is_null($fltr) && file_exists(dirname(__FILE__) . '/filter/' . $fltr . '.filter.php')) {
|
|
| 1707 | 1710 | require_once dirname(__FILE__) . '/filter/' . $fltr . '.filter.php'; |
| 1708 | 1711 | /** |
| 1709 | 1712 | * @var tv_DL_filter|content_DL_filter $fltr_class |
@@ -1711,12 +1714,12 @@ discard block |
||
| 1711 | 1714 | $fltr_class = $fltr . '_DL_filter'; |
| 1712 | 1715 | $this->totalFilters++; |
| 1713 | 1716 | $fltr_obj = new $fltr_class(); |
| 1714 | - if ($fltr_obj->init($this, $filter)) { |
|
| 1717 | + if ($fltr_obj->init($this, $filter)) {
|
|
| 1715 | 1718 | $out = $fltr_obj; |
| 1716 | - } else { |
|
| 1719 | + } else {
|
|
| 1717 | 1720 | $this->debug->error("Wrong filter parameter: '{$this->debug->dumpData($filter)}'", 'Filter'); |
| 1718 | 1721 | } |
| 1719 | - } else { |
|
| 1722 | + } else {
|
|
| 1720 | 1723 | $this->debug->error("Error load Filter: '{$this->debug->dumpData($filter)}'", 'Filter'); |
| 1721 | 1724 | } |
| 1722 | 1725 | $this->debug->debugEnd("loadFilter"); |
@@ -1728,8 +1731,8 @@ discard block |
||
| 1728 | 1731 | * Общее число фильтров |
| 1729 | 1732 | * @return int |
| 1730 | 1733 | */ |
| 1731 | - public function getCountFilters() |
|
| 1732 | - { |
|
| 1734 | + public function getCountFilters() |
|
| 1735 | + {
|
|
| 1733 | 1736 | return (int)$this->totalFilters; |
| 1734 | 1737 | } |
| 1735 | 1738 | |
@@ -1737,8 +1740,8 @@ discard block |
||
| 1737 | 1740 | * Выполнить SQL запрос |
| 1738 | 1741 | * @param string $q SQL запрос |
| 1739 | 1742 | */ |
| 1740 | - public function dbQuery($q) |
|
| 1741 | - { |
|
| 1743 | + public function dbQuery($q) |
|
| 1744 | + {
|
|
| 1742 | 1745 | $this->debug->debug($q, "query", 1, 'sql'); |
| 1743 | 1746 | $out = $this->modx->db->query($q); |
| 1744 | 1747 | $this->debug->debugEnd("query"); |
@@ -1756,8 +1759,8 @@ discard block |
||
| 1756 | 1759 | * @param string $tpl шаблон подстановки значения в SQL запрос |
| 1757 | 1760 | * @return string строка для подстановки в SQL запрос |
| 1758 | 1761 | */ |
| 1759 | - public function LikeEscape($field, $value, $escape = '=', $tpl = '%[+value+]%') |
|
| 1760 | - { |
|
| 1762 | + public function LikeEscape($field, $value, $escape = '=', $tpl = '%[+value+]%') |
|
| 1763 | + {
|
|
| 1761 | 1764 | return sqlHelper::LikeEscape($this->modx, $field, $value, $escape, $tpl); |
| 1762 | 1765 | } |
| 1763 | 1766 | |
@@ -1765,8 +1768,8 @@ discard block |
||
| 1765 | 1768 | * Получение REQUEST_URI без GET-ключа с |
| 1766 | 1769 | * @return string |
| 1767 | 1770 | */ |
| 1768 | - public function getRequest() |
|
| 1769 | - { |
|
| 1771 | + public function getRequest() |
|
| 1772 | + {
|
|
| 1770 | 1773 | $URL = null; |
| 1771 | 1774 | parse_str(parse_url(MODX_SITE_URL . $_SERVER['REQUEST_URI'], PHP_URL_QUERY), $URL); |
| 1772 | 1775 | |