@@ -130,7 +130,7 @@ |
||
| 130 | 130 | * duplicate of method in documentParser class |
| 131 | 131 | * |
| 132 | 132 | * @param string $propertyString |
| 133 | - * @return array |
|
| 133 | + * @return string |
|
| 134 | 134 | */ |
| 135 | 135 | function parseProperties($propertyString) { |
| 136 | 136 | $parameter= array (); |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if (file_exists(dirname(__FILE__)."/../assets/cache/siteManager.php")) { |
| 3 | 3 | include_once(dirname(__FILE__)."/../assets/cache/siteManager.php"); |
| 4 | -}else{ |
|
| 4 | +} else { |
|
| 5 | 5 | define('MGR_DIR', 'manager'); |
| 6 | 6 | } |
| 7 | 7 | |
@@ -58,13 +58,15 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | // get base path and url |
| 60 | 60 | $a = explode("install", str_replace("\\", "/", dirname($_SERVER["PHP_SELF"]))); |
| 61 | -if (count($a) > 1) |
|
| 61 | +if (count($a) > 1) { |
|
| 62 | 62 | array_pop($a); |
| 63 | +} |
|
| 63 | 64 | $url = implode("install", $a); |
| 64 | 65 | reset($a); |
| 65 | 66 | $a = explode("install", str_replace("\\", "/", realpath(dirname(__FILE__)))); |
| 66 | -if (count($a) > 1) |
|
| 67 | +if (count($a) > 1) { |
|
| 67 | 68 | array_pop($a); |
| 69 | +} |
|
| 68 | 70 | $pth = implode("install", $a); |
| 69 | 71 | unset ($a); |
| 70 | 72 | $base_url = $url . (substr($url, -1) != "/" ? "/" : ""); |
@@ -85,7 +87,9 @@ discard block |
||
| 85 | 87 | echo "<span class=\"notok\" style='color:#707070'>".$_lang['setup_database_selection_failed']."</span>".$_lang['setup_database_selection_failed_note']."</p>"; |
| 86 | 88 | $create = true; |
| 87 | 89 | } else { |
| 88 | - if (function_exists('mysqli_set_charset')) mysqli_set_charset($conn, $database_charset); |
|
| 90 | + if (function_exists('mysqli_set_charset')) { |
|
| 91 | + mysqli_set_charset($conn, $database_charset); |
|
| 92 | + } |
|
| 89 | 93 | mysqli_query($conn, "{$database_connection_method} {$database_connection_charset}"); |
| 90 | 94 | echo '<span class="ok">'.$_lang['ok']."</span></p>"; |
| 91 | 95 | } |
@@ -132,7 +136,8 @@ discard block |
||
| 132 | 136 | * @param string $propertyString |
| 133 | 137 | * @return array |
| 134 | 138 | */ |
| 135 | - function parseProperties($propertyString) { |
|
| 139 | + function parseProperties($propertyString) |
|
| 140 | + { |
|
| 136 | 141 | $parameter= array (); |
| 137 | 142 | if (!empty ($propertyString)) { |
| 138 | 143 | $tmpParams= explode("&", $propertyString); |
@@ -141,11 +146,14 @@ discard block |
||
| 141 | 146 | if (strpos($tmpParams[$x], '=', 0)) { |
| 142 | 147 | $pTmp= explode("=", $tmpParams[$x]); |
| 143 | 148 | $pvTmp= explode(";", trim($pTmp[1])); |
| 144 | - if ($pvTmp[1] == 'list' && $pvTmp[3] != "") |
|
| 145 | - $parameter[trim($pTmp[0])]= $pvTmp[3]; //list default |
|
| 149 | + if ($pvTmp[1] == 'list' && $pvTmp[3] != "") { |
|
| 150 | + $parameter[trim($pTmp[0])]= $pvTmp[3]; |
|
| 151 | + } |
|
| 152 | + //list default |
|
| 146 | 153 | else |
| 147 | - if ($pvTmp[1] != 'list' && $pvTmp[2] != "") |
|
| 148 | - $parameter[trim($pTmp[0])]= $pvTmp[2]; |
|
| 154 | + if ($pvTmp[1] != 'list' && $pvTmp[2] != "") { |
|
| 155 | + $parameter[trim($pTmp[0])]= $pvTmp[2]; |
|
| 156 | + } |
|
| 149 | 157 | } |
| 150 | 158 | } |
| 151 | 159 | } |
@@ -216,7 +224,7 @@ discard block |
||
| 216 | 224 | // custom or not |
| 217 | 225 | if (file_exists(dirname(__FILE__)."/../../assets/cache/siteManager.php")) { |
| 218 | 226 | $mgrdir = 'include_once(dirname(__FILE__)."/../../assets/cache/siteManager.php");'; |
| 219 | -}else{ |
|
| 227 | +} else { |
|
| 220 | 228 | $mgrdir = 'define(\'MGR_DIR\', \'manager\');'; |
| 221 | 229 | } |
| 222 | 230 | |
@@ -352,7 +360,9 @@ discard block |
||
| 352 | 360 | echo "<p>" . mysqli_error($sqlParser->conn) . "</p>"; |
| 353 | 361 | return; |
| 354 | 362 | } |
| 355 | - if(!is_null($save_sql_id_as)) $custom_placeholders[$save_sql_id_as] = @mysqli_insert_id($sqlParser->conn); |
|
| 363 | + if(!is_null($save_sql_id_as)) { |
|
| 364 | + $custom_placeholders[$save_sql_id_as] = @mysqli_insert_id($sqlParser->conn); |
|
| 365 | + } |
|
| 356 | 366 | echo "<p> $name: <span class=\"ok\">" . $_lang['installed'] . "</span></p>"; |
| 357 | 367 | } |
| 358 | 368 | } |
@@ -446,9 +456,9 @@ discard block |
||
| 446 | 456 | $overwrite = mysqli_real_escape_string($conn, $moduleChunk[4]); |
| 447 | 457 | $filecontent = $moduleChunk[2]; |
| 448 | 458 | |
| 449 | - if (!file_exists($filecontent)) |
|
| 450 | - echo "<p> $name: <span class=\"notok\">" . $_lang['unable_install_chunk'] . " '$filecontent' " . $_lang['not_found'] . ".</span></p>"; |
|
| 451 | - else { |
|
| 459 | + if (!file_exists($filecontent)) { |
|
| 460 | + echo "<p> $name: <span class=\"notok\">" . $_lang['unable_install_chunk'] . " '$filecontent' " . $_lang['not_found'] . ".</span></p>"; |
|
| 461 | + } else { |
|
| 452 | 462 | |
| 453 | 463 | // Create the category if it does not already exist |
| 454 | 464 | $category_id = getCreateDbCategory($category, $sqlParser); |
@@ -500,9 +510,9 @@ discard block |
||
| 500 | 510 | $guid = mysqli_real_escape_string($conn, $moduleModule[4]); |
| 501 | 511 | $shared = mysqli_real_escape_string($conn, $moduleModule[5]); |
| 502 | 512 | $category = mysqli_real_escape_string($conn, $moduleModule[6]); |
| 503 | - if (!file_exists($filecontent)) |
|
| 504 | - echo "<p> $name: <span class=\"notok\">" . $_lang['unable_install_module'] . " '$filecontent' " . $_lang['not_found'] . ".</span></p>"; |
|
| 505 | - else { |
|
| 513 | + if (!file_exists($filecontent)) { |
|
| 514 | + echo "<p> $name: <span class=\"notok\">" . $_lang['unable_install_module'] . " '$filecontent' " . $_lang['not_found'] . ".</span></p>"; |
|
| 515 | + } else { |
|
| 506 | 516 | |
| 507 | 517 | // Create the category if it does not already exist |
| 508 | 518 | $category = getCreateDbCategory($category, $sqlParser); |
@@ -552,9 +562,9 @@ discard block |
||
| 552 | 562 | // parse comma-separated legacy names and prepare them for sql IN clause |
| 553 | 563 | $leg_names = "'" . implode("','", preg_split('/\s*,\s*/', mysqli_real_escape_string($conn, $modulePlugin[7]))) . "'"; |
| 554 | 564 | } |
| 555 | - if (!file_exists($filecontent)) |
|
| 556 | - echo "<p> $name: <span class=\"notok\">" . $_lang['unable_install_plugin'] . " '$filecontent' " . $_lang['not_found'] . ".</span></p>"; |
|
| 557 | - else { |
|
| 565 | + if (!file_exists($filecontent)) { |
|
| 566 | + echo "<p> $name: <span class=\"notok\">" . $_lang['unable_install_plugin'] . " '$filecontent' " . $_lang['not_found'] . ".</span></p>"; |
|
| 567 | + } else { |
|
| 558 | 568 | |
| 559 | 569 | // disable legacy versions based on legacy_names provided |
| 560 | 570 | if(!empty($leg_names)) { |
@@ -573,7 +583,7 @@ discard block |
||
| 573 | 583 | $insert = true; |
| 574 | 584 | while($row = mysqli_fetch_assoc($rs)) { |
| 575 | 585 | $props = mysqli_real_escape_string($conn, propUpdate($properties,$row['properties'])); |
| 576 | - if($row['description'] == $desc){ |
|
| 586 | + if($row['description'] == $desc) { |
|
| 577 | 587 | if (! mysqli_query($sqlParser->conn, "UPDATE $dbase.`" . $table_prefix . "site_plugins` SET plugincode='$plugin', description='$desc', properties='$props' WHERE id={$row['id']};")) { |
| 578 | 588 | echo "<p>" . mysqli_error($sqlParser->conn) . "</p>"; |
| 579 | 589 | return; |
@@ -631,9 +641,9 @@ discard block |
||
| 631 | 641 | $filecontent = $moduleSnippet[2]; |
| 632 | 642 | $properties = $moduleSnippet[3]; |
| 633 | 643 | $category = mysqli_real_escape_string($conn, $moduleSnippet[4]); |
| 634 | - if (!file_exists($filecontent)) |
|
| 635 | - echo "<p> $name: <span class=\"notok\">" . $_lang['unable_install_snippet'] . " '$filecontent' " . $_lang['not_found'] . ".</span></p>"; |
|
| 636 | - else { |
|
| 644 | + if (!file_exists($filecontent)) { |
|
| 645 | + echo "<p> $name: <span class=\"notok\">" . $_lang['unable_install_snippet'] . " '$filecontent' " . $_lang['not_found'] . ".</span></p>"; |
|
| 646 | + } else { |
|
| 637 | 647 | |
| 638 | 648 | // Create the category if it does not already exist |
| 639 | 649 | $category = getCreateDbCategory($category, $sqlParser); |
@@ -741,13 +751,16 @@ discard block |
||
| 741 | 751 | } |
| 742 | 752 | |
| 743 | 753 | // call back function |
| 744 | -if ($callBackFnc != "") |
|
| 754 | +if ($callBackFnc != "") { |
|
| 745 | 755 | $callBackFnc ($sqlParser); |
| 756 | +} |
|
| 746 | 757 | |
| 747 | 758 | // Setup the MODX API -- needed for the cache processor |
| 748 | 759 | define('MODX_API_MODE', true); |
| 749 | 760 | define('MODX_BASE_PATH', $base_path); |
| 750 | -if (!defined('MODX_MANAGER_PATH')) define('MODX_MANAGER_PATH', $base_path.MGR_DIR.'/'); |
|
| 761 | +if (!defined('MODX_MANAGER_PATH')) { |
|
| 762 | + define('MODX_MANAGER_PATH', $base_path.MGR_DIR.'/'); |
|
| 763 | +} |
|
| 751 | 764 | $database_type = 'mysqli'; |
| 752 | 765 | // initiate a new document parser |
| 753 | 766 | include_once('../'.MGR_DIR.'/includes/document.parser.class.inc.php'); |
@@ -792,11 +805,12 @@ discard block |
||
| 792 | 805 | * @param string $old |
| 793 | 806 | * @return string |
| 794 | 807 | */ |
| 795 | -function propUpdate($new,$old){ |
|
| 808 | +function propUpdate($new,$old) |
|
| 809 | +{ |
|
| 796 | 810 | $newArr = parseProperties($new); |
| 797 | 811 | $oldArr = parseProperties($old); |
| 798 | - foreach ($oldArr as $k => $v){ |
|
| 799 | - if (isset($v['0']['options'])){ |
|
| 812 | + foreach ($oldArr as $k => $v) { |
|
| 813 | + if (isset($v['0']['options'])) { |
|
| 800 | 814 | $oldArr[$k]['0']['options'] = $newArr[$k]['0']['options']; |
| 801 | 815 | } |
| 802 | 816 | } |
@@ -811,12 +825,17 @@ discard block |
||
| 811 | 825 | * @param bool|mixed $json |
| 812 | 826 | * @return string |
| 813 | 827 | */ |
| 814 | -function parseProperties($propertyString, $json=false) { |
|
| 828 | +function parseProperties($propertyString, $json=false) |
|
| 829 | +{ |
|
| 815 | 830 | $propertyString = str_replace('{}', '', $propertyString ); |
| 816 | 831 | $propertyString = str_replace('} {', ',', $propertyString ); |
| 817 | 832 | |
| 818 | - if(empty($propertyString)) return array(); |
|
| 819 | - if($propertyString=='{}' || $propertyString=='[]') return array(); |
|
| 833 | + if(empty($propertyString)) { |
|
| 834 | + return array(); |
|
| 835 | + } |
|
| 836 | + if($propertyString=='{}' || $propertyString=='[]') { |
|
| 837 | + return array(); |
|
| 838 | + } |
|
| 820 | 839 | |
| 821 | 840 | $jsonFormat = isJson($propertyString, true); |
| 822 | 841 | $property = array(); |
@@ -858,7 +877,7 @@ discard block |
||
| 858 | 877 | |
| 859 | 878 | } |
| 860 | 879 | // new json-format |
| 861 | - } else if(!empty($jsonFormat)){ |
|
| 880 | + } else if(!empty($jsonFormat)) { |
|
| 862 | 881 | $property = $jsonFormat; |
| 863 | 882 | } |
| 864 | 883 | if ($json) { |
@@ -873,7 +892,8 @@ discard block |
||
| 873 | 892 | * @param bool $returnData |
| 874 | 893 | * @return bool|mixed |
| 875 | 894 | */ |
| 876 | -function isJson($string, $returnData=false) { |
|
| 895 | +function isJson($string, $returnData=false) |
|
| 896 | +{ |
|
| 877 | 897 | $data = json_decode($string, true); |
| 878 | 898 | return (json_last_error() == JSON_ERROR_NONE) ? ($returnData ? $data : true) : false; |
| 879 | 899 | } |
@@ -883,7 +903,8 @@ discard block |
||
| 883 | 903 | * @param SqlParser $sqlParser |
| 884 | 904 | * @return int |
| 885 | 905 | */ |
| 886 | -function getCreateDbCategory($category, $sqlParser) { |
|
| 906 | +function getCreateDbCategory($category, $sqlParser) |
|
| 907 | +{ |
|
| 887 | 908 | $dbase = $sqlParser->dbname; |
| 888 | 909 | $dbase = '`' . trim($dbase,'`') . '`'; |
| 889 | 910 | $table_prefix = $sqlParser->prefix; |
@@ -911,7 +932,8 @@ discard block |
||
| 911 | 932 | * @param string $type |
| 912 | 933 | * @return string |
| 913 | 934 | */ |
| 914 | -function removeDocblock($code, $type) { |
|
| 935 | +function removeDocblock($code, $type) |
|
| 936 | +{ |
|
| 915 | 937 | |
| 916 | 938 | $cleaned = preg_replace("/^.*?\/\*\*.*?\*\/\s+/s", '', $code, 1); |
| 917 | 939 | |
@@ -932,8 +954,9 @@ discard block |
||
| 932 | 954 | default: |
| 933 | 955 | return $cleaned; |
| 934 | 956 | }; |
| 935 | - if(substr(trim($cleaned),0,$count) == $include.' MODX_BASE_PATH.\'assets/'.$elm_name.'/') |
|
| 936 | - return $cleaned; |
|
| 957 | + if(substr(trim($cleaned),0,$count) == $include.' MODX_BASE_PATH.\'assets/'.$elm_name.'/') { |
|
| 958 | + return $cleaned; |
|
| 959 | + } |
|
| 937 | 960 | |
| 938 | 961 | // fileBinding not found - return code incl docblock |
| 939 | 962 | return $code; |
@@ -719,7 +719,7 @@ discard block |
||
| 719 | 719 | |
| 720 | 720 | /** |
| 721 | 721 | * @param string $string |
| 722 | - * @return bool|string |
|
| 722 | + * @return string|false |
|
| 723 | 723 | */ |
| 724 | 724 | function removeLastPath($string) |
| 725 | 725 | { |
@@ -734,7 +734,7 @@ discard block |
||
| 734 | 734 | |
| 735 | 735 | /** |
| 736 | 736 | * @param string $string |
| 737 | - * @return bool|string |
|
| 737 | + * @return string|false |
|
| 738 | 738 | */ |
| 739 | 739 | function getExtension($string) |
| 740 | 740 | { |
@@ -893,7 +893,9 @@ |
||
| 893 | 893 | global $modx, $_lang, $startpath, $filemanager_path, $uploadablefiles, $new_file_permissions; |
| 894 | 894 | $msg = ''; |
| 895 | 895 | foreach ($_FILES['userfile']['name'] as $i => $name) { |
| 896 | - if (empty($_FILES['userfile']['tmp_name'][$i])) continue; |
|
| 896 | + if (empty($_FILES['userfile']['tmp_name'][$i])) { |
|
| 897 | + continue; |
|
| 898 | + } |
|
| 897 | 899 | $userfile= array(); |
| 898 | 900 | |
| 899 | 901 | $userfile['tmp_name'] = $_FILES['userfile']['tmp_name'][$i]; |
@@ -344,7 +344,7 @@ |
||
| 344 | 344 | |
| 345 | 345 | /** |
| 346 | 346 | * @param string $filepath |
| 347 | - * @return bool|string |
|
| 347 | + * @return null|string |
|
| 348 | 348 | */ |
| 349 | 349 | function getFileContent($filepath) { |
| 350 | 350 | global $_lang; |
@@ -104,7 +104,8 @@ discard block |
||
| 104 | 104 | /** |
| 105 | 105 | * @return string |
| 106 | 106 | */ |
| 107 | -function run() { |
|
| 107 | +function run() |
|
| 108 | +{ |
|
| 108 | 109 | global $modx, $_lang; |
| 109 | 110 | |
| 110 | 111 | $tbl_site_content = $modx->getFullTableName('site_content'); |
@@ -171,7 +172,8 @@ discard block |
||
| 171 | 172 | * @param array $files |
| 172 | 173 | * @param string $mode |
| 173 | 174 | */ |
| 174 | -function importFiles($parent, $filedir, $files, $mode) { |
|
| 175 | +function importFiles($parent, $filedir, $files, $mode) |
|
| 176 | +{ |
|
| 175 | 177 | global $modx; |
| 176 | 178 | global $_lang, $allowedfiles; |
| 177 | 179 | global $search_default, $cache_default, $publish_default; |
@@ -318,7 +320,8 @@ discard block |
||
| 318 | 320 | * @param int $count |
| 319 | 321 | * @return array |
| 320 | 322 | */ |
| 321 | -function getFiles($directory, $listing = array(), $count = 0) { |
|
| 323 | +function getFiles($directory, $listing = array(), $count = 0) |
|
| 324 | +{ |
|
| 322 | 325 | global $_lang; |
| 323 | 326 | global $filesfound; |
| 324 | 327 | $dummy = $count; |
@@ -346,7 +349,8 @@ discard block |
||
| 346 | 349 | * @param string $filepath |
| 347 | 350 | * @return bool|string |
| 348 | 351 | */ |
| 349 | -function getFileContent($filepath) { |
|
| 352 | +function getFileContent($filepath) |
|
| 353 | +{ |
|
| 350 | 354 | global $_lang; |
| 351 | 355 | // get the file |
| 352 | 356 | if(!$buffer = file_get_contents($filepath)) { |
@@ -360,7 +364,8 @@ discard block |
||
| 360 | 364 | * @param array $array |
| 361 | 365 | * @return array |
| 362 | 366 | */ |
| 363 | -function pop_index($array) { |
|
| 367 | +function pop_index($array) |
|
| 368 | +{ |
|
| 364 | 369 | $new_array = array(); |
| 365 | 370 | foreach($array as $k => $v) { |
| 366 | 371 | if($v !== 'index.html' && $v !== 'index.htm') { |
@@ -383,7 +388,8 @@ discard block |
||
| 383 | 388 | * @param string $alias |
| 384 | 389 | * @return array |
| 385 | 390 | */ |
| 386 | -function treatContent($src, $filename, $alias) { |
|
| 391 | +function treatContent($src, $filename, $alias) |
|
| 392 | +{ |
|
| 387 | 393 | global $modx; |
| 388 | 394 | |
| 389 | 395 | $src = mb_convert_encoding($src, $modx->config['modx_charset'], 'UTF-8,SJIS-win,eucJP-win,SJIS,EUC-JP,ASCII'); |
@@ -427,7 +433,8 @@ discard block |
||
| 427 | 433 | /** |
| 428 | 434 | * @return void |
| 429 | 435 | */ |
| 430 | -function convertLink() { |
|
| 436 | +function convertLink() |
|
| 437 | +{ |
|
| 431 | 438 | global $modx; |
| 432 | 439 | $tbl_site_content = $modx->getFullTableName('site_content'); |
| 433 | 440 | |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | * MODX_MANAGER_PATH."includes/extenders/ex_{$extname}.inc.php" |
| 257 | 257 | * $extname - extension name in lowercase |
| 258 | 258 | * |
| 259 | - * @param $extname |
|
| 259 | + * @param string $extname |
|
| 260 | 260 | * @param bool $reload |
| 261 | 261 | * @return bool |
| 262 | 262 | */ |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | * @param int $count_attempts |
| 300 | 300 | * @param string $type $type |
| 301 | 301 | * @param string $responseCode |
| 302 | - * @return bool|null |
|
| 302 | + * @return false|null |
|
| 303 | 303 | * @global string $base_url |
| 304 | 304 | * @global string $site_url |
| 305 | 305 | */ |
@@ -1000,7 +1000,7 @@ discard block |
||
| 1000 | 1000 | } |
| 1001 | 1001 | |
| 1002 | 1002 | /** |
| 1003 | - * @param $contents |
|
| 1003 | + * @param string $contents |
|
| 1004 | 1004 | * @return mixed |
| 1005 | 1005 | */ |
| 1006 | 1006 | public function RecoveryEscapedTags($contents) |
@@ -1024,7 +1024,7 @@ discard block |
||
| 1024 | 1024 | } |
| 1025 | 1025 | |
| 1026 | 1026 | /** |
| 1027 | - * @param $tstart |
|
| 1027 | + * @param double $tstart |
|
| 1028 | 1028 | * @return array |
| 1029 | 1029 | */ |
| 1030 | 1030 | public function getTimerStats($tstart) |
@@ -1776,7 +1776,7 @@ discard block |
||
| 1776 | 1776 | |
| 1777 | 1777 | /** |
| 1778 | 1778 | * Remove Comment-Tags from output like <!--@- Comment -@--> |
| 1779 | - * @param $content |
|
| 1779 | + * @param string $content |
|
| 1780 | 1780 | * @param string $left |
| 1781 | 1781 | * @param string $right |
| 1782 | 1782 | * @return mixed |
@@ -1949,7 +1949,7 @@ discard block |
||
| 1949 | 1949 | /** |
| 1950 | 1950 | * Run snippets as per the tags in $documentSource and replace the tags with the returned values. |
| 1951 | 1951 | * |
| 1952 | - * @param $content |
|
| 1952 | + * @param string $content |
|
| 1953 | 1953 | * @return string |
| 1954 | 1954 | * @internal param string $documentSource |
| 1955 | 1955 | */ |
@@ -2981,7 +2981,7 @@ discard block |
||
| 2981 | 2981 | |
| 2982 | 2982 | /** |
| 2983 | 2983 | * @param $templateID |
| 2984 | - * @return mixed |
|
| 2984 | + * @return string |
|
| 2985 | 2985 | */ |
| 2986 | 2986 | public function _getTemplateCodeFromDB($templateID) |
| 2987 | 2987 | { |
@@ -3022,9 +3022,9 @@ discard block |
||
| 3022 | 3022 | } |
| 3023 | 3023 | |
| 3024 | 3024 | /** |
| 3025 | - * @param $id |
|
| 3025 | + * @param integer $id |
|
| 3026 | 3026 | * @param int $top |
| 3027 | - * @return mixed |
|
| 3027 | + * @return string |
|
| 3028 | 3028 | */ |
| 3029 | 3029 | public function getUltimateParentId($id, $top = 0) |
| 3030 | 3030 | { |
@@ -3355,7 +3355,7 @@ discard block |
||
| 3355 | 3355 | * |
| 3356 | 3356 | * @param int $type Types: 1=template, 2=tv, 3=chunk, 4=snippet, 5=plugin, 6=module, 7=resource, 8=role |
| 3357 | 3357 | * @param int $id Element- / Resource-id |
| 3358 | - * @return bool |
|
| 3358 | + * @return false|null |
|
| 3359 | 3359 | */ |
| 3360 | 3360 | public function lockElement($type, $id) |
| 3361 | 3361 | { |
@@ -3377,7 +3377,7 @@ discard block |
||
| 3377 | 3377 | * @param int $type Types: 1=template, 2=tv, 3=chunk, 4=snippet, 5=plugin, 6=module, 7=resource, 8=role |
| 3378 | 3378 | * @param int $id Element- / Resource-id |
| 3379 | 3379 | * @param bool $includeAllUsers true = Deletes not only own user-locks |
| 3380 | - * @return bool |
|
| 3380 | + * @return false|null |
|
| 3381 | 3381 | */ |
| 3382 | 3382 | public function unlockElement($type, $id, $includeAllUsers = false) |
| 3383 | 3383 | { |
@@ -3485,7 +3485,7 @@ discard block |
||
| 3485 | 3485 | * @param array $params |
| 3486 | 3486 | * @param string $msg |
| 3487 | 3487 | * @param array $files |
| 3488 | - * @return mixed |
|
| 3488 | + * @return boolean |
|
| 3489 | 3489 | */ |
| 3490 | 3490 | public function sendmail($params = array(), $msg = '', $files = array()) |
| 3491 | 3491 | { |
@@ -3981,7 +3981,7 @@ discard block |
||
| 3981 | 3981 | * |
| 3982 | 3982 | * @param string $type |
| 3983 | 3983 | * @param bool $report |
| 3984 | - * @return bool |
|
| 3984 | + * @return boolean|null |
|
| 3985 | 3985 | */ |
| 3986 | 3986 | public function clearCache($type = '', $report = false) |
| 3987 | 3987 | { |
@@ -4348,7 +4348,7 @@ discard block |
||
| 4348 | 4348 | * - Placeholders prefix. Default: '{'. |
| 4349 | 4349 | * @param string $suffix {string} |
| 4350 | 4350 | * - Placeholders suffix. Default: '}'. |
| 4351 | - * @return bool|mixed|string {string; false} - Parsed chunk or false if $chunkArr is not array. |
|
| 4351 | + * @return false|string {string; false} - Parsed chunk or false if $chunkArr is not array. |
|
| 4352 | 4352 | * - Parsed chunk or false if $chunkArr is not array. |
| 4353 | 4353 | */ |
| 4354 | 4354 | public function parseChunk($chunkName, $chunkArr, $prefix = '{', $suffix = '}') |
@@ -5324,7 +5324,7 @@ discard block |
||
| 5324 | 5324 | * Remove event listener - only for use within the current execution cycle |
| 5325 | 5325 | * |
| 5326 | 5326 | * @param string $evtName |
| 5327 | - * @return boolean |
|
| 5327 | + * @return false|null |
|
| 5328 | 5328 | */ |
| 5329 | 5329 | public function removeEventListener($evtName) |
| 5330 | 5330 | { |
@@ -5348,7 +5348,7 @@ discard block |
||
| 5348 | 5348 | * |
| 5349 | 5349 | * @param string $evtName |
| 5350 | 5350 | * @param array $extParams Parameters available to plugins. Each array key will be the PHP variable name, and the array value will be the variable value. |
| 5351 | - * @return boolean|array |
|
| 5351 | + * @return false|null |
|
| 5352 | 5352 | */ |
| 5353 | 5353 | public function invokeEvent($evtName, $extParams = array()) |
| 5354 | 5354 | { |
@@ -5947,7 +5947,7 @@ discard block |
||
| 5947 | 5947 | |
| 5948 | 5948 | /** |
| 5949 | 5949 | * @param string $str |
| 5950 | - * @return bool|mixed|string |
|
| 5950 | + * @return string |
|
| 5951 | 5951 | */ |
| 5952 | 5952 | public function atBindFileContent($str = '') |
| 5953 | 5953 | { |
@@ -5998,8 +5998,8 @@ discard block |
||
| 5998 | 5998 | } |
| 5999 | 5999 | |
| 6000 | 6000 | /** |
| 6001 | - * @param $str |
|
| 6002 | - * @return bool|string |
|
| 6001 | + * @param string $str |
|
| 6002 | + * @return false|string |
|
| 6003 | 6003 | */ |
| 6004 | 6004 | public function getExtFromFilename($str) |
| 6005 | 6005 | { |
@@ -6027,7 +6027,7 @@ discard block |
||
| 6027 | 6027 | * @param string $text Error message |
| 6028 | 6028 | * @param string $file File where the error was detected |
| 6029 | 6029 | * @param string $line Line number within $file |
| 6030 | - * @return boolean |
|
| 6030 | + * @return boolean|null |
|
| 6031 | 6031 | */ |
| 6032 | 6032 | public function phpError($nr, $text, $file, $line) |
| 6033 | 6033 | { |
@@ -6079,7 +6079,7 @@ discard block |
||
| 6079 | 6079 | * @param string $text |
| 6080 | 6080 | * @param string $line |
| 6081 | 6081 | * @param string $output |
| 6082 | - * @return bool |
|
| 6082 | + * @return null|boolean |
|
| 6083 | 6083 | */ |
| 6084 | 6084 | public function messageQuit($msg = 'unspecified error', $query = '', $is_error = true, $nr = '', $file = '', $source = '', $text = '', $line = '', $output = '') |
| 6085 | 6085 | { |
@@ -6501,7 +6501,7 @@ discard block |
||
| 6501 | 6501 | |
| 6502 | 6502 | /** |
| 6503 | 6503 | * @param string $str |
| 6504 | - * @return bool|mixed|string |
|
| 6504 | + * @return string |
|
| 6505 | 6505 | */ |
| 6506 | 6506 | public function atBindInclude($str = '') |
| 6507 | 6507 | { |
@@ -6552,7 +6552,7 @@ discard block |
||
| 6552 | 6552 | * @param $str |
| 6553 | 6553 | * @param int $flags |
| 6554 | 6554 | * @param string $encode |
| 6555 | - * @return mixed |
|
| 6555 | + * @return string |
|
| 6556 | 6556 | */ |
| 6557 | 6557 | public function htmlspecialchars($str, $flags = ENT_COMPAT, $encode = '') |
| 6558 | 6558 | { |
@@ -6561,7 +6561,7 @@ discard block |
||
| 6561 | 6561 | } |
| 6562 | 6562 | |
| 6563 | 6563 | /** |
| 6564 | - * @param $string |
|
| 6564 | + * @param string $string |
|
| 6565 | 6565 | * @param bool $returnData |
| 6566 | 6566 | * @return bool|mixed |
| 6567 | 6567 | */ |
@@ -240,9 +240,9 @@ discard block |
||
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
| 243 | - * @param string|array $fields |
|
| 244 | - * @param string|array $from |
|
| 245 | - * @param string|array $where |
|
| 243 | + * @param string $fields |
|
| 244 | + * @param string $from |
|
| 245 | + * @param string $where |
|
| 246 | 246 | * @param string $orderBy |
| 247 | 247 | * @param string $limit |
| 248 | 248 | * @return bool|mysqli_result |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | * @param string $fromtable |
| 327 | 327 | * @param string $where |
| 328 | 328 | * @param string $limit |
| 329 | - * @return mixed |
|
| 329 | + * @return null|integer |
|
| 330 | 330 | */ |
| 331 | 331 | public function insert($fields, $intotable, $fromfields = "*", $fromtable = "", $where = "", $limit = "") |
| 332 | 332 | { |
@@ -435,7 +435,7 @@ discard block |
||
| 435 | 435 | |
| 436 | 436 | /** |
| 437 | 437 | * @param null|mysqli $conn |
| 438 | - * @return mixed |
|
| 438 | + * @return integer |
|
| 439 | 439 | */ |
| 440 | 440 | public function getInsertId($conn = null) |
| 441 | 441 | { |
@@ -513,7 +513,7 @@ discard block |
||
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | /** |
| 516 | - * @param $name |
|
| 516 | + * @param string $name |
|
| 517 | 517 | * @param mysqli_result|string $dsq |
| 518 | 518 | * @return array |
| 519 | 519 | */ |
@@ -572,7 +572,7 @@ discard block |
||
| 572 | 572 | |
| 573 | 573 | /** |
| 574 | 574 | * @param string $table |
| 575 | - * @return array |
|
| 575 | + * @return boolean |
|
| 576 | 576 | */ |
| 577 | 577 | public function getTableMetaData($table) |
| 578 | 578 | { |
@@ -619,7 +619,7 @@ discard block |
||
| 619 | 619 | } |
| 620 | 620 | |
| 621 | 621 | /** |
| 622 | - * @param string|mysqli_result $rs |
|
| 622 | + * @param string $rs |
|
| 623 | 623 | * @param bool $index |
| 624 | 624 | * @return array |
| 625 | 625 | */ |
@@ -373,7 +373,8 @@ discard block |
||
| 373 | 373 | * @return bool|mixed|mysqli_result |
| 374 | 374 | */ |
| 375 | 375 | public function save($fields, $table, $where = '') |
| 376 | - { // This is similar to "replace into table". |
|
| 376 | + { |
|
| 377 | +// This is similar to "replace into table". |
|
| 377 | 378 | |
| 378 | 379 | if ($where === '') { |
| 379 | 380 | $mode = 'insert'; |
@@ -490,7 +491,7 @@ discard block |
||
| 490 | 491 | { |
| 491 | 492 | $out = false; |
| 492 | 493 | if ($ds instanceof mysqli_result) { |
| 493 | - switch($mode){ |
|
| 494 | + switch($mode) { |
|
| 494 | 495 | case 'assoc': |
| 495 | 496 | $out = $ds->fetch_assoc(); |
| 496 | 497 | break; |
@@ -278,8 +278,7 @@ discard block |
||
| 278 | 278 | /** |
| 279 | 279 | * Sets the width attribute of each column in the array. |
| 280 | 280 | * |
| 281 | - * @param array $value An Array of column widths in the order of the keys in the |
|
| 282 | - * source table array. |
|
| 281 | + * @param string[] $widthArray |
|
| 283 | 282 | */ |
| 284 | 283 | public function setColumnWidths($widthArray) |
| 285 | 284 | { |
@@ -289,7 +288,6 @@ discard block |
||
| 289 | 288 | /** |
| 290 | 289 | * An optional array of values that can be preselected when using |
| 291 | 290 | * |
| 292 | - * @param array $value Indicates the INPUT form element type attribute. |
|
| 293 | 291 | */ |
| 294 | 292 | public function setSelectedValues($valueArray) |
| 295 | 293 | { |
@@ -326,7 +324,7 @@ discard block |
||
| 326 | 324 | /** |
| 327 | 325 | * Determines what class the current row should have applied. |
| 328 | 326 | * |
| 329 | - * @param int $value The position of the current row being rendered. |
|
| 327 | + * @param integer $position |
|
| 330 | 328 | * @return string |
| 331 | 329 | */ |
| 332 | 330 | public function determineRowClass($position) |
@@ -353,7 +351,6 @@ discard block |
||
| 353 | 351 | * Generates an onclick action applied to the current cell, to execute |
| 354 | 352 | * any specified cell actions. |
| 355 | 353 | * |
| 356 | - * @param string $value Indicates the INPUT form element type attribute. |
|
| 357 | 354 | * @return string |
| 358 | 355 | */ |
| 359 | 356 | public function getCellAction($currentActionFieldValue) |
@@ -395,7 +392,7 @@ discard block |
||
| 395 | 392 | /** |
| 396 | 393 | * Function to prepare a link generated in the table cell/link actions. |
| 397 | 394 | * |
| 398 | - * @param string $value Indicates the INPUT form element type attribute. |
|
| 395 | + * @param string $link |
|
| 399 | 396 | * @return string |
| 400 | 397 | */ |
| 401 | 398 | public function prepareLink($link) |
@@ -414,7 +411,7 @@ discard block |
||
| 414 | 411 | * |
| 415 | 412 | * @param array $fieldsArray The associative array representing the table rows |
| 416 | 413 | * and columns. |
| 417 | - * @param array $fieldHeadersArray An optional array of values for providing |
|
| 414 | + * @param string[] $fieldHeadersArray An optional array of values for providing |
|
| 418 | 415 | * alternative field headers; this is an associative arrays of keys from |
| 419 | 416 | * the $fieldsArray where the values represent the alt heading content |
| 420 | 417 | * for each column. |
@@ -457,7 +457,8 @@ |
||
| 457 | 457 | if ($this->formElementType) { |
| 458 | 458 | $table = "\n" . '<form id="' . $this->formName . '" name="' . $this->formName . '" action="' . $this->formAction . '" method="POST">' . $table; |
| 459 | 459 | } |
| 460 | - if (strlen($this->pageNav) > 1) {//changed to display the pagination if exists. |
|
| 460 | + if (strlen($this->pageNav) > 1) { |
|
| 461 | +//changed to display the pagination if exists. |
|
| 461 | 462 | /* commented this part because of cookie |
| 462 | 463 | $table .= '<div id="max-display-records" ><select style="display:inline" onchange="javascript:updatePageSize(this[this.selectedIndex].value);">'; |
| 463 | 464 | $pageSizes= array (10, 25, 50, 100, 250); |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | /** |
| 96 | 96 | * @param string $mode |
| 97 | 97 | * @param string $modifiers |
| 98 | - * @return bool|string |
|
| 98 | + * @return false|string |
|
| 99 | 99 | */ |
| 100 | 100 | public function _getDelim($mode,$modifiers) { |
| 101 | 101 | $c = substr($modifiers,0,1); |
@@ -132,6 +132,14 @@ discard block |
||
| 132 | 132 | return $opt; |
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * @param string $mode |
|
| 138 | + * @param false|string $delim |
|
| 139 | + * @param string $modifiers |
|
| 140 | + * |
|
| 141 | + * @return string |
|
| 142 | + */ |
|
| 135 | 143 | public function _getRemainModifiers($mode,$delim,$modifiers) { |
| 136 | 144 | if($delim) { |
| 137 | 145 | if($mode=='(') |
@@ -159,6 +167,9 @@ discard block |
||
| 159 | 167 | return substr($string,strpos($string, $delim)+$len); |
| 160 | 168 | } |
| 161 | 169 | |
| 170 | + /** |
|
| 171 | + * @param string $modifiers |
|
| 172 | + */ |
|
| 162 | 173 | public function splitEachModifiers($modifiers) { |
| 163 | 174 | global $modx; |
| 164 | 175 | |
@@ -228,6 +239,9 @@ discard block |
||
| 228 | 239 | return $result; |
| 229 | 240 | } |
| 230 | 241 | |
| 242 | + /** |
|
| 243 | + * @param string $key |
|
| 244 | + */ |
|
| 231 | 245 | public function parsePhx($key,$value,$modifiers) |
| 232 | 246 | { |
| 233 | 247 | global $modx; |
@@ -294,6 +308,9 @@ discard block |
||
| 294 | 308 | else return true; |
| 295 | 309 | } |
| 296 | 310 | |
| 311 | + /** |
|
| 312 | + * @param string $cmd |
|
| 313 | + */ |
|
| 297 | 314 | public function getValueFromPreset($key, $value, $cmd, $opt) |
| 298 | 315 | { |
| 299 | 316 | global $modx; |
@@ -979,6 +996,9 @@ discard block |
||
| 979 | 996 | return $value; |
| 980 | 997 | } |
| 981 | 998 | |
| 999 | + /** |
|
| 1000 | + * @param string $cmd |
|
| 1001 | + */ |
|
| 982 | 1002 | public function includeMdfFile($cmd) { |
| 983 | 1003 | global $modx; |
| 984 | 1004 | $key = $this->key; |
@@ -1134,6 +1154,10 @@ discard block |
||
| 1134 | 1154 | } |
| 1135 | 1155 | |
| 1136 | 1156 | // Sets a placeholder variable which can only be access by Modifiers |
| 1157 | + |
|
| 1158 | + /** |
|
| 1159 | + * @param string $value |
|
| 1160 | + */ |
|
| 1137 | 1161 | public function setModifiersVariable($key, $value) { |
| 1138 | 1162 | if ($key != 'phx' && $key != 'dummy') $this->placeholders[$key] = $value; |
| 1139 | 1163 | } |
@@ -1,8 +1,11 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if(!defined('MODX_CORE_PATH')) define('MODX_CORE_PATH', MODX_MANAGER_PATH.'includes/'); |
|
| 3 | +if(!defined('MODX_CORE_PATH')) { |
|
| 4 | + define('MODX_CORE_PATH', MODX_MANAGER_PATH.'includes/'); |
|
| 5 | +} |
|
| 4 | 6 | |
| 5 | -class MODIFIERS { |
|
| 7 | +class MODIFIERS |
|
| 8 | +{ |
|
| 6 | 9 | /** |
| 7 | 10 | * @var array |
| 8 | 11 | */ |
@@ -61,7 +64,9 @@ discard block |
||
| 61 | 64 | { |
| 62 | 65 | global $modx; |
| 63 | 66 | |
| 64 | - if (function_exists('mb_internal_encoding')) mb_internal_encoding($modx->config['modx_charset']); |
|
| 67 | + if (function_exists('mb_internal_encoding')) { |
|
| 68 | + mb_internal_encoding($modx->config['modx_charset']); |
|
| 69 | + } |
|
| 65 | 70 | $this->condModifiers = '=,is,eq,equals,ne,neq,notequals,isnot,isnt,not,%,isempty,isnotempty,isntempty,>=,gte,eg,gte,greaterthan,>,gt,isgreaterthan,isgt,lowerthan,<,lt,<=,lte,islte,islowerthan,islt,el,find,in,inarray,in_array,fnmatch,wcard,wcard_match,wildcard,wildcard_match,is_file,is_dir,file_exists,is_readable,is_writable,is_image,regex,preg,preg_match,memberof,mo,isinrole,ir'; |
| 66 | 71 | } |
| 67 | 72 | |
@@ -74,7 +79,9 @@ discard block |
||
| 74 | 79 | public function phxFilter($key,$value,$modifiers) |
| 75 | 80 | { |
| 76 | 81 | global $modx; |
| 77 | - if(substr($modifiers,0,3)!=='id(') $value = $this->parseDocumentSource($value); |
|
| 82 | + if(substr($modifiers,0,3)!=='id(') { |
|
| 83 | + $value = $this->parseDocumentSource($value); |
|
| 84 | + } |
|
| 78 | 85 | $this->srcValue = $value; |
| 79 | 86 | $modifiers = trim($modifiers); |
| 80 | 87 | $modifiers = ':'.trim($modifiers,':'); |
@@ -97,13 +104,18 @@ discard block |
||
| 97 | 104 | * @param string $modifiers |
| 98 | 105 | * @return bool|string |
| 99 | 106 | */ |
| 100 | - public function _getDelim($mode,$modifiers) { |
|
| 107 | + public function _getDelim($mode,$modifiers) |
|
| 108 | + { |
|
| 101 | 109 | $c = substr($modifiers,0,1); |
| 102 | - if(!in_array($c, array('"', "'", '`')) ) return false; |
|
| 110 | + if(!in_array($c, array('"', "'", '`')) ) { |
|
| 111 | + return false; |
|
| 112 | + } |
|
| 103 | 113 | |
| 104 | 114 | $modifiers = substr($modifiers,1); |
| 105 | 115 | $closure = $mode=='(' ? "{$c})" : $c; |
| 106 | - if(strpos($modifiers, $closure)===false) return false; |
|
| 116 | + if(strpos($modifiers, $closure)===false) { |
|
| 117 | + return false; |
|
| 118 | + } |
|
| 107 | 119 | |
| 108 | 120 | return $c; |
| 109 | 121 | } |
@@ -114,52 +126,65 @@ discard block |
||
| 114 | 126 | * @param string $modifiers |
| 115 | 127 | * @return bool|string |
| 116 | 128 | */ |
| 117 | - public function _getOpt($mode,$delim,$modifiers) { |
|
| 129 | + public function _getOpt($mode,$delim,$modifiers) |
|
| 130 | + { |
|
| 118 | 131 | if($delim) { |
| 119 | - if($mode=='(') return substr($modifiers,1,strpos($modifiers, $delim . ')' )-1); |
|
| 132 | + if($mode=='(') { |
|
| 133 | + return substr($modifiers,1,strpos($modifiers, $delim . ')' )-1); |
|
| 134 | + } |
|
| 120 | 135 | |
| 121 | 136 | return substr($modifiers,1,strpos($modifiers,$delim,1)-1); |
| 122 | - } |
|
| 123 | - else { |
|
| 124 | - if($mode=='(') return substr($modifiers,0,strpos($modifiers, ')') ); |
|
| 137 | + } else { |
|
| 138 | + if($mode=='(') { |
|
| 139 | + return substr($modifiers,0,strpos($modifiers, ')') ); |
|
| 140 | + } |
|
| 125 | 141 | |
| 126 | 142 | $chars = str_split($modifiers); |
| 127 | 143 | $opt=''; |
| 128 | 144 | foreach($chars as $c) { |
| 129 | - if($c==':' || $c==')') break; |
|
| 145 | + if($c==':' || $c==')') { |
|
| 146 | + break; |
|
| 147 | + } |
|
| 130 | 148 | $opt .=$c; |
| 131 | 149 | } |
| 132 | 150 | return $opt; |
| 133 | 151 | } |
| 134 | 152 | } |
| 135 | - public function _getRemainModifiers($mode,$delim,$modifiers) { |
|
| 153 | + public function _getRemainModifiers($mode,$delim,$modifiers) |
|
| 154 | + { |
|
| 136 | 155 | if($delim) { |
| 137 | - if($mode=='(') |
|
| 138 | - return $this->_fetchContent($modifiers, $delim . ')'); |
|
| 139 | - else { |
|
| 156 | + if($mode=='(') { |
|
| 157 | + return $this->_fetchContent($modifiers, $delim . ')'); |
|
| 158 | + } else { |
|
| 140 | 159 | $modifiers = trim($modifiers); |
| 141 | 160 | $modifiers = substr($modifiers,1); |
| 142 | 161 | return $this->_fetchContent($modifiers, $delim); |
| 143 | 162 | } |
| 144 | - } |
|
| 145 | - else { |
|
| 146 | - if($mode=='(') return $this->_fetchContent($modifiers, ')'); |
|
| 163 | + } else { |
|
| 164 | + if($mode=='(') { |
|
| 165 | + return $this->_fetchContent($modifiers, ')'); |
|
| 166 | + } |
|
| 147 | 167 | $chars = str_split($modifiers); |
| 148 | 168 | foreach($chars as $c) { |
| 149 | - if($c==':') return $modifiers; |
|
| 150 | - else $modifiers = substr($modifiers,1); |
|
| 169 | + if($c==':') { |
|
| 170 | + return $modifiers; |
|
| 171 | + } else { |
|
| 172 | + $modifiers = substr($modifiers,1); |
|
| 173 | + } |
|
| 151 | 174 | } |
| 152 | 175 | return $modifiers; |
| 153 | 176 | } |
| 154 | 177 | } |
| 155 | 178 | |
| 156 | - public function _fetchContent($string,$delim) { |
|
| 179 | + public function _fetchContent($string,$delim) |
|
| 180 | + { |
|
| 157 | 181 | $len = strlen($delim); |
| 158 | 182 | $string = $this->parseDocumentSource($string); |
| 159 | 183 | return substr($string,strpos($string, $delim)+$len); |
| 160 | 184 | } |
| 161 | 185 | |
| 162 | - public function splitEachModifiers($modifiers) { |
|
| 186 | + public function splitEachModifiers($modifiers) |
|
| 187 | + { |
|
| 163 | 188 | global $modx; |
| 164 | 189 | |
| 165 | 190 | $cmd = ''; |
@@ -170,11 +195,15 @@ discard block |
||
| 170 | 195 | $c = substr($modifiers,0,1); |
| 171 | 196 | $modifiers = substr($modifiers,1); |
| 172 | 197 | |
| 173 | - if($c===':' && preg_match('@^(!?[<>=]{1,2})@', $modifiers, $match)) { // :=, :!=, :<=, :>=, :!<=, :!>= |
|
| 198 | + if($c===':' && preg_match('@^(!?[<>=]{1,2})@', $modifiers, $match)) { |
|
| 199 | +// :=, :!=, :<=, :>=, :!<=, :!>= |
|
| 174 | 200 | $c = substr($modifiers,strlen($match[1]),1); |
| 175 | 201 | $debuginfo = "#i=0 #c=[{$c}] #m=[{$modifiers}]"; |
| 176 | - if($c==='(') $modifiers = substr($modifiers,strlen($match[1])+1); |
|
| 177 | - else $modifiers = substr($modifiers,strlen($match[1])); |
|
| 202 | + if($c==='(') { |
|
| 203 | + $modifiers = substr($modifiers,strlen($match[1])+1); |
|
| 204 | + } else { |
|
| 205 | + $modifiers = substr($modifiers,strlen($match[1])); |
|
| 206 | + } |
|
| 178 | 207 | |
| 179 | 208 | $delim = $this->_getDelim($c,$modifiers); |
| 180 | 209 | $opt = $this->_getOpt($c,$delim,$modifiers); |
@@ -182,13 +211,12 @@ discard block |
||
| 182 | 211 | |
| 183 | 212 | $result[]=array('cmd'=>trim($match[1]),'opt'=>$opt,'debuginfo'=>$debuginfo); |
| 184 | 213 | $cmd = ''; |
| 185 | - } |
|
| 186 | - elseif(in_array($c,array('+','-','*','/')) && preg_match('@^[0-9]+@', $modifiers, $match)) { // :+3, :-3, :*3 ... |
|
| 214 | + } elseif(in_array($c,array('+','-','*','/')) && preg_match('@^[0-9]+@', $modifiers, $match)) { |
|
| 215 | +// :+3, :-3, :*3 ... |
|
| 187 | 216 | $modifiers = substr($modifiers,strlen($match[0])); |
| 188 | 217 | $result[]=array('cmd'=>'math','opt'=>'%s'.$c.$match[0]); |
| 189 | 218 | $cmd = ''; |
| 190 | - } |
|
| 191 | - elseif($c==='(' || $c==='=') { |
|
| 219 | + } elseif($c==='(' || $c==='=') { |
|
| 192 | 220 | $modifiers = $m1 = trim($modifiers); |
| 193 | 221 | $delim = $this->_getDelim($c,$modifiers); |
| 194 | 222 | $opt = $this->_getOpt($c,$delim,$modifiers); |
@@ -198,29 +226,29 @@ discard block |
||
| 198 | 226 | $result[]=array('cmd'=>trim($cmd),'opt'=>$opt,'debuginfo'=>$debuginfo); |
| 199 | 227 | |
| 200 | 228 | $cmd = ''; |
| 201 | - } |
|
| 202 | - elseif($c==':') { |
|
| 229 | + } elseif($c==':') { |
|
| 203 | 230 | $debuginfo = "#i=2 #c=[{$c}] #m=[{$modifiers}]"; |
| 204 | - if($cmd!=='') $result[]=array('cmd'=>trim($cmd),'opt'=>'','debuginfo'=>$debuginfo); |
|
| 231 | + if($cmd!=='') { |
|
| 232 | + $result[]=array('cmd'=>trim($cmd),'opt'=>'','debuginfo'=>$debuginfo); |
|
| 233 | + } |
|
| 205 | 234 | |
| 206 | 235 | $cmd = ''; |
| 207 | - } |
|
| 208 | - elseif(trim($modifiers)=='' && trim($cmd)!=='') { |
|
| 236 | + } elseif(trim($modifiers)=='' && trim($cmd)!=='') { |
|
| 209 | 237 | $debuginfo = "#i=3 #c=[{$c}] #m=[{$modifiers}]"; |
| 210 | 238 | $cmd .= $c; |
| 211 | 239 | $result[]=array('cmd'=>trim($cmd),'opt'=>'','debuginfo'=>$debuginfo); |
| 212 | 240 | |
| 213 | 241 | break; |
| 214 | - } |
|
| 215 | - else { |
|
| 242 | + } else { |
|
| 216 | 243 | $cmd .= $c; |
| 217 | 244 | } |
| 218 | 245 | } |
| 219 | 246 | |
| 220 | - if(empty($result)) return array(); |
|
| 247 | + if(empty($result)) { |
|
| 248 | + return array(); |
|
| 249 | + } |
|
| 221 | 250 | |
| 222 | - foreach($result as $i=>$a) |
|
| 223 | - { |
|
| 251 | + foreach($result as $i=>$a) { |
|
| 224 | 252 | $a['opt'] = $this->parseDocumentSource($a['opt']); |
| 225 | 253 | $result[$i]['opt'] = $modx->mergePlaceholderContent($a['opt'],$this->placeholders); |
| 226 | 254 | } |
@@ -233,22 +261,23 @@ discard block |
||
| 233 | 261 | global $modx; |
| 234 | 262 | $lastKey = ''; |
| 235 | 263 | $cacheKey = md5(sprintf('parsePhx#%s#%s#%s',$key,$value,print_r($modifiers,true))); |
| 236 | - if(isset($this->tmpCache[$cacheKey])) return $this->tmpCache[$cacheKey]; |
|
| 237 | - if(empty($modifiers)) return ''; |
|
| 264 | + if(isset($this->tmpCache[$cacheKey])) { |
|
| 265 | + return $this->tmpCache[$cacheKey]; |
|
| 266 | + } |
|
| 267 | + if(empty($modifiers)) { |
|
| 268 | + return ''; |
|
| 269 | + } |
|
| 238 | 270 | |
| 239 | - foreach($modifiers as $m) |
|
| 240 | - { |
|
| 271 | + foreach($modifiers as $m) { |
|
| 241 | 272 | $lastKey = strtolower($m['cmd']); |
| 242 | 273 | } |
| 243 | 274 | $_ = explode(',',$this->condModifiers); |
| 244 | - if(in_array($lastKey,$_)) |
|
| 245 | - { |
|
| 275 | + if(in_array($lastKey,$_)) { |
|
| 246 | 276 | $modifiers[] = array('cmd'=>'then','opt'=>'1'); |
| 247 | 277 | $modifiers[] = array('cmd'=>'else','opt'=>'0'); |
| 248 | 278 | } |
| 249 | 279 | |
| 250 | - foreach($modifiers as $i=>$a) |
|
| 251 | - { |
|
| 280 | + foreach($modifiers as $i=>$a) { |
|
| 252 | 281 | $value = $this->Filter($key,$value, $a['cmd'], $a['opt']); |
| 253 | 282 | } |
| 254 | 283 | $this->tmpCache[$cacheKey] = $value; |
@@ -260,25 +289,32 @@ discard block |
||
| 260 | 289 | { |
| 261 | 290 | global $modx; |
| 262 | 291 | |
| 263 | - if($key==='documentObject') $value = $modx->documentIdentifier; |
|
| 292 | + if($key==='documentObject') { |
|
| 293 | + $value = $modx->documentIdentifier; |
|
| 294 | + } |
|
| 264 | 295 | $cmd = $this->parseDocumentSource($cmd); |
| 265 | - if(preg_match('@^[1-9][/0-9]*$@',$cmd)) |
|
| 266 | - { |
|
| 267 | - if(strpos($cmd,'/')!==false) |
|
| 268 | - $cmd = $this->substr($cmd,strrpos($cmd,'/')+1); |
|
| 296 | + if(preg_match('@^[1-9][/0-9]*$@',$cmd)) { |
|
| 297 | + if(strpos($cmd,'/')!==false) { |
|
| 298 | + $cmd = $this->substr($cmd,strrpos($cmd,'/')+1); |
|
| 299 | + } |
|
| 269 | 300 | $opt = $cmd; |
| 270 | 301 | $cmd = 'id'; |
| 271 | 302 | } |
| 272 | 303 | |
| 273 | - if(isset($modx->snippetCache["phx:{$cmd}"])) $this->elmName = "phx:{$cmd}"; |
|
| 274 | - elseif(isset($modx->chunkCache["phx:{$cmd}"])) $this->elmName = "phx:{$cmd}"; |
|
| 275 | - else $this->elmName = ''; |
|
| 304 | + if(isset($modx->snippetCache["phx:{$cmd}"])) { |
|
| 305 | + $this->elmName = "phx:{$cmd}"; |
|
| 306 | + } elseif(isset($modx->chunkCache["phx:{$cmd}"])) { |
|
| 307 | + $this->elmName = "phx:{$cmd}"; |
|
| 308 | + } else { |
|
| 309 | + $this->elmName = ''; |
|
| 310 | + } |
|
| 276 | 311 | |
| 277 | 312 | $cmd = strtolower($cmd); |
| 278 | - if($this->elmName!=='') |
|
| 279 | - $value = $this->getValueFromElement($key, $value, $cmd, $opt); |
|
| 280 | - else |
|
| 281 | - $value = $this->getValueFromPreset($key, $value, $cmd, $opt); |
|
| 313 | + if($this->elmName!=='') { |
|
| 314 | + $value = $this->getValueFromElement($key, $value, $cmd, $opt); |
|
| 315 | + } else { |
|
| 316 | + $value = $this->getValueFromPreset($key, $value, $cmd, $opt); |
|
| 317 | + } |
|
| 282 | 318 | |
| 283 | 319 | $value = str_replace('[+key+]', $key, $value); |
| 284 | 320 | |
@@ -287,29 +323,37 @@ discard block |
||
| 287 | 323 | |
| 288 | 324 | public function isEmpty($cmd,$value) |
| 289 | 325 | { |
| 290 | - if($value!=='') return false; |
|
| 326 | + if($value!=='') { |
|
| 327 | + return false; |
|
| 328 | + } |
|
| 291 | 329 | |
| 292 | 330 | $_ = explode(',', $this->condModifiers . ',_default,default,if,input,or,and,show,this,select,switch,then,else,id,ifempty,smart_desc,smart_description,summary'); |
| 293 | - if(in_array($cmd,$_)) return false; |
|
| 294 | - else return true; |
|
| 331 | + if(in_array($cmd,$_)) { |
|
| 332 | + return false; |
|
| 333 | + } else { |
|
| 334 | + return true; |
|
| 335 | + } |
|
| 295 | 336 | } |
| 296 | 337 | |
| 297 | 338 | public function getValueFromPreset($key, $value, $cmd, $opt) |
| 298 | 339 | { |
| 299 | 340 | global $modx; |
| 300 | 341 | |
| 301 | - if($this->isEmpty($cmd,$value)) return ''; |
|
| 342 | + if($this->isEmpty($cmd,$value)) { |
|
| 343 | + return ''; |
|
| 344 | + } |
|
| 302 | 345 | |
| 303 | 346 | $this->key = $key; |
| 304 | 347 | $this->value = $value; |
| 305 | 348 | $this->opt = $opt; |
| 306 | 349 | |
| 307 | - switch ($cmd) |
|
| 308 | - { |
|
| 350 | + switch ($cmd) { |
|
| 309 | 351 | ##### Conditional Modifiers |
| 310 | 352 | case 'input': |
| 311 | 353 | case 'if': |
| 312 | - if(!$opt) return $value; |
|
| 354 | + if(!$opt) { |
|
| 355 | + return $value; |
|
| 356 | + } |
|
| 313 | 357 | return $opt; |
| 314 | 358 | case '=': |
| 315 | 359 | case 'eq': |
@@ -370,14 +414,24 @@ discard block |
||
| 370 | 414 | case 'file_exists': |
| 371 | 415 | case 'is_readable': |
| 372 | 416 | case 'is_writable': |
| 373 | - if(!$opt) $path = $value; |
|
| 374 | - else $path = $opt; |
|
| 375 | - if(strpos($path,MODX_MANAGER_PATH)!==false) exit('Can not read core path'); |
|
| 376 | - if(strpos($path,$modx->config['base_path'])===false) $path = ltrim($path,'/'); |
|
| 417 | + if(!$opt) { |
|
| 418 | + $path = $value; |
|
| 419 | + } else { |
|
| 420 | + $path = $opt; |
|
| 421 | + } |
|
| 422 | + if(strpos($path,MODX_MANAGER_PATH)!==false) { |
|
| 423 | + exit('Can not read core path'); |
|
| 424 | + } |
|
| 425 | + if(strpos($path,$modx->config['base_path'])===false) { |
|
| 426 | + $path = ltrim($path,'/'); |
|
| 427 | + } |
|
| 377 | 428 | $this->condition[] = (int)($cmd($path)!==false);break; |
| 378 | 429 | case 'is_image': |
| 379 | - if(!$opt) $path = $value; |
|
| 380 | - else $path = $opt; |
|
| 430 | + if(!$opt) { |
|
| 431 | + $path = $value; |
|
| 432 | + } else { |
|
| 433 | + $path = $opt; |
|
| 434 | + } |
|
| 381 | 435 | if(!is_file($path)) {$this->condition[]='0';break;} |
| 382 | 436 | $_ = getimagesize($path); |
| 383 | 437 | $this->condition[] = (int)($_[0]);break; |
@@ -400,17 +454,23 @@ discard block |
||
| 400 | 454 | case 'this': |
| 401 | 455 | $conditional = implode(' ',$this->condition); |
| 402 | 456 | $isvalid = (int)(eval("return ({$conditional});")); |
| 403 | - if ($isvalid) return $this->srcValue; |
|
| 457 | + if ($isvalid) { |
|
| 458 | + return $this->srcValue; |
|
| 459 | + } |
|
| 404 | 460 | return NULL; |
| 405 | 461 | case 'then': |
| 406 | 462 | $conditional = implode(' ',$this->condition); |
| 407 | 463 | $isvalid = (int)eval("return ({$conditional});"); |
| 408 | - if ($isvalid) return $opt; |
|
| 464 | + if ($isvalid) { |
|
| 465 | + return $opt; |
|
| 466 | + } |
|
| 409 | 467 | return null; |
| 410 | 468 | case 'else': |
| 411 | 469 | $conditional = implode(' ',$this->condition); |
| 412 | 470 | $isvalid = (int)eval("return ({$conditional});"); |
| 413 | - if (!$isvalid) return $opt; |
|
| 471 | + if (!$isvalid) { |
|
| 472 | + return $opt; |
|
| 473 | + } |
|
| 414 | 474 | break; |
| 415 | 475 | case 'select': |
| 416 | 476 | case 'switch': |
@@ -421,8 +481,11 @@ discard block |
||
| 421 | 481 | $mi = explode('=',$raw[$m],2); |
| 422 | 482 | $map[$mi[0]] = $mi[1]; |
| 423 | 483 | } |
| 424 | - if(isset($map[$value])) return $map[$value]; |
|
| 425 | - else return ''; |
|
| 484 | + if(isset($map[$value])) { |
|
| 485 | + return $map[$value]; |
|
| 486 | + } else { |
|
| 487 | + return ''; |
|
| 488 | + } |
|
| 426 | 489 | ##### End of Conditional Modifiers |
| 427 | 490 | |
| 428 | 491 | ##### Encode / Decode / Hash / Escape |
@@ -448,24 +511,25 @@ discard block |
||
| 448 | 511 | case 'spam_protect': |
| 449 | 512 | return str_replace(array('@','.'),array('@','.'),$value); |
| 450 | 513 | case 'strip': |
| 451 | - if($opt==='') $opt = ' '; |
|
| 514 | + if($opt==='') { |
|
| 515 | + $opt = ' '; |
|
| 516 | + } |
|
| 452 | 517 | return preg_replace('/[\n\r\t\s]+/', $opt, $value); |
| 453 | 518 | case 'strip_linefeeds': |
| 454 | 519 | return str_replace(array("\n","\r"), '', $value); |
| 455 | 520 | case 'notags': |
| 456 | 521 | case 'strip_tags': |
| 457 | 522 | case 'remove_html': |
| 458 | - if($opt!=='') |
|
| 459 | - { |
|
| 523 | + if($opt!=='') { |
|
| 460 | 524 | $param = array(); |
| 461 | - foreach(explode(',',$opt) as $v) |
|
| 462 | - { |
|
| 525 | + foreach(explode(',',$opt) as $v) { |
|
| 463 | 526 | $v = trim($v,'</> '); |
| 464 | 527 | $param[] = "<{$v}>"; |
| 465 | 528 | } |
| 466 | 529 | $params = implode(',',$param); |
| 530 | + } else { |
|
| 531 | + $params = ''; |
|
| 467 | 532 | } |
| 468 | - else $params = ''; |
|
| 469 | 533 | if(!strpos($params,'<br>')===false) { |
| 470 | 534 | $value = preg_replace('@(<br[ /]*>)\n@','$1',$value); |
| 471 | 535 | $value = preg_replace('@<br[ /]*>@',"\n",$value); |
@@ -476,8 +540,11 @@ discard block |
||
| 476 | 540 | case 'encode_url': |
| 477 | 541 | return urlencode($value); |
| 478 | 542 | case 'base64_decode': |
| 479 | - if($opt!=='false') $opt = true; |
|
| 480 | - else $opt = false; |
|
| 543 | + if($opt!=='false') { |
|
| 544 | + $opt = true; |
|
| 545 | + } else { |
|
| 546 | + $opt = false; |
|
| 547 | + } |
|
| 481 | 548 | return base64_decode($value,$opt); |
| 482 | 549 | case 'encode_sha1': $cmd = 'sha1'; |
| 483 | 550 | case 'addslashes': |
@@ -503,16 +570,19 @@ discard block |
||
| 503 | 570 | return $this->strtoupper($value); |
| 504 | 571 | case 'capitalize': |
| 505 | 572 | $_ = explode(' ',$value); |
| 506 | - foreach($_ as $i=>$v) |
|
| 507 | - { |
|
| 573 | + foreach($_ as $i=>$v) { |
|
| 508 | 574 | $_[$i] = ucfirst($v); |
| 509 | 575 | } |
| 510 | 576 | return implode(' ',$_); |
| 511 | 577 | case 'zenhan': |
| 512 | - if(empty($opt)) $opt='VKas'; |
|
| 578 | + if(empty($opt)) { |
|
| 579 | + $opt='VKas'; |
|
| 580 | + } |
|
| 513 | 581 | return mb_convert_kana($value,$opt,$modx->config['modx_charset']); |
| 514 | 582 | case 'hanzen': |
| 515 | - if(empty($opt)) $opt='VKAS'; |
|
| 583 | + if(empty($opt)) { |
|
| 584 | + $opt='VKAS'; |
|
| 585 | + } |
|
| 516 | 586 | return mb_convert_kana($value,$opt,$modx->config['modx_charset']); |
| 517 | 587 | case 'str_shuffle': |
| 518 | 588 | case 'shuffle': |
@@ -537,13 +607,18 @@ discard block |
||
| 537 | 607 | $value = preg_replace('/\r/', '', $value); |
| 538 | 608 | return count(preg_split('/\n+/',$value)); |
| 539 | 609 | case 'strpos': |
| 540 | - if($opt!=0&&empty($opt)) return $value; |
|
| 610 | + if($opt!=0&&empty($opt)) { |
|
| 611 | + return $value; |
|
| 612 | + } |
|
| 541 | 613 | return $this->strpos($value,$opt); |
| 542 | 614 | case 'wordwrap': |
| 543 | 615 | // default: 70 |
| 544 | 616 | $wrapat = (int)$opt > 0 ? (int)$opt : 70; |
| 545 | - if (version_compare(PHP_VERSION, '5.3.0') >= 0) return $this->includeMdfFile('wordwrap'); |
|
| 546 | - else return preg_replace("@(\b\w+\b)@e","wordwrap('\\1',\$wrapat,' ',1)",$value); |
|
| 617 | + if (version_compare(PHP_VERSION, '5.3.0') >= 0) { |
|
| 618 | + return $this->includeMdfFile('wordwrap'); |
|
| 619 | + } else { |
|
| 620 | + return preg_replace("@(\b\w+\b)@e","wordwrap('\\1',\$wrapat,' ',1)",$value); |
|
| 621 | + } |
|
| 547 | 622 | case 'wrap_text': |
| 548 | 623 | $width = preg_match('/^[1-9][0-9]*$/',$opt) ? $opt : 70; |
| 549 | 624 | if($modx->config['manager_language']==='japanese-utf8') { |
@@ -559,30 +634,36 @@ discard block |
||
| 559 | 634 | $value = $this->substr($value,$width); |
| 560 | 635 | } |
| 561 | 636 | return implode("\n",$chunk); |
| 637 | + } else { |
|
| 638 | + return wordwrap($value,$width,"\n",true); |
|
| 562 | 639 | } |
| 563 | - else |
|
| 564 | - return wordwrap($value,$width,"\n",true); |
|
| 565 | 640 | case 'substr': |
| 566 | - if(empty($opt)) break; |
|
| 641 | + if(empty($opt)) { |
|
| 642 | + break; |
|
| 643 | + } |
|
| 567 | 644 | if(strpos($opt,',')!==false) { |
| 568 | 645 | list($b,$e) = explode(',',$opt,2); |
| 569 | 646 | return $this->substr($value,$b,(int)$e); |
| 647 | + } else { |
|
| 648 | + return $this->substr($value,$opt); |
|
| 570 | 649 | } |
| 571 | - else return $this->substr($value,$opt); |
|
| 572 | 650 | case 'limit': |
| 573 | 651 | case 'trim_to': // http://www.movabletype.jp/documentation/appendices/modifiers/trim_to.html |
| 574 | - if(strpos($opt,'+')!==false) |
|
| 575 | - list($len,$str) = explode('+',$opt,2); |
|
| 576 | - else { |
|
| 652 | + if(strpos($opt,'+')!==false) { |
|
| 653 | + list($len,$str) = explode('+',$opt,2); |
|
| 654 | + } else { |
|
| 577 | 655 | $len = $opt; |
| 578 | 656 | $str = ''; |
| 579 | 657 | } |
| 580 | - if($len==='') $len = 100; |
|
| 581 | - if(abs($len) > $this->strlen($value)) $str =''; |
|
| 658 | + if($len==='') { |
|
| 659 | + $len = 100; |
|
| 660 | + } |
|
| 661 | + if(abs($len) > $this->strlen($value)) { |
|
| 662 | + $str =''; |
|
| 663 | + } |
|
| 582 | 664 | if(preg_match('/^[1-9][0-9]*$/',$len)) { |
| 583 | 665 | return $this->substr($value,0,$len) . $str; |
| 584 | - } |
|
| 585 | - elseif(preg_match('/^\-[1-9][0-9]*$/',$len)) { |
|
| 666 | + } elseif(preg_match('/^\-[1-9][0-9]*$/',$len)) { |
|
| 586 | 667 | return $str . $this->substr($value,$len); |
| 587 | 668 | } |
| 588 | 669 | break; |
@@ -592,18 +673,30 @@ discard block |
||
| 592 | 673 | return $this->includeMdfFile('summary'); |
| 593 | 674 | case 'replace': |
| 594 | 675 | case 'str_replace': |
| 595 | - if(empty($opt) || strpos($opt,',')===false) break; |
|
| 596 | - if (substr_count($opt, ',') ==1) $delim = ','; |
|
| 597 | - elseif(substr_count($opt, '|') ==1) $delim = '|'; |
|
| 598 | - elseif(substr_count($opt, '=>')==1) $delim = '=>'; |
|
| 599 | - elseif(substr_count($opt, '/') ==1) $delim = '/'; |
|
| 600 | - else break; |
|
| 676 | + if(empty($opt) || strpos($opt,',')===false) { |
|
| 677 | + break; |
|
| 678 | + } |
|
| 679 | + if (substr_count($opt, ',') ==1) { |
|
| 680 | + $delim = ','; |
|
| 681 | + } elseif(substr_count($opt, '|') ==1) { |
|
| 682 | + $delim = '|'; |
|
| 683 | + } elseif(substr_count($opt, '=>')==1) { |
|
| 684 | + $delim = '=>'; |
|
| 685 | + } elseif(substr_count($opt, '/') ==1) { |
|
| 686 | + $delim = '/'; |
|
| 687 | + } else { |
|
| 688 | + break; |
|
| 689 | + } |
|
| 601 | 690 | list($s,$r) = explode($delim,$opt); |
| 602 | - if($value!=='') return str_replace($s,$r,$value); |
|
| 691 | + if($value!=='') { |
|
| 692 | + return str_replace($s,$r,$value); |
|
| 693 | + } |
|
| 603 | 694 | break; |
| 604 | 695 | case 'replace_to': |
| 605 | 696 | case 'tpl': |
| 606 | - if($value!=='') return str_replace(array('[+value+]','[+output+]','{value}','%s'),$value,$opt); |
|
| 697 | + if($value!=='') { |
|
| 698 | + return str_replace(array('[+value+]','[+output+]','{value}','%s'),$value,$opt); |
|
| 699 | + } |
|
| 607 | 700 | break; |
| 608 | 701 | case 'eachtpl': |
| 609 | 702 | $value = explode('||',$value); |
@@ -614,59 +707,83 @@ discard block |
||
| 614 | 707 | return implode("\n", $_); |
| 615 | 708 | case 'array_pop': |
| 616 | 709 | case 'array_shift': |
| 617 | - if(strpos($value,'||')!==false) $delim = '||'; |
|
| 618 | - else $delim = ','; |
|
| 710 | + if(strpos($value,'||')!==false) { |
|
| 711 | + $delim = '||'; |
|
| 712 | + } else { |
|
| 713 | + $delim = ','; |
|
| 714 | + } |
|
| 619 | 715 | return $cmd(explode($delim,$value)); |
| 620 | 716 | case 'preg_replace': |
| 621 | 717 | case 'regex_replace': |
| 622 | - if(empty($opt) || strpos($opt,',')===false) break; |
|
| 718 | + if(empty($opt) || strpos($opt,',')===false) { |
|
| 719 | + break; |
|
| 720 | + } |
|
| 623 | 721 | list($s,$r) = explode(',',$opt,2); |
| 624 | - if($value!=='') return preg_replace($s,$r,$value); |
|
| 722 | + if($value!=='') { |
|
| 723 | + return preg_replace($s,$r,$value); |
|
| 724 | + } |
|
| 625 | 725 | break; |
| 626 | 726 | case 'cat': |
| 627 | 727 | case 'concatenate': |
| 628 | 728 | case '.': |
| 629 | - if($value!=='') return $value . $opt; |
|
| 729 | + if($value!=='') { |
|
| 730 | + return $value . $opt; |
|
| 731 | + } |
|
| 630 | 732 | break; |
| 631 | 733 | case 'sprintf': |
| 632 | 734 | case 'string_format': |
| 633 | - if($value!=='') return sprintf($opt,$value); |
|
| 735 | + if($value!=='') { |
|
| 736 | + return sprintf($opt,$value); |
|
| 737 | + } |
|
| 634 | 738 | break; |
| 635 | 739 | case 'number_format': |
| 636 | - if($opt=='') $opt = 0; |
|
| 740 | + if($opt=='') { |
|
| 741 | + $opt = 0; |
|
| 742 | + } |
|
| 637 | 743 | return number_format($value,$opt); |
| 638 | 744 | case 'money_format': |
| 639 | 745 | setlocale(LC_MONETARY,setlocale(LC_TIME,0)); |
| 640 | - if($value!=='') return money_format($opt,(double)$value); |
|
| 746 | + if($value!=='') { |
|
| 747 | + return money_format($opt,(double)$value); |
|
| 748 | + } |
|
| 641 | 749 | break; |
| 642 | 750 | case 'tobool': |
| 643 | 751 | return boolval($value); |
| 644 | 752 | case 'nl2lf': |
| 645 | - if($value!=='') return str_replace(array("\r\n","\n", "\r"), '\n', $value); |
|
| 753 | + if($value!=='') { |
|
| 754 | + return str_replace(array("\r\n","\n", "\r"), '\n', $value); |
|
| 755 | + } |
|
| 646 | 756 | break; |
| 647 | 757 | case 'br2nl': |
| 648 | 758 | return preg_replace('@<br[\s/]*>@i', "\n", $value); |
| 649 | 759 | case 'nl2br': |
| 650 | - if (version_compare(PHP_VERSION, '5.3.0', '<')) |
|
| 651 | - return nl2br($value); |
|
| 652 | - if($opt!=='') |
|
| 653 | - { |
|
| 760 | + if (version_compare(PHP_VERSION, '5.3.0', '<')) { |
|
| 761 | + return nl2br($value); |
|
| 762 | + } |
|
| 763 | + if($opt!=='') { |
|
| 654 | 764 | $opt = trim($opt); |
| 655 | 765 | $opt = strtolower($opt); |
| 656 | - if($opt==='false') $opt = false; |
|
| 657 | - elseif($opt==='0') $opt = false; |
|
| 658 | - else $opt = true; |
|
| 766 | + if($opt==='false') { |
|
| 767 | + $opt = false; |
|
| 768 | + } elseif($opt==='0') { |
|
| 769 | + $opt = false; |
|
| 770 | + } else { |
|
| 771 | + $opt = true; |
|
| 772 | + } |
|
| 773 | + } elseif(isset($modx->config['mce_element_format'])&&$modx->config['mce_element_format']==='html') { |
|
| 774 | + $opt = false; |
|
| 775 | + } else { |
|
| 776 | + $opt = true; |
|
| 659 | 777 | } |
| 660 | - elseif(isset($modx->config['mce_element_format'])&&$modx->config['mce_element_format']==='html') |
|
| 661 | - $opt = false; |
|
| 662 | - else $opt = true; |
|
| 663 | 778 | return nl2br($value,$opt); |
| 664 | 779 | case 'ltrim': |
| 665 | 780 | case 'rtrim': |
| 666 | 781 | case 'trim': // ref http://mblo.info/modifiers/custom-modifiers/rtrim_opt.html |
| 667 | - if($opt==='') |
|
| 668 | - return $cmd($value); |
|
| 669 | - else return $cmd($value,$opt); |
|
| 782 | + if($opt==='') { |
|
| 783 | + return $cmd($value); |
|
| 784 | + } else { |
|
| 785 | + return $cmd($value,$opt); |
|
| 786 | + } |
|
| 670 | 787 | // These are all straight wrappers for PHP functions |
| 671 | 788 | case 'ucfirst': |
| 672 | 789 | case 'lcfirst': |
@@ -677,15 +794,24 @@ discard block |
||
| 677 | 794 | case 'strftime': |
| 678 | 795 | case 'date': |
| 679 | 796 | case 'dateformat': |
| 680 | - if(empty($opt)) $opt = $modx->toDateFormat(null, 'formatOnly'); |
|
| 681 | - if(!preg_match('@^[0-9]+$@',$value)) $value = strtotime($value); |
|
| 682 | - if(strpos($opt,'%')!==false) |
|
| 683 | - return strftime($opt,0+$value); |
|
| 684 | - else |
|
| 685 | - return date($opt,0+$value); |
|
| 797 | + if(empty($opt)) { |
|
| 798 | + $opt = $modx->toDateFormat(null, 'formatOnly'); |
|
| 799 | + } |
|
| 800 | + if(!preg_match('@^[0-9]+$@',$value)) { |
|
| 801 | + $value = strtotime($value); |
|
| 802 | + } |
|
| 803 | + if(strpos($opt,'%')!==false) { |
|
| 804 | + return strftime($opt,0+$value); |
|
| 805 | + } else { |
|
| 806 | + return date($opt,0+$value); |
|
| 807 | + } |
|
| 686 | 808 | case 'time': |
| 687 | - if(empty($opt)) $opt = '%H:%M'; |
|
| 688 | - if(!preg_match('@^[0-9]+$@',$value)) $value = strtotime($value); |
|
| 809 | + if(empty($opt)) { |
|
| 810 | + $opt = '%H:%M'; |
|
| 811 | + } |
|
| 812 | + if(!preg_match('@^[0-9]+$@',$value)) { |
|
| 813 | + $value = strtotime($value); |
|
| 814 | + } |
|
| 689 | 815 | return strftime($opt,0+$value); |
| 690 | 816 | case 'strtotime': |
| 691 | 817 | return strtotime($value); |
@@ -695,7 +821,9 @@ discard block |
||
| 695 | 821 | case 'tofloat': |
| 696 | 822 | return floatval($value); |
| 697 | 823 | case 'round': |
| 698 | - if(!$opt) $opt = 0; |
|
| 824 | + if(!$opt) { |
|
| 825 | + $opt = 0; |
|
| 826 | + } |
|
| 699 | 827 | return $cmd($value,$opt); |
| 700 | 828 | case 'max': |
| 701 | 829 | case 'min': |
@@ -707,28 +835,42 @@ discard block |
||
| 707 | 835 | case 'math': |
| 708 | 836 | case 'calc': |
| 709 | 837 | $value = (int)$value; |
| 710 | - if(empty($value)) $value = '0'; |
|
| 838 | + if(empty($value)) { |
|
| 839 | + $value = '0'; |
|
| 840 | + } |
|
| 711 | 841 | $filter = str_replace(array('[+value+]','[+output+]','{value}','%s'),'?',$opt); |
| 712 | 842 | $filter = preg_replace('@([a-zA-Z\n\r\t\s])@','',$filter); |
| 713 | - if(strpos($filter,'?')===false) $filter = "?{$filter}"; |
|
| 843 | + if(strpos($filter,'?')===false) { |
|
| 844 | + $filter = "?{$filter}"; |
|
| 845 | + } |
|
| 714 | 846 | $filter = str_replace('?',$value,$filter); |
| 715 | 847 | return eval("return {$filter};"); |
| 716 | 848 | case 'count': |
| 717 | - if($value=='') return 0; |
|
| 849 | + if($value=='') { |
|
| 850 | + return 0; |
|
| 851 | + } |
|
| 718 | 852 | $value = explode(',',$value); |
| 719 | 853 | return count($value); |
| 720 | 854 | case 'sort': |
| 721 | 855 | case 'rsort': |
| 722 | - if(strpos($value,"\n")!==false) $delim="\n"; |
|
| 723 | - else $delim = ','; |
|
| 856 | + if(strpos($value,"\n")!==false) { |
|
| 857 | + $delim="\n"; |
|
| 858 | + } else { |
|
| 859 | + $delim = ','; |
|
| 860 | + } |
|
| 724 | 861 | $swap = explode($delim,$value); |
| 725 | - if(!$opt) $opt = SORT_REGULAR; |
|
| 726 | - else $opt = constant($opt); |
|
| 862 | + if(!$opt) { |
|
| 863 | + $opt = SORT_REGULAR; |
|
| 864 | + } else { |
|
| 865 | + $opt = constant($opt); |
|
| 866 | + } |
|
| 727 | 867 | $cmd($swap,$opt); |
| 728 | 868 | return implode($delim,$swap); |
| 729 | 869 | ##### Resource fields |
| 730 | 870 | case 'id': |
| 731 | - if($opt) return $this->getDocumentObject($opt,$key); |
|
| 871 | + if($opt) { |
|
| 872 | + return $this->getDocumentObject($opt,$key); |
|
| 873 | + } |
|
| 732 | 874 | break; |
| 733 | 875 | case 'type': |
| 734 | 876 | case 'contenttype': |
@@ -765,7 +907,9 @@ discard block |
||
| 765 | 907 | case 'privatemgr': |
| 766 | 908 | case 'content_dispo': |
| 767 | 909 | case 'hidemenu': |
| 768 | - if($cmd==='contenttype') $cmd = 'contentType'; |
|
| 910 | + if($cmd==='contenttype') { |
|
| 911 | + $cmd = 'contentType'; |
|
| 912 | + } |
|
| 769 | 913 | return $this->getDocumentObject($value,$cmd); |
| 770 | 914 | case 'title': |
| 771 | 915 | $pagetitle = $this->getDocumentObject($value,'pagetitle'); |
@@ -780,13 +924,20 @@ discard block |
||
| 780 | 924 | $templateName = $modx->db->getValue($rs); |
| 781 | 925 | return !$templateName ? '(blank)' : $templateName; |
| 782 | 926 | case 'getfield': |
| 783 | - if(!$opt) $opt = 'content'; |
|
| 927 | + if(!$opt) { |
|
| 928 | + $opt = 'content'; |
|
| 929 | + } |
|
| 784 | 930 | return $modx->getField($opt,$value); |
| 785 | 931 | case 'children': |
| 786 | 932 | case 'childids': |
| 787 | - if($value=='') $value = 0; // 値がない場合はルートと見なす |
|
| 933 | + if($value=='') { |
|
| 934 | + $value = 0; |
|
| 935 | + } |
|
| 936 | + // 値がない場合はルートと見なす |
|
| 788 | 937 | $published = 1; |
| 789 | - if($opt=='') $opt = 'page'; |
|
| 938 | + if($opt=='') { |
|
| 939 | + $opt = 'page'; |
|
| 940 | + } |
|
| 790 | 941 | $_ = explode(',',$opt); |
| 791 | 942 | $where = array(); |
| 792 | 943 | foreach($_ as $opt) { |
@@ -802,29 +953,43 @@ discard block |
||
| 802 | 953 | $where = implode(' AND ', $where); |
| 803 | 954 | $children = $modx->getDocumentChildren($value, $published, '0', 'id', $where); |
| 804 | 955 | $result = array(); |
| 805 | - foreach((array)$children as $child){ |
|
| 956 | + foreach((array)$children as $child) { |
|
| 806 | 957 | $result[] = $child['id']; |
| 807 | 958 | } |
| 808 | 959 | return implode(',', $result); |
| 809 | 960 | case 'fullurl': |
| 810 | - if(!is_numeric($value)) return $value; |
|
| 961 | + if(!is_numeric($value)) { |
|
| 962 | + return $value; |
|
| 963 | + } |
|
| 811 | 964 | return $modx->makeUrl($value); |
| 812 | 965 | case 'makeurl': |
| 813 | - if(!is_numeric($value)) return $value; |
|
| 814 | - if(!$opt) $opt = 'full'; |
|
| 966 | + if(!is_numeric($value)) { |
|
| 967 | + return $value; |
|
| 968 | + } |
|
| 969 | + if(!$opt) { |
|
| 970 | + $opt = 'full'; |
|
| 971 | + } |
|
| 815 | 972 | return $modx->makeUrl($value,'','',$opt); |
| 816 | 973 | |
| 817 | 974 | ##### File system |
| 818 | 975 | case 'getimageinfo': |
| 819 | 976 | case 'imageinfo': |
| 820 | - if(!is_file($value)) return ''; |
|
| 977 | + if(!is_file($value)) { |
|
| 978 | + return ''; |
|
| 979 | + } |
|
| 821 | 980 | $_ = getimagesize($value); |
| 822 | - if(!$_[0]) return ''; |
|
| 981 | + if(!$_[0]) { |
|
| 982 | + return ''; |
|
| 983 | + } |
|
| 823 | 984 | $info['width'] = $_[0]; |
| 824 | 985 | $info['height'] = $_[1]; |
| 825 | - if ($_[0] > $_[1]) $info['aspect'] = 'landscape'; |
|
| 826 | - elseif($_[0] < $_[1]) $info['aspect'] = 'portrait'; |
|
| 827 | - else $info['aspect'] = 'square'; |
|
| 986 | + if ($_[0] > $_[1]) { |
|
| 987 | + $info['aspect'] = 'landscape'; |
|
| 988 | + } elseif($_[0] < $_[1]) { |
|
| 989 | + $info['aspect'] = 'portrait'; |
|
| 990 | + } else { |
|
| 991 | + $info['aspect'] = 'square'; |
|
| 992 | + } |
|
| 828 | 993 | switch($_[2]) { |
| 829 | 994 | case IMAGETYPE_GIF : $info['type'] = 'gif'; break; |
| 830 | 995 | case IMAGETYPE_JPEG : $info['type'] = 'jpg'; break; |
@@ -843,33 +1008,47 @@ discard block |
||
| 843 | 1008 | |
| 844 | 1009 | case 'file_get_contents': |
| 845 | 1010 | case 'readfile': |
| 846 | - if(!is_file($value)) return $value; |
|
| 1011 | + if(!is_file($value)) { |
|
| 1012 | + return $value; |
|
| 1013 | + } |
|
| 847 | 1014 | $value = realpath($value); |
| 848 | - if(strpos($value,MODX_MANAGER_PATH)!==false) exit('Can not read core file'); |
|
| 1015 | + if(strpos($value,MODX_MANAGER_PATH)!==false) { |
|
| 1016 | + exit('Can not read core file'); |
|
| 1017 | + } |
|
| 849 | 1018 | $ext = strtolower(substr($value,-4)); |
| 850 | - if($ext==='.php') exit('Can not read php file'); |
|
| 851 | - if($ext==='.cgi') exit('Can not read cgi file'); |
|
| 1019 | + if($ext==='.php') { |
|
| 1020 | + exit('Can not read php file'); |
|
| 1021 | + } |
|
| 1022 | + if($ext==='.cgi') { |
|
| 1023 | + exit('Can not read cgi file'); |
|
| 1024 | + } |
|
| 852 | 1025 | return file_get_contents($value); |
| 853 | 1026 | case 'filesize': |
| 854 | - if($value == '') return ''; |
|
| 1027 | + if($value == '') { |
|
| 1028 | + return ''; |
|
| 1029 | + } |
|
| 855 | 1030 | $filename = $value; |
| 856 | 1031 | |
| 857 | 1032 | $site_url = $modx->config['site_url']; |
| 858 | - if(strpos($filename,$site_url) === 0) |
|
| 859 | - $filename = substr($filename,0,strlen($site_url)); |
|
| 1033 | + if(strpos($filename,$site_url) === 0) { |
|
| 1034 | + $filename = substr($filename,0,strlen($site_url)); |
|
| 1035 | + } |
|
| 860 | 1036 | $filename = trim($filename,'/'); |
| 861 | 1037 | |
| 862 | 1038 | $opt = trim($opt,'/'); |
| 863 | - if($opt!=='') $opt .= '/'; |
|
| 1039 | + if($opt!=='') { |
|
| 1040 | + $opt .= '/'; |
|
| 1041 | + } |
|
| 864 | 1042 | |
| 865 | 1043 | $filename = MODX_BASE_PATH.$opt.$filename; |
| 866 | 1044 | |
| 867 | - if(is_file($filename)){ |
|
| 1045 | + if(is_file($filename)) { |
|
| 868 | 1046 | clearstatcache(); |
| 869 | 1047 | $size = filesize($filename); |
| 870 | 1048 | return $size; |
| 1049 | + } else { |
|
| 1050 | + return ''; |
|
| 871 | 1051 | } |
| 872 | - else return ''; |
|
| 873 | 1052 | ##### User info |
| 874 | 1053 | case 'username': |
| 875 | 1054 | case 'fullname': |
@@ -897,32 +1076,47 @@ discard block |
||
| 897 | 1076 | $this->opt = $cmd; |
| 898 | 1077 | return $this->includeMdfFile('moduser'); |
| 899 | 1078 | case 'userinfo': |
| 900 | - if(empty($opt)) $this->opt = 'username'; |
|
| 1079 | + if(empty($opt)) { |
|
| 1080 | + $this->opt = 'username'; |
|
| 1081 | + } |
|
| 901 | 1082 | return $this->includeMdfFile('moduser'); |
| 902 | 1083 | case 'webuserinfo': |
| 903 | - if(empty($opt)) $this->opt = 'username'; |
|
| 1084 | + if(empty($opt)) { |
|
| 1085 | + $this->opt = 'username'; |
|
| 1086 | + } |
|
| 904 | 1087 | $this->value = -$value; |
| 905 | 1088 | return $this->includeMdfFile('moduser'); |
| 906 | 1089 | ##### Special functions |
| 907 | 1090 | case 'ifempty': |
| 908 | 1091 | case '_default': |
| 909 | 1092 | case 'default': |
| 910 | - if (empty($value)) return $opt; break; |
|
| 1093 | + if (empty($value)) { |
|
| 1094 | + return $opt; |
|
| 1095 | + } |
|
| 1096 | + break; |
|
| 911 | 1097 | case 'ifnotempty': |
| 912 | - if (!empty($value)) return $opt; break; |
|
| 1098 | + if (!empty($value)) { |
|
| 1099 | + return $opt; |
|
| 1100 | + } |
|
| 1101 | + break; |
|
| 913 | 1102 | case 'datagrid': |
| 914 | 1103 | include_once(MODX_CORE_PATH . 'controls/datagrid.class.php'); |
| 915 | 1104 | $grd = new DataGrid(null, trim($value)); |
| 916 | 1105 | $grd->itemStyle = ''; |
| 917 | 1106 | $grd->altItemStyle = ''; |
| 918 | 1107 | $pos = strpos($value,"\n"); |
| 919 | - if($pos) $_ = substr($value,0,$pos); |
|
| 920 | - else $_ = $pos; |
|
| 1108 | + if($pos) { |
|
| 1109 | + $_ = substr($value,0,$pos); |
|
| 1110 | + } else { |
|
| 1111 | + $_ = $pos; |
|
| 1112 | + } |
|
| 921 | 1113 | $grd->cdelim = strpos($_,"\t")!==false ? 'tab' : ','; |
| 922 | 1114 | return $grd->render(); |
| 923 | 1115 | case 'rotate': |
| 924 | 1116 | case 'evenodd': |
| 925 | - if(strpos($opt,',')===false) $opt = 'odd,even'; |
|
| 1117 | + if(strpos($opt,',')===false) { |
|
| 1118 | + $opt = 'odd,even'; |
|
| 1119 | + } |
|
| 926 | 1120 | $_ = explode(',', $opt); |
| 927 | 1121 | $c = count($_); |
| 928 | 1122 | $i = $value + $c; |
@@ -931,7 +1125,9 @@ discard block |
||
| 931 | 1125 | case 'takeval': |
| 932 | 1126 | $arr = explode(",",$opt); |
| 933 | 1127 | $idx = $value; |
| 934 | - if(!is_numeric($idx)) return $value; |
|
| 1128 | + if(!is_numeric($idx)) { |
|
| 1129 | + return $value; |
|
| 1130 | + } |
|
| 935 | 1131 | return $arr[$idx]; |
| 936 | 1132 | case 'getimage': |
| 937 | 1133 | return $this->includeMdfFile('getimage'); |
@@ -939,14 +1135,18 @@ discard block |
||
| 939 | 1135 | return $modx->nicesize($value); |
| 940 | 1136 | case 'googlemap': |
| 941 | 1137 | case 'googlemaps': |
| 942 | - if(empty($opt)) $opt = 'border:none;width:500px;height:350px;'; |
|
| 1138 | + if(empty($opt)) { |
|
| 1139 | + $opt = 'border:none;width:500px;height:350px;'; |
|
| 1140 | + } |
|
| 943 | 1141 | $tpl = '<iframe style="[+style+]" src="https://maps.google.co.jp/maps?ll=[+value+]&output=embed&z=15"></iframe>'; |
| 944 | 1142 | $ph['style'] = $opt; |
| 945 | 1143 | $ph['value'] = $value; |
| 946 | 1144 | return $modx->parseText($tpl,$ph); |
| 947 | 1145 | case 'youtube': |
| 948 | 1146 | case 'youtube16x9': |
| 949 | - if(empty($opt)) $opt = 560; |
|
| 1147 | + if(empty($opt)) { |
|
| 1148 | + $opt = 560; |
|
| 1149 | + } |
|
| 950 | 1150 | $h = round($opt*0.5625); |
| 951 | 1151 | $tpl = '<iframe width="%s" height="%s" src="https://www.youtube.com/embed/%s" frameborder="0" allowfullscreen></iframe>'; |
| 952 | 1152 | return sprintf($tpl,$opt,$h,$value); |
@@ -979,7 +1179,8 @@ discard block |
||
| 979 | 1179 | return $value; |
| 980 | 1180 | } |
| 981 | 1181 | |
| 982 | - public function includeMdfFile($cmd) { |
|
| 1182 | + public function includeMdfFile($cmd) |
|
| 1183 | + { |
|
| 983 | 1184 | global $modx; |
| 984 | 1185 | $key = $this->key; |
| 985 | 1186 | $value = $this->value; |
@@ -990,55 +1191,65 @@ discard block |
||
| 990 | 1191 | public function getValueFromElement($key, $value, $cmd, $opt) |
| 991 | 1192 | { |
| 992 | 1193 | global $modx; |
| 993 | - if( isset($modx->snippetCache[$this->elmName]) ) |
|
| 994 | - { |
|
| 1194 | + if( isset($modx->snippetCache[$this->elmName]) ) { |
|
| 995 | 1195 | $php = $modx->snippetCache[$this->elmName]; |
| 996 | - } |
|
| 997 | - else |
|
| 998 | - { |
|
| 1196 | + } else { |
|
| 999 | 1197 | $esc_elmName = $modx->db->escape($this->elmName); |
| 1000 | 1198 | $result = $modx->db->select('snippet','[+prefix+]site_snippets',"name='{$esc_elmName}'"); |
| 1001 | 1199 | $total = $modx->db->getRecordCount($result); |
| 1002 | - if($total == 1) |
|
| 1003 | - { |
|
| 1200 | + if($total == 1) { |
|
| 1004 | 1201 | $row = $modx->db->getRow($result); |
| 1005 | 1202 | $php = $row['snippet']; |
| 1006 | - } |
|
| 1007 | - elseif($total == 0) |
|
| 1008 | - { |
|
| 1203 | + } elseif($total == 0) { |
|
| 1009 | 1204 | $assets_path = MODX_BASE_PATH.'assets/'; |
| 1010 | - if(is_file($assets_path."modifiers/mdf_{$cmd}.inc.php")) |
|
| 1011 | - $modifiers_path = $assets_path."modifiers/mdf_{$cmd}.inc.php"; |
|
| 1012 | - elseif(is_file($assets_path."plugins/phx/modifiers/{$cmd}.phx.php")) |
|
| 1013 | - $modifiers_path = $assets_path."plugins/phx/modifiers/{$cmd}.phx.php"; |
|
| 1014 | - elseif(is_file(MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php")) |
|
| 1015 | - $modifiers_path = MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php"; |
|
| 1016 | - else $modifiers_path = false; |
|
| 1205 | + if(is_file($assets_path."modifiers/mdf_{$cmd}.inc.php")) { |
|
| 1206 | + $modifiers_path = $assets_path."modifiers/mdf_{$cmd}.inc.php"; |
|
| 1207 | + } elseif(is_file($assets_path."plugins/phx/modifiers/{$cmd}.phx.php")) { |
|
| 1208 | + $modifiers_path = $assets_path."plugins/phx/modifiers/{$cmd}.phx.php"; |
|
| 1209 | + } elseif(is_file(MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php")) { |
|
| 1210 | + $modifiers_path = MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php"; |
|
| 1211 | + } else { |
|
| 1212 | + $modifiers_path = false; |
|
| 1213 | + } |
|
| 1017 | 1214 | |
| 1018 | 1215 | if($modifiers_path !== false) { |
| 1019 | 1216 | $php = @file_get_contents($modifiers_path); |
| 1020 | 1217 | $php = trim($php); |
| 1021 | - if(substr($php,0,5)==='<?php') $php = substr($php,6); |
|
| 1022 | - if(substr($php,0,2)==='<?') $php = substr($php,3); |
|
| 1023 | - if(substr($php,-2)==='?>') $php = substr($php,0,-2); |
|
| 1024 | - if($this->elmName!=='') |
|
| 1025 | - $modx->snippetCache[$this->elmName.'Props'] = ''; |
|
| 1026 | - } |
|
| 1027 | - else |
|
| 1028 | - $php = false; |
|
| 1218 | + if(substr($php,0,5)==='<?php') { |
|
| 1219 | + $php = substr($php,6); |
|
| 1220 | + } |
|
| 1221 | + if(substr($php,0,2)==='<?') { |
|
| 1222 | + $php = substr($php,3); |
|
| 1223 | + } |
|
| 1224 | + if(substr($php,-2)==='?>') { |
|
| 1225 | + $php = substr($php,0,-2); |
|
| 1226 | + } |
|
| 1227 | + if($this->elmName!=='') { |
|
| 1228 | + $modx->snippetCache[$this->elmName.'Props'] = ''; |
|
| 1229 | + } |
|
| 1230 | + } else { |
|
| 1231 | + $php = false; |
|
| 1232 | + } |
|
| 1233 | + } else { |
|
| 1234 | + $php = false; |
|
| 1235 | + } |
|
| 1236 | + if($this->elmName!=='') { |
|
| 1237 | + $modx->snippetCache[$this->elmName]= $php; |
|
| 1029 | 1238 | } |
| 1030 | - else $php = false; |
|
| 1031 | - if($this->elmName!=='') $modx->snippetCache[$this->elmName]= $php; |
|
| 1032 | 1239 | } |
| 1033 | - if($php==='') $php=false; |
|
| 1240 | + if($php==='') { |
|
| 1241 | + $php=false; |
|
| 1242 | + } |
|
| 1034 | 1243 | |
| 1035 | - if($php===false) $html = $modx->getChunk($this->elmName); |
|
| 1036 | - else $html = false; |
|
| 1244 | + if($php===false) { |
|
| 1245 | + $html = $modx->getChunk($this->elmName); |
|
| 1246 | + } else { |
|
| 1247 | + $html = false; |
|
| 1248 | + } |
|
| 1037 | 1249 | |
| 1038 | 1250 | $self = '[+output+]'; |
| 1039 | 1251 | |
| 1040 | - if($php !== false) |
|
| 1041 | - { |
|
| 1252 | + if($php !== false) { |
|
| 1042 | 1253 | ob_start(); |
| 1043 | 1254 | $options = $opt; |
| 1044 | 1255 | $output = $value; |
@@ -1050,19 +1261,19 @@ discard block |
||
| 1050 | 1261 | $this->vars['options'] = & $opt; |
| 1051 | 1262 | $custom = eval($php); |
| 1052 | 1263 | $msg = ob_get_contents(); |
| 1053 | - if($value===$this->bt) $value = $msg . $custom; |
|
| 1264 | + if($value===$this->bt) { |
|
| 1265 | + $value = $msg . $custom; |
|
| 1266 | + } |
|
| 1054 | 1267 | ob_end_clean(); |
| 1055 | - } |
|
| 1056 | - elseif($html!==false && isset($value) && $value!=='') |
|
| 1057 | - { |
|
| 1268 | + } elseif($html!==false && isset($value) && $value!=='') { |
|
| 1058 | 1269 | $html = str_replace(array($self,'[+value+]'), $value, $html); |
| 1059 | 1270 | $value = str_replace(array('[+options+]','[+param+]'), $opt, $html); |
| 1271 | + } else { |
|
| 1272 | + return false; |
|
| 1060 | 1273 | } |
| 1061 | - else return false; |
|
| 1062 | 1274 | |
| 1063 | 1275 | if($php===false && $html===false && $value!=='' |
| 1064 | - && (strpos($cmd,'[+value+]')!==false || strpos($cmd,$self)!==false)) |
|
| 1065 | - { |
|
| 1276 | + && (strpos($cmd,'[+value+]')!==false || strpos($cmd,$self)!==false)) { |
|
| 1066 | 1277 | $value = str_replace(array('[+value+]',$self),$value,$cmd); |
| 1067 | 1278 | } |
| 1068 | 1279 | return $value; |
@@ -1072,23 +1283,39 @@ discard block |
||
| 1072 | 1283 | { |
| 1073 | 1284 | global $modx; |
| 1074 | 1285 | |
| 1075 | - if(strpos($content,'[')===false && strpos($content,'{')===false) return $content; |
|
| 1286 | + if(strpos($content,'[')===false && strpos($content,'{')===false) { |
|
| 1287 | + return $content; |
|
| 1288 | + } |
|
| 1076 | 1289 | |
| 1077 | - if(!$modx->maxParserPasses) $modx->maxParserPasses = 10; |
|
| 1290 | + if(!$modx->maxParserPasses) { |
|
| 1291 | + $modx->maxParserPasses = 10; |
|
| 1292 | + } |
|
| 1078 | 1293 | $bt=''; |
| 1079 | 1294 | $i=0; |
| 1080 | - while($bt!==$content) |
|
| 1081 | - { |
|
| 1295 | + while($bt!==$content) { |
|
| 1082 | 1296 | $bt = $content; |
| 1083 | - if(strpos($content,'[*')!==false && $modx->documentIdentifier) |
|
| 1084 | - $content = $modx->mergeDocumentContent($content); |
|
| 1085 | - if(strpos($content,'[(')!==false) $content = $modx->mergeSettingsContent($content); |
|
| 1086 | - if(strpos($content,'{{')!==false) $content = $modx->mergeChunkContent($content); |
|
| 1087 | - if(strpos($content,'[!')!==false) $content = str_replace(array('[!','!]'),array('[[',']]'),$content); |
|
| 1088 | - if(strpos($content,'[[')!==false) $content = $modx->evalSnippets($content); |
|
| 1089 | - |
|
| 1090 | - if($content===$bt) break; |
|
| 1091 | - if($modx->maxParserPasses < $i) break; |
|
| 1297 | + if(strpos($content,'[*')!==false && $modx->documentIdentifier) { |
|
| 1298 | + $content = $modx->mergeDocumentContent($content); |
|
| 1299 | + } |
|
| 1300 | + if(strpos($content,'[(')!==false) { |
|
| 1301 | + $content = $modx->mergeSettingsContent($content); |
|
| 1302 | + } |
|
| 1303 | + if(strpos($content,'{{')!==false) { |
|
| 1304 | + $content = $modx->mergeChunkContent($content); |
|
| 1305 | + } |
|
| 1306 | + if(strpos($content,'[!')!==false) { |
|
| 1307 | + $content = str_replace(array('[!','!]'),array('[[',']]'),$content); |
|
| 1308 | + } |
|
| 1309 | + if(strpos($content,'[[')!==false) { |
|
| 1310 | + $content = $modx->evalSnippets($content); |
|
| 1311 | + } |
|
| 1312 | + |
|
| 1313 | + if($content===$bt) { |
|
| 1314 | + break; |
|
| 1315 | + } |
|
| 1316 | + if($modx->maxParserPasses < $i) { |
|
| 1317 | + break; |
|
| 1318 | + } |
|
| 1092 | 1319 | $i++; |
| 1093 | 1320 | } |
| 1094 | 1321 | return $content; |
@@ -1099,103 +1326,138 @@ discard block |
||
| 1099 | 1326 | global $modx; |
| 1100 | 1327 | |
| 1101 | 1328 | $target = trim($target); |
| 1102 | - if(empty($target)) $target = $modx->config['site_start']; |
|
| 1103 | - if(preg_match('@^[1-9][0-9]*$@',$target)) $method='id'; |
|
| 1104 | - else $method = 'alias'; |
|
| 1329 | + if(empty($target)) { |
|
| 1330 | + $target = $modx->config['site_start']; |
|
| 1331 | + } |
|
| 1332 | + if(preg_match('@^[1-9][0-9]*$@',$target)) { |
|
| 1333 | + $method='id'; |
|
| 1334 | + } else { |
|
| 1335 | + $method = 'alias'; |
|
| 1336 | + } |
|
| 1105 | 1337 | |
| 1106 | - if(!isset($this->documentObject[$target])) |
|
| 1107 | - { |
|
| 1338 | + if(!isset($this->documentObject[$target])) { |
|
| 1108 | 1339 | $this->documentObject[$target] = $modx->getDocumentObject($method,$target,'direct'); |
| 1109 | 1340 | } |
| 1110 | 1341 | |
| 1111 | - if($this->documentObject[$target]['publishedon']==='0') |
|
| 1112 | - return ''; |
|
| 1113 | - elseif(isset($this->documentObject[$target][$field])) |
|
| 1114 | - { |
|
| 1115 | - if(is_array($this->documentObject[$target][$field])) |
|
| 1116 | - { |
|
| 1342 | + if($this->documentObject[$target]['publishedon']==='0') { |
|
| 1343 | + return ''; |
|
| 1344 | + } elseif(isset($this->documentObject[$target][$field])) { |
|
| 1345 | + if(is_array($this->documentObject[$target][$field])) { |
|
| 1117 | 1346 | $a = $modx->getTemplateVarOutput($field,$target); |
| 1118 | 1347 | $this->documentObject[$target][$field] = $a[$field]; |
| 1119 | 1348 | } |
| 1349 | + } else { |
|
| 1350 | + $this->documentObject[$target][$field] = false; |
|
| 1120 | 1351 | } |
| 1121 | - else $this->documentObject[$target][$field] = false; |
|
| 1122 | 1352 | |
| 1123 | 1353 | return $this->documentObject[$target][$field]; |
| 1124 | 1354 | } |
| 1125 | 1355 | |
| 1126 | - public function setPlaceholders($value = '', $key = '', $path = '') { |
|
| 1127 | - if($path!=='') $key = "{$path}.{$key}"; |
|
| 1356 | + public function setPlaceholders($value = '', $key = '', $path = '') |
|
| 1357 | + { |
|
| 1358 | + if($path!=='') { |
|
| 1359 | + $key = "{$path}.{$key}"; |
|
| 1360 | + } |
|
| 1128 | 1361 | if (is_array($value)) { |
| 1129 | 1362 | foreach ($value as $subkey => $subval) { |
| 1130 | 1363 | $this->setPlaceholders($subval, $subkey, $key); |
| 1131 | 1364 | } |
| 1365 | + } else { |
|
| 1366 | + $this->setModifiersVariable($key, $value); |
|
| 1132 | 1367 | } |
| 1133 | - else $this->setModifiersVariable($key, $value); |
|
| 1134 | 1368 | } |
| 1135 | 1369 | |
| 1136 | 1370 | // Sets a placeholder variable which can only be access by Modifiers |
| 1137 | - public function setModifiersVariable($key, $value) { |
|
| 1138 | - if ($key != 'phx' && $key != 'dummy') $this->placeholders[$key] = $value; |
|
| 1371 | + public function setModifiersVariable($key, $value) |
|
| 1372 | + { |
|
| 1373 | + if ($key != 'phx' && $key != 'dummy') { |
|
| 1374 | + $this->placeholders[$key] = $value; |
|
| 1375 | + } |
|
| 1139 | 1376 | } |
| 1140 | 1377 | |
| 1141 | 1378 | //mbstring |
| 1142 | - public function substr($str, $s, $l = null) { |
|
| 1379 | + public function substr($str, $s, $l = null) |
|
| 1380 | + { |
|
| 1143 | 1381 | global $modx; |
| 1144 | - if(is_null($l)) $l = $this->strlen($str); |
|
| 1145 | - if (function_exists('mb_substr')) |
|
| 1146 | - { |
|
| 1147 | - if(strpos($str,"\r")!==false) |
|
| 1148 | - $str = str_replace(array("\r\n","\r"), "\n", $str); |
|
| 1382 | + if(is_null($l)) { |
|
| 1383 | + $l = $this->strlen($str); |
|
| 1384 | + } |
|
| 1385 | + if (function_exists('mb_substr')) { |
|
| 1386 | + if(strpos($str,"\r")!==false) { |
|
| 1387 | + $str = str_replace(array("\r\n","\r"), "\n", $str); |
|
| 1388 | + } |
|
| 1149 | 1389 | return mb_substr($str, $s, $l, $modx->config['modx_charset']); |
| 1150 | 1390 | } |
| 1151 | 1391 | return substr($str, $s, $l); |
| 1152 | 1392 | } |
| 1153 | - public function strpos($haystack,$needle,$offset=0) { |
|
| 1393 | + public function strpos($haystack,$needle,$offset=0) |
|
| 1394 | + { |
|
| 1154 | 1395 | global $modx; |
| 1155 | - if (function_exists('mb_strpos')) return mb_strpos($haystack,$needle,$offset,$modx->config['modx_charset']); |
|
| 1396 | + if (function_exists('mb_strpos')) { |
|
| 1397 | + return mb_strpos($haystack,$needle,$offset,$modx->config['modx_charset']); |
|
| 1398 | + } |
|
| 1156 | 1399 | return strpos($haystack,$needle,$offset); |
| 1157 | 1400 | } |
| 1158 | - public function strlen($str) { |
|
| 1401 | + public function strlen($str) |
|
| 1402 | + { |
|
| 1159 | 1403 | global $modx; |
| 1160 | - if (function_exists('mb_strlen')) return mb_strlen(str_replace("\r\n", "\n", $str),$modx->config['modx_charset']); |
|
| 1404 | + if (function_exists('mb_strlen')) { |
|
| 1405 | + return mb_strlen(str_replace("\r\n", "\n", $str),$modx->config['modx_charset']); |
|
| 1406 | + } |
|
| 1161 | 1407 | return strlen($str); |
| 1162 | 1408 | } |
| 1163 | - public function strtolower($str) { |
|
| 1164 | - if (function_exists('mb_strtolower')) return mb_strtolower($str); |
|
| 1409 | + public function strtolower($str) |
|
| 1410 | + { |
|
| 1411 | + if (function_exists('mb_strtolower')) { |
|
| 1412 | + return mb_strtolower($str); |
|
| 1413 | + } |
|
| 1165 | 1414 | return strtolower($str); |
| 1166 | 1415 | } |
| 1167 | - public function strtoupper($str) { |
|
| 1168 | - if (function_exists('mb_strtoupper')) return mb_strtoupper($str); |
|
| 1416 | + public function strtoupper($str) |
|
| 1417 | + { |
|
| 1418 | + if (function_exists('mb_strtoupper')) { |
|
| 1419 | + return mb_strtoupper($str); |
|
| 1420 | + } |
|
| 1169 | 1421 | return strtoupper($str); |
| 1170 | 1422 | } |
| 1171 | - public function ucfirst($str) { |
|
| 1172 | - if (function_exists('mb_strtoupper')) |
|
| 1173 | - return mb_strtoupper($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str)); |
|
| 1423 | + public function ucfirst($str) |
|
| 1424 | + { |
|
| 1425 | + if (function_exists('mb_strtoupper')) { |
|
| 1426 | + return mb_strtoupper($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str)); |
|
| 1427 | + } |
|
| 1174 | 1428 | return ucfirst($str); |
| 1175 | 1429 | } |
| 1176 | - public function lcfirst($str) { |
|
| 1177 | - if (function_exists('mb_strtolower')) |
|
| 1178 | - return mb_strtolower($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str)); |
|
| 1430 | + public function lcfirst($str) |
|
| 1431 | + { |
|
| 1432 | + if (function_exists('mb_strtolower')) { |
|
| 1433 | + return mb_strtolower($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str)); |
|
| 1434 | + } |
|
| 1179 | 1435 | return lcfirst($str); |
| 1180 | 1436 | } |
| 1181 | - public function ucwords($str) { |
|
| 1182 | - if (function_exists('mb_convert_case')) |
|
| 1183 | - return mb_convert_case($str, MB_CASE_TITLE); |
|
| 1437 | + public function ucwords($str) |
|
| 1438 | + { |
|
| 1439 | + if (function_exists('mb_convert_case')) { |
|
| 1440 | + return mb_convert_case($str, MB_CASE_TITLE); |
|
| 1441 | + } |
|
| 1184 | 1442 | return ucwords($str); |
| 1185 | 1443 | } |
| 1186 | - public function strrev($str) { |
|
| 1444 | + public function strrev($str) |
|
| 1445 | + { |
|
| 1187 | 1446 | preg_match_all('/./us', $str, $ar); |
| 1188 | 1447 | return implode(array_reverse($ar[0])); |
| 1189 | 1448 | } |
| 1190 | - public function str_shuffle($str) { |
|
| 1449 | + public function str_shuffle($str) |
|
| 1450 | + { |
|
| 1191 | 1451 | preg_match_all('/./us', $str, $ar); |
| 1192 | 1452 | shuffle($ar[0]); |
| 1193 | 1453 | return implode($ar[0]); |
| 1194 | 1454 | } |
| 1195 | - public function str_word_count($str) { |
|
| 1455 | + public function str_word_count($str) |
|
| 1456 | + { |
|
| 1196 | 1457 | return count(preg_split('~[^\p{L}\p{N}\']+~u',$str)); |
| 1197 | 1458 | } |
| 1198 | - public function strip_tags($value,$params='') { |
|
| 1459 | + public function strip_tags($value,$params='') |
|
| 1460 | + { |
|
| 1199 | 1461 | global $modx; |
| 1200 | 1462 | |
| 1201 | 1463 | if(stripos($params,'style')===false && stripos($value,'</style>')!==false) { |
@@ -149,7 +149,7 @@ |
||
| 149 | 149 | /** |
| 150 | 150 | * This function returns the current page number. |
| 151 | 151 | * |
| 152 | - * @return int |
|
| 152 | + * @return string |
|
| 153 | 153 | */ |
| 154 | 154 | public function getCurrentPage() |
| 155 | 155 | { |
@@ -16,7 +16,7 @@ |
||
| 16 | 16 | // sanitize array |
| 17 | 17 | if (!function_exists('modx_sanitize_gpc')) { |
| 18 | 18 | /** |
| 19 | - * @param array|string $values |
|
| 19 | + * @param string $values |
|
| 20 | 20 | * @param int $depth |
| 21 | 21 | * @return array|string |
| 22 | 22 | */ |