@@ -330,8 +330,8 @@ |
||
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | /** |
| 333 | - * @param $string |
|
| 334 | - * @return null |
|
| 333 | + * @param string $string |
|
| 334 | + * @return string|null |
|
| 335 | 335 | */ |
| 336 | 336 | protected static function getQuotedString($string) |
| 337 | 337 | { |
@@ -862,7 +862,7 @@ discard block |
||
| 862 | 862 | |
| 863 | 863 | // A reserved word cannot be preceded by a '.' |
| 864 | 864 | // this makes it so in "mytable.from", "from" is not considered a reserved word |
| 865 | - if (!$previous || !isset($previous[self::TOKEN_VALUE]) || $previous[self::TOKEN_VALUE] !== '.') { |
|
| 865 | + if ( ! $previous || ! isset($previous[self::TOKEN_VALUE]) || $previous[self::TOKEN_VALUE] !== '.') { |
|
| 866 | 866 | $upper = strtoupper($string); |
| 867 | 867 | // Top Level Reserved Word |
| 868 | 868 | if (preg_match('/^(' . self::$regex_reserved_toplevel . ')($|\s|' . self::$regex_boundaries . ')/', $upper, |
@@ -1118,7 +1118,7 @@ discard block |
||
| 1118 | 1118 | $length = 0; |
| 1119 | 1119 | for ($j = 1; $j <= 250; $j++) { |
| 1120 | 1120 | // Reached end of string |
| 1121 | - if (!isset($tokens[$i + $j])) { |
|
| 1121 | + if ( ! isset($tokens[$i + $j])) { |
|
| 1122 | 1122 | break; |
| 1123 | 1123 | } |
| 1124 | 1124 | |
@@ -1156,7 +1156,7 @@ discard block |
||
| 1156 | 1156 | $return = rtrim($return, ' '); |
| 1157 | 1157 | } |
| 1158 | 1158 | |
| 1159 | - if (!$inline_parentheses) { |
|
| 1159 | + if ( ! $inline_parentheses) { |
|
| 1160 | 1160 | $increase_block_indent = true; |
| 1161 | 1161 | // Add a newline after the parentheses |
| 1162 | 1162 | $newline = true; |
@@ -1189,7 +1189,7 @@ discard block |
||
| 1189 | 1189 | } |
| 1190 | 1190 | |
| 1191 | 1191 | // Add a newline before the closing parentheses (if not already added) |
| 1192 | - if (!$added_newline) { |
|
| 1192 | + if ( ! $added_newline) { |
|
| 1193 | 1193 | $return .= "\n" . str_repeat($tab, $indent_level); |
| 1194 | 1194 | } |
| 1195 | 1195 | } // Top level reserved words start a new line and increase the special indent level |
@@ -1206,7 +1206,7 @@ discard block |
||
| 1206 | 1206 | // Add a newline after the top level reserved word |
| 1207 | 1207 | $newline = true; |
| 1208 | 1208 | // Add a newline before the top level reserved word (if not already added) |
| 1209 | - if (!$added_newline) { |
|
| 1209 | + if ( ! $added_newline) { |
|
| 1210 | 1210 | $return .= "\n" . str_repeat($tab, $indent_level); |
| 1211 | 1211 | } // If we already added a newline, redo the indentation since it may be different now |
| 1212 | 1212 | else { |
@@ -1220,14 +1220,14 @@ discard block |
||
| 1220 | 1220 | $highlighted = preg_replace('/\s+/', ' ', $highlighted); |
| 1221 | 1221 | } |
| 1222 | 1222 | //if SQL 'LIMIT' clause, start variable to reset newline |
| 1223 | - if ($token[self::TOKEN_VALUE] === 'LIMIT' && !$inline_parentheses) { |
|
| 1223 | + if ($token[self::TOKEN_VALUE] === 'LIMIT' && ! $inline_parentheses) { |
|
| 1224 | 1224 | $clause_limit = true; |
| 1225 | 1225 | } |
| 1226 | 1226 | } // Checks if we are out of the limit clause |
| 1227 | 1227 | elseif ($clause_limit && $token[self::TOKEN_VALUE] !== "," && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_NUMBER && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) { |
| 1228 | 1228 | $clause_limit = false; |
| 1229 | 1229 | } // Commas start a new line (unless within inline parentheses or SQL 'LIMIT' clause) |
| 1230 | - elseif ($token[self::TOKEN_VALUE] === ',' && !$inline_parentheses) { |
|
| 1230 | + elseif ($token[self::TOKEN_VALUE] === ',' && ! $inline_parentheses) { |
|
| 1231 | 1231 | //If the previous TOKEN_VALUE is 'LIMIT', resets new line |
| 1232 | 1232 | if ($clause_limit === true) { |
| 1233 | 1233 | $newline = false; |
@@ -1239,7 +1239,7 @@ discard block |
||
| 1239 | 1239 | } // Newline reserved words start a new line |
| 1240 | 1240 | elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE) { |
| 1241 | 1241 | // Add a newline before the reserved word (if not already added) |
| 1242 | - if (!$added_newline) { |
|
| 1242 | + if ( ! $added_newline) { |
|
| 1243 | 1243 | $return .= "\n" . str_repeat($tab, $indent_level); |
| 1244 | 1244 | } |
| 1245 | 1245 | |
@@ -1333,7 +1333,7 @@ discard block |
||
| 1333 | 1333 | foreach ($tokens as $token) { |
| 1334 | 1334 | // If this is a query separator |
| 1335 | 1335 | if ($token[self::TOKEN_VALUE] === ';') { |
| 1336 | - if (!$empty) { |
|
| 1336 | + if ( ! $empty) { |
|
| 1337 | 1337 | $queries[] = $current_query . ';'; |
| 1338 | 1338 | } |
| 1339 | 1339 | $current_query = ''; |
@@ -1349,7 +1349,7 @@ discard block |
||
| 1349 | 1349 | $current_query .= $token[self::TOKEN_VALUE]; |
| 1350 | 1350 | } |
| 1351 | 1351 | |
| 1352 | - if (!$empty) { |
|
| 1352 | + if ( ! $empty) { |
|
| 1353 | 1353 | $queries[] = trim($current_query); |
| 1354 | 1354 | } |
| 1355 | 1355 | |
@@ -1643,7 +1643,7 @@ discard block |
||
| 1643 | 1643 | return $string . "\n"; |
| 1644 | 1644 | } else { |
| 1645 | 1645 | $string = trim($string); |
| 1646 | - if (!self::$use_pre) { |
|
| 1646 | + if ( ! self::$use_pre) { |
|
| 1647 | 1647 | return $string; |
| 1648 | 1648 | } |
| 1649 | 1649 | |
@@ -12,8 +12,8 @@ discard block |
||
| 12 | 12 | * @link http://github.com/jdorn/sql-formatter |
| 13 | 13 | * @version 1.2.18 |
| 14 | 14 | */ |
| 15 | -class SqlFormatter |
|
| 16 | -{ |
|
| 15 | +class SqlFormatter |
|
| 16 | +{
|
|
| 17 | 17 | // Constants for token types |
| 18 | 18 | const TOKEN_TYPE_WHITESPACE = 0; |
| 19 | 19 | const TOKEN_TYPE_WORD = 1; |
@@ -732,8 +732,8 @@ discard block |
||
| 732 | 732 | * Get stats about the token cache |
| 733 | 733 | * @return Array An array containing the keys 'hits', 'misses', 'entries', and 'size' in bytes |
| 734 | 734 | */ |
| 735 | - public static function getCacheStats() |
|
| 736 | - { |
|
| 735 | + public static function getCacheStats() |
|
| 736 | + {
|
|
| 737 | 737 | return array( |
| 738 | 738 | 'hits' => self::$cache_hits, |
| 739 | 739 | 'misses' => self::$cache_misses, |
@@ -745,9 +745,9 @@ discard block |
||
| 745 | 745 | /** |
| 746 | 746 | * Stuff that only needs to be done once. Builds regular expressions and sorts the reserved words. |
| 747 | 747 | */ |
| 748 | - protected static function init() |
|
| 749 | - { |
|
| 750 | - if (self::$init) { |
|
| 748 | + protected static function init() |
|
| 749 | + {
|
|
| 750 | + if (self::$init) {
|
|
| 751 | 751 | return; |
| 752 | 752 | } |
| 753 | 753 | |
@@ -779,10 +779,10 @@ discard block |
||
| 779 | 779 | * |
| 780 | 780 | * @return Array An associative array containing the type and value of the token. |
| 781 | 781 | */ |
| 782 | - protected static function getNextToken($string, $previous = null) |
|
| 783 | - { |
|
| 782 | + protected static function getNextToken($string, $previous = null) |
|
| 783 | + {
|
|
| 784 | 784 | // Whitespace |
| 785 | - if (preg_match('/^\s+/', $string, $matches)) { |
|
| 785 | + if (preg_match('/^\s+/', $string, $matches)) {
|
|
| 786 | 786 | return array( |
| 787 | 787 | self::TOKEN_VALUE => $matches[0], |
| 788 | 788 | self::TOKEN_TYPE => self::TOKEN_TYPE_WHITESPACE |
@@ -790,17 +790,18 @@ discard block |
||
| 790 | 790 | } |
| 791 | 791 | |
| 792 | 792 | // Comment |
| 793 | - if ($string[0] === '#' || (isset($string[1]) && ($string[0] === '-' && $string[1] === '-') || ($string[0] === '/' && $string[1] === '*'))) { |
|
| 793 | + if ($string[0] === '#' || (isset($string[1]) && ($string[0] === '-' && $string[1] === '-') || ($string[0] === '/' && $string[1] === '*'))) {
|
|
| 794 | 794 | // Comment until end of line |
| 795 | - if ($string[0] === '-' || $string[0] === '#') { |
|
| 795 | + if ($string[0] === '-' || $string[0] === '#') {
|
|
| 796 | 796 | $last = strpos($string, "\n"); |
| 797 | 797 | $type = self::TOKEN_TYPE_COMMENT; |
| 798 | - } else { // Comment until closing comment tag |
|
| 798 | + } else {
|
|
| 799 | +// Comment until closing comment tag |
|
| 799 | 800 | $last = strpos($string, "*/", 2) + 2; |
| 800 | 801 | $type = self::TOKEN_TYPE_BLOCK_COMMENT; |
| 801 | 802 | } |
| 802 | 803 | |
| 803 | - if ($last === false) { |
|
| 804 | + if ($last === false) {
|
|
| 804 | 805 | $last = strlen($string); |
| 805 | 806 | } |
| 806 | 807 | |
@@ -811,7 +812,7 @@ discard block |
||
| 811 | 812 | } |
| 812 | 813 | |
| 813 | 814 | // Quoted String |
| 814 | - if ($string[0] === '"' || $string[0] === '\'' || $string[0] === '`' || $string[0] === '[') { |
|
| 815 | + if ($string[0] === '"' || $string[0] === '\'' || $string[0] === '`' || $string[0] === '[') {
|
|
| 815 | 816 | $return = array( |
| 816 | 817 | self::TOKEN_TYPE => (($string[0] === '`' || $string[0] === '[') ? self::TOKEN_TYPE_BACKTICK_QUOTE : self::TOKEN_TYPE_QUOTE), |
| 817 | 818 | self::TOKEN_VALUE => self::getQuotedString($string) |
@@ -821,31 +822,31 @@ discard block |
||
| 821 | 822 | } |
| 822 | 823 | |
| 823 | 824 | // User-defined Variable |
| 824 | - if (($string[0] === '@' || $string[0] === ':') && isset($string[1])) { |
|
| 825 | + if (($string[0] === '@' || $string[0] === ':') && isset($string[1])) {
|
|
| 825 | 826 | $ret = array( |
| 826 | 827 | self::TOKEN_VALUE => null, |
| 827 | 828 | self::TOKEN_TYPE => self::TOKEN_TYPE_VARIABLE |
| 828 | 829 | ); |
| 829 | 830 | |
| 830 | 831 | // If the variable name is quoted |
| 831 | - if ($string[1] === '"' || $string[1] === '\'' || $string[1] === '`') { |
|
| 832 | + if ($string[1] === '"' || $string[1] === '\'' || $string[1] === '`') {
|
|
| 832 | 833 | $ret[self::TOKEN_VALUE] = $string[0] . self::getQuotedString(substr($string, 1)); |
| 833 | 834 | } // Non-quoted variable name |
| 834 | - else { |
|
| 835 | + else {
|
|
| 835 | 836 | preg_match('/^(' . $string[0] . '[a-zA-Z0-9\._\$]+)/', $string, $matches); |
| 836 | - if ($matches) { |
|
| 837 | + if ($matches) {
|
|
| 837 | 838 | $ret[self::TOKEN_VALUE] = $matches[1]; |
| 838 | 839 | } |
| 839 | 840 | } |
| 840 | 841 | |
| 841 | - if ($ret[self::TOKEN_VALUE] !== null) { |
|
| 842 | + if ($ret[self::TOKEN_VALUE] !== null) {
|
|
| 842 | 843 | return $ret; |
| 843 | 844 | } |
| 844 | 845 | } |
| 845 | 846 | |
| 846 | 847 | // Number (decimal, binary, or hex) |
| 847 | 848 | if (preg_match('/^([0-9]+(\.[0-9]+)?|0x[0-9a-fA-F]+|0b[01]+)($|\s|"\'`|' . self::$regex_boundaries . ')/', |
| 848 | - $string, $matches)) { |
|
| 849 | + $string, $matches)) {
|
|
| 849 | 850 | return array( |
| 850 | 851 | self::TOKEN_VALUE => $matches[1], |
| 851 | 852 | self::TOKEN_TYPE => self::TOKEN_TYPE_NUMBER |
@@ -853,7 +854,7 @@ discard block |
||
| 853 | 854 | } |
| 854 | 855 | |
| 855 | 856 | // Boundary Character (punctuation and symbols) |
| 856 | - if (preg_match('/^(' . self::$regex_boundaries . ')/', $string, $matches)) { |
|
| 857 | + if (preg_match('/^(' . self::$regex_boundaries . ')/', $string, $matches)) {
|
|
| 857 | 858 | return array( |
| 858 | 859 | self::TOKEN_VALUE => $matches[1], |
| 859 | 860 | self::TOKEN_TYPE => self::TOKEN_TYPE_BOUNDARY |
@@ -862,11 +863,11 @@ discard block |
||
| 862 | 863 | |
| 863 | 864 | // A reserved word cannot be preceded by a '.' |
| 864 | 865 | // this makes it so in "mytable.from", "from" is not considered a reserved word |
| 865 | - if (!$previous || !isset($previous[self::TOKEN_VALUE]) || $previous[self::TOKEN_VALUE] !== '.') { |
|
| 866 | + if (!$previous || !isset($previous[self::TOKEN_VALUE]) || $previous[self::TOKEN_VALUE] !== '.') {
|
|
| 866 | 867 | $upper = strtoupper($string); |
| 867 | 868 | // Top Level Reserved Word |
| 868 | 869 | if (preg_match('/^(' . self::$regex_reserved_toplevel . ')($|\s|' . self::$regex_boundaries . ')/', $upper, |
| 869 | - $matches)) { |
|
| 870 | + $matches)) {
|
|
| 870 | 871 | return array( |
| 871 | 872 | self::TOKEN_TYPE => self::TOKEN_TYPE_RESERVED_TOPLEVEL, |
| 872 | 873 | self::TOKEN_VALUE => substr($string, 0, strlen($matches[1])) |
@@ -874,7 +875,7 @@ discard block |
||
| 874 | 875 | } |
| 875 | 876 | // Newline Reserved Word |
| 876 | 877 | if (preg_match('/^(' . self::$regex_reserved_newline . ')($|\s|' . self::$regex_boundaries . ')/', $upper, |
| 877 | - $matches)) { |
|
| 878 | + $matches)) {
|
|
| 878 | 879 | return array( |
| 879 | 880 | self::TOKEN_TYPE => self::TOKEN_TYPE_RESERVED_NEWLINE, |
| 880 | 881 | self::TOKEN_VALUE => substr($string, 0, strlen($matches[1])) |
@@ -882,7 +883,7 @@ discard block |
||
| 882 | 883 | } |
| 883 | 884 | // Other Reserved Word |
| 884 | 885 | if (preg_match('/^(' . self::$regex_reserved . ')($|\s|' . self::$regex_boundaries . ')/', $upper, |
| 885 | - $matches)) { |
|
| 886 | + $matches)) {
|
|
| 886 | 887 | return array( |
| 887 | 888 | self::TOKEN_TYPE => self::TOKEN_TYPE_RESERVED, |
| 888 | 889 | self::TOKEN_VALUE => substr($string, 0, strlen($matches[1])) |
@@ -894,7 +895,7 @@ discard block |
||
| 894 | 895 | // this makes it so "count(" is considered a function, but "count" alone is not |
| 895 | 896 | $upper = strtoupper($string); |
| 896 | 897 | // function |
| 897 | - if (preg_match('/^(' . self::$regex_function . '[(]|\s|[)])/', $upper, $matches)) { |
|
| 898 | + if (preg_match('/^(' . self::$regex_function . '[(]|\s|[)])/', $upper, $matches)) {
|
|
| 898 | 899 | return array( |
| 899 | 900 | self::TOKEN_TYPE => self::TOKEN_TYPE_RESERVED, |
| 900 | 901 | self::TOKEN_VALUE => substr($string, 0, strlen($matches[1]) - 1) |
@@ -914,8 +915,8 @@ discard block |
||
| 914 | 915 | * @param $string |
| 915 | 916 | * @return null |
| 916 | 917 | */ |
| 917 | - protected static function getQuotedString($string) |
|
| 918 | - { |
|
| 918 | + protected static function getQuotedString($string) |
|
| 919 | + {
|
|
| 919 | 920 | $ret = null; |
| 920 | 921 | |
| 921 | 922 | // This checks for the following patterns: |
@@ -924,7 +925,7 @@ discard block |
||
| 924 | 925 | // 3. double quoted string using "" or \" to escape |
| 925 | 926 | // 4. single quoted string using '' or \' to escape |
| 926 | 927 | if (preg_match('/^(((`[^`]*($|`))+)|((\[[^\]]*($|\]))(\][^\]]*($|\]))*)|(("[^"\\\\]*(?:\\\\.[^"\\\\]*)*("|$))+)|((\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*(\'|$))+))/s', |
| 927 | - $string, $matches)) { |
|
| 928 | + $string, $matches)) {
|
|
| 928 | 929 | $ret = $matches[1]; |
| 929 | 930 | } |
| 930 | 931 | |
@@ -939,8 +940,8 @@ discard block |
||
| 939 | 940 | * |
| 940 | 941 | * @return Array An array of tokens. |
| 941 | 942 | */ |
| 942 | - protected static function tokenize($string) |
|
| 943 | - { |
|
| 943 | + protected static function tokenize($string) |
|
| 944 | + {
|
|
| 944 | 945 | self::init(); |
| 945 | 946 | |
| 946 | 947 | $tokens = array(); |
@@ -953,9 +954,9 @@ discard block |
||
| 953 | 954 | $current_length = strlen($string); |
| 954 | 955 | |
| 955 | 956 | // Keep processing the string until it is empty |
| 956 | - while ($current_length) { |
|
| 957 | + while ($current_length) {
|
|
| 957 | 958 | // If the string stopped shrinking, there was a problem |
| 958 | - if ($old_string_len <= $current_length) { |
|
| 959 | + if ($old_string_len <= $current_length) {
|
|
| 959 | 960 | $tokens[] = array( |
| 960 | 961 | self::TOKEN_VALUE => $string, |
| 961 | 962 | self::TOKEN_TYPE => self::TOKEN_TYPE_ERROR |
@@ -966,26 +967,26 @@ discard block |
||
| 966 | 967 | $old_string_len = $current_length; |
| 967 | 968 | |
| 968 | 969 | // Determine if we can use caching |
| 969 | - if ($current_length >= self::$max_cachekey_size) { |
|
| 970 | + if ($current_length >= self::$max_cachekey_size) {
|
|
| 970 | 971 | $cacheKey = substr($string, 0, self::$max_cachekey_size); |
| 971 | - } else { |
|
| 972 | + } else {
|
|
| 972 | 973 | $cacheKey = false; |
| 973 | 974 | } |
| 974 | 975 | |
| 975 | 976 | // See if the token is already cached |
| 976 | - if ($cacheKey && isset(self::$token_cache[$cacheKey])) { |
|
| 977 | + if ($cacheKey && isset(self::$token_cache[$cacheKey])) {
|
|
| 977 | 978 | // Retrieve from cache |
| 978 | 979 | $token = self::$token_cache[$cacheKey]; |
| 979 | 980 | $token_length = strlen($token[self::TOKEN_VALUE]); |
| 980 | 981 | self::$cache_hits++; |
| 981 | - } else { |
|
| 982 | + } else {
|
|
| 982 | 983 | // Get the next token and the token type |
| 983 | 984 | $token = self::getNextToken($string, $token); |
| 984 | 985 | $token_length = strlen($token[self::TOKEN_VALUE]); |
| 985 | 986 | self::$cache_misses++; |
| 986 | 987 | |
| 987 | 988 | // If the token is shorter than the max length, store it in cache |
| 988 | - if ($cacheKey && $token_length < self::$max_cachekey_size) { |
|
| 989 | + if ($cacheKey && $token_length < self::$max_cachekey_size) {
|
|
| 989 | 990 | self::$token_cache[$cacheKey] = $token; |
| 990 | 991 | } |
| 991 | 992 | } |
@@ -1009,8 +1010,8 @@ discard block |
||
| 1009 | 1010 | * |
| 1010 | 1011 | * @return String The SQL string with HTML styles and formatting wrapped in a <pre> tag |
| 1011 | 1012 | */ |
| 1012 | - public static function format($string, $highlight = true) |
|
| 1013 | - { |
|
| 1013 | + public static function format($string, $highlight = true) |
|
| 1014 | + {
|
|
| 1014 | 1015 | // This variable will be populated with formatted html |
| 1015 | 1016 | $return = ''; |
| 1016 | 1017 | |
@@ -1032,47 +1033,48 @@ discard block |
||
| 1032 | 1033 | |
| 1033 | 1034 | // Remove existing whitespace |
| 1034 | 1035 | $tokens = array(); |
| 1035 | - foreach ($original_tokens as $i => $token) { |
|
| 1036 | - if ($token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) { |
|
| 1036 | + foreach ($original_tokens as $i => $token) {
|
|
| 1037 | + if ($token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
|
|
| 1037 | 1038 | $token['i'] = $i; |
| 1038 | 1039 | $tokens[] = $token; |
| 1039 | 1040 | } |
| 1040 | 1041 | } |
| 1041 | 1042 | |
| 1042 | 1043 | // Format token by token |
| 1043 | - foreach ($tokens as $i => $token) { |
|
| 1044 | + foreach ($tokens as $i => $token) {
|
|
| 1044 | 1045 | // Get highlighted token if doing syntax highlighting |
| 1045 | - if ($highlight) { |
|
| 1046 | + if ($highlight) {
|
|
| 1046 | 1047 | $highlighted = self::highlightToken($token); |
| 1047 | - } else { // If returning raw text |
|
| 1048 | + } else {
|
|
| 1049 | +// If returning raw text |
|
| 1048 | 1050 | $highlighted = $token[self::TOKEN_VALUE]; |
| 1049 | 1051 | } |
| 1050 | 1052 | |
| 1051 | 1053 | // If we are increasing the special indent level now |
| 1052 | - if ($increase_special_indent) { |
|
| 1054 | + if ($increase_special_indent) {
|
|
| 1053 | 1055 | $indent_level++; |
| 1054 | 1056 | $increase_special_indent = false; |
| 1055 | 1057 | array_unshift($indent_types, 'special'); |
| 1056 | 1058 | } |
| 1057 | 1059 | // If we are increasing the block indent level now |
| 1058 | - if ($increase_block_indent) { |
|
| 1060 | + if ($increase_block_indent) {
|
|
| 1059 | 1061 | $indent_level++; |
| 1060 | 1062 | $increase_block_indent = false; |
| 1061 | 1063 | array_unshift($indent_types, 'block'); |
| 1062 | 1064 | } |
| 1063 | 1065 | |
| 1064 | 1066 | // If we need a new line before the token |
| 1065 | - if ($newline) { |
|
| 1067 | + if ($newline) {
|
|
| 1066 | 1068 | $return .= "\n" . str_repeat($tab, $indent_level); |
| 1067 | 1069 | $newline = false; |
| 1068 | 1070 | $added_newline = true; |
| 1069 | - } else { |
|
| 1071 | + } else {
|
|
| 1070 | 1072 | $added_newline = false; |
| 1071 | 1073 | } |
| 1072 | 1074 | |
| 1073 | 1075 | // Display comments directly where they appear in the source |
| 1074 | - if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) { |
|
| 1075 | - if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) { |
|
| 1076 | + if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
|
|
| 1077 | + if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
|
|
| 1076 | 1078 | $indent = str_repeat($tab, $indent_level); |
| 1077 | 1079 | $return .= "\n" . $indent; |
| 1078 | 1080 | $highlighted = str_replace("\n", "\n" . $indent, $highlighted); |
@@ -1083,12 +1085,12 @@ discard block |
||
| 1083 | 1085 | continue; |
| 1084 | 1086 | } |
| 1085 | 1087 | |
| 1086 | - if ($inline_parentheses) { |
|
| 1088 | + if ($inline_parentheses) {
|
|
| 1087 | 1089 | // End of inline parentheses |
| 1088 | - if ($token[self::TOKEN_VALUE] === ')') { |
|
| 1090 | + if ($token[self::TOKEN_VALUE] === ')') {
|
|
| 1089 | 1091 | $return = rtrim($return, ' '); |
| 1090 | 1092 | |
| 1091 | - if ($inline_indented) { |
|
| 1093 | + if ($inline_indented) {
|
|
| 1092 | 1094 | array_shift($indent_types); |
| 1093 | 1095 | $indent_level--; |
| 1094 | 1096 | $return .= "\n" . str_repeat($tab, $indent_level); |
@@ -1100,8 +1102,8 @@ discard block |
||
| 1100 | 1102 | continue; |
| 1101 | 1103 | } |
| 1102 | 1104 | |
| 1103 | - if ($token[self::TOKEN_VALUE] === ',') { |
|
| 1104 | - if ($inline_count >= 30) { |
|
| 1105 | + if ($token[self::TOKEN_VALUE] === ',') {
|
|
| 1106 | + if ($inline_count >= 30) {
|
|
| 1105 | 1107 | $inline_count = 0; |
| 1106 | 1108 | $newline = true; |
| 1107 | 1109 | } |
@@ -1111,21 +1113,21 @@ discard block |
||
| 1111 | 1113 | } |
| 1112 | 1114 | |
| 1113 | 1115 | // Opening parentheses increase the block indent level and start a new line |
| 1114 | - if ($token[self::TOKEN_VALUE] === '(') { |
|
| 1116 | + if ($token[self::TOKEN_VALUE] === '(') {
|
|
| 1115 | 1117 | // First check if this should be an inline parentheses block |
| 1116 | 1118 | // Examples are "NOW()", "COUNT(*)", "int(10)", key(`somecolumn`), DECIMAL(7,2) |
| 1117 | 1119 | // Allow up to 3 non-whitespace tokens inside inline parentheses |
| 1118 | 1120 | $length = 0; |
| 1119 | - for ($j = 1; $j <= 250; $j++) { |
|
| 1121 | + for ($j = 1; $j <= 250; $j++) {
|
|
| 1120 | 1122 | // Reached end of string |
| 1121 | - if (!isset($tokens[$i + $j])) { |
|
| 1123 | + if (!isset($tokens[$i + $j])) {
|
|
| 1122 | 1124 | break; |
| 1123 | 1125 | } |
| 1124 | 1126 | |
| 1125 | 1127 | $next = $tokens[$i + $j]; |
| 1126 | 1128 | |
| 1127 | 1129 | // Reached closing parentheses, able to inline it |
| 1128 | - if ($next[self::TOKEN_VALUE] === ')') { |
|
| 1130 | + if ($next[self::TOKEN_VALUE] === ')') {
|
|
| 1129 | 1131 | $inline_parentheses = true; |
| 1130 | 1132 | $inline_count = 0; |
| 1131 | 1133 | $inline_indented = false; |
@@ -1133,72 +1135,72 @@ discard block |
||
| 1133 | 1135 | } |
| 1134 | 1136 | |
| 1135 | 1137 | // Reached an invalid token for inline parentheses |
| 1136 | - if ($next[self::TOKEN_VALUE] === ';' || $next[self::TOKEN_VALUE] === '(') { |
|
| 1138 | + if ($next[self::TOKEN_VALUE] === ';' || $next[self::TOKEN_VALUE] === '(') {
|
|
| 1137 | 1139 | break; |
| 1138 | 1140 | } |
| 1139 | 1141 | |
| 1140 | 1142 | // Reached an invalid token type for inline parentheses |
| 1141 | - if ($next[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_TOPLEVEL || $next[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE || $next[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $next[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) { |
|
| 1143 | + if ($next[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_TOPLEVEL || $next[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE || $next[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $next[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
|
|
| 1142 | 1144 | break; |
| 1143 | 1145 | } |
| 1144 | 1146 | |
| 1145 | 1147 | $length += strlen($next[self::TOKEN_VALUE]); |
| 1146 | 1148 | } |
| 1147 | 1149 | |
| 1148 | - if ($inline_parentheses && $length > 30) { |
|
| 1150 | + if ($inline_parentheses && $length > 30) {
|
|
| 1149 | 1151 | $increase_block_indent = true; |
| 1150 | 1152 | $inline_indented = true; |
| 1151 | 1153 | $newline = true; |
| 1152 | 1154 | } |
| 1153 | 1155 | |
| 1154 | 1156 | // Take out the preceding space unless there was whitespace there in the original query |
| 1155 | - if (isset($original_tokens[$token['i'] - 1]) && $original_tokens[$token['i'] - 1][self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) { |
|
| 1157 | + if (isset($original_tokens[$token['i'] - 1]) && $original_tokens[$token['i'] - 1][self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
|
|
| 1156 | 1158 | $return = rtrim($return, ' '); |
| 1157 | 1159 | } |
| 1158 | 1160 | |
| 1159 | - if (!$inline_parentheses) { |
|
| 1161 | + if (!$inline_parentheses) {
|
|
| 1160 | 1162 | $increase_block_indent = true; |
| 1161 | 1163 | // Add a newline after the parentheses |
| 1162 | 1164 | $newline = true; |
| 1163 | 1165 | } |
| 1164 | 1166 | |
| 1165 | 1167 | } // Closing parentheses decrease the block indent level |
| 1166 | - elseif ($token[self::TOKEN_VALUE] === ')') { |
|
| 1168 | + elseif ($token[self::TOKEN_VALUE] === ')') {
|
|
| 1167 | 1169 | // Remove whitespace before the closing parentheses |
| 1168 | 1170 | $return = rtrim($return, ' '); |
| 1169 | 1171 | |
| 1170 | 1172 | $indent_level--; |
| 1171 | 1173 | |
| 1172 | 1174 | // Reset indent level |
| 1173 | - while ($j = array_shift($indent_types)) { |
|
| 1174 | - if ($j === 'special') { |
|
| 1175 | + while ($j = array_shift($indent_types)) {
|
|
| 1176 | + if ($j === 'special') {
|
|
| 1175 | 1177 | $indent_level--; |
| 1176 | - } else { |
|
| 1178 | + } else {
|
|
| 1177 | 1179 | break; |
| 1178 | 1180 | } |
| 1179 | 1181 | } |
| 1180 | 1182 | |
| 1181 | - if ($indent_level < 0) { |
|
| 1183 | + if ($indent_level < 0) {
|
|
| 1182 | 1184 | // This is an error |
| 1183 | 1185 | $indent_level = 0; |
| 1184 | 1186 | |
| 1185 | - if ($highlight) { |
|
| 1187 | + if ($highlight) {
|
|
| 1186 | 1188 | $return .= "\n" . self::highlightError($token[self::TOKEN_VALUE]); |
| 1187 | 1189 | continue; |
| 1188 | 1190 | } |
| 1189 | 1191 | } |
| 1190 | 1192 | |
| 1191 | 1193 | // Add a newline before the closing parentheses (if not already added) |
| 1192 | - if (!$added_newline) { |
|
| 1194 | + if (!$added_newline) {
|
|
| 1193 | 1195 | $return .= "\n" . str_repeat($tab, $indent_level); |
| 1194 | 1196 | } |
| 1195 | 1197 | } // Top level reserved words start a new line and increase the special indent level |
| 1196 | - elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_TOPLEVEL) { |
|
| 1198 | + elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_TOPLEVEL) {
|
|
| 1197 | 1199 | $increase_special_indent = true; |
| 1198 | 1200 | |
| 1199 | 1201 | // If the last indent type was 'special', decrease the special indent for this round |
| 1200 | 1202 | reset($indent_types); |
| 1201 | - if (current($indent_types) === 'special') { |
|
| 1203 | + if (current($indent_types) === 'special') {
|
|
| 1202 | 1204 | $indent_level--; |
| 1203 | 1205 | array_shift($indent_types); |
| 1204 | 1206 | } |
@@ -1206,88 +1208,88 @@ discard block |
||
| 1206 | 1208 | // Add a newline after the top level reserved word |
| 1207 | 1209 | $newline = true; |
| 1208 | 1210 | // Add a newline before the top level reserved word (if not already added) |
| 1209 | - if (!$added_newline) { |
|
| 1211 | + if (!$added_newline) {
|
|
| 1210 | 1212 | $return .= "\n" . str_repeat($tab, $indent_level); |
| 1211 | 1213 | } // If we already added a newline, redo the indentation since it may be different now |
| 1212 | - else { |
|
| 1214 | + else {
|
|
| 1213 | 1215 | $return = rtrim($return, $tab) . str_repeat($tab, $indent_level); |
| 1214 | 1216 | } |
| 1215 | 1217 | |
| 1216 | 1218 | // If the token may have extra whitespace |
| 1217 | 1219 | if (strpos($token[self::TOKEN_VALUE], ' ') !== false || strpos($token[self::TOKEN_VALUE], |
| 1218 | 1220 | "\n") !== false || strpos($token[self::TOKEN_VALUE], "\t") !== false |
| 1219 | - ) { |
|
| 1221 | + ) {
|
|
| 1220 | 1222 | $highlighted = preg_replace('/\s+/', ' ', $highlighted); |
| 1221 | 1223 | } |
| 1222 | 1224 | //if SQL 'LIMIT' clause, start variable to reset newline |
| 1223 | - if ($token[self::TOKEN_VALUE] === 'LIMIT' && !$inline_parentheses) { |
|
| 1225 | + if ($token[self::TOKEN_VALUE] === 'LIMIT' && !$inline_parentheses) {
|
|
| 1224 | 1226 | $clause_limit = true; |
| 1225 | 1227 | } |
| 1226 | 1228 | } // Checks if we are out of the limit clause |
| 1227 | - elseif ($clause_limit && $token[self::TOKEN_VALUE] !== "," && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_NUMBER && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) { |
|
| 1229 | + elseif ($clause_limit && $token[self::TOKEN_VALUE] !== "," && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_NUMBER && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
|
|
| 1228 | 1230 | $clause_limit = false; |
| 1229 | 1231 | } // Commas start a new line (unless within inline parentheses or SQL 'LIMIT' clause) |
| 1230 | - elseif ($token[self::TOKEN_VALUE] === ',' && !$inline_parentheses) { |
|
| 1232 | + elseif ($token[self::TOKEN_VALUE] === ',' && !$inline_parentheses) {
|
|
| 1231 | 1233 | //If the previous TOKEN_VALUE is 'LIMIT', resets new line |
| 1232 | - if ($clause_limit === true) { |
|
| 1234 | + if ($clause_limit === true) {
|
|
| 1233 | 1235 | $newline = false; |
| 1234 | 1236 | $clause_limit = false; |
| 1235 | 1237 | } // All other cases of commas |
| 1236 | - else { |
|
| 1238 | + else {
|
|
| 1237 | 1239 | $newline = true; |
| 1238 | 1240 | } |
| 1239 | 1241 | } // Newline reserved words start a new line |
| 1240 | - elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE) { |
|
| 1242 | + elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE) {
|
|
| 1241 | 1243 | // Add a newline before the reserved word (if not already added) |
| 1242 | - if (!$added_newline) { |
|
| 1244 | + if (!$added_newline) {
|
|
| 1243 | 1245 | $return .= "\n" . str_repeat($tab, $indent_level); |
| 1244 | 1246 | } |
| 1245 | 1247 | |
| 1246 | 1248 | // If the token may have extra whitespace |
| 1247 | 1249 | if (strpos($token[self::TOKEN_VALUE], ' ') !== false || strpos($token[self::TOKEN_VALUE], |
| 1248 | 1250 | "\n") !== false || strpos($token[self::TOKEN_VALUE], "\t") !== false |
| 1249 | - ) { |
|
| 1251 | + ) {
|
|
| 1250 | 1252 | $highlighted = preg_replace('/\s+/', ' ', $highlighted); |
| 1251 | 1253 | } |
| 1252 | 1254 | } // Multiple boundary characters in a row should not have spaces between them (not including parentheses) |
| 1253 | - elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BOUNDARY) { |
|
| 1254 | - if (isset($tokens[$i - 1]) && $tokens[$i - 1][self::TOKEN_TYPE] === self::TOKEN_TYPE_BOUNDARY) { |
|
| 1255 | - if (isset($original_tokens[$token['i'] - 1]) && $original_tokens[$token['i'] - 1][self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) { |
|
| 1255 | + elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BOUNDARY) {
|
|
| 1256 | + if (isset($tokens[$i - 1]) && $tokens[$i - 1][self::TOKEN_TYPE] === self::TOKEN_TYPE_BOUNDARY) {
|
|
| 1257 | + if (isset($original_tokens[$token['i'] - 1]) && $original_tokens[$token['i'] - 1][self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
|
|
| 1256 | 1258 | $return = rtrim($return, ' '); |
| 1257 | 1259 | } |
| 1258 | 1260 | } |
| 1259 | 1261 | } |
| 1260 | 1262 | |
| 1261 | 1263 | // If the token shouldn't have a space before it |
| 1262 | - if ($token[self::TOKEN_VALUE] === '.' || $token[self::TOKEN_VALUE] === ',' || $token[self::TOKEN_VALUE] === ';') { |
|
| 1264 | + if ($token[self::TOKEN_VALUE] === '.' || $token[self::TOKEN_VALUE] === ',' || $token[self::TOKEN_VALUE] === ';') {
|
|
| 1263 | 1265 | $return = rtrim($return, ' '); |
| 1264 | 1266 | } |
| 1265 | 1267 | |
| 1266 | 1268 | $return .= $highlighted . ' '; |
| 1267 | 1269 | |
| 1268 | 1270 | // If the token shouldn't have a space after it |
| 1269 | - if ($token[self::TOKEN_VALUE] === '(' || $token[self::TOKEN_VALUE] === '.') { |
|
| 1271 | + if ($token[self::TOKEN_VALUE] === '(' || $token[self::TOKEN_VALUE] === '.') {
|
|
| 1270 | 1272 | $return = rtrim($return, ' '); |
| 1271 | 1273 | } |
| 1272 | 1274 | |
| 1273 | 1275 | // If this is the "-" of a negative number, it shouldn't have a space after it |
| 1274 | - if ($token[self::TOKEN_VALUE] === '-' && isset($tokens[$i + 1]) && $tokens[$i + 1][self::TOKEN_TYPE] === self::TOKEN_TYPE_NUMBER && isset($tokens[$i - 1])) { |
|
| 1276 | + if ($token[self::TOKEN_VALUE] === '-' && isset($tokens[$i + 1]) && $tokens[$i + 1][self::TOKEN_TYPE] === self::TOKEN_TYPE_NUMBER && isset($tokens[$i - 1])) {
|
|
| 1275 | 1277 | $prev = $tokens[$i - 1][self::TOKEN_TYPE]; |
| 1276 | - if ($prev !== self::TOKEN_TYPE_QUOTE && $prev !== self::TOKEN_TYPE_BACKTICK_QUOTE && $prev !== self::TOKEN_TYPE_WORD && $prev !== self::TOKEN_TYPE_NUMBER) { |
|
| 1278 | + if ($prev !== self::TOKEN_TYPE_QUOTE && $prev !== self::TOKEN_TYPE_BACKTICK_QUOTE && $prev !== self::TOKEN_TYPE_WORD && $prev !== self::TOKEN_TYPE_NUMBER) {
|
|
| 1277 | 1279 | $return = rtrim($return, ' '); |
| 1278 | 1280 | } |
| 1279 | 1281 | } |
| 1280 | 1282 | } |
| 1281 | 1283 | |
| 1282 | 1284 | // If there are unmatched parentheses |
| 1283 | - if ($highlight && array_search('block', $indent_types) !== false) { |
|
| 1285 | + if ($highlight && array_search('block', $indent_types) !== false) {
|
|
| 1284 | 1286 | $return .= "\n" . self::highlightError("WARNING: unclosed parentheses or section"); |
| 1285 | 1287 | } |
| 1286 | 1288 | |
| 1287 | 1289 | // Replace tab characters with the configuration tab character |
| 1288 | 1290 | $return = trim(str_replace("\t", self::$tab, $return)); |
| 1289 | 1291 | |
| 1290 | - if ($highlight) { |
|
| 1292 | + if ($highlight) {
|
|
| 1291 | 1293 | $return = self::output($return); |
| 1292 | 1294 | } |
| 1293 | 1295 | |
@@ -1301,13 +1303,13 @@ discard block |
||
| 1301 | 1303 | * |
| 1302 | 1304 | * @return String The SQL string with HTML styles applied |
| 1303 | 1305 | */ |
| 1304 | - public static function highlight($string) |
|
| 1305 | - { |
|
| 1306 | + public static function highlight($string) |
|
| 1307 | + {
|
|
| 1306 | 1308 | $tokens = self::tokenize($string); |
| 1307 | 1309 | |
| 1308 | 1310 | $return = ''; |
| 1309 | 1311 | |
| 1310 | - foreach ($tokens as $token) { |
|
| 1312 | + foreach ($tokens as $token) {
|
|
| 1311 | 1313 | $return .= self::highlightToken($token); |
| 1312 | 1314 | } |
| 1313 | 1315 | |
@@ -1322,18 +1324,18 @@ discard block |
||
| 1322 | 1324 | * |
| 1323 | 1325 | * @return Array An array of individual query strings without trailing semicolons |
| 1324 | 1326 | */ |
| 1325 | - public static function splitQuery($string) |
|
| 1326 | - { |
|
| 1327 | + public static function splitQuery($string) |
|
| 1328 | + {
|
|
| 1327 | 1329 | $queries = array(); |
| 1328 | 1330 | $current_query = ''; |
| 1329 | 1331 | $empty = true; |
| 1330 | 1332 | |
| 1331 | 1333 | $tokens = self::tokenize($string); |
| 1332 | 1334 | |
| 1333 | - foreach ($tokens as $token) { |
|
| 1335 | + foreach ($tokens as $token) {
|
|
| 1334 | 1336 | // If this is a query separator |
| 1335 | - if ($token[self::TOKEN_VALUE] === ';') { |
|
| 1336 | - if (!$empty) { |
|
| 1337 | + if ($token[self::TOKEN_VALUE] === ';') {
|
|
| 1338 | + if (!$empty) {
|
|
| 1337 | 1339 | $queries[] = $current_query . ';'; |
| 1338 | 1340 | } |
| 1339 | 1341 | $current_query = ''; |
@@ -1342,14 +1344,14 @@ discard block |
||
| 1342 | 1344 | } |
| 1343 | 1345 | |
| 1344 | 1346 | // If this is a non-empty character |
| 1345 | - if ($token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_COMMENT && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_BLOCK_COMMENT) { |
|
| 1347 | + if ($token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_COMMENT && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_BLOCK_COMMENT) {
|
|
| 1346 | 1348 | $empty = false; |
| 1347 | 1349 | } |
| 1348 | 1350 | |
| 1349 | 1351 | $current_query .= $token[self::TOKEN_VALUE]; |
| 1350 | 1352 | } |
| 1351 | 1353 | |
| 1352 | - if (!$empty) { |
|
| 1354 | + if (!$empty) {
|
|
| 1353 | 1355 | $queries[] = trim($current_query); |
| 1354 | 1356 | } |
| 1355 | 1357 | |
@@ -1363,15 +1365,15 @@ discard block |
||
| 1363 | 1365 | * |
| 1364 | 1366 | * @return String The SQL string without comments |
| 1365 | 1367 | */ |
| 1366 | - public static function removeComments($string) |
|
| 1367 | - { |
|
| 1368 | + public static function removeComments($string) |
|
| 1369 | + {
|
|
| 1368 | 1370 | $result = ''; |
| 1369 | 1371 | |
| 1370 | 1372 | $tokens = self::tokenize($string); |
| 1371 | 1373 | |
| 1372 | - foreach ($tokens as $token) { |
|
| 1374 | + foreach ($tokens as $token) {
|
|
| 1373 | 1375 | // Skip comment tokens |
| 1374 | - if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) { |
|
| 1376 | + if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
|
|
| 1375 | 1377 | continue; |
| 1376 | 1378 | } |
| 1377 | 1379 | |
@@ -1389,32 +1391,32 @@ discard block |
||
| 1389 | 1391 | * |
| 1390 | 1392 | * @return String The SQL string without comments |
| 1391 | 1393 | */ |
| 1392 | - public static function compress($string) |
|
| 1393 | - { |
|
| 1394 | + public static function compress($string) |
|
| 1395 | + {
|
|
| 1394 | 1396 | $result = ''; |
| 1395 | 1397 | |
| 1396 | 1398 | $tokens = self::tokenize($string); |
| 1397 | 1399 | |
| 1398 | 1400 | $whitespace = true; |
| 1399 | - foreach ($tokens as $token) { |
|
| 1401 | + foreach ($tokens as $token) {
|
|
| 1400 | 1402 | // Skip comment tokens |
| 1401 | - if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) { |
|
| 1403 | + if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
|
|
| 1402 | 1404 | continue; |
| 1403 | 1405 | } // Remove extra whitespace in reserved words (e.g "OUTER JOIN" becomes "OUTER JOIN") |
| 1404 | - elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_TOPLEVEL) { |
|
| 1406 | + elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_TOPLEVEL) {
|
|
| 1405 | 1407 | $token[self::TOKEN_VALUE] = preg_replace('/\s+/', ' ', $token[self::TOKEN_VALUE]); |
| 1406 | 1408 | } |
| 1407 | 1409 | |
| 1408 | - if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_WHITESPACE) { |
|
| 1410 | + if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_WHITESPACE) {
|
|
| 1409 | 1411 | // If the last token was whitespace, don't add another one |
| 1410 | - if ($whitespace) { |
|
| 1412 | + if ($whitespace) {
|
|
| 1411 | 1413 | continue; |
| 1412 | - } else { |
|
| 1414 | + } else {
|
|
| 1413 | 1415 | $whitespace = true; |
| 1414 | 1416 | // Convert all whitespace to a single space |
| 1415 | 1417 | $token[self::TOKEN_VALUE] = ' '; |
| 1416 | 1418 | } |
| 1417 | - } else { |
|
| 1419 | + } else {
|
|
| 1418 | 1420 | $whitespace = false; |
| 1419 | 1421 | } |
| 1420 | 1422 | |
@@ -1431,39 +1433,39 @@ discard block |
||
| 1431 | 1433 | * |
| 1432 | 1434 | * @return String HTML code of the highlighted token. |
| 1433 | 1435 | */ |
| 1434 | - protected static function highlightToken($token) |
|
| 1435 | - { |
|
| 1436 | + protected static function highlightToken($token) |
|
| 1437 | + {
|
|
| 1436 | 1438 | $type = $token[self::TOKEN_TYPE]; |
| 1437 | 1439 | |
| 1438 | - if (self::is_cli()) { |
|
| 1440 | + if (self::is_cli()) {
|
|
| 1439 | 1441 | $token = $token[self::TOKEN_VALUE]; |
| 1440 | - } else { |
|
| 1441 | - if (defined('ENT_IGNORE')) { |
|
| 1442 | + } else {
|
|
| 1443 | + if (defined('ENT_IGNORE')) {
|
|
| 1442 | 1444 | $token = htmlentities($token[self::TOKEN_VALUE], ENT_COMPAT | ENT_IGNORE, 'UTF-8'); |
| 1443 | - } else { |
|
| 1445 | + } else {
|
|
| 1444 | 1446 | $token = htmlentities($token[self::TOKEN_VALUE], ENT_COMPAT, 'UTF-8'); |
| 1445 | 1447 | } |
| 1446 | 1448 | } |
| 1447 | 1449 | |
| 1448 | - if ($type === self::TOKEN_TYPE_BOUNDARY) { |
|
| 1450 | + if ($type === self::TOKEN_TYPE_BOUNDARY) {
|
|
| 1449 | 1451 | return self::highlightBoundary($token); |
| 1450 | - } elseif ($type === self::TOKEN_TYPE_WORD) { |
|
| 1452 | + } elseif ($type === self::TOKEN_TYPE_WORD) {
|
|
| 1451 | 1453 | return self::highlightWord($token); |
| 1452 | - } elseif ($type === self::TOKEN_TYPE_BACKTICK_QUOTE) { |
|
| 1454 | + } elseif ($type === self::TOKEN_TYPE_BACKTICK_QUOTE) {
|
|
| 1453 | 1455 | return self::highlightBacktickQuote($token); |
| 1454 | - } elseif ($type === self::TOKEN_TYPE_QUOTE) { |
|
| 1456 | + } elseif ($type === self::TOKEN_TYPE_QUOTE) {
|
|
| 1455 | 1457 | return self::highlightQuote($token); |
| 1456 | - } elseif ($type === self::TOKEN_TYPE_RESERVED) { |
|
| 1458 | + } elseif ($type === self::TOKEN_TYPE_RESERVED) {
|
|
| 1457 | 1459 | return self::highlightReservedWord($token); |
| 1458 | - } elseif ($type === self::TOKEN_TYPE_RESERVED_TOPLEVEL) { |
|
| 1460 | + } elseif ($type === self::TOKEN_TYPE_RESERVED_TOPLEVEL) {
|
|
| 1459 | 1461 | return self::highlightReservedWord($token); |
| 1460 | - } elseif ($type === self::TOKEN_TYPE_RESERVED_NEWLINE) { |
|
| 1462 | + } elseif ($type === self::TOKEN_TYPE_RESERVED_NEWLINE) {
|
|
| 1461 | 1463 | return self::highlightReservedWord($token); |
| 1462 | - } elseif ($type === self::TOKEN_TYPE_NUMBER) { |
|
| 1464 | + } elseif ($type === self::TOKEN_TYPE_NUMBER) {
|
|
| 1463 | 1465 | return self::highlightNumber($token); |
| 1464 | - } elseif ($type === self::TOKEN_TYPE_VARIABLE) { |
|
| 1466 | + } elseif ($type === self::TOKEN_TYPE_VARIABLE) {
|
|
| 1465 | 1467 | return self::highlightVariable($token); |
| 1466 | - } elseif ($type === self::TOKEN_TYPE_COMMENT || $type === self::TOKEN_TYPE_BLOCK_COMMENT) { |
|
| 1468 | + } elseif ($type === self::TOKEN_TYPE_COMMENT || $type === self::TOKEN_TYPE_BLOCK_COMMENT) {
|
|
| 1467 | 1469 | return self::highlightComment($token); |
| 1468 | 1470 | } |
| 1469 | 1471 | |
@@ -1477,11 +1479,11 @@ discard block |
||
| 1477 | 1479 | * |
| 1478 | 1480 | * @return String HTML code of the highlighted token. |
| 1479 | 1481 | */ |
| 1480 | - protected static function highlightQuote($value) |
|
| 1481 | - { |
|
| 1482 | - if (self::is_cli()) { |
|
| 1482 | + protected static function highlightQuote($value) |
|
| 1483 | + {
|
|
| 1484 | + if (self::is_cli()) {
|
|
| 1483 | 1485 | return self::$cli_quote . $value . "\x1b[0m"; |
| 1484 | - } else { |
|
| 1486 | + } else {
|
|
| 1485 | 1487 | return '<span ' . self::$quote_attributes . '>' . $value . '</span>'; |
| 1486 | 1488 | } |
| 1487 | 1489 | } |
@@ -1493,11 +1495,11 @@ discard block |
||
| 1493 | 1495 | * |
| 1494 | 1496 | * @return String HTML code of the highlighted token. |
| 1495 | 1497 | */ |
| 1496 | - protected static function highlightBacktickQuote($value) |
|
| 1497 | - { |
|
| 1498 | - if (self::is_cli()) { |
|
| 1498 | + protected static function highlightBacktickQuote($value) |
|
| 1499 | + {
|
|
| 1500 | + if (self::is_cli()) {
|
|
| 1499 | 1501 | return self::$cli_backtick_quote . $value . "\x1b[0m"; |
| 1500 | - } else { |
|
| 1502 | + } else {
|
|
| 1501 | 1503 | return '<span ' . self::$backtick_quote_attributes . '>' . $value . '</span>'; |
| 1502 | 1504 | } |
| 1503 | 1505 | } |
@@ -1509,11 +1511,11 @@ discard block |
||
| 1509 | 1511 | * |
| 1510 | 1512 | * @return String HTML code of the highlighted token. |
| 1511 | 1513 | */ |
| 1512 | - protected static function highlightReservedWord($value) |
|
| 1513 | - { |
|
| 1514 | - if (self::is_cli()) { |
|
| 1514 | + protected static function highlightReservedWord($value) |
|
| 1515 | + {
|
|
| 1516 | + if (self::is_cli()) {
|
|
| 1515 | 1517 | return self::$cli_reserved . $value . "\x1b[0m"; |
| 1516 | - } else { |
|
| 1518 | + } else {
|
|
| 1517 | 1519 | return '<span ' . self::$reserved_attributes . '>' . $value . '</span>'; |
| 1518 | 1520 | } |
| 1519 | 1521 | } |
@@ -1525,15 +1527,15 @@ discard block |
||
| 1525 | 1527 | * |
| 1526 | 1528 | * @return String HTML code of the highlighted token. |
| 1527 | 1529 | */ |
| 1528 | - protected static function highlightBoundary($value) |
|
| 1529 | - { |
|
| 1530 | - if ($value === '(' || $value === ')') { |
|
| 1530 | + protected static function highlightBoundary($value) |
|
| 1531 | + {
|
|
| 1532 | + if ($value === '(' || $value === ')') {
|
|
| 1531 | 1533 | return $value; |
| 1532 | 1534 | } |
| 1533 | 1535 | |
| 1534 | - if (self::is_cli()) { |
|
| 1536 | + if (self::is_cli()) {
|
|
| 1535 | 1537 | return self::$cli_boundary . $value . "\x1b[0m"; |
| 1536 | - } else { |
|
| 1538 | + } else {
|
|
| 1537 | 1539 | return '<span ' . self::$boundary_attributes . '>' . $value . '</span>'; |
| 1538 | 1540 | } |
| 1539 | 1541 | } |
@@ -1545,11 +1547,11 @@ discard block |
||
| 1545 | 1547 | * |
| 1546 | 1548 | * @return String HTML code of the highlighted token. |
| 1547 | 1549 | */ |
| 1548 | - protected static function highlightNumber($value) |
|
| 1549 | - { |
|
| 1550 | - if (self::is_cli()) { |
|
| 1550 | + protected static function highlightNumber($value) |
|
| 1551 | + {
|
|
| 1552 | + if (self::is_cli()) {
|
|
| 1551 | 1553 | return self::$cli_number . $value . "\x1b[0m"; |
| 1552 | - } else { |
|
| 1554 | + } else {
|
|
| 1553 | 1555 | return '<span ' . self::$number_attributes . '>' . $value . '</span>'; |
| 1554 | 1556 | } |
| 1555 | 1557 | } |
@@ -1561,11 +1563,11 @@ discard block |
||
| 1561 | 1563 | * |
| 1562 | 1564 | * @return String HTML code of the highlighted token. |
| 1563 | 1565 | */ |
| 1564 | - protected static function highlightError($value) |
|
| 1565 | - { |
|
| 1566 | - if (self::is_cli()) { |
|
| 1566 | + protected static function highlightError($value) |
|
| 1567 | + {
|
|
| 1568 | + if (self::is_cli()) {
|
|
| 1567 | 1569 | return self::$cli_error . $value . "\x1b[0m"; |
| 1568 | - } else { |
|
| 1570 | + } else {
|
|
| 1569 | 1571 | return '<span ' . self::$error_attributes . '>' . $value . '</span>'; |
| 1570 | 1572 | } |
| 1571 | 1573 | } |
@@ -1577,11 +1579,11 @@ discard block |
||
| 1577 | 1579 | * |
| 1578 | 1580 | * @return String HTML code of the highlighted token. |
| 1579 | 1581 | */ |
| 1580 | - protected static function highlightComment($value) |
|
| 1581 | - { |
|
| 1582 | - if (self::is_cli()) { |
|
| 1582 | + protected static function highlightComment($value) |
|
| 1583 | + {
|
|
| 1584 | + if (self::is_cli()) {
|
|
| 1583 | 1585 | return self::$cli_comment . $value . "\x1b[0m"; |
| 1584 | - } else { |
|
| 1586 | + } else {
|
|
| 1585 | 1587 | return '<span ' . self::$comment_attributes . '>' . $value . '</span>'; |
| 1586 | 1588 | } |
| 1587 | 1589 | } |
@@ -1593,11 +1595,11 @@ discard block |
||
| 1593 | 1595 | * |
| 1594 | 1596 | * @return String HTML code of the highlighted token. |
| 1595 | 1597 | */ |
| 1596 | - protected static function highlightWord($value) |
|
| 1597 | - { |
|
| 1598 | - if (self::is_cli()) { |
|
| 1598 | + protected static function highlightWord($value) |
|
| 1599 | + {
|
|
| 1600 | + if (self::is_cli()) {
|
|
| 1599 | 1601 | return self::$cli_word . $value . "\x1b[0m"; |
| 1600 | - } else { |
|
| 1602 | + } else {
|
|
| 1601 | 1603 | return '<span ' . self::$word_attributes . '>' . $value . '</span>'; |
| 1602 | 1604 | } |
| 1603 | 1605 | } |
@@ -1609,11 +1611,11 @@ discard block |
||
| 1609 | 1611 | * |
| 1610 | 1612 | * @return String HTML code of the highlighted token. |
| 1611 | 1613 | */ |
| 1612 | - protected static function highlightVariable($value) |
|
| 1613 | - { |
|
| 1614 | - if (self::is_cli()) { |
|
| 1614 | + protected static function highlightVariable($value) |
|
| 1615 | + {
|
|
| 1616 | + if (self::is_cli()) {
|
|
| 1615 | 1617 | return self::$cli_variable . $value . "\x1b[0m"; |
| 1616 | - } else { |
|
| 1618 | + } else {
|
|
| 1617 | 1619 | return '<span ' . self::$variable_attributes . '>' . $value . '</span>'; |
| 1618 | 1620 | } |
| 1619 | 1621 | } |
@@ -1625,8 +1627,8 @@ discard block |
||
| 1625 | 1627 | * |
| 1626 | 1628 | * @return String The quoted string |
| 1627 | 1629 | */ |
| 1628 | - private static function quote_regex($a) |
|
| 1629 | - { |
|
| 1630 | + private static function quote_regex($a) |
|
| 1631 | + {
|
|
| 1630 | 1632 | return preg_quote($a, '/'); |
| 1631 | 1633 | } |
| 1632 | 1634 | |
@@ -1637,13 +1639,13 @@ discard block |
||
| 1637 | 1639 | * |
| 1638 | 1640 | * @return String The quoted string |
| 1639 | 1641 | */ |
| 1640 | - private static function output($string) |
|
| 1641 | - { |
|
| 1642 | - if (self::is_cli()) { |
|
| 1642 | + private static function output($string) |
|
| 1643 | + {
|
|
| 1644 | + if (self::is_cli()) {
|
|
| 1643 | 1645 | return $string . "\n"; |
| 1644 | - } else { |
|
| 1646 | + } else {
|
|
| 1645 | 1647 | $string = trim($string); |
| 1646 | - if (!self::$use_pre) { |
|
| 1648 | + if (!self::$use_pre) {
|
|
| 1647 | 1649 | return $string; |
| 1648 | 1650 | } |
| 1649 | 1651 | |
@@ -1654,11 +1656,11 @@ discard block |
||
| 1654 | 1656 | /** |
| 1655 | 1657 | * @return bool |
| 1656 | 1658 | */ |
| 1657 | - private static function is_cli() |
|
| 1658 | - { |
|
| 1659 | - if (isset(self::$cli)) { |
|
| 1659 | + private static function is_cli() |
|
| 1660 | + {
|
|
| 1661 | + if (isset(self::$cli)) {
|
|
| 1660 | 1662 | return self::$cli; |
| 1661 | - } else { |
|
| 1663 | + } else {
|
|
| 1662 | 1664 | return php_sapi_name() === 'cli'; |
| 1663 | 1665 | } |
| 1664 | 1666 | } |
@@ -440,8 +440,8 @@ |
||
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | /** |
| 443 | - * @param $table |
|
| 444 | - * @param $sort |
|
| 443 | + * @param string $table |
|
| 444 | + * @param string $sort |
|
| 445 | 445 | * @return array |
| 446 | 446 | */ |
| 447 | 447 | protected function injectSortByTV($table, $sort) |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | } |
| 296 | 296 | $where = sqlHelper::trimLogicalOp($where); |
| 297 | 297 | |
| 298 | - $where = "WHERE {$where}"; |
|
| 298 | + $where = "where {$where}"; |
|
| 299 | 299 | $whereArr = array(); |
| 300 | 300 | if (!$this->getCFGDef('showNoPublish', 0)) { |
| 301 | 301 | $whereArr[] = "c.deleted=0 AND c.published=1"; |
@@ -388,15 +388,15 @@ discard block |
||
| 388 | 388 | |
| 389 | 389 | if ($this->getCFGDef('showNoPublish', 0)) { |
| 390 | 390 | if ($where != '') { |
| 391 | - $where = "WHERE {$where}"; |
|
| 391 | + $where = "where {$where}"; |
|
| 392 | 392 | } else { |
| 393 | 393 | $where = ''; |
| 394 | 394 | } |
| 395 | 395 | } else { |
| 396 | 396 | if ($where != '') { |
| 397 | - $where = "WHERE {$where} AND "; |
|
| 397 | + $where = "where {$where} AND "; |
|
| 398 | 398 | } else { |
| 399 | - $where = "WHERE {$where} "; |
|
| 399 | + $where = "where {$where} "; |
|
| 400 | 400 | } |
| 401 | 401 | $where .= "c.deleted=0 AND c.published=1"; |
| 402 | 402 | } |
@@ -410,7 +410,7 @@ discard block |
||
| 410 | 410 | |
| 411 | 411 | $limit = $this->LimitSQL($this->getCFGDef('queryLimit', 0)); |
| 412 | 412 | |
| 413 | - $rs = $this->dbQuery("SELECT {$fields} FROM {$tbl_site_content} {$where} {$group} {$sort} {$limit}"); |
|
| 413 | + $rs = $this->dbQuery("select {$fields} FROM {$tbl_site_content} {$where} {$group} {$sort} {$limit}"); |
|
| 414 | 414 | |
| 415 | 415 | while ($item = $this->modx->db->getRow($rs)) { |
| 416 | 416 | $out[$item['id']] = $item; |
@@ -436,9 +436,9 @@ discard block |
||
| 436 | 436 | $tbl_site_content = $this->getTable('site_content', 'c'); |
| 437 | 437 | $sanitarInIDs = $this->sanitarIn($id); |
| 438 | 438 | if ($this->getCFGDef('showNoPublish', 0)) { |
| 439 | - $where = "WHERE {$where} c.parent IN ({$sanitarInIDs}) AND c.isfolder=1"; |
|
| 439 | + $where = "where {$where} c.parent IN ({$sanitarInIDs}) AND c.isfolder=1"; |
|
| 440 | 440 | } else { |
| 441 | - $where = "WHERE {$where} c.parent IN ({$sanitarInIDs}) AND c.deleted=0 AND c.published=1 AND c.isfolder=1"; |
|
| 441 | + $where = "where {$where} c.parent IN ({$sanitarInIDs}) AND c.deleted=0 AND c.published=1 AND c.isfolder=1"; |
|
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | $rs = $this->dbQuery("SELECT id FROM {$tbl_site_content} {$where}"); |
@@ -528,7 +528,7 @@ discard block |
||
| 528 | 528 | $group = $this->getGroupSQL($this->getCFGDef('groupBy', '')); |
| 529 | 529 | |
| 530 | 530 | if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
| 531 | - $rs = $this->dbQuery("SELECT {$fields} FROM " . $from . " " . $where . " " . |
|
| 531 | + $rs = $this->dbQuery("select {$fields} FROM " . $from . " " . $where . " " . |
|
| 532 | 532 | $group . " " . |
| 533 | 533 | $sort . " " . |
| 534 | 534 | $this->LimitSQL($this->getCFGDef('queryLimit', 0)) |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | $this->_docs = ($type == 'parents') ? $this->getChildrenList() : $this->getDocList(); |
| 64 | 64 | if ($tvlist != '' && count($this->_docs) > 0) { |
| 65 | 65 | $tv = $this->extTV->getTVList(array_keys($this->_docs), $tvlist); |
| 66 | - if (!is_array($tv)) { |
|
| 66 | + if ( ! is_array($tv)) { |
|
| 67 | 67 | $tv = array(); |
| 68 | 68 | } |
| 69 | 69 | foreach ($tv as $docID => $TVitem) { |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | } |
| 140 | 140 | $date = $this->getCFGDef('dateSource', 'pub_date'); |
| 141 | 141 | if (isset($item[$date])) { |
| 142 | - if (!$item[$date] && $date == 'pub_date' && isset($item['createdon'])) { |
|
| 142 | + if ( ! $item[$date] && $date == 'pub_date' && isset($item['createdon'])) { |
|
| 143 | 143 | $date = 'createdon'; |
| 144 | 144 | } |
| 145 | 145 | $_date = is_numeric($item[$date]) && $item[$date] == (int)$item[$date] ? $item[$date] : strtotime($item[$date]); |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | |
| 222 | 222 | if (array('1') == $fields || in_array('date', $fields)) { |
| 223 | 223 | if (isset($row[$date])) { |
| 224 | - if (!$row[$date] && $date == 'pub_date' && isset($row['createdon'])) { |
|
| 224 | + if ( ! $row[$date] && $date == 'pub_date' && isset($row['createdon'])) { |
|
| 225 | 225 | $date = 'createdon'; |
| 226 | 226 | } |
| 227 | 227 | $_date = is_numeric($row[$date]) && $row[$date] == (int)$row[$date] ? $row[$date] : strtotime($row[$date]); |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | $row['title'] = empty($row['menutitle']) ? $row['pagetitle'] : $row['menutitle']; |
| 241 | 241 | } |
| 242 | 242 | } |
| 243 | - if ((bool)$this->getCFGDef('makeUrl', 1) && (array('1') == $fields || in_array('url',$fields)) |
|
| 243 | + if ((bool)$this->getCFGDef('makeUrl', 1) && (array('1') == $fields || in_array('url', $fields)) |
|
| 244 | 244 | ) { |
| 245 | 245 | if (isset($row['type']) && $row['type'] == 'reference' && isset($row['content'])) { |
| 246 | 246 | $row['url'] = is_numeric($row['content']) ? $this->modx->makeUrl($row['content'], '', '', |
@@ -287,10 +287,10 @@ discard block |
||
| 287 | 287 | |
| 288 | 288 | $where = "WHERE {$where}"; |
| 289 | 289 | $whereArr = array(); |
| 290 | - if (!$this->getCFGDef('showNoPublish', 0)) { |
|
| 290 | + if ( ! $this->getCFGDef('showNoPublish', 0)) { |
|
| 291 | 291 | $whereArr[] = "c.deleted=0 AND c.published=1"; |
| 292 | 292 | } |
| 293 | - else{ |
|
| 293 | + else { |
|
| 294 | 294 | $q_true = 1; |
| 295 | 295 | } |
| 296 | 296 | |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | $group = $this->getGroupSQL($this->getCFGDef('groupBy', 'c.id')); |
| 343 | 343 | |
| 344 | 344 | $q_true = $q_true ? $q_true : $group != ''; |
| 345 | - if ( $q_true ){ |
|
| 345 | + if ($q_true) { |
|
| 346 | 346 | $maxDocs = $this->getCFGDef('maxDocs', 0); |
| 347 | 347 | $limit = $maxDocs > 0 ? $this->LimitSQL($this->getCFGDef('maxDocs', 0)) : ''; |
| 348 | 348 | $rs = $this->dbQuery("SELECT count(*) FROM (SELECT count(*) FROM {$from} {$where} {$group} {$limit}) as `tmp`"); |
@@ -448,7 +448,7 @@ discard block |
||
| 448 | 448 | protected function injectSortByTV($table, $sort) |
| 449 | 449 | { |
| 450 | 450 | $out = $this->getExtender('tv', true, true)->injectSortByTV($table, $sort); |
| 451 | - if (!is_array($out) || empty($out)) { |
|
| 451 | + if ( ! is_array($out) || empty($out)) { |
|
| 452 | 452 | $out = array($table, $sort); |
| 453 | 453 | } |
| 454 | 454 | |
@@ -465,12 +465,12 @@ discard block |
||
| 465 | 465 | |
| 466 | 466 | $tmpWhere = $this->getCFGDef('addWhereList', ''); |
| 467 | 467 | $tmpWhere = sqlHelper::trimLogicalOp($tmpWhere); |
| 468 | - if (!empty($tmpWhere)) { |
|
| 468 | + if ( ! empty($tmpWhere)) { |
|
| 469 | 469 | $where[] = $tmpWhere; |
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | $tmpWhere = sqlHelper::trimLogicalOp($this->_filters['where']); |
| 473 | - if (!empty($tmpWhere)) { |
|
| 473 | + if ( ! empty($tmpWhere)) { |
|
| 474 | 474 | $where[] = $tmpWhere; |
| 475 | 475 | } |
| 476 | 476 | |
@@ -503,13 +503,13 @@ discard block |
||
| 503 | 503 | $tmpWhere = "((" . $tmpWhere . ") OR c.id IN({$addDocs}))"; |
| 504 | 504 | } |
| 505 | 505 | } |
| 506 | - if (!empty($tmpWhere)) { |
|
| 506 | + if ( ! empty($tmpWhere)) { |
|
| 507 | 507 | $where[] = $tmpWhere; |
| 508 | 508 | } |
| 509 | - if (!$this->getCFGDef('showNoPublish', 0)) { |
|
| 509 | + if ( ! $this->getCFGDef('showNoPublish', 0)) { |
|
| 510 | 510 | $where[] = "c.deleted=0 AND c.published=1"; |
| 511 | 511 | } |
| 512 | - if (!empty($where)) { |
|
| 512 | + if ( ! empty($where)) { |
|
| 513 | 513 | $where = "WHERE " . implode(" AND ", $where); |
| 514 | 514 | } else { |
| 515 | 515 | $where = ''; |
@@ -7,8 +7,8 @@ discard block |
||
| 7 | 7 | * @license GNU General Public License (GPL), http://www.gnu.org/copyleft/gpl.html |
| 8 | 8 | * @author Agel_Nash <[email protected]>, kabachello <[email protected]> |
| 9 | 9 | */ |
| 10 | -class site_contentDocLister extends DocLister |
|
| 11 | -{ |
|
| 10 | +class site_contentDocLister extends DocLister |
|
| 11 | +{
|
|
| 12 | 12 | /** |
| 13 | 13 | * Экземпляр экстендера TV |
| 14 | 14 | * |
@@ -28,8 +28,8 @@ discard block |
||
| 28 | 28 | * @param array $cfg |
| 29 | 29 | * @param null $startTime |
| 30 | 30 | */ |
| 31 | - public function __construct($modx, $cfg = array(), $startTime = null) |
|
| 32 | - { |
|
| 31 | + public function __construct($modx, $cfg = array(), $startTime = null) |
|
| 32 | + {
|
|
| 33 | 33 | parent::__construct($modx, $cfg, $startTime); |
| 34 | 34 | $this->extTV = $this->getExtender('tv', true, true); |
| 35 | 35 | } |
@@ -37,9 +37,9 @@ discard block |
||
| 37 | 37 | /** |
| 38 | 38 | * @absctract |
| 39 | 39 | */ |
| 40 | - public function getDocs($tvlist = '') |
|
| 41 | - { |
|
| 42 | - if ($tvlist == '') { |
|
| 40 | + public function getDocs($tvlist = '') |
|
| 41 | + {
|
|
| 42 | + if ($tvlist == '') {
|
|
| 43 | 43 | $tvlist = $this->getCFGDef('tvList', ''); |
| 44 | 44 | } |
| 45 | 45 | |
@@ -50,31 +50,31 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | $extJotCount = $this->getCFGdef('jotcount', 0) ? $this->getExtender('jotcount', true) : null; |
| 52 | 52 | |
| 53 | - if ($extJotCount) { |
|
| 53 | + if ($extJotCount) {
|
|
| 54 | 54 | $extJotCount->init($this); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - if ($this->extPaginate = $this->getExtender('paginate')) { |
|
| 57 | + if ($this->extPaginate = $this->getExtender('paginate')) {
|
|
| 58 | 58 | $this->extPaginate->init($this); |
| 59 | - } else { |
|
| 59 | + } else {
|
|
| 60 | 60 | $this->config->setConfig(array('start' => 0)); |
| 61 | 61 | } |
| 62 | 62 | $type = $this->getCFGDef('idType', 'parents'); |
| 63 | 63 | $this->_docs = ($type == 'parents') ? $this->getChildrenList() : $this->getDocList(); |
| 64 | - if ($tvlist != '' && count($this->_docs) > 0) { |
|
| 64 | + if ($tvlist != '' && count($this->_docs) > 0) {
|
|
| 65 | 65 | $tv = $this->extTV->getTVList(array_keys($this->_docs), $tvlist); |
| 66 | - if (!is_array($tv)) { |
|
| 66 | + if (!is_array($tv)) {
|
|
| 67 | 67 | $tv = array(); |
| 68 | 68 | } |
| 69 | - foreach ($tv as $docID => $TVitem) { |
|
| 70 | - if (isset($this->_docs[$docID]) && is_array($this->_docs[$docID])) { |
|
| 69 | + foreach ($tv as $docID => $TVitem) {
|
|
| 70 | + if (isset($this->_docs[$docID]) && is_array($this->_docs[$docID])) {
|
|
| 71 | 71 | $this->_docs[$docID] = array_merge($this->_docs[$docID], $TVitem); |
| 72 | - } else { |
|
| 72 | + } else {
|
|
| 73 | 73 | unset($this->_docs[$docID]); |
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | - if (1 == $this->getCFGDef('tree', '0')) { |
|
| 77 | + if (1 == $this->getCFGDef('tree', '0')) {
|
|
| 78 | 78 | $this->treeBuild('id', 'parent'); |
| 79 | 79 | } |
| 80 | 80 | |
@@ -85,23 +85,23 @@ discard block |
||
| 85 | 85 | * @param string $tpl |
| 86 | 86 | * @return string |
| 87 | 87 | */ |
| 88 | - public function _render($tpl = '') |
|
| 89 | - { |
|
| 88 | + public function _render($tpl = '') |
|
| 89 | + {
|
|
| 90 | 90 | $out = ''; |
| 91 | 91 | $separator = $this->getCFGDef('outputSeparator', ''); |
| 92 | - if ($tpl == '') { |
|
| 92 | + if ($tpl == '') {
|
|
| 93 | 93 | $tpl = $this->getCFGDef('tpl', '@CODE:<a href="[+url+]">[+pagetitle+]</a><br />'); |
| 94 | 94 | } |
| 95 | - if ($tpl != '') { |
|
| 95 | + if ($tpl != '') {
|
|
| 96 | 96 | $this->toPlaceholders(count($this->_docs), 1, "display"); // [+display+] - сколько показано на странице. |
| 97 | 97 | |
| 98 | 98 | $i = 1; |
| 99 | 99 | $sysPlh = $this->renameKeyArr($this->_plh, $this->getCFGDef("sysKey", "dl")); |
| 100 | - if (count($this->_docs) > 0) { |
|
| 100 | + if (count($this->_docs) > 0) {
|
|
| 101 | 101 | /** |
| 102 | 102 | * @var $extUser user_DL_Extender |
| 103 | 103 | */ |
| 104 | - if ($extUser = $this->getExtender('user')) { |
|
| 104 | + if ($extUser = $this->getExtender('user')) {
|
|
| 105 | 105 | $extUser->init($this, array('fields' => $this->getCFGDef("userFields", ""))); |
| 106 | 106 | } |
| 107 | 107 | |
@@ -116,9 +116,9 @@ discard block |
||
| 116 | 116 | $extPrepare = $this->getExtender('prepare'); |
| 117 | 117 | |
| 118 | 118 | $this->skippedDocs = 0; |
| 119 | - foreach ($this->_docs as $item) { |
|
| 119 | + foreach ($this->_docs as $item) {
|
|
| 120 | 120 | $this->renderTPL = $tpl; |
| 121 | - if ($extUser) { |
|
| 121 | + if ($extUser) {
|
|
| 122 | 122 | $item = $extUser->setUserData($item); //[+user.id.createdby+], [+user.fullname.publishedby+], [+dl.user.publishedby+].... |
| 123 | 123 | } |
| 124 | 124 | |
@@ -130,24 +130,24 @@ discard block |
||
| 130 | 130 | |
| 131 | 131 | $item['title'] = ($item['menutitle'] == '' ? $item['pagetitle'] : $item['menutitle']); |
| 132 | 132 | |
| 133 | - if ($this->getCFGDef('makeUrl', 1)) { |
|
| 134 | - if ($item['type'] == 'reference') { |
|
| 133 | + if ($this->getCFGDef('makeUrl', 1)) {
|
|
| 134 | + if ($item['type'] == 'reference') {
|
|
| 135 | 135 | $item['url'] = is_numeric($item['content']) ? $this->modx->makeUrl($item['content'], '', '', |
| 136 | 136 | $this->getCFGDef('urlScheme', '')) : $item['content']; |
| 137 | - } else { |
|
| 137 | + } else {
|
|
| 138 | 138 | $item['url'] = $this->modx->makeUrl($item['id'], '', '', $this->getCFGDef('urlScheme', '')); |
| 139 | 139 | } |
| 140 | 140 | } |
| 141 | 141 | $date = $this->getCFGDef('dateSource', 'pub_date'); |
| 142 | - if (isset($item[$date])) { |
|
| 143 | - if (!$item[$date] && $date == 'pub_date' && isset($item['createdon'])) { |
|
| 142 | + if (isset($item[$date])) {
|
|
| 143 | + if (!$item[$date] && $date == 'pub_date' && isset($item['createdon'])) {
|
|
| 144 | 144 | $date = 'createdon'; |
| 145 | 145 | } |
| 146 | 146 | $_date = is_numeric($item[$date]) && $item[$date] == (int)$item[$date] ? $item[$date] : strtotime($item[$date]); |
| 147 | - if ($_date !== false) { |
|
| 147 | + if ($_date !== false) {
|
|
| 148 | 148 | $_date = $_date + $this->modx->config['server_offset_time']; |
| 149 | 149 | $dateFormat = $this->getCFGDef('dateFormat', '%d.%b.%y %H:%M'); |
| 150 | - if ($dateFormat) { |
|
| 150 | + if ($dateFormat) {
|
|
| 151 | 151 | $item['date'] = strftime($dateFormat, $_date); |
| 152 | 152 | } |
| 153 | 153 | } |
@@ -156,33 +156,33 @@ discard block |
||
| 156 | 156 | $findTpl = $this->renderTPL; |
| 157 | 157 | $tmp = $this->uniformPrepare($item, $i); |
| 158 | 158 | extract($tmp, EXTR_SKIP); |
| 159 | - if ($this->renderTPL == '') { |
|
| 159 | + if ($this->renderTPL == '') {
|
|
| 160 | 160 | $this->renderTPL = $findTpl; |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - if ($extPrepare) { |
|
| 163 | + if ($extPrepare) {
|
|
| 164 | 164 | $item = $extPrepare->init($this, array( |
| 165 | 165 | 'data' => $item, |
| 166 | 166 | 'nameParam' => 'prepare' |
| 167 | 167 | )); |
| 168 | - if (is_bool($item) && $item === false) { |
|
| 168 | + if (is_bool($item) && $item === false) {
|
|
| 169 | 169 | $this->skippedDocs++; |
| 170 | 170 | continue; |
| 171 | 171 | } |
| 172 | 172 | } |
| 173 | 173 | $tmp = $this->parseChunk($this->renderTPL, $item); |
| 174 | 174 | |
| 175 | - if ($this->getCFGDef('contentPlaceholder', 0) !== 0) { |
|
| 175 | + if ($this->getCFGDef('contentPlaceholder', 0) !== 0) {
|
|
| 176 | 176 | $this->toPlaceholders($tmp, 1, |
| 177 | 177 | "item[" . $i . "]"); // [+item[x]+] – individual placeholder for each iteration documents on this page |
| 178 | 178 | } |
| 179 | 179 | $out .= $tmp; |
| 180 | - if (next($this->_docs) !== false) { |
|
| 180 | + if (next($this->_docs) !== false) {
|
|
| 181 | 181 | $out .= $separator; |
| 182 | 182 | } |
| 183 | 183 | $i++; |
| 184 | 184 | } |
| 185 | - } else { |
|
| 185 | + } else {
|
|
| 186 | 186 | $noneTPL = $this->getCFGDef('noneTPL', ''); |
| 187 | 187 | $out = ($noneTPL != '') ? $this->parseChunk($noneTPL, $sysPlh) : ''; |
| 188 | 188 | } |
@@ -198,8 +198,8 @@ discard block |
||
| 198 | 198 | * @param array $array |
| 199 | 199 | * @return string |
| 200 | 200 | */ |
| 201 | - public function getJSON($data, $fields, $array = array()) |
|
| 202 | - { |
|
| 201 | + public function getJSON($data, $fields, $array = array()) |
|
| 202 | + {
|
|
| 203 | 203 | $out = array(); |
| 204 | 204 | $fields = is_array($fields) ? $fields : explode(",", $fields); |
| 205 | 205 | $date = $this->getCFGDef('dateSource', 'pub_date'); |
@@ -218,50 +218,50 @@ discard block |
||
| 218 | 218 | */ |
| 219 | 219 | $extE = $this->getExtender('e', true, true); |
| 220 | 220 | |
| 221 | - foreach ($data as $num => $row) { |
|
| 222 | - if ((array('1') == $fields || in_array('summary', $fields)) && $extSummary) { |
|
| 221 | + foreach ($data as $num => $row) {
|
|
| 222 | + if ((array('1') == $fields || in_array('summary', $fields)) && $extSummary) {
|
|
| 223 | 223 | $row['summary'] = $this->getSummary($row, $extSummary, 'introtext', 'content'); |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - if (array('1') == $fields || in_array('date', $fields)) { |
|
| 227 | - if (isset($row[$date])) { |
|
| 228 | - if (!$row[$date] && $date == 'pub_date' && isset($row['createdon'])) { |
|
| 226 | + if (array('1') == $fields || in_array('date', $fields)) {
|
|
| 227 | + if (isset($row[$date])) {
|
|
| 228 | + if (!$row[$date] && $date == 'pub_date' && isset($row['createdon'])) {
|
|
| 229 | 229 | $date = 'createdon'; |
| 230 | 230 | } |
| 231 | 231 | $_date = is_numeric($row[$date]) && $row[$date] == (int)$row[$date] ? $row[$date] : strtotime($row[$date]); |
| 232 | - if ($_date !== false) { |
|
| 232 | + if ($_date !== false) {
|
|
| 233 | 233 | $_date = $_date + $this->modx->config['server_offset_time']; |
| 234 | 234 | $dateFormat = $this->getCFGDef('dateFormat', '%d.%b.%y %H:%M'); |
| 235 | - if ($dateFormat) { |
|
| 235 | + if ($dateFormat) {
|
|
| 236 | 236 | $row['date'] = strftime($dateFormat, $_date); |
| 237 | 237 | } |
| 238 | 238 | } |
| 239 | 239 | } |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | - if (array('1') == $fields || in_array('title', $fields)) { |
|
| 243 | - if (isset($row['pagetitle'])) { |
|
| 242 | + if (array('1') == $fields || in_array('title', $fields)) {
|
|
| 243 | + if (isset($row['pagetitle'])) {
|
|
| 244 | 244 | $row['title'] = empty($row['menutitle']) ? $row['pagetitle'] : $row['menutitle']; |
| 245 | 245 | } |
| 246 | 246 | } |
| 247 | 247 | if ((bool)$this->getCFGDef('makeUrl', 1) && (array('1') == $fields || in_array('url',$fields)) |
| 248 | - ) { |
|
| 249 | - if (isset($row['type']) && $row['type'] == 'reference' && isset($row['content'])) { |
|
| 248 | + ) {
|
|
| 249 | + if (isset($row['type']) && $row['type'] == 'reference' && isset($row['content'])) {
|
|
| 250 | 250 | $row['url'] = is_numeric($row['content']) ? $this->modx->makeUrl($row['content'], '', '', |
| 251 | 251 | $this->getCFGDef('urlScheme', '')) : $row['content']; |
| 252 | - } elseif (isset($row['id'])) { |
|
| 252 | + } elseif (isset($row['id'])) {
|
|
| 253 | 253 | $row['url'] = $this->modx->makeUrl($row['id'], '', '', $this->getCFGDef('urlScheme', '')); |
| 254 | 254 | } |
| 255 | 255 | } |
| 256 | - if ($extE && $tmp = $extE->init($this, array('data' => $row))) { |
|
| 257 | - if (is_array($tmp)) { |
|
| 256 | + if ($extE && $tmp = $extE->init($this, array('data' => $row))) {
|
|
| 257 | + if (is_array($tmp)) {
|
|
| 258 | 258 | $row = $tmp; |
| 259 | 259 | } |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - if ($extPrepare) { |
|
| 262 | + if ($extPrepare) {
|
|
| 263 | 263 | $row = $extPrepare->init($this, array('data' => $row)); |
| 264 | - if (is_bool($row) && $row === false) { |
|
| 264 | + if (is_bool($row) && $row === false) {
|
|
| 265 | 265 | continue; |
| 266 | 266 | } |
| 267 | 267 | } |
@@ -274,36 +274,35 @@ discard block |
||
| 274 | 274 | /** |
| 275 | 275 | * @abstract |
| 276 | 276 | */ |
| 277 | - public function getChildrenCount() |
|
| 278 | - { |
|
| 277 | + public function getChildrenCount() |
|
| 278 | + {
|
|
| 279 | 279 | $out = 0; |
| 280 | 280 | $sanitarInIDs = $this->sanitarIn($this->IDs); |
| 281 | - if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
|
| 281 | + if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) {
|
|
| 282 | 282 | $q_true = $this->getCFGDef('ignoreEmpty', '0'); |
| 283 | 283 | $q_true = $q_true ? $q_true : $this->getCFGDef('idType', 'parents') == 'parents'; |
| 284 | 284 | $where = $this->getCFGDef('addWhereList', ''); |
| 285 | 285 | $where = sqlHelper::trimLogicalOp($where); |
| 286 | 286 | $where = ($where ? $where . ' AND ' : '') . $this->_filters['where']; |
| 287 | - if ($where != '' && $this->_filters['where'] != '') { |
|
| 287 | + if ($where != '' && $this->_filters['where'] != '') {
|
|
| 288 | 288 | $where .= " AND "; |
| 289 | 289 | } |
| 290 | 290 | $where = sqlHelper::trimLogicalOp($where); |
| 291 | 291 | |
| 292 | 292 | $where = "WHERE {$where}"; |
| 293 | 293 | $whereArr = array(); |
| 294 | - if (!$this->getCFGDef('showNoPublish', 0)) { |
|
| 294 | + if (!$this->getCFGDef('showNoPublish', 0)) {
|
|
| 295 | 295 | $whereArr[] = "c.deleted=0 AND c.published=1"; |
| 296 | - } |
|
| 297 | - else{ |
|
| 296 | + } else {
|
|
| 298 | 297 | $q_true = 1; |
| 299 | 298 | } |
| 300 | 299 | |
| 301 | 300 | $tbl_site_content = $this->getTable('site_content', 'c'); |
| 302 | 301 | |
| 303 | - if ($sanitarInIDs != "''") { |
|
| 304 | - switch ($this->getCFGDef('idType', 'parents')) { |
|
| 302 | + if ($sanitarInIDs != "''") {
|
|
| 303 | + switch ($this->getCFGDef('idType', 'parents')) {
|
|
| 305 | 304 | case 'parents': |
| 306 | - switch ($this->getCFGDef('showParent', '0')) { |
|
| 305 | + switch ($this->getCFGDef('showParent', '0')) {
|
|
| 307 | 306 | case '-1': |
| 308 | 307 | $tmpWhere = "c.parent IN (" . $sanitarInIDs . ")"; |
| 309 | 308 | break; |
@@ -315,10 +314,10 @@ discard block |
||
| 315 | 314 | $tmpWhere = "(c.parent IN ({$sanitarInIDs}) OR c.id IN({$sanitarInIDs}))"; |
| 316 | 315 | break; |
| 317 | 316 | } |
| 318 | - if (($addDocs = $this->getCFGDef('documents', '')) != '') { |
|
| 317 | + if (($addDocs = $this->getCFGDef('documents', '')) != '') {
|
|
| 319 | 318 | $addDocs = $this->sanitarIn($this->cleanIDs($addDocs)); |
| 320 | 319 | $whereArr[] = "((" . $tmpWhere . ") OR c.id IN({$addDocs}))"; |
| 321 | - } else { |
|
| 320 | + } else {
|
|
| 322 | 321 | $whereArr[] = $tmpWhere; |
| 323 | 322 | } |
| 324 | 323 | |
@@ -333,26 +332,25 @@ discard block |
||
| 333 | 332 | |
| 334 | 333 | $q_true = $q_true ? $q_true : trim($where) != 'WHERE'; |
| 335 | 334 | |
| 336 | - if (trim($where) != 'WHERE') { |
|
| 335 | + if (trim($where) != 'WHERE') {
|
|
| 337 | 336 | $where .= " AND "; |
| 338 | 337 | } |
| 339 | 338 | |
| 340 | 339 | $where .= implode(" AND ", $whereArr); |
| 341 | 340 | $where = sqlHelper::trimLogicalOp($where); |
| 342 | 341 | |
| 343 | - if (trim($where) == 'WHERE') { |
|
| 342 | + if (trim($where) == 'WHERE') {
|
|
| 344 | 343 | $where = ''; |
| 345 | 344 | } |
| 346 | 345 | $group = $this->getGroupSQL($this->getCFGDef('groupBy', 'c.id')); |
| 347 | 346 | |
| 348 | 347 | $q_true = $q_true ? $q_true : $group != ''; |
| 349 | - if ( $q_true ){ |
|
| 348 | + if ( $q_true ) {
|
|
| 350 | 349 | $maxDocs = $this->getCFGDef('maxDocs', 0); |
| 351 | 350 | $limit = $maxDocs > 0 ? $this->LimitSQL($this->getCFGDef('maxDocs', 0)) : ''; |
| 352 | 351 | $rs = $this->dbQuery("SELECT count(*) FROM (SELECT count(*) FROM {$from} {$where} {$group} {$limit}) as `tmp`"); |
| 353 | 352 | $out = $this->modx->db->getValue($rs); |
| 354 | - } |
|
| 355 | - else { |
|
| 353 | + } else {
|
|
| 356 | 354 | $out = count($this->IDs); |
| 357 | 355 | } |
| 358 | 356 | } |
@@ -363,11 +361,11 @@ discard block |
||
| 363 | 361 | /** |
| 364 | 362 | * @return array |
| 365 | 363 | */ |
| 366 | - protected function getDocList() |
|
| 367 | - { |
|
| 364 | + protected function getDocList() |
|
| 365 | + {
|
|
| 368 | 366 | $out = array(); |
| 369 | 367 | $sanitarInIDs = $this->sanitarIn($this->IDs); |
| 370 | - if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
|
| 368 | + if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) {
|
|
| 371 | 369 | $where = $this->getCFGDef('addWhereList', ''); |
| 372 | 370 | $where = sqlHelper::trimLogicalOp($where); |
| 373 | 371 | |
@@ -375,21 +373,21 @@ discard block |
||
| 375 | 373 | $where = sqlHelper::trimLogicalOp($where); |
| 376 | 374 | |
| 377 | 375 | $tbl_site_content = $this->getTable('site_content', 'c'); |
| 378 | - if ($sanitarInIDs != "''") { |
|
| 376 | + if ($sanitarInIDs != "''") {
|
|
| 379 | 377 | $where .= ($where ? " AND " : "") . "c.id IN ({$sanitarInIDs}) AND"; |
| 380 | 378 | } |
| 381 | 379 | $where = sqlHelper::trimLogicalOp($where); |
| 382 | 380 | |
| 383 | - if ($this->getCFGDef('showNoPublish', 0)) { |
|
| 384 | - if ($where != '') { |
|
| 381 | + if ($this->getCFGDef('showNoPublish', 0)) {
|
|
| 382 | + if ($where != '') {
|
|
| 385 | 383 | $where = "WHERE {$where}"; |
| 386 | - } else { |
|
| 384 | + } else {
|
|
| 387 | 385 | $where = ''; |
| 388 | 386 | } |
| 389 | - } else { |
|
| 390 | - if ($where != '') { |
|
| 387 | + } else {
|
|
| 388 | + if ($where != '') {
|
|
| 391 | 389 | $where = "WHERE {$where} AND "; |
| 392 | - } else { |
|
| 390 | + } else {
|
|
| 393 | 391 | $where = "WHERE {$where} "; |
| 394 | 392 | } |
| 395 | 393 | $where .= "c.deleted=0 AND c.published=1"; |
@@ -406,7 +404,7 @@ discard block |
||
| 406 | 404 | |
| 407 | 405 | $rs = $this->dbQuery("SELECT {$fields} FROM {$tbl_site_content} {$where} {$group} {$sort} {$limit}"); |
| 408 | 406 | |
| 409 | - while ($item = $this->modx->db->getRow($rs)) { |
|
| 407 | + while ($item = $this->modx->db->getRow($rs)) {
|
|
| 410 | 408 | $out[$item['id']] = $item; |
| 411 | 409 | }; |
| 412 | 410 | } |
@@ -418,26 +416,26 @@ discard block |
||
| 418 | 416 | * @param string $id |
| 419 | 417 | * @return array |
| 420 | 418 | */ |
| 421 | - public function getChildrenFolder($id) |
|
| 422 | - { |
|
| 419 | + public function getChildrenFolder($id) |
|
| 420 | + {
|
|
| 423 | 421 | $out = array(); |
| 424 | 422 | $where = $this->getCFGDef('addWhereFolder', ''); |
| 425 | 423 | $where = sqlHelper::trimLogicalOp($where); |
| 426 | - if ($where != '') { |
|
| 424 | + if ($where != '') {
|
|
| 427 | 425 | $where .= " AND "; |
| 428 | 426 | } |
| 429 | 427 | |
| 430 | 428 | $tbl_site_content = $this->getTable('site_content', 'c'); |
| 431 | 429 | $sanitarInIDs = $this->sanitarIn($id); |
| 432 | - if ($this->getCFGDef('showNoPublish', 0)) { |
|
| 430 | + if ($this->getCFGDef('showNoPublish', 0)) {
|
|
| 433 | 431 | $where = "WHERE {$where} c.parent IN ({$sanitarInIDs}) AND c.isfolder=1"; |
| 434 | - } else { |
|
| 432 | + } else {
|
|
| 435 | 433 | $where = "WHERE {$where} c.parent IN ({$sanitarInIDs}) AND c.deleted=0 AND c.published=1 AND c.isfolder=1"; |
| 436 | 434 | } |
| 437 | 435 | |
| 438 | 436 | $rs = $this->dbQuery("SELECT id FROM {$tbl_site_content} {$where}"); |
| 439 | 437 | |
| 440 | - while ($item = $this->modx->db->getRow($rs)) { |
|
| 438 | + while ($item = $this->modx->db->getRow($rs)) {
|
|
| 441 | 439 | $out[] = $item['id']; |
| 442 | 440 | } |
| 443 | 441 | |
@@ -449,10 +447,10 @@ discard block |
||
| 449 | 447 | * @param $sort |
| 450 | 448 | * @return array |
| 451 | 449 | */ |
| 452 | - protected function injectSortByTV($table, $sort) |
|
| 453 | - { |
|
| 450 | + protected function injectSortByTV($table, $sort) |
|
| 451 | + {
|
|
| 454 | 452 | $out = $this->getExtender('tv', true, true)->injectSortByTV($table, $sort); |
| 455 | - if (!is_array($out) || empty($out)) { |
|
| 453 | + if (!is_array($out) || empty($out)) {
|
|
| 456 | 454 | $out = array($table, $sort); |
| 457 | 455 | } |
| 458 | 456 | |
@@ -462,19 +460,19 @@ discard block |
||
| 462 | 460 | /** |
| 463 | 461 | * @return array |
| 464 | 462 | */ |
| 465 | - protected function getChildrenList() |
|
| 466 | - { |
|
| 463 | + protected function getChildrenList() |
|
| 464 | + {
|
|
| 467 | 465 | $where = array(); |
| 468 | 466 | $out = array(); |
| 469 | 467 | |
| 470 | 468 | $tmpWhere = $this->getCFGDef('addWhereList', ''); |
| 471 | 469 | $tmpWhere = sqlHelper::trimLogicalOp($tmpWhere); |
| 472 | - if (!empty($tmpWhere)) { |
|
| 470 | + if (!empty($tmpWhere)) {
|
|
| 473 | 471 | $where[] = $tmpWhere; |
| 474 | 472 | } |
| 475 | 473 | |
| 476 | 474 | $tmpWhere = sqlHelper::trimLogicalOp($this->_filters['where']); |
| 477 | - if (!empty($tmpWhere)) { |
|
| 475 | + if (!empty($tmpWhere)) {
|
|
| 478 | 476 | $where[] = $tmpWhere; |
| 479 | 477 | } |
| 480 | 478 | |
@@ -485,8 +483,8 @@ discard block |
||
| 485 | 483 | $sanitarInIDs = $this->sanitarIn($this->IDs); |
| 486 | 484 | |
| 487 | 485 | $tmpWhere = null; |
| 488 | - if ($sanitarInIDs != "''") { |
|
| 489 | - switch ($this->getCFGDef('showParent', '0')) { |
|
| 486 | + if ($sanitarInIDs != "''") {
|
|
| 487 | + switch ($this->getCFGDef('showParent', '0')) {
|
|
| 490 | 488 | case '-1': |
| 491 | 489 | $tmpWhere = "c.parent IN (" . $sanitarInIDs . ")"; |
| 492 | 490 | break; |
@@ -499,36 +497,36 @@ discard block |
||
| 499 | 497 | break; |
| 500 | 498 | } |
| 501 | 499 | } |
| 502 | - if (($addDocs = $this->getCFGDef('documents', '')) != '') { |
|
| 500 | + if (($addDocs = $this->getCFGDef('documents', '')) != '') {
|
|
| 503 | 501 | $addDocs = $this->sanitarIn($this->cleanIDs($addDocs)); |
| 504 | - if (empty($tmpWhere)) { |
|
| 502 | + if (empty($tmpWhere)) {
|
|
| 505 | 503 | $tmpWhere = "c.id IN({$addDocs})"; |
| 506 | - } else { |
|
| 504 | + } else {
|
|
| 507 | 505 | $tmpWhere = "((" . $tmpWhere . ") OR c.id IN({$addDocs}))"; |
| 508 | 506 | } |
| 509 | 507 | } |
| 510 | - if (!empty($tmpWhere)) { |
|
| 508 | + if (!empty($tmpWhere)) {
|
|
| 511 | 509 | $where[] = $tmpWhere; |
| 512 | 510 | } |
| 513 | - if (!$this->getCFGDef('showNoPublish', 0)) { |
|
| 511 | + if (!$this->getCFGDef('showNoPublish', 0)) {
|
|
| 514 | 512 | $where[] = "c.deleted=0 AND c.published=1"; |
| 515 | 513 | } |
| 516 | - if (!empty($where)) { |
|
| 514 | + if (!empty($where)) {
|
|
| 517 | 515 | $where = "WHERE " . implode(" AND ", $where); |
| 518 | - } else { |
|
| 516 | + } else {
|
|
| 519 | 517 | $where = ''; |
| 520 | 518 | } |
| 521 | 519 | $fields = $this->getCFGDef('selectFields', 'c.*'); |
| 522 | 520 | $group = $this->getGroupSQL($this->getCFGDef('groupBy', '')); |
| 523 | 521 | |
| 524 | - if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
|
| 522 | + if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) {
|
|
| 525 | 523 | $rs = $this->dbQuery("SELECT {$fields} FROM " . $from . " " . $where . " " . |
| 526 | 524 | $group . " " . |
| 527 | 525 | $sort . " " . |
| 528 | 526 | $this->LimitSQL($this->getCFGDef('queryLimit', 0)) |
| 529 | 527 | ); |
| 530 | 528 | |
| 531 | - while ($item = $this->modx->db->getRow($rs)) { |
|
| 529 | + while ($item = $this->modx->db->getRow($rs)) {
|
|
| 532 | 530 | $out[$item['id']] = $item; |
| 533 | 531 | } |
| 534 | 532 | } |
@@ -541,10 +539,10 @@ discard block |
||
| 541 | 539 | * @param string $type |
| 542 | 540 | * @return string |
| 543 | 541 | */ |
| 544 | - public function changeSortType($field, $type) |
|
| 545 | - { |
|
| 542 | + public function changeSortType($field, $type) |
|
| 543 | + {
|
|
| 546 | 544 | $type = trim($type); |
| 547 | - switch (strtoupper($type)) { |
|
| 545 | + switch (strtoupper($type)) {
|
|
| 548 | 546 | case 'TVDATETIME': |
| 549 | 547 | $field = "STR_TO_DATE(" . $field . ",'%d-%m-%Y %H:%i:%s')"; |
| 550 | 548 | break; |
@@ -44,10 +44,10 @@ |
||
| 44 | 44 | $reflectTPL = APIHelpers::getkey($params, 'reflectTPL', |
| 45 | 45 | '@CODE: <li><a href="[+url+]" title="[+title+]">[+title+]</a></li>'); |
| 46 | 46 | /** |
| 47 | - * activeReflectTPL |
|
| 48 | - * Шаблон активной даты. |
|
| 49 | - * Поддерживается такие же плейсхолдеры, как и в шаблоне reflectTPL |
|
| 50 | - */ |
|
| 47 | + * activeReflectTPL |
|
| 48 | + * Шаблон активной даты. |
|
| 49 | + * Поддерживается такие же плейсхолдеры, как и в шаблоне reflectTPL |
|
| 50 | + */ |
|
| 51 | 51 | $activeReflectTPL = APIHelpers::getkey($params, 'activeReflectTPL', '@CODE: <li><span>[+title+]</span></li>'); |
| 52 | 52 | |
| 53 | 53 | list($dateFormat, $sqlDateFormat, $reflectValidator) = DLReflect::switchReflect($reflectType, function () { |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * year - по годам |
| 26 | 26 | */ |
| 27 | 27 | $reflectType = APIHelpers::getkey($params, 'reflectType', 'month'); |
| 28 | -if (!in_array($reflectType, array('year', 'month'))) { |
|
| 28 | +if (!in_array($reflectType, array('year', 'month'))) {
|
|
| 29 | 29 | return ''; |
| 30 | 30 | } |
| 31 | 31 | |
@@ -50,9 +50,9 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | $activeReflectTPL = APIHelpers::getkey($params, 'activeReflectTPL', '@CODE: <li><span>[+title+]</span></li>'); |
| 52 | 52 | |
| 53 | -list($dateFormat, $sqlDateFormat, $reflectValidator) = DLReflect::switchReflect($reflectType, function () { |
|
| 53 | +list($dateFormat, $sqlDateFormat, $reflectValidator) = DLReflect::switchReflect($reflectType, function () {
|
|
| 54 | 54 | return array('m-Y', '%m-%Y', array('DLReflect', 'validateMonth')); |
| 55 | -}, function () { |
|
| 55 | +}, function () {
|
|
| 56 | 56 | return array('Y', '%Y', array('DLReflect', 'validateYear')); |
| 57 | 57 | }); |
| 58 | 58 | $tmp = $originalDate = date($dateFormat); |
@@ -65,13 +65,13 @@ discard block |
||
| 65 | 65 | * Если не указан в параметре, то генерируется автоматически текущая дата |
| 66 | 66 | */ |
| 67 | 67 | $currentReflect = APIHelpers::getkey($params, 'currentReflect', $tmp); |
| 68 | -if (!call_user_func($reflectValidator, $currentYear)) { |
|
| 68 | +if (!call_user_func($reflectValidator, $currentYear)) {
|
|
| 69 | 69 | $currentReflect = $tmp; |
| 70 | 70 | } |
| 71 | 71 | $originalCurrentReflect = $currentReflect; |
| 72 | 72 | |
| 73 | 73 | $selectCurrentReflect = APIHelpers::getkey($params, 'selectCurrentReflect', 1); |
| 74 | -if (!$selectCurrentReflect && $currentReflect == $tmp) { |
|
| 74 | +if (!$selectCurrentReflect && $currentReflect == $tmp) {
|
|
| 75 | 75 | $currentReflect = null; |
| 76 | 76 | } |
| 77 | 77 | |
@@ -99,12 +99,12 @@ discard block |
||
| 99 | 99 | */ |
| 100 | 100 | $tmp = APIHelpers::getkey($params, 'activeReflect', $currentReflect); |
| 101 | 101 | $tmpGet = APIHelpers::getkey($_GET, $reflectType, $tmp); |
| 102 | -if (!call_user_func($reflectValidator, $tmpGet)) { |
|
| 102 | +if (!call_user_func($reflectValidator, $tmpGet)) {
|
|
| 103 | 103 | $activeReflect = $tmp; |
| 104 | - if (!call_user_func($reflectValidator, $activeReflect)) { |
|
| 104 | + if (!call_user_func($reflectValidator, $activeReflect)) {
|
|
| 105 | 105 | $activeReflect = $currentReflect; |
| 106 | 106 | } |
| 107 | -} else { |
|
| 107 | +} else {
|
|
| 108 | 108 | $activeReflect = $tmpGet; |
| 109 | 109 | } |
| 110 | 110 | |
@@ -159,10 +159,10 @@ discard block |
||
| 159 | 159 | $DLParams['api'] = 'id'; |
| 160 | 160 | $DLParams['orderBy'] = $reflectField; |
| 161 | 161 | $DLParams['saveDLObject'] = 'DLAPI'; |
| 162 | -if ($reflectSource == 'tv') { |
|
| 162 | +if ($reflectSource == 'tv') {
|
|
| 163 | 163 | $DLParams['tvSortType'] = 'TVDATETIME'; |
| 164 | 164 | $DLParams['selectFields'] = "DATE_FORMAT(STR_TO_DATE(`dltv_" . $reflectField . "_1`.`value`,'%d-%m-%Y %H:%i:%s'), '" . $sqlDateFormat . "') as `id`"; |
| 165 | -} else { |
|
| 165 | +} else {
|
|
| 166 | 166 | $DLParams['orderBy'] = $reflectField; |
| 167 | 167 | $DLParams['selectFields'] = "DATE_FORMAT(FROM_UNIXTIME(" . $reflectField . "), '" . $sqlDateFormat . "') as `id`"; |
| 168 | 168 | } |
@@ -170,32 +170,32 @@ discard block |
||
| 170 | 170 | /** Получаем объект DocLister'a */ |
| 171 | 171 | $DLAPI = $modx->getPlaceholder('DLAPI'); |
| 172 | 172 | |
| 173 | -if ($reflectType == 'month') { |
|
| 173 | +if ($reflectType == 'month') {
|
|
| 174 | 174 | //Загружаем лексикон с месяцами |
| 175 | 175 | $DLAPI->loadLang('months'); |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | /** Разбираем API ответ от DocLister'a */ |
| 179 | 179 | $totalReflects = json_decode($totalReflects, true); |
| 180 | -if (is_null($totalReflects)) { |
|
| 180 | +if (is_null($totalReflects)) {
|
|
| 181 | 181 | $totalReflects = array(); |
| 182 | 182 | } |
| 183 | 183 | $totalReflects = new DLCollection($modx, $totalReflects); |
| 184 | -$totalReflects = $totalReflects->filter(function ($el) { |
|
| 184 | +$totalReflects = $totalReflects->filter(function ($el) {
|
|
| 185 | 185 | return !empty($el['id']); |
| 186 | 186 | }); |
| 187 | 187 | /** Добавляем активную дату в коллекцию */ |
| 188 | -if (!is_null($activeReflect)) { |
|
| 188 | +if (!is_null($activeReflect)) {
|
|
| 189 | 189 | $totalReflects->add(array('id' => $activeReflect), $activeReflect); |
| 190 | 190 | } |
| 191 | 191 | $hasCurrentReflect = ($totalReflects->indexOf(array('id' => $originalCurrentReflect)) !== false); |
| 192 | 192 | |
| 193 | 193 | /** Добавляем текущую дату в коллекцию */ |
| 194 | -if ($appendCurrentReflect) { |
|
| 194 | +if ($appendCurrentReflect) {
|
|
| 195 | 195 | $totalReflects->add(array('id' => $originalCurrentReflect), $originalCurrentReflect); |
| 196 | 196 | } |
| 197 | 197 | /** Сортируем даты по возрастанию */ |
| 198 | -$totalReflects->sort(function ($a, $b) use ($dateFormat) { |
|
| 198 | +$totalReflects->sort(function ($a, $b) use ($dateFormat) {
|
|
| 199 | 199 | $aDate = DateTime::createFromFormat($dateFormat, $a['id']); |
| 200 | 200 | $bDate = DateTime::createFromFormat($dateFormat, $b['id']); |
| 201 | 201 | |
@@ -207,9 +207,9 @@ discard block |
||
| 207 | 207 | $activeReflect, |
| 208 | 208 | $originalDate, |
| 209 | 209 | $dateFormat |
| 210 | -) { |
|
| 210 | +) {
|
|
| 211 | 211 | $aDate = DateTime::createFromFormat($dateFormat, $val['id']); |
| 212 | - if (is_null($activeReflect)) { |
|
| 212 | + if (is_null($activeReflect)) {
|
|
| 213 | 213 | $activeReflect = $originalDate; |
| 214 | 214 | } |
| 215 | 215 | $bDate = DateTime::createFromFormat($dateFormat, $activeReflect); |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | return $aDate->getTimestamp() < $bDate->getTimestamp(); |
| 218 | 218 | }); |
| 219 | 219 | /** Удаляем текущую активную дату из списка дат идущих за текущим */ |
| 220 | -if ($rReflect->indexOf(array('id' => $originalCurrentReflect)) !== false) { |
|
| 220 | +if ($rReflect->indexOf(array('id' => $originalCurrentReflect)) !== false) {
|
|
| 221 | 221 | $rReflect->reindex()->remove(0); |
| 222 | 222 | } |
| 223 | 223 | /** Разворачиваем в обратном порядке список дат до текущей даты */ |
@@ -225,13 +225,13 @@ discard block |
||
| 225 | 225 | |
| 226 | 226 | /** Расчитываем сколько дат из какого списка взять */ |
| 227 | 227 | $showBefore = ($lReflect->count() < $limitBefore || empty($limitBefore)) ? $lReflect->count() : $limitBefore; |
| 228 | -if (($rReflect->count() < $limitAfter) || empty($limitAfter)) { |
|
| 228 | +if (($rReflect->count() < $limitAfter) || empty($limitAfter)) {
|
|
| 229 | 229 | $showAfter = $rReflect->count(); |
| 230 | 230 | $showBefore += !empty($limitAfter) ? ($limitAfter - $rReflect->count()) : 0; |
| 231 | -} else { |
|
| 232 | - if ($limitBefore > 0) { |
|
| 231 | +} else {
|
|
| 232 | + if ($limitBefore > 0) {
|
|
| 233 | 233 | $showAfter = $limitAfter + ($limitBefore - $showBefore); |
| 234 | - } else { |
|
| 234 | + } else {
|
|
| 235 | 235 | $showAfter = $limitAfter; |
| 236 | 236 | } |
| 237 | 237 | } |
@@ -241,25 +241,25 @@ discard block |
||
| 241 | 241 | $outReflects = new DLCollection($modx); |
| 242 | 242 | /** Берем нужное число элементов с левой стороны */ |
| 243 | 243 | $i = 0; |
| 244 | -foreach ($lReflect as $item) { |
|
| 245 | - if ((++$i) > $showBefore) { |
|
| 244 | +foreach ($lReflect as $item) {
|
|
| 245 | + if ((++$i) > $showBefore) {
|
|
| 246 | 246 | break; |
| 247 | 247 | } |
| 248 | 248 | $outReflects->add($item['id']); |
| 249 | 249 | } |
| 250 | 250 | /** Добавляем текущую дату */ |
| 251 | -if (is_null($activeReflect)) { |
|
| 252 | - if (($hasCurrentReflect && !$selectCurrentReflect) || $appendCurrentReflect) { |
|
| 251 | +if (is_null($activeReflect)) {
|
|
| 252 | + if (($hasCurrentReflect && !$selectCurrentReflect) || $appendCurrentReflect) {
|
|
| 253 | 253 | $outReflects->add($originalCurrentReflect); |
| 254 | 254 | } |
| 255 | -} else { |
|
| 255 | +} else {
|
|
| 256 | 256 | $outReflects->add($activeReflect); |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** Берем оставшее число позиций с правой стороны */ |
| 260 | 260 | $i = 0; |
| 261 | -foreach ($rReflect as $item) { |
|
| 262 | - if ((++$i) > $showAfter) { |
|
| 261 | +foreach ($rReflect as $item) {
|
|
| 262 | + if ((++$i) > $showAfter) {
|
|
| 263 | 263 | break; |
| 264 | 264 | } |
| 265 | 265 | $outReflects->add($item['id']); |
@@ -267,11 +267,11 @@ discard block |
||
| 267 | 267 | |
| 268 | 268 | $sortDir = APIHelpers::getkey($params, 'sortDir', 'ASC'); |
| 269 | 269 | /** Сортируем результатирующий список */ |
| 270 | -$outReflects = $outReflects->sort(function ($a, $b) use ($sortDir, $dateFormat) { |
|
| 270 | +$outReflects = $outReflects->sort(function ($a, $b) use ($sortDir, $dateFormat) {
|
|
| 271 | 271 | $aDate = DateTime::createFromFormat($dateFormat, $a); |
| 272 | 272 | $bDate = DateTime::createFromFormat($dateFormat, $b); |
| 273 | 273 | $out = false; |
| 274 | - switch ($sortDir) { |
|
| 274 | + switch ($sortDir) {
|
|
| 275 | 275 | case 'ASC': |
| 276 | 276 | $out = $aDate->getTimestamp() - $bDate->getTimestamp(); |
| 277 | 277 | break; |
@@ -284,10 +284,10 @@ discard block |
||
| 284 | 284 | })->reindex()->unique(); |
| 285 | 285 | |
| 286 | 286 | /** Применяем шаблон к каждой отображаемой дате */ |
| 287 | -foreach ($outReflects as $reflectItem) { |
|
| 287 | +foreach ($outReflects as $reflectItem) {
|
|
| 288 | 288 | $tpl = (!is_null($activeReflect) && $activeReflect == $reflectItem) ? $activeReflectTPL : $reflectTPL; |
| 289 | 289 | |
| 290 | - $data = DLReflect::switchReflect($reflectType, function () use ($reflectItem, $DLAPI) { |
|
| 290 | + $data = DLReflect::switchReflect($reflectType, function () use ($reflectItem, $DLAPI) {
|
|
| 291 | 291 | list($vMonth, $vYear) = explode('-', $reflectItem, 2); |
| 292 | 292 | |
| 293 | 293 | return array( |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | 'monthName' => $DLAPI->getMsg('months.' . (int)$vMonth), |
| 296 | 296 | 'year' => $vYear, |
| 297 | 297 | ); |
| 298 | - }, function () use ($reflectItem) { |
|
| 298 | + }, function () use ($reflectItem) {
|
|
| 299 | 299 | return array( |
| 300 | 300 | 'year' => $reflectItem |
| 301 | 301 | ); |
@@ -321,9 +321,9 @@ discard block |
||
| 321 | 321 | /** |
| 322 | 322 | * Ну и выводим стек отладки если это нужно |
| 323 | 323 | */ |
| 324 | -if (isset($_SESSION['usertype']) && $_SESSION['usertype'] == 'manager') { |
|
| 324 | +if (isset($_SESSION['usertype']) && $_SESSION['usertype'] == 'manager') {
|
|
| 325 | 325 | $debug = $DLAPI->debug->showLog(); |
| 326 | -} else { |
|
| 326 | +} else {
|
|
| 327 | 327 | $debug = ''; |
| 328 | 328 | } |
| 329 | 329 | |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * year - по годам |
| 26 | 26 | */ |
| 27 | 27 | $reflectType = APIHelpers::getkey($params, 'reflectType', 'month'); |
| 28 | -if (!in_array($reflectType, array('year', 'month'))) { |
|
| 28 | +if ( ! in_array($reflectType, array('year', 'month'))) { |
|
| 29 | 29 | return ''; |
| 30 | 30 | } |
| 31 | 31 | |
@@ -50,9 +50,9 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | $activeReflectTPL = APIHelpers::getkey($params, 'activeReflectTPL', '@CODE: <li><span>[+title+]</span></li>'); |
| 52 | 52 | |
| 53 | -list($dateFormat, $sqlDateFormat, $reflectValidator) = DLReflect::switchReflect($reflectType, function () { |
|
| 53 | +list($dateFormat, $sqlDateFormat, $reflectValidator) = DLReflect::switchReflect($reflectType, function() { |
|
| 54 | 54 | return array('m-Y', '%m-%Y', array('DLReflect', 'validateMonth')); |
| 55 | -}, function () { |
|
| 55 | +}, function() { |
|
| 56 | 56 | return array('Y', '%Y', array('DLReflect', 'validateYear')); |
| 57 | 57 | }); |
| 58 | 58 | $tmp = $originalDate = date($dateFormat); |
@@ -65,13 +65,13 @@ discard block |
||
| 65 | 65 | * Если не указан в параметре, то генерируется автоматически текущая дата |
| 66 | 66 | */ |
| 67 | 67 | $currentReflect = APIHelpers::getkey($params, 'currentReflect', $tmp); |
| 68 | -if (!call_user_func($reflectValidator, $currentYear)) { |
|
| 68 | +if ( ! call_user_func($reflectValidator, $currentYear)) { |
|
| 69 | 69 | $currentReflect = $tmp; |
| 70 | 70 | } |
| 71 | 71 | $originalCurrentReflect = $currentReflect; |
| 72 | 72 | |
| 73 | 73 | $selectCurrentReflect = APIHelpers::getkey($params, 'selectCurrentReflect', 1); |
| 74 | -if (!$selectCurrentReflect && $currentReflect == $tmp) { |
|
| 74 | +if ( ! $selectCurrentReflect && $currentReflect == $tmp) { |
|
| 75 | 75 | $currentReflect = null; |
| 76 | 76 | } |
| 77 | 77 | |
@@ -99,9 +99,9 @@ discard block |
||
| 99 | 99 | */ |
| 100 | 100 | $tmp = APIHelpers::getkey($params, 'activeReflect', $currentReflect); |
| 101 | 101 | $tmpGet = APIHelpers::getkey($_GET, $reflectType, $tmp); |
| 102 | -if (!call_user_func($reflectValidator, $tmpGet)) { |
|
| 102 | +if ( ! call_user_func($reflectValidator, $tmpGet)) { |
|
| 103 | 103 | $activeReflect = $tmp; |
| 104 | - if (!call_user_func($reflectValidator, $activeReflect)) { |
|
| 104 | + if ( ! call_user_func($reflectValidator, $activeReflect)) { |
|
| 105 | 105 | $activeReflect = $currentReflect; |
| 106 | 106 | } |
| 107 | 107 | } else { |
@@ -181,11 +181,11 @@ discard block |
||
| 181 | 181 | $totalReflects = array(); |
| 182 | 182 | } |
| 183 | 183 | $totalReflects = new DLCollection($modx, $totalReflects); |
| 184 | -$totalReflects = $totalReflects->filter(function ($el) { |
|
| 185 | - return !empty($el['id']); |
|
| 184 | +$totalReflects = $totalReflects->filter(function($el) { |
|
| 185 | + return ! empty($el['id']); |
|
| 186 | 186 | }); |
| 187 | 187 | /** Добавляем активную дату в коллекцию */ |
| 188 | -if (!is_null($activeReflect)) { |
|
| 188 | +if ( ! is_null($activeReflect)) { |
|
| 189 | 189 | $totalReflects->add(array('id' => $activeReflect), $activeReflect); |
| 190 | 190 | } |
| 191 | 191 | $hasCurrentReflect = ($totalReflects->indexOf(array('id' => $originalCurrentReflect)) !== false); |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | $totalReflects->add(array('id' => $originalCurrentReflect), $originalCurrentReflect); |
| 196 | 196 | } |
| 197 | 197 | /** Сортируем даты по возрастанию */ |
| 198 | -$totalReflects->sort(function ($a, $b) use ($dateFormat) { |
|
| 198 | +$totalReflects->sort(function($a, $b) use ($dateFormat) { |
|
| 199 | 199 | $aDate = DateTime::createFromFormat($dateFormat, $a['id']); |
| 200 | 200 | $bDate = DateTime::createFromFormat($dateFormat, $b['id']); |
| 201 | 201 | |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | })->reindex(); |
| 204 | 204 | |
| 205 | 205 | /** Разделяем коллекцию дат на 2 части (до текущей даты и после) */ |
| 206 | -list($lReflect, $rReflect) = $totalReflects->partition(function ($key, $val) use ( |
|
| 206 | +list($lReflect, $rReflect) = $totalReflects->partition(function($key, $val) use ( |
|
| 207 | 207 | $activeReflect, |
| 208 | 208 | $originalDate, |
| 209 | 209 | $dateFormat |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | $showBefore = ($lReflect->count() < $limitBefore || empty($limitBefore)) ? $lReflect->count() : $limitBefore; |
| 228 | 228 | if (($rReflect->count() < $limitAfter) || empty($limitAfter)) { |
| 229 | 229 | $showAfter = $rReflect->count(); |
| 230 | - $showBefore += !empty($limitAfter) ? ($limitAfter - $rReflect->count()) : 0; |
|
| 230 | + $showBefore += ! empty($limitAfter) ? ($limitAfter - $rReflect->count()) : 0; |
|
| 231 | 231 | } else { |
| 232 | 232 | if ($limitBefore > 0) { |
| 233 | 233 | $showAfter = $limitAfter + ($limitBefore - $showBefore); |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | } |
| 250 | 250 | /** Добавляем текущую дату */ |
| 251 | 251 | if (is_null($activeReflect)) { |
| 252 | - if (($hasCurrentReflect && !$selectCurrentReflect) || $appendCurrentReflect) { |
|
| 252 | + if (($hasCurrentReflect && ! $selectCurrentReflect) || $appendCurrentReflect) { |
|
| 253 | 253 | $outReflects->add($originalCurrentReflect); |
| 254 | 254 | } |
| 255 | 255 | } else { |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | |
| 268 | 268 | $sortDir = APIHelpers::getkey($params, 'sortDir', 'ASC'); |
| 269 | 269 | /** Сортируем результатирующий список */ |
| 270 | -$outReflects = $outReflects->sort(function ($a, $b) use ($sortDir, $dateFormat) { |
|
| 270 | +$outReflects = $outReflects->sort(function($a, $b) use ($sortDir, $dateFormat) { |
|
| 271 | 271 | $aDate = DateTime::createFromFormat($dateFormat, $a); |
| 272 | 272 | $bDate = DateTime::createFromFormat($dateFormat, $b); |
| 273 | 273 | $out = false; |
@@ -285,9 +285,9 @@ discard block |
||
| 285 | 285 | |
| 286 | 286 | /** Применяем шаблон к каждой отображаемой дате */ |
| 287 | 287 | foreach ($outReflects as $reflectItem) { |
| 288 | - $tpl = (!is_null($activeReflect) && $activeReflect == $reflectItem) ? $activeReflectTPL : $reflectTPL; |
|
| 288 | + $tpl = ( ! is_null($activeReflect) && $activeReflect == $reflectItem) ? $activeReflectTPL : $reflectTPL; |
|
| 289 | 289 | |
| 290 | - $data = DLReflect::switchReflect($reflectType, function () use ($reflectItem, $DLAPI) { |
|
| 290 | + $data = DLReflect::switchReflect($reflectType, function() use ($reflectItem, $DLAPI) { |
|
| 291 | 291 | list($vMonth, $vYear) = explode('-', $reflectItem, 2); |
| 292 | 292 | |
| 293 | 293 | return array( |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | 'monthName' => $DLAPI->getMsg('months.' . (int)$vMonth), |
| 296 | 296 | 'year' => $vYear, |
| 297 | 297 | ); |
| 298 | - }, function () use ($reflectItem) { |
|
| 298 | + }, function() use ($reflectItem) { |
|
| 299 | 299 | return array( |
| 300 | 300 | 'year' => $reflectItem |
| 301 | 301 | ); |
@@ -399,8 +399,8 @@ discard block |
||
| 399 | 399 | /** |
| 400 | 400 | * @param $name |
| 401 | 401 | * @param $table |
| 402 | - * @param $alias |
|
| 403 | - * @return mixed |
|
| 402 | + * @param string $alias |
|
| 403 | + * @return string |
|
| 404 | 404 | */ |
| 405 | 405 | public function TableAlias($name, $table, $alias) |
| 406 | 406 | { |
@@ -465,7 +465,7 @@ discard block |
||
| 465 | 465 | /** |
| 466 | 466 | * Разбор JSON строки при помощи json_decode |
| 467 | 467 | * |
| 468 | - * @param $json string строка c JSON |
|
| 468 | + * @param string $json string строка c JSON |
|
| 469 | 469 | * @param array $config ассоциативный массив с настройками для json_decode |
| 470 | 470 | * @param bool $nop создавать ли пустой объект запрашиваемого типа |
| 471 | 471 | * @return array|mixed|xNop |
@@ -550,7 +550,7 @@ discard block |
||
| 550 | 550 | * Удаление определенных данных из массива |
| 551 | 551 | * |
| 552 | 552 | * @param array $data массив с данными |
| 553 | - * @param mixed $val значение которые необходимо удалить из массива |
|
| 553 | + * @param string $val значение которые необходимо удалить из массива |
|
| 554 | 554 | * @return array отчищеный массив с данными |
| 555 | 555 | */ |
| 556 | 556 | private function unsetArrayVal($data, $val) |
@@ -1180,7 +1180,7 @@ discard block |
||
| 1180 | 1180 | |
| 1181 | 1181 | /** |
| 1182 | 1182 | * @param array $item |
| 1183 | - * @param null $extSummary |
|
| 1183 | + * @param summary_DL_Extender $extSummary |
|
| 1184 | 1184 | * @param string $introField |
| 1185 | 1185 | * @param string $contentField |
| 1186 | 1186 | * @return mixed|string |
@@ -1700,8 +1700,8 @@ |
||
| 1700 | 1700 | $fltr_params = explode(':', $filter, 2); |
| 1701 | 1701 | $fltr = APIHelpers::getkey($fltr_params, 0, null); |
| 1702 | 1702 | /** |
| 1703 | - * @var tv_DL_filter|content_DL_filter $fltr_class |
|
| 1704 | - */ |
|
| 1703 | + * @var tv_DL_filter|content_DL_filter $fltr_class |
|
| 1704 | + */ |
|
| 1705 | 1705 | $fltr_class = $fltr . '_DL_filter'; |
| 1706 | 1706 | // check if the filter is implemented |
| 1707 | 1707 | if (!is_null($fltr)) { |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | $this->modx = $modx; |
| 196 | 196 | $this->setDebug(1); |
| 197 | 197 | |
| 198 | - if (!is_array($cfg) || empty($cfg)) { |
|
| 198 | + if ( ! is_array($cfg) || empty($cfg)) { |
|
| 199 | 199 | $cfg = $this->modx->Event->params; |
| 200 | 200 | } |
| 201 | 201 | } else { |
@@ -390,11 +390,11 @@ discard block |
||
| 390 | 390 | */ |
| 391 | 391 | public function getTable($name, $alias = '') |
| 392 | 392 | { |
| 393 | - if (!isset($this->_table[$name])) { |
|
| 393 | + if ( ! isset($this->_table[$name])) { |
|
| 394 | 394 | $this->_table[$name] = $this->modx->getFullTableName($name); |
| 395 | 395 | } |
| 396 | 396 | $table = $this->_table[$name]; |
| 397 | - if (!empty($alias) && is_scalar($alias)) { |
|
| 397 | + if ( ! empty($alias) && is_scalar($alias)) { |
|
| 398 | 398 | $table .= " as `" . $alias . "`"; |
| 399 | 399 | } |
| 400 | 400 | |
@@ -409,7 +409,7 @@ discard block |
||
| 409 | 409 | */ |
| 410 | 410 | public function TableAlias($name, $table, $alias) |
| 411 | 411 | { |
| 412 | - if (!$this->checkTableAlias($name, $table)) { |
|
| 412 | + if ( ! $this->checkTableAlias($name, $table)) { |
|
| 413 | 413 | $this->AddTable[$table][$name] = $alias; |
| 414 | 414 | } |
| 415 | 415 | |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | public function isErrorJSON($json) |
| 455 | 455 | { |
| 456 | 456 | $error = jsonHelper::json_last_error_msg(); |
| 457 | - if (!in_array($error, array('error_none', 'other'))) { |
|
| 457 | + if ( ! in_array($error, array('error_none', 'other'))) { |
|
| 458 | 458 | $this->debug->error($this->getMsg('json.' . $error) . ": " . $this->debug->dumpData($json, 'code'), 'JSON'); |
| 459 | 459 | $error = true; |
| 460 | 460 | } |
@@ -473,13 +473,13 @@ discard block |
||
| 473 | 473 | $extenders = $this->getCFGDef('extender', ''); |
| 474 | 474 | $extenders = explode(",", $extenders); |
| 475 | 475 | $tmp = $this->getCFGDef('requestActive', '') != '' || in_array('request', $extenders); |
| 476 | - if ($tmp && !$this->_loadExtender('request')) { |
|
| 476 | + if ($tmp && ! $this->_loadExtender('request')) { |
|
| 477 | 477 | //OR request in extender's parameter |
| 478 | 478 | throw new Exception('Error load request extender'); |
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | $tmp = $this->getCFGDef('summary', '') != '' || in_array('summary', $extenders); |
| 482 | - if ($tmp && !$this->_loadExtender('summary')) { |
|
| 482 | + if ($tmp && ! $this->_loadExtender('summary')) { |
|
| 483 | 483 | //OR summary in extender's parameter |
| 484 | 484 | throw new Exception('Error load summary extender'); |
| 485 | 485 | } |
@@ -491,7 +491,7 @@ discard block |
||
| 491 | 491 | $this->getCFGDef('TplCurrentPage', '') != '' || $this->getCFGDef('TplWrapPaginate', '') != '' || |
| 492 | 492 | $this->getCFGDef('pageLimit', '') != '' || $this->getCFGDef('pageAdjacents', '') != '' || |
| 493 | 493 | $this->getCFGDef('PaginateClass', '') != '' || $this->getCFGDef('TplNextP', '') != '' |
| 494 | - ) && !$this->_loadExtender('paginate') |
|
| 494 | + ) && ! $this->_loadExtender('paginate') |
|
| 495 | 495 | ) { |
| 496 | 496 | throw new Exception('Error load paginate extender'); |
| 497 | 497 | } else { |
@@ -658,7 +658,7 @@ discard block |
||
| 658 | 658 | if ($ext != '') { |
| 659 | 659 | $ext = explode(",", $ext); |
| 660 | 660 | foreach ($ext as $item) { |
| 661 | - if ($item != '' && !$this->_loadExtender($item)) { |
|
| 661 | + if ($item != '' && ! $this->_loadExtender($item)) { |
|
| 662 | 662 | throw new Exception('Error load ' . APIHelpers::e($item) . ' extender'); |
| 663 | 663 | } |
| 664 | 664 | } |
@@ -719,7 +719,7 @@ discard block |
||
| 719 | 719 | */ |
| 720 | 720 | public function sanitarIn($data, $sep = ',', $quote = true) |
| 721 | 721 | { |
| 722 | - if (!is_array($data)) { |
|
| 722 | + if ( ! is_array($data)) { |
|
| 723 | 723 | $data = explode($sep, $data); |
| 724 | 724 | } |
| 725 | 725 | $out = array(); |
@@ -856,7 +856,7 @@ discard block |
||
| 856 | 856 | protected function renderTree($data) |
| 857 | 857 | { |
| 858 | 858 | $out = ''; |
| 859 | - if (!empty($data['#childNodes'])) { |
|
| 859 | + if ( ! empty($data['#childNodes'])) { |
|
| 860 | 860 | foreach ($data['#childNodes'] as $item) { |
| 861 | 861 | $out .= $this->renderTree($item); |
| 862 | 862 | } |
@@ -895,7 +895,7 @@ discard block |
||
| 895 | 895 | public function parseLang($tpl) |
| 896 | 896 | { |
| 897 | 897 | $this->debug->debug(array("parseLang" => $tpl), "parseLang", 2, array('html')); |
| 898 | - if (is_scalar($tpl) && !empty($tpl)) { |
|
| 898 | + if (is_scalar($tpl) && ! empty($tpl)) { |
|
| 899 | 899 | if (preg_match_all("/\[\%([a-zA-Z0-9\.\_\-]+)\%\]/", $tpl, $match)) { |
| 900 | 900 | $langVal = array(); |
| 901 | 901 | foreach ($match[1] as $item) { |
@@ -970,7 +970,7 @@ discard block |
||
| 970 | 970 | { |
| 971 | 971 | $out = $data; |
| 972 | 972 | $docs = count($this->_docs) - $this->skippedDocs; |
| 973 | - if ((($this->getCFGDef("noneWrapOuter", "1") && $docs == 0) || $docs > 0) && !empty($this->ownerTPL)) { |
|
| 973 | + if ((($this->getCFGDef("noneWrapOuter", "1") && $docs == 0) || $docs > 0) && ! empty($this->ownerTPL)) { |
|
| 974 | 974 | $this->debug->debug("", "renderWrapTPL", 2); |
| 975 | 975 | $parse = true; |
| 976 | 976 | $plh = array($this->getCFGDef("sysKey", "dl") . ".wrap" => $data); |
@@ -993,7 +993,7 @@ discard block |
||
| 993 | 993 | } |
| 994 | 994 | $plh = $params; |
| 995 | 995 | } |
| 996 | - if ($parse && !empty($this->ownerTPL)) { |
|
| 996 | + if ($parse && ! empty($this->ownerTPL)) { |
|
| 997 | 997 | $this->debug->updateMessage( |
| 998 | 998 | array("render ownerTPL" => $this->ownerTPL, "With data" => print_r($plh, 1)), |
| 999 | 999 | "renderWrapTPL", |
@@ -1033,7 +1033,7 @@ discard block |
||
| 1033 | 1033 | $offset = $this->getCFGDef('reversePagination', |
| 1034 | 1034 | 0) && $this->extPaginate->currentPage() > 1 ? $this->extPaginate->totalPage() * $this->getCFGDef('display', |
| 1035 | 1035 | 0) - $this->extPaginate->totalDocs() : 0; |
| 1036 | - if ($this->getCFGDef('maxDocs', 0) && !$this->getCFGDef('reversePagination', |
|
| 1036 | + if ($this->getCFGDef('maxDocs', 0) && ! $this->getCFGDef('reversePagination', |
|
| 1037 | 1037 | 0) && $this->extPaginate->currentPage() == $this->extPaginate->totalPage() |
| 1038 | 1038 | ) { |
| 1039 | 1039 | $iteration += $this->getCFGDef('display', 0); |
@@ -1150,10 +1150,10 @@ discard block |
||
| 1150 | 1150 | $introField = $this->getCFGDef("introField", $introField); |
| 1151 | 1151 | $contentField = $this->getCFGDef("contentField", $contentField); |
| 1152 | 1152 | |
| 1153 | - if (!empty($introField) && !empty($item[$introField]) && mb_strlen($item[$introField], 'UTF-8') > 0) { |
|
| 1153 | + if ( ! empty($introField) && ! empty($item[$introField]) && mb_strlen($item[$introField], 'UTF-8') > 0) { |
|
| 1154 | 1154 | $out = $item[$introField]; |
| 1155 | 1155 | } else { |
| 1156 | - if (!empty($contentField) && !empty($item[$contentField]) && mb_strlen($item[$contentField], 'UTF-8') > 0) { |
|
| 1156 | + if ( ! empty($contentField) && ! empty($item[$contentField]) && mb_strlen($item[$contentField], 'UTF-8') > 0) { |
|
| 1157 | 1157 | $out = $extSummary->init($this, array( |
| 1158 | 1158 | "content" => $item[$contentField], |
| 1159 | 1159 | "action" => $this->getCFGDef("summary", ""), |
@@ -1222,7 +1222,7 @@ discard block |
||
| 1222 | 1222 | $flag = true; |
| 1223 | 1223 | |
| 1224 | 1224 | } else { |
| 1225 | - if (!class_exists($classname, false) && $classname != '') { |
|
| 1225 | + if ( ! class_exists($classname, false) && $classname != '') { |
|
| 1226 | 1226 | if (file_exists(dirname(__FILE__) . "/extender/" . $name . ".extender.inc")) { |
| 1227 | 1227 | include_once(dirname(__FILE__) . "/extender/" . $name . ".extender.inc"); |
| 1228 | 1228 | } |
@@ -1232,7 +1232,7 @@ discard block |
||
| 1232 | 1232 | $flag = true; |
| 1233 | 1233 | } |
| 1234 | 1234 | } |
| 1235 | - if (!$flag) { |
|
| 1235 | + if ( ! $flag) { |
|
| 1236 | 1236 | $this->debug->debug("Error load Extender " . $this->debug->dumpData($name)); |
| 1237 | 1237 | } |
| 1238 | 1238 | $this->debug->debugEnd('LoadExtender'); |
@@ -1290,7 +1290,7 @@ discard block |
||
| 1290 | 1290 | $this->debug->debug('clean IDs ' . $this->debug->dumpData($IDs) . ' with separator ' . $this->debug->dumpData($sep), |
| 1291 | 1291 | 'cleanIDs', 2); |
| 1292 | 1292 | $out = array(); |
| 1293 | - if (!is_array($IDs)) { |
|
| 1293 | + if ( ! is_array($IDs)) { |
|
| 1294 | 1294 | $IDs = explode($sep, $IDs); |
| 1295 | 1295 | } |
| 1296 | 1296 | foreach ($IDs as $item) { |
@@ -1326,7 +1326,7 @@ discard block |
||
| 1326 | 1326 | { |
| 1327 | 1327 | $out = array(); |
| 1328 | 1328 | foreach ($this->_docs as $doc => $val) { |
| 1329 | - if (isset($val[$userField]) && (($uniq && !in_array($val[$userField], $out)) || !$uniq)) { |
|
| 1329 | + if (isset($val[$userField]) && (($uniq && ! in_array($val[$userField], $out)) || ! $uniq)) { |
|
| 1330 | 1330 | $out[$doc] = $val[$userField]; |
| 1331 | 1331 | } |
| 1332 | 1332 | } |
@@ -1415,7 +1415,7 @@ discard block |
||
| 1415 | 1415 | $out['order'] = $tmp; |
| 1416 | 1416 | // no break |
| 1417 | 1417 | } |
| 1418 | - if ('' == $out['order'] || !in_array(strtoupper($out['order']), array('ASC', 'DESC'))) { |
|
| 1418 | + if ('' == $out['order'] || ! in_array(strtoupper($out['order']), array('ASC', 'DESC'))) { |
|
| 1419 | 1419 | $out['order'] = $orderDef; //Default |
| 1420 | 1420 | } |
| 1421 | 1421 | |
@@ -1510,21 +1510,21 @@ discard block |
||
| 1510 | 1510 | $children = array(); // children of each ID |
| 1511 | 1511 | $ids = array(); |
| 1512 | 1512 | foreach ($data as $i => $r) { |
| 1513 | - $row =& $data[$i]; |
|
| 1513 | + $row = & $data[$i]; |
|
| 1514 | 1514 | $id = $row[$idName]; |
| 1515 | 1515 | $pid = $row[$pidName]; |
| 1516 | - $children[$pid][$id] =& $row; |
|
| 1517 | - if (!isset($children[$id])) { |
|
| 1516 | + $children[$pid][$id] = & $row; |
|
| 1517 | + if ( ! isset($children[$id])) { |
|
| 1518 | 1518 | $children[$id] = array(); |
| 1519 | 1519 | } |
| 1520 | - $row['#childNodes'] =& $children[$id]; |
|
| 1520 | + $row['#childNodes'] = & $children[$id]; |
|
| 1521 | 1521 | $ids[$row[$idName]] = true; |
| 1522 | 1522 | } |
| 1523 | 1523 | // Root elements are elements with non-found PIDs. |
| 1524 | 1524 | $this->_tree = array(); |
| 1525 | 1525 | foreach ($data as $i => $r) { |
| 1526 | - $row =& $data[$i]; |
|
| 1527 | - if (!isset($ids[$row[$pidName]])) { |
|
| 1526 | + $row = & $data[$i]; |
|
| 1527 | + if ( ! isset($ids[$row[$pidName]])) { |
|
| 1528 | 1528 | $this->_tree[$row[$idName]] = $row; |
| 1529 | 1529 | } |
| 1530 | 1530 | } |
@@ -1540,10 +1540,10 @@ discard block |
||
| 1540 | 1540 | */ |
| 1541 | 1541 | public function getPK($full = true) |
| 1542 | 1542 | { |
| 1543 | - $idField = isset($this->idField) ? $this->idField: 'id'; |
|
| 1543 | + $idField = isset($this->idField) ? $this->idField : 'id'; |
|
| 1544 | 1544 | if ($full) { |
| 1545 | 1545 | $idField = '`' . $idField . '`'; |
| 1546 | - if (!empty($this->alias)) { |
|
| 1546 | + if ( ! empty($this->alias)) { |
|
| 1547 | 1547 | $idField = '`' . $this->alias . '`.' . $idField; |
| 1548 | 1548 | } |
| 1549 | 1549 | } |
@@ -1560,9 +1560,9 @@ discard block |
||
| 1560 | 1560 | public function getParentField($full = true) |
| 1561 | 1561 | { |
| 1562 | 1562 | $parentField = isset($this->parentField) ? $this->parentField : ''; |
| 1563 | - if ($full && !empty($parentField)) { |
|
| 1563 | + if ($full && ! empty($parentField)) { |
|
| 1564 | 1564 | $parentField = '`' . $parentField . '`'; |
| 1565 | - if (!empty($this->alias)) { |
|
| 1565 | + if ( ! empty($this->alias)) { |
|
| 1566 | 1566 | $parentField = '`' . $this->alias . '`.' . $parentField; |
| 1567 | 1567 | } |
| 1568 | 1568 | } |
@@ -1582,7 +1582,7 @@ discard block |
||
| 1582 | 1582 | $this->debug->debug("getFilters: " . $this->debug->dumpData($filter_string), 'getFilter', 1); |
| 1583 | 1583 | // the filter parameter tells us, which filters can be used in this query |
| 1584 | 1584 | $filter_string = trim($filter_string, ' ;'); |
| 1585 | - if (!$filter_string) { |
|
| 1585 | + if ( ! $filter_string) { |
|
| 1586 | 1586 | return; |
| 1587 | 1587 | } |
| 1588 | 1588 | $output = array('join' => '', 'where' => ''); |
@@ -1595,7 +1595,7 @@ discard block |
||
| 1595 | 1595 | $subfilters = $this->smartSplit($subfilters); |
| 1596 | 1596 | foreach ($subfilters as $subfilter) { |
| 1597 | 1597 | $subfilter = $this->getFilters(trim($subfilter)); |
| 1598 | - if (!$subfilter) { |
|
| 1598 | + if ( ! $subfilter) { |
|
| 1599 | 1599 | continue; |
| 1600 | 1600 | } |
| 1601 | 1601 | if ($subfilter['join']) { |
@@ -1605,14 +1605,14 @@ discard block |
||
| 1605 | 1605 | $wheres[] = $subfilter['where']; |
| 1606 | 1606 | } |
| 1607 | 1607 | } |
| 1608 | - $output['join'] = !empty($joins) ? implode(' ', $joins) : ''; |
|
| 1609 | - $output['where'] = !empty($wheres) ? '(' . implode($sql, $wheres) . ')' : ''; |
|
| 1608 | + $output['join'] = ! empty($joins) ? implode(' ', $joins) : ''; |
|
| 1609 | + $output['where'] = ! empty($wheres) ? '(' . implode($sql, $wheres) . ')' : ''; |
|
| 1610 | 1610 | } |
| 1611 | 1611 | } |
| 1612 | 1612 | |
| 1613 | - if (!$logic_op_found) { |
|
| 1613 | + if ( ! $logic_op_found) { |
|
| 1614 | 1614 | $filter = $this->loadFilter($filter_string); |
| 1615 | - if (!$filter) { |
|
| 1615 | + if ( ! $filter) { |
|
| 1616 | 1616 | $this->debug->warning('Error while loading DocLister filter "' . $this->debug->dumpData($filter_string) . '": check syntax!'); |
| 1617 | 1617 | $output = false; |
| 1618 | 1618 | } else { |
@@ -1646,8 +1646,8 @@ discard block |
||
| 1646 | 1646 | * @return $this |
| 1647 | 1647 | */ |
| 1648 | 1648 | public function setFiltersJoin($join = '') { |
| 1649 | - if (!empty($join)) { |
|
| 1650 | - if (!empty($this->_filters['join'])) { |
|
| 1649 | + if ( ! empty($join)) { |
|
| 1650 | + if ( ! empty($this->_filters['join'])) { |
|
| 1651 | 1651 | $this->_filters['join'] .= ' ' . $join; |
| 1652 | 1652 | } else { |
| 1653 | 1653 | $this->_filters['join'] = $join; |
@@ -1704,8 +1704,8 @@ discard block |
||
| 1704 | 1704 | */ |
| 1705 | 1705 | $fltr_class = $fltr . '_DL_filter'; |
| 1706 | 1706 | // check if the filter is implemented |
| 1707 | - if (!is_null($fltr)) { |
|
| 1708 | - if (!class_exists($fltr_class) && file_exists(__DIR__ . '/filter/' . $fltr . '.filter.php')) { |
|
| 1707 | + if ( ! is_null($fltr)) { |
|
| 1708 | + if ( ! class_exists($fltr_class) && file_exists(__DIR__ . '/filter/' . $fltr . '.filter.php')) { |
|
| 1709 | 1709 | require_once dirname(__FILE__) . '/filter/' . $fltr . '.filter.php'; |
| 1710 | 1710 | } |
| 1711 | 1711 | if (class_exists($fltr_class)) { |
@@ -1718,7 +1718,7 @@ discard block |
||
| 1718 | 1718 | } |
| 1719 | 1719 | } |
| 1720 | 1720 | } |
| 1721 | - if (!$out) { |
|
| 1721 | + if ( ! $out) { |
|
| 1722 | 1722 | $this->debug->error("Error load Filter: '{$this->debug->dumpData($filter)}'", 'Filter'); |
| 1723 | 1723 | } |
| 1724 | 1724 | |
@@ -17,8 +17,8 @@ discard block |
||
| 17 | 17 | /** |
| 18 | 18 | * Class DocLister |
| 19 | 19 | */ |
| 20 | -abstract class DocLister |
|
| 21 | -{ |
|
| 20 | +abstract class DocLister |
|
| 21 | +{
|
|
| 22 | 22 | /** |
| 23 | 23 | * Ключ в массиве $_REQUEST в котором находится алиас запрашиваемого документа |
| 24 | 24 | */ |
@@ -181,48 +181,48 @@ discard block |
||
| 181 | 181 | * @param int $startTime время запуска сниппета |
| 182 | 182 | * @throws Exception |
| 183 | 183 | */ |
| 184 | - public function __construct($modx, $cfg = array(), $startTime = null) |
|
| 185 | - { |
|
| 184 | + public function __construct($modx, $cfg = array(), $startTime = null) |
|
| 185 | + {
|
|
| 186 | 186 | $this->setTimeStart($startTime); |
| 187 | 187 | |
| 188 | - if (extension_loaded('mbstring')) { |
|
| 188 | + if (extension_loaded('mbstring')) {
|
|
| 189 | 189 | mb_internal_encoding("UTF-8"); |
| 190 | - } else { |
|
| 190 | + } else {
|
|
| 191 | 191 | throw new Exception('Not found php extension mbstring'); |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - if ($modx instanceof DocumentParser) { |
|
| 194 | + if ($modx instanceof DocumentParser) {
|
|
| 195 | 195 | $this->modx = $modx; |
| 196 | 196 | $this->setDebug(1); |
| 197 | 197 | |
| 198 | - if (!is_array($cfg) || empty($cfg)) { |
|
| 198 | + if (!is_array($cfg) || empty($cfg)) {
|
|
| 199 | 199 | $cfg = $this->modx->Event->params; |
| 200 | 200 | } |
| 201 | - } else { |
|
| 201 | + } else {
|
|
| 202 | 202 | throw new Exception('MODX var is not instaceof DocumentParser'); |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | $this->FS = \Helpers\FS::getInstance(); |
| 206 | 206 | $this->config = new \Helpers\Config($cfg); |
| 207 | 207 | |
| 208 | - if (isset($cfg['config'])) { |
|
| 208 | + if (isset($cfg['config'])) {
|
|
| 209 | 209 | $this->config->setPath(dirname(__DIR__))->loadConfig($cfg['config']); |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | - if ($this->config->setConfig($cfg) === false) { |
|
| 212 | + if ($this->config->setConfig($cfg) === false) {
|
|
| 213 | 213 | throw new Exception('no parameters to run DocLister'); |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | $this->loadLang(array('core', 'json')); |
| 217 | 217 | $this->setDebug($this->getCFGDef('debug', 0)); |
| 218 | 218 | |
| 219 | - if ($this->checkDL()) { |
|
| 219 | + if ($this->checkDL()) {
|
|
| 220 | 220 | $cfg = array(); |
| 221 | 221 | $idType = $this->getCFGDef('idType', ''); |
| 222 | - if (empty($idType) && $this->getCFGDef('documents', '') != '') { |
|
| 222 | + if (empty($idType) && $this->getCFGDef('documents', '') != '') {
|
|
| 223 | 223 | $idType = 'documents'; |
| 224 | 224 | } |
| 225 | - switch ($idType) { |
|
| 225 | + switch ($idType) {
|
|
| 226 | 226 | case 'documents': |
| 227 | 227 | $IDs = $this->getCFGDef('documents'); |
| 228 | 228 | $cfg['idType'] = "documents"; |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | case 'parents': |
| 231 | 231 | default: |
| 232 | 232 | $cfg['idType'] = "parents"; |
| 233 | - if (($IDs = $this->getCFGDef('parents', '')) === '') { |
|
| 233 | + if (($IDs = $this->getCFGDef('parents', '')) === '') {
|
|
| 234 | 234 | $IDs = $this->getCurrentMODXPageID(); |
| 235 | 235 | } |
| 236 | 236 | break; |
@@ -249,12 +249,12 @@ discard block |
||
| 249 | 249 | |
| 250 | 250 | $this->setLocate(); |
| 251 | 251 | |
| 252 | - if ($this->getCFGDef("customLang")) { |
|
| 252 | + if ($this->getCFGDef("customLang")) {
|
|
| 253 | 253 | $this->getCustomLang(); |
| 254 | 254 | } |
| 255 | 255 | $this->loadExtender($this->getCFGDef("extender", "")); |
| 256 | 256 | |
| 257 | - if ($this->checkExtender('request')) { |
|
| 257 | + if ($this->checkExtender('request')) {
|
|
| 258 | 258 | $this->extender['request']->init($this, $this->getCFGDef("requestActive", "")); |
| 259 | 259 | } |
| 260 | 260 | $this->_filters = $this->getFilters($this->getCFGDef('filters', '')); |
@@ -266,25 +266,25 @@ discard block |
||
| 266 | 266 | * @param string $str строка с фильтром |
| 267 | 267 | * @return array массив субфильтров |
| 268 | 268 | */ |
| 269 | - public function smartSplit($str) |
|
| 270 | - { |
|
| 269 | + public function smartSplit($str) |
|
| 270 | + {
|
|
| 271 | 271 | $res = array(); |
| 272 | 272 | $cur = ''; |
| 273 | 273 | $open = 0; |
| 274 | 274 | $strlen = mb_strlen($str, 'UTF-8'); |
| 275 | - for ($i = 0; $i <= $strlen; $i++) { |
|
| 275 | + for ($i = 0; $i <= $strlen; $i++) {
|
|
| 276 | 276 | $e = mb_substr($str, $i, 1, 'UTF-8'); |
| 277 | - switch ($e) { |
|
| 277 | + switch ($e) {
|
|
| 278 | 278 | case '\\': |
| 279 | 279 | $cur .= $e; |
| 280 | 280 | $cur .= mb_substr($str, ++$i, 1, 'UTF-8'); |
| 281 | 281 | break; |
| 282 | 282 | case ')': |
| 283 | 283 | $open--; |
| 284 | - if ($open == 0) { |
|
| 284 | + if ($open == 0) {
|
|
| 285 | 285 | $res[] = $cur . ')'; |
| 286 | 286 | $cur = ''; |
| 287 | - } else { |
|
| 287 | + } else {
|
|
| 288 | 288 | $cur .= $e; |
| 289 | 289 | } |
| 290 | 290 | break; |
@@ -293,10 +293,10 @@ discard block |
||
| 293 | 293 | $cur .= $e; |
| 294 | 294 | break; |
| 295 | 295 | case ';': |
| 296 | - if ($open == 0) { |
|
| 296 | + if ($open == 0) {
|
|
| 297 | 297 | $res[] = $cur; |
| 298 | 298 | $cur = ''; |
| 299 | - } else { |
|
| 299 | + } else {
|
|
| 300 | 300 | $cur .= $e; |
| 301 | 301 | } |
| 302 | 302 | break; |
@@ -305,7 +305,7 @@ discard block |
||
| 305 | 305 | } |
| 306 | 306 | } |
| 307 | 307 | $cur = preg_replace("/(\))$/u", '', $cur); |
| 308 | - if ($cur != '') { |
|
| 308 | + if ($cur != '') {
|
|
| 309 | 309 | $res[] = $cur; |
| 310 | 310 | } |
| 311 | 311 | |
@@ -316,8 +316,8 @@ discard block |
||
| 316 | 316 | * Трансформация объекта в строку |
| 317 | 317 | * @return string последний ответ от DocLister'а |
| 318 | 318 | */ |
| 319 | - public function __toString() |
|
| 320 | - { |
|
| 319 | + public function __toString() |
|
| 320 | + {
|
|
| 321 | 321 | return $this->outData; |
| 322 | 322 | } |
| 323 | 323 | |
@@ -325,8 +325,8 @@ discard block |
||
| 325 | 325 | * Установить время запуска сниппета |
| 326 | 326 | * @param float|null $time |
| 327 | 327 | */ |
| 328 | - public function setTimeStart($time = null) |
|
| 329 | - { |
|
| 328 | + public function setTimeStart($time = null) |
|
| 329 | + {
|
|
| 330 | 330 | $this->_timeStart = is_null($time) ? microtime(true) : $time; |
| 331 | 331 | } |
| 332 | 332 | |
@@ -335,8 +335,8 @@ discard block |
||
| 335 | 335 | * |
| 336 | 336 | * @return int |
| 337 | 337 | */ |
| 338 | - public function getTimeStart() |
|
| 339 | - { |
|
| 338 | + public function getTimeStart() |
|
| 339 | + {
|
|
| 340 | 340 | return $this->_timeStart; |
| 341 | 341 | } |
| 342 | 342 | |
@@ -344,27 +344,27 @@ discard block |
||
| 344 | 344 | * Установка режима отладки |
| 345 | 345 | * @param int $flag режим отладки |
| 346 | 346 | */ |
| 347 | - public function setDebug($flag = 0) |
|
| 348 | - { |
|
| 347 | + public function setDebug($flag = 0) |
|
| 348 | + {
|
|
| 349 | 349 | $flag = abs((int)$flag); |
| 350 | - if ($this->_debugMode != $flag) { |
|
| 350 | + if ($this->_debugMode != $flag) {
|
|
| 351 | 351 | $this->_debugMode = $flag; |
| 352 | 352 | $this->debug = null; |
| 353 | - if ($this->_debugMode > 0) { |
|
| 354 | - if (isset($_SESSION['usertype']) && $_SESSION['usertype'] == 'manager') { |
|
| 353 | + if ($this->_debugMode > 0) {
|
|
| 354 | + if (isset($_SESSION['usertype']) && $_SESSION['usertype'] == 'manager') {
|
|
| 355 | 355 | error_reporting(E_ALL ^ E_NOTICE); |
| 356 | 356 | ini_set('display_errors', 1); |
| 357 | 357 | } |
| 358 | 358 | $dir = dirname(dirname(__FILE__)); |
| 359 | - if (file_exists($dir . "/lib/DLdebug.class.php")) { |
|
| 359 | + if (file_exists($dir . "/lib/DLdebug.class.php")) {
|
|
| 360 | 360 | include_once($dir . "/lib/DLdebug.class.php"); |
| 361 | - if (class_exists("DLdebug", false)) { |
|
| 361 | + if (class_exists("DLdebug", false)) {
|
|
| 362 | 362 | $this->debug = new DLdebug($this); |
| 363 | 363 | } |
| 364 | 364 | } |
| 365 | 365 | } |
| 366 | 366 | |
| 367 | - if (is_null($this->debug)) { |
|
| 367 | + if (is_null($this->debug)) {
|
|
| 368 | 368 | $this->debug = new xNop(); |
| 369 | 369 | $this->_debugMode = 0; |
| 370 | 370 | error_reporting(0); |
@@ -376,8 +376,8 @@ discard block |
||
| 376 | 376 | /** |
| 377 | 377 | * Информация о режиме отладки |
| 378 | 378 | */ |
| 379 | - public function getDebug() |
|
| 380 | - { |
|
| 379 | + public function getDebug() |
|
| 380 | + {
|
|
| 381 | 381 | return $this->_debugMode; |
| 382 | 382 | } |
| 383 | 383 | |
@@ -388,13 +388,13 @@ discard block |
||
| 388 | 388 | * @param string $alias желаемый алиас таблицы |
| 389 | 389 | * @return string имя таблицы с префиксом и алиасом |
| 390 | 390 | */ |
| 391 | - public function getTable($name, $alias = '') |
|
| 392 | - { |
|
| 393 | - if (!isset($this->_table[$name])) { |
|
| 391 | + public function getTable($name, $alias = '') |
|
| 392 | + {
|
|
| 393 | + if (!isset($this->_table[$name])) {
|
|
| 394 | 394 | $this->_table[$name] = $this->modx->getFullTableName($name); |
| 395 | 395 | } |
| 396 | 396 | $table = $this->_table[$name]; |
| 397 | - if (!empty($alias) && is_scalar($alias)) { |
|
| 397 | + if (!empty($alias) && is_scalar($alias)) {
|
|
| 398 | 398 | $table .= " as `" . $alias . "`"; |
| 399 | 399 | } |
| 400 | 400 | |
@@ -407,9 +407,9 @@ discard block |
||
| 407 | 407 | * @param $alias |
| 408 | 408 | * @return mixed |
| 409 | 409 | */ |
| 410 | - public function TableAlias($name, $table, $alias) |
|
| 411 | - { |
|
| 412 | - if (!$this->checkTableAlias($name, $table)) { |
|
| 410 | + public function TableAlias($name, $table, $alias) |
|
| 411 | + {
|
|
| 412 | + if (!$this->checkTableAlias($name, $table)) {
|
|
| 413 | 413 | $this->AddTable[$table][$name] = $alias; |
| 414 | 414 | } |
| 415 | 415 | |
@@ -421,8 +421,8 @@ discard block |
||
| 421 | 421 | * @param $table |
| 422 | 422 | * @return bool |
| 423 | 423 | */ |
| 424 | - public function checkTableAlias($name, $table) |
|
| 425 | - { |
|
| 424 | + public function checkTableAlias($name, $table) |
|
| 425 | + {
|
|
| 426 | 426 | return isset($this->AddTable[$table][$name]); |
| 427 | 427 | } |
| 428 | 428 | |
@@ -434,8 +434,8 @@ discard block |
||
| 434 | 434 | * @param bool $nop создавать ли пустой объект запрашиваемого типа |
| 435 | 435 | * @return array|mixed|xNop |
| 436 | 436 | */ |
| 437 | - public function jsonDecode($json, $config = array(), $nop = false) |
|
| 438 | - { |
|
| 437 | + public function jsonDecode($json, $config = array(), $nop = false) |
|
| 438 | + {
|
|
| 439 | 439 | $this->debug->debug('Decode JSON: ' . $this->debug->dumpData($json) . "\r\nwith config: " . $this->debug->dumpData($config), |
| 440 | 440 | 'jsonDecode', 2); |
| 441 | 441 | $config = jsonHelper::jsonDecode($json, $config, $nop); |
@@ -451,10 +451,10 @@ discard block |
||
| 451 | 451 | * @param $json string строка с JSON для записи в лог при отладке |
| 452 | 452 | * @return bool|string |
| 453 | 453 | */ |
| 454 | - public function isErrorJSON($json) |
|
| 455 | - { |
|
| 454 | + public function isErrorJSON($json) |
|
| 455 | + {
|
|
| 456 | 456 | $error = jsonHelper::json_last_error_msg(); |
| 457 | - if (!in_array($error, array('error_none', 'other'))) { |
|
| 457 | + if (!in_array($error, array('error_none', 'other'))) {
|
|
| 458 | 458 | $this->debug->error($this->getMsg('json.' . $error) . ": " . $this->debug->dumpData($json, 'code'), 'JSON'); |
| 459 | 459 | $error = true; |
| 460 | 460 | } |
@@ -466,20 +466,20 @@ discard block |
||
| 466 | 466 | * Проверка параметров и загрузка необходимых экстендеров |
| 467 | 467 | * return boolean статус загрузки |
| 468 | 468 | */ |
| 469 | - public function checkDL() |
|
| 470 | - { |
|
| 469 | + public function checkDL() |
|
| 470 | + {
|
|
| 471 | 471 | $this->debug->debug('Check DocLister parameters', 'checkDL', 2); |
| 472 | 472 | $flag = true; |
| 473 | 473 | $extenders = $this->getCFGDef('extender', ''); |
| 474 | 474 | $extenders = explode(",", $extenders); |
| 475 | 475 | $tmp = $this->getCFGDef('requestActive', '') != '' || in_array('request', $extenders); |
| 476 | - if ($tmp && !$this->_loadExtender('request')) { |
|
| 476 | + if ($tmp && !$this->_loadExtender('request')) {
|
|
| 477 | 477 | //OR request in extender's parameter |
| 478 | 478 | throw new Exception('Error load request extender'); |
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | $tmp = $this->getCFGDef('summary', '') != '' || in_array('summary', $extenders); |
| 482 | - if ($tmp && !$this->_loadExtender('summary')) { |
|
| 482 | + if ($tmp && !$this->_loadExtender('summary')) {
|
|
| 483 | 483 | //OR summary in extender's parameter |
| 484 | 484 | throw new Exception('Error load summary extender'); |
| 485 | 485 | } |
@@ -492,15 +492,15 @@ discard block |
||
| 492 | 492 | $this->getCFGDef('pageLimit', '') != '' || $this->getCFGDef('pageAdjacents', '') != '' || |
| 493 | 493 | $this->getCFGDef('PaginateClass', '') != '' || $this->getCFGDef('TplNextP', '') != '' |
| 494 | 494 | ) && !$this->_loadExtender('paginate') |
| 495 | - ) { |
|
| 495 | + ) {
|
|
| 496 | 496 | throw new Exception('Error load paginate extender'); |
| 497 | - } else { |
|
| 498 | - if ((int)$this->getCFGDef('display', 0) == 0) { |
|
| 497 | + } else {
|
|
| 498 | + if ((int)$this->getCFGDef('display', 0) == 0) {
|
|
| 499 | 499 | $extenders = $this->unsetArrayVal($extenders, 'paginate'); |
| 500 | 500 | } |
| 501 | 501 | } |
| 502 | 502 | |
| 503 | - if ($this->getCFGDef('prepare', '') != '' || $this->getCFGDef('prepareWrap') != '') { |
|
| 503 | + if ($this->getCFGDef('prepare', '') != '' || $this->getCFGDef('prepareWrap') != '') {
|
|
| 504 | 504 | $this->_loadExtender('prepare'); |
| 505 | 505 | } |
| 506 | 506 | |
@@ -517,14 +517,14 @@ discard block |
||
| 517 | 517 | * @param mixed $val значение которые необходимо удалить из массива |
| 518 | 518 | * @return array отчищеный массив с данными |
| 519 | 519 | */ |
| 520 | - private function unsetArrayVal($data, $val) |
|
| 521 | - { |
|
| 520 | + private function unsetArrayVal($data, $val) |
|
| 521 | + {
|
|
| 522 | 522 | $out = array(); |
| 523 | - if (is_array($data)) { |
|
| 524 | - foreach ($data as $item) { |
|
| 525 | - if ($item != $val) { |
|
| 523 | + if (is_array($data)) {
|
|
| 524 | + foreach ($data as $item) {
|
|
| 525 | + if ($item != $val) {
|
|
| 526 | 526 | $out[] = $item; |
| 527 | - } else { |
|
| 527 | + } else {
|
|
| 528 | 528 | continue; |
| 529 | 529 | } |
| 530 | 530 | } |
@@ -539,14 +539,14 @@ discard block |
||
| 539 | 539 | * @param int $id уникальный идентификатор страницы |
| 540 | 540 | * @return string URL страницы |
| 541 | 541 | */ |
| 542 | - public function getUrl($id = 0) |
|
| 543 | - { |
|
| 542 | + public function getUrl($id = 0) |
|
| 543 | + {
|
|
| 544 | 544 | $id = ((int)$id > 0) ? (int)$id : $this->getCurrentMODXPageID(); |
| 545 | 545 | |
| 546 | 546 | $link = $this->checkExtender('request') ? $this->extender['request']->getLink() : $this->getRequest(); |
| 547 | - if ($id == $this->modx->config['site_start']) { |
|
| 547 | + if ($id == $this->modx->config['site_start']) {
|
|
| 548 | 548 | $url = $this->modx->config['site_url'] . ($link != '' ? "?{$link}" : ""); |
| 549 | - } else { |
|
| 549 | + } else {
|
|
| 550 | 550 | $url = $this->modx->makeUrl($id, '', $link, $this->getCFGDef('urlScheme', '')); |
| 551 | 551 | } |
| 552 | 552 | |
@@ -574,20 +574,20 @@ discard block |
||
| 574 | 574 | * @param string $tpl шаблон |
| 575 | 575 | * @return string |
| 576 | 576 | */ |
| 577 | - public function render($tpl = '') |
|
| 578 | - { |
|
| 577 | + public function render($tpl = '') |
|
| 578 | + {
|
|
| 579 | 579 | $this->debug->debug(array('Render data with template ' => $tpl), 'render', 2, array('html')); |
| 580 | 580 | $out = ''; |
| 581 | - if (1 == $this->getCFGDef('tree', '0')) { |
|
| 582 | - foreach ($this->_tree as $item) { |
|
| 581 | + if (1 == $this->getCFGDef('tree', '0')) {
|
|
| 582 | + foreach ($this->_tree as $item) {
|
|
| 583 | 583 | $out .= $this->renderTree($item); |
| 584 | 584 | } |
| 585 | 585 | $out = $this->renderWrap($out); |
| 586 | - } else { |
|
| 586 | + } else {
|
|
| 587 | 587 | $out = $this->_render($tpl); |
| 588 | 588 | } |
| 589 | 589 | |
| 590 | - if ($out) { |
|
| 590 | + if ($out) {
|
|
| 591 | 591 | $this->outData = DLTemplate::getInstance($this->modx)->parseDocumentSource($out); |
| 592 | 592 | } |
| 593 | 593 | $this->debug->debugEnd('render'); |
@@ -604,8 +604,8 @@ discard block |
||
| 604 | 604 | * |
| 605 | 605 | * @return int |
| 606 | 606 | */ |
| 607 | - public function getCurrentMODXPageID() |
|
| 608 | - { |
|
| 607 | + public function getCurrentMODXPageID() |
|
| 608 | + {
|
|
| 609 | 609 | $id = isset($this->modx->documentIdentifier) ? (int)$this->modx->documentIdentifier : 0; |
| 610 | 610 | $docData = isset($this->modx->documentObject) ? $this->modx->documentObject : array(); |
| 611 | 611 | |
@@ -621,9 +621,9 @@ discard block |
||
| 621 | 621 | * @param integer $line error on line |
| 622 | 622 | * @param array $trace stack trace |
| 623 | 623 | */ |
| 624 | - public function ErrorLogger($message, $code, $file, $line, $trace) |
|
| 625 | - { |
|
| 626 | - if (abs($this->getCFGDef('debug', '0')) == '1') { |
|
| 624 | + public function ErrorLogger($message, $code, $file, $line, $trace) |
|
| 625 | + {
|
|
| 626 | + if (abs($this->getCFGDef('debug', '0')) == '1') {
|
|
| 627 | 627 | $out = "CODE #" . $code . "<br />"; |
| 628 | 628 | $out .= "on file: " . $file . ":" . $line . "<br />"; |
| 629 | 629 | $out .= "<pre>"; |
@@ -640,8 +640,8 @@ discard block |
||
| 640 | 640 | * |
| 641 | 641 | * @return DocumentParser |
| 642 | 642 | */ |
| 643 | - public function getMODX() |
|
| 644 | - { |
|
| 643 | + public function getMODX() |
|
| 644 | + {
|
|
| 645 | 645 | return $this->modx; |
| 646 | 646 | } |
| 647 | 647 | |
@@ -652,13 +652,13 @@ discard block |
||
| 652 | 652 | * @return boolean status load extenders |
| 653 | 653 | * @throws Exception |
| 654 | 654 | */ |
| 655 | - public function loadExtender($ext = '') |
|
| 656 | - { |
|
| 655 | + public function loadExtender($ext = '') |
|
| 656 | + {
|
|
| 657 | 657 | $out = true; |
| 658 | - if ($ext != '') { |
|
| 658 | + if ($ext != '') {
|
|
| 659 | 659 | $ext = explode(",", $ext); |
| 660 | - foreach ($ext as $item) { |
|
| 661 | - if ($item != '' && !$this->_loadExtender($item)) { |
|
| 660 | + foreach ($ext as $item) {
|
|
| 661 | + if ($item != '' && !$this->_loadExtender($item)) {
|
|
| 662 | 662 | throw new Exception('Error load ' . APIHelpers::e($item) . ' extender'); |
| 663 | 663 | } |
| 664 | 664 | } |
@@ -674,8 +674,8 @@ discard block |
||
| 674 | 674 | * @param mixed $def значение по умолчанию, если в конфиге нет искомого параметра |
| 675 | 675 | * @return mixed значение из конфига |
| 676 | 676 | */ |
| 677 | - public function getCFGDef($name, $def = null) |
|
| 678 | - { |
|
| 677 | + public function getCFGDef($name, $def = null) |
|
| 678 | + {
|
|
| 679 | 679 | return $this->config->getCFGDef($name, $def); |
| 680 | 680 | } |
| 681 | 681 | |
@@ -687,15 +687,15 @@ discard block |
||
| 687 | 687 | * @param string $key ключ локального плейсхолдера |
| 688 | 688 | * @return string |
| 689 | 689 | */ |
| 690 | - public function toPlaceholders($data, $set = 0, $key = 'contentPlaceholder') |
|
| 691 | - { |
|
| 690 | + public function toPlaceholders($data, $set = 0, $key = 'contentPlaceholder') |
|
| 691 | + {
|
|
| 692 | 692 | $this->debug->debug(null, 'toPlaceholders', 2); |
| 693 | - if ($set == 0) { |
|
| 693 | + if ($set == 0) {
|
|
| 694 | 694 | $set = $this->getCFGDef('contentPlaceholder', 0); |
| 695 | 695 | } |
| 696 | 696 | $this->_plh[$key] = $data; |
| 697 | 697 | $id = $this->getCFGDef('id', ''); |
| 698 | - if ($id != '') { |
|
| 698 | + if ($id != '') {
|
|
| 699 | 699 | $id .= "."; |
| 700 | 700 | } |
| 701 | 701 | $out = DLTemplate::getInstance($this->getMODX())->toPlaceholders($data, $set, $key, $id); |
@@ -717,14 +717,14 @@ discard block |
||
| 717 | 717 | * @param boolean $quote заключать ли данные на выходе в кавычки |
| 718 | 718 | * @return string обработанная строка |
| 719 | 719 | */ |
| 720 | - public function sanitarIn($data, $sep = ',', $quote = true) |
|
| 721 | - { |
|
| 722 | - if (!is_array($data)) { |
|
| 720 | + public function sanitarIn($data, $sep = ',', $quote = true) |
|
| 721 | + {
|
|
| 722 | + if (!is_array($data)) {
|
|
| 723 | 723 | $data = explode($sep, $data); |
| 724 | 724 | } |
| 725 | 725 | $out = array(); |
| 726 | - foreach ($data as $item) { |
|
| 727 | - if ($item !== '') { |
|
| 726 | + foreach ($data as $item) {
|
|
| 727 | + if ($item !== '') {
|
|
| 728 | 728 | $out[] = $this->modx->db->escape($item); |
| 729 | 729 | } |
| 730 | 730 | } |
@@ -745,12 +745,12 @@ discard block |
||
| 745 | 745 | * @param string $lang имя языкового пакета |
| 746 | 746 | * @return array |
| 747 | 747 | */ |
| 748 | - public function getCustomLang($lang = '') |
|
| 749 | - { |
|
| 750 | - if (empty($lang)) { |
|
| 748 | + public function getCustomLang($lang = '') |
|
| 749 | + {
|
|
| 750 | + if (empty($lang)) {
|
|
| 751 | 751 | $lang = $this->getCFGDef('lang', $this->modx->config['manager_language']); |
| 752 | 752 | } |
| 753 | - if (file_exists(dirname(dirname(__FILE__)) . "/lang/" . $lang . ".php")) { |
|
| 753 | + if (file_exists(dirname(dirname(__FILE__)) . "/lang/" . $lang . ".php")) {
|
|
| 754 | 754 | $tmp = include(dirname(__FILE__) . "/lang/" . $lang . ".php"); |
| 755 | 755 | $this->_customLang = is_array($tmp) ? $tmp : array(); |
| 756 | 756 | } |
@@ -766,25 +766,25 @@ discard block |
||
| 766 | 766 | * @param boolean $rename Переименовывать ли элементы массива |
| 767 | 767 | * @return array массив с лексиконом |
| 768 | 768 | */ |
| 769 | - public function loadLang($name = 'core', $lang = '', $rename = true) |
|
| 770 | - { |
|
| 771 | - if (empty($lang)) { |
|
| 769 | + public function loadLang($name = 'core', $lang = '', $rename = true) |
|
| 770 | + {
|
|
| 771 | + if (empty($lang)) {
|
|
| 772 | 772 | $lang = $this->getCFGDef('lang', $this->modx->config['manager_language']); |
| 773 | 773 | } |
| 774 | 774 | |
| 775 | 775 | $this->debug->debug('Load language ' . $this->debug->dumpData($name) . "." . $this->debug->dumpData($lang), |
| 776 | 776 | 'loadlang', 2); |
| 777 | - if (is_scalar($name)) { |
|
| 777 | + if (is_scalar($name)) {
|
|
| 778 | 778 | $name = array($name); |
| 779 | 779 | } |
| 780 | - foreach ($name as $n) { |
|
| 781 | - if (file_exists(dirname(__FILE__) . "/lang/" . $lang . "/" . $n . ".inc.php")) { |
|
| 780 | + foreach ($name as $n) {
|
|
| 781 | + if (file_exists(dirname(__FILE__) . "/lang/" . $lang . "/" . $n . ".inc.php")) {
|
|
| 782 | 782 | $tmp = include(dirname(__FILE__) . "/lang/" . $lang . "/" . $n . ".inc.php"); |
| 783 | - if (is_array($tmp)) { |
|
| 783 | + if (is_array($tmp)) {
|
|
| 784 | 784 | /** |
| 785 | 785 | * Переименовыываем элементы массива из array('test'=>'data') в array('name.test'=>'data') |
| 786 | 786 | */ |
| 787 | - if ($rename) { |
|
| 787 | + if ($rename) {
|
|
| 788 | 788 | $tmp = $this->renameKeyArr($tmp, $n, '', '.'); |
| 789 | 789 | } |
| 790 | 790 | $this->_lang = array_merge($this->_lang, $tmp); |
@@ -803,11 +803,11 @@ discard block |
||
| 803 | 803 | * @param string $def Строка по умолчанию, если запись в языковом пакете не будет обнаружена |
| 804 | 804 | * @return string строка в соответствии с текущими языковыми настройками |
| 805 | 805 | */ |
| 806 | - public function getMsg($name, $def = '') |
|
| 807 | - { |
|
| 808 | - if (isset($this->_customLang[$name])) { |
|
| 806 | + public function getMsg($name, $def = '') |
|
| 807 | + {
|
|
| 808 | + if (isset($this->_customLang[$name])) {
|
|
| 809 | 809 | $say = $this->_customLang[$name]; |
| 810 | - } else { |
|
| 810 | + } else {
|
|
| 811 | 811 | $say = \APIHelpers::getkey($this->_lang, $name, $def); |
| 812 | 812 | } |
| 813 | 813 | |
@@ -823,8 +823,8 @@ discard block |
||
| 823 | 823 | * @param string $sep разделитель суффиксов, префиксов и ключей массива |
| 824 | 824 | * @return array массив с переименованными ключами |
| 825 | 825 | */ |
| 826 | - public function renameKeyArr($data, $prefix = '', $suffix = '', $sep = '.') |
|
| 827 | - { |
|
| 826 | + public function renameKeyArr($data, $prefix = '', $suffix = '', $sep = '.') |
|
| 827 | + {
|
|
| 828 | 828 | return \APIHelpers::renameKeyArr($data, $prefix, $suffix, $sep); |
| 829 | 829 | } |
| 830 | 830 | |
@@ -834,12 +834,12 @@ discard block |
||
| 834 | 834 | * @param string $locale локаль |
| 835 | 835 | * @return string имя установленной локали |
| 836 | 836 | */ |
| 837 | - public function setLocate($locale = '') |
|
| 838 | - { |
|
| 839 | - if ('' == $locale) { |
|
| 837 | + public function setLocate($locale = '') |
|
| 838 | + {
|
|
| 839 | + if ('' == $locale) {
|
|
| 840 | 840 | $locale = $this->getCFGDef('locale', ''); |
| 841 | 841 | } |
| 842 | - if ('' != $locale) { |
|
| 842 | + if ('' != $locale) {
|
|
| 843 | 843 | setlocale(LC_ALL, $locale); |
| 844 | 844 | } |
| 845 | 845 | |
@@ -853,11 +853,11 @@ discard block |
||
| 853 | 853 | * @param array $data массив сформированный как дерево |
| 854 | 854 | * @return string строка для отображения пользователю |
| 855 | 855 | */ |
| 856 | - protected function renderTree($data) |
|
| 857 | - { |
|
| 856 | + protected function renderTree($data) |
|
| 857 | + {
|
|
| 858 | 858 | $out = ''; |
| 859 | - if (!empty($data['#childNodes'])) { |
|
| 860 | - foreach ($data['#childNodes'] as $item) { |
|
| 859 | + if (!empty($data['#childNodes'])) {
|
|
| 860 | + foreach ($data['#childNodes'] as $item) {
|
|
| 861 | 861 | $out .= $this->renderTree($item); |
| 862 | 862 | } |
| 863 | 863 | } |
@@ -874,8 +874,8 @@ discard block |
||
| 874 | 874 | * @param string $name Template: chunk name || @CODE: template || @FILE: file with template |
| 875 | 875 | * @return string html template with placeholders without data |
| 876 | 876 | */ |
| 877 | - private function _getChunk($name) |
|
| 878 | - { |
|
| 877 | + private function _getChunk($name) |
|
| 878 | + {
|
|
| 879 | 879 | $this->debug->debug(array('Get chunk by name' => $name), "getChunk", 2, array('html')); |
| 880 | 880 | //without trim |
| 881 | 881 | $tpl = DLTemplate::getInstance($this->getMODX())->getChunk($name); |
@@ -892,18 +892,18 @@ discard block |
||
| 892 | 892 | * @param string $tpl HTML шаблон |
| 893 | 893 | * @return string |
| 894 | 894 | */ |
| 895 | - public function parseLang($tpl) |
|
| 896 | - { |
|
| 895 | + public function parseLang($tpl) |
|
| 896 | + {
|
|
| 897 | 897 | $this->debug->debug(array("parseLang" => $tpl), "parseLang", 2, array('html')); |
| 898 | - if (is_scalar($tpl) && !empty($tpl)) { |
|
| 899 | - if (preg_match_all("/\[\%([a-zA-Z0-9\.\_\-]+)\%\]/", $tpl, $match)) { |
|
| 898 | + if (is_scalar($tpl) && !empty($tpl)) {
|
|
| 899 | + if (preg_match_all("/\[\%([a-zA-Z0-9\.\_\-]+)\%\]/", $tpl, $match)) {
|
|
| 900 | 900 | $langVal = array(); |
| 901 | - foreach ($match[1] as $item) { |
|
| 901 | + foreach ($match[1] as $item) {
|
|
| 902 | 902 | $langVal[] = $this->getMsg($item); |
| 903 | 903 | } |
| 904 | 904 | $tpl = str_replace($match[0], $langVal, $tpl); |
| 905 | 905 | } |
| 906 | - } else { |
|
| 906 | + } else {
|
|
| 907 | 907 | $tpl = ''; |
| 908 | 908 | } |
| 909 | 909 | $this->debug->debugEnd("parseLang"); |
@@ -919,24 +919,24 @@ discard block |
||
| 919 | 919 | * @param bool $parseDocumentSource render html template via DocumentParser::parseDocumentSource() |
| 920 | 920 | * @return string html template with data without placeholders |
| 921 | 921 | */ |
| 922 | - public function parseChunk($name, $data, $parseDocumentSource = false) |
|
| 923 | - { |
|
| 922 | + public function parseChunk($name, $data, $parseDocumentSource = false) |
|
| 923 | + {
|
|
| 924 | 924 | $this->debug->debug( |
| 925 | 925 | array("parseChunk" => $name, "With data" => print_r($data, 1)), |
| 926 | 926 | "parseChunk", |
| 927 | 927 | 2, array('html', null) |
| 928 | 928 | ); |
| 929 | 929 | $DLTemplate = DLTemplate::getInstance($this->getMODX()); |
| 930 | - if ($path = $this->getCFGDef('templatePath')) { |
|
| 930 | + if ($path = $this->getCFGDef('templatePath')) {
|
|
| 931 | 931 | $DLTemplate->setTemplatePath($path); |
| 932 | 932 | } |
| 933 | - if ($ext = $this->getCFGDef('templateExtension')) { |
|
| 933 | + if ($ext = $this->getCFGDef('templateExtension')) {
|
|
| 934 | 934 | $DLTemplate->setTemplateExtension($ext); |
| 935 | 935 | } |
| 936 | 936 | $DLTemplate->setTwigTemplateVars(array('DocLister' => $this)); |
| 937 | 937 | $out = $DLTemplate->parseChunk($name, $data, $parseDocumentSource); |
| 938 | 938 | $out = $this->parseLang($out); |
| 939 | - if (empty($out)) { |
|
| 939 | + if (empty($out)) {
|
|
| 940 | 940 | $this->debug->debug("Empty chunk: " . $this->debug->dumpData($name), '', 2); |
| 941 | 941 | } |
| 942 | 942 | $this->debug->debugEnd("parseChunk"); |
@@ -952,8 +952,8 @@ discard block |
||
| 952 | 952 | * |
| 953 | 953 | * @return string html template from parameter |
| 954 | 954 | */ |
| 955 | - public function getChunkByParam($name, $val = '') |
|
| 956 | - { |
|
| 955 | + public function getChunkByParam($name, $val = '') |
|
| 956 | + {
|
|
| 957 | 957 | $data = $this->getCFGDef($name, $val); |
| 958 | 958 | $data = $this->_getChunk($data); |
| 959 | 959 | |
@@ -966,11 +966,11 @@ discard block |
||
| 966 | 966 | * @param string $data html код который нужно обернуть в ownerTPL |
| 967 | 967 | * @return string результатирующий html код |
| 968 | 968 | */ |
| 969 | - public function renderWrap($data) |
|
| 970 | - { |
|
| 969 | + public function renderWrap($data) |
|
| 970 | + {
|
|
| 971 | 971 | $out = $data; |
| 972 | 972 | $docs = count($this->_docs) - $this->skippedDocs; |
| 973 | - if ((($this->getCFGDef("noneWrapOuter", "1") && $docs == 0) || $docs > 0) && !empty($this->ownerTPL)) { |
|
| 973 | + if ((($this->getCFGDef("noneWrapOuter", "1") && $docs == 0) || $docs > 0) && !empty($this->ownerTPL)) {
|
|
| 974 | 974 | $this->debug->debug("", "renderWrapTPL", 2); |
| 975 | 975 | $parse = true; |
| 976 | 976 | $plh = array($this->getCFGDef("sysKey", "dl") . ".wrap" => $data); |
@@ -978,7 +978,7 @@ discard block |
||
| 978 | 978 | * @var $extPrepare prepare_DL_Extender |
| 979 | 979 | */ |
| 980 | 980 | $extPrepare = $this->getExtender('prepare'); |
| 981 | - if ($extPrepare) { |
|
| 981 | + if ($extPrepare) {
|
|
| 982 | 982 | $params = $extPrepare->init($this, array( |
| 983 | 983 | 'data' => array( |
| 984 | 984 | 'docs' => $this->_docs, |
@@ -987,13 +987,13 @@ discard block |
||
| 987 | 987 | 'nameParam' => 'prepareWrap', |
| 988 | 988 | 'return' => 'placeholders' |
| 989 | 989 | )); |
| 990 | - if (is_bool($params) && $params === false) { |
|
| 990 | + if (is_bool($params) && $params === false) {
|
|
| 991 | 991 | $out = $data; |
| 992 | 992 | $parse = false; |
| 993 | 993 | } |
| 994 | 994 | $plh = $params; |
| 995 | 995 | } |
| 996 | - if ($parse && !empty($this->ownerTPL)) { |
|
| 996 | + if ($parse && !empty($this->ownerTPL)) {
|
|
| 997 | 997 | $this->debug->updateMessage( |
| 998 | 998 | array("render ownerTPL" => $this->ownerTPL, "With data" => print_r($plh, 1)), |
| 999 | 999 | "renderWrapTPL", |
@@ -1001,7 +1001,7 @@ discard block |
||
| 1001 | 1001 | ); |
| 1002 | 1002 | $out = $this->parseChunk($this->ownerTPL, $plh); |
| 1003 | 1003 | } |
| 1004 | - if (empty($this->ownerTPL)) { |
|
| 1004 | + if (empty($this->ownerTPL)) {
|
|
| 1005 | 1005 | $this->debug->updateMessage("empty ownerTPL", "renderWrapTPL"); |
| 1006 | 1006 | } |
| 1007 | 1007 | $this->debug->debugEnd("renderWrapTPL"); |
@@ -1017,8 +1017,8 @@ discard block |
||
| 1017 | 1017 | * @param int $i номер итерации в цикле |
| 1018 | 1018 | * @return array массив с данными которые можно использовать в цикле render метода |
| 1019 | 1019 | */ |
| 1020 | - protected function uniformPrepare(&$data, $i = 0) |
|
| 1021 | - { |
|
| 1020 | + protected function uniformPrepare(&$data, $i = 0) |
|
| 1021 | + {
|
|
| 1022 | 1022 | $class = array(); |
| 1023 | 1023 | |
| 1024 | 1024 | $iterationName = ($i % 2 == 1) ? 'Odd' : 'Even'; |
@@ -1029,13 +1029,13 @@ discard block |
||
| 1029 | 1029 | $this->renderTPL = $this->getCFGDef('tpl' . $iterationName, $this->renderTPL); |
| 1030 | 1030 | $iteration = $i; |
| 1031 | 1031 | |
| 1032 | - if ($this->extPaginate) { |
|
| 1032 | + if ($this->extPaginate) {
|
|
| 1033 | 1033 | $offset = $this->getCFGDef('reversePagination', |
| 1034 | 1034 | 0) && $this->extPaginate->currentPage() > 1 ? $this->extPaginate->totalPage() * $this->getCFGDef('display', |
| 1035 | 1035 | 0) - $this->extPaginate->totalDocs() : 0; |
| 1036 | 1036 | if ($this->getCFGDef('maxDocs', 0) && !$this->getCFGDef('reversePagination', |
| 1037 | 1037 | 0) && $this->extPaginate->currentPage() == $this->extPaginate->totalPage() |
| 1038 | - ) { |
|
| 1038 | + ) {
|
|
| 1039 | 1039 | $iteration += $this->getCFGDef('display', 0); |
| 1040 | 1040 | } |
| 1041 | 1041 | $iteration += $this->getCFGDef('display', |
@@ -1045,20 +1045,20 @@ discard block |
||
| 1045 | 1045 | $data[$this->getCFGDef("sysKey", |
| 1046 | 1046 | "dl") . '.full_iteration'] = $iteration; |
| 1047 | 1047 | |
| 1048 | - if ($i == 1) { |
|
| 1048 | + if ($i == 1) {
|
|
| 1049 | 1049 | $this->renderTPL = $this->getCFGDef('tplFirst', $this->renderTPL); |
| 1050 | 1050 | $class[] = $this->getCFGDef('firstClass', 'first'); |
| 1051 | 1051 | } |
| 1052 | - if ($i == (count($this->_docs) - $this->skippedDocs)) { |
|
| 1052 | + if ($i == (count($this->_docs) - $this->skippedDocs)) {
|
|
| 1053 | 1053 | $this->renderTPL = $this->getCFGDef('tplLast', $this->renderTPL); |
| 1054 | 1054 | $class[] = $this->getCFGDef('lastClass', 'last'); |
| 1055 | 1055 | } |
| 1056 | - if ($this->modx->documentIdentifier == $data['id']) { |
|
| 1056 | + if ($this->modx->documentIdentifier == $data['id']) {
|
|
| 1057 | 1057 | $this->renderTPL = $this->getCFGDef('tplCurrent', $this->renderTPL); |
| 1058 | 1058 | $data[$this->getCFGDef("sysKey", |
| 1059 | 1059 | "dl") . '.active'] = 1; //[+active+] - 1 if $modx->documentIdentifer equal ID this element |
| 1060 | 1060 | $class[] = $this->getCFGDef('currentClass', 'current'); |
| 1061 | - } else { |
|
| 1061 | + } else {
|
|
| 1062 | 1062 | $data[$this->getCFGDef("sysKey", "dl") . '.active'] = 0; |
| 1063 | 1063 | } |
| 1064 | 1064 | |
@@ -1069,8 +1069,8 @@ discard block |
||
| 1069 | 1069 | * @var $extE e_DL_Extender |
| 1070 | 1070 | */ |
| 1071 | 1071 | $extE = $this->getExtender('e', true, true); |
| 1072 | - if ($out = $extE->init($this, compact('data'))) { |
|
| 1073 | - if (is_array($out)) { |
|
| 1072 | + if ($out = $extE->init($this, compact('data'))) {
|
|
| 1073 | + if (is_array($out)) {
|
|
| 1074 | 1074 | $data = $out; |
| 1075 | 1075 | } |
| 1076 | 1076 | } |
@@ -1086,42 +1086,43 @@ discard block |
||
| 1086 | 1086 | * @param array $array данные которые необходимо примешать к ответу на каждой записи $data |
| 1087 | 1087 | * @return string JSON строка |
| 1088 | 1088 | */ |
| 1089 | - public function getJSON($data, $fields, $array = array()) |
|
| 1090 | - { |
|
| 1089 | + public function getJSON($data, $fields, $array = array()) |
|
| 1090 | + {
|
|
| 1091 | 1091 | $out = array(); |
| 1092 | 1092 | $fields = is_array($fields) ? $fields : explode(",", $fields); |
| 1093 | - if (is_array($array) && count($array) > 0) { |
|
| 1093 | + if (is_array($array) && count($array) > 0) {
|
|
| 1094 | 1094 | $tmp = array(); |
| 1095 | - foreach ($data as $i => $v) { //array_merge not valid work with integer index key |
|
| 1095 | + foreach ($data as $i => $v) {
|
|
| 1096 | +//array_merge not valid work with integer index key |
|
| 1096 | 1097 | $tmp[$i] = (isset($array[$i]) ? array_merge($v, $array[$i]) : $v); |
| 1097 | 1098 | } |
| 1098 | 1099 | $data = $tmp; |
| 1099 | 1100 | } |
| 1100 | 1101 | |
| 1101 | - foreach ($data as $num => $doc) { |
|
| 1102 | + foreach ($data as $num => $doc) {
|
|
| 1102 | 1103 | $tmp = array(); |
| 1103 | - foreach ($doc as $name => $value) { |
|
| 1104 | - if (in_array($name, $fields) || (isset($fields[0]) && $fields[0] == '1')) { |
|
| 1104 | + foreach ($doc as $name => $value) {
|
|
| 1105 | + if (in_array($name, $fields) || (isset($fields[0]) && $fields[0] == '1')) {
|
|
| 1105 | 1106 | $tmp[str_replace(".", "_", $name)] = $value; //JSON element name without dot |
| 1106 | 1107 | } |
| 1107 | 1108 | } |
| 1108 | 1109 | $out[$num] = $tmp; |
| 1109 | 1110 | } |
| 1110 | 1111 | |
| 1111 | - if ('new' == $this->getCFGDef('JSONformat', 'old')) { |
|
| 1112 | + if ('new' == $this->getCFGDef('JSONformat', 'old')) {
|
|
| 1112 | 1113 | $return = array(); |
| 1113 | 1114 | |
| 1114 | 1115 | $return['rows'] = array(); |
| 1115 | - foreach ($out as $key => $item) { |
|
| 1116 | + foreach ($out as $key => $item) {
|
|
| 1116 | 1117 | $return['rows'][] = $item; |
| 1117 | 1118 | } |
| 1118 | 1119 | $return['total'] = $this->getChildrenCount(); |
| 1119 | - } elseif ('simple' == $this->getCFGDef('JSONformat', 'old')) { |
|
| 1120 | + } elseif ('simple' == $this->getCFGDef('JSONformat', 'old')) {
|
|
| 1120 | 1121 | $return = array(); |
| 1121 | - foreach ($out as $key => $item) { |
|
| 1122 | + foreach ($out as $key => $item) {
|
|
| 1122 | 1123 | $return[] = $item; |
| 1123 | 1124 | } |
| 1124 | - } else { |
|
| 1125 | + } else {
|
|
| 1125 | 1126 | $return = $out; |
| 1126 | 1127 | } |
| 1127 | 1128 | $this->outData = json_encode($return); |
@@ -1137,11 +1138,11 @@ discard block |
||
| 1137 | 1138 | * @param string $contentField |
| 1138 | 1139 | * @return mixed|string |
| 1139 | 1140 | */ |
| 1140 | - protected function getSummary(array $item = array(), $extSummary = null, $introField = '', $contentField = '') |
|
| 1141 | - { |
|
| 1141 | + protected function getSummary(array $item = array(), $extSummary = null, $introField = '', $contentField = '') |
|
| 1142 | + {
|
|
| 1142 | 1143 | $out = ''; |
| 1143 | 1144 | |
| 1144 | - if (is_null($extSummary)) { |
|
| 1145 | + if (is_null($extSummary)) {
|
|
| 1145 | 1146 | /** |
| 1146 | 1147 | * @var $extSummary summary_DL_Extender |
| 1147 | 1148 | */ |
@@ -1150,10 +1151,10 @@ discard block |
||
| 1150 | 1151 | $introField = $this->getCFGDef("introField", $introField); |
| 1151 | 1152 | $contentField = $this->getCFGDef("contentField", $contentField); |
| 1152 | 1153 | |
| 1153 | - if (!empty($introField) && !empty($item[$introField]) && mb_strlen($item[$introField], 'UTF-8') > 0) { |
|
| 1154 | + if (!empty($introField) && !empty($item[$introField]) && mb_strlen($item[$introField], 'UTF-8') > 0) {
|
|
| 1154 | 1155 | $out = $item[$introField]; |
| 1155 | - } else { |
|
| 1156 | - if (!empty($contentField) && !empty($item[$contentField]) && mb_strlen($item[$contentField], 'UTF-8') > 0) { |
|
| 1156 | + } else {
|
|
| 1157 | + if (!empty($contentField) && !empty($item[$contentField]) && mb_strlen($item[$contentField], 'UTF-8') > 0) {
|
|
| 1157 | 1158 | $out = $extSummary->init($this, array( |
| 1158 | 1159 | "content" => $item[$contentField], |
| 1159 | 1160 | "action" => $this->getCFGDef("summary", ""), |
@@ -1171,8 +1172,8 @@ discard block |
||
| 1171 | 1172 | * @param string $name extender name |
| 1172 | 1173 | * @return boolean status extender load |
| 1173 | 1174 | */ |
| 1174 | - public function checkExtender($name) |
|
| 1175 | - { |
|
| 1175 | + public function checkExtender($name) |
|
| 1176 | + {
|
|
| 1176 | 1177 | return (isset($this->extender[$name]) && $this->extender[$name] instanceof $name . "_DL_Extender"); |
| 1177 | 1178 | } |
| 1178 | 1179 | |
@@ -1180,8 +1181,8 @@ discard block |
||
| 1180 | 1181 | * @param $name |
| 1181 | 1182 | * @param $obj |
| 1182 | 1183 | */ |
| 1183 | - public function setExtender($name, $obj) |
|
| 1184 | - { |
|
| 1184 | + public function setExtender($name, $obj) |
|
| 1185 | + {
|
|
| 1185 | 1186 | $this->extender[$name] = $obj; |
| 1186 | 1187 | } |
| 1187 | 1188 | |
@@ -1193,13 +1194,13 @@ discard block |
||
| 1193 | 1194 | * @param bool $nop если экстендер не загружен, то загружать ли xNop |
| 1194 | 1195 | * @return null|xNop |
| 1195 | 1196 | */ |
| 1196 | - public function getExtender($name, $autoload = false, $nop = false) |
|
| 1197 | - { |
|
| 1197 | + public function getExtender($name, $autoload = false, $nop = false) |
|
| 1198 | + {
|
|
| 1198 | 1199 | $out = null; |
| 1199 | - if ((is_scalar($name) && $this->checkExtender($name)) || ($autoload && $this->_loadExtender($name))) { |
|
| 1200 | + if ((is_scalar($name) && $this->checkExtender($name)) || ($autoload && $this->_loadExtender($name))) {
|
|
| 1200 | 1201 | $out = $this->extender[$name]; |
| 1201 | 1202 | } |
| 1202 | - if ($nop && is_null($out)) { |
|
| 1203 | + if ($nop && is_null($out)) {
|
|
| 1203 | 1204 | $out = new xNop(); |
| 1204 | 1205 | } |
| 1205 | 1206 | |
@@ -1212,27 +1213,27 @@ discard block |
||
| 1212 | 1213 | * @param string $name name extender |
| 1213 | 1214 | * @return boolean $flag status load extender |
| 1214 | 1215 | */ |
| 1215 | - protected function _loadExtender($name) |
|
| 1216 | - { |
|
| 1216 | + protected function _loadExtender($name) |
|
| 1217 | + {
|
|
| 1217 | 1218 | $this->debug->debug('Load Extender ' . $this->debug->dumpData($name), 'LoadExtender', 2); |
| 1218 | 1219 | $flag = false; |
| 1219 | 1220 | |
| 1220 | 1221 | $classname = ($name != '') ? $name . "_DL_Extender" : ""; |
| 1221 | - if ($classname != '' && isset($this->extender[$name]) && $this->extender[$name] instanceof $classname) { |
|
| 1222 | + if ($classname != '' && isset($this->extender[$name]) && $this->extender[$name] instanceof $classname) {
|
|
| 1222 | 1223 | $flag = true; |
| 1223 | 1224 | |
| 1224 | - } else { |
|
| 1225 | - if (!class_exists($classname, false) && $classname != '') { |
|
| 1226 | - if (file_exists(dirname(__FILE__) . "/extender/" . $name . ".extender.inc")) { |
|
| 1225 | + } else {
|
|
| 1226 | + if (!class_exists($classname, false) && $classname != '') {
|
|
| 1227 | + if (file_exists(dirname(__FILE__) . "/extender/" . $name . ".extender.inc")) {
|
|
| 1227 | 1228 | include_once(dirname(__FILE__) . "/extender/" . $name . ".extender.inc"); |
| 1228 | 1229 | } |
| 1229 | 1230 | } |
| 1230 | - if (class_exists($classname, false) && $classname != '') { |
|
| 1231 | + if (class_exists($classname, false) && $classname != '') {
|
|
| 1231 | 1232 | $this->extender[$name] = new $classname($this, $name); |
| 1232 | 1233 | $flag = true; |
| 1233 | 1234 | } |
| 1234 | 1235 | } |
| 1235 | - if (!$flag) { |
|
| 1236 | + if (!$flag) {
|
|
| 1236 | 1237 | $this->debug->debug("Error load Extender " . $this->debug->dumpData($name)); |
| 1237 | 1238 | } |
| 1238 | 1239 | $this->debug->debugEnd('LoadExtender'); |
@@ -1250,16 +1251,16 @@ discard block |
||
| 1250 | 1251 | * @param mixed $IDs список id документов по которым необходима выборка |
| 1251 | 1252 | * @return array очищенный массив |
| 1252 | 1253 | */ |
| 1253 | - public function setIDs($IDs) |
|
| 1254 | - { |
|
| 1254 | + public function setIDs($IDs) |
|
| 1255 | + {
|
|
| 1255 | 1256 | $this->debug->debug('set ID list ' . $this->debug->dumpData($IDs), 'setIDs', 2); |
| 1256 | 1257 | $IDs = $this->cleanIDs($IDs); |
| 1257 | 1258 | $type = $this->getCFGDef('idType', 'parents'); |
| 1258 | 1259 | $depth = $this->getCFGDef('depth', ''); |
| 1259 | - if ($type == 'parents' && $depth > 0) { |
|
| 1260 | + if ($type == 'parents' && $depth > 0) {
|
|
| 1260 | 1261 | $tmp = $IDs; |
| 1261 | - do { |
|
| 1262 | - if (count($tmp) > 0) { |
|
| 1262 | + do {
|
|
| 1263 | + if (count($tmp) > 0) {
|
|
| 1263 | 1264 | $tmp = $this->getChildrenFolder($tmp); |
| 1264 | 1265 | $IDs = array_merge($IDs, $tmp); |
| 1265 | 1266 | } |
@@ -1273,8 +1274,8 @@ discard block |
||
| 1273 | 1274 | /** |
| 1274 | 1275 | * @return int |
| 1275 | 1276 | */ |
| 1276 | - public function getIDs() |
|
| 1277 | - { |
|
| 1277 | + public function getIDs() |
|
| 1278 | + {
|
|
| 1278 | 1279 | return $this->IDs; |
| 1279 | 1280 | } |
| 1280 | 1281 | |
@@ -1285,17 +1286,18 @@ discard block |
||
| 1285 | 1286 | * @param string $sep разделитель |
| 1286 | 1287 | * @return array очищенный массив с данными |
| 1287 | 1288 | */ |
| 1288 | - public function cleanIDs($IDs, $sep = ',') |
|
| 1289 | - { |
|
| 1289 | + public function cleanIDs($IDs, $sep = ',') |
|
| 1290 | + {
|
|
| 1290 | 1291 | $this->debug->debug('clean IDs ' . $this->debug->dumpData($IDs) . ' with separator ' . $this->debug->dumpData($sep), |
| 1291 | 1292 | 'cleanIDs', 2); |
| 1292 | 1293 | $out = array(); |
| 1293 | - if (!is_array($IDs)) { |
|
| 1294 | + if (!is_array($IDs)) {
|
|
| 1294 | 1295 | $IDs = explode($sep, $IDs); |
| 1295 | 1296 | } |
| 1296 | - foreach ($IDs as $item) { |
|
| 1297 | + foreach ($IDs as $item) {
|
|
| 1297 | 1298 | $item = trim($item); |
| 1298 | - if (is_numeric($item) && (int)$item >= 0) { //Fix 0xfffffffff |
|
| 1299 | + if (is_numeric($item) && (int)$item >= 0) {
|
|
| 1300 | +//Fix 0xfffffffff |
|
| 1299 | 1301 | $out[] = (int)$item; |
| 1300 | 1302 | } |
| 1301 | 1303 | } |
@@ -1309,8 +1311,8 @@ discard block |
||
| 1309 | 1311 | * Проверка массива с id-шниками документов для выборки |
| 1310 | 1312 | * @return boolean пригодны ли данные для дальнейшего использования |
| 1311 | 1313 | */ |
| 1312 | - protected function checkIDs() |
|
| 1313 | - { |
|
| 1314 | + protected function checkIDs() |
|
| 1315 | + {
|
|
| 1314 | 1316 | return (is_array($this->IDs) && count($this->IDs) > 0) ? true : false; |
| 1315 | 1317 | } |
| 1316 | 1318 | |
@@ -1322,11 +1324,11 @@ discard block |
||
| 1322 | 1324 | * @global array $_docs all documents |
| 1323 | 1325 | * @return array all field values |
| 1324 | 1326 | */ |
| 1325 | - public function getOneField($userField, $uniq = false) |
|
| 1326 | - { |
|
| 1327 | + public function getOneField($userField, $uniq = false) |
|
| 1328 | + {
|
|
| 1327 | 1329 | $out = array(); |
| 1328 | - foreach ($this->_docs as $doc => $val) { |
|
| 1329 | - if (isset($val[$userField]) && (($uniq && !in_array($val[$userField], $out)) || !$uniq)) { |
|
| 1330 | + foreach ($this->_docs as $doc => $val) {
|
|
| 1331 | + if (isset($val[$userField]) && (($uniq && !in_array($val[$userField], $out)) || !$uniq)) {
|
|
| 1330 | 1332 | $out[$doc] = $val[$userField]; |
| 1331 | 1333 | } |
| 1332 | 1334 | } |
@@ -1337,8 +1339,8 @@ discard block |
||
| 1337 | 1339 | /** |
| 1338 | 1340 | * @return DLCollection |
| 1339 | 1341 | */ |
| 1340 | - public function docsCollection() |
|
| 1341 | - { |
|
| 1342 | + public function docsCollection() |
|
| 1343 | + {
|
|
| 1342 | 1344 | return new DLCollection($this->modx, $this->_docs); |
| 1343 | 1345 | } |
| 1344 | 1346 | |
@@ -1366,10 +1368,10 @@ discard block |
||
| 1366 | 1368 | * @param string $group |
| 1367 | 1369 | * @return string |
| 1368 | 1370 | */ |
| 1369 | - protected function getGroupSQL($group = '') |
|
| 1370 | - { |
|
| 1371 | + protected function getGroupSQL($group = '') |
|
| 1372 | + {
|
|
| 1371 | 1373 | $out = ''; |
| 1372 | - if ($group != '') { |
|
| 1374 | + if ($group != '') {
|
|
| 1373 | 1375 | $out = 'GROUP BY ' . $group; |
| 1374 | 1376 | } |
| 1375 | 1377 | |
@@ -1388,12 +1390,12 @@ discard block |
||
| 1388 | 1390 | * |
| 1389 | 1391 | * @return string Order by for SQL |
| 1390 | 1392 | */ |
| 1391 | - protected function SortOrderSQL($sortName, $orderDef = 'DESC') |
|
| 1392 | - { |
|
| 1393 | + protected function SortOrderSQL($sortName, $orderDef = 'DESC') |
|
| 1394 | + {
|
|
| 1393 | 1395 | $this->debug->debug('', 'sortORDER', 2); |
| 1394 | 1396 | |
| 1395 | 1397 | $sort = ''; |
| 1396 | - switch ($this->getCFGDef('sortType', '')) { |
|
| 1398 | + switch ($this->getCFGDef('sortType', '')) {
|
|
| 1397 | 1399 | case 'none': |
| 1398 | 1400 | break; |
| 1399 | 1401 | case 'doclist': |
@@ -1404,10 +1406,10 @@ discard block |
||
| 1404 | 1406 | break; |
| 1405 | 1407 | default: |
| 1406 | 1408 | $out = array('orderBy' => '', 'order' => '', 'sortBy' => ''); |
| 1407 | - if (($tmp = $this->getCFGDef('orderBy', '')) != '') { |
|
| 1409 | + if (($tmp = $this->getCFGDef('orderBy', '')) != '') {
|
|
| 1408 | 1410 | $out['orderBy'] = $tmp; |
| 1409 | - } else { |
|
| 1410 | - switch (true) { |
|
| 1411 | + } else {
|
|
| 1412 | + switch (true) {
|
|
| 1411 | 1413 | case ('' != ($tmp = $this->getCFGDef('sortDir', ''))): //higher priority than order |
| 1412 | 1414 | $out['order'] = $tmp; |
| 1413 | 1415 | // no break |
@@ -1415,7 +1417,7 @@ discard block |
||
| 1415 | 1417 | $out['order'] = $tmp; |
| 1416 | 1418 | // no break |
| 1417 | 1419 | } |
| 1418 | - if ('' == $out['order'] || !in_array(strtoupper($out['order']), array('ASC', 'DESC'))) { |
|
| 1420 | + if ('' == $out['order'] || !in_array(strtoupper($out['order']), array('ASC', 'DESC'))) {
|
|
| 1419 | 1421 | $out['order'] = $orderDef; //Default |
| 1420 | 1422 | } |
| 1421 | 1423 | |
@@ -1436,30 +1438,30 @@ discard block |
||
| 1436 | 1438 | * |
| 1437 | 1439 | * @return string LIMIT вставка в SQL запрос |
| 1438 | 1440 | */ |
| 1439 | - protected function LimitSQL($limit = 0, $offset = 0) |
|
| 1440 | - { |
|
| 1441 | + protected function LimitSQL($limit = 0, $offset = 0) |
|
| 1442 | + {
|
|
| 1441 | 1443 | $this->debug->debug('', 'limitSQL', 2); |
| 1442 | 1444 | $ret = ''; |
| 1443 | - if ($limit == 0) { |
|
| 1445 | + if ($limit == 0) {
|
|
| 1444 | 1446 | $limit = $this->getCFGDef('display', 0); |
| 1445 | 1447 | } |
| 1446 | 1448 | $maxDocs = $this->getCFGDef('maxDocs', 0); |
| 1447 | - if ($maxDocs > 0 && $limit > $maxDocs) { |
|
| 1449 | + if ($maxDocs > 0 && $limit > $maxDocs) {
|
|
| 1448 | 1450 | $limit = $maxDocs; |
| 1449 | 1451 | } |
| 1450 | - if ($offset == 0) { |
|
| 1452 | + if ($offset == 0) {
|
|
| 1451 | 1453 | $offset = $this->getCFGDef('offset', 0); |
| 1452 | 1454 | } |
| 1453 | 1455 | $offset += $this->getCFGDef('start', 0); |
| 1454 | 1456 | $total = $this->getCFGDef('total', 0); |
| 1455 | - if ($limit < ($total - $limit)) { |
|
| 1457 | + if ($limit < ($total - $limit)) {
|
|
| 1456 | 1458 | $limit = $total - $offset; |
| 1457 | 1459 | } |
| 1458 | 1460 | |
| 1459 | - if ($limit != 0) { |
|
| 1461 | + if ($limit != 0) {
|
|
| 1460 | 1462 | $ret = "LIMIT " . (int)$offset . "," . (int)$limit; |
| 1461 | - } else { |
|
| 1462 | - if ($offset != 0) { |
|
| 1463 | + } else {
|
|
| 1464 | + if ($offset != 0) {
|
|
| 1463 | 1465 | /** |
| 1464 | 1466 | * To retrieve all rows from a certain offset up to the end of the result set, you can use some large number for the second parameter |
| 1465 | 1467 | * @see http://dev.mysql.com/doc/refman/5.0/en/select.html |
@@ -1479,8 +1481,8 @@ discard block |
||
| 1479 | 1481 | * @param string $charset |
| 1480 | 1482 | * @return string Clear string |
| 1481 | 1483 | */ |
| 1482 | - public function sanitarData($data, $charset = 'UTF-8') |
|
| 1483 | - { |
|
| 1484 | + public function sanitarData($data, $charset = 'UTF-8') |
|
| 1485 | + {
|
|
| 1484 | 1486 | return APIHelpers::sanitarTag($data, $charset); |
| 1485 | 1487 | } |
| 1486 | 1488 | |
@@ -1491,8 +1493,8 @@ discard block |
||
| 1491 | 1493 | * @param string $parentField default name parent field |
| 1492 | 1494 | * @return array |
| 1493 | 1495 | */ |
| 1494 | - public function treeBuild($idField = 'id', $parentField = 'parent') |
|
| 1495 | - { |
|
| 1496 | + public function treeBuild($idField = 'id', $parentField = 'parent') |
|
| 1497 | + {
|
|
| 1496 | 1498 | return $this->_treeBuild($this->_docs, $this->getCFGDef('idField', $idField), |
| 1497 | 1499 | $this->getCFGDef('parentField', $parentField)); |
| 1498 | 1500 | } |
@@ -1505,16 +1507,16 @@ discard block |
||
| 1505 | 1507 | * @param string $pidName name parent field in associative data array |
| 1506 | 1508 | * @return array |
| 1507 | 1509 | */ |
| 1508 | - private function _treeBuild($data, $idName, $pidName) |
|
| 1509 | - { |
|
| 1510 | + private function _treeBuild($data, $idName, $pidName) |
|
| 1511 | + {
|
|
| 1510 | 1512 | $children = array(); // children of each ID |
| 1511 | 1513 | $ids = array(); |
| 1512 | - foreach ($data as $i => $r) { |
|
| 1514 | + foreach ($data as $i => $r) {
|
|
| 1513 | 1515 | $row =& $data[$i]; |
| 1514 | 1516 | $id = $row[$idName]; |
| 1515 | 1517 | $pid = $row[$pidName]; |
| 1516 | 1518 | $children[$pid][$id] =& $row; |
| 1517 | - if (!isset($children[$id])) { |
|
| 1519 | + if (!isset($children[$id])) {
|
|
| 1518 | 1520 | $children[$id] = array(); |
| 1519 | 1521 | } |
| 1520 | 1522 | $row['#childNodes'] =& $children[$id]; |
@@ -1522,9 +1524,9 @@ discard block |
||
| 1522 | 1524 | } |
| 1523 | 1525 | // Root elements are elements with non-found PIDs. |
| 1524 | 1526 | $this->_tree = array(); |
| 1525 | - foreach ($data as $i => $r) { |
|
| 1527 | + foreach ($data as $i => $r) {
|
|
| 1526 | 1528 | $row =& $data[$i]; |
| 1527 | - if (!isset($ids[$row[$pidName]])) { |
|
| 1529 | + if (!isset($ids[$row[$pidName]])) {
|
|
| 1528 | 1530 | $this->_tree[$row[$idName]] = $row; |
| 1529 | 1531 | } |
| 1530 | 1532 | } |
@@ -1538,12 +1540,12 @@ discard block |
||
| 1538 | 1540 | * @param bool $full если true то возвращается значение для подстановки в запрос |
| 1539 | 1541 | * @return string PrimaryKey основной таблицы |
| 1540 | 1542 | */ |
| 1541 | - public function getPK($full = true) |
|
| 1542 | - { |
|
| 1543 | + public function getPK($full = true) |
|
| 1544 | + {
|
|
| 1543 | 1545 | $idField = isset($this->idField) ? $this->idField: 'id'; |
| 1544 | - if ($full) { |
|
| 1546 | + if ($full) {
|
|
| 1545 | 1547 | $idField = '`' . $idField . '`'; |
| 1546 | - if (!empty($this->alias)) { |
|
| 1548 | + if (!empty($this->alias)) {
|
|
| 1547 | 1549 | $idField = '`' . $this->alias . '`.' . $idField; |
| 1548 | 1550 | } |
| 1549 | 1551 | } |
@@ -1557,12 +1559,12 @@ discard block |
||
| 1557 | 1559 | * @param bool $full если true то возвращается значение для подстановки в запрос |
| 1558 | 1560 | * @return string Parent Key основной таблицы |
| 1559 | 1561 | */ |
| 1560 | - public function getParentField($full = true) |
|
| 1561 | - { |
|
| 1562 | + public function getParentField($full = true) |
|
| 1563 | + {
|
|
| 1562 | 1564 | $parentField = isset($this->parentField) ? $this->parentField : ''; |
| 1563 | - if ($full && !empty($parentField)) { |
|
| 1565 | + if ($full && !empty($parentField)) {
|
|
| 1564 | 1566 | $parentField = '`' . $parentField . '`'; |
| 1565 | - if (!empty($this->alias)) { |
|
| 1567 | + if (!empty($this->alias)) {
|
|
| 1566 | 1568 | $parentField = '`' . $this->alias . '`.' . $parentField; |
| 1567 | 1569 | } |
| 1568 | 1570 | } |
@@ -1577,31 +1579,31 @@ discard block |
||
| 1577 | 1579 | * @param string $filter_string строка со всеми фильтрами |
| 1578 | 1580 | * @return mixed результат разбора фильтров |
| 1579 | 1581 | */ |
| 1580 | - protected function getFilters($filter_string) |
|
| 1581 | - { |
|
| 1582 | + protected function getFilters($filter_string) |
|
| 1583 | + {
|
|
| 1582 | 1584 | $this->debug->debug("getFilters: " . $this->debug->dumpData($filter_string), 'getFilter', 1); |
| 1583 | 1585 | // the filter parameter tells us, which filters can be used in this query |
| 1584 | 1586 | $filter_string = trim($filter_string, ' ;'); |
| 1585 | - if (!$filter_string) { |
|
| 1587 | + if (!$filter_string) {
|
|
| 1586 | 1588 | return; |
| 1587 | 1589 | } |
| 1588 | 1590 | $output = array('join' => '', 'where' => ''); |
| 1589 | 1591 | $logic_op_found = false; |
| 1590 | 1592 | $joins = $wheres = array(); |
| 1591 | - foreach ($this->_logic_ops as $op => $sql) { |
|
| 1592 | - if (strpos($filter_string, $op) === 0) { |
|
| 1593 | + foreach ($this->_logic_ops as $op => $sql) {
|
|
| 1594 | + if (strpos($filter_string, $op) === 0) {
|
|
| 1593 | 1595 | $logic_op_found = true; |
| 1594 | 1596 | $subfilters = mb_substr($filter_string, strlen($op) + 1, mb_strlen($filter_string, "UTF-8"), "UTF-8"); |
| 1595 | 1597 | $subfilters = $this->smartSplit($subfilters); |
| 1596 | - foreach ($subfilters as $subfilter) { |
|
| 1598 | + foreach ($subfilters as $subfilter) {
|
|
| 1597 | 1599 | $subfilter = $this->getFilters(trim($subfilter)); |
| 1598 | - if (!$subfilter) { |
|
| 1600 | + if (!$subfilter) {
|
|
| 1599 | 1601 | continue; |
| 1600 | 1602 | } |
| 1601 | - if ($subfilter['join']) { |
|
| 1603 | + if ($subfilter['join']) {
|
|
| 1602 | 1604 | $joins[] = $subfilter['join']; |
| 1603 | 1605 | } |
| 1604 | - if ($subfilter['where']) { |
|
| 1606 | + if ($subfilter['where']) {
|
|
| 1605 | 1607 | $wheres[] = $subfilter['where']; |
| 1606 | 1608 | } |
| 1607 | 1609 | } |
@@ -1610,12 +1612,12 @@ discard block |
||
| 1610 | 1612 | } |
| 1611 | 1613 | } |
| 1612 | 1614 | |
| 1613 | - if (!$logic_op_found) { |
|
| 1615 | + if (!$logic_op_found) {
|
|
| 1614 | 1616 | $filter = $this->loadFilter($filter_string); |
| 1615 | - if (!$filter) { |
|
| 1617 | + if (!$filter) {
|
|
| 1616 | 1618 | $this->debug->warning('Error while loading DocLister filter "' . $this->debug->dumpData($filter_string) . '": check syntax!'); |
| 1617 | 1619 | $output = false; |
| 1618 | - } else { |
|
| 1620 | + } else {
|
|
| 1619 | 1621 | $output['join'] = $filter->get_join(); |
| 1620 | 1622 | $output['where'] = stripslashes($filter->get_where()); |
| 1621 | 1623 | } |
@@ -1628,16 +1630,16 @@ discard block |
||
| 1628 | 1630 | /** |
| 1629 | 1631 | * @return mixed |
| 1630 | 1632 | */ |
| 1631 | - public function filtersWhere() |
|
| 1632 | - { |
|
| 1633 | + public function filtersWhere() |
|
| 1634 | + {
|
|
| 1633 | 1635 | return APIHelpers::getkey($this->_filters, 'where', ''); |
| 1634 | 1636 | } |
| 1635 | 1637 | |
| 1636 | 1638 | /** |
| 1637 | 1639 | * @return mixed |
| 1638 | 1640 | */ |
| 1639 | - public function filtersJoin() |
|
| 1640 | - { |
|
| 1641 | + public function filtersJoin() |
|
| 1642 | + {
|
|
| 1641 | 1643 | return APIHelpers::getkey($this->_filters, 'join', ''); |
| 1642 | 1644 | } |
| 1643 | 1645 | |
@@ -1645,11 +1647,12 @@ discard block |
||
| 1645 | 1647 | * @param string $join |
| 1646 | 1648 | * @return $this |
| 1647 | 1649 | */ |
| 1648 | - public function setFiltersJoin($join = '') { |
|
| 1649 | - if (!empty($join)) { |
|
| 1650 | - if (!empty($this->_filters['join'])) { |
|
| 1650 | + public function setFiltersJoin($join = '') |
|
| 1651 | + {
|
|
| 1652 | + if (!empty($join)) {
|
|
| 1653 | + if (!empty($this->_filters['join'])) {
|
|
| 1651 | 1654 | $this->_filters['join'] .= ' ' . $join; |
| 1652 | - } else { |
|
| 1655 | + } else {
|
|
| 1653 | 1656 | $this->_filters['join'] = $join; |
| 1654 | 1657 | } |
| 1655 | 1658 | } |
@@ -1664,10 +1667,10 @@ discard block |
||
| 1664 | 1667 | * @param $type string тип фильтрации |
| 1665 | 1668 | * @return string имя поля с учетом приведения типа |
| 1666 | 1669 | */ |
| 1667 | - public function changeSortType($field, $type) |
|
| 1668 | - { |
|
| 1670 | + public function changeSortType($field, $type) |
|
| 1671 | + {
|
|
| 1669 | 1672 | $type = trim($type); |
| 1670 | - switch (strtoupper($type)) { |
|
| 1673 | + switch (strtoupper($type)) {
|
|
| 1671 | 1674 | case 'DECIMAL': |
| 1672 | 1675 | $field = 'CAST(' . $field . ' as DECIMAL(10,2))'; |
| 1673 | 1676 | break; |
@@ -1693,8 +1696,8 @@ discard block |
||
| 1693 | 1696 | * @param string $filter срока с параметрами фильтрации |
| 1694 | 1697 | * @return bool |
| 1695 | 1698 | */ |
| 1696 | - protected function loadFilter($filter) |
|
| 1697 | - { |
|
| 1699 | + protected function loadFilter($filter) |
|
| 1700 | + {
|
|
| 1698 | 1701 | $this->debug->debug('Load filter ' . $this->debug->dumpData($filter), 'loadFilter', 2); |
| 1699 | 1702 | $out = false; |
| 1700 | 1703 | $fltr_params = explode(':', $filter, 2); |
@@ -1704,21 +1707,21 @@ discard block |
||
| 1704 | 1707 | */ |
| 1705 | 1708 | $fltr_class = $fltr . '_DL_filter'; |
| 1706 | 1709 | // check if the filter is implemented |
| 1707 | - if (!is_null($fltr)) { |
|
| 1708 | - if (!class_exists($fltr_class) && file_exists(__DIR__ . '/filter/' . $fltr . '.filter.php')) { |
|
| 1710 | + if (!is_null($fltr)) {
|
|
| 1711 | + if (!class_exists($fltr_class) && file_exists(__DIR__ . '/filter/' . $fltr . '.filter.php')) {
|
|
| 1709 | 1712 | require_once dirname(__FILE__) . '/filter/' . $fltr . '.filter.php'; |
| 1710 | 1713 | } |
| 1711 | - if (class_exists($fltr_class)) { |
|
| 1714 | + if (class_exists($fltr_class)) {
|
|
| 1712 | 1715 | $this->totalFilters++; |
| 1713 | 1716 | $fltr_obj = new $fltr_class(); |
| 1714 | - if ($fltr_obj->init($this, $filter)) { |
|
| 1717 | + if ($fltr_obj->init($this, $filter)) {
|
|
| 1715 | 1718 | $out = $fltr_obj; |
| 1716 | - } else { |
|
| 1719 | + } else {
|
|
| 1717 | 1720 | $this->debug->error("Wrong filter parameter: '{$this->debug->dumpData($filter)}'", 'Filter'); |
| 1718 | 1721 | } |
| 1719 | 1722 | } |
| 1720 | 1723 | } |
| 1721 | - if (!$out) { |
|
| 1724 | + if (!$out) {
|
|
| 1722 | 1725 | $this->debug->error("Error load Filter: '{$this->debug->dumpData($filter)}'", 'Filter'); |
| 1723 | 1726 | } |
| 1724 | 1727 | |
@@ -1731,8 +1734,8 @@ discard block |
||
| 1731 | 1734 | * Общее число фильтров |
| 1732 | 1735 | * @return int |
| 1733 | 1736 | */ |
| 1734 | - public function getCountFilters() |
|
| 1735 | - { |
|
| 1737 | + public function getCountFilters() |
|
| 1738 | + {
|
|
| 1736 | 1739 | return (int)$this->totalFilters; |
| 1737 | 1740 | } |
| 1738 | 1741 | |
@@ -1740,8 +1743,8 @@ discard block |
||
| 1740 | 1743 | * Выполнить SQL запрос |
| 1741 | 1744 | * @param string $q SQL запрос |
| 1742 | 1745 | */ |
| 1743 | - public function dbQuery($q) |
|
| 1744 | - { |
|
| 1746 | + public function dbQuery($q) |
|
| 1747 | + {
|
|
| 1745 | 1748 | $this->debug->debug($q, "query", 1, 'sql'); |
| 1746 | 1749 | $out = $this->modx->db->query($q); |
| 1747 | 1750 | $this->debug->debugEnd("query"); |
@@ -1759,8 +1762,8 @@ discard block |
||
| 1759 | 1762 | * @param string $tpl шаблон подстановки значения в SQL запрос |
| 1760 | 1763 | * @return string строка для подстановки в SQL запрос |
| 1761 | 1764 | */ |
| 1762 | - public function LikeEscape($field, $value, $escape = '=', $tpl = '%[+value+]%') |
|
| 1763 | - { |
|
| 1765 | + public function LikeEscape($field, $value, $escape = '=', $tpl = '%[+value+]%') |
|
| 1766 | + {
|
|
| 1764 | 1767 | return sqlHelper::LikeEscape($this->modx, $field, $value, $escape, $tpl); |
| 1765 | 1768 | } |
| 1766 | 1769 | |
@@ -1768,8 +1771,8 @@ discard block |
||
| 1768 | 1771 | * Получение REQUEST_URI без GET-ключа с |
| 1769 | 1772 | * @return string |
| 1770 | 1773 | */ |
| 1771 | - public function getRequest() |
|
| 1772 | - { |
|
| 1774 | + public function getRequest() |
|
| 1775 | + {
|
|
| 1773 | 1776 | $URL = null; |
| 1774 | 1777 | parse_str(parse_url(MODX_SITE_URL . $_SERVER['REQUEST_URI'], PHP_URL_QUERY), $URL); |
| 1775 | 1778 | |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | include_once(MODX_BASE_PATH . 'assets/lib/APIHelpers.class.php'); |
| 3 | -if (!function_exists('validateMonth')) { |
|
| 3 | +if ( ! function_exists('validateMonth')) { |
|
| 4 | 4 | /** |
| 5 | 5 | * @param $val |
| 6 | 6 | * @return bool |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | } |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | -if (!function_exists('buildUrl')) { |
|
| 23 | +if ( ! function_exists('buildUrl')) { |
|
| 24 | 24 | /** |
| 25 | 25 | * @param $url |
| 26 | 26 | * @param int $start |
@@ -33,13 +33,13 @@ discard block |
||
| 33 | 33 | $requestName = 'start'; |
| 34 | 34 | if ($requestName != '' && is_array($params)) { |
| 35 | 35 | $params = array_merge($params, array($requestName => null)); |
| 36 | - if (!empty($start)) { |
|
| 36 | + if ( ! empty($start)) { |
|
| 37 | 37 | $params[$requestName] = $start; |
| 38 | 38 | } |
| 39 | 39 | $q = http_build_query($params); |
| 40 | 40 | $url = explode("?", $url, 2); |
| 41 | 41 | $url = $url[0]; |
| 42 | - if (!empty($q)) { |
|
| 42 | + if ( ! empty($q)) { |
|
| 43 | 43 | $url .= "?" . $q; |
| 44 | 44 | } |
| 45 | 45 | } |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | $tmp = date("Y-m-d H:i:s"); |
| 61 | 61 | $currentDay = APIHelpers::getkey($params, 'currentDay', $tmp); // Текущий день |
| 62 | -if (!validateDate($currentDay)) { |
|
| 62 | +if ( ! validateDate($currentDay)) { |
|
| 63 | 63 | $currentDay = $tmp; |
| 64 | 64 | } |
| 65 | 65 | |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | 'pagesAfter' => ceil($elements['after'] / $elements['display']) |
| 156 | 156 | ); |
| 157 | 157 | |
| 158 | -if (!is_null($beforeStart)) { |
|
| 158 | +if ( ! is_null($beforeStart)) { |
|
| 159 | 159 | $tpl = $DLObj->getCFGDef('TplPrevP', '@CODE: <a href="[+url+]">Назад</a>'); |
| 160 | 160 | $beforePage = $DLObj->parseChunk($tpl, array_merge($pageParams, array( |
| 161 | 161 | 'url' => buildUrl($DLObj->getUrl(), $beforeStart), |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | } |
| 175 | 175 | $modx->setPlaceholder('pages.before', $beforePage); |
| 176 | 176 | |
| 177 | -if (!is_null($afterStart)) { |
|
| 177 | +if ( ! is_null($afterStart)) { |
|
| 178 | 178 | $tpl = $DLObj->getCFGDef('TplNextP', '@CODE: <a href="[+url+]">Далее</a>'); |
| 179 | 179 | $afterPage = $DLObj->parseChunk($tpl, array_merge($pageParams, array( |
| 180 | 180 | 'url' => buildUrl($DLObj->getUrl(), $afterStart), |
@@ -1,14 +1,14 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | include_once(MODX_BASE_PATH . 'assets/lib/APIHelpers.class.php'); |
| 3 | -if (!function_exists('validateMonth')) { |
|
| 3 | +if (!function_exists('validateMonth')) {
|
|
| 4 | 4 | /** |
| 5 | 5 | * @param $val |
| 6 | 6 | * @return bool |
| 7 | 7 | */ |
| 8 | - function validateDate($val) |
|
| 9 | - { |
|
| 8 | + function validateDate($val) |
|
| 9 | + {
|
|
| 10 | 10 | $flag = false; |
| 11 | - if (is_string($val)) { |
|
| 11 | + if (is_string($val)) {
|
|
| 12 | 12 | $val = explode("-", $val, 3); |
| 13 | 13 | $flag = (count($val) == 3 && is_array($val) && strlen($val[2]) == 2 && strlen($val[1]) == 2 && strlen($val[0]) == 4); //Валидация содержимого массива |
| 14 | 14 | $flag = ($flag && (int)$val[2] > 0 && (int)$val[2] <= 31); //Валидация дня |
@@ -20,26 +20,26 @@ discard block |
||
| 20 | 20 | } |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | -if (!function_exists('buildUrl')) { |
|
| 23 | +if (!function_exists('buildUrl')) {
|
|
| 24 | 24 | /** |
| 25 | 25 | * @param $url |
| 26 | 26 | * @param int $start |
| 27 | 27 | * @return array|string |
| 28 | 28 | */ |
| 29 | - function buildUrl($url, $start = 0) |
|
| 30 | - { |
|
| 29 | + function buildUrl($url, $start = 0) |
|
| 30 | + {
|
|
| 31 | 31 | $params = parse_url($url, PHP_URL_QUERY); |
| 32 | 32 | parse_str(html_entity_decode($params), $params); |
| 33 | 33 | $requestName = 'start'; |
| 34 | - if ($requestName != '' && is_array($params)) { |
|
| 34 | + if ($requestName != '' && is_array($params)) {
|
|
| 35 | 35 | $params = array_merge($params, array($requestName => null)); |
| 36 | - if (!empty($start)) { |
|
| 36 | + if (!empty($start)) {
|
|
| 37 | 37 | $params[$requestName] = $start; |
| 38 | 38 | } |
| 39 | 39 | $q = http_build_query($params); |
| 40 | 40 | $url = explode("?", $url, 2); |
| 41 | 41 | $url = $url[0]; |
| 42 | - if (!empty($q)) { |
|
| 42 | + if (!empty($q)) {
|
|
| 43 | 43 | $url .= "?" . $q; |
| 44 | 44 | } |
| 45 | 45 | } |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | $tmp = date("Y-m-d H:i:s"); |
| 61 | 61 | $currentDay = APIHelpers::getkey($params, 'currentDay', $tmp); // Текущий день |
| 62 | -if (!validateDate($currentDay)) { |
|
| 62 | +if (!validateDate($currentDay)) {
|
|
| 63 | 63 | $currentDay = $tmp; |
| 64 | 64 | } |
| 65 | 65 | |
@@ -70,17 +70,17 @@ discard block |
||
| 70 | 70 | //Если положительное значение, то нужы события предстоящие. Если отрицательное - прошедшее |
| 71 | 71 | $rule = ($start >= 0) ? 'after' : 'before'; |
| 72 | 72 | $noRule = ($start >= 0) ? 'before' : 'after'; |
| 73 | -if ($start < 0) { |
|
| 73 | +if ($start < 0) {
|
|
| 74 | 74 | $start = abs($start) > $display ? ($start + $display) : 0; |
| 75 | 75 | } |
| 76 | 76 | $d = $modx->db->escape($currentDay); |
| 77 | -if ($dateSource == 'tv') { |
|
| 77 | +if ($dateSource == 'tv') {
|
|
| 78 | 78 | $params['tvSortType'] = 'TVDATETIME'; |
| 79 | 79 | $query = array( |
| 80 | 80 | 'after' => "STR_TO_DATE(`dltv_" . $dateField . "_1`.`value`,'%d-%m-%Y %H:%i:%s') >= '" . $d . "'", |
| 81 | 81 | 'before' => "STR_TO_DATE(`dltv_" . $dateField . "_1`.`value`,'%d-%m-%Y %H:%i:%s') < '" . $d . "'" |
| 82 | 82 | ); |
| 83 | -} else { |
|
| 83 | +} else {
|
|
| 84 | 84 | $query = array( |
| 85 | 85 | 'after' => "FROM_UNIXTIME(" . $dateField . ") >= '" . $d . "'", |
| 86 | 86 | 'before' => "FROM_UNIXTIME(" . $dateField . ") < '" . $d . "'" |
@@ -119,32 +119,32 @@ discard block |
||
| 119 | 119 | $elements[$noRule] = $DLObj->getChildrenCount(); |
| 120 | 120 | |
| 121 | 121 | $afterStart = $beforeStart = null; |
| 122 | -switch (true) { |
|
| 122 | +switch (true) {
|
|
| 123 | 123 | case ($elements['offset'] > 0): |
| 124 | 124 | $beforeStart = $elements['offset'] - $elements['display']; |
| 125 | - if ($elements['offset'] + $elements['display'] < $elements['after']) { |
|
| 125 | + if ($elements['offset'] + $elements['display'] < $elements['after']) {
|
|
| 126 | 126 | $afterStart = $elements['offset'] + $elements['display']; |
| 127 | - } else { |
|
| 127 | + } else {
|
|
| 128 | 128 | $afterStart = null; |
| 129 | 129 | } |
| 130 | 130 | break; |
| 131 | 131 | case ($elements['offset'] < 0): |
| 132 | 132 | $afterStart = $elements['offset'] + $elements['display']; |
| 133 | - if (abs($elements['offset']) + $elements['display'] <= $elements['before']) { |
|
| 133 | + if (abs($elements['offset']) + $elements['display'] <= $elements['before']) {
|
|
| 134 | 134 | $beforeStart = $elements['offset'] - $elements['display']; |
| 135 | - } else { |
|
| 135 | + } else {
|
|
| 136 | 136 | $beforeStart = null; |
| 137 | 137 | } |
| 138 | 138 | break; |
| 139 | 139 | default: // ($start = 0) |
| 140 | - if ($elements['display'] < $elements['after']) { |
|
| 140 | + if ($elements['display'] < $elements['after']) {
|
|
| 141 | 141 | $afterStart = $elements['display']; |
| 142 | - } else { |
|
| 142 | + } else {
|
|
| 143 | 143 | $afterStart = null; |
| 144 | 144 | } |
| 145 | - if ($elements['display'] <= $elements['before']) { |
|
| 145 | + if ($elements['display'] <= $elements['before']) {
|
|
| 146 | 146 | $beforeStart = -1 * $elements['display']; |
| 147 | - } else { |
|
| 147 | + } else {
|
|
| 148 | 148 | $beforeStart = null; |
| 149 | 149 | } |
| 150 | 150 | } |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | 'pagesAfter' => ceil($elements['after'] / $elements['display']) |
| 156 | 156 | ); |
| 157 | 157 | |
| 158 | -if (!is_null($beforeStart)) { |
|
| 158 | +if (!is_null($beforeStart)) {
|
|
| 159 | 159 | $tpl = $DLObj->getCFGDef('TplPrevP', '@CODE: <a href="[+url+]">Назад</a>'); |
| 160 | 160 | $beforePage = $DLObj->parseChunk($tpl, array_merge($pageParams, array( |
| 161 | 161 | 'url' => buildUrl($DLObj->getUrl(), $beforeStart), |
@@ -163,8 +163,8 @@ discard block |
||
| 163 | 163 | 'elements' => $elements['before'], |
| 164 | 164 | 'pages' => ceil($elements['before'] / $elements['display']) |
| 165 | 165 | ))); |
| 166 | -} else { |
|
| 167 | - if ($DLObj->getCFGDef("PrevNextAlwaysShow", 0)) { |
|
| 166 | +} else {
|
|
| 167 | + if ($DLObj->getCFGDef("PrevNextAlwaysShow", 0)) {
|
|
| 168 | 168 | $tpl = $DLObj->getCFGDef('TplPrevI', '@CODE: Назад'); |
| 169 | 169 | $beforePage = $DLObj->parseChunk($tpl, array_merge($pageParams, array( |
| 170 | 170 | 'elements' => $elements['before'], |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | } |
| 175 | 175 | $modx->setPlaceholder('pages.before', $beforePage); |
| 176 | 176 | |
| 177 | -if (!is_null($afterStart)) { |
|
| 177 | +if (!is_null($afterStart)) {
|
|
| 178 | 178 | $tpl = $DLObj->getCFGDef('TplNextP', '@CODE: <a href="[+url+]">Далее</a>'); |
| 179 | 179 | $afterPage = $DLObj->parseChunk($tpl, array_merge($pageParams, array( |
| 180 | 180 | 'url' => buildUrl($DLObj->getUrl(), $afterStart), |
@@ -182,8 +182,8 @@ discard block |
||
| 182 | 182 | 'elements' => $elements['after'], |
| 183 | 183 | 'pages' => ceil($elements['before'] / $elements['display']) |
| 184 | 184 | ))); |
| 185 | -} else { |
|
| 186 | - if ($DLObj->getCFGDef("PrevNextAlwaysShow", 0)) { |
|
| 185 | +} else {
|
|
| 186 | + if ($DLObj->getCFGDef("PrevNextAlwaysShow", 0)) {
|
|
| 187 | 187 | $tpl = $DLObj->getCFGDef('TplNextI', '@CODE: Далее'); |
| 188 | 188 | $afterPage = $DLObj->parseChunk($tpl, array_merge($pageParams, array( |
| 189 | 189 | 'elements' => $elements['after'], |
@@ -194,10 +194,10 @@ discard block |
||
| 194 | 194 | $modx->setPlaceholder('pages.after', $afterPage); |
| 195 | 195 | |
| 196 | 196 | $debug = $DLObj->getCFGDef('debug', 0); |
| 197 | -if ($debug) { |
|
| 198 | - if ($debug > 0) { |
|
| 197 | +if ($debug) {
|
|
| 198 | + if ($debug > 0) {
|
|
| 199 | 199 | $out = $DLObj->debug->showLog() . $out; |
| 200 | - } else { |
|
| 200 | + } else {
|
|
| 201 | 201 | $out .= $DLObj->debug->showLog(); |
| 202 | 202 | } |
| 203 | 203 | } |
@@ -26,13 +26,13 @@ discard block |
||
| 26 | 26 | * year - по годам |
| 27 | 27 | */ |
| 28 | 28 | $reflectType = APIHelpers::getkey($params, 'reflectType', 'month'); |
| 29 | -if (!in_array($reflectType, array('year', 'month'))) { |
|
| 29 | +if ( ! in_array($reflectType, array('year', 'month'))) { |
|
| 30 | 30 | return ''; |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | -list($dateFormat, $sqlDateFormat, $reflectValidator) = DLReflect::switchReflect($reflectType, function () { |
|
| 33 | +list($dateFormat, $sqlDateFormat, $reflectValidator) = DLReflect::switchReflect($reflectType, function() { |
|
| 34 | 34 | return array('m-Y', '%m-%Y', array('DLReflect', 'validateMonth')); |
| 35 | -}, function () { |
|
| 35 | +}, function() { |
|
| 36 | 36 | return array('Y', '%Y', array('DLReflect', 'validateYear')); |
| 37 | 37 | }); |
| 38 | 38 | |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | $selectCurrentReflect = APIHelpers::getkey($params, 'selectCurrentReflect', 1); |
| 51 | 51 | if ($selectCurrentReflect) { |
| 52 | 52 | $currentReflect = APIHelpers::getkey($params, 'currentReflect', $tmp); |
| 53 | - if (!call_user_func($reflectValidator, $currentReflect)) { |
|
| 53 | + if ( ! call_user_func($reflectValidator, $currentReflect)) { |
|
| 54 | 54 | $currentReflect = $tmp; |
| 55 | 55 | } |
| 56 | 56 | } else { |
@@ -65,9 +65,9 @@ discard block |
||
| 65 | 65 | */ |
| 66 | 66 | $tmp = APIHelpers::getkey($params, 'activeReflect', $currentReflect); |
| 67 | 67 | $tmpGet = APIHelpers::getkey($_GET, $reflectType, $tmp); |
| 68 | -if (!call_user_func($reflectValidator, $tmpGet)) { |
|
| 68 | +if ( ! call_user_func($reflectValidator, $tmpGet)) { |
|
| 69 | 69 | $activeReflect = $tmp; |
| 70 | - if (!call_user_func($reflectValidator, $activeReflect)) { |
|
| 70 | + if ( ! call_user_func($reflectValidator, $activeReflect)) { |
|
| 71 | 71 | $activeReflect = $currentReflect; |
| 72 | 72 | } |
| 73 | 73 | } else { |
@@ -26,13 +26,13 @@ discard block |
||
| 26 | 26 | * year - по годам |
| 27 | 27 | */ |
| 28 | 28 | $reflectType = APIHelpers::getkey($params, 'reflectType', 'month'); |
| 29 | -if (!in_array($reflectType, array('year', 'month'))) { |
|
| 29 | +if (!in_array($reflectType, array('year', 'month'))) {
|
|
| 30 | 30 | return ''; |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | -list($dateFormat, $sqlDateFormat, $reflectValidator) = DLReflect::switchReflect($reflectType, function () { |
|
| 33 | +list($dateFormat, $sqlDateFormat, $reflectValidator) = DLReflect::switchReflect($reflectType, function () {
|
|
| 34 | 34 | return array('m-Y', '%m-%Y', array('DLReflect', 'validateMonth')); |
| 35 | -}, function () { |
|
| 35 | +}, function () {
|
|
| 36 | 36 | return array('Y', '%Y', array('DLReflect', 'validateYear')); |
| 37 | 37 | }); |
| 38 | 38 | |
@@ -48,12 +48,12 @@ discard block |
||
| 48 | 48 | * Если не указан в параметре, то генерируется автоматически текущая дата |
| 49 | 49 | */ |
| 50 | 50 | $selectCurrentReflect = APIHelpers::getkey($params, 'selectCurrentReflect', 1); |
| 51 | -if ($selectCurrentReflect) { |
|
| 51 | +if ($selectCurrentReflect) {
|
|
| 52 | 52 | $currentReflect = APIHelpers::getkey($params, 'currentReflect', $tmp); |
| 53 | - if (!call_user_func($reflectValidator, $currentReflect)) { |
|
| 53 | + if (!call_user_func($reflectValidator, $currentReflect)) {
|
|
| 54 | 54 | $currentReflect = $tmp; |
| 55 | 55 | } |
| 56 | -} else { |
|
| 56 | +} else {
|
|
| 57 | 57 | $currentReflect = null; |
| 58 | 58 | } |
| 59 | 59 | /** |
@@ -65,24 +65,24 @@ discard block |
||
| 65 | 65 | */ |
| 66 | 66 | $tmp = APIHelpers::getkey($params, 'activeReflect', $currentReflect); |
| 67 | 67 | $tmpGet = APIHelpers::getkey($_GET, $reflectType, $tmp); |
| 68 | -if (!call_user_func($reflectValidator, $tmpGet)) { |
|
| 68 | +if (!call_user_func($reflectValidator, $tmpGet)) {
|
|
| 69 | 69 | $activeReflect = $tmp; |
| 70 | - if (!call_user_func($reflectValidator, $activeReflect)) { |
|
| 70 | + if (!call_user_func($reflectValidator, $activeReflect)) {
|
|
| 71 | 71 | $activeReflect = $currentReflect; |
| 72 | 72 | } |
| 73 | -} else { |
|
| 73 | +} else {
|
|
| 74 | 74 | $activeReflect = $tmpGet; |
| 75 | 75 | } |
| 76 | -if ($activeReflect) { |
|
| 76 | +if ($activeReflect) {
|
|
| 77 | 77 | $v = $modx->db->escape($activeReflect); |
| 78 | - if ($reflectSource == 'tv') { |
|
| 78 | + if ($reflectSource == 'tv') {
|
|
| 79 | 79 | $params['tvSortType'] = 'TVDATETIME'; |
| 80 | 80 | $params['addWhereList'] = "DATE_FORMAT(STR_TO_DATE(`dltv_" . $reflectField . "_1`.`value`,'%d-%m-%Y %H:%i:%s'), '" . $sqlDateFormat . "')='" . $v . "'"; |
| 81 | - } else { |
|
| 81 | + } else {
|
|
| 82 | 82 | $params['addWhereList'] = "DATE_FORMAT(FROM_UNIXTIME(" . $reflectField . "), '" . $sqlDateFormat . "')='" . $v . "'"; |
| 83 | 83 | } |
| 84 | -} else { |
|
| 85 | - if ($reflectSource == 'tv') { |
|
| 84 | +} else {
|
|
| 85 | + if ($reflectSource == 'tv') {
|
|
| 86 | 86 | $params['tvSortType'] = 'TVDATETIME'; |
| 87 | 87 | } |
| 88 | 88 | } |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | 'format' => $format, |
| 89 | 89 | 'start' => microtime(true) - $this->DocLister->getTimeStart() |
| 90 | 90 | ); |
| 91 | - if (is_scalar($key) && !empty($key)) { |
|
| 91 | + if (is_scalar($key) && ! empty($key)) { |
|
| 92 | 92 | $data['time'] = microtime(true); |
| 93 | 93 | $this->_calcLog[$key] = $data; |
| 94 | 94 | } else { |
@@ -104,9 +104,9 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | public function updateMessage($message, $key, $format = null) |
| 106 | 106 | { |
| 107 | - if (is_scalar($key) && !empty($key) && isset($this->_calcLog[$key])) { |
|
| 107 | + if (is_scalar($key) && ! empty($key) && isset($this->_calcLog[$key])) { |
|
| 108 | 108 | $this->_calcLog[$key]['msg'] = $message; |
| 109 | - if (!is_null($format)) { |
|
| 109 | + if ( ! is_null($format)) { |
|
| 110 | 110 | $this->_calcLog[$key]['format'] = $format; |
| 111 | 111 | } |
| 112 | 112 | } |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | */ |
| 166 | 166 | private function _sendLogEvent($type, $message, $title = '') |
| 167 | 167 | { |
| 168 | - $title = "DocLister" . (!empty($title) ? ' - ' . $title : ''); |
|
| 168 | + $title = "DocLister" . ( ! empty($title) ? ' - ' . $title : ''); |
|
| 169 | 169 | $this->modx->logEvent(0, $type, $message, $title); |
| 170 | 170 | } |
| 171 | 171 | |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | $msg = $this->dumpData($msg); |
| 204 | 204 | break; |
| 205 | 205 | } |
| 206 | - if (!empty($title) && !is_numeric($title)) { |
|
| 206 | + if ( ! empty($title) && ! is_numeric($title)) { |
|
| 207 | 207 | $message .= $this->DocLister->parseChunk('@CODE:<strong>[+title+]</strong>: [+msg+]<br />', |
| 208 | 208 | compact('msg', 'title')); |
| 209 | 209 | } else { |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | </li>'; |
| 223 | 223 | $out .= $this->DocLister->parseChunk("@CODE: " . $tpl, $item); |
| 224 | 224 | } |
| 225 | - if (!empty($out)) { |
|
| 225 | + if ( ! empty($out)) { |
|
| 226 | 226 | $out = $this->DocLister->parseChunk("@CODE: |
| 227 | 227 | <style>.dlDebug{ |
| 228 | 228 | background: #eee !important; |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | public function dumpData($data, $wrap = '', $charset = 'UTF-8') |
| 280 | 280 | { |
| 281 | 281 | $out = $this->DocLister->sanitarData(print_r($data, 1), $charset); |
| 282 | - if (!empty($wrap) && is_string($wrap)) { |
|
| 282 | + if ( ! empty($wrap) && is_string($wrap)) { |
|
| 283 | 283 | $out = "<{$wrap}>{$out}</{$wrap}>"; |
| 284 | 284 | } |
| 285 | 285 | |
@@ -5,8 +5,8 @@ discard block |
||
| 5 | 5 | /** |
| 6 | 6 | * Class DLdebug |
| 7 | 7 | */ |
| 8 | -class DLdebug |
|
| 9 | -{ |
|
| 8 | +class DLdebug |
|
| 9 | +{
|
|
| 10 | 10 | /** |
| 11 | 11 | * @var array |
| 12 | 12 | */ |
@@ -35,9 +35,9 @@ discard block |
||
| 35 | 35 | * DLdebug constructor. |
| 36 | 36 | * @param $DocLister |
| 37 | 37 | */ |
| 38 | - public function __construct($DocLister) |
|
| 39 | - { |
|
| 40 | - if ($DocLister instanceof DocLister) { |
|
| 38 | + public function __construct($DocLister) |
|
| 39 | + {
|
|
| 40 | + if ($DocLister instanceof DocLister) {
|
|
| 41 | 41 | $this->DocLister = $DocLister; |
| 42 | 42 | $this->modx = $this->DocLister->getMODX(); |
| 43 | 43 | } |
@@ -47,16 +47,16 @@ discard block |
||
| 47 | 47 | /** |
| 48 | 48 | * @return array |
| 49 | 49 | */ |
| 50 | - public function getLog() |
|
| 51 | - { |
|
| 50 | + public function getLog() |
|
| 51 | + {
|
|
| 52 | 52 | return $this->_log; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | 56 | * @return $this |
| 57 | 57 | */ |
| 58 | - public function clearLog() |
|
| 59 | - { |
|
| 58 | + public function clearLog() |
|
| 59 | + {
|
|
| 60 | 60 | $this->_log = array(); |
| 61 | 61 | |
| 62 | 62 | return $this; |
@@ -65,8 +65,8 @@ discard block |
||
| 65 | 65 | /** |
| 66 | 66 | * @return int |
| 67 | 67 | */ |
| 68 | - public function countLog() |
|
| 69 | - { |
|
| 68 | + public function countLog() |
|
| 69 | + {
|
|
| 70 | 70 | return count($this->_log); |
| 71 | 71 | } |
| 72 | 72 | |
@@ -79,19 +79,19 @@ discard block |
||
| 79 | 79 | * @param int $mode |
| 80 | 80 | * @param bool $format |
| 81 | 81 | */ |
| 82 | - public function debug($message, $key = null, $mode = 0, $format = false) |
|
| 83 | - { |
|
| 82 | + public function debug($message, $key = null, $mode = 0, $format = false) |
|
| 83 | + {
|
|
| 84 | 84 | $mode = (int)$mode; |
| 85 | - if ($mode > 0 && $this->DocLister->getDebug() >= $mode) { |
|
| 85 | + if ($mode > 0 && $this->DocLister->getDebug() >= $mode) {
|
|
| 86 | 86 | $data = array( |
| 87 | 87 | 'msg' => $message, |
| 88 | 88 | 'format' => $format, |
| 89 | 89 | 'start' => microtime(true) - $this->DocLister->getTimeStart() |
| 90 | 90 | ); |
| 91 | - if (is_scalar($key) && !empty($key)) { |
|
| 91 | + if (is_scalar($key) && !empty($key)) {
|
|
| 92 | 92 | $data['time'] = microtime(true); |
| 93 | 93 | $this->_calcLog[$key] = $data; |
| 94 | - } else { |
|
| 94 | + } else {
|
|
| 95 | 95 | $this->_log[$this->countLog()] = $data; |
| 96 | 96 | } |
| 97 | 97 | } |
@@ -102,11 +102,11 @@ discard block |
||
| 102 | 102 | * @param $key |
| 103 | 103 | * @param null $format |
| 104 | 104 | */ |
| 105 | - public function updateMessage($message, $key, $format = null) |
|
| 106 | - { |
|
| 107 | - if (is_scalar($key) && !empty($key) && isset($this->_calcLog[$key])) { |
|
| 105 | + public function updateMessage($message, $key, $format = null) |
|
| 106 | + {
|
|
| 107 | + if (is_scalar($key) && !empty($key) && isset($this->_calcLog[$key])) {
|
|
| 108 | 108 | $this->_calcLog[$key]['msg'] = $message; |
| 109 | - if (!is_null($format)) { |
|
| 109 | + if (!is_null($format)) {
|
|
| 110 | 110 | $this->_calcLog[$key]['format'] = $format; |
| 111 | 111 | } |
| 112 | 112 | } |
@@ -117,9 +117,9 @@ discard block |
||
| 117 | 117 | * @param null $msg |
| 118 | 118 | * @param null $format |
| 119 | 119 | */ |
| 120 | - public function debugEnd($key, $msg = null, $format = null) |
|
| 121 | - { |
|
| 122 | - if (is_scalar($key) && isset($this->_calcLog[$key], $this->_calcLog[$key]['time']) && $this->DocLister->getDebug() > 0) { |
|
| 120 | + public function debugEnd($key, $msg = null, $format = null) |
|
| 121 | + {
|
|
| 122 | + if (is_scalar($key) && isset($this->_calcLog[$key], $this->_calcLog[$key]['time']) && $this->DocLister->getDebug() > 0) {
|
|
| 123 | 123 | $this->_log[$this->countLog()] = array( |
| 124 | 124 | 'msg' => isset($msg) ? $msg : $this->_calcLog[$key]['msg'], |
| 125 | 125 | 'start' => $this->_calcLog[$key]['start'], |
@@ -135,8 +135,8 @@ discard block |
||
| 135 | 135 | * @param $message |
| 136 | 136 | * @param string $title |
| 137 | 137 | */ |
| 138 | - public function info($message, $title = '') |
|
| 139 | - { |
|
| 138 | + public function info($message, $title = '') |
|
| 139 | + {
|
|
| 140 | 140 | $this->_sendLogEvent(1, $message, $title); |
| 141 | 141 | } |
| 142 | 142 | |
@@ -144,8 +144,8 @@ discard block |
||
| 144 | 144 | * @param $message |
| 145 | 145 | * @param string $title |
| 146 | 146 | */ |
| 147 | - public function warning($message, $title = '') |
|
| 148 | - { |
|
| 147 | + public function warning($message, $title = '') |
|
| 148 | + {
|
|
| 149 | 149 | $this->_sendLogEvent(2, $message, $title); |
| 150 | 150 | } |
| 151 | 151 | |
@@ -153,8 +153,8 @@ discard block |
||
| 153 | 153 | * @param $message |
| 154 | 154 | * @param string $title |
| 155 | 155 | */ |
| 156 | - public function error($message, $title = '') |
|
| 157 | - { |
|
| 156 | + public function error($message, $title = '') |
|
| 157 | + {
|
|
| 158 | 158 | $this->_sendLogEvent(3, $message, $title); |
| 159 | 159 | } |
| 160 | 160 | |
@@ -163,8 +163,8 @@ discard block |
||
| 163 | 163 | * @param $message |
| 164 | 164 | * @param string $title |
| 165 | 165 | */ |
| 166 | - private function _sendLogEvent($type, $message, $title = '') |
|
| 167 | - { |
|
| 166 | + private function _sendLogEvent($type, $message, $title = '') |
|
| 167 | + {
|
|
| 168 | 168 | $title = "DocLister" . (!empty($title) ? ' - ' . $title : ''); |
| 169 | 169 | $this->modx->logEvent(0, $type, $message, $title); |
| 170 | 170 | } |
@@ -172,26 +172,26 @@ discard block |
||
| 172 | 172 | /** |
| 173 | 173 | * @return string |
| 174 | 174 | */ |
| 175 | - public function showLog() |
|
| 176 | - { |
|
| 175 | + public function showLog() |
|
| 176 | + {
|
|
| 177 | 177 | $out = ""; |
| 178 | - if ($this->DocLister->getDebug() > 0 && is_array($this->_log)) { |
|
| 179 | - foreach ($this->_log as $item) { |
|
| 178 | + if ($this->DocLister->getDebug() > 0 && is_array($this->_log)) {
|
|
| 179 | + foreach ($this->_log as $item) {
|
|
| 180 | 180 | $item['time'] = isset($item['time']) ? round(floatval($item['time']), 5) : 0; |
| 181 | 181 | $item['start'] = isset($item['start']) ? round(floatval($item['start']), 5) : 0; |
| 182 | 182 | |
| 183 | - if (isset($item['msg'])) { |
|
| 184 | - if (is_scalar($item['msg'])) { |
|
| 183 | + if (isset($item['msg'])) {
|
|
| 184 | + if (is_scalar($item['msg'])) {
|
|
| 185 | 185 | $item['msg'] = array($item['msg']); |
| 186 | 186 | } |
| 187 | - if (is_scalar($item['format'])) { |
|
| 187 | + if (is_scalar($item['format'])) {
|
|
| 188 | 188 | $item['format'] = array($item['format']); |
| 189 | 189 | } |
| 190 | 190 | $message = ''; |
| 191 | 191 | $i = 0; |
| 192 | - foreach ($item['msg'] as $title => $msg) { |
|
| 192 | + foreach ($item['msg'] as $title => $msg) {
|
|
| 193 | 193 | $format = isset($item['format'][$i]) ? $item['format'][$i] : null; |
| 194 | - switch ($format) { |
|
| 194 | + switch ($format) {
|
|
| 195 | 195 | case 'sql': |
| 196 | 196 | $msg = $this->dumpData(Formatter\SqlFormatter::format($msg), '', null); |
| 197 | 197 | break; |
@@ -203,16 +203,16 @@ discard block |
||
| 203 | 203 | $msg = $this->dumpData($msg); |
| 204 | 204 | break; |
| 205 | 205 | } |
| 206 | - if (!empty($title) && !is_numeric($title)) { |
|
| 206 | + if (!empty($title) && !is_numeric($title)) {
|
|
| 207 | 207 | $message .= $this->DocLister->parseChunk('@CODE:<strong>[+title+]</strong>: [+msg+]<br />', |
| 208 | 208 | compact('msg', 'title')); |
| 209 | - } else { |
|
| 209 | + } else {
|
|
| 210 | 210 | $message .= $msg; |
| 211 | 211 | } |
| 212 | 212 | $i++; |
| 213 | 213 | } |
| 214 | 214 | $item['msg'] = $message; |
| 215 | - } else { |
|
| 215 | + } else {
|
|
| 216 | 216 | $item['msg'] = ''; |
| 217 | 217 | } |
| 218 | 218 | |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | </li>'; |
| 223 | 223 | $out .= $this->DocLister->parseChunk("@CODE: " . $tpl, $item); |
| 224 | 224 | } |
| 225 | - if (!empty($out)) { |
|
| 225 | + if (!empty($out)) {
|
|
| 226 | 226 | $out = $this->DocLister->parseChunk("@CODE: |
| 227 | 227 | <style>.dlDebug{ |
| 228 | 228 | background: #eee !important; |
@@ -276,10 +276,10 @@ discard block |
||
| 276 | 276 | * @param string $charset |
| 277 | 277 | * @return string |
| 278 | 278 | */ |
| 279 | - public function dumpData($data, $wrap = '', $charset = 'UTF-8') |
|
| 280 | - { |
|
| 279 | + public function dumpData($data, $wrap = '', $charset = 'UTF-8') |
|
| 280 | + {
|
|
| 281 | 281 | $out = $this->DocLister->sanitarData(print_r($data, 1), $charset); |
| 282 | - if (!empty($wrap) && is_string($wrap)) { |
|
| 282 | + if (!empty($wrap) && is_string($wrap)) {
|
|
| 283 | 283 | $out = "<{$wrap}>{$out}</{$wrap}>"; |
| 284 | 284 | } |
| 285 | 285 | |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if (!class_exists("DLReflect", false)) { |
|
| 3 | +if ( ! class_exists("DLReflect", false)) { |
|
| 4 | 4 | /** |
| 5 | 5 | * Class DLReflect |
| 6 | 6 | */ |
@@ -1,19 +1,19 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if (!class_exists("DLReflect", false)) { |
|
| 3 | +if (!class_exists("DLReflect", false)) {
|
|
| 4 | 4 | /** |
| 5 | 5 | * Class DLReflect |
| 6 | 6 | */ |
| 7 | - class DLReflect |
|
| 8 | - { |
|
| 7 | + class DLReflect |
|
| 8 | + {
|
|
| 9 | 9 | /** |
| 10 | 10 | * @param $val |
| 11 | 11 | * @return bool |
| 12 | 12 | */ |
| 13 | - public static function validateMonth($val) |
|
| 14 | - { |
|
| 13 | + public static function validateMonth($val) |
|
| 14 | + {
|
|
| 15 | 15 | $flag = false; |
| 16 | - if (is_scalar($val)) { |
|
| 16 | + if (is_scalar($val)) {
|
|
| 17 | 17 | $val = explode("-", $val, 2); |
| 18 | 18 | $flag = (count($val) && is_array($val) && strlen($val[0]) == 2 && strlen($val[1]) == 4); //Валидация содержимого массива |
| 19 | 19 | $flag = ($flag && (int)$val[0] > 0 && (int)$val[0] <= 12); //Валидация месяца |
@@ -27,10 +27,10 @@ discard block |
||
| 27 | 27 | * @param $val |
| 28 | 28 | * @return bool |
| 29 | 29 | */ |
| 30 | - public static function validateYear($val) |
|
| 31 | - { |
|
| 30 | + public static function validateYear($val) |
|
| 31 | + {
|
|
| 32 | 32 | $flag = false; |
| 33 | - if (is_scalar($val)) { |
|
| 33 | + if (is_scalar($val)) {
|
|
| 34 | 34 | $flag = (strlen($val) == 4); //Валидация строки |
| 35 | 35 | $flag = ($flag && (int)$val > 1900 && (int)$val <= 2100); //Валидация года |
| 36 | 36 | } |
@@ -44,8 +44,8 @@ discard block |
||
| 44 | 44 | * @param $yearAction |
| 45 | 45 | * @return mixed|null |
| 46 | 46 | */ |
| 47 | - public static function switchReflect($type, $monthAction, $yearAction) |
|
| 48 | - { |
|
| 47 | + public static function switchReflect($type, $monthAction, $yearAction) |
|
| 48 | + {
|
|
| 49 | 49 | $out = null; |
| 50 | 50 | $action = $type . "Action"; |
| 51 | 51 | |
@@ -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'; |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | * @param int $debug |
| 44 | 44 | * @param int $maxpass |
| 45 | 45 | */ |
| 46 | - public function __construct($debug = 0, $maxpass = 50) |
|
| 47 | - { |
|
| 46 | + public function __construct($debug = 0, $maxpass = 50) |
|
| 47 | + {
|
|
| 48 | 48 | global $modx; |
| 49 | 49 | $this->user["mgrid"] = isset($_SESSION['mgrInternalKey']) ? intval($_SESSION['mgrInternalKey']) : 0; |
| 50 | 50 | $this->user["usrid"] = isset($_SESSION['webInternalKey']) ? intval($_SESSION['webInternalKey']) : 0; |
@@ -55,14 +55,14 @@ discard block |
||
| 55 | 55 | $this->maxPasses = ($maxpass != '') ? $maxpass : 50; |
| 56 | 56 | |
| 57 | 57 | $modx->setPlaceholder("phx", "&_PHX_INTERNAL_&"); |
| 58 | - if (function_exists('mb_internal_encoding')) { |
|
| 58 | + if (function_exists('mb_internal_encoding')) {
|
|
| 59 | 59 | mb_internal_encoding($modx->config['modx_charset']); |
| 60 | 60 | } |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | // Plugin event hook for MODx |
| 64 | - public function OnParseDocument() |
|
| 65 | - { |
|
| 64 | + public function OnParseDocument() |
|
| 65 | + {
|
|
| 66 | 66 | global $modx; |
| 67 | 67 | // Get document output from MODx |
| 68 | 68 | $template = $modx->documentOutput; |
@@ -77,11 +77,11 @@ discard block |
||
| 77 | 77 | * @param string $template |
| 78 | 78 | * @return mixed|string |
| 79 | 79 | */ |
| 80 | - public function Parse($template = '') |
|
| 81 | - { |
|
| 80 | + public function Parse($template = '') |
|
| 81 | + {
|
|
| 82 | 82 | global $modx; |
| 83 | 83 | // If we already reached max passes don't get at it again. |
| 84 | - if ($this->curPass == $this->maxPasses) { |
|
| 84 | + if ($this->curPass == $this->maxPasses) {
|
|
| 85 | 85 | return $template; |
| 86 | 86 | } |
| 87 | 87 | // Set template pre-process hash |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | $template = $this->ParseValues($template); |
| 93 | 93 | // clean up unused placeholders that have modifiers attached (MODx can't clean them) |
| 94 | 94 | preg_match_all('~(?:=`[^`@]*?)(\[\+([^:\+\[\]]+)([^\[\]]*?)\+\])~s', $template, $matches); |
| 95 | - if ($matches[0]) { |
|
| 95 | + if ($matches[0]) {
|
|
| 96 | 96 | $template = str_replace($matches[1], '', $template); |
| 97 | 97 | $this->Log("Cleaning unsolved tags: \n" . implode("\n", $matches[2])); |
| 98 | 98 | } |
@@ -101,11 +101,11 @@ discard block |
||
| 101 | 101 | // Set template post-process hash |
| 102 | 102 | $et = md5($template); |
| 103 | 103 | // If template has changed, parse it once more... |
| 104 | - if ($st != $et) { |
|
| 104 | + if ($st != $et) {
|
|
| 105 | 105 | $template = $this->Parse($template); |
| 106 | 106 | } |
| 107 | 107 | // Write an event log if debugging is enabled and there is something to log |
| 108 | - if ($this->debug && $this->debugLog) { |
|
| 108 | + if ($this->debug && $this->debugLog) {
|
|
| 109 | 109 | $modx->logEvent($this->curPass, 1, $this->createEventLog(), $this->name . ' ' . $this->version); |
| 110 | 110 | $this->debugLog = false; |
| 111 | 111 | } |
@@ -119,8 +119,8 @@ discard block |
||
| 119 | 119 | * @param string $template |
| 120 | 120 | * @return mixed|string |
| 121 | 121 | */ |
| 122 | - public function ParseValues($template = '') |
|
| 123 | - { |
|
| 122 | + public function ParseValues($template = '') |
|
| 123 | + {
|
|
| 124 | 124 | global $modx; |
| 125 | 125 | |
| 126 | 126 | $this->curPass = $this->curPass + 1; |
@@ -129,12 +129,12 @@ discard block |
||
| 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 | $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 | |
@@ -236,23 +236,23 @@ discard block |
||
| 236 | 236 | * @param $modifiers |
| 237 | 237 | * @return mixed|null|string |
| 238 | 238 | */ |
| 239 | - public function Filter($input, $modifiers) |
|
| 240 | - { |
|
| 239 | + public function Filter($input, $modifiers) |
|
| 240 | + {
|
|
| 241 | 241 | global $modx; |
| 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(eval("return (" . $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(eval("return (" . $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(eval("return (" . $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 | } |
@@ -414,13 +414,13 @@ discard block |
||
| 414 | 414 | $output = eval("return " . $filter . ";"); |
| 415 | 415 | break; |
| 416 | 416 | case "isnotempty": |
| 417 | - if (!empty($output)) { |
|
| 417 | + if (!empty($output)) {
|
|
| 418 | 418 | $output = $modifier_value[$i]; |
| 419 | 419 | } |
| 420 | 420 | break; |
| 421 | 421 | case "isempty": |
| 422 | 422 | case "ifempty": |
| 423 | - if (empty($output)) { |
|
| 423 | + if (empty($output)) {
|
|
| 424 | 424 | $output = $modifier_value[$i]; |
| 425 | 425 | } |
| 426 | 426 | break; |
@@ -432,12 +432,12 @@ discard block |
||
| 432 | 432 | break; |
| 433 | 433 | case "set": |
| 434 | 434 | $c = $i + 1; |
| 435 | - if ($count > $c && $modifier_cmd[$c] == "value") { |
|
| 435 | + if ($count > $c && $modifier_cmd[$c] == "value") {
|
|
| 436 | 436 | $output = preg_replace("~([^a-zA-Z0-9])~", "", $modifier_value[$i]); |
| 437 | 437 | } |
| 438 | 438 | break; |
| 439 | 439 | case "value": |
| 440 | - if ($i > 0 && $modifier_cmd[$i - 1] == "set") { |
|
| 440 | + if ($i > 0 && $modifier_cmd[$i - 1] == "set") {
|
|
| 441 | 441 | $modx->SetPlaceholder("phx." . $output, $modifier_value[$i]); |
| 442 | 442 | } |
| 443 | 443 | $output = null; |
@@ -446,13 +446,13 @@ discard block |
||
| 446 | 446 | $output = md5($output); |
| 447 | 447 | break; |
| 448 | 448 | case "userinfo": |
| 449 | - if ($output == "&_PHX_INTERNAL_&") { |
|
| 449 | + if ($output == "&_PHX_INTERNAL_&") {
|
|
| 450 | 450 | $output = $this->user["id"]; |
| 451 | 451 | } |
| 452 | 452 | $output = $this->ModUser($output, $modifier_value[$i]); |
| 453 | 453 | break; |
| 454 | 454 | case "inrole": // deprecated |
| 455 | - if ($output == "&_PHX_INTERNAL_&") { |
|
| 455 | + if ($output == "&_PHX_INTERNAL_&") {
|
|
| 456 | 456 | $output = $this->user["id"]; |
| 457 | 457 | } |
| 458 | 458 | $grps = ($this->strlen($modifier_value[$i]) > 0) ? explode(",", $modifier_value[$i]) : array(); |
@@ -464,19 +464,21 @@ discard block |
||
| 464 | 464 | $snippet = ''; |
| 465 | 465 | // modified by Anton Kuzmin (23.06.2010) // |
| 466 | 466 | $snippetName = 'phx:' . $modifier_cmd[$i]; |
| 467 | - if (isset($modx->snippetCache[$snippetName])) { |
|
| 467 | + if (isset($modx->snippetCache[$snippetName])) {
|
|
| 468 | 468 | $snippet = $modx->snippetCache[$snippetName]; |
| 469 | - } else { // not in cache so let's check the db |
|
| 469 | + } else {
|
|
| 470 | +// not in cache so let's check the db |
|
| 470 | 471 | $sql = "SELECT snippet FROM " . $modx->getFullTableName("site_snippets") . " WHERE " . $modx->getFullTableName("site_snippets") . ".name='" . $modx->db->escape($snippetName) . "';"; |
| 471 | 472 | $result = $modx->dbQuery($sql); |
| 472 | - if ($modx->recordCount($result) == 1) { |
|
| 473 | + if ($modx->recordCount($result) == 1) {
|
|
| 473 | 474 | $row = $modx->fetchRow($result); |
| 474 | 475 | $snippet = $modx->snippetCache[$row['name']] = $row['snippet']; |
| 475 | 476 | $this->Log(" |--- DB -> Custom Modifier"); |
| 476 | - } else { |
|
| 477 | - if ($modx->recordCount($result) == 0) { // If snippet not found, look in the modifiers folder |
|
| 477 | + } else {
|
|
| 478 | + if ($modx->recordCount($result) == 0) {
|
|
| 479 | +// If snippet not found, look in the modifiers folder |
|
| 478 | 480 | $filename = $modx->config['rb_base_dir'] . 'plugins/phx/modifiers/' . $modifier_cmd[$i] . '.phx.php'; |
| 479 | - if (@file_exists($filename)) { |
|
| 481 | + if (@file_exists($filename)) {
|
|
| 480 | 482 | $file_contents = @file_get_contents($filename); |
| 481 | 483 | $file_contents = str_replace('<' . '?php', '', $file_contents); |
| 482 | 484 | $file_contents = str_replace('?' . '>', '', $file_contents); |
@@ -484,7 +486,7 @@ discard block |
||
| 484 | 486 | $snippet = $modx->snippetCache[$snippetName] = $file_contents; |
| 485 | 487 | $modx->snippetCache[$snippetName . 'Props'] = ''; |
| 486 | 488 | $this->Log(" |--- File ($filename) -> Custom Modifier"); |
| 487 | - } else { |
|
| 489 | + } else {
|
|
| 488 | 490 | $this->Log(" |--- PHX Error: {$modifier_cmd[$i]} could not be found"); |
| 489 | 491 | } |
| 490 | 492 | } |
@@ -493,19 +495,19 @@ discard block |
||
| 493 | 495 | $cm = $snippet; |
| 494 | 496 | // end // |
| 495 | 497 | |
| 496 | - if (!empty($cm)) { |
|
| 498 | + if (!empty($cm)) {
|
|
| 497 | 499 | ob_start(); |
| 498 | 500 | $options = $modifier_value[$i]; |
| 499 | 501 | $custom = eval($cm); |
| 500 | 502 | $msg = ob_get_contents(); |
| 501 | 503 | $output = $msg . $custom; |
| 502 | 504 | ob_end_clean(); |
| 503 | - } else { |
|
| 505 | + } else {
|
|
| 504 | 506 | $output = ''; |
| 505 | 507 | } |
| 506 | 508 | break; |
| 507 | 509 | } |
| 508 | - if (count($condition)) { |
|
| 510 | + if (count($condition)) {
|
|
| 509 | 511 | $this->Log(" |--- Condition = '" . $condition[count($condition) - 1] . "'"); |
| 510 | 512 | } |
| 511 | 513 | $this->Log(" |--- Output = '" . $output . "'"); |
@@ -519,9 +521,9 @@ discard block |
||
| 519 | 521 | /** |
| 520 | 522 | * @return string |
| 521 | 523 | */ |
| 522 | - public function createEventLog() |
|
| 523 | - { |
|
| 524 | - if (!empty($this->console)) { |
|
| 524 | + public function createEventLog() |
|
| 525 | + {
|
|
| 526 | + if (!empty($this->console)) {
|
|
| 525 | 527 | $console = implode("\n", $this->console); |
| 526 | 528 | $this->console = array(); |
| 527 | 529 | |
@@ -534,8 +536,8 @@ discard block |
||
| 534 | 536 | * @param $string |
| 535 | 537 | * @return array|mixed|string |
| 536 | 538 | */ |
| 537 | - public function LogClean($string) |
|
| 538 | - { |
|
| 539 | + public function LogClean($string) |
|
| 540 | + {
|
|
| 539 | 541 | $string = preg_replace("/&(#[0-9]+|[a-z]+);/i", "&$1;", $string); |
| 540 | 542 | $string = APIHelpers::sanitarTag($string); |
| 541 | 543 | |
@@ -546,9 +548,9 @@ discard block |
||
| 546 | 548 | /** |
| 547 | 549 | * @param $string |
| 548 | 550 | */ |
| 549 | - public function Log($string) |
|
| 550 | - { |
|
| 551 | - if ($this->debug) { |
|
| 551 | + public function Log($string) |
|
| 552 | + {
|
|
| 553 | + if ($this->debug) {
|
|
| 552 | 554 | $this->debugLog = true; |
| 553 | 555 | $this->console[] = (count($this->console) + 1 - $this->curPass) . " [" . strftime("%H:%M:%S", |
| 554 | 556 | time()) . "] " . $this->LogClean($string); |
@@ -559,9 +561,9 @@ discard block |
||
| 559 | 561 | /** |
| 560 | 562 | * @param $string |
| 561 | 563 | */ |
| 562 | - public function LogSnippet($string) |
|
| 563 | - { |
|
| 564 | - if ($this->debug) { |
|
| 564 | + public function LogSnippet($string) |
|
| 565 | + {
|
|
| 566 | + if ($this->debug) {
|
|
| 565 | 567 | $this->debugLog = true; |
| 566 | 568 | $this->console[] = (count($this->console) + 1 - $this->curPass) . " [" . strftime("%H:%M:%S", |
| 567 | 569 | time()) . "] " . " |--- Returns: <div style='margin: 10px;'>" . $this->LogClean($string) . "</div>"; |
@@ -569,8 +571,8 @@ discard block |
||
| 569 | 571 | } |
| 570 | 572 | |
| 571 | 573 | // Log pass |
| 572 | - public function LogPass() |
|
| 573 | - { |
|
| 574 | + public function LogPass() |
|
| 575 | + {
|
|
| 574 | 576 | $this->console[] = "<div style='margin: 2px;margin-top: 5px;border-bottom: 1px solid black;'>Pass " . $this->curPass . "</div>"; |
| 575 | 577 | } |
| 576 | 578 | |
@@ -578,8 +580,8 @@ discard block |
||
| 578 | 580 | /** |
| 579 | 581 | * @param $string |
| 580 | 582 | */ |
| 581 | - public function LogSource($string) |
|
| 582 | - { |
|
| 583 | + public function LogSource($string) |
|
| 584 | + {
|
|
| 583 | 585 | $this->console[] = "<div style='margin: 2px;margin-top: 5px;border-bottom: 1px solid black;'>Source:</div>" . $this->LogClean($string); |
| 584 | 586 | } |
| 585 | 587 | |
@@ -591,17 +593,17 @@ discard block |
||
| 591 | 593 | * @param $field |
| 592 | 594 | * @return mixed |
| 593 | 595 | */ |
| 594 | - public function ModUser($userid, $field) |
|
| 595 | - { |
|
| 596 | + public function ModUser($userid, $field) |
|
| 597 | + {
|
|
| 596 | 598 | global $modx; |
| 597 | - if (!array_key_exists($userid, $this->cache["ui"])) { |
|
| 598 | - if (intval($userid) < 0) { |
|
| 599 | + if (!array_key_exists($userid, $this->cache["ui"])) {
|
|
| 600 | + if (intval($userid) < 0) {
|
|
| 599 | 601 | $user = $modx->getWebUserInfo(-($userid)); |
| 600 | - } else { |
|
| 602 | + } else {
|
|
| 601 | 603 | $user = $modx->getUserInfo($userid); |
| 602 | 604 | } |
| 603 | 605 | $this->cache["ui"][$userid] = $user; |
| 604 | - } else { |
|
| 606 | + } else {
|
|
| 605 | 607 | $user = $this->cache["ui"][$userid]; |
| 606 | 608 | } |
| 607 | 609 | |
@@ -614,32 +616,32 @@ discard block |
||
| 614 | 616 | * @param array $groupNames |
| 615 | 617 | * @return bool |
| 616 | 618 | */ |
| 617 | - public function isMemberOfWebGroupByUserId($userid = 0, $groupNames = array()) |
|
| 618 | - { |
|
| 619 | + public function isMemberOfWebGroupByUserId($userid = 0, $groupNames = array()) |
|
| 620 | + {
|
|
| 619 | 621 | global $modx; |
| 620 | 622 | |
| 621 | 623 | // if $groupNames is not an array return false |
| 622 | - if (!is_array($groupNames)) { |
|
| 624 | + if (!is_array($groupNames)) {
|
|
| 623 | 625 | return false; |
| 624 | 626 | } |
| 625 | 627 | |
| 626 | 628 | // if the user id is a negative number make it positive |
| 627 | - if (intval($userid) < 0) { |
|
| 629 | + if (intval($userid) < 0) {
|
|
| 628 | 630 | $userid = -($userid); |
| 629 | 631 | } |
| 630 | 632 | |
| 631 | 633 | // Creates an array with all webgroups the user id is in |
| 632 | - if (!array_key_exists($userid, $this->cache["mo"])) { |
|
| 634 | + if (!array_key_exists($userid, $this->cache["mo"])) {
|
|
| 633 | 635 | $tbl = $modx->getFullTableName("webgroup_names"); |
| 634 | 636 | $tbl2 = $modx->getFullTableName("web_groups"); |
| 635 | 637 | $sql = "SELECT wgn.name FROM $tbl wgn INNER JOIN $tbl2 wg ON wg.webgroup=wgn.id AND wg.webuser='" . $userid . "'"; |
| 636 | 638 | $this->cache["mo"][$userid] = $grpNames = $modx->db->getColumn("name", $sql); |
| 637 | - } else { |
|
| 639 | + } else {
|
|
| 638 | 640 | $grpNames = $this->cache["mo"][$userid]; |
| 639 | 641 | } |
| 640 | 642 | // Check if a supplied group matches a webgroup from the array we just created |
| 641 | - foreach ($groupNames as $k => $v) { |
|
| 642 | - if (in_array(trim($v), $grpNames)) { |
|
| 643 | + foreach ($groupNames as $k => $v) {
|
|
| 644 | + if (in_array(trim($v), $grpNames)) {
|
|
| 643 | 645 | return true; |
| 644 | 646 | } |
| 645 | 647 | } |
@@ -653,14 +655,14 @@ discard block |
||
| 653 | 655 | * @param $name |
| 654 | 656 | * @return mixed|string |
| 655 | 657 | */ |
| 656 | - public function getPHxVariable($name) |
|
| 657 | - { |
|
| 658 | + public function getPHxVariable($name) |
|
| 659 | + {
|
|
| 658 | 660 | global $modx; |
| 659 | 661 | // Check if this variable is created by PHx |
| 660 | - if (array_key_exists($name, $this->placeholders)) { |
|
| 662 | + if (array_key_exists($name, $this->placeholders)) {
|
|
| 661 | 663 | // Return the value from PHx |
| 662 | 664 | return $this->placeholders[$name]; |
| 663 | - } else { |
|
| 665 | + } else {
|
|
| 664 | 666 | // Return the value from MODx |
| 665 | 667 | return $modx->getPlaceholder($name); |
| 666 | 668 | } |
@@ -671,9 +673,9 @@ discard block |
||
| 671 | 673 | * @param $name |
| 672 | 674 | * @param $value |
| 673 | 675 | */ |
| 674 | - public function setPHxVariable($name, $value) |
|
| 675 | - { |
|
| 676 | - if ($name != "phx") { |
|
| 676 | + public function setPHxVariable($name, $value) |
|
| 677 | + {
|
|
| 678 | + if ($name != "phx") {
|
|
| 677 | 679 | $this->placeholders[$name] = $value; |
| 678 | 680 | } |
| 679 | 681 | } |
@@ -685,9 +687,9 @@ discard block |
||
| 685 | 687 | * @param null $l |
| 686 | 688 | * @return string |
| 687 | 689 | */ |
| 688 | - public function substr($str, $s, $l = null) |
|
| 689 | - { |
|
| 690 | - if (function_exists('mb_substr')) { |
|
| 690 | + public function substr($str, $s, $l = null) |
|
| 691 | + {
|
|
| 692 | + if (function_exists('mb_substr')) {
|
|
| 691 | 693 | return mb_substr($str, $s, $l); |
| 692 | 694 | } |
| 693 | 695 | |
@@ -698,9 +700,9 @@ discard block |
||
| 698 | 700 | * @param $str |
| 699 | 701 | * @return int |
| 700 | 702 | */ |
| 701 | - public function strlen($str) |
|
| 702 | - { |
|
| 703 | - if (function_exists('mb_strlen')) { |
|
| 703 | + public function strlen($str) |
|
| 704 | + {
|
|
| 705 | + if (function_exists('mb_strlen')) {
|
|
| 704 | 706 | return mb_strlen($str); |
| 705 | 707 | } |
| 706 | 708 | |
@@ -711,9 +713,9 @@ discard block |
||
| 711 | 713 | * @param $str |
| 712 | 714 | * @return string |
| 713 | 715 | */ |
| 714 | - public function strtolower($str) |
|
| 715 | - { |
|
| 716 | - if (function_exists('mb_strtolower')) { |
|
| 716 | + public function strtolower($str) |
|
| 717 | + {
|
|
| 718 | + if (function_exists('mb_strtolower')) {
|
|
| 717 | 719 | return mb_strtolower($str); |
| 718 | 720 | } |
| 719 | 721 | |
@@ -724,9 +726,9 @@ discard block |
||
| 724 | 726 | * @param $str |
| 725 | 727 | * @return string |
| 726 | 728 | */ |
| 727 | - public function strtoupper($str) |
|
| 728 | - { |
|
| 729 | - if (function_exists('mb_strtoupper')) { |
|
| 729 | + public function strtoupper($str) |
|
| 730 | + {
|
|
| 731 | + if (function_exists('mb_strtoupper')) {
|
|
| 730 | 732 | return mb_strtoupper($str); |
| 731 | 733 | } |
| 732 | 734 | |
@@ -737,9 +739,9 @@ discard block |
||
| 737 | 739 | * @param $str |
| 738 | 740 | * @return string |
| 739 | 741 | */ |
| 740 | - public function ucfirst($str) |
|
| 741 | - { |
|
| 742 | - if (function_exists('mb_strtoupper') && function_exists('mb_substr') && function_exists('mb_strlen')) { |
|
| 742 | + public function ucfirst($str) |
|
| 743 | + {
|
|
| 744 | + if (function_exists('mb_strtoupper') && function_exists('mb_substr') && function_exists('mb_strlen')) {
|
|
| 743 | 745 | return mb_strtoupper(mb_substr($str, 0, 1)) . mb_substr($str, 1, mb_strlen($str)); |
| 744 | 746 | } |
| 745 | 747 | |
@@ -750,9 +752,9 @@ discard block |
||
| 750 | 752 | * @param $str |
| 751 | 753 | * @return string |
| 752 | 754 | */ |
| 753 | - public function lcfirst($str) |
|
| 754 | - { |
|
| 755 | - if (function_exists('mb_strtolower') && function_exists('mb_substr') && function_exists('mb_strlen')) { |
|
| 755 | + public function lcfirst($str) |
|
| 756 | + {
|
|
| 757 | + if (function_exists('mb_strtolower') && function_exists('mb_substr') && function_exists('mb_strlen')) {
|
|
| 756 | 758 | return mb_strtolower(mb_substr($str, 0, 1)) . mb_substr($str, 1, mb_strlen($str)); |
| 757 | 759 | } |
| 758 | 760 | |
@@ -763,9 +765,9 @@ discard block |
||
| 763 | 765 | * @param $str |
| 764 | 766 | * @return string |
| 765 | 767 | */ |
| 766 | - public function ucwords($str) |
|
| 767 | - { |
|
| 768 | - if (function_exists('mb_convert_case')) { |
|
| 768 | + public function ucwords($str) |
|
| 769 | + {
|
|
| 770 | + if (function_exists('mb_convert_case')) {
|
|
| 769 | 771 | return mb_convert_case($str, MB_CASE_TITLE); |
| 770 | 772 | } |
| 771 | 773 | |
@@ -776,8 +778,8 @@ discard block |
||
| 776 | 778 | * @param $str |
| 777 | 779 | * @return string |
| 778 | 780 | */ |
| 779 | - public function strrev($str) |
|
| 780 | - { |
|
| 781 | + public function strrev($str) |
|
| 782 | + {
|
|
| 781 | 783 | preg_match_all('/./us', $str, $ar); |
| 782 | 784 | |
| 783 | 785 | return implode(array_reverse($ar[0])); |
@@ -787,8 +789,8 @@ discard block |
||
| 787 | 789 | * @param $str |
| 788 | 790 | * @return string |
| 789 | 791 | */ |
| 790 | - public function str_shuffle($str) |
|
| 791 | - { |
|
| 792 | + public function str_shuffle($str) |
|
| 793 | + {
|
|
| 792 | 794 | preg_match_all('/./us', $str, $ar); |
| 793 | 795 | shuffle($ar[0]); |
| 794 | 796 | |
@@ -799,8 +801,8 @@ discard block |
||
| 799 | 801 | * @param $str |
| 800 | 802 | * @return int |
| 801 | 803 | */ |
| 802 | - public function str_word_count($str) |
|
| 803 | - { |
|
| 804 | + public function str_word_count($str) |
|
| 805 | + {
|
|
| 804 | 806 | return count(preg_split('~[^\p{L}\p{N}\']+~u', $str)); |
| 805 | 807 | } |
| 806 | 808 | } |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | default: |
| 201 | 201 | $this->Log("MODx / PHx placeholder variable: " . $input); |
| 202 | 202 | // Check if placeholder is set |
| 203 | - if (!array_key_exists($input, $this->placeholders) && !array_key_exists($input, |
|
| 203 | + if ( ! array_key_exists($input, $this->placeholders) && ! array_key_exists($input, |
|
| 204 | 204 | $modx->placeholders) |
| 205 | 205 | ) { |
| 206 | 206 | // not set so try again later. |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | case "show": |
| 310 | 310 | $conditional = implode(' ', $condition); |
| 311 | 311 | $isvalid = intval(eval("return (" . $conditional . ");")); |
| 312 | - if (!$isvalid) { |
|
| 312 | + if ( ! $isvalid) { |
|
| 313 | 313 | $output = null; |
| 314 | 314 | } |
| 315 | 315 | break; |
@@ -325,7 +325,7 @@ discard block |
||
| 325 | 325 | case "else": |
| 326 | 326 | $conditional = implode(' ', $condition); |
| 327 | 327 | $isvalid = intval(eval("return (" . $conditional . ");")); |
| 328 | - if (!$isvalid) { |
|
| 328 | + if ( ! $isvalid) { |
|
| 329 | 329 | $output = $modifier_value[$i]; |
| 330 | 330 | } |
| 331 | 331 | break; |
@@ -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) {return wordwrap($m[1],$wrapat,' ',1);},$output); |
|
| 394 | + $output = preg_replace_callback("@(\b\w+\b)@", function($m) use($wrapat) {return wordwrap($m[1], $wrapat, ' ', 1); },$output); |
|
| 395 | 395 | break; |
| 396 | 396 | case "limit": // default: 100 |
| 397 | 397 | $limit = intval($modifier_value[$i]) ? intval($modifier_value[$i]) : 100; |
@@ -414,7 +414,7 @@ discard block |
||
| 414 | 414 | $output = eval("return " . $filter . ";"); |
| 415 | 415 | break; |
| 416 | 416 | case "isnotempty": |
| 417 | - if (!empty($output)) { |
|
| 417 | + if ( ! empty($output)) { |
|
| 418 | 418 | $output = $modifier_value[$i]; |
| 419 | 419 | } |
| 420 | 420 | break; |
@@ -493,7 +493,7 @@ discard block |
||
| 493 | 493 | $cm = $snippet; |
| 494 | 494 | // end // |
| 495 | 495 | |
| 496 | - if (!empty($cm)) { |
|
| 496 | + if ( ! empty($cm)) { |
|
| 497 | 497 | ob_start(); |
| 498 | 498 | $options = $modifier_value[$i]; |
| 499 | 499 | $custom = eval($cm); |
@@ -521,7 +521,7 @@ discard block |
||
| 521 | 521 | */ |
| 522 | 522 | public function createEventLog() |
| 523 | 523 | { |
| 524 | - if (!empty($this->console)) { |
|
| 524 | + if ( ! empty($this->console)) { |
|
| 525 | 525 | $console = implode("\n", $this->console); |
| 526 | 526 | $this->console = array(); |
| 527 | 527 | |
@@ -594,7 +594,7 @@ discard block |
||
| 594 | 594 | public function ModUser($userid, $field) |
| 595 | 595 | { |
| 596 | 596 | global $modx; |
| 597 | - if (!array_key_exists($userid, $this->cache["ui"])) { |
|
| 597 | + if ( ! array_key_exists($userid, $this->cache["ui"])) { |
|
| 598 | 598 | if (intval($userid) < 0) { |
| 599 | 599 | $user = $modx->getWebUserInfo(-($userid)); |
| 600 | 600 | } else { |
@@ -619,7 +619,7 @@ discard block |
||
| 619 | 619 | global $modx; |
| 620 | 620 | |
| 621 | 621 | // if $groupNames is not an array return false |
| 622 | - if (!is_array($groupNames)) { |
|
| 622 | + if ( ! is_array($groupNames)) { |
|
| 623 | 623 | return false; |
| 624 | 624 | } |
| 625 | 625 | |
@@ -629,7 +629,7 @@ discard block |
||
| 629 | 629 | } |
| 630 | 630 | |
| 631 | 631 | // Creates an array with all webgroups the user id is in |
| 632 | - if (!array_key_exists($userid, $this->cache["mo"])) { |
|
| 632 | + if ( ! array_key_exists($userid, $this->cache["mo"])) { |
|
| 633 | 633 | $tbl = $modx->getFullTableName("webgroup_names"); |
| 634 | 634 | $tbl2 = $modx->getFullTableName("web_groups"); |
| 635 | 635 | $sql = "SELECT wgn.name FROM $tbl wgn INNER JOIN $tbl2 wg ON wg.webgroup=wgn.id AND wg.webuser='" . $userid . "'"; |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | // Parser: Preparation, cleaning and checkup |
| 76 | 76 | /** |
| 77 | 77 | * @param string $template |
| 78 | - * @return mixed|string |
|
| 78 | + * @return string |
|
| 79 | 79 | */ |
| 80 | 80 | public function Parse($template = '') |
| 81 | 81 | { |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | // Parser: modifier detection and eXtended processing if needed |
| 234 | 234 | /** |
| 235 | 235 | * @param $input |
| 236 | - * @param $modifiers |
|
| 236 | + * @param string $modifiers |
|
| 237 | 237 | * @return mixed|null|string |
| 238 | 238 | */ |
| 239 | 239 | public function Filter($input, $modifiers) |
@@ -588,8 +588,8 @@ discard block |
||
| 588 | 588 | // positive userid = manager, negative integer = webuser |
| 589 | 589 | /** |
| 590 | 590 | * @param $userid |
| 591 | - * @param $field |
|
| 592 | - * @return mixed |
|
| 591 | + * @param string $field |
|
| 592 | + * @return string |
|
| 593 | 593 | */ |
| 594 | 594 | public function ModUser($userid, $field) |
| 595 | 595 | { |
@@ -650,7 +650,7 @@ discard block |
||
| 650 | 650 | |
| 651 | 651 | // Returns the value of a PHx/MODx placeholder. |
| 652 | 652 | /** |
| 653 | - * @param $name |
|
| 653 | + * @param string $name |
|
| 654 | 654 | * @return mixed|string |
| 655 | 655 | */ |
| 656 | 656 | public function getPHxVariable($name) |
@@ -668,8 +668,8 @@ discard block |
||
| 668 | 668 | |
| 669 | 669 | // Sets a placeholder variable which can only be access by PHx |
| 670 | 670 | /** |
| 671 | - * @param $name |
|
| 672 | - * @param $value |
|
| 671 | + * @param string $name |
|
| 672 | + * @param string $value |
|
| 673 | 673 | */ |
| 674 | 674 | public function setPHxVariable($name, $value) |
| 675 | 675 | { |
@@ -680,9 +680,9 @@ discard block |
||
| 680 | 680 | |
| 681 | 681 | //mbstring |
| 682 | 682 | /** |
| 683 | - * @param $str |
|
| 684 | - * @param $s |
|
| 685 | - * @param null $l |
|
| 683 | + * @param string $str |
|
| 684 | + * @param integer $s |
|
| 685 | + * @param integer $l |
|
| 686 | 686 | * @return string |
| 687 | 687 | */ |
| 688 | 688 | public function substr($str, $s, $l = null) |
@@ -695,7 +695,7 @@ discard block |
||
| 695 | 695 | } |
| 696 | 696 | |
| 697 | 697 | /** |
| 698 | - * @param $str |
|
| 698 | + * @param string $str |
|
| 699 | 699 | * @return int |
| 700 | 700 | */ |
| 701 | 701 | public function strlen($str) |
@@ -708,7 +708,7 @@ discard block |
||
| 708 | 708 | } |
| 709 | 709 | |
| 710 | 710 | /** |
| 711 | - * @param $str |
|
| 711 | + * @param string $str |
|
| 712 | 712 | * @return string |
| 713 | 713 | */ |
| 714 | 714 | public function strtolower($str) |
@@ -721,7 +721,7 @@ discard block |
||
| 721 | 721 | } |
| 722 | 722 | |
| 723 | 723 | /** |
| 724 | - * @param $str |
|
| 724 | + * @param string $str |
|
| 725 | 725 | * @return string |
| 726 | 726 | */ |
| 727 | 727 | public function strtoupper($str) |
@@ -734,7 +734,7 @@ discard block |
||
| 734 | 734 | } |
| 735 | 735 | |
| 736 | 736 | /** |
| 737 | - * @param $str |
|
| 737 | + * @param string $str |
|
| 738 | 738 | * @return string |
| 739 | 739 | */ |
| 740 | 740 | public function ucfirst($str) |
@@ -747,7 +747,7 @@ discard block |
||
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | /** |
| 750 | - * @param $str |
|
| 750 | + * @param string $str |
|
| 751 | 751 | * @return string |
| 752 | 752 | */ |
| 753 | 753 | public function lcfirst($str) |
@@ -760,7 +760,7 @@ discard block |
||
| 760 | 760 | } |
| 761 | 761 | |
| 762 | 762 | /** |
| 763 | - * @param $str |
|
| 763 | + * @param string $str |
|
| 764 | 764 | * @return string |
| 765 | 765 | */ |
| 766 | 766 | public function ucwords($str) |
@@ -773,7 +773,7 @@ discard block |
||
| 773 | 773 | } |
| 774 | 774 | |
| 775 | 775 | /** |
| 776 | - * @param $str |
|
| 776 | + * @param string $str |
|
| 777 | 777 | * @return string |
| 778 | 778 | */ |
| 779 | 779 | public function strrev($str) |
@@ -784,7 +784,7 @@ discard block |
||
| 784 | 784 | } |
| 785 | 785 | |
| 786 | 786 | /** |
| 787 | - * @param $str |
|
| 787 | + * @param string $str |
|
| 788 | 788 | * @return string |
| 789 | 789 | */ |
| 790 | 790 | public function str_shuffle($str) |
@@ -796,7 +796,7 @@ discard block |
||
| 796 | 796 | } |
| 797 | 797 | |
| 798 | 798 | /** |
| 799 | - * @param $str |
|
| 799 | + * @param string $str |
|
| 800 | 800 | * @return int |
| 801 | 801 | */ |
| 802 | 802 | public function str_word_count($str) |