@@ -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 | |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | preg_match_all('~(?:=`[^`@]*?)(\[\+([^:\+\[\]]+)([^\[\]]*?)\+\])~s', $template, $matches);
|
| 96 | 96 | if ($matches[0]) {
|
| 97 | 97 | $template = str_replace($matches[1], '', $template); |
| 98 | - $this->Log("Cleaning unsolved tags: \n" . implode("\n", $matches[2]));
|
|
| 98 | + $this->Log("Cleaning unsolved tags: \n".implode("\n", $matches[2]));
|
|
| 99 | 99 | } |
| 100 | 100 | // Restore non-call characters in the template: [, ] |
| 101 | 101 | $template = str_replace($this->safetags[1], $this->safetags[2], $template); |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | } |
| 108 | 108 | // Write an event log if debugging is enabled and there is something to log |
| 109 | 109 | if ($this->debug && $this->debugLog) {
|
| 110 | - $this->modx->logEvent($this->curPass, 1, $this->createEventLog(), $this->name . ' ' . $this->version); |
|
| 110 | + $this->modx->logEvent($this->curPass, 1, $this->createEventLog(), $this->name.' '.$this->version); |
|
| 111 | 111 | $this->debugLog = false; |
| 112 | 112 | } |
| 113 | 113 | |
@@ -137,8 +137,8 @@ discard block |
||
| 137 | 137 | for ($i = 0; $i < $count; $i++) {
|
| 138 | 138 | $var_search[] = $matches[0][$i]; |
| 139 | 139 | $input = $matches[1][$i]; |
| 140 | - $this->Log('MODX Chunk: ' . $input);
|
|
| 141 | - $input = $this->modx->mergeChunkContent('{{' . $input . '}}');
|
|
| 140 | + $this->Log('MODX Chunk: '.$input);
|
|
| 141 | + $input = $this->modx->mergeChunkContent('{{'.$input.'}}');
|
|
| 142 | 142 | $var_replace[] = $this->Filter($input, $matches[2][$i]); |
| 143 | 143 | } |
| 144 | 144 | $template = str_replace($var_search, $var_replace, $template); |
@@ -154,10 +154,10 @@ discard block |
||
| 154 | 154 | // for each detected snippet |
| 155 | 155 | for ($i = 0; $i < $count; $i++) {
|
| 156 | 156 | $snippet = $matches[2][$i]; // snippet call |
| 157 | - $this->Log("MODx Snippet -> " . $snippet);
|
|
| 157 | + $this->Log("MODx Snippet -> ".$snippet);
|
|
| 158 | 158 | |
| 159 | 159 | // Let MODx evaluate snippet |
| 160 | - $replace = $this->modx->evalSnippets("[[" . $snippet . "]]");
|
|
| 160 | + $replace = $this->modx->evalSnippets("[[".$snippet."]]");
|
|
| 161 | 161 | $this->LogSnippet($replace); |
| 162 | 162 | |
| 163 | 163 | // Replace values |
@@ -186,19 +186,19 @@ discard block |
||
| 186 | 186 | switch ($matches[1][$i]) {
|
| 187 | 187 | // Document / Template Variable eXtended |
| 188 | 188 | case "*": |
| 189 | - $this->Log("MODx TV/DV: " . $input);
|
|
| 190 | - $input = $this->modx->mergeDocumentContent("[*" . $input . "*]");
|
|
| 189 | + $this->Log("MODx TV/DV: ".$input);
|
|
| 190 | + $input = $this->modx->mergeDocumentContent("[*".$input."*]");
|
|
| 191 | 191 | $replace = $this->Filter($input, $modifiers); |
| 192 | 192 | break; |
| 193 | 193 | // MODx Setting eXtended |
| 194 | 194 | case "(":
|
| 195 | - $this->Log("MODx Setting variable: " . $input);
|
|
| 196 | - $input = $this->modx->mergeSettingsContent("[(" . $input . ")]");
|
|
| 195 | + $this->Log("MODx Setting variable: ".$input);
|
|
| 196 | + $input = $this->modx->mergeSettingsContent("[(".$input.")]");
|
|
| 197 | 197 | $replace = $this->Filter($input, $modifiers); |
| 198 | 198 | break; |
| 199 | 199 | // MODx Placeholder eXtended |
| 200 | 200 | default: |
| 201 | - $this->Log("MODx / PHx placeholder variable: " . $input);
|
|
| 201 | + $this->Log("MODx / PHx placeholder variable: ".$input);
|
|
| 202 | 202 | // Check if placeholder is set |
| 203 | 203 | if (!array_key_exists($input, $this->placeholders) && !array_key_exists($input, |
| 204 | 204 | $this->modx->placeholders) |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | public function Filter($input, $modifiers) |
| 241 | 241 | {
|
| 242 | 242 | $output = $input; |
| 243 | - $this->Log(" |--- Input = '" . $output . "'");
|
|
| 243 | + $this->Log(" |--- Input = '".$output."'");
|
|
| 244 | 244 | if (preg_match_all('~:([^:=]+)(?:=`(.*?)`(?=:[^:=]+|$))?~s', $modifiers, $matches)) {
|
| 245 | 245 | $modifier_cmd = $matches[1]; // modifier command |
| 246 | 246 | $modifier_value = $matches[2]; // modifier value |
@@ -248,9 +248,9 @@ discard block |
||
| 248 | 248 | $condition = array(); |
| 249 | 249 | for ($i = 0; $i < $count; $i++) {
|
| 250 | 250 | $output = trim($output); |
| 251 | - $this->Log(" |--- Modifier = '" . $modifier_cmd[$i] . "'");
|
|
| 251 | + $this->Log(" |--- Modifier = '".$modifier_cmd[$i]."'");
|
|
| 252 | 252 | if ($modifier_value[$i] != '') {
|
| 253 | - $this->Log(" |--- Options = '" . $modifier_value[$i] . "'");
|
|
| 253 | + $this->Log(" |--- Options = '".$modifier_value[$i]."'");
|
|
| 254 | 254 | } |
| 255 | 255 | switch ($modifier_cmd[$i]) {
|
| 256 | 256 | ##### Conditional Modifiers |
@@ -391,7 +391,7 @@ discard block |
||
| 391 | 391 | break; |
| 392 | 392 | case "wordwrap": // default: 70 |
| 393 | 393 | $wrapat = intval($modifier_value[$i]) ? intval($modifier_value[$i]) : 70; |
| 394 | - $output = preg_replace_callback("@(\b\w+\b)@", function ($m) use ($wrapat) {
|
|
| 394 | + $output = preg_replace_callback("@(\b\w+\b)@", function($m) use ($wrapat) {
|
|
| 395 | 395 | return wordwrap($m[1], $wrapat, ' ', 1); |
| 396 | 396 | }, $output); |
| 397 | 397 | break; |
@@ -413,7 +413,7 @@ discard block |
||
| 413 | 413 | case "math": |
| 414 | 414 | $filter = preg_replace("~([a-zA-Z\n\r\t\s])~", "", $modifier_value[$i]);
|
| 415 | 415 | $filter = str_replace("?", $output, $filter);
|
| 416 | - $output = eval("return " . $filter . ";");
|
|
| 416 | + $output = eval("return ".$filter.";");
|
|
| 417 | 417 | break; |
| 418 | 418 | case "isnotempty": |
| 419 | 419 | if (!empty($output)) {
|
@@ -430,7 +430,7 @@ discard block |
||
| 430 | 430 | $output = nl2br($output); |
| 431 | 431 | break; |
| 432 | 432 | case "date": |
| 433 | - $output = strftime($modifier_value[$i], (int)$output); |
|
| 433 | + $output = strftime($modifier_value[$i], (int) $output); |
|
| 434 | 434 | break; |
| 435 | 435 | case "set": |
| 436 | 436 | $c = $i + 1; |
@@ -440,7 +440,7 @@ discard block |
||
| 440 | 440 | break; |
| 441 | 441 | case "value": |
| 442 | 442 | if ($i > 0 && $modifier_cmd[$i - 1] == "set") {
|
| 443 | - $this->modx->SetPlaceholder("phx." . $output, $modifier_value[$i]);
|
|
| 443 | + $this->modx->SetPlaceholder("phx.".$output, $modifier_value[$i]);
|
|
| 444 | 444 | } |
| 445 | 445 | $output = null; |
| 446 | 446 | break; |
@@ -465,12 +465,12 @@ discard block |
||
| 465 | 465 | default: |
| 466 | 466 | $snippet = ''; |
| 467 | 467 | // modified by Anton Kuzmin (23.06.2010) // |
| 468 | - $snippetName = 'phx:' . $modifier_cmd[$i]; |
|
| 468 | + $snippetName = 'phx:'.$modifier_cmd[$i]; |
|
| 469 | 469 | if (isset($this->modx->snippetCache[$snippetName])) {
|
| 470 | 470 | $snippet = $this->modx->snippetCache[$snippetName]; |
| 471 | 471 | } else {
|
| 472 | 472 | // not in cache so let's check the db |
| 473 | - $sql = "SELECT snippet FROM " . $this->modx->getFullTableName("site_snippets") . " WHERE " . $this->modx->getFullTableName("site_snippets") . ".name='" . $this->modx->db->escape($snippetName) . "';";
|
|
| 473 | + $sql = "SELECT snippet FROM ".$this->modx->getFullTableName("site_snippets")." WHERE ".$this->modx->getFullTableName("site_snippets").".name='".$this->modx->db->escape($snippetName)."';";
|
|
| 474 | 474 | $result = $this->modx->db->query($sql); |
| 475 | 475 | if ($this->modx->db->getRecordCount($result) == 1) {
|
| 476 | 476 | $row = $this->modx->db->getRow($result); |
@@ -479,14 +479,14 @@ discard block |
||
| 479 | 479 | } else {
|
| 480 | 480 | if ($this->modx->db->getRecordCount($result) == 0) {
|
| 481 | 481 | // If snippet not found, look in the modifiers folder |
| 482 | - $filename = $this->modx->config['rb_base_dir'] . 'plugins/phx/modifiers/' . $modifier_cmd[$i] . '.phx.php'; |
|
| 482 | + $filename = $this->modx->config['rb_base_dir'].'plugins/phx/modifiers/'.$modifier_cmd[$i].'.phx.php'; |
|
| 483 | 483 | if (@file_exists($filename)) {
|
| 484 | 484 | $file_contents = @file_get_contents($filename); |
| 485 | - $file_contents = str_replace('<' . '?php', '', $file_contents);
|
|
| 486 | - $file_contents = str_replace('?' . '>', '', $file_contents);
|
|
| 485 | + $file_contents = str_replace('<'.'?php', '', $file_contents);
|
|
| 486 | + $file_contents = str_replace('?'.'>', '', $file_contents);
|
|
| 487 | 487 | $file_contents = str_replace('<?', '', $file_contents);
|
| 488 | 488 | $snippet = $this->modx->snippetCache[$snippetName] = $file_contents; |
| 489 | - $this->modx->snippetCache[$snippetName . 'Props'] = ''; |
|
| 489 | + $this->modx->snippetCache[$snippetName.'Props'] = ''; |
|
| 490 | 490 | $this->Log(" |--- File ($filename) -> Custom Modifier");
|
| 491 | 491 | } else {
|
| 492 | 492 | $this->Log(" |--- PHX Error: {$modifier_cmd[$i]} could not be found");
|
@@ -506,9 +506,9 @@ discard block |
||
| 506 | 506 | break; |
| 507 | 507 | } |
| 508 | 508 | if (count($condition)) {
|
| 509 | - $this->Log(" |--- Condition = '" . $condition[count($condition) - 1] . "'");
|
|
| 509 | + $this->Log(" |--- Condition = '".$condition[count($condition) - 1]."'");
|
|
| 510 | 510 | } |
| 511 | - $this->Log(" |--- Output = '" . $output . "'");
|
|
| 511 | + $this->Log(" |--- Output = '".$output."'");
|
|
| 512 | 512 | } |
| 513 | 513 | } |
| 514 | 514 | |
@@ -521,7 +521,7 @@ discard block |
||
| 521 | 521 | */ |
| 522 | 522 | private function runCode($code) |
| 523 | 523 | {
|
| 524 | - return eval("return (" . $code . ");");
|
|
| 524 | + return eval("return (".$code.");");
|
|
| 525 | 525 | } |
| 526 | 526 | // Event logging (debug) |
| 527 | 527 | |
@@ -535,7 +535,7 @@ discard block |
||
| 535 | 535 | $console = implode("\n", $this->console);
|
| 536 | 536 | $this->console = array(); |
| 537 | 537 | |
| 538 | - $out = '<pre style="overflow: auto;">' . $console . '</pre>'; |
|
| 538 | + $out = '<pre style="overflow: auto;">'.$console.'</pre>'; |
|
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | return $out; |
@@ -564,8 +564,8 @@ discard block |
||
| 564 | 564 | {
|
| 565 | 565 | if ($this->debug) {
|
| 566 | 566 | $this->debugLog = true; |
| 567 | - $this->console[] = (count($this->console) + 1 - $this->curPass) . " [" . strftime("%H:%M:%S",
|
|
| 568 | - time()) . "] " . $this->LogClean($string); |
|
| 567 | + $this->console[] = (count($this->console) + 1 - $this->curPass)." [".strftime("%H:%M:%S",
|
|
| 568 | + time())."] ".$this->LogClean($string); |
|
| 569 | 569 | } |
| 570 | 570 | } |
| 571 | 571 | |
@@ -578,15 +578,15 @@ discard block |
||
| 578 | 578 | {
|
| 579 | 579 | if ($this->debug) {
|
| 580 | 580 | $this->debugLog = true; |
| 581 | - $this->console[] = (count($this->console) + 1 - $this->curPass) . " [" . strftime("%H:%M:%S",
|
|
| 582 | - time()) . "] " . " |--- Returns: <div style='margin: 10px;'>" . $this->LogClean($string) . "</div>"; |
|
| 581 | + $this->console[] = (count($this->console) + 1 - $this->curPass)." [".strftime("%H:%M:%S",
|
|
| 582 | + time())."] "." |--- Returns: <div style='margin: 10px;'>".$this->LogClean($string)."</div>"; |
|
| 583 | 583 | } |
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | // Log pass |
| 587 | 587 | public function LogPass() |
| 588 | 588 | {
|
| 589 | - $this->console[] = "<div style='margin: 5px 2px 2px;border-bottom: 1px solid black;'>Pass " . $this->curPass . "</div>"; |
|
| 589 | + $this->console[] = "<div style='margin: 5px 2px 2px;border-bottom: 1px solid black;'>Pass ".$this->curPass."</div>"; |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | // Log pass |
@@ -596,7 +596,7 @@ discard block |
||
| 596 | 596 | */ |
| 597 | 597 | public function LogSource($string) |
| 598 | 598 | {
|
| 599 | - $this->console[] = "<div style='margin: 5px 2px 2px;border-bottom: 1px solid black;'>Source:</div>" . $this->LogClean($string); |
|
| 599 | + $this->console[] = "<div style='margin: 5px 2px 2px;border-bottom: 1px solid black;'>Source:</div>".$this->LogClean($string); |
|
| 600 | 600 | } |
| 601 | 601 | |
| 602 | 602 | |
@@ -632,7 +632,7 @@ discard block |
||
| 632 | 632 | */ |
| 633 | 633 | public function isMemberOfWebGroupByUserId($userid = 0, $groupNames = array()) |
| 634 | 634 | {
|
| 635 | - $userid = (int)$userid; |
|
| 635 | + $userid = (int) $userid; |
|
| 636 | 636 | // if $groupNames is not an array return false |
| 637 | 637 | if (!is_array($groupNames)) {
|
| 638 | 638 | return false; |
@@ -757,7 +757,7 @@ discard block |
||
| 757 | 757 | public function ucfirst($str) |
| 758 | 758 | {
|
| 759 | 759 | if (function_exists('mb_strtoupper') && function_exists('mb_substr') && function_exists('mb_strlen')) {
|
| 760 | - return mb_strtoupper(mb_substr($str, 0, 1)) . mb_substr($str, 1, mb_strlen($str)); |
|
| 760 | + return mb_strtoupper(mb_substr($str, 0, 1)).mb_substr($str, 1, mb_strlen($str)); |
|
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | return ucfirst($str); |
@@ -770,7 +770,7 @@ discard block |
||
| 770 | 770 | public function lcfirst($str) |
| 771 | 771 | {
|
| 772 | 772 | if (function_exists('mb_strtolower') && function_exists('mb_substr') && function_exists('mb_strlen')) {
|
| 773 | - return mb_strtolower(mb_substr($str, 0, 1)) . mb_substr($str, 1, mb_strlen($str)); |
|
| 773 | + return mb_strtolower(mb_substr($str, 0, 1)).mb_substr($str, 1, mb_strlen($str)); |
|
| 774 | 774 | } |
| 775 | 775 | |
| 776 | 776 | 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* |
@@ -79,10 +79,10 @@ discard block |
||
| 79 | 79 | * @param string $template |
| 80 | 80 | * @return mixed|string |
| 81 | 81 | */ |
| 82 | - public function Parse($template = '') |
|
| 83 | - {
|
|
| 82 | + public function Parse($template = '') |
|
| 83 | + { |
|
| 84 | 84 | // If we already reached max passes don't get at it again. |
| 85 | - if ($this->curPass == $this->maxPasses) {
|
|
| 85 | + if ($this->curPass == $this->maxPasses) { |
|
| 86 | 86 | return $template; |
| 87 | 87 | } |
| 88 | 88 | // Set template pre-process hash |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | $template = $this->ParseValues($template); |
| 94 | 94 | // clean up unused placeholders that have modifiers attached (MODx can't clean them) |
| 95 | 95 | preg_match_all('~(?:=`[^`@]*?)(\[\+([^:\+\[\]]+)([^\[\]]*?)\+\])~s', $template, $matches);
|
| 96 | - if ($matches[0]) {
|
|
| 96 | + if ($matches[0]) { |
|
| 97 | 97 | $template = str_replace($matches[1], '', $template); |
| 98 | 98 | $this->Log("Cleaning unsolved tags: \n" . implode("\n", $matches[2]));
|
| 99 | 99 | } |
@@ -102,11 +102,11 @@ discard block |
||
| 102 | 102 | // Set template post-process hash |
| 103 | 103 | $et = md5($template); |
| 104 | 104 | // If template has changed, parse it once more... |
| 105 | - if ($st != $et) {
|
|
| 105 | + if ($st != $et) { |
|
| 106 | 106 | $template = $this->Parse($template); |
| 107 | 107 | } |
| 108 | 108 | // Write an event log if debugging is enabled and there is something to log |
| 109 | - if ($this->debug && $this->debugLog) {
|
|
| 109 | + if ($this->debug && $this->debugLog) { |
|
| 110 | 110 | $this->modx->logEvent($this->curPass, 1, $this->createEventLog(), $this->name . ' ' . $this->version); |
| 111 | 111 | $this->debugLog = false; |
| 112 | 112 | } |
@@ -121,20 +121,20 @@ discard block |
||
| 121 | 121 | * @param string $template |
| 122 | 122 | * @return mixed|string |
| 123 | 123 | */ |
| 124 | - public function ParseValues($template = '') |
|
| 125 | - {
|
|
| 124 | + public function ParseValues($template = '') |
|
| 125 | + { |
|
| 126 | 126 | $this->curPass = $this->curPass + 1; |
| 127 | 127 | $st = md5($template); |
| 128 | 128 | |
| 129 | 129 | $this->LogPass(); |
| 130 | 130 | |
| 131 | 131 | // MODX Chunks |
| 132 | - if (preg_match_all('~(?<!(?:then|else)=`){{([^:\+{}]+)([^{}]*?)}}~s', $template, $matches)) {
|
|
| 132 | + if (preg_match_all('~(?<!(?:then|else)=`){{([^:\+{}]+)([^{}]*?)}}~s', $template, $matches)) { |
|
| 133 | 133 | $this->Log('MODX Chunks -> Merging all chunk tags');
|
| 134 | 134 | $count = count($matches[0]); |
| 135 | 135 | $var_search = array(); |
| 136 | 136 | $var_replace = array(); |
| 137 | - for ($i = 0; $i < $count; $i++) {
|
|
| 137 | + for ($i = 0; $i < $count; $i++) { |
|
| 138 | 138 | $var_search[] = $matches[0][$i]; |
| 139 | 139 | $input = $matches[1][$i]; |
| 140 | 140 | $this->Log('MODX Chunk: ' . $input);
|
@@ -146,13 +146,13 @@ discard block |
||
| 146 | 146 | |
| 147 | 147 | // MODx Snippets |
| 148 | 148 | //if ( preg_match_all('~\[(\[|!)([^\[]*?)(!|\])\]~s',$template, $matches)) {
|
| 149 | - if (preg_match_all('~(?<!(?:then|else)=`)\[(\[)([^\[]*?)(\])\]~s', $template, $matches)) {
|
|
| 149 | + if (preg_match_all('~(?<!(?:then|else)=`)\[(\[)([^\[]*?)(\])\]~s', $template, $matches)) { |
|
| 150 | 150 | $count = count($matches[0]); |
| 151 | 151 | $var_search = array(); |
| 152 | 152 | $var_replace = array(); |
| 153 | 153 | |
| 154 | 154 | // for each detected snippet |
| 155 | - for ($i = 0; $i < $count; $i++) {
|
|
| 155 | + for ($i = 0; $i < $count; $i++) { |
|
| 156 | 156 | $snippet = $matches[2][$i]; // snippet call |
| 157 | 157 | $this->Log("MODx Snippet -> " . $snippet);
|
| 158 | 158 | |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | // PHx / MODx Tags |
| 171 | - if (preg_match_all('~\[(\+|\*|\()([^:\+\[\]]+)([^\[\]]*?)(\1|\))\]~s', $template, $matches)) {
|
|
| 171 | + if (preg_match_all('~\[(\+|\*|\()([^:\+\[\]]+)([^\[\]]*?)(\1|\))\]~s', $template, $matches)) { |
|
| 172 | 172 | |
| 173 | 173 | //$matches[0] // Complete string that's need to be replaced |
| 174 | 174 | //$matches[1] // Type |
@@ -179,11 +179,11 @@ discard block |
||
| 179 | 179 | $count = count($matches[0]); |
| 180 | 180 | $var_search = array(); |
| 181 | 181 | $var_replace = array(); |
| 182 | - for ($i = 0; $i < $count; $i++) {
|
|
| 182 | + for ($i = 0; $i < $count; $i++) { |
|
| 183 | 183 | $input = $matches[2][$i]; |
| 184 | 184 | $modifiers = $matches[3][$i]; |
| 185 | 185 | $var_search[] = $matches[0][$i]; |
| 186 | - switch ($matches[1][$i]) {
|
|
| 186 | + switch ($matches[1][$i]) { |
|
| 187 | 187 | // Document / Template Variable eXtended |
| 188 | 188 | case "*": |
| 189 | 189 | $this->Log("MODx TV/DV: " . $input);
|
@@ -202,10 +202,10 @@ discard block |
||
| 202 | 202 | // Check if placeholder is set |
| 203 | 203 | if (!array_key_exists($input, $this->placeholders) && !array_key_exists($input, |
| 204 | 204 | $this->modx->placeholders) |
| 205 | - ) {
|
|
| 205 | + ) { |
|
| 206 | 206 | // not set so try again later. |
| 207 | 207 | $input = ''; |
| 208 | - } else {
|
|
| 208 | + } else { |
|
| 209 | 209 | // is set, get value and run filter |
| 210 | 210 | $input = $this->getPHxVariable($input); |
| 211 | 211 | } |
@@ -219,11 +219,11 @@ discard block |
||
| 219 | 219 | $et = md5($template); // Post-process template hash |
| 220 | 220 | |
| 221 | 221 | // Log an event if this was the maximum pass |
| 222 | - if ($this->curPass == $this->maxPasses) {
|
|
| 222 | + if ($this->curPass == $this->maxPasses) { |
|
| 223 | 223 | $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.");
|
| 224 | 224 | } |
| 225 | 225 | // If this pass is not at maximum passes and the template hash is not the same, get at it again. |
| 226 | - if (($this->curPass < $this->maxPasses) && ($st != $et)) {
|
|
| 226 | + if (($this->curPass < $this->maxPasses) && ($st != $et)) { |
|
| 227 | 227 | $template = $this->ParseValues($template); |
| 228 | 228 | } |
| 229 | 229 | |
@@ -237,22 +237,22 @@ discard block |
||
| 237 | 237 | * @param $modifiers |
| 238 | 238 | * @return mixed|null|string |
| 239 | 239 | */ |
| 240 | - public function Filter($input, $modifiers) |
|
| 241 | - {
|
|
| 240 | + public function Filter($input, $modifiers) |
|
| 241 | + { |
|
| 242 | 242 | $output = $input; |
| 243 | 243 | $this->Log(" |--- Input = '" . $output . "'");
|
| 244 | - if (preg_match_all('~:([^:=]+)(?:=`(.*?)`(?=:[^:=]+|$))?~s', $modifiers, $matches)) {
|
|
| 244 | + if (preg_match_all('~:([^:=]+)(?:=`(.*?)`(?=:[^:=]+|$))?~s', $modifiers, $matches)) { |
|
| 245 | 245 | $modifier_cmd = $matches[1]; // modifier command |
| 246 | 246 | $modifier_value = $matches[2]; // modifier value |
| 247 | 247 | $count = count($modifier_cmd); |
| 248 | 248 | $condition = array(); |
| 249 | - for ($i = 0; $i < $count; $i++) {
|
|
| 249 | + for ($i = 0; $i < $count; $i++) { |
|
| 250 | 250 | $output = trim($output); |
| 251 | 251 | $this->Log(" |--- Modifier = '" . $modifier_cmd[$i] . "'");
|
| 252 | - if ($modifier_value[$i] != '') {
|
|
| 252 | + if ($modifier_value[$i] != '') { |
|
| 253 | 253 | $this->Log(" |--- Options = '" . $modifier_value[$i] . "'");
|
| 254 | 254 | } |
| 255 | - switch ($modifier_cmd[$i]) {
|
|
| 255 | + switch ($modifier_cmd[$i]) { |
|
| 256 | 256 | ##### Conditional Modifiers |
| 257 | 257 | case "input": |
| 258 | 258 | case "if": |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | case "ir": |
| 295 | 295 | case "memberof": |
| 296 | 296 | case "mo": // Is Member Of (same as inrole but this one can be stringed as a conditional) |
| 297 | - if ($output == "&_PHX_INTERNAL_&") {
|
|
| 297 | + if ($output == "&_PHX_INTERNAL_&") { |
|
| 298 | 298 | $output = $this->user["id"]; |
| 299 | 299 | } |
| 300 | 300 | $grps = ($this->strlen($modifier_value[$i]) > 0) ? explode(",", $modifier_value[$i]) : array();
|
@@ -309,23 +309,23 @@ discard block |
||
| 309 | 309 | case "show": |
| 310 | 310 | $conditional = implode(' ', $condition);
|
| 311 | 311 | $isvalid = intval($this->runCode($conditional)); |
| 312 | - if (!$isvalid) {
|
|
| 312 | + if (!$isvalid) { |
|
| 313 | 313 | $output = null; |
| 314 | 314 | } |
| 315 | 315 | break; |
| 316 | 316 | case "then": |
| 317 | 317 | $conditional = implode(' ', $condition);
|
| 318 | 318 | $isvalid = intval($this->runCode($conditional)); |
| 319 | - if ($isvalid) {
|
|
| 319 | + if ($isvalid) { |
|
| 320 | 320 | $output = $modifier_value[$i]; |
| 321 | - } else {
|
|
| 321 | + } else { |
|
| 322 | 322 | $output = null; |
| 323 | 323 | } |
| 324 | 324 | break; |
| 325 | 325 | case "else": |
| 326 | 326 | $conditional = implode(' ', $condition);
|
| 327 | 327 | $isvalid = intval($this->runCode($conditional)); |
| 328 | - if (!$isvalid) {
|
|
| 328 | + if (!$isvalid) { |
|
| 329 | 329 | $output = $modifier_value[$i]; |
| 330 | 330 | } |
| 331 | 331 | break; |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | $raw = explode("&", $modifier_value[$i]);
|
| 334 | 334 | $map = array(); |
| 335 | 335 | $count = count($raw); |
| 336 | - for ($m = 0; $m < $count; $m++) {
|
|
| 336 | + for ($m = 0; $m < $count; $m++) { |
|
| 337 | 337 | $mi = explode("=", $raw[$m]);
|
| 338 | 338 | $map[$mi[0]] = $mi[1]; |
| 339 | 339 | } |
@@ -391,7 +391,7 @@ discard block |
||
| 391 | 391 | break; |
| 392 | 392 | case "wordwrap": // default: 70 |
| 393 | 393 | $wrapat = intval($modifier_value[$i]) ? intval($modifier_value[$i]) : 70; |
| 394 | - $output = preg_replace_callback("@(\b\w+\b)@", function ($m) use ($wrapat) {
|
|
| 394 | + $output = preg_replace_callback("@(\b\w+\b)@", function ($m) use ($wrapat){ |
|
| 395 | 395 | return wordwrap($m[1], $wrapat, ' ', 1); |
| 396 | 396 | }, $output); |
| 397 | 397 | break; |
@@ -416,13 +416,13 @@ discard block |
||
| 416 | 416 | $output = eval("return " . $filter . ";");
|
| 417 | 417 | break; |
| 418 | 418 | case "isnotempty": |
| 419 | - if (!empty($output)) {
|
|
| 419 | + if (!empty($output)) { |
|
| 420 | 420 | $output = $modifier_value[$i]; |
| 421 | 421 | } |
| 422 | 422 | break; |
| 423 | 423 | case "isempty": |
| 424 | 424 | case "ifempty": |
| 425 | - if (empty($output)) {
|
|
| 425 | + if (empty($output)) { |
|
| 426 | 426 | $output = $modifier_value[$i]; |
| 427 | 427 | } |
| 428 | 428 | break; |
@@ -434,12 +434,12 @@ discard block |
||
| 434 | 434 | break; |
| 435 | 435 | case "set": |
| 436 | 436 | $c = $i + 1; |
| 437 | - if ($count > $c && $modifier_cmd[$c] == "value") {
|
|
| 437 | + if ($count > $c && $modifier_cmd[$c] == "value") { |
|
| 438 | 438 | $output = preg_replace("~([^a-zA-Z0-9])~", "", $modifier_value[$i]);
|
| 439 | 439 | } |
| 440 | 440 | break; |
| 441 | 441 | case "value": |
| 442 | - if ($i > 0 && $modifier_cmd[$i - 1] == "set") {
|
|
| 442 | + if ($i > 0 && $modifier_cmd[$i - 1] == "set") { |
|
| 443 | 443 | $this->modx->SetPlaceholder("phx." . $output, $modifier_value[$i]);
|
| 444 | 444 | } |
| 445 | 445 | $output = null; |
@@ -448,13 +448,13 @@ discard block |
||
| 448 | 448 | $output = md5($output); |
| 449 | 449 | break; |
| 450 | 450 | case "userinfo": |
| 451 | - if ($output == "&_PHX_INTERNAL_&") {
|
|
| 451 | + if ($output == "&_PHX_INTERNAL_&") { |
|
| 452 | 452 | $output = $this->user["id"]; |
| 453 | 453 | } |
| 454 | 454 | $output = $this->ModUser($output, $modifier_value[$i]); |
| 455 | 455 | break; |
| 456 | 456 | case "inrole": // deprecated |
| 457 | - if ($output == "&_PHX_INTERNAL_&") {
|
|
| 457 | + if ($output == "&_PHX_INTERNAL_&") { |
|
| 458 | 458 | $output = $this->user["id"]; |
| 459 | 459 | } |
| 460 | 460 | $grps = ($this->strlen($modifier_value[$i]) > 0) ? explode(",", $modifier_value[$i]) : array();
|
@@ -466,21 +466,21 @@ discard block |
||
| 466 | 466 | $snippet = ''; |
| 467 | 467 | // modified by Anton Kuzmin (23.06.2010) // |
| 468 | 468 | $snippetName = 'phx:' . $modifier_cmd[$i]; |
| 469 | - if (isset($this->modx->snippetCache[$snippetName])) {
|
|
| 469 | + if (isset($this->modx->snippetCache[$snippetName])) { |
|
| 470 | 470 | $snippet = $this->modx->snippetCache[$snippetName]; |
| 471 | - } else {
|
|
| 471 | + } else { |
|
| 472 | 472 | // not in cache so let's check the db |
| 473 | 473 | $sql = "SELECT snippet FROM " . $this->modx->getFullTableName("site_snippets") . " WHERE " . $this->modx->getFullTableName("site_snippets") . ".name='" . $this->modx->db->escape($snippetName) . "';";
|
| 474 | 474 | $result = $this->modx->db->query($sql); |
| 475 | - if ($this->modx->db->getRecordCount($result) == 1) {
|
|
| 475 | + if ($this->modx->db->getRecordCount($result) == 1) { |
|
| 476 | 476 | $row = $this->modx->db->getRow($result); |
| 477 | 477 | $snippet = $this->modx->snippetCache[$row['name']] = $row['snippet']; |
| 478 | 478 | $this->Log(" |--- DB -> Custom Modifier");
|
| 479 | - } else {
|
|
| 480 | - if ($this->modx->db->getRecordCount($result) == 0) {
|
|
| 479 | + } else { |
|
| 480 | + if ($this->modx->db->getRecordCount($result) == 0) { |
|
| 481 | 481 | // If snippet not found, look in the modifiers folder |
| 482 | 482 | $filename = $this->modx->config['rb_base_dir'] . 'plugins/phx/modifiers/' . $modifier_cmd[$i] . '.phx.php'; |
| 483 | - if (@file_exists($filename)) {
|
|
| 483 | + if (@file_exists($filename)) { |
|
| 484 | 484 | $file_contents = @file_get_contents($filename); |
| 485 | 485 | $file_contents = str_replace('<' . '?php', '', $file_contents);
|
| 486 | 486 | $file_contents = str_replace('?' . '>', '', $file_contents);
|
@@ -488,24 +488,24 @@ discard block |
||
| 488 | 488 | $snippet = $this->modx->snippetCache[$snippetName] = $file_contents; |
| 489 | 489 | $this->modx->snippetCache[$snippetName . 'Props'] = ''; |
| 490 | 490 | $this->Log(" |--- File ($filename) -> Custom Modifier");
|
| 491 | - } else {
|
|
| 491 | + } else { |
|
| 492 | 492 | $this->Log(" |--- PHX Error: {$modifier_cmd[$i]} could not be found");
|
| 493 | 493 | } |
| 494 | 494 | } |
| 495 | 495 | } |
| 496 | 496 | } |
| 497 | - if (!empty($snippet)) {
|
|
| 497 | + if (!empty($snippet)) { |
|
| 498 | 498 | $output = $this->modx->runSnippet($snippetName, array( |
| 499 | 499 | 'input' => $output, |
| 500 | 500 | 'output' => $output, |
| 501 | 501 | 'options' => $modifier_value[$i] |
| 502 | 502 | )); |
| 503 | - } else {
|
|
| 503 | + } else { |
|
| 504 | 504 | $output = ''; |
| 505 | 505 | } |
| 506 | 506 | break; |
| 507 | 507 | } |
| 508 | - if (count($condition)) {
|
|
| 508 | + if (count($condition)) { |
|
| 509 | 509 | $this->Log(" |--- Condition = '" . $condition[count($condition) - 1] . "'");
|
| 510 | 510 | } |
| 511 | 511 | $this->Log(" |--- Output = '" . $output . "'");
|
@@ -519,8 +519,8 @@ discard block |
||
| 519 | 519 | * @param string $code |
| 520 | 520 | * @return mixed |
| 521 | 521 | */ |
| 522 | - private function runCode($code) |
|
| 523 | - {
|
|
| 522 | + private function runCode($code) |
|
| 523 | + { |
|
| 524 | 524 | return eval("return (" . $code . ");");
|
| 525 | 525 | } |
| 526 | 526 | // Event logging (debug) |
@@ -528,10 +528,10 @@ discard block |
||
| 528 | 528 | /** |
| 529 | 529 | * @return string |
| 530 | 530 | */ |
| 531 | - public function createEventLog() |
|
| 532 | - {
|
|
| 531 | + public function createEventLog() |
|
| 532 | + { |
|
| 533 | 533 | $out = ''; |
| 534 | - if (!empty($this->console)) {
|
|
| 534 | + if (!empty($this->console)) { |
|
| 535 | 535 | $console = implode("\n", $this->console);
|
| 536 | 536 | $this->console = array(); |
| 537 | 537 | |
@@ -547,8 +547,8 @@ discard block |
||
| 547 | 547 | * @param $string |
| 548 | 548 | * @return array|mixed|string |
| 549 | 549 | */ |
| 550 | - public function LogClean($string) |
|
| 551 | - {
|
|
| 550 | + public function LogClean($string) |
|
| 551 | + { |
|
| 552 | 552 | $string = preg_replace("/&(#[0-9]+|[a-z]+);/i", "&$1;", $string);
|
| 553 | 553 | $string = APIHelpers::sanitarTag($string); |
| 554 | 554 | |
@@ -560,9 +560,9 @@ discard block |
||
| 560 | 560 | /** |
| 561 | 561 | * @param $string |
| 562 | 562 | */ |
| 563 | - public function Log($string) |
|
| 564 | - {
|
|
| 565 | - if ($this->debug) {
|
|
| 563 | + public function Log($string) |
|
| 564 | + { |
|
| 565 | + if ($this->debug) { |
|
| 566 | 566 | $this->debugLog = true; |
| 567 | 567 | $this->console[] = (count($this->console) + 1 - $this->curPass) . " [" . strftime("%H:%M:%S",
|
| 568 | 568 | time()) . "] " . $this->LogClean($string); |
@@ -574,9 +574,9 @@ discard block |
||
| 574 | 574 | /** |
| 575 | 575 | * @param $string |
| 576 | 576 | */ |
| 577 | - public function LogSnippet($string) |
|
| 578 | - {
|
|
| 579 | - if ($this->debug) {
|
|
| 577 | + public function LogSnippet($string) |
|
| 578 | + { |
|
| 579 | + if ($this->debug) { |
|
| 580 | 580 | $this->debugLog = true; |
| 581 | 581 | $this->console[] = (count($this->console) + 1 - $this->curPass) . " [" . strftime("%H:%M:%S",
|
| 582 | 582 | time()) . "] " . " |--- Returns: <div style='margin: 10px;'>" . $this->LogClean($string) . "</div>"; |
@@ -584,8 +584,8 @@ discard block |
||
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | // Log pass |
| 587 | - public function LogPass() |
|
| 588 | - {
|
|
| 587 | + public function LogPass() |
|
| 588 | + { |
|
| 589 | 589 | $this->console[] = "<div style='margin: 5px 2px 2px;border-bottom: 1px solid black;'>Pass " . $this->curPass . "</div>"; |
| 590 | 590 | } |
| 591 | 591 | |
@@ -594,8 +594,8 @@ discard block |
||
| 594 | 594 | /** |
| 595 | 595 | * @param $string |
| 596 | 596 | */ |
| 597 | - public function LogSource($string) |
|
| 598 | - {
|
|
| 597 | + public function LogSource($string) |
|
| 598 | + { |
|
| 599 | 599 | $this->console[] = "<div style='margin: 5px 2px 2px;border-bottom: 1px solid black;'>Source:</div>" . $this->LogClean($string); |
| 600 | 600 | } |
| 601 | 601 | |
@@ -607,16 +607,16 @@ discard block |
||
| 607 | 607 | * @param $field |
| 608 | 608 | * @return mixed |
| 609 | 609 | */ |
| 610 | - public function ModUser($userid, $field) |
|
| 611 | - {
|
|
| 612 | - if (!array_key_exists($userid, $this->cache["ui"])) {
|
|
| 613 | - if (intval($userid) < 0) {
|
|
| 610 | + public function ModUser($userid, $field) |
|
| 611 | + { |
|
| 612 | + if (!array_key_exists($userid, $this->cache["ui"])) { |
|
| 613 | + if (intval($userid) < 0) { |
|
| 614 | 614 | $user = $this->modx->getWebUserInfo(-($userid)); |
| 615 | - } else {
|
|
| 615 | + } else { |
|
| 616 | 616 | $user = $this->modx->getUserInfo($userid); |
| 617 | 617 | } |
| 618 | 618 | $this->cache["ui"][$userid] = $user; |
| 619 | - } else {
|
|
| 619 | + } else { |
|
| 620 | 620 | $user = $this->cache["ui"][$userid]; |
| 621 | 621 | } |
| 622 | 622 | |
@@ -630,31 +630,31 @@ discard block |
||
| 630 | 630 | * @param array $groupNames |
| 631 | 631 | * @return bool |
| 632 | 632 | */ |
| 633 | - public function isMemberOfWebGroupByUserId($userid = 0, $groupNames = array()) |
|
| 634 | - {
|
|
| 633 | + public function isMemberOfWebGroupByUserId($userid = 0, $groupNames = array()) |
|
| 634 | + { |
|
| 635 | 635 | $userid = (int)$userid; |
| 636 | 636 | // if $groupNames is not an array return false |
| 637 | - if (!is_array($groupNames)) {
|
|
| 637 | + if (!is_array($groupNames)) { |
|
| 638 | 638 | return false; |
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | // if the user id is a negative number make it positive |
| 642 | - if (intval($userid) < 0) {
|
|
| 642 | + if (intval($userid) < 0) { |
|
| 643 | 643 | $userid = -($userid); |
| 644 | 644 | } |
| 645 | 645 | |
| 646 | 646 | // Creates an array with all webgroups the user id is in |
| 647 | - if (!array_key_exists($userid, $this->cache["mo"])) {
|
|
| 647 | + if (!array_key_exists($userid, $this->cache["mo"])) { |
|
| 648 | 648 | $tbl = $this->modx->getFullTableName("webgroup_names");
|
| 649 | 649 | $tbl2 = $this->modx->getFullTableName("web_groups");
|
| 650 | 650 | $sql = "SELECT `wgn`.`name` FROM {$tbl} `wgn` INNER JOIN {$tbl2} `wg` ON `wg`.`webgroup`=`wgn`.`id` AND `wg`.`webuser`={$userid}";
|
| 651 | 651 | $this->cache["mo"][$userid] = $grpNames = $this->modx->db->getColumn("name", $sql);
|
| 652 | - } else {
|
|
| 652 | + } else { |
|
| 653 | 653 | $grpNames = $this->cache["mo"][$userid]; |
| 654 | 654 | } |
| 655 | 655 | // Check if a supplied group matches a webgroup from the array we just created |
| 656 | - foreach ($groupNames as $k => $v) {
|
|
| 657 | - if (in_array(trim($v), $grpNames)) {
|
|
| 656 | + foreach ($groupNames as $k => $v) { |
|
| 657 | + if (in_array(trim($v), $grpNames)) { |
|
| 658 | 658 | return true; |
| 659 | 659 | } |
| 660 | 660 | } |
@@ -669,13 +669,13 @@ discard block |
||
| 669 | 669 | * @param $name |
| 670 | 670 | * @return mixed|string |
| 671 | 671 | */ |
| 672 | - public function getPHxVariable($name) |
|
| 673 | - {
|
|
| 672 | + public function getPHxVariable($name) |
|
| 673 | + { |
|
| 674 | 674 | // Check if this variable is created by PHx |
| 675 | - if (array_key_exists($name, $this->placeholders)) {
|
|
| 675 | + if (array_key_exists($name, $this->placeholders)) { |
|
| 676 | 676 | // Return the value from PHx |
| 677 | 677 | return $this->placeholders[$name]; |
| 678 | - } else {
|
|
| 678 | + } else { |
|
| 679 | 679 | // Return the value from MODx |
| 680 | 680 | return $this->modx->getPlaceholder($name); |
| 681 | 681 | } |
@@ -687,9 +687,9 @@ discard block |
||
| 687 | 687 | * @param $name |
| 688 | 688 | * @param $value |
| 689 | 689 | */ |
| 690 | - public function setPHxVariable($name, $value) |
|
| 691 | - {
|
|
| 692 | - if ($name != "phx") {
|
|
| 690 | + public function setPHxVariable($name, $value) |
|
| 691 | + { |
|
| 692 | + if ($name != "phx") { |
|
| 693 | 693 | $this->placeholders[$name] = $value; |
| 694 | 694 | } |
| 695 | 695 | } |
@@ -702,9 +702,9 @@ discard block |
||
| 702 | 702 | * @param null $l |
| 703 | 703 | * @return string |
| 704 | 704 | */ |
| 705 | - public function substr($str, $s, $l = null) |
|
| 706 | - {
|
|
| 707 | - if (function_exists('mb_substr')) {
|
|
| 705 | + public function substr($str, $s, $l = null) |
|
| 706 | + { |
|
| 707 | + if (function_exists('mb_substr')) { |
|
| 708 | 708 | return mb_substr($str, $s, $l); |
| 709 | 709 | } |
| 710 | 710 | |
@@ -715,9 +715,9 @@ discard block |
||
| 715 | 715 | * @param $str |
| 716 | 716 | * @return int |
| 717 | 717 | */ |
| 718 | - public function strlen($str) |
|
| 719 | - {
|
|
| 720 | - if (function_exists('mb_strlen')) {
|
|
| 718 | + public function strlen($str) |
|
| 719 | + { |
|
| 720 | + if (function_exists('mb_strlen')) { |
|
| 721 | 721 | return mb_strlen($str); |
| 722 | 722 | } |
| 723 | 723 | |
@@ -728,9 +728,9 @@ discard block |
||
| 728 | 728 | * @param $str |
| 729 | 729 | * @return string |
| 730 | 730 | */ |
| 731 | - public function strtolower($str) |
|
| 732 | - {
|
|
| 733 | - if (function_exists('mb_strtolower')) {
|
|
| 731 | + public function strtolower($str) |
|
| 732 | + { |
|
| 733 | + if (function_exists('mb_strtolower')) { |
|
| 734 | 734 | return mb_strtolower($str); |
| 735 | 735 | } |
| 736 | 736 | |
@@ -741,9 +741,9 @@ discard block |
||
| 741 | 741 | * @param $str |
| 742 | 742 | * @return string |
| 743 | 743 | */ |
| 744 | - public function strtoupper($str) |
|
| 745 | - {
|
|
| 746 | - if (function_exists('mb_strtoupper')) {
|
|
| 744 | + public function strtoupper($str) |
|
| 745 | + { |
|
| 746 | + if (function_exists('mb_strtoupper')) { |
|
| 747 | 747 | return mb_strtoupper($str); |
| 748 | 748 | } |
| 749 | 749 | |
@@ -754,9 +754,9 @@ discard block |
||
| 754 | 754 | * @param $str |
| 755 | 755 | * @return string |
| 756 | 756 | */ |
| 757 | - public function ucfirst($str) |
|
| 758 | - {
|
|
| 759 | - if (function_exists('mb_strtoupper') && function_exists('mb_substr') && function_exists('mb_strlen')) {
|
|
| 757 | + public function ucfirst($str) |
|
| 758 | + { |
|
| 759 | + if (function_exists('mb_strtoupper') && function_exists('mb_substr') && function_exists('mb_strlen')) { |
|
| 760 | 760 | return mb_strtoupper(mb_substr($str, 0, 1)) . mb_substr($str, 1, mb_strlen($str)); |
| 761 | 761 | } |
| 762 | 762 | |
@@ -767,9 +767,9 @@ discard block |
||
| 767 | 767 | * @param $str |
| 768 | 768 | * @return string |
| 769 | 769 | */ |
| 770 | - public function lcfirst($str) |
|
| 771 | - {
|
|
| 772 | - if (function_exists('mb_strtolower') && function_exists('mb_substr') && function_exists('mb_strlen')) {
|
|
| 770 | + public function lcfirst($str) |
|
| 771 | + { |
|
| 772 | + if (function_exists('mb_strtolower') && function_exists('mb_substr') && function_exists('mb_strlen')) { |
|
| 773 | 773 | return mb_strtolower(mb_substr($str, 0, 1)) . mb_substr($str, 1, mb_strlen($str)); |
| 774 | 774 | } |
| 775 | 775 | |
@@ -780,9 +780,9 @@ discard block |
||
| 780 | 780 | * @param $str |
| 781 | 781 | * @return string |
| 782 | 782 | */ |
| 783 | - public function ucwords($str) |
|
| 784 | - {
|
|
| 785 | - if (function_exists('mb_convert_case')) {
|
|
| 783 | + public function ucwords($str) |
|
| 784 | + { |
|
| 785 | + if (function_exists('mb_convert_case')) { |
|
| 786 | 786 | return mb_convert_case($str, MB_CASE_TITLE); |
| 787 | 787 | } |
| 788 | 788 | |
@@ -793,8 +793,8 @@ discard block |
||
| 793 | 793 | * @param $str |
| 794 | 794 | * @return string |
| 795 | 795 | */ |
| 796 | - public function strrev($str) |
|
| 797 | - {
|
|
| 796 | + public function strrev($str) |
|
| 797 | + { |
|
| 798 | 798 | preg_match_all('/./us', $str, $ar);
|
| 799 | 799 | |
| 800 | 800 | return implode(array_reverse($ar[0])); |
@@ -804,8 +804,8 @@ discard block |
||
| 804 | 804 | * @param $str |
| 805 | 805 | * @return string |
| 806 | 806 | */ |
| 807 | - public function str_shuffle($str) |
|
| 808 | - {
|
|
| 807 | + public function str_shuffle($str) |
|
| 808 | + { |
|
| 809 | 809 | preg_match_all('/./us', $str, $ar);
|
| 810 | 810 | shuffle($ar[0]); |
| 811 | 811 | |
@@ -816,8 +816,8 @@ discard block |
||
| 816 | 816 | * @param $str |
| 817 | 817 | * @return int |
| 818 | 818 | */ |
| 819 | - public function str_word_count($str) |
|
| 820 | - {
|
|
| 819 | + public function str_word_count($str) |
|
| 820 | + { |
|
| 821 | 821 | return count(preg_split('~[^\p{L}\p{N}\']+~u', $str));
|
| 822 | 822 | } |
| 823 | 823 | } |