@@ -7,15 +7,15 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * Class MODxAPIhelpers |
9 | 9 | */ |
10 | -class MODxAPIhelpers |
|
11 | -{ |
|
10 | +class MODxAPIhelpers |
|
11 | +{ |
|
12 | 12 | /** |
13 | 13 | * @param $email |
14 | 14 | * @param bool $dns |
15 | 15 | * @return false|string |
16 | 16 | */ |
17 | - public function emailValidate($email, $dns = true) |
|
18 | - { |
|
17 | + public function emailValidate($email, $dns = true) |
|
18 | + { |
|
19 | 19 | return \APIhelpers::emailValidate($email, $dns); |
20 | 20 | } |
21 | 21 | |
@@ -24,8 +24,8 @@ discard block |
||
24 | 24 | * @param string $data |
25 | 25 | * @return string |
26 | 26 | */ |
27 | - public function genPass($len, $data = '') |
|
28 | - { |
|
27 | + public function genPass($len, $data = '') |
|
28 | + { |
|
29 | 29 | return \APIhelpers::genPass($len, $data); |
30 | 30 | } |
31 | 31 | |
@@ -33,8 +33,8 @@ discard block |
||
33 | 33 | * @param string $out |
34 | 34 | * @return string |
35 | 35 | */ |
36 | - public function getUserIP($out = '127.0.0.1') |
|
37 | - { |
|
36 | + public function getUserIP($out = '127.0.0.1') |
|
37 | + { |
|
38 | 38 | return \APIhelpers::getUserIP($out); |
39 | 39 | } |
40 | 40 | |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | * @param $data |
43 | 43 | * @return array|mixed|string |
44 | 44 | */ |
45 | - public function sanitarTag($data) |
|
46 | - { |
|
45 | + public function sanitarTag($data) |
|
46 | + { |
|
47 | 47 | return \APIhelpers::sanitarTag($data); |
48 | 48 | } |
49 | 49 | |
@@ -54,8 +54,8 @@ discard block |
||
54 | 54 | * @param array $mixArray |
55 | 55 | * @return bool |
56 | 56 | */ |
57 | - public function checkString($value, $minLen = 1, $alph = array(), $mixArray = array()) |
|
58 | - { |
|
57 | + public function checkString($value, $minLen = 1, $alph = array(), $mixArray = array()) |
|
58 | + { |
|
59 | 59 | return \APIhelpers::checkString($value, $minLen, $alph, $mixArray); |
60 | 60 | } |
61 | 61 | } |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | /** |
64 | 64 | * Class MODxAPI |
65 | 65 | */ |
66 | -abstract class MODxAPI extends MODxAPIhelpers |
|
67 | -{ |
|
66 | +abstract class MODxAPI extends MODxAPIhelpers |
|
67 | +{ |
|
68 | 68 | /** |
69 | 69 | * Объект DocumentParser - основной класс MODX |
70 | 70 | * @var \DocumentParser |
@@ -148,10 +148,10 @@ discard block |
||
148 | 148 | * @param bool $debug |
149 | 149 | * @throws Exception |
150 | 150 | */ |
151 | - public function __construct(DocumentParser $modx, $debug = false) |
|
152 | - { |
|
151 | + public function __construct(DocumentParser $modx, $debug = false) |
|
152 | + { |
|
153 | 153 | $this->modx = $modx; |
154 | - if (function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc()) { |
|
154 | + if (function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc()) { |
|
155 | 155 | throw new Exception('Magic Quotes is a deprecated and mostly useless setting that should be disabled. Please ask your server administrator to disable it in php.ini or in your webserver config.'); |
156 | 156 | } |
157 | 157 | |
@@ -163,8 +163,8 @@ discard block |
||
163 | 163 | * @param boolean $flag |
164 | 164 | * @return $this |
165 | 165 | */ |
166 | - public function setDebug($flag) |
|
167 | - { |
|
166 | + public function setDebug($flag) |
|
167 | + { |
|
168 | 168 | $this->_debug = (bool)$flag; |
169 | 169 | |
170 | 170 | return $this; |
@@ -173,16 +173,16 @@ discard block |
||
173 | 173 | /** |
174 | 174 | * @return bool |
175 | 175 | */ |
176 | - public function getDebug() |
|
177 | - { |
|
176 | + public function getDebug() |
|
177 | + { |
|
178 | 178 | return $this->_debug; |
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
182 | 182 | * @return array |
183 | 183 | */ |
184 | - public function getDefaultFields() |
|
185 | - { |
|
184 | + public function getDefaultFields() |
|
185 | + { |
|
186 | 186 | return $this->default_field; |
187 | 187 | } |
188 | 188 | |
@@ -191,8 +191,8 @@ discard block |
||
191 | 191 | * @param null $default |
192 | 192 | * @return mixed |
193 | 193 | */ |
194 | - final public function modxConfig($name, $default = null) |
|
195 | - { |
|
194 | + final public function modxConfig($name, $default = null) |
|
195 | + { |
|
196 | 196 | return APIHelpers::getkey($this->modx->config, $name, $default); |
197 | 197 | } |
198 | 198 | |
@@ -200,9 +200,9 @@ discard block |
||
200 | 200 | * @param $q |
201 | 201 | * @return $this |
202 | 202 | */ |
203 | - public function addQuery($q) |
|
204 | - { |
|
205 | - if (is_scalar($q) && !empty($q)) { |
|
203 | + public function addQuery($q) |
|
204 | + { |
|
205 | + if (is_scalar($q) && !empty($q)) { |
|
206 | 206 | $this->_query[] = $q; |
207 | 207 | } |
208 | 208 | |
@@ -212,8 +212,8 @@ discard block |
||
212 | 212 | /** |
213 | 213 | * @return array |
214 | 214 | */ |
215 | - public function getQueryList() |
|
216 | - { |
|
215 | + public function getQueryList() |
|
216 | + { |
|
217 | 217 | return $this->_query; |
218 | 218 | } |
219 | 219 | |
@@ -221,9 +221,9 @@ discard block |
||
221 | 221 | * @param $SQL |
222 | 222 | * @return mixed |
223 | 223 | */ |
224 | - final public function query($SQL) |
|
225 | - { |
|
226 | - if ($this->getDebug()) { |
|
224 | + final public function query($SQL) |
|
225 | + { |
|
226 | + if ($this->getDebug()) { |
|
227 | 227 | $this->addQuery($SQL); |
228 | 228 | } |
229 | 229 | |
@@ -234,11 +234,11 @@ discard block |
||
234 | 234 | * @param $value |
235 | 235 | * @return string|void |
236 | 236 | */ |
237 | - final public function escape($value) |
|
238 | - { |
|
239 | - if (!is_scalar($value)) { |
|
237 | + final public function escape($value) |
|
238 | + { |
|
239 | + if (!is_scalar($value)) { |
|
240 | 240 | $value = ''; |
241 | - } else { |
|
241 | + } else { |
|
242 | 242 | $value = $this->modx->db->escape($value); |
243 | 243 | } |
244 | 244 | |
@@ -251,10 +251,10 @@ discard block |
||
251 | 251 | * @param bool $flag |
252 | 252 | * @return $this |
253 | 253 | */ |
254 | - final public function invokeEvent($name, $data = array(), $flag = false) |
|
255 | - { |
|
254 | + final public function invokeEvent($name, $data = array(), $flag = false) |
|
255 | + { |
|
256 | 256 | $flag = (isset($flag) && $flag != '') ? (bool)$flag : false; |
257 | - if ($flag) { |
|
257 | + if ($flag) { |
|
258 | 258 | $this->modx->invokeEvent($name, $data); |
259 | 259 | } |
260 | 260 | |
@@ -267,8 +267,8 @@ discard block |
||
267 | 267 | * @param boolean $flag |
268 | 268 | * @return array|bool |
269 | 269 | */ |
270 | - final public function getInvokeEventResult($name, $data = array(), $flag = null) |
|
271 | - { |
|
270 | + final public function getInvokeEventResult($name, $data = array(), $flag = null) |
|
271 | + { |
|
272 | 272 | $flag = (isset($flag) && $flag != '') ? (bool)$flag : false; |
273 | 273 | |
274 | 274 | return $flag ? $this->modx->invokeEvent($name, $data) : false; |
@@ -277,8 +277,8 @@ discard block |
||
277 | 277 | /** |
278 | 278 | * @return $this |
279 | 279 | */ |
280 | - final public function clearLog() |
|
281 | - { |
|
280 | + final public function clearLog() |
|
281 | + { |
|
282 | 282 | $this->log = array(); |
283 | 283 | |
284 | 284 | return $this; |
@@ -287,8 +287,8 @@ discard block |
||
287 | 287 | /** |
288 | 288 | * @return array |
289 | 289 | */ |
290 | - final public function getLog() |
|
291 | - { |
|
290 | + final public function getLog() |
|
291 | + { |
|
292 | 292 | return $this->log; |
293 | 293 | } |
294 | 294 | |
@@ -296,10 +296,10 @@ discard block |
||
296 | 296 | * @param bool $flush |
297 | 297 | * @return $this |
298 | 298 | */ |
299 | - final public function list_log($flush = false) |
|
300 | - { |
|
299 | + final public function list_log($flush = false) |
|
300 | + { |
|
301 | 301 | echo '<pre>' . print_r(APIHelpers::sanitarTag($this->log), true) . '</pre>'; |
302 | - if ($flush) { |
|
302 | + if ($flush) { |
|
303 | 303 | $this->clearLog(); |
304 | 304 | } |
305 | 305 | |
@@ -310,10 +310,10 @@ discard block |
||
310 | 310 | * @param bool $full |
311 | 311 | * @return string |
312 | 312 | */ |
313 | - final public function getCachePath($full = true) |
|
314 | - { |
|
313 | + final public function getCachePath($full = true) |
|
314 | + { |
|
315 | 315 | $path = $this->modx->getCachePath(); |
316 | - if ($full) { |
|
316 | + if ($full) { |
|
317 | 317 | $path = MODX_BASE_PATH . substr($path, strlen(MODX_BASE_URL)); |
318 | 318 | } |
319 | 319 | |
@@ -324,10 +324,10 @@ discard block |
||
324 | 324 | * @param boolean $fire_events |
325 | 325 | * @param bool $custom |
326 | 326 | */ |
327 | - final public function clearCache($fire_events = false, $custom = false) |
|
328 | - { |
|
327 | + final public function clearCache($fire_events = false, $custom = false) |
|
328 | + { |
|
329 | 329 | $IDs = array(); |
330 | - if ($custom === false) { |
|
330 | + if ($custom === false) { |
|
331 | 331 | $this->modx->clearCache(); |
332 | 332 | include_once(MODX_MANAGER_PATH . 'processors/cache_sync.class.processor.php'); |
333 | 333 | $sync = new synccache(); |
@@ -335,22 +335,22 @@ discard block |
||
335 | 335 | $sync->setCachepath($path); |
336 | 336 | $sync->setReport(false); |
337 | 337 | $sync->emptyCache(); |
338 | - } else { |
|
339 | - if (is_scalar($custom)) { |
|
338 | + } else { |
|
339 | + if (is_scalar($custom)) { |
|
340 | 340 | $custom = array($custom); |
341 | 341 | } |
342 | - switch ($this->modx->config['cache_type']) { |
|
342 | + switch ($this->modx->config['cache_type']) { |
|
343 | 343 | case 2: |
344 | 344 | $cacheFile = "_*.pageCache.php"; |
345 | 345 | break; |
346 | 346 | default: |
347 | 347 | $cacheFile = ".pageCache.php"; |
348 | 348 | } |
349 | - if (is_array($custom)) { |
|
350 | - foreach ($custom as $id) { |
|
349 | + if (is_array($custom)) { |
|
350 | + foreach ($custom as $id) { |
|
351 | 351 | $tmp = glob(MODX_BASE_PATH . "assets/cache/docid_" . $id . $cacheFile); |
352 | - foreach ($tmp as $file) { |
|
353 | - if (is_readable($file)) { |
|
352 | + foreach ($tmp as $file) { |
|
353 | + if (is_readable($file)) { |
|
354 | 354 | unlink($file); |
355 | 355 | } |
356 | 356 | $IDs[] = $id; |
@@ -366,9 +366,9 @@ discard block |
||
366 | 366 | * @param integer $id |
367 | 367 | * @return MODxAPI |
368 | 368 | */ |
369 | - public function switchObject($id) |
|
370 | - { |
|
371 | - switch (true) { |
|
369 | + public function switchObject($id) |
|
370 | + { |
|
371 | + switch (true) { |
|
372 | 372 | //Если загружен другой объект - не тот, с которым мы хотим временно поработать |
373 | 373 | case ($this->getID() != $id && $id): |
374 | 374 | $obj = clone $this; |
@@ -390,8 +390,8 @@ discard block |
||
390 | 390 | * @param bool $flag |
391 | 391 | * @return $this |
392 | 392 | */ |
393 | - public function useIgnore($flag = true) |
|
394 | - { |
|
393 | + public function useIgnore($flag = true) |
|
394 | + { |
|
395 | 395 | $this->ignoreError = $flag ? 'IGNORE' : ''; |
396 | 396 | |
397 | 397 | return $this; |
@@ -400,8 +400,8 @@ discard block |
||
400 | 400 | /** |
401 | 401 | * @return bool |
402 | 402 | */ |
403 | - public function hasIgnore() |
|
404 | - { |
|
403 | + public function hasIgnore() |
|
404 | + { |
|
405 | 405 | return (bool)$this->ignoreError; |
406 | 406 | } |
407 | 407 | |
@@ -410,9 +410,9 @@ discard block |
||
410 | 410 | * @param $value |
411 | 411 | * @return $this |
412 | 412 | */ |
413 | - public function set($key, $value) |
|
414 | - { |
|
415 | - if ((is_scalar($value) || $this->isJsonField($key)) && is_scalar($key) && !empty($key)) { |
|
413 | + public function set($key, $value) |
|
414 | + { |
|
415 | + if ((is_scalar($value) || $this->isJsonField($key)) && is_scalar($key) && !empty($key)) { |
|
416 | 416 | $this->field[$key] = $value; |
417 | 417 | } |
418 | 418 | |
@@ -422,8 +422,8 @@ discard block |
||
422 | 422 | /** |
423 | 423 | * @return null|int |
424 | 424 | */ |
425 | - final public function getID() |
|
426 | - { |
|
425 | + final public function getID() |
|
426 | + { |
|
427 | 427 | return $this->id; |
428 | 428 | } |
429 | 429 | |
@@ -431,8 +431,8 @@ discard block |
||
431 | 431 | * @param $key |
432 | 432 | * @return mixed |
433 | 433 | */ |
434 | - public function get($key) |
|
435 | - { |
|
434 | + public function get($key) |
|
435 | + { |
|
436 | 436 | return APIHelpers::getkey($this->field, $key, null); |
437 | 437 | } |
438 | 438 | |
@@ -440,10 +440,10 @@ discard block |
||
440 | 440 | * @param $data |
441 | 441 | * @return $this |
442 | 442 | */ |
443 | - public function fromArray($data) |
|
444 | - { |
|
445 | - if (is_array($data)) { |
|
446 | - foreach ($data as $key => $value) { |
|
443 | + public function fromArray($data) |
|
444 | + { |
|
445 | + if (is_array($data)) { |
|
446 | + foreach ($data as $key => $value) { |
|
447 | 447 | $this->set($key, $value); |
448 | 448 | } |
449 | 449 | } |
@@ -459,22 +459,22 @@ discard block |
||
459 | 459 | * @return $this |
460 | 460 | * @throws Exception |
461 | 461 | */ |
462 | - final protected function Uset($key, $id = '') |
|
463 | - { |
|
464 | - if (!isset($this->field[$key])) { |
|
462 | + final protected function Uset($key, $id = '') |
|
463 | + { |
|
464 | + if (!isset($this->field[$key])) { |
|
465 | 465 | $tmp = "`{$key}`=''"; |
466 | 466 | $this->log[] = "{$key} is empty"; |
467 | - } else { |
|
468 | - if ($this->issetField($key) && is_scalar($this->field[$key])) { |
|
467 | + } else { |
|
468 | + if ($this->issetField($key) && is_scalar($this->field[$key])) { |
|
469 | 469 | $tmp = "`{$key}`='{$this->escape($this->field[$key])}'"; |
470 | - } else { |
|
470 | + } else { |
|
471 | 471 | throw new Exception("{$key} is invalid <pre>" . print_r($this->field[$key], true) . "</pre>"); |
472 | 472 | } |
473 | 473 | } |
474 | - if (!empty($tmp) && $this->isChanged($key)) { |
|
475 | - if ($id == '') { |
|
474 | + if (!empty($tmp) && $this->isChanged($key)) { |
|
475 | + if ($id == '') { |
|
476 | 476 | $this->set[] = $tmp; |
477 | - } else { |
|
477 | + } else { |
|
478 | 478 | $this->set[$id][] = $tmp; |
479 | 479 | } |
480 | 480 | } |
@@ -488,8 +488,11 @@ discard block |
||
488 | 488 | * @param array $data |
489 | 489 | * @return $this |
490 | 490 | */ |
491 | - public function store($data = array()) { |
|
492 | - if (is_array($data)) $this->store = $data; |
|
491 | + public function store($data = array()) |
|
492 | + { |
|
493 | + if (is_array($data)) { |
|
494 | + $this->store = $data; |
|
495 | + } |
|
493 | 496 | |
494 | 497 | return $this; |
495 | 498 | } |
@@ -500,10 +503,11 @@ discard block |
||
500 | 503 | * @param string $key |
501 | 504 | * @return MODxAPI |
502 | 505 | */ |
503 | - public function rollback($key = '') { |
|
504 | - if (!empty($key) && isset($this->store[$key])) { |
|
506 | + public function rollback($key = '') |
|
507 | + { |
|
508 | + if (!empty($key) && isset($this->store[$key])) { |
|
505 | 509 | $this->set($key,$this->store[$key]); |
506 | - } else { |
|
510 | + } else { |
|
507 | 511 | $this->fromArray($this->store); |
508 | 512 | } |
509 | 513 | |
@@ -516,7 +520,8 @@ discard block |
||
516 | 520 | * @param $key |
517 | 521 | * @return bool |
518 | 522 | */ |
519 | - public function isChanged($key) { |
|
523 | + public function isChanged($key) |
|
524 | + { |
|
520 | 525 | $flag = !isset($this->store[$key]) || (isset($this->store[$key]) && $this->store[$key] != $this->field[$key]); |
521 | 526 | |
522 | 527 | return $flag; |
@@ -529,23 +534,24 @@ discard block |
||
529 | 534 | * @return array |
530 | 535 | * @throws Exception |
531 | 536 | */ |
532 | - final public function cleanIDs($IDs, $sep = ',', $ignore = array()) |
|
533 | - { |
|
537 | + final public function cleanIDs($IDs, $sep = ',', $ignore = array()) |
|
538 | + { |
|
534 | 539 | $out = array(); |
535 | - if (!is_array($IDs)) { |
|
536 | - if (is_scalar($IDs)) { |
|
540 | + if (!is_array($IDs)) { |
|
541 | + if (is_scalar($IDs)) { |
|
537 | 542 | $IDs = explode($sep, $IDs); |
538 | - } else { |
|
543 | + } else { |
|
539 | 544 | $IDs = array(); |
540 | 545 | throw new Exception('Invalid IDs list <pre>' . print_r($IDs, 1) . '</pre>'); |
541 | 546 | } |
542 | 547 | } |
543 | - foreach ($IDs as $item) { |
|
548 | + foreach ($IDs as $item) { |
|
544 | 549 | $item = trim($item); |
545 | - if (is_scalar($item) && (int)$item >= 0) { //Fix 0xfffffffff |
|
546 | - if (!empty($ignore) && in_array((int)$item, $ignore, true)) { |
|
550 | + if (is_scalar($item) && (int)$item >= 0) { |
|
551 | +//Fix 0xfffffffff |
|
552 | + if (!empty($ignore) && in_array((int)$item, $ignore, true)) { |
|
547 | 553 | $this->log[] = 'Ignore id ' . (int)$item; |
548 | - } else { |
|
554 | + } else { |
|
549 | 555 | $out[] = (int)$item; |
550 | 556 | } |
551 | 557 | } |
@@ -561,26 +567,26 @@ discard block |
||
561 | 567 | * @return $this |
562 | 568 | * @throws Exception |
563 | 569 | */ |
564 | - final public function fromJson($data, $callback = null) |
|
565 | - { |
|
566 | - if (is_scalar($data) && !empty($data)) { |
|
570 | + final public function fromJson($data, $callback = null) |
|
571 | + { |
|
572 | + if (is_scalar($data) && !empty($data)) { |
|
567 | 573 | $json = json_decode($data); |
568 | - } else { |
|
574 | + } else { |
|
569 | 575 | throw new Exception("json is not string with json data"); |
570 | 576 | } |
571 | 577 | |
572 | - if ($this->jsonError($json)) { |
|
573 | - if (isset($callback) && is_callable($callback)) { |
|
578 | + if ($this->jsonError($json)) { |
|
579 | + if (isset($callback) && is_callable($callback)) { |
|
574 | 580 | call_user_func_array($callback, array($json)); |
575 | - } else { |
|
576 | - if (isset($callback)) { |
|
581 | + } else { |
|
582 | + if (isset($callback)) { |
|
577 | 583 | throw new Exception("Can't call callback JSON unpack <pre>" . print_r($callback, 1) . "</pre>"); |
578 | 584 | } |
579 | - foreach ($json as $key => $val) { |
|
585 | + foreach ($json as $key => $val) { |
|
580 | 586 | $this->set($key, $val); |
581 | 587 | } |
582 | 588 | } |
583 | - } else { |
|
589 | + } else { |
|
584 | 590 | throw new Exception('Error from JSON decode: <pre>' . print_r($data, 1) . '</pre>'); |
585 | 591 | } |
586 | 592 | |
@@ -592,19 +598,19 @@ discard block |
||
592 | 598 | * @return string |
593 | 599 | * @throws Exception |
594 | 600 | */ |
595 | - final public function toJson($callback = null) |
|
596 | - { |
|
601 | + final public function toJson($callback = null) |
|
602 | + { |
|
597 | 603 | $data = $this->toArray(); |
598 | - if (isset($callback) && is_callable($callback)) { |
|
604 | + if (isset($callback) && is_callable($callback)) { |
|
599 | 605 | $data = call_user_func_array($callback, array($data)); |
600 | - } else { |
|
601 | - if (isset($callback)) { |
|
606 | + } else { |
|
607 | + if (isset($callback)) { |
|
602 | 608 | throw new Exception("Can't call callback JSON pre pack <pre>" . print_r($callback, 1) . "</pre>"); |
603 | 609 | } |
604 | 610 | } |
605 | 611 | $json = json_encode($data); |
606 | 612 | |
607 | - if ($this->jsonError($data)) { |
|
613 | + if ($this->jsonError($data)) { |
|
608 | 614 | throw new Exception('Error from JSON decode: <pre>' . print_r($data, 1) . '</pre>'); |
609 | 615 | } |
610 | 616 | |
@@ -615,10 +621,10 @@ discard block |
||
615 | 621 | * @param $data |
616 | 622 | * @return bool |
617 | 623 | */ |
618 | - final protected function jsonError($data) |
|
619 | - { |
|
624 | + final protected function jsonError($data) |
|
625 | + { |
|
620 | 626 | $flag = false; |
621 | - if (json_last_error() === JSON_ERROR_NONE && is_object($data) && $data instanceof stdClass) { |
|
627 | + if (json_last_error() === JSON_ERROR_NONE && is_object($data) && $data instanceof stdClass) { |
|
622 | 628 | $flag = true; |
623 | 629 | } |
624 | 630 | |
@@ -631,25 +637,25 @@ discard block |
||
631 | 637 | * @param string $sep |
632 | 638 | * @return array |
633 | 639 | */ |
634 | - public function toArray($prefix = '', $suffix = '', $sep = '_') |
|
635 | - { |
|
640 | + public function toArray($prefix = '', $suffix = '', $sep = '_') |
|
641 | + { |
|
636 | 642 | $tpl = ''; |
637 | 643 | $plh = '[+key+]'; |
638 | - if ($prefix !== '') { |
|
644 | + if ($prefix !== '') { |
|
639 | 645 | $tpl = $prefix . $sep; |
640 | 646 | } |
641 | 647 | $tpl .= $plh; |
642 | - if ($suffix !== '') { |
|
648 | + if ($suffix !== '') { |
|
643 | 649 | $tpl .= $sep . $suffix; |
644 | 650 | } |
645 | 651 | $out = array(); |
646 | 652 | $fields = $this->field; |
647 | 653 | $fields[$this->fieldPKName()] = $this->getID(); |
648 | - if ($tpl != $plh) { |
|
649 | - foreach ($fields as $key => $value) { |
|
654 | + if ($tpl != $plh) { |
|
655 | + foreach ($fields as $key => $value) { |
|
650 | 656 | $out[str_replace($plh, $key, $tpl)] = $value; |
651 | 657 | } |
652 | - } else { |
|
658 | + } else { |
|
653 | 659 | $out = $fields; |
654 | 660 | } |
655 | 661 | |
@@ -659,8 +665,8 @@ discard block |
||
659 | 665 | /** |
660 | 666 | * @return string |
661 | 667 | */ |
662 | - final public function fieldPKName() |
|
663 | - { |
|
668 | + final public function fieldPKName() |
|
669 | + { |
|
664 | 670 | return $this->pkName; |
665 | 671 | } |
666 | 672 | |
@@ -668,8 +674,8 @@ discard block |
||
668 | 674 | * @param $table |
669 | 675 | * @return mixed|string |
670 | 676 | */ |
671 | - final public function makeTable($table) |
|
672 | - { |
|
677 | + final public function makeTable($table) |
|
678 | + { |
|
673 | 679 | //Без использования APIHelpers::getkey(). Иначе getFullTableName будет всегда выполняться |
674 | 680 | return (isset($this->_table[$table])) ? $this->_table[$table] : $this->modx->getFullTableName($table); |
675 | 681 | } |
@@ -679,14 +685,14 @@ discard block |
||
679 | 685 | * @param string $sep |
680 | 686 | * @return array|string |
681 | 687 | */ |
682 | - final public function sanitarIn($data, $sep = ',') |
|
683 | - { |
|
684 | - if (!is_array($data)) { |
|
688 | + final public function sanitarIn($data, $sep = ',') |
|
689 | + { |
|
690 | + if (!is_array($data)) { |
|
685 | 691 | $data = explode($sep, $data); |
686 | 692 | } |
687 | 693 | $out = array(); |
688 | - foreach ($data as $item) { |
|
689 | - if ($item !== '') { |
|
694 | + foreach ($data as $item) { |
|
695 | + if ($item !== '') { |
|
690 | 696 | $out[] = $this->escape($item); |
691 | 697 | } |
692 | 698 | } |
@@ -701,34 +707,34 @@ discard block |
||
701 | 707 | * @param string $PK |
702 | 708 | * @return bool |
703 | 709 | */ |
704 | - public function checkUnique($table, $field, $PK = 'id') |
|
705 | - { |
|
706 | - if (is_array($field)) { |
|
710 | + public function checkUnique($table, $field, $PK = 'id') |
|
711 | + { |
|
712 | + if (is_array($field)) { |
|
707 | 713 | $where = array(); |
708 | - foreach ($field as $_field) { |
|
714 | + foreach ($field as $_field) { |
|
709 | 715 | $val = $this->get($_field); |
710 | - if ($val != '') { |
|
716 | + if ($val != '') { |
|
711 | 717 | $where[] = "`" . $this->escape($_field) . "` = '" . $this->escape($val) . "'"; |
712 | 718 | } |
713 | 719 | } |
714 | 720 | $where = implode(' AND ', $where); |
715 | - } else { |
|
721 | + } else { |
|
716 | 722 | $where = ''; |
717 | 723 | $val = $this->get($field); |
718 | - if ($val != '') { |
|
724 | + if ($val != '') { |
|
719 | 725 | $where = "`" . $this->escape($field) . "` = '" . $this->escape($val) . "'"; |
720 | 726 | } |
721 | 727 | } |
722 | 728 | |
723 | - if ($where != '') { |
|
729 | + if ($where != '') { |
|
724 | 730 | $sql = $this->query("SELECT `" . $this->escape($PK) . "` FROM " . $this->makeTable($table) . " WHERE " . $where); |
725 | 731 | $id = $this->modx->db->getValue($sql); |
726 | - if (is_null($id) || (!$this->newDoc && $id == $this->getID())) { |
|
732 | + if (is_null($id) || (!$this->newDoc && $id == $this->getID())) { |
|
727 | 733 | $flag = true; |
728 | - } else { |
|
734 | + } else { |
|
729 | 735 | $flag = false; |
730 | 736 | } |
731 | - } else { |
|
737 | + } else { |
|
732 | 738 | $flag = false; |
733 | 739 | } |
734 | 740 | |
@@ -739,8 +745,8 @@ discard block |
||
739 | 745 | * @param array $data |
740 | 746 | * @return $this |
741 | 747 | */ |
742 | - public function create($data = array()) |
|
743 | - { |
|
748 | + public function create($data = array()) |
|
749 | + { |
|
744 | 750 | $this->close(); |
745 | 751 | $this->fromArray($data); |
746 | 752 | |
@@ -751,8 +757,8 @@ discard block |
||
751 | 757 | * @param $id |
752 | 758 | * @return $this |
753 | 759 | */ |
754 | - public function copy($id) |
|
755 | - { |
|
760 | + public function copy($id) |
|
761 | + { |
|
756 | 762 | $this->edit($id)->id = 0; |
757 | 763 | $this->newDoc = true; |
758 | 764 | $this->store = array(); |
@@ -763,8 +769,8 @@ discard block |
||
763 | 769 | /** |
764 | 770 | * |
765 | 771 | */ |
766 | - public function close() |
|
767 | - { |
|
772 | + public function close() |
|
773 | + { |
|
768 | 774 | $this->newDoc = true; |
769 | 775 | $this->id = null; |
770 | 776 | $this->field = array(); |
@@ -777,8 +783,8 @@ discard block |
||
777 | 783 | * @param $key |
778 | 784 | * @return bool |
779 | 785 | */ |
780 | - public function issetField($key) |
|
781 | - { |
|
786 | + public function issetField($key) |
|
787 | + { |
|
782 | 788 | return (is_scalar($key) && array_key_exists($key, $this->default_field)); |
783 | 789 | } |
784 | 790 | |
@@ -806,8 +812,8 @@ discard block |
||
806 | 812 | * @param $data |
807 | 813 | * @return array|mixed|string |
808 | 814 | */ |
809 | - final public function sanitarTag($data) |
|
810 | - { |
|
815 | + final public function sanitarTag($data) |
|
816 | + { |
|
811 | 817 | return parent::sanitarTag($this->modx->stripTags($data)); |
812 | 818 | } |
813 | 819 | |
@@ -816,17 +822,17 @@ discard block |
||
816 | 822 | * @param bool $dmi3yy |
817 | 823 | * @return bool |
818 | 824 | */ |
819 | - final protected function checkVersion($version, $dmi3yy = true) |
|
820 | - { |
|
825 | + final protected function checkVersion($version, $dmi3yy = true) |
|
826 | + { |
|
821 | 827 | $flag = false; |
822 | 828 | $currentVer = $this->modx->getVersionData('version'); |
823 | - if (is_array($currentVer)) { |
|
829 | + if (is_array($currentVer)) { |
|
824 | 830 | $currentVer = APIHelpers::getkey($currentVer, 'version', ''); |
825 | 831 | } |
826 | 832 | $tmp = substr($currentVer, 0, strlen($version)); |
827 | - if (version_compare($tmp, $version, '>=')) { |
|
833 | + if (version_compare($tmp, $version, '>=')) { |
|
828 | 834 | $flag = true; |
829 | - if ($dmi3yy) { |
|
835 | + if ($dmi3yy) { |
|
830 | 836 | $flag = (boolean)preg_match('/^' . $tmp . '(.*)\-d/', $currentVer); |
831 | 837 | } |
832 | 838 | } |
@@ -838,10 +844,10 @@ discard block |
||
838 | 844 | * @param string $name |
839 | 845 | * @return bool|mixed |
840 | 846 | */ |
841 | - protected function eraseField($name) |
|
842 | - { |
|
847 | + protected function eraseField($name) |
|
848 | + { |
|
843 | 849 | $flag = false; |
844 | - if (array_key_exists($name, $this->field)) { |
|
850 | + if (array_key_exists($name, $this->field)) { |
|
845 | 851 | $flag = $this->field[$name]; |
846 | 852 | unset($this->field[$name]); |
847 | 853 | } |
@@ -854,8 +860,8 @@ discard block |
||
854 | 860 | * @param string $field имя поля |
855 | 861 | * @return boolean |
856 | 862 | */ |
857 | - public function isJsonField($field) |
|
858 | - { |
|
863 | + public function isJsonField($field) |
|
864 | + { |
|
859 | 865 | return (is_scalar($field) && in_array($field, $this->jsonFields)); |
860 | 866 | } |
861 | 867 | |
@@ -864,9 +870,9 @@ discard block |
||
864 | 870 | * @param string $field имя поля |
865 | 871 | * @return $this |
866 | 872 | */ |
867 | - public function markAsDecode($field) |
|
868 | - { |
|
869 | - if (is_scalar($field)) { |
|
873 | + public function markAsDecode($field) |
|
874 | + { |
|
875 | + if (is_scalar($field)) { |
|
870 | 876 | $this->_decodedFields->set($field, false); |
871 | 877 | } |
872 | 878 | |
@@ -878,9 +884,9 @@ discard block |
||
878 | 884 | * @param string $field имя поля |
879 | 885 | * @return $this |
880 | 886 | */ |
881 | - public function markAsEncode($field) |
|
882 | - { |
|
883 | - if (is_scalar($field)) { |
|
887 | + public function markAsEncode($field) |
|
888 | + { |
|
889 | + if (is_scalar($field)) { |
|
884 | 890 | $this->_decodedFields->set($field, true); |
885 | 891 | } |
886 | 892 | |
@@ -891,10 +897,10 @@ discard block |
||
891 | 897 | * Пометить все поля как запакованные |
892 | 898 | * @return $this |
893 | 899 | */ |
894 | - public function markAllEncode() |
|
895 | - { |
|
900 | + public function markAllEncode() |
|
901 | + { |
|
896 | 902 | $this->_decodedFields->clear(); |
897 | - foreach ($this->jsonFields as $field) { |
|
903 | + foreach ($this->jsonFields as $field) { |
|
898 | 904 | $this->markAsEncode($field); |
899 | 905 | } |
900 | 906 | |
@@ -905,10 +911,10 @@ discard block |
||
905 | 911 | * Пометить все поля как распакованные |
906 | 912 | * @return $this |
907 | 913 | */ |
908 | - public function markAllDecode() |
|
909 | - { |
|
914 | + public function markAllDecode() |
|
915 | + { |
|
910 | 916 | $this->_decodedFields->clear(); |
911 | - foreach ($this->jsonFields as $field) { |
|
917 | + foreach ($this->jsonFields as $field) { |
|
912 | 918 | $this->markAsDecode($field); |
913 | 919 | } |
914 | 920 | |
@@ -919,9 +925,9 @@ discard block |
||
919 | 925 | * Получить список не запакованных полей |
920 | 926 | * @return DLCollection |
921 | 927 | */ |
922 | - public function getNoEncodeFields() |
|
923 | - { |
|
924 | - return $this->_decodedFields->filter(function ($value) { |
|
928 | + public function getNoEncodeFields() |
|
929 | + { |
|
930 | + return $this->_decodedFields->filter(function ($value) { |
|
925 | 931 | return ($value === false); |
926 | 932 | }); |
927 | 933 | } |
@@ -930,9 +936,9 @@ discard block |
||
930 | 936 | * Получить список не распакованных полей |
931 | 937 | * @return DLCollection |
932 | 938 | */ |
933 | - public function getNoDecodeFields() |
|
934 | - { |
|
935 | - return $this->_decodedFields->filter(function ($value) { |
|
939 | + public function getNoDecodeFields() |
|
940 | + { |
|
941 | + return $this->_decodedFields->filter(function ($value) { |
|
936 | 942 | return ($value === true); |
937 | 943 | }); |
938 | 944 | } |
@@ -942,8 +948,8 @@ discard block |
||
942 | 948 | * @param string $field имя поля |
943 | 949 | * @return boolean |
944 | 950 | */ |
945 | - public function isDecodableField($field) |
|
946 | - { |
|
951 | + public function isDecodableField($field) |
|
952 | + { |
|
947 | 953 | $data = $this->get($field); |
948 | 954 | |
949 | 955 | /** |
@@ -958,8 +964,8 @@ discard block |
||
958 | 964 | * @param string $field имя поля |
959 | 965 | * @return boolean |
960 | 966 | */ |
961 | - public function isEncodableField($field) |
|
962 | - { |
|
967 | + public function isEncodableField($field) |
|
968 | + { |
|
963 | 969 | /** |
964 | 970 | * Если поле было распаковано ранее и еще не упаковано |
965 | 971 | */ |
@@ -972,14 +978,14 @@ discard block |
||
972 | 978 | * @param bool $store обновить распакованное поле |
973 | 979 | * @return array ассоциативный массив с данными из json строки |
974 | 980 | */ |
975 | - public function decodeField($field, $store = false) |
|
976 | - { |
|
981 | + public function decodeField($field, $store = false) |
|
982 | + { |
|
977 | 983 | $out = array(); |
978 | - if ($this->isDecodableField($field)) { |
|
984 | + if ($this->isDecodableField($field)) { |
|
979 | 985 | $data = $this->get($field); |
980 | 986 | $out = jsonHelper::jsonDecode($data, array('assoc' => true), true); |
981 | 987 | } |
982 | - if ($store) { |
|
988 | + if ($store) { |
|
983 | 989 | $this->field[$field] = $out; |
984 | 990 | $this->markAsDecode($field); |
985 | 991 | } |
@@ -991,9 +997,9 @@ discard block |
||
991 | 997 | * Декодирование всех json полей |
992 | 998 | * @return $this |
993 | 999 | */ |
994 | - protected function decodeFields() |
|
995 | - { |
|
996 | - foreach ($this->getNoDecodeFields() as $field => $flag) { |
|
1000 | + protected function decodeFields() |
|
1001 | + { |
|
1002 | + foreach ($this->getNoDecodeFields() as $field => $flag) { |
|
997 | 1003 | $this->decodeField($field, true); |
998 | 1004 | } |
999 | 1005 | |
@@ -1006,14 +1012,14 @@ discard block |
||
1006 | 1012 | * @param bool $store обновить запакованное поле |
1007 | 1013 | * @return string|null json строка |
1008 | 1014 | */ |
1009 | - public function encodeField($field, $store = false) |
|
1010 | - { |
|
1015 | + public function encodeField($field, $store = false) |
|
1016 | + { |
|
1011 | 1017 | $out = null; |
1012 | - if ($this->isEncodableField($field)) { |
|
1018 | + if ($this->isEncodableField($field)) { |
|
1013 | 1019 | $data = $this->get($field); |
1014 | 1020 | $out = json_encode($data); |
1015 | 1021 | } |
1016 | - if ($store) { |
|
1022 | + if ($store) { |
|
1017 | 1023 | $this->field[$field] = $out; |
1018 | 1024 | $this->markAsEncode($field); |
1019 | 1025 | } |
@@ -1025,9 +1031,9 @@ discard block |
||
1025 | 1031 | * Запаковка всех json полей |
1026 | 1032 | * @return $this |
1027 | 1033 | */ |
1028 | - protected function encodeFields() |
|
1029 | - { |
|
1030 | - foreach ($this->getNoEncodeFields() as $field => $flag) { |
|
1034 | + protected function encodeFields() |
|
1035 | + { |
|
1036 | + foreach ($this->getNoEncodeFields() as $field => $flag) { |
|
1031 | 1037 | $this->encodeField($field, true); |
1032 | 1038 | } |
1033 | 1039 |