@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | # Date: March 22, 2013 |
11 | 11 | # |
12 | 12 | ####*/ |
13 | -include_once(MODX_BASE_PATH . 'assets/lib/APIHelpers.class.php'); |
|
13 | +include_once(MODX_BASE_PATH.'assets/lib/APIHelpers.class.php'); |
|
14 | 14 | |
15 | 15 | /** |
16 | 16 | * Class DLphx |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | $this->user["usrid"] = isset($_SESSION['webInternalKey']) ? intval($_SESSION['webInternalKey']) : 0; |
53 | 53 | $this->user["id"] = ($this->user["usrid"] > 0) ? (-$this->user["usrid"]) : $this->user["mgrid"]; |
54 | 54 | |
55 | - $this->debug = (bool)$debug; |
|
55 | + $this->debug = (bool) $debug; |
|
56 | 56 | |
57 | 57 | $this->maxPasses = ($maxpass != '') ? $maxpass : 50; |
58 | 58 | |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | preg_match_all('~(?:=`[^`@]*?)(\[\+([^:\+\[\]]+)([^\[\]]*?)\+\])~s', $template, $matches); |
95 | 95 | if ($matches[0]) { |
96 | 96 | $template = str_replace($matches[1], '', $template); |
97 | - $this->Log("Cleaning unsolved tags: \n" . implode("\n", $matches[2])); |
|
97 | + $this->Log("Cleaning unsolved tags: \n".implode("\n", $matches[2])); |
|
98 | 98 | } |
99 | 99 | // Restore non-call characters in the template: [, ] |
100 | 100 | $template = str_replace($this->safetags[1], $this->safetags[2], $template); |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | } |
107 | 107 | // Write an event log if debugging is enabled and there is something to log |
108 | 108 | if ($this->debug && $this->debugLog) { |
109 | - $this->modx->logEvent($this->curPass, 1, $this->createEventLog(), $this->name . ' ' . $this->version); |
|
109 | + $this->modx->logEvent($this->curPass, 1, $this->createEventLog(), $this->name.' '.$this->version); |
|
110 | 110 | $this->debugLog = false; |
111 | 111 | } |
112 | 112 | |
@@ -135,8 +135,8 @@ discard block |
||
135 | 135 | for ($i = 0; $i < $count; $i++) { |
136 | 136 | $var_search[] = $matches[0][$i]; |
137 | 137 | $input = $matches[1][$i]; |
138 | - $this->Log('MODX Chunk: ' . $input); |
|
139 | - $input = $this->modx->mergeChunkContent('{{' . $input . '}}'); |
|
138 | + $this->Log('MODX Chunk: '.$input); |
|
139 | + $input = $this->modx->mergeChunkContent('{{'.$input.'}}'); |
|
140 | 140 | $var_replace[] = $this->Filter($input, $matches[2][$i]); |
141 | 141 | } |
142 | 142 | $template = str_replace($var_search, $var_replace, $template); |
@@ -152,10 +152,10 @@ discard block |
||
152 | 152 | // for each detected snippet |
153 | 153 | for ($i = 0; $i < $count; $i++) { |
154 | 154 | $snippet = $matches[2][$i]; // snippet call |
155 | - $this->Log("MODx Snippet -> " . $snippet); |
|
155 | + $this->Log("MODx Snippet -> ".$snippet); |
|
156 | 156 | |
157 | 157 | // Let MODx evaluate snippet |
158 | - $replace = $this->modx->evalSnippets("[[" . $snippet . "]]"); |
|
158 | + $replace = $this->modx->evalSnippets("[[".$snippet."]]"); |
|
159 | 159 | $this->LogSnippet($replace); |
160 | 160 | |
161 | 161 | // Replace values |
@@ -184,19 +184,19 @@ discard block |
||
184 | 184 | switch ($matches[1][$i]) { |
185 | 185 | // Document / Template Variable eXtended |
186 | 186 | case "*": |
187 | - $this->Log("MODx TV/DV: " . $input); |
|
188 | - $input = $this->modx->mergeDocumentContent("[*" . $input . "*]"); |
|
187 | + $this->Log("MODx TV/DV: ".$input); |
|
188 | + $input = $this->modx->mergeDocumentContent("[*".$input."*]"); |
|
189 | 189 | $replace = $this->Filter($input, $modifiers); |
190 | 190 | break; |
191 | 191 | // MODx Setting eXtended |
192 | 192 | case "(": |
193 | - $this->Log("MODx Setting variable: " . $input); |
|
194 | - $input = $this->modx->mergeSettingsContent("[(" . $input . ")]"); |
|
193 | + $this->Log("MODx Setting variable: ".$input); |
|
194 | + $input = $this->modx->mergeSettingsContent("[(".$input.")]"); |
|
195 | 195 | $replace = $this->Filter($input, $modifiers); |
196 | 196 | break; |
197 | 197 | // MODx Placeholder eXtended |
198 | 198 | default: |
199 | - $this->Log("MODx / PHx placeholder variable: " . $input); |
|
199 | + $this->Log("MODx / PHx placeholder variable: ".$input); |
|
200 | 200 | // Check if placeholder is set |
201 | 201 | if (!array_key_exists($input, $this->placeholders) && !array_key_exists($input, |
202 | 202 | $this->modx->placeholders) |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | public function Filter($input, $modifiers) |
238 | 238 | { |
239 | 239 | $output = $input; |
240 | - $this->Log(" |--- Input = '" . $output . "'"); |
|
240 | + $this->Log(" |--- Input = '".$output."'"); |
|
241 | 241 | if (preg_match_all('~:([^:=]+)(?:=`(.*?)`(?=:[^:=]+|$))?~s', $modifiers, $matches)) { |
242 | 242 | $modifier_cmd = $matches[1]; // modifier command |
243 | 243 | $modifier_value = $matches[2]; // modifier value |
@@ -245,9 +245,9 @@ discard block |
||
245 | 245 | $condition = array(); |
246 | 246 | for ($i = 0; $i < $count; $i++) { |
247 | 247 | $output = trim($output); |
248 | - $this->Log(" |--- Modifier = '" . $modifier_cmd[$i] . "'"); |
|
248 | + $this->Log(" |--- Modifier = '".$modifier_cmd[$i]."'"); |
|
249 | 249 | if ($modifier_value[$i] != '') { |
250 | - $this->Log(" |--- Options = '" . $modifier_value[$i] . "'"); |
|
250 | + $this->Log(" |--- Options = '".$modifier_value[$i]."'"); |
|
251 | 251 | } |
252 | 252 | switch ($modifier_cmd[$i]) { |
253 | 253 | ##### Conditional Modifiers |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | break; |
389 | 389 | case "wordwrap": // default: 70 |
390 | 390 | $wrapat = intval($modifier_value[$i]) ? intval($modifier_value[$i]) : 70; |
391 | - $output = preg_replace_callback("@(\b\w+\b)@",function($m) use($wrapat) {return wordwrap($m[1],$wrapat,' ',1);},$output); |
|
391 | + $output = preg_replace_callback("@(\b\w+\b)@", function($m) use($wrapat) {return wordwrap($m[1], $wrapat, ' ', 1); },$output); |
|
392 | 392 | break; |
393 | 393 | case "limit": // default: 100 |
394 | 394 | $limit = intval($modifier_value[$i]) ? intval($modifier_value[$i]) : 100; |
@@ -408,7 +408,7 @@ discard block |
||
408 | 408 | case "math": |
409 | 409 | $filter = preg_replace("~([a-zA-Z\n\r\t\s])~", "", $modifier_value[$i]); |
410 | 410 | $filter = str_replace("?", $output, $filter); |
411 | - $output = eval("return " . $filter . ";"); |
|
411 | + $output = eval("return ".$filter.";"); |
|
412 | 412 | break; |
413 | 413 | case "isnotempty": |
414 | 414 | if (!empty($output)) { |
@@ -425,7 +425,7 @@ discard block |
||
425 | 425 | $output = nl2br($output); |
426 | 426 | break; |
427 | 427 | case "date": |
428 | - $output = strftime($modifier_value[$i], (int)$output); |
|
428 | + $output = strftime($modifier_value[$i], (int) $output); |
|
429 | 429 | break; |
430 | 430 | case "set": |
431 | 431 | $c = $i + 1; |
@@ -435,7 +435,7 @@ discard block |
||
435 | 435 | break; |
436 | 436 | case "value": |
437 | 437 | if ($i > 0 && $modifier_cmd[$i - 1] == "set") { |
438 | - $this->modx->SetPlaceholder("phx." . $output, $modifier_value[$i]); |
|
438 | + $this->modx->SetPlaceholder("phx.".$output, $modifier_value[$i]); |
|
439 | 439 | } |
440 | 440 | $output = null; |
441 | 441 | break; |
@@ -460,12 +460,12 @@ discard block |
||
460 | 460 | default: |
461 | 461 | $snippet = ''; |
462 | 462 | // modified by Anton Kuzmin (23.06.2010) // |
463 | - $snippetName = 'phx:' . $modifier_cmd[$i]; |
|
463 | + $snippetName = 'phx:'.$modifier_cmd[$i]; |
|
464 | 464 | if (isset($this->modx->snippetCache[$snippetName])) { |
465 | 465 | $snippet = $this->modx->snippetCache[$snippetName]; |
466 | 466 | } else { |
467 | 467 | // not in cache so let's check the db |
468 | - $sql = "SELECT snippet FROM " . $this->modx->getFullTableName("site_snippets") . " WHERE " . $this->modx->getFullTableName("site_snippets") . ".name='" . $this->modx->db->escape($snippetName) . "';"; |
|
468 | + $sql = "SELECT snippet FROM ".$this->modx->getFullTableName("site_snippets")." WHERE ".$this->modx->getFullTableName("site_snippets").".name='".$this->modx->db->escape($snippetName)."';"; |
|
469 | 469 | $result = $this->modx->db->query($sql); |
470 | 470 | if ($this->modx->db->getRecordCount($result) == 1) { |
471 | 471 | $row = $this->modx->db->getRow($result); |
@@ -474,14 +474,14 @@ discard block |
||
474 | 474 | } else { |
475 | 475 | if ($this->modx->db->getRecordCount($result) == 0) { |
476 | 476 | // If snippet not found, look in the modifiers folder |
477 | - $filename = $this->modx->config['rb_base_dir'] . 'plugins/phx/modifiers/' . $modifier_cmd[$i] . '.phx.php'; |
|
477 | + $filename = $this->modx->config['rb_base_dir'].'plugins/phx/modifiers/'.$modifier_cmd[$i].'.phx.php'; |
|
478 | 478 | if (@file_exists($filename)) { |
479 | 479 | $file_contents = @file_get_contents($filename); |
480 | - $file_contents = str_replace('<' . '?php', '', $file_contents); |
|
481 | - $file_contents = str_replace('?' . '>', '', $file_contents); |
|
480 | + $file_contents = str_replace('<'.'?php', '', $file_contents); |
|
481 | + $file_contents = str_replace('?'.'>', '', $file_contents); |
|
482 | 482 | $file_contents = str_replace('<?', '', $file_contents); |
483 | 483 | $snippet = $this->modx->snippetCache[$snippetName] = $file_contents; |
484 | - $this->modx->snippetCache[$snippetName . 'Props'] = ''; |
|
484 | + $this->modx->snippetCache[$snippetName.'Props'] = ''; |
|
485 | 485 | $this->Log(" |--- File ($filename) -> Custom Modifier"); |
486 | 486 | } else { |
487 | 487 | $this->Log(" |--- PHX Error: {$modifier_cmd[$i]} could not be found"); |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | $options = $modifier_value[$i]; |
498 | 498 | $custom = eval($cm); |
499 | 499 | $msg = ob_get_contents(); |
500 | - $output = $msg . $custom; |
|
500 | + $output = $msg.$custom; |
|
501 | 501 | ob_end_clean(); |
502 | 502 | } else { |
503 | 503 | $output = ''; |
@@ -505,9 +505,9 @@ discard block |
||
505 | 505 | break; |
506 | 506 | } |
507 | 507 | if (count($condition)) { |
508 | - $this->Log(" |--- Condition = '" . $condition[count($condition) - 1] . "'"); |
|
508 | + $this->Log(" |--- Condition = '".$condition[count($condition) - 1]."'"); |
|
509 | 509 | } |
510 | - $this->Log(" |--- Output = '" . $output . "'"); |
|
510 | + $this->Log(" |--- Output = '".$output."'"); |
|
511 | 511 | } |
512 | 512 | } |
513 | 513 | |
@@ -520,7 +520,7 @@ discard block |
||
520 | 520 | */ |
521 | 521 | private function runCode($code) |
522 | 522 | { |
523 | - return eval("return (" . $code . ");"); |
|
523 | + return eval("return (".$code.");"); |
|
524 | 524 | } |
525 | 525 | // Event logging (debug) |
526 | 526 | /** |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | $console = implode("\n", $this->console); |
534 | 534 | $this->console = array(); |
535 | 535 | |
536 | - $out = '<pre style="overflow: auto;">' . $console . '</pre>'; |
|
536 | + $out = '<pre style="overflow: auto;">'.$console.'</pre>'; |
|
537 | 537 | } |
538 | 538 | |
539 | 539 | return $out; |
@@ -560,8 +560,8 @@ discard block |
||
560 | 560 | { |
561 | 561 | if ($this->debug) { |
562 | 562 | $this->debugLog = true; |
563 | - $this->console[] = (count($this->console) + 1 - $this->curPass) . " [" . strftime("%H:%M:%S", |
|
564 | - time()) . "] " . $this->LogClean($string); |
|
563 | + $this->console[] = (count($this->console) + 1 - $this->curPass)." [".strftime("%H:%M:%S", |
|
564 | + time())."] ".$this->LogClean($string); |
|
565 | 565 | } |
566 | 566 | } |
567 | 567 | |
@@ -573,15 +573,15 @@ discard block |
||
573 | 573 | { |
574 | 574 | if ($this->debug) { |
575 | 575 | $this->debugLog = true; |
576 | - $this->console[] = (count($this->console) + 1 - $this->curPass) . " [" . strftime("%H:%M:%S", |
|
577 | - time()) . "] " . " |--- Returns: <div style='margin: 10px;'>" . $this->LogClean($string) . "</div>"; |
|
576 | + $this->console[] = (count($this->console) + 1 - $this->curPass)." [".strftime("%H:%M:%S", |
|
577 | + time())."] "." |--- Returns: <div style='margin: 10px;'>".$this->LogClean($string)."</div>"; |
|
578 | 578 | } |
579 | 579 | } |
580 | 580 | |
581 | 581 | // Log pass |
582 | 582 | public function LogPass() |
583 | 583 | { |
584 | - $this->console[] = "<div style='margin: 5px 2px 2px;border-bottom: 1px solid black;'>Pass " . $this->curPass . "</div>"; |
|
584 | + $this->console[] = "<div style='margin: 5px 2px 2px;border-bottom: 1px solid black;'>Pass ".$this->curPass."</div>"; |
|
585 | 585 | } |
586 | 586 | |
587 | 587 | // Log pass |
@@ -590,7 +590,7 @@ discard block |
||
590 | 590 | */ |
591 | 591 | public function LogSource($string) |
592 | 592 | { |
593 | - $this->console[] = "<div style='margin: 5px 2px 2px;border-bottom: 1px solid black;'>Source:</div>" . $this->LogClean($string); |
|
593 | + $this->console[] = "<div style='margin: 5px 2px 2px;border-bottom: 1px solid black;'>Source:</div>".$this->LogClean($string); |
|
594 | 594 | } |
595 | 595 | |
596 | 596 | |
@@ -625,7 +625,7 @@ discard block |
||
625 | 625 | */ |
626 | 626 | public function isMemberOfWebGroupByUserId($userid = 0, $groupNames = array()) |
627 | 627 | { |
628 | - $userid = (int)$userid; |
|
628 | + $userid = (int) $userid; |
|
629 | 629 | // if $groupNames is not an array return false |
630 | 630 | if (!is_array($groupNames)) { |
631 | 631 | return false; |
@@ -747,7 +747,7 @@ discard block |
||
747 | 747 | public function ucfirst($str) |
748 | 748 | { |
749 | 749 | if (function_exists('mb_strtoupper') && function_exists('mb_substr') && function_exists('mb_strlen')) { |
750 | - return mb_strtoupper(mb_substr($str, 0, 1)) . mb_substr($str, 1, mb_strlen($str)); |
|
750 | + return mb_strtoupper(mb_substr($str, 0, 1)).mb_substr($str, 1, mb_strlen($str)); |
|
751 | 751 | } |
752 | 752 | |
753 | 753 | return ucfirst($str); |
@@ -760,7 +760,7 @@ discard block |
||
760 | 760 | public function lcfirst($str) |
761 | 761 | { |
762 | 762 | if (function_exists('mb_strtolower') && function_exists('mb_substr') && function_exists('mb_strlen')) { |
763 | - return mb_strtolower(mb_substr($str, 0, 1)) . mb_substr($str, 1, mb_strlen($str)); |
|
763 | + return mb_strtolower(mb_substr($str, 0, 1)).mb_substr($str, 1, mb_strlen($str)); |
|
764 | 764 | } |
765 | 765 | |
766 | 766 | return lcfirst($str); |
@@ -15,8 +15,8 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * Class DLphx |
17 | 17 | */ |
18 | -class DLphx |
|
19 | -{ |
|
18 | +class DLphx |
|
19 | +{ |
|
20 | 20 | public $placeholders = array(); |
21 | 21 | public $name = 'PHx'; |
22 | 22 | public $version = '2.2.0'; |
@@ -45,8 +45,8 @@ discard block |
||
45 | 45 | * @param int|bool|string $debug |
46 | 46 | * @param int $maxpass |
47 | 47 | */ |
48 | - public function __construct(DocumentParser $modx, $debug = false, $maxpass = 50) |
|
49 | - { |
|
48 | + public function __construct(DocumentParser $modx, $debug = false, $maxpass = 50) |
|
49 | + { |
|
50 | 50 | $this->modx = $modx; |
51 | 51 | $this->user["mgrid"] = isset($_SESSION['mgrInternalKey']) ? intval($_SESSION['mgrInternalKey']) : 0; |
52 | 52 | $this->user["usrid"] = isset($_SESSION['webInternalKey']) ? intval($_SESSION['webInternalKey']) : 0; |
@@ -57,14 +57,14 @@ discard block |
||
57 | 57 | $this->maxPasses = ($maxpass != '') ? $maxpass : 50; |
58 | 58 | |
59 | 59 | $this->modx->setPlaceholder("phx", "&_PHX_INTERNAL_&"); |
60 | - if (function_exists('mb_internal_encoding')) { |
|
60 | + if (function_exists('mb_internal_encoding')) { |
|
61 | 61 | mb_internal_encoding($this->modx->config['modx_charset']); |
62 | 62 | } |
63 | 63 | } |
64 | 64 | |
65 | 65 | // Plugin event hook for MODx |
66 | - public function OnParseDocument() |
|
67 | - { |
|
66 | + public function OnParseDocument() |
|
67 | + { |
|
68 | 68 | // Get document output from MODx |
69 | 69 | $template = $this->modx->documentOutput; |
70 | 70 | // To the parse cave .. let's go! *insert batman tune here* |
@@ -78,10 +78,10 @@ discard block |
||
78 | 78 | * @param string $template |
79 | 79 | * @return mixed|string |
80 | 80 | */ |
81 | - public function Parse($template = '') |
|
82 | - { |
|
81 | + public function Parse($template = '') |
|
82 | + { |
|
83 | 83 | // If we already reached max passes don't get at it again. |
84 | - if ($this->curPass == $this->maxPasses) { |
|
84 | + if ($this->curPass == $this->maxPasses) { |
|
85 | 85 | return $template; |
86 | 86 | } |
87 | 87 | // Set template pre-process hash |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | $template = $this->ParseValues($template); |
93 | 93 | // clean up unused placeholders that have modifiers attached (MODx can't clean them) |
94 | 94 | preg_match_all('~(?:=`[^`@]*?)(\[\+([^:\+\[\]]+)([^\[\]]*?)\+\])~s', $template, $matches); |
95 | - if ($matches[0]) { |
|
95 | + if ($matches[0]) { |
|
96 | 96 | $template = str_replace($matches[1], '', $template); |
97 | 97 | $this->Log("Cleaning unsolved tags: \n" . implode("\n", $matches[2])); |
98 | 98 | } |
@@ -101,11 +101,11 @@ discard block |
||
101 | 101 | // Set template post-process hash |
102 | 102 | $et = md5($template); |
103 | 103 | // If template has changed, parse it once more... |
104 | - if ($st != $et) { |
|
104 | + if ($st != $et) { |
|
105 | 105 | $template = $this->Parse($template); |
106 | 106 | } |
107 | 107 | // Write an event log if debugging is enabled and there is something to log |
108 | - if ($this->debug && $this->debugLog) { |
|
108 | + if ($this->debug && $this->debugLog) { |
|
109 | 109 | $this->modx->logEvent($this->curPass, 1, $this->createEventLog(), $this->name . ' ' . $this->version); |
110 | 110 | $this->debugLog = false; |
111 | 111 | } |
@@ -119,20 +119,20 @@ discard block |
||
119 | 119 | * @param string $template |
120 | 120 | * @return mixed|string |
121 | 121 | */ |
122 | - public function ParseValues($template = '') |
|
123 | - { |
|
122 | + public function ParseValues($template = '') |
|
123 | + { |
|
124 | 124 | $this->curPass = $this->curPass + 1; |
125 | 125 | $st = md5($template); |
126 | 126 | |
127 | 127 | $this->LogPass(); |
128 | 128 | |
129 | 129 | // MODX Chunks |
130 | - if (preg_match_all('~(?<!(?:then|else)=`){{([^:\+{}]+)([^{}]*?)}}~s', $template, $matches)) { |
|
130 | + if (preg_match_all('~(?<!(?:then|else)=`){{([^:\+{}]+)([^{}]*?)}}~s', $template, $matches)) { |
|
131 | 131 | $this->Log('MODX Chunks -> Merging all chunk tags'); |
132 | 132 | $count = count($matches[0]); |
133 | 133 | $var_search = array(); |
134 | 134 | $var_replace = array(); |
135 | - for ($i = 0; $i < $count; $i++) { |
|
135 | + for ($i = 0; $i < $count; $i++) { |
|
136 | 136 | $var_search[] = $matches[0][$i]; |
137 | 137 | $input = $matches[1][$i]; |
138 | 138 | $this->Log('MODX Chunk: ' . $input); |
@@ -144,13 +144,13 @@ discard block |
||
144 | 144 | |
145 | 145 | // MODx Snippets |
146 | 146 | //if ( preg_match_all('~\[(\[|!)([^\[]*?)(!|\])\]~s',$template, $matches)) { |
147 | - if (preg_match_all('~(?<!(?:then|else)=`)\[(\[)([^\[]*?)(\])\]~s', $template, $matches)) { |
|
147 | + if (preg_match_all('~(?<!(?:then|else)=`)\[(\[)([^\[]*?)(\])\]~s', $template, $matches)) { |
|
148 | 148 | $count = count($matches[0]); |
149 | 149 | $var_search = array(); |
150 | 150 | $var_replace = array(); |
151 | 151 | |
152 | 152 | // for each detected snippet |
153 | - for ($i = 0; $i < $count; $i++) { |
|
153 | + for ($i = 0; $i < $count; $i++) { |
|
154 | 154 | $snippet = $matches[2][$i]; // snippet call |
155 | 155 | $this->Log("MODx Snippet -> " . $snippet); |
156 | 156 | |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | } |
167 | 167 | |
168 | 168 | // PHx / MODx Tags |
169 | - if (preg_match_all('~\[(\+|\*|\()([^:\+\[\]]+)([^\[\]]*?)(\1|\))\]~s', $template, $matches)) { |
|
169 | + if (preg_match_all('~\[(\+|\*|\()([^:\+\[\]]+)([^\[\]]*?)(\1|\))\]~s', $template, $matches)) { |
|
170 | 170 | |
171 | 171 | //$matches[0] // Complete string that's need to be replaced |
172 | 172 | //$matches[1] // Type |
@@ -177,11 +177,11 @@ discard block |
||
177 | 177 | $count = count($matches[0]); |
178 | 178 | $var_search = array(); |
179 | 179 | $var_replace = array(); |
180 | - for ($i = 0; $i < $count; $i++) { |
|
180 | + for ($i = 0; $i < $count; $i++) { |
|
181 | 181 | $input = $matches[2][$i]; |
182 | 182 | $modifiers = $matches[3][$i]; |
183 | 183 | $var_search[] = $matches[0][$i]; |
184 | - switch ($matches[1][$i]) { |
|
184 | + switch ($matches[1][$i]) { |
|
185 | 185 | // Document / Template Variable eXtended |
186 | 186 | case "*": |
187 | 187 | $this->Log("MODx TV/DV: " . $input); |
@@ -200,10 +200,10 @@ discard block |
||
200 | 200 | // Check if placeholder is set |
201 | 201 | if (!array_key_exists($input, $this->placeholders) && !array_key_exists($input, |
202 | 202 | $this->modx->placeholders) |
203 | - ) { |
|
203 | + ) { |
|
204 | 204 | // not set so try again later. |
205 | 205 | $input = ''; |
206 | - } else { |
|
206 | + } else { |
|
207 | 207 | // is set, get value and run filter |
208 | 208 | $input = $this->getPHxVariable($input); |
209 | 209 | } |
@@ -217,11 +217,11 @@ discard block |
||
217 | 217 | $et = md5($template); // Post-process template hash |
218 | 218 | |
219 | 219 | // Log an event if this was the maximum pass |
220 | - if ($this->curPass == $this->maxPasses) { |
|
220 | + if ($this->curPass == $this->maxPasses) { |
|
221 | 221 | $this->Log("Max passes reached. infinite loop protection so exiting.\n If you need the extra passes set the max passes to the highest count of nested tags in your template."); |
222 | 222 | } |
223 | 223 | // If this pass is not at maximum passes and the template hash is not the same, get at it again. |
224 | - if (($this->curPass < $this->maxPasses) && ($st != $et)) { |
|
224 | + if (($this->curPass < $this->maxPasses) && ($st != $et)) { |
|
225 | 225 | $template = $this->ParseValues($template); |
226 | 226 | } |
227 | 227 | |
@@ -234,22 +234,22 @@ discard block |
||
234 | 234 | * @param $modifiers |
235 | 235 | * @return mixed|null|string |
236 | 236 | */ |
237 | - public function Filter($input, $modifiers) |
|
238 | - { |
|
237 | + public function Filter($input, $modifiers) |
|
238 | + { |
|
239 | 239 | $output = $input; |
240 | 240 | $this->Log(" |--- Input = '" . $output . "'"); |
241 | - if (preg_match_all('~:([^:=]+)(?:=`(.*?)`(?=:[^:=]+|$))?~s', $modifiers, $matches)) { |
|
241 | + if (preg_match_all('~:([^:=]+)(?:=`(.*?)`(?=:[^:=]+|$))?~s', $modifiers, $matches)) { |
|
242 | 242 | $modifier_cmd = $matches[1]; // modifier command |
243 | 243 | $modifier_value = $matches[2]; // modifier value |
244 | 244 | $count = count($modifier_cmd); |
245 | 245 | $condition = array(); |
246 | - for ($i = 0; $i < $count; $i++) { |
|
246 | + for ($i = 0; $i < $count; $i++) { |
|
247 | 247 | $output = trim($output); |
248 | 248 | $this->Log(" |--- Modifier = '" . $modifier_cmd[$i] . "'"); |
249 | - if ($modifier_value[$i] != '') { |
|
249 | + if ($modifier_value[$i] != '') { |
|
250 | 250 | $this->Log(" |--- Options = '" . $modifier_value[$i] . "'"); |
251 | 251 | } |
252 | - switch ($modifier_cmd[$i]) { |
|
252 | + switch ($modifier_cmd[$i]) { |
|
253 | 253 | ##### Conditional Modifiers |
254 | 254 | case "input": |
255 | 255 | case "if": |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | case "ir": |
292 | 292 | case "memberof": |
293 | 293 | case "mo": // Is Member Of (same as inrole but this one can be stringed as a conditional) |
294 | - if ($output == "&_PHX_INTERNAL_&") { |
|
294 | + if ($output == "&_PHX_INTERNAL_&") { |
|
295 | 295 | $output = $this->user["id"]; |
296 | 296 | } |
297 | 297 | $grps = ($this->strlen($modifier_value[$i]) > 0) ? explode(",", $modifier_value[$i]) : array(); |
@@ -306,23 +306,23 @@ discard block |
||
306 | 306 | case "show": |
307 | 307 | $conditional = implode(' ', $condition); |
308 | 308 | $isvalid = intval($this->runCode($conditional)); |
309 | - if (!$isvalid) { |
|
309 | + if (!$isvalid) { |
|
310 | 310 | $output = null; |
311 | 311 | } |
312 | 312 | break; |
313 | 313 | case "then": |
314 | 314 | $conditional = implode(' ', $condition); |
315 | 315 | $isvalid = intval($this->runCode($conditional)); |
316 | - if ($isvalid) { |
|
316 | + if ($isvalid) { |
|
317 | 317 | $output = $modifier_value[$i]; |
318 | - } else { |
|
318 | + } else { |
|
319 | 319 | $output = null; |
320 | 320 | } |
321 | 321 | break; |
322 | 322 | case "else": |
323 | 323 | $conditional = implode(' ', $condition); |
324 | 324 | $isvalid = intval($this->runCode($conditional)); |
325 | - if (!$isvalid) { |
|
325 | + if (!$isvalid) { |
|
326 | 326 | $output = $modifier_value[$i]; |
327 | 327 | } |
328 | 328 | break; |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | $raw = explode("&", $modifier_value[$i]); |
331 | 331 | $map = array(); |
332 | 332 | $count = count($raw); |
333 | - for ($m = 0; $m < $count; $m++) { |
|
333 | + for ($m = 0; $m < $count; $m++) { |
|
334 | 334 | $mi = explode("=", $raw[$m]); |
335 | 335 | $map[$mi[0]] = $mi[1]; |
336 | 336 | } |
@@ -411,13 +411,13 @@ discard block |
||
411 | 411 | $output = eval("return " . $filter . ";"); |
412 | 412 | break; |
413 | 413 | case "isnotempty": |
414 | - if (!empty($output)) { |
|
414 | + if (!empty($output)) { |
|
415 | 415 | $output = $modifier_value[$i]; |
416 | 416 | } |
417 | 417 | break; |
418 | 418 | case "isempty": |
419 | 419 | case "ifempty": |
420 | - if (empty($output)) { |
|
420 | + if (empty($output)) { |
|
421 | 421 | $output = $modifier_value[$i]; |
422 | 422 | } |
423 | 423 | break; |
@@ -429,12 +429,12 @@ discard block |
||
429 | 429 | break; |
430 | 430 | case "set": |
431 | 431 | $c = $i + 1; |
432 | - if ($count > $c && $modifier_cmd[$c] == "value") { |
|
432 | + if ($count > $c && $modifier_cmd[$c] == "value") { |
|
433 | 433 | $output = preg_replace("~([^a-zA-Z0-9])~", "", $modifier_value[$i]); |
434 | 434 | } |
435 | 435 | break; |
436 | 436 | case "value": |
437 | - if ($i > 0 && $modifier_cmd[$i - 1] == "set") { |
|
437 | + if ($i > 0 && $modifier_cmd[$i - 1] == "set") { |
|
438 | 438 | $this->modx->SetPlaceholder("phx." . $output, $modifier_value[$i]); |
439 | 439 | } |
440 | 440 | $output = null; |
@@ -443,13 +443,13 @@ discard block |
||
443 | 443 | $output = md5($output); |
444 | 444 | break; |
445 | 445 | case "userinfo": |
446 | - if ($output == "&_PHX_INTERNAL_&") { |
|
446 | + if ($output == "&_PHX_INTERNAL_&") { |
|
447 | 447 | $output = $this->user["id"]; |
448 | 448 | } |
449 | 449 | $output = $this->ModUser($output, $modifier_value[$i]); |
450 | 450 | break; |
451 | 451 | case "inrole": // deprecated |
452 | - if ($output == "&_PHX_INTERNAL_&") { |
|
452 | + if ($output == "&_PHX_INTERNAL_&") { |
|
453 | 453 | $output = $this->user["id"]; |
454 | 454 | } |
455 | 455 | $grps = ($this->strlen($modifier_value[$i]) > 0) ? explode(",", $modifier_value[$i]) : array(); |
@@ -461,21 +461,21 @@ discard block |
||
461 | 461 | $snippet = ''; |
462 | 462 | // modified by Anton Kuzmin (23.06.2010) // |
463 | 463 | $snippetName = 'phx:' . $modifier_cmd[$i]; |
464 | - if (isset($this->modx->snippetCache[$snippetName])) { |
|
464 | + if (isset($this->modx->snippetCache[$snippetName])) { |
|
465 | 465 | $snippet = $this->modx->snippetCache[$snippetName]; |
466 | - } else { |
|
466 | + } else { |
|
467 | 467 | // not in cache so let's check the db |
468 | 468 | $sql = "SELECT snippet FROM " . $this->modx->getFullTableName("site_snippets") . " WHERE " . $this->modx->getFullTableName("site_snippets") . ".name='" . $this->modx->db->escape($snippetName) . "';"; |
469 | 469 | $result = $this->modx->db->query($sql); |
470 | - if ($this->modx->db->getRecordCount($result) == 1) { |
|
470 | + if ($this->modx->db->getRecordCount($result) == 1) { |
|
471 | 471 | $row = $this->modx->db->getRow($result); |
472 | 472 | $snippet = $this->modx->snippetCache[$row['name']] = $row['snippet']; |
473 | 473 | $this->Log(" |--- DB -> Custom Modifier"); |
474 | - } else { |
|
475 | - if ($this->modx->db->getRecordCount($result) == 0) { |
|
474 | + } else { |
|
475 | + if ($this->modx->db->getRecordCount($result) == 0) { |
|
476 | 476 | // If snippet not found, look in the modifiers folder |
477 | 477 | $filename = $this->modx->config['rb_base_dir'] . 'plugins/phx/modifiers/' . $modifier_cmd[$i] . '.phx.php'; |
478 | - if (@file_exists($filename)) { |
|
478 | + if (@file_exists($filename)) { |
|
479 | 479 | $file_contents = @file_get_contents($filename); |
480 | 480 | $file_contents = str_replace('<' . '?php', '', $file_contents); |
481 | 481 | $file_contents = str_replace('?' . '>', '', $file_contents); |
@@ -483,7 +483,7 @@ discard block |
||
483 | 483 | $snippet = $this->modx->snippetCache[$snippetName] = $file_contents; |
484 | 484 | $this->modx->snippetCache[$snippetName . 'Props'] = ''; |
485 | 485 | $this->Log(" |--- File ($filename) -> Custom Modifier"); |
486 | - } else { |
|
486 | + } else { |
|
487 | 487 | $this->Log(" |--- PHX Error: {$modifier_cmd[$i]} could not be found"); |
488 | 488 | } |
489 | 489 | } |
@@ -492,19 +492,19 @@ discard block |
||
492 | 492 | $cm = $snippet; |
493 | 493 | // end // |
494 | 494 | |
495 | - if (!empty($cm)) { |
|
495 | + if (!empty($cm)) { |
|
496 | 496 | ob_start(); |
497 | 497 | $options = $modifier_value[$i]; |
498 | 498 | $custom = eval($cm); |
499 | 499 | $msg = ob_get_contents(); |
500 | 500 | $output = $msg . $custom; |
501 | 501 | ob_end_clean(); |
502 | - } else { |
|
502 | + } else { |
|
503 | 503 | $output = ''; |
504 | 504 | } |
505 | 505 | break; |
506 | 506 | } |
507 | - if (count($condition)) { |
|
507 | + if (count($condition)) { |
|
508 | 508 | $this->Log(" |--- Condition = '" . $condition[count($condition) - 1] . "'"); |
509 | 509 | } |
510 | 510 | $this->Log(" |--- Output = '" . $output . "'"); |
@@ -518,18 +518,18 @@ discard block |
||
518 | 518 | * @param string $code |
519 | 519 | * @return mixed |
520 | 520 | */ |
521 | - private function runCode($code) |
|
522 | - { |
|
521 | + private function runCode($code) |
|
522 | + { |
|
523 | 523 | return eval("return (" . $code . ");"); |
524 | 524 | } |
525 | 525 | // Event logging (debug) |
526 | 526 | /** |
527 | 527 | * @return string |
528 | 528 | */ |
529 | - public function createEventLog() |
|
530 | - { |
|
529 | + public function createEventLog() |
|
530 | + { |
|
531 | 531 | $out = ''; |
532 | - if (!empty($this->console)) { |
|
532 | + if (!empty($this->console)) { |
|
533 | 533 | $console = implode("\n", $this->console); |
534 | 534 | $this->console = array(); |
535 | 535 | |
@@ -544,8 +544,8 @@ discard block |
||
544 | 544 | * @param $string |
545 | 545 | * @return array|mixed|string |
546 | 546 | */ |
547 | - public function LogClean($string) |
|
548 | - { |
|
547 | + public function LogClean($string) |
|
548 | + { |
|
549 | 549 | $string = preg_replace("/&(#[0-9]+|[a-z]+);/i", "&$1;", $string); |
550 | 550 | $string = APIHelpers::sanitarTag($string); |
551 | 551 | |
@@ -556,9 +556,9 @@ discard block |
||
556 | 556 | /** |
557 | 557 | * @param $string |
558 | 558 | */ |
559 | - public function Log($string) |
|
560 | - { |
|
561 | - if ($this->debug) { |
|
559 | + public function Log($string) |
|
560 | + { |
|
561 | + if ($this->debug) { |
|
562 | 562 | $this->debugLog = true; |
563 | 563 | $this->console[] = (count($this->console) + 1 - $this->curPass) . " [" . strftime("%H:%M:%S", |
564 | 564 | time()) . "] " . $this->LogClean($string); |
@@ -569,9 +569,9 @@ discard block |
||
569 | 569 | /** |
570 | 570 | * @param $string |
571 | 571 | */ |
572 | - public function LogSnippet($string) |
|
573 | - { |
|
574 | - if ($this->debug) { |
|
572 | + public function LogSnippet($string) |
|
573 | + { |
|
574 | + if ($this->debug) { |
|
575 | 575 | $this->debugLog = true; |
576 | 576 | $this->console[] = (count($this->console) + 1 - $this->curPass) . " [" . strftime("%H:%M:%S", |
577 | 577 | time()) . "] " . " |--- Returns: <div style='margin: 10px;'>" . $this->LogClean($string) . "</div>"; |
@@ -579,8 +579,8 @@ discard block |
||
579 | 579 | } |
580 | 580 | |
581 | 581 | // Log pass |
582 | - public function LogPass() |
|
583 | - { |
|
582 | + public function LogPass() |
|
583 | + { |
|
584 | 584 | $this->console[] = "<div style='margin: 5px 2px 2px;border-bottom: 1px solid black;'>Pass " . $this->curPass . "</div>"; |
585 | 585 | } |
586 | 586 | |
@@ -588,8 +588,8 @@ discard block |
||
588 | 588 | /** |
589 | 589 | * @param $string |
590 | 590 | */ |
591 | - public function LogSource($string) |
|
592 | - { |
|
591 | + public function LogSource($string) |
|
592 | + { |
|
593 | 593 | $this->console[] = "<div style='margin: 5px 2px 2px;border-bottom: 1px solid black;'>Source:</div>" . $this->LogClean($string); |
594 | 594 | } |
595 | 595 | |
@@ -601,16 +601,16 @@ discard block |
||
601 | 601 | * @param $field |
602 | 602 | * @return mixed |
603 | 603 | */ |
604 | - public function ModUser($userid, $field) |
|
605 | - { |
|
606 | - if (!array_key_exists($userid, $this->cache["ui"])) { |
|
607 | - if (intval($userid) < 0) { |
|
604 | + public function ModUser($userid, $field) |
|
605 | + { |
|
606 | + if (!array_key_exists($userid, $this->cache["ui"])) { |
|
607 | + if (intval($userid) < 0) { |
|
608 | 608 | $user = $this->modx->getWebUserInfo(-($userid)); |
609 | - } else { |
|
609 | + } else { |
|
610 | 610 | $user = $this->modx->getUserInfo($userid); |
611 | 611 | } |
612 | 612 | $this->cache["ui"][$userid] = $user; |
613 | - } else { |
|
613 | + } else { |
|
614 | 614 | $user = $this->cache["ui"][$userid]; |
615 | 615 | } |
616 | 616 | |
@@ -623,31 +623,31 @@ discard block |
||
623 | 623 | * @param array $groupNames |
624 | 624 | * @return bool |
625 | 625 | */ |
626 | - public function isMemberOfWebGroupByUserId($userid = 0, $groupNames = array()) |
|
627 | - { |
|
626 | + public function isMemberOfWebGroupByUserId($userid = 0, $groupNames = array()) |
|
627 | + { |
|
628 | 628 | $userid = (int)$userid; |
629 | 629 | // if $groupNames is not an array return false |
630 | - if (!is_array($groupNames)) { |
|
630 | + if (!is_array($groupNames)) { |
|
631 | 631 | return false; |
632 | 632 | } |
633 | 633 | |
634 | 634 | // if the user id is a negative number make it positive |
635 | - if (intval($userid) < 0) { |
|
635 | + if (intval($userid) < 0) { |
|
636 | 636 | $userid = -($userid); |
637 | 637 | } |
638 | 638 | |
639 | 639 | // Creates an array with all webgroups the user id is in |
640 | - if (!array_key_exists($userid, $this->cache["mo"])) { |
|
640 | + if (!array_key_exists($userid, $this->cache["mo"])) { |
|
641 | 641 | $tbl = $this->modx->getFullTableName("webgroup_names"); |
642 | 642 | $tbl2 = $this->modx->getFullTableName("web_groups"); |
643 | 643 | $sql = "SELECT `wgn`.`name` FROM {$tbl} `wgn` INNER JOIN {$tbl2} `wg` ON `wg`.`webgroup`=`wgn`.`id` AND `wg`.`webuser`={$userid}"; |
644 | 644 | $this->cache["mo"][$userid] = $grpNames = $this->modx->db->getColumn("name", $sql); |
645 | - } else { |
|
645 | + } else { |
|
646 | 646 | $grpNames = $this->cache["mo"][$userid]; |
647 | 647 | } |
648 | 648 | // Check if a supplied group matches a webgroup from the array we just created |
649 | - foreach ($groupNames as $k => $v) { |
|
650 | - if (in_array(trim($v), $grpNames)) { |
|
649 | + foreach ($groupNames as $k => $v) { |
|
650 | + if (in_array(trim($v), $grpNames)) { |
|
651 | 651 | return true; |
652 | 652 | } |
653 | 653 | } |
@@ -661,13 +661,13 @@ discard block |
||
661 | 661 | * @param $name |
662 | 662 | * @return mixed|string |
663 | 663 | */ |
664 | - public function getPHxVariable($name) |
|
665 | - { |
|
664 | + public function getPHxVariable($name) |
|
665 | + { |
|
666 | 666 | // Check if this variable is created by PHx |
667 | - if (array_key_exists($name, $this->placeholders)) { |
|
667 | + if (array_key_exists($name, $this->placeholders)) { |
|
668 | 668 | // Return the value from PHx |
669 | 669 | return $this->placeholders[$name]; |
670 | - } else { |
|
670 | + } else { |
|
671 | 671 | // Return the value from MODx |
672 | 672 | return $this->modx->getPlaceholder($name); |
673 | 673 | } |
@@ -678,9 +678,9 @@ discard block |
||
678 | 678 | * @param $name |
679 | 679 | * @param $value |
680 | 680 | */ |
681 | - public function setPHxVariable($name, $value) |
|
682 | - { |
|
683 | - if ($name != "phx") { |
|
681 | + public function setPHxVariable($name, $value) |
|
682 | + { |
|
683 | + if ($name != "phx") { |
|
684 | 684 | $this->placeholders[$name] = $value; |
685 | 685 | } |
686 | 686 | } |
@@ -692,9 +692,9 @@ discard block |
||
692 | 692 | * @param null $l |
693 | 693 | * @return string |
694 | 694 | */ |
695 | - public function substr($str, $s, $l = null) |
|
696 | - { |
|
697 | - if (function_exists('mb_substr')) { |
|
695 | + public function substr($str, $s, $l = null) |
|
696 | + { |
|
697 | + if (function_exists('mb_substr')) { |
|
698 | 698 | return mb_substr($str, $s, $l); |
699 | 699 | } |
700 | 700 | |
@@ -705,9 +705,9 @@ discard block |
||
705 | 705 | * @param $str |
706 | 706 | * @return int |
707 | 707 | */ |
708 | - public function strlen($str) |
|
709 | - { |
|
710 | - if (function_exists('mb_strlen')) { |
|
708 | + public function strlen($str) |
|
709 | + { |
|
710 | + if (function_exists('mb_strlen')) { |
|
711 | 711 | return mb_strlen($str); |
712 | 712 | } |
713 | 713 | |
@@ -718,9 +718,9 @@ discard block |
||
718 | 718 | * @param $str |
719 | 719 | * @return string |
720 | 720 | */ |
721 | - public function strtolower($str) |
|
722 | - { |
|
723 | - if (function_exists('mb_strtolower')) { |
|
721 | + public function strtolower($str) |
|
722 | + { |
|
723 | + if (function_exists('mb_strtolower')) { |
|
724 | 724 | return mb_strtolower($str); |
725 | 725 | } |
726 | 726 | |
@@ -731,9 +731,9 @@ discard block |
||
731 | 731 | * @param $str |
732 | 732 | * @return string |
733 | 733 | */ |
734 | - public function strtoupper($str) |
|
735 | - { |
|
736 | - if (function_exists('mb_strtoupper')) { |
|
734 | + public function strtoupper($str) |
|
735 | + { |
|
736 | + if (function_exists('mb_strtoupper')) { |
|
737 | 737 | return mb_strtoupper($str); |
738 | 738 | } |
739 | 739 | |
@@ -744,9 +744,9 @@ discard block |
||
744 | 744 | * @param $str |
745 | 745 | * @return string |
746 | 746 | */ |
747 | - public function ucfirst($str) |
|
748 | - { |
|
749 | - if (function_exists('mb_strtoupper') && function_exists('mb_substr') && function_exists('mb_strlen')) { |
|
747 | + public function ucfirst($str) |
|
748 | + { |
|
749 | + if (function_exists('mb_strtoupper') && function_exists('mb_substr') && function_exists('mb_strlen')) { |
|
750 | 750 | return mb_strtoupper(mb_substr($str, 0, 1)) . mb_substr($str, 1, mb_strlen($str)); |
751 | 751 | } |
752 | 752 | |
@@ -757,9 +757,9 @@ discard block |
||
757 | 757 | * @param $str |
758 | 758 | * @return string |
759 | 759 | */ |
760 | - public function lcfirst($str) |
|
761 | - { |
|
762 | - if (function_exists('mb_strtolower') && function_exists('mb_substr') && function_exists('mb_strlen')) { |
|
760 | + public function lcfirst($str) |
|
761 | + { |
|
762 | + if (function_exists('mb_strtolower') && function_exists('mb_substr') && function_exists('mb_strlen')) { |
|
763 | 763 | return mb_strtolower(mb_substr($str, 0, 1)) . mb_substr($str, 1, mb_strlen($str)); |
764 | 764 | } |
765 | 765 | |
@@ -770,9 +770,9 @@ discard block |
||
770 | 770 | * @param $str |
771 | 771 | * @return string |
772 | 772 | */ |
773 | - public function ucwords($str) |
|
774 | - { |
|
775 | - if (function_exists('mb_convert_case')) { |
|
773 | + public function ucwords($str) |
|
774 | + { |
|
775 | + if (function_exists('mb_convert_case')) { |
|
776 | 776 | return mb_convert_case($str, MB_CASE_TITLE); |
777 | 777 | } |
778 | 778 | |
@@ -783,8 +783,8 @@ discard block |
||
783 | 783 | * @param $str |
784 | 784 | * @return string |
785 | 785 | */ |
786 | - public function strrev($str) |
|
787 | - { |
|
786 | + public function strrev($str) |
|
787 | + { |
|
788 | 788 | preg_match_all('/./us', $str, $ar); |
789 | 789 | |
790 | 790 | return implode(array_reverse($ar[0])); |
@@ -794,8 +794,8 @@ discard block |
||
794 | 794 | * @param $str |
795 | 795 | * @return string |
796 | 796 | */ |
797 | - public function str_shuffle($str) |
|
798 | - { |
|
797 | + public function str_shuffle($str) |
|
798 | + { |
|
799 | 799 | preg_match_all('/./us', $str, $ar); |
800 | 800 | shuffle($ar[0]); |
801 | 801 | |
@@ -806,8 +806,8 @@ discard block |
||
806 | 806 | * @param $str |
807 | 807 | * @return int |
808 | 808 | */ |
809 | - public function str_word_count($str) |
|
810 | - { |
|
809 | + public function str_word_count($str) |
|
810 | + { |
|
811 | 811 | return count(preg_split('~[^\p{L}\p{N}\']+~u', $str)); |
812 | 812 | } |
813 | 813 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -include_once(MODX_BASE_PATH . 'assets/lib/APIHelpers.class.php'); |
|
3 | +include_once(MODX_BASE_PATH.'assets/lib/APIHelpers.class.php'); |
|
4 | 4 | |
5 | 5 | /** |
6 | 6 | * Class DLTemplate |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * @param array $data |
122 | 122 | * @return $this |
123 | 123 | */ |
124 | - public function setTwigTemplateVars($data = array()) { |
|
124 | + public function setTwigTemplateVars($data = array()){ |
|
125 | 125 | if (is_array($data)) $this->twigTemplateVars = $data; |
126 | 126 | return $this; |
127 | 127 | } |
@@ -156,20 +156,20 @@ discard block |
||
156 | 156 | public function getChunk($name) |
157 | 157 | { |
158 | 158 | $tpl = ''; |
159 | - $this->twigEnabled = substr($name,0,3) == '@T_'; |
|
159 | + $this->twigEnabled = substr($name, 0, 3) == '@T_'; |
|
160 | 160 | if ($name != '' && !isset($this->modx->chunkCache[$name])) { |
161 | 161 | $mode = (preg_match('/^((@[A-Z_]+)[:]{0,1})(.*)/Asu', trim($name), |
162 | 162 | $tmp) && isset($tmp[2], $tmp[3])) ? $tmp[2] : false; |
163 | 163 | $subTmp = (isset($tmp[3])) ? trim($tmp[3]) : null; |
164 | - if ($this->twigEnabled) $mode = '@'.substr($mode,3); |
|
164 | + if ($this->twigEnabled) $mode = '@'.substr($mode, 3); |
|
165 | 165 | switch ($mode) { |
166 | 166 | case '@FILE': |
167 | 167 | if ($subTmp != '') { |
168 | - $real = realpath(MODX_BASE_PATH . $this->templatePath); |
|
169 | - $path = realpath(MODX_BASE_PATH . $this->templatePath . preg_replace(array( |
|
168 | + $real = realpath(MODX_BASE_PATH.$this->templatePath); |
|
169 | + $path = realpath(MODX_BASE_PATH.$this->templatePath.preg_replace(array( |
|
170 | 170 | '/\.*[\/|\\\]/i', |
171 | 171 | '/[\/|\\\]+/i' |
172 | - ), array('/', '/'), $subTmp) . '.' . $this->templateExtension); |
|
172 | + ), array('/', '/'), $subTmp).'.'.$this->templateExtension); |
|
173 | 173 | $fname = explode(".", $path); |
174 | 174 | if ($real == substr($path, 0, |
175 | 175 | strlen($real)) && end($fname) == $this->templateExtension && file_exists($path) |
@@ -191,11 +191,11 @@ discard block |
||
191 | 191 | case '@DOCUMENT': |
192 | 192 | case '@DOC': |
193 | 193 | switch (true) { |
194 | - case ((int)$subTmp > 0): |
|
195 | - $tpl = $this->modx->getPageInfo((int)$subTmp, 0, "content"); |
|
194 | + case ((int) $subTmp > 0): |
|
195 | + $tpl = $this->modx->getPageInfo((int) $subTmp, 0, "content"); |
|
196 | 196 | $tpl = isset($tpl['content']) ? $tpl['content'] : ''; |
197 | 197 | break; |
198 | - case ((int)$subTmp == 0): |
|
198 | + case ((int) $subTmp == 0): |
|
199 | 199 | $tpl = $this->modx->documentObject['content']; |
200 | 200 | break; |
201 | 201 | } |
@@ -257,12 +257,12 @@ discard block |
||
257 | 257 | */ |
258 | 258 | public function renderDoc($id, $events = false, $tpl = null) |
259 | 259 | { |
260 | - if ((int)$id <= 0) { |
|
260 | + if ((int) $id <= 0) { |
|
261 | 261 | return ''; |
262 | 262 | } |
263 | 263 | |
264 | 264 | $m = clone $this->modx; //Чтобы была возможность вызывать события |
265 | - $m->documentObject = $m->getDocumentObject('id', (int)$id, $events ? 'prepareResponse' : null); |
|
265 | + $m->documentObject = $m->getDocumentObject('id', (int) $id, $events ? 'prepareResponse' : null); |
|
266 | 266 | if ($m->documentObject['type'] == "reference") { |
267 | 267 | if (is_numeric($m->documentObject['content']) && $m->documentObject['content'] > 0) { |
268 | 268 | $m->documentObject['content'] = $this->renderDoc($m->documentObject['content'], $events); |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | public function getTemplate($id) |
298 | 298 | { |
299 | 299 | $tpl = null; |
300 | - $id = (int)$id; |
|
300 | + $id = (int) $id; |
|
301 | 301 | if ($id > 0) { |
302 | 302 | $tpl = $this->modx->db->getValue("SELECT `content` FROM {$this->modx->getFullTableName("site_templates")} WHERE `id` = {$id}"); |
303 | 303 | } |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | $plh = $this->twigTemplateVars; |
324 | 324 | $plh['data'] = $data; |
325 | 325 | $plh['modx'] = $this->modx; |
326 | - $out = $twig->render(md5($name),$plh); |
|
326 | + $out = $twig->render(md5($name), $plh); |
|
327 | 327 | } else { |
328 | 328 | if (is_array($data) && ($out != '')) { |
329 | 329 | if (preg_match("/\[\+[A-Z0-9\.\_\-]+\+\]/is", $out)) { |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | */ |
357 | 357 | public function setPHxPlaceholders($value = '', $key = '', $path = '') |
358 | 358 | { |
359 | - $keypath = !empty($path) ? $path . "." . $key : $key; |
|
359 | + $keypath = !empty($path) ? $path.".".$key : $key; |
|
360 | 360 | $this->phx->curPass = 0; |
361 | 361 | if (is_array($value)) { |
362 | 362 | foreach ($value as $subkey => $subval) { |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | * @param string $tpl |
375 | 375 | * @return null |
376 | 376 | */ |
377 | - protected function getTwig($name, $tpl) { |
|
377 | + protected function getTwig($name, $tpl){ |
|
378 | 378 | if (is_null($this->twig) && isset($this->modx->twig)) { |
379 | 379 | $twig = clone $this->modx->twig; |
380 | 380 | $this->twig = $twig; |
@@ -415,7 +415,7 @@ discard block |
||
415 | 415 | public function createPHx($debug = 0, $maxpass = 50) |
416 | 416 | { |
417 | 417 | if (!class_exists('DLphx', false)) { |
418 | - include_once(__DIR__ . '/DLphx.class.php'); |
|
418 | + include_once(__DIR__.'/DLphx.class.php'); |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | return new DLphx($this->modx, $debug, $maxpass); |
@@ -121,8 +121,11 @@ discard block |
||
121 | 121 | * @param array $data |
122 | 122 | * @return $this |
123 | 123 | */ |
124 | - public function setTwigTemplateVars($data = array()) { |
|
125 | - if (is_array($data)) $this->twigTemplateVars = $data; |
|
124 | + public function setTwigTemplateVars($data = array()) |
|
125 | + { |
|
126 | + if (is_array($data)) { |
|
127 | + $this->twigTemplateVars = $data; |
|
128 | + } |
|
126 | 129 | return $this; |
127 | 130 | } |
128 | 131 | |
@@ -161,7 +164,9 @@ discard block |
||
161 | 164 | $mode = (preg_match('/^((@[A-Z_]+)[:]{0,1})(.*)/Asu', trim($name), |
162 | 165 | $tmp) && isset($tmp[2], $tmp[3])) ? $tmp[2] : false; |
163 | 166 | $subTmp = (isset($tmp[3])) ? trim($tmp[3]) : null; |
164 | - if ($this->twigEnabled) $mode = '@'.substr($mode,3); |
|
167 | + if ($this->twigEnabled) { |
|
168 | + $mode = '@'.substr($mode,3); |
|
169 | + } |
|
165 | 170 | switch ($mode) { |
166 | 171 | case '@FILE': |
167 | 172 | if ($subTmp != '') { |
@@ -374,7 +379,8 @@ discard block |
||
374 | 379 | * @param string $tpl |
375 | 380 | * @return null |
376 | 381 | */ |
377 | - protected function getTwig($name, $tpl) { |
|
382 | + protected function getTwig($name, $tpl) |
|
383 | + { |
|
378 | 384 | if (is_null($this->twig) && isset($this->modx->twig)) { |
379 | 385 | $twig = clone $this->modx->twig; |
380 | 386 | $this->twig = $twig; |