@@ -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)) |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | $this->_docs = ($type == 'parents') ? $this->getChildrenList() : $this->getDocList(); |
62 | 62 | if ($tvlist != '' && count($this->_docs) > 0) { |
63 | 63 | $tv = $this->extTV->getTVList(array_keys($this->_docs), $tvlist); |
64 | - if (!is_array($tv)) { |
|
64 | + if ( ! is_array($tv)) { |
|
65 | 65 | $tv = array(); |
66 | 66 | } |
67 | 67 | foreach ($tv as $docID => $TVitem) { |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | } |
139 | 139 | $date = $this->getCFGDef('dateSource', 'pub_date'); |
140 | 140 | if (isset($item[$date])) { |
141 | - if (!$item[$date] && $date == 'pub_date' && isset($item['createdon'])) { |
|
141 | + if ( ! $item[$date] && $date == 'pub_date' && isset($item['createdon'])) { |
|
142 | 142 | $date = 'createdon'; |
143 | 143 | } |
144 | 144 | $_date = is_numeric($item[$date]) && $item[$date] == (int)$item[$date] ? $item[$date] : strtotime($item[$date]); |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | |
224 | 224 | if (array('1') == $fields || in_array('date', $fields)) { |
225 | 225 | if (isset($row[$date])) { |
226 | - if (!$row[$date] && $date == 'pub_date' && isset($row['createdon'])) { |
|
226 | + if ( ! $row[$date] && $date == 'pub_date' && isset($row['createdon'])) { |
|
227 | 227 | $date = 'createdon'; |
228 | 228 | } |
229 | 229 | $_date = is_numeric($row[$date]) && $row[$date] == (int)$row[$date] ? $row[$date] : strtotime($row[$date]); |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | $row['title'] = empty($row['menutitle']) ? $row['pagetitle'] : $row['menutitle']; |
243 | 243 | } |
244 | 244 | } |
245 | - if ((bool)$this->getCFGDef('makeUrl', 1) && (array('1') == $fields || in_array('url',$fields)) |
|
245 | + if ((bool)$this->getCFGDef('makeUrl', 1) && (array('1') == $fields || in_array('url', $fields)) |
|
246 | 246 | ) { |
247 | 247 | if (isset($row['type']) && $row['type'] == 'reference' && isset($row['content'])) { |
248 | 248 | $row['url'] = is_numeric($row['content']) ? $this->modx->makeUrl($row['content'], '', '', |
@@ -289,10 +289,10 @@ discard block |
||
289 | 289 | |
290 | 290 | $where = "WHERE {$where}"; |
291 | 291 | $whereArr = array(); |
292 | - if (!$this->getCFGDef('showNoPublish', 0)) { |
|
292 | + if ( ! $this->getCFGDef('showNoPublish', 0)) { |
|
293 | 293 | $whereArr[] = "c.deleted=0 AND c.published=1"; |
294 | 294 | } |
295 | - else{ |
|
295 | + else { |
|
296 | 296 | $q_true = 1; |
297 | 297 | } |
298 | 298 | |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | $group = $this->getGroupSQL($this->getCFGDef('groupBy', 'c.id')); |
345 | 345 | |
346 | 346 | $q_true = $q_true ? $q_true : $group != ''; |
347 | - if ( $q_true ){ |
|
347 | + if ($q_true) { |
|
348 | 348 | $maxDocs = $this->getCFGDef('maxDocs', 0); |
349 | 349 | $limit = $maxDocs > 0 ? $this->LimitSQL($this->getCFGDef('maxDocs', 0)) : ''; |
350 | 350 | $rs = $this->dbQuery("SELECT count(*) FROM (SELECT count(*) FROM {$from} {$where} {$group} {$limit}) as `tmp`"); |
@@ -450,7 +450,7 @@ discard block |
||
450 | 450 | protected function injectSortByTV($table, $sort) |
451 | 451 | { |
452 | 452 | $out = $this->getExtender('tv', true, true)->injectSortByTV($table, $sort); |
453 | - if (!is_array($out) || empty($out)) { |
|
453 | + if ( ! is_array($out) || empty($out)) { |
|
454 | 454 | $out = array($table, $sort); |
455 | 455 | } |
456 | 456 | |
@@ -467,12 +467,12 @@ discard block |
||
467 | 467 | |
468 | 468 | $tmpWhere = $this->getCFGDef('addWhereList', ''); |
469 | 469 | $tmpWhere = sqlHelper::trimLogicalOp($tmpWhere); |
470 | - if (!empty($tmpWhere)) { |
|
470 | + if ( ! empty($tmpWhere)) { |
|
471 | 471 | $where[] = $tmpWhere; |
472 | 472 | } |
473 | 473 | |
474 | 474 | $tmpWhere = sqlHelper::trimLogicalOp($this->_filters['where']); |
475 | - if (!empty($tmpWhere)) { |
|
475 | + if ( ! empty($tmpWhere)) { |
|
476 | 476 | $where[] = $tmpWhere; |
477 | 477 | } |
478 | 478 | |
@@ -505,13 +505,13 @@ discard block |
||
505 | 505 | $tmpWhere = "((" . $tmpWhere . ") OR c.id IN({$addDocs}))"; |
506 | 506 | } |
507 | 507 | } |
508 | - if (!empty($tmpWhere)) { |
|
508 | + if ( ! empty($tmpWhere)) { |
|
509 | 509 | $where[] = $tmpWhere; |
510 | 510 | } |
511 | - if (!$this->getCFGDef('showNoPublish', 0)) { |
|
511 | + if ( ! $this->getCFGDef('showNoPublish', 0)) { |
|
512 | 512 | $where[] = "c.deleted=0 AND c.published=1"; |
513 | 513 | } |
514 | - if (!empty($where)) { |
|
514 | + if ( ! empty($where)) { |
|
515 | 515 | $where = "WHERE " . implode(" AND ", $where); |
516 | 516 | } else { |
517 | 517 | $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,29 +50,29 @@ 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 | 59 | } |
60 | 60 | $type = $this->getCFGDef('idType', 'parents'); |
61 | 61 | $this->_docs = ($type == 'parents') ? $this->getChildrenList() : $this->getDocList(); |
62 | - if ($tvlist != '' && count($this->_docs) > 0) { |
|
62 | + if ($tvlist != '' && count($this->_docs) > 0) { |
|
63 | 63 | $tv = $this->extTV->getTVList(array_keys($this->_docs), $tvlist); |
64 | - if (!is_array($tv)) { |
|
64 | + if (!is_array($tv)) { |
|
65 | 65 | $tv = array(); |
66 | 66 | } |
67 | - foreach ($tv as $docID => $TVitem) { |
|
68 | - if (isset($this->_docs[$docID]) && is_array($this->_docs[$docID])) { |
|
67 | + foreach ($tv as $docID => $TVitem) { |
|
68 | + if (isset($this->_docs[$docID]) && is_array($this->_docs[$docID])) { |
|
69 | 69 | $this->_docs[$docID] = array_merge($this->_docs[$docID], $TVitem); |
70 | - } else { |
|
70 | + } else { |
|
71 | 71 | unset($this->_docs[$docID]); |
72 | 72 | } |
73 | 73 | } |
74 | 74 | } |
75 | - if (1 == $this->getCFGDef('tree', '0')) { |
|
75 | + if (1 == $this->getCFGDef('tree', '0')) { |
|
76 | 76 | $this->treeBuild('id', 'parent'); |
77 | 77 | } |
78 | 78 | |
@@ -83,23 +83,23 @@ discard block |
||
83 | 83 | * @param string $tpl |
84 | 84 | * @return string |
85 | 85 | */ |
86 | - public function _render($tpl = '') |
|
87 | - { |
|
86 | + public function _render($tpl = '') |
|
87 | + { |
|
88 | 88 | $out = ''; |
89 | 89 | $separator = $this->getCFGDef('outputSeparator', ''); |
90 | - if ($tpl == '') { |
|
90 | + if ($tpl == '') { |
|
91 | 91 | $tpl = $this->getCFGDef('tpl', '@CODE:<a href="[+url+]">[+pagetitle+]</a><br />'); |
92 | 92 | } |
93 | - if ($tpl != '') { |
|
93 | + if ($tpl != '') { |
|
94 | 94 | $this->toPlaceholders(count($this->_docs), 1, "display"); // [+display+] - сколько показано на странице. |
95 | 95 | |
96 | 96 | $i = 1; |
97 | 97 | $sysPlh = $this->renameKeyArr($this->_plh, $this->getCFGDef("sysKey", "dl")); |
98 | - if (count($this->_docs) > 0) { |
|
98 | + if (count($this->_docs) > 0) { |
|
99 | 99 | /** |
100 | 100 | * @var $extUser user_DL_Extender |
101 | 101 | */ |
102 | - if ($extUser = $this->getExtender('user')) { |
|
102 | + if ($extUser = $this->getExtender('user')) { |
|
103 | 103 | $extUser->init($this, array('fields' => $this->getCFGDef("userFields", ""))); |
104 | 104 | } |
105 | 105 | |
@@ -114,9 +114,9 @@ discard block |
||
114 | 114 | $extPrepare = $this->getExtender('prepare'); |
115 | 115 | |
116 | 116 | $this->skippedDocs = 0; |
117 | - foreach ($this->_docs as $item) { |
|
117 | + foreach ($this->_docs as $item) { |
|
118 | 118 | $this->renderTPL = $tpl; |
119 | - if ($extUser) { |
|
119 | + if ($extUser) { |
|
120 | 120 | $item = $extUser->setUserData($item); //[+user.id.createdby+], [+user.fullname.publishedby+], [+dl.user.publishedby+].... |
121 | 121 | } |
122 | 122 | |
@@ -128,24 +128,24 @@ discard block |
||
128 | 128 | |
129 | 129 | $item['title'] = ($item['menutitle'] == '' ? $item['pagetitle'] : $item['menutitle']); |
130 | 130 | |
131 | - if ($this->getCFGDef('makeUrl', 1)) { |
|
132 | - if ($item['type'] == 'reference') { |
|
131 | + if ($this->getCFGDef('makeUrl', 1)) { |
|
132 | + if ($item['type'] == 'reference') { |
|
133 | 133 | $item['url'] = is_numeric($item['content']) ? $this->modx->makeUrl($item['content'], '', '', |
134 | 134 | $this->getCFGDef('urlScheme', '')) : $item['content']; |
135 | - } else { |
|
135 | + } else { |
|
136 | 136 | $item['url'] = $this->modx->makeUrl($item['id'], '', '', $this->getCFGDef('urlScheme', '')); |
137 | 137 | } |
138 | 138 | } |
139 | 139 | $date = $this->getCFGDef('dateSource', 'pub_date'); |
140 | - if (isset($item[$date])) { |
|
141 | - if (!$item[$date] && $date == 'pub_date' && isset($item['createdon'])) { |
|
140 | + if (isset($item[$date])) { |
|
141 | + if (!$item[$date] && $date == 'pub_date' && isset($item['createdon'])) { |
|
142 | 142 | $date = 'createdon'; |
143 | 143 | } |
144 | 144 | $_date = is_numeric($item[$date]) && $item[$date] == (int)$item[$date] ? $item[$date] : strtotime($item[$date]); |
145 | - if ($_date !== false) { |
|
145 | + if ($_date !== false) { |
|
146 | 146 | $_date = $_date + $this->modx->config['server_offset_time']; |
147 | 147 | $dateFormat = $this->getCFGDef('dateFormat', '%d.%b.%y %H:%M'); |
148 | - if ($dateFormat) { |
|
148 | + if ($dateFormat) { |
|
149 | 149 | $item['date'] = strftime($dateFormat, $_date); |
150 | 150 | } |
151 | 151 | } |
@@ -154,33 +154,33 @@ discard block |
||
154 | 154 | $findTpl = $this->renderTPL; |
155 | 155 | $tmp = $this->uniformPrepare($item, $i); |
156 | 156 | extract($tmp, EXTR_SKIP); |
157 | - if ($this->renderTPL == '') { |
|
157 | + if ($this->renderTPL == '') { |
|
158 | 158 | $this->renderTPL = $findTpl; |
159 | 159 | } |
160 | 160 | |
161 | - if ($extPrepare) { |
|
161 | + if ($extPrepare) { |
|
162 | 162 | $item = $extPrepare->init($this, array( |
163 | 163 | 'data' => $item, |
164 | 164 | 'nameParam' => 'prepare' |
165 | 165 | )); |
166 | - if (is_bool($item) && $item === false) { |
|
166 | + if (is_bool($item) && $item === false) { |
|
167 | 167 | $this->skippedDocs++; |
168 | 168 | continue; |
169 | 169 | } |
170 | 170 | } |
171 | 171 | $tmp = $this->parseChunk($this->renderTPL, $item); |
172 | 172 | |
173 | - if ($this->getCFGDef('contentPlaceholder', 0) !== 0) { |
|
173 | + if ($this->getCFGDef('contentPlaceholder', 0) !== 0) { |
|
174 | 174 | $this->toPlaceholders($tmp, 1, |
175 | 175 | "item[" . $i . "]"); // [+item[x]+] – individual placeholder for each iteration documents on this page |
176 | 176 | } |
177 | 177 | $out .= $tmp; |
178 | - if (next($this->_docs) !== false) { |
|
178 | + if (next($this->_docs) !== false) { |
|
179 | 179 | $out .= $separator; |
180 | 180 | } |
181 | 181 | $i++; |
182 | 182 | } |
183 | - } else { |
|
183 | + } else { |
|
184 | 184 | $noneTPL = $this->getCFGDef('noneTPL', ''); |
185 | 185 | $out = ($noneTPL != '') ? $this->parseChunk($noneTPL, $sysPlh) : ''; |
186 | 186 | } |
@@ -196,8 +196,8 @@ discard block |
||
196 | 196 | * @param array $array |
197 | 197 | * @return string |
198 | 198 | */ |
199 | - public function getJSON($data, $fields, $array = array()) |
|
200 | - { |
|
199 | + public function getJSON($data, $fields, $array = array()) |
|
200 | + { |
|
201 | 201 | $out = array(); |
202 | 202 | $fields = is_array($fields) ? $fields : explode(",", $fields); |
203 | 203 | $date = $this->getCFGDef('dateSource', 'pub_date'); |
@@ -216,50 +216,50 @@ discard block |
||
216 | 216 | */ |
217 | 217 | $extE = $this->getExtender('e', true, true); |
218 | 218 | |
219 | - foreach ($data as $num => $row) { |
|
220 | - if ((array('1') == $fields || in_array('summary', $fields)) && $extSummary) { |
|
219 | + foreach ($data as $num => $row) { |
|
220 | + if ((array('1') == $fields || in_array('summary', $fields)) && $extSummary) { |
|
221 | 221 | $row['summary'] = $this->getSummary($row, $extSummary, 'introtext', 'content'); |
222 | 222 | } |
223 | 223 | |
224 | - if (array('1') == $fields || in_array('date', $fields)) { |
|
225 | - if (isset($row[$date])) { |
|
226 | - if (!$row[$date] && $date == 'pub_date' && isset($row['createdon'])) { |
|
224 | + if (array('1') == $fields || in_array('date', $fields)) { |
|
225 | + if (isset($row[$date])) { |
|
226 | + if (!$row[$date] && $date == 'pub_date' && isset($row['createdon'])) { |
|
227 | 227 | $date = 'createdon'; |
228 | 228 | } |
229 | 229 | $_date = is_numeric($row[$date]) && $row[$date] == (int)$row[$date] ? $row[$date] : strtotime($row[$date]); |
230 | - if ($_date !== false) { |
|
230 | + if ($_date !== false) { |
|
231 | 231 | $_date = $_date + $this->modx->config['server_offset_time']; |
232 | 232 | $dateFormat = $this->getCFGDef('dateFormat', '%d.%b.%y %H:%M'); |
233 | - if ($dateFormat) { |
|
233 | + if ($dateFormat) { |
|
234 | 234 | $row['date'] = strftime($dateFormat, $_date); |
235 | 235 | } |
236 | 236 | } |
237 | 237 | } |
238 | 238 | } |
239 | 239 | |
240 | - if (array('1') == $fields || in_array('title', $fields)) { |
|
241 | - if (isset($row['pagetitle'])) { |
|
240 | + if (array('1') == $fields || in_array('title', $fields)) { |
|
241 | + if (isset($row['pagetitle'])) { |
|
242 | 242 | $row['title'] = empty($row['menutitle']) ? $row['pagetitle'] : $row['menutitle']; |
243 | 243 | } |
244 | 244 | } |
245 | 245 | if ((bool)$this->getCFGDef('makeUrl', 1) && (array('1') == $fields || in_array('url',$fields)) |
246 | - ) { |
|
247 | - if (isset($row['type']) && $row['type'] == 'reference' && isset($row['content'])) { |
|
246 | + ) { |
|
247 | + if (isset($row['type']) && $row['type'] == 'reference' && isset($row['content'])) { |
|
248 | 248 | $row['url'] = is_numeric($row['content']) ? $this->modx->makeUrl($row['content'], '', '', |
249 | 249 | $this->getCFGDef('urlScheme', '')) : $row['content']; |
250 | - } elseif (isset($row['id'])) { |
|
250 | + } elseif (isset($row['id'])) { |
|
251 | 251 | $row['url'] = $this->modx->makeUrl($row['id'], '', '', $this->getCFGDef('urlScheme', '')); |
252 | 252 | } |
253 | 253 | } |
254 | - if ($extE && $tmp = $extE->init($this, array('data' => $row))) { |
|
255 | - if (is_array($tmp)) { |
|
254 | + if ($extE && $tmp = $extE->init($this, array('data' => $row))) { |
|
255 | + if (is_array($tmp)) { |
|
256 | 256 | $row = $tmp; |
257 | 257 | } |
258 | 258 | } |
259 | 259 | |
260 | - if ($extPrepare) { |
|
260 | + if ($extPrepare) { |
|
261 | 261 | $row = $extPrepare->init($this, array('data' => $row)); |
262 | - if (is_bool($row) && $row === false) { |
|
262 | + if (is_bool($row) && $row === false) { |
|
263 | 263 | continue; |
264 | 264 | } |
265 | 265 | } |
@@ -272,36 +272,35 @@ discard block |
||
272 | 272 | /** |
273 | 273 | * @abstract |
274 | 274 | */ |
275 | - public function getChildrenCount() |
|
276 | - { |
|
275 | + public function getChildrenCount() |
|
276 | + { |
|
277 | 277 | $out = 0; |
278 | 278 | $sanitarInIDs = $this->sanitarIn($this->IDs); |
279 | - if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
|
279 | + if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
|
280 | 280 | $q_true = $this->getCFGDef('ignoreEmpty', '0'); |
281 | 281 | $q_true = $q_true ? $q_true : $this->getCFGDef('idType', 'parents') == 'parents'; |
282 | 282 | $where = $this->getCFGDef('addWhereList', ''); |
283 | 283 | $where = sqlHelper::trimLogicalOp($where); |
284 | 284 | $where = ($where ? $where . ' AND ' : '') . $this->_filters['where']; |
285 | - if ($where != '' && $this->_filters['where'] != '') { |
|
285 | + if ($where != '' && $this->_filters['where'] != '') { |
|
286 | 286 | $where .= " AND "; |
287 | 287 | } |
288 | 288 | $where = sqlHelper::trimLogicalOp($where); |
289 | 289 | |
290 | 290 | $where = "WHERE {$where}"; |
291 | 291 | $whereArr = array(); |
292 | - if (!$this->getCFGDef('showNoPublish', 0)) { |
|
292 | + if (!$this->getCFGDef('showNoPublish', 0)) { |
|
293 | 293 | $whereArr[] = "c.deleted=0 AND c.published=1"; |
294 | - } |
|
295 | - else{ |
|
294 | + } else { |
|
296 | 295 | $q_true = 1; |
297 | 296 | } |
298 | 297 | |
299 | 298 | $tbl_site_content = $this->getTable('site_content', 'c'); |
300 | 299 | |
301 | - if ($sanitarInIDs != "''") { |
|
302 | - switch ($this->getCFGDef('idType', 'parents')) { |
|
300 | + if ($sanitarInIDs != "''") { |
|
301 | + switch ($this->getCFGDef('idType', 'parents')) { |
|
303 | 302 | case 'parents': |
304 | - switch ($this->getCFGDef('showParent', '0')) { |
|
303 | + switch ($this->getCFGDef('showParent', '0')) { |
|
305 | 304 | case '-1': |
306 | 305 | $tmpWhere = "c.parent IN (" . $sanitarInIDs . ")"; |
307 | 306 | break; |
@@ -313,10 +312,10 @@ discard block |
||
313 | 312 | $tmpWhere = "(c.parent IN ({$sanitarInIDs}) OR c.id IN({$sanitarInIDs}))"; |
314 | 313 | break; |
315 | 314 | } |
316 | - if (($addDocs = $this->getCFGDef('documents', '')) != '') { |
|
315 | + if (($addDocs = $this->getCFGDef('documents', '')) != '') { |
|
317 | 316 | $addDocs = $this->sanitarIn($this->cleanIDs($addDocs)); |
318 | 317 | $whereArr[] = "((" . $tmpWhere . ") OR c.id IN({$addDocs}))"; |
319 | - } else { |
|
318 | + } else { |
|
320 | 319 | $whereArr[] = $tmpWhere; |
321 | 320 | } |
322 | 321 | |
@@ -331,26 +330,25 @@ discard block |
||
331 | 330 | |
332 | 331 | $q_true = $q_true ? $q_true : trim($where) != 'WHERE'; |
333 | 332 | |
334 | - if (trim($where) != 'WHERE') { |
|
333 | + if (trim($where) != 'WHERE') { |
|
335 | 334 | $where .= " AND "; |
336 | 335 | } |
337 | 336 | |
338 | 337 | $where .= implode(" AND ", $whereArr); |
339 | 338 | $where = sqlHelper::trimLogicalOp($where); |
340 | 339 | |
341 | - if (trim($where) == 'WHERE') { |
|
340 | + if (trim($where) == 'WHERE') { |
|
342 | 341 | $where = ''; |
343 | 342 | } |
344 | 343 | $group = $this->getGroupSQL($this->getCFGDef('groupBy', 'c.id')); |
345 | 344 | |
346 | 345 | $q_true = $q_true ? $q_true : $group != ''; |
347 | - if ( $q_true ){ |
|
346 | + if ( $q_true ) { |
|
348 | 347 | $maxDocs = $this->getCFGDef('maxDocs', 0); |
349 | 348 | $limit = $maxDocs > 0 ? $this->LimitSQL($this->getCFGDef('maxDocs', 0)) : ''; |
350 | 349 | $rs = $this->dbQuery("SELECT count(*) FROM (SELECT count(*) FROM {$from} {$where} {$group} {$limit}) as `tmp`"); |
351 | 350 | $out = $this->modx->db->getValue($rs); |
352 | - } |
|
353 | - else { |
|
351 | + } else { |
|
354 | 352 | $out = count($this->IDs); |
355 | 353 | } |
356 | 354 | } |
@@ -361,11 +359,11 @@ discard block |
||
361 | 359 | /** |
362 | 360 | * @return array |
363 | 361 | */ |
364 | - protected function getDocList() |
|
365 | - { |
|
362 | + protected function getDocList() |
|
363 | + { |
|
366 | 364 | $out = array(); |
367 | 365 | $sanitarInIDs = $this->sanitarIn($this->IDs); |
368 | - if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
|
366 | + if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
|
369 | 367 | $where = $this->getCFGDef('addWhereList', ''); |
370 | 368 | $where = sqlHelper::trimLogicalOp($where); |
371 | 369 | |
@@ -373,21 +371,21 @@ discard block |
||
373 | 371 | $where = sqlHelper::trimLogicalOp($where); |
374 | 372 | |
375 | 373 | $tbl_site_content = $this->getTable('site_content', 'c'); |
376 | - if ($sanitarInIDs != "''") { |
|
374 | + if ($sanitarInIDs != "''") { |
|
377 | 375 | $where .= ($where ? " AND " : "") . "c.id IN ({$sanitarInIDs}) AND"; |
378 | 376 | } |
379 | 377 | $where = sqlHelper::trimLogicalOp($where); |
380 | 378 | |
381 | - if ($this->getCFGDef('showNoPublish', 0)) { |
|
382 | - if ($where != '') { |
|
379 | + if ($this->getCFGDef('showNoPublish', 0)) { |
|
380 | + if ($where != '') { |
|
383 | 381 | $where = "WHERE {$where}"; |
384 | - } else { |
|
382 | + } else { |
|
385 | 383 | $where = ''; |
386 | 384 | } |
387 | - } else { |
|
388 | - if ($where != '') { |
|
385 | + } else { |
|
386 | + if ($where != '') { |
|
389 | 387 | $where = "WHERE {$where} AND "; |
390 | - } else { |
|
388 | + } else { |
|
391 | 389 | $where = "WHERE {$where} "; |
392 | 390 | } |
393 | 391 | $where .= "c.deleted=0 AND c.published=1"; |
@@ -404,7 +402,7 @@ discard block |
||
404 | 402 | |
405 | 403 | $rs = $this->dbQuery("SELECT {$fields} FROM {$tbl_site_content} {$where} {$group} {$sort} {$limit}"); |
406 | 404 | |
407 | - while ($item = $this->modx->db->getRow($rs)) { |
|
405 | + while ($item = $this->modx->db->getRow($rs)) { |
|
408 | 406 | $out[$item['id']] = $item; |
409 | 407 | }; |
410 | 408 | } |
@@ -416,26 +414,26 @@ discard block |
||
416 | 414 | * @param string|array $id |
417 | 415 | * @return array |
418 | 416 | */ |
419 | - public function getChildrenFolder($id) |
|
420 | - { |
|
417 | + public function getChildrenFolder($id) |
|
418 | + { |
|
421 | 419 | $out = array(); |
422 | 420 | $where = $this->getCFGDef('addWhereFolder', ''); |
423 | 421 | $where = sqlHelper::trimLogicalOp($where); |
424 | - if ($where != '') { |
|
422 | + if ($where != '') { |
|
425 | 423 | $where .= " AND "; |
426 | 424 | } |
427 | 425 | |
428 | 426 | $tbl_site_content = $this->getTable('site_content', 'c'); |
429 | 427 | $sanitarInIDs = $this->sanitarIn($id); |
430 | - if ($this->getCFGDef('showNoPublish', 0)) { |
|
428 | + if ($this->getCFGDef('showNoPublish', 0)) { |
|
431 | 429 | $where = "WHERE {$where} c.parent IN ({$sanitarInIDs}) AND c.isfolder=1"; |
432 | - } else { |
|
430 | + } else { |
|
433 | 431 | $where = "WHERE {$where} c.parent IN ({$sanitarInIDs}) AND c.deleted=0 AND c.published=1 AND c.isfolder=1"; |
434 | 432 | } |
435 | 433 | |
436 | 434 | $rs = $this->dbQuery("SELECT id FROM {$tbl_site_content} {$where}"); |
437 | 435 | |
438 | - while ($item = $this->modx->db->getRow($rs)) { |
|
436 | + while ($item = $this->modx->db->getRow($rs)) { |
|
439 | 437 | $out[] = $item['id']; |
440 | 438 | } |
441 | 439 | |
@@ -447,10 +445,10 @@ discard block |
||
447 | 445 | * @param $sort |
448 | 446 | * @return array |
449 | 447 | */ |
450 | - protected function injectSortByTV($table, $sort) |
|
451 | - { |
|
448 | + protected function injectSortByTV($table, $sort) |
|
449 | + { |
|
452 | 450 | $out = $this->getExtender('tv', true, true)->injectSortByTV($table, $sort); |
453 | - if (!is_array($out) || empty($out)) { |
|
451 | + if (!is_array($out) || empty($out)) { |
|
454 | 452 | $out = array($table, $sort); |
455 | 453 | } |
456 | 454 | |
@@ -460,19 +458,19 @@ discard block |
||
460 | 458 | /** |
461 | 459 | * @return array |
462 | 460 | */ |
463 | - protected function getChildrenList() |
|
464 | - { |
|
461 | + protected function getChildrenList() |
|
462 | + { |
|
465 | 463 | $where = array(); |
466 | 464 | $out = array(); |
467 | 465 | |
468 | 466 | $tmpWhere = $this->getCFGDef('addWhereList', ''); |
469 | 467 | $tmpWhere = sqlHelper::trimLogicalOp($tmpWhere); |
470 | - if (!empty($tmpWhere)) { |
|
468 | + if (!empty($tmpWhere)) { |
|
471 | 469 | $where[] = $tmpWhere; |
472 | 470 | } |
473 | 471 | |
474 | 472 | $tmpWhere = sqlHelper::trimLogicalOp($this->_filters['where']); |
475 | - if (!empty($tmpWhere)) { |
|
473 | + if (!empty($tmpWhere)) { |
|
476 | 474 | $where[] = $tmpWhere; |
477 | 475 | } |
478 | 476 | |
@@ -483,8 +481,8 @@ discard block |
||
483 | 481 | $sanitarInIDs = $this->sanitarIn($this->IDs); |
484 | 482 | |
485 | 483 | $tmpWhere = null; |
486 | - if ($sanitarInIDs != "''") { |
|
487 | - switch ($this->getCFGDef('showParent', '0')) { |
|
484 | + if ($sanitarInIDs != "''") { |
|
485 | + switch ($this->getCFGDef('showParent', '0')) { |
|
488 | 486 | case '-1': |
489 | 487 | $tmpWhere = "c.parent IN (" . $sanitarInIDs . ")"; |
490 | 488 | break; |
@@ -497,36 +495,36 @@ discard block |
||
497 | 495 | break; |
498 | 496 | } |
499 | 497 | } |
500 | - if (($addDocs = $this->getCFGDef('documents', '')) != '') { |
|
498 | + if (($addDocs = $this->getCFGDef('documents', '')) != '') { |
|
501 | 499 | $addDocs = $this->sanitarIn($this->cleanIDs($addDocs)); |
502 | - if (empty($tmpWhere)) { |
|
500 | + if (empty($tmpWhere)) { |
|
503 | 501 | $tmpWhere = "c.id IN({$addDocs})"; |
504 | - } else { |
|
502 | + } else { |
|
505 | 503 | $tmpWhere = "((" . $tmpWhere . ") OR c.id IN({$addDocs}))"; |
506 | 504 | } |
507 | 505 | } |
508 | - if (!empty($tmpWhere)) { |
|
506 | + if (!empty($tmpWhere)) { |
|
509 | 507 | $where[] = $tmpWhere; |
510 | 508 | } |
511 | - if (!$this->getCFGDef('showNoPublish', 0)) { |
|
509 | + if (!$this->getCFGDef('showNoPublish', 0)) { |
|
512 | 510 | $where[] = "c.deleted=0 AND c.published=1"; |
513 | 511 | } |
514 | - if (!empty($where)) { |
|
512 | + if (!empty($where)) { |
|
515 | 513 | $where = "WHERE " . implode(" AND ", $where); |
516 | - } else { |
|
514 | + } else { |
|
517 | 515 | $where = ''; |
518 | 516 | } |
519 | 517 | $fields = $this->getCFGDef('selectFields', 'c.*'); |
520 | 518 | $group = $this->getGroupSQL($this->getCFGDef('groupBy', '')); |
521 | 519 | |
522 | - if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
|
520 | + if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
|
523 | 521 | $rs = $this->dbQuery("SELECT {$fields} FROM " . $from . " " . $where . " " . |
524 | 522 | $group . " " . |
525 | 523 | $sort . " " . |
526 | 524 | $this->LimitSQL($this->getCFGDef('queryLimit', 0)) |
527 | 525 | ); |
528 | 526 | |
529 | - while ($item = $this->modx->db->getRow($rs)) { |
|
527 | + while ($item = $this->modx->db->getRow($rs)) { |
|
530 | 528 | $out[$item['id']] = $item; |
531 | 529 | } |
532 | 530 | } |
@@ -539,10 +537,10 @@ discard block |
||
539 | 537 | * @param string $type |
540 | 538 | * @return string |
541 | 539 | */ |
542 | - public function changeSortType($field, $type) |
|
543 | - { |
|
540 | + public function changeSortType($field, $type) |
|
541 | + { |
|
544 | 542 | $type = trim($type); |
545 | - switch (strtoupper($type)) { |
|
543 | + switch (strtoupper($type)) { |
|
546 | 544 | case 'TVDATETIME': |
547 | 545 | $field = "STR_TO_DATE(" . $field . ",'%d-%m-%Y %H:%i:%s')"; |
548 | 546 | 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)) { |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | $this->modx = $modx; |
203 | 203 | $this->setDebug(1); |
204 | 204 | |
205 | - if (!is_array($cfg) || empty($cfg)) { |
|
205 | + if ( ! is_array($cfg) || empty($cfg)) { |
|
206 | 206 | $cfg = $this->modx->Event->params; |
207 | 207 | } |
208 | 208 | } else { |
@@ -406,11 +406,11 @@ discard block |
||
406 | 406 | */ |
407 | 407 | public function getTable($name, $alias = '') |
408 | 408 | { |
409 | - if (!isset($this->_table[$name])) { |
|
409 | + if ( ! isset($this->_table[$name])) { |
|
410 | 410 | $this->_table[$name] = $this->modx->getFullTableName($name); |
411 | 411 | } |
412 | 412 | $table = $this->_table[$name]; |
413 | - if (!empty($alias) && is_scalar($alias)) { |
|
413 | + if ( ! empty($alias) && is_scalar($alias)) { |
|
414 | 414 | $table .= " as `" . $alias . "`"; |
415 | 415 | } |
416 | 416 | |
@@ -425,7 +425,7 @@ discard block |
||
425 | 425 | */ |
426 | 426 | public function TableAlias($name, $table, $alias) |
427 | 427 | { |
428 | - if (!$this->checkTableAlias($name, $table)) { |
|
428 | + if ( ! $this->checkTableAlias($name, $table)) { |
|
429 | 429 | $this->AddTable[$table][$name] = $alias; |
430 | 430 | } |
431 | 431 | |
@@ -470,7 +470,7 @@ discard block |
||
470 | 470 | public function isErrorJSON($json) |
471 | 471 | { |
472 | 472 | $error = jsonHelper::json_last_error_msg(); |
473 | - if (!in_array($error, array('error_none', 'other'))) { |
|
473 | + if ( ! in_array($error, array('error_none', 'other'))) { |
|
474 | 474 | $this->debug->error($this->getMsg('json.' . $error) . ": " . $this->debug->dumpData($json, 'code'), 'JSON'); |
475 | 475 | $error = true; |
476 | 476 | } |
@@ -489,13 +489,13 @@ discard block |
||
489 | 489 | $extenders = $this->getCFGDef('extender', ''); |
490 | 490 | $extenders = explode(",", $extenders); |
491 | 491 | $tmp = $this->getCFGDef('requestActive', '') != '' || in_array('request', $extenders); |
492 | - if ($tmp && !$this->_loadExtender('request')) { |
|
492 | + if ($tmp && ! $this->_loadExtender('request')) { |
|
493 | 493 | //OR request in extender's parameter |
494 | 494 | throw new Exception('Error load request extender'); |
495 | 495 | } |
496 | 496 | |
497 | 497 | $tmp = $this->getCFGDef('summary', '') != '' || in_array('summary', $extenders); |
498 | - if ($tmp && !$this->_loadExtender('summary')) { |
|
498 | + if ($tmp && ! $this->_loadExtender('summary')) { |
|
499 | 499 | //OR summary in extender's parameter |
500 | 500 | throw new Exception('Error load summary extender'); |
501 | 501 | } |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | $this->getCFGDef('TplCurrentPage', '') != '' || $this->getCFGDef('TplWrapPaginate', '') != '' || |
508 | 508 | $this->getCFGDef('pageLimit', '') != '' || $this->getCFGDef('pageAdjacents', '') != '' || |
509 | 509 | $this->getCFGDef('PaginateClass', '') != '' || $this->getCFGDef('TplNextP', '') != '' |
510 | - ) && !$this->_loadExtender('paginate') |
|
510 | + ) && ! $this->_loadExtender('paginate') |
|
511 | 511 | ) { |
512 | 512 | throw new Exception('Error load paginate extender'); |
513 | 513 | } else { |
@@ -674,7 +674,7 @@ discard block |
||
674 | 674 | if ($ext != '') { |
675 | 675 | $ext = explode(",", $ext); |
676 | 676 | foreach ($ext as $item) { |
677 | - if ($item != '' && !$this->_loadExtender($item)) { |
|
677 | + if ($item != '' && ! $this->_loadExtender($item)) { |
|
678 | 678 | throw new Exception('Error load ' . APIHelpers::e($item) . ' extender'); |
679 | 679 | } |
680 | 680 | } |
@@ -735,8 +735,8 @@ discard block |
||
735 | 735 | */ |
736 | 736 | public function sanitarIn($data, $sep = ',', $quote = true) |
737 | 737 | { |
738 | - if(is_scalar($data)) $data = explode($sep, $data); |
|
739 | - if(!is_array($data)) $data = array(); //@TODO: throw |
|
738 | + if (is_scalar($data)) $data = explode($sep, $data); |
|
739 | + if ( ! is_array($data)) $data = array(); //@TODO: throw |
|
740 | 740 | |
741 | 741 | $out = array(); |
742 | 742 | foreach ($data as $item) { |
@@ -872,7 +872,7 @@ discard block |
||
872 | 872 | protected function renderTree($data) |
873 | 873 | { |
874 | 874 | $out = ''; |
875 | - if (!empty($data['#childNodes'])) { |
|
875 | + if ( ! empty($data['#childNodes'])) { |
|
876 | 876 | foreach ($data['#childNodes'] as $item) { |
877 | 877 | $out .= $this->renderTree($item); |
878 | 878 | } |
@@ -911,7 +911,7 @@ discard block |
||
911 | 911 | public function parseLang($tpl) |
912 | 912 | { |
913 | 913 | $this->debug->debug(array("parseLang" => $tpl), "parseLang", 2, array('html')); |
914 | - if (is_scalar($tpl) && !empty($tpl)) { |
|
914 | + if (is_scalar($tpl) && ! empty($tpl)) { |
|
915 | 915 | if (preg_match_all("/\[\%([a-zA-Z0-9\.\_\-]+)\%\]/", $tpl, $match)) { |
916 | 916 | $langVal = array(); |
917 | 917 | foreach ($match[1] as $item) { |
@@ -979,7 +979,7 @@ discard block |
||
979 | 979 | { |
980 | 980 | $out = $data; |
981 | 981 | $docs = count($this->_docs) - $this->skippedDocs; |
982 | - if ((($this->getCFGDef("noneWrapOuter", "1") && $docs == 0) || $docs > 0) && !empty($this->ownerTPL)) { |
|
982 | + if ((($this->getCFGDef("noneWrapOuter", "1") && $docs == 0) || $docs > 0) && ! empty($this->ownerTPL)) { |
|
983 | 983 | $this->debug->debug("", "renderWrapTPL", 2); |
984 | 984 | $parse = true; |
985 | 985 | $plh = array($this->getCFGDef("sysKey", "dl") . ".wrap" => $data); |
@@ -1002,7 +1002,7 @@ discard block |
||
1002 | 1002 | } |
1003 | 1003 | $plh = $params; |
1004 | 1004 | } |
1005 | - if ($parse && !empty($this->ownerTPL)) { |
|
1005 | + if ($parse && ! empty($this->ownerTPL)) { |
|
1006 | 1006 | $this->debug->updateMessage( |
1007 | 1007 | array("render ownerTPL" => $this->ownerTPL, "With data" => print_r($plh, 1)), |
1008 | 1008 | "renderWrapTPL", |
@@ -1042,7 +1042,7 @@ discard block |
||
1042 | 1042 | $offset = $this->getCFGDef('reversePagination', |
1043 | 1043 | 0) && $this->extPaginate->currentPage() > 1 ? $this->extPaginate->totalPage() * $this->getCFGDef('display', |
1044 | 1044 | 0) - $this->extPaginate->totalDocs() : 0; |
1045 | - if ($this->getCFGDef('maxDocs', 0) && !$this->getCFGDef('reversePagination', |
|
1045 | + if ($this->getCFGDef('maxDocs', 0) && ! $this->getCFGDef('reversePagination', |
|
1046 | 1046 | 0) && $this->extPaginate->currentPage() == $this->extPaginate->totalPage() |
1047 | 1047 | ) { |
1048 | 1048 | $iteration += $this->getCFGDef('display', 0); |
@@ -1159,10 +1159,10 @@ discard block |
||
1159 | 1159 | $introField = $this->getCFGDef("introField", $introField); |
1160 | 1160 | $contentField = $this->getCFGDef("contentField", $contentField); |
1161 | 1161 | |
1162 | - if (!empty($introField) && !empty($item[$introField]) && mb_strlen($item[$introField], 'UTF-8') > 0) { |
|
1162 | + if ( ! empty($introField) && ! empty($item[$introField]) && mb_strlen($item[$introField], 'UTF-8') > 0) { |
|
1163 | 1163 | $out = $item[$introField]; |
1164 | 1164 | } else { |
1165 | - if (!empty($contentField) && !empty($item[$contentField]) && mb_strlen($item[$contentField], 'UTF-8') > 0) { |
|
1165 | + if ( ! empty($contentField) && ! empty($item[$contentField]) && mb_strlen($item[$contentField], 'UTF-8') > 0) { |
|
1166 | 1166 | $out = $extSummary->init($this, array( |
1167 | 1167 | "content" => $item[$contentField], |
1168 | 1168 | "action" => $this->getCFGDef("summary", ""), |
@@ -1231,7 +1231,7 @@ discard block |
||
1231 | 1231 | $flag = true; |
1232 | 1232 | |
1233 | 1233 | } else { |
1234 | - if (!class_exists($classname, false) && $classname != '') { |
|
1234 | + if ( ! class_exists($classname, false) && $classname != '') { |
|
1235 | 1235 | if (file_exists(dirname(__FILE__) . "/extender/" . $name . ".extender.inc")) { |
1236 | 1236 | include_once(dirname(__FILE__) . "/extender/" . $name . ".extender.inc"); |
1237 | 1237 | } |
@@ -1241,7 +1241,7 @@ discard block |
||
1241 | 1241 | $flag = true; |
1242 | 1242 | } |
1243 | 1243 | } |
1244 | - if (!$flag) { |
|
1244 | + if ( ! $flag) { |
|
1245 | 1245 | $this->debug->debug("Error load Extender " . $this->debug->dumpData($name)); |
1246 | 1246 | } |
1247 | 1247 | $this->debug->debugEnd('LoadExtender'); |
@@ -1299,7 +1299,7 @@ discard block |
||
1299 | 1299 | $this->debug->debug('clean IDs ' . $this->debug->dumpData($IDs) . ' with separator ' . $this->debug->dumpData($sep), |
1300 | 1300 | 'cleanIDs', 2); |
1301 | 1301 | $out = array(); |
1302 | - if (!is_array($IDs)) { |
|
1302 | + if ( ! is_array($IDs)) { |
|
1303 | 1303 | $IDs = explode($sep, $IDs); |
1304 | 1304 | } |
1305 | 1305 | foreach ($IDs as $item) { |
@@ -1335,7 +1335,7 @@ discard block |
||
1335 | 1335 | { |
1336 | 1336 | $out = array(); |
1337 | 1337 | foreach ($this->_docs as $doc => $val) { |
1338 | - if (isset($val[$userField]) && (($uniq && !in_array($val[$userField], $out)) || !$uniq)) { |
|
1338 | + if (isset($val[$userField]) && (($uniq && ! in_array($val[$userField], $out)) || ! $uniq)) { |
|
1339 | 1339 | $out[$doc] = $val[$userField]; |
1340 | 1340 | } |
1341 | 1341 | } |
@@ -1424,7 +1424,7 @@ discard block |
||
1424 | 1424 | $out['order'] = $tmp; |
1425 | 1425 | // no break |
1426 | 1426 | } |
1427 | - if ('' == $out['order'] || !in_array(strtoupper($out['order']), array('ASC', 'DESC'))) { |
|
1427 | + if ('' == $out['order'] || ! in_array(strtoupper($out['order']), array('ASC', 'DESC'))) { |
|
1428 | 1428 | $out['order'] = $orderDef; //Default |
1429 | 1429 | } |
1430 | 1430 | |
@@ -1519,21 +1519,21 @@ discard block |
||
1519 | 1519 | $children = array(); // children of each ID |
1520 | 1520 | $ids = array(); |
1521 | 1521 | foreach ($data as $i => $r) { |
1522 | - $row =& $data[$i]; |
|
1522 | + $row = & $data[$i]; |
|
1523 | 1523 | $id = $row[$idName]; |
1524 | 1524 | $pid = $row[$pidName]; |
1525 | - $children[$pid][$id] =& $row; |
|
1526 | - if (!isset($children[$id])) { |
|
1525 | + $children[$pid][$id] = & $row; |
|
1526 | + if ( ! isset($children[$id])) { |
|
1527 | 1527 | $children[$id] = array(); |
1528 | 1528 | } |
1529 | - $row['#childNodes'] =& $children[$id]; |
|
1529 | + $row['#childNodes'] = & $children[$id]; |
|
1530 | 1530 | $ids[$row[$idName]] = true; |
1531 | 1531 | } |
1532 | 1532 | // Root elements are elements with non-found PIDs. |
1533 | 1533 | $this->_tree = array(); |
1534 | 1534 | foreach ($data as $i => $r) { |
1535 | - $row =& $data[$i]; |
|
1536 | - if (!isset($ids[$row[$pidName]])) { |
|
1535 | + $row = & $data[$i]; |
|
1536 | + if ( ! isset($ids[$row[$pidName]])) { |
|
1537 | 1537 | $this->_tree[$row[$idName]] = $row; |
1538 | 1538 | } |
1539 | 1539 | } |
@@ -1549,10 +1549,10 @@ discard block |
||
1549 | 1549 | */ |
1550 | 1550 | public function getPK($full = true) |
1551 | 1551 | { |
1552 | - $idField = isset($this->idField) ? $this->idField: 'id'; |
|
1552 | + $idField = isset($this->idField) ? $this->idField : 'id'; |
|
1553 | 1553 | if ($full) { |
1554 | 1554 | $idField = '`' . $idField . '`'; |
1555 | - if (!empty($this->alias)) { |
|
1555 | + if ( ! empty($this->alias)) { |
|
1556 | 1556 | $idField = '`' . $this->alias . '`.' . $idField; |
1557 | 1557 | } |
1558 | 1558 | } |
@@ -1569,9 +1569,9 @@ discard block |
||
1569 | 1569 | public function getParentField($full = true) |
1570 | 1570 | { |
1571 | 1571 | $parentField = isset($this->parentField) ? $this->parentField : ''; |
1572 | - if ($full && !empty($parentField)) { |
|
1572 | + if ($full && ! empty($parentField)) { |
|
1573 | 1573 | $parentField = '`' . $parentField . '`'; |
1574 | - if (!empty($this->alias)) { |
|
1574 | + if ( ! empty($this->alias)) { |
|
1575 | 1575 | $parentField = '`' . $this->alias . '`.' . $parentField; |
1576 | 1576 | } |
1577 | 1577 | } |
@@ -1591,7 +1591,7 @@ discard block |
||
1591 | 1591 | $this->debug->debug("getFilters: " . $this->debug->dumpData($filter_string), 'getFilter', 1); |
1592 | 1592 | // the filter parameter tells us, which filters can be used in this query |
1593 | 1593 | $filter_string = trim($filter_string, ' ;'); |
1594 | - if (!$filter_string) { |
|
1594 | + if ( ! $filter_string) { |
|
1595 | 1595 | return; |
1596 | 1596 | } |
1597 | 1597 | $output = array('join' => '', 'where' => ''); |
@@ -1604,7 +1604,7 @@ discard block |
||
1604 | 1604 | $subfilters = $this->smartSplit($subfilters); |
1605 | 1605 | foreach ($subfilters as $subfilter) { |
1606 | 1606 | $subfilter = $this->getFilters(trim($subfilter)); |
1607 | - if (!$subfilter) { |
|
1607 | + if ( ! $subfilter) { |
|
1608 | 1608 | continue; |
1609 | 1609 | } |
1610 | 1610 | if ($subfilter['join']) { |
@@ -1614,14 +1614,14 @@ discard block |
||
1614 | 1614 | $wheres[] = $subfilter['where']; |
1615 | 1615 | } |
1616 | 1616 | } |
1617 | - $output['join'] = !empty($joins) ? implode(' ', $joins) : ''; |
|
1618 | - $output['where'] = !empty($wheres) ? '(' . implode($sql, $wheres) . ')' : ''; |
|
1617 | + $output['join'] = ! empty($joins) ? implode(' ', $joins) : ''; |
|
1618 | + $output['where'] = ! empty($wheres) ? '(' . implode($sql, $wheres) . ')' : ''; |
|
1619 | 1619 | } |
1620 | 1620 | } |
1621 | 1621 | |
1622 | - if (!$logic_op_found) { |
|
1622 | + if ( ! $logic_op_found) { |
|
1623 | 1623 | $filter = $this->loadFilter($filter_string); |
1624 | - if (!$filter) { |
|
1624 | + if ( ! $filter) { |
|
1625 | 1625 | $this->debug->warning('Error while loading DocLister filter "' . $this->debug->dumpData($filter_string) . '": check syntax!'); |
1626 | 1626 | $output = false; |
1627 | 1627 | } else { |
@@ -1655,8 +1655,8 @@ discard block |
||
1655 | 1655 | * @return $this |
1656 | 1656 | */ |
1657 | 1657 | public function setFiltersJoin($join = '') { |
1658 | - if (!empty($join)) { |
|
1659 | - if (!empty($this->_filters['join'])) { |
|
1658 | + if ( ! empty($join)) { |
|
1659 | + if ( ! empty($this->_filters['join'])) { |
|
1660 | 1660 | $this->_filters['join'] .= ' ' . $join; |
1661 | 1661 | } else { |
1662 | 1662 | $this->_filters['join'] = $join; |
@@ -1713,8 +1713,8 @@ discard block |
||
1713 | 1713 | */ |
1714 | 1714 | $fltr_class = $fltr . '_DL_filter'; |
1715 | 1715 | // check if the filter is implemented |
1716 | - if (!is_null($fltr)) { |
|
1717 | - if (!class_exists($fltr_class) && file_exists(__DIR__ . '/filter/' . $fltr . '.filter.php')) { |
|
1716 | + if ( ! is_null($fltr)) { |
|
1717 | + if ( ! class_exists($fltr_class) && file_exists(__DIR__ . '/filter/' . $fltr . '.filter.php')) { |
|
1718 | 1718 | require_once dirname(__FILE__) . '/filter/' . $fltr . '.filter.php'; |
1719 | 1719 | } |
1720 | 1720 | if (class_exists($fltr_class)) { |
@@ -1727,7 +1727,7 @@ discard block |
||
1727 | 1727 | } |
1728 | 1728 | } |
1729 | 1729 | } |
1730 | - if (!$out) { |
|
1730 | + if ( ! $out) { |
|
1731 | 1731 | $this->debug->error("Error load Filter: '{$this->debug->dumpData($filter)}'", 'Filter'); |
1732 | 1732 | } |
1733 | 1733 |
@@ -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 | */ |
@@ -188,48 +188,48 @@ discard block |
||
188 | 188 | * @param int $startTime время запуска сниппета |
189 | 189 | * @throws Exception |
190 | 190 | */ |
191 | - public function __construct($modx, $cfg = array(), $startTime = null) |
|
192 | - { |
|
191 | + public function __construct($modx, $cfg = array(), $startTime = null) |
|
192 | + { |
|
193 | 193 | $this->setTimeStart($startTime); |
194 | 194 | |
195 | - if (extension_loaded('mbstring')) { |
|
195 | + if (extension_loaded('mbstring')) { |
|
196 | 196 | mb_internal_encoding("UTF-8"); |
197 | - } else { |
|
197 | + } else { |
|
198 | 198 | throw new Exception('Not found php extension mbstring'); |
199 | 199 | } |
200 | 200 | |
201 | - if ($modx instanceof DocumentParser) { |
|
201 | + if ($modx instanceof DocumentParser) { |
|
202 | 202 | $this->modx = $modx; |
203 | 203 | $this->setDebug(1); |
204 | 204 | |
205 | - if (!is_array($cfg) || empty($cfg)) { |
|
205 | + if (!is_array($cfg) || empty($cfg)) { |
|
206 | 206 | $cfg = $this->modx->Event->params; |
207 | 207 | } |
208 | - } else { |
|
208 | + } else { |
|
209 | 209 | throw new Exception('MODX var is not instaceof DocumentParser'); |
210 | 210 | } |
211 | 211 | |
212 | 212 | $this->FS = \Helpers\FS::getInstance(); |
213 | 213 | $this->config = new \Helpers\Config($cfg); |
214 | 214 | |
215 | - if (isset($cfg['config'])) { |
|
215 | + if (isset($cfg['config'])) { |
|
216 | 216 | $this->config->setPath(dirname(__DIR__))->loadConfig($cfg['config']); |
217 | 217 | } |
218 | 218 | |
219 | - if ($this->config->setConfig($cfg) === false) { |
|
219 | + if ($this->config->setConfig($cfg) === false) { |
|
220 | 220 | throw new Exception('no parameters to run DocLister'); |
221 | 221 | } |
222 | 222 | |
223 | 223 | $this->loadLang(array('core', 'json')); |
224 | 224 | $this->setDebug($this->getCFGDef('debug', 0)); |
225 | 225 | |
226 | - if ($this->checkDL()) { |
|
226 | + if ($this->checkDL()) { |
|
227 | 227 | $cfg = array(); |
228 | 228 | $idType = $this->getCFGDef('idType', ''); |
229 | - if (empty($idType) && $this->getCFGDef('documents', '') != '') { |
|
229 | + if (empty($idType) && $this->getCFGDef('documents', '') != '') { |
|
230 | 230 | $idType = 'documents'; |
231 | 231 | } |
232 | - switch ($idType) { |
|
232 | + switch ($idType) { |
|
233 | 233 | case 'documents': |
234 | 234 | $IDs = $this->getCFGDef('documents'); |
235 | 235 | $cfg['idType'] = "documents"; |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | case 'parents': |
238 | 238 | default: |
239 | 239 | $cfg['idType'] = "parents"; |
240 | - if (($IDs = $this->getCFGDef('parents', '')) === '') { |
|
240 | + if (($IDs = $this->getCFGDef('parents', '')) === '') { |
|
241 | 241 | $IDs = $this->getCurrentMODXPageID(); |
242 | 242 | } |
243 | 243 | break; |
@@ -256,21 +256,21 @@ discard block |
||
256 | 256 | |
257 | 257 | $this->setLocate(); |
258 | 258 | |
259 | - if ($this->getCFGDef("customLang")) { |
|
259 | + if ($this->getCFGDef("customLang")) { |
|
260 | 260 | $this->getCustomLang(); |
261 | 261 | } |
262 | 262 | $this->loadExtender($this->getCFGDef("extender", "")); |
263 | 263 | |
264 | - if ($this->checkExtender('request')) { |
|
264 | + if ($this->checkExtender('request')) { |
|
265 | 265 | $this->extender['request']->init($this, $this->getCFGDef("requestActive", "")); |
266 | 266 | } |
267 | 267 | $this->_filters = $this->getFilters($this->getCFGDef('filters', '')); |
268 | 268 | $this->ownerTPL = $this->getCFGDef("ownerTPL", ""); |
269 | 269 | $DLTemplate = DLTemplate::getInstance($modx); |
270 | - if ($path = $this->getCFGDef('templatePath')) { |
|
270 | + if ($path = $this->getCFGDef('templatePath')) { |
|
271 | 271 | $DLTemplate->setTemplatePath($path); |
272 | 272 | } |
273 | - if ($ext = $this->getCFGDef('templateExtension')) { |
|
273 | + if ($ext = $this->getCFGDef('templateExtension')) { |
|
274 | 274 | $DLTemplate->setTemplateExtension($ext); |
275 | 275 | } |
276 | 276 | $DLTemplate->setTwigTemplateVars(array('DocLister' => $this)); |
@@ -282,25 +282,25 @@ discard block |
||
282 | 282 | * @param string $str строка с фильтром |
283 | 283 | * @return array массив субфильтров |
284 | 284 | */ |
285 | - public function smartSplit($str) |
|
286 | - { |
|
285 | + public function smartSplit($str) |
|
286 | + { |
|
287 | 287 | $res = array(); |
288 | 288 | $cur = ''; |
289 | 289 | $open = 0; |
290 | 290 | $strlen = mb_strlen($str, 'UTF-8'); |
291 | - for ($i = 0; $i <= $strlen; $i++) { |
|
291 | + for ($i = 0; $i <= $strlen; $i++) { |
|
292 | 292 | $e = mb_substr($str, $i, 1, 'UTF-8'); |
293 | - switch ($e) { |
|
293 | + switch ($e) { |
|
294 | 294 | case '\\': |
295 | 295 | $cur .= $e; |
296 | 296 | $cur .= mb_substr($str, ++$i, 1, 'UTF-8'); |
297 | 297 | break; |
298 | 298 | case ')': |
299 | 299 | $open--; |
300 | - if ($open == 0) { |
|
300 | + if ($open == 0) { |
|
301 | 301 | $res[] = $cur . ')'; |
302 | 302 | $cur = ''; |
303 | - } else { |
|
303 | + } else { |
|
304 | 304 | $cur .= $e; |
305 | 305 | } |
306 | 306 | break; |
@@ -309,10 +309,10 @@ discard block |
||
309 | 309 | $cur .= $e; |
310 | 310 | break; |
311 | 311 | case ';': |
312 | - if ($open == 0) { |
|
312 | + if ($open == 0) { |
|
313 | 313 | $res[] = $cur; |
314 | 314 | $cur = ''; |
315 | - } else { |
|
315 | + } else { |
|
316 | 316 | $cur .= $e; |
317 | 317 | } |
318 | 318 | break; |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | } |
322 | 322 | } |
323 | 323 | $cur = preg_replace("/(\))$/u", '', $cur); |
324 | - if ($cur != '') { |
|
324 | + if ($cur != '') { |
|
325 | 325 | $res[] = $cur; |
326 | 326 | } |
327 | 327 | |
@@ -332,8 +332,8 @@ discard block |
||
332 | 332 | * Трансформация объекта в строку |
333 | 333 | * @return string последний ответ от DocLister'а |
334 | 334 | */ |
335 | - public function __toString() |
|
336 | - { |
|
335 | + public function __toString() |
|
336 | + { |
|
337 | 337 | return $this->outData; |
338 | 338 | } |
339 | 339 | |
@@ -341,8 +341,8 @@ discard block |
||
341 | 341 | * Установить время запуска сниппета |
342 | 342 | * @param float|null $time |
343 | 343 | */ |
344 | - public function setTimeStart($time = null) |
|
345 | - { |
|
344 | + public function setTimeStart($time = null) |
|
345 | + { |
|
346 | 346 | $this->_timeStart = is_null($time) ? microtime(true) : $time; |
347 | 347 | } |
348 | 348 | |
@@ -351,8 +351,8 @@ discard block |
||
351 | 351 | * |
352 | 352 | * @return int |
353 | 353 | */ |
354 | - public function getTimeStart() |
|
355 | - { |
|
354 | + public function getTimeStart() |
|
355 | + { |
|
356 | 356 | return $this->_timeStart; |
357 | 357 | } |
358 | 358 | |
@@ -360,27 +360,27 @@ discard block |
||
360 | 360 | * Установка режима отладки |
361 | 361 | * @param int $flag режим отладки |
362 | 362 | */ |
363 | - public function setDebug($flag = 0) |
|
364 | - { |
|
363 | + public function setDebug($flag = 0) |
|
364 | + { |
|
365 | 365 | $flag = abs((int)$flag); |
366 | - if ($this->_debugMode != $flag) { |
|
366 | + if ($this->_debugMode != $flag) { |
|
367 | 367 | $this->_debugMode = $flag; |
368 | 368 | $this->debug = null; |
369 | - if ($this->_debugMode > 0) { |
|
370 | - if (isset($_SESSION['usertype']) && $_SESSION['usertype'] == 'manager') { |
|
369 | + if ($this->_debugMode > 0) { |
|
370 | + if (isset($_SESSION['usertype']) && $_SESSION['usertype'] == 'manager') { |
|
371 | 371 | error_reporting(E_ALL ^ E_NOTICE); |
372 | 372 | ini_set('display_errors', 1); |
373 | 373 | } |
374 | 374 | $dir = dirname(dirname(__FILE__)); |
375 | - if (file_exists($dir . "/lib/DLdebug.class.php")) { |
|
375 | + if (file_exists($dir . "/lib/DLdebug.class.php")) { |
|
376 | 376 | include_once($dir . "/lib/DLdebug.class.php"); |
377 | - if (class_exists("DLdebug", false)) { |
|
377 | + if (class_exists("DLdebug", false)) { |
|
378 | 378 | $this->debug = new DLdebug($this); |
379 | 379 | } |
380 | 380 | } |
381 | 381 | } |
382 | 382 | |
383 | - if (is_null($this->debug)) { |
|
383 | + if (is_null($this->debug)) { |
|
384 | 384 | $this->debug = new xNop(); |
385 | 385 | $this->_debugMode = 0; |
386 | 386 | error_reporting(0); |
@@ -392,8 +392,8 @@ discard block |
||
392 | 392 | /** |
393 | 393 | * Информация о режиме отладки |
394 | 394 | */ |
395 | - public function getDebug() |
|
396 | - { |
|
395 | + public function getDebug() |
|
396 | + { |
|
397 | 397 | return $this->_debugMode; |
398 | 398 | } |
399 | 399 | |
@@ -404,13 +404,13 @@ discard block |
||
404 | 404 | * @param string $alias желаемый алиас таблицы |
405 | 405 | * @return string имя таблицы с префиксом и алиасом |
406 | 406 | */ |
407 | - public function getTable($name, $alias = '') |
|
408 | - { |
|
409 | - if (!isset($this->_table[$name])) { |
|
407 | + public function getTable($name, $alias = '') |
|
408 | + { |
|
409 | + if (!isset($this->_table[$name])) { |
|
410 | 410 | $this->_table[$name] = $this->modx->getFullTableName($name); |
411 | 411 | } |
412 | 412 | $table = $this->_table[$name]; |
413 | - if (!empty($alias) && is_scalar($alias)) { |
|
413 | + if (!empty($alias) && is_scalar($alias)) { |
|
414 | 414 | $table .= " as `" . $alias . "`"; |
415 | 415 | } |
416 | 416 | |
@@ -423,9 +423,9 @@ discard block |
||
423 | 423 | * @param $alias |
424 | 424 | * @return mixed |
425 | 425 | */ |
426 | - public function TableAlias($name, $table, $alias) |
|
427 | - { |
|
428 | - if (!$this->checkTableAlias($name, $table)) { |
|
426 | + public function TableAlias($name, $table, $alias) |
|
427 | + { |
|
428 | + if (!$this->checkTableAlias($name, $table)) { |
|
429 | 429 | $this->AddTable[$table][$name] = $alias; |
430 | 430 | } |
431 | 431 | |
@@ -437,8 +437,8 @@ discard block |
||
437 | 437 | * @param $table |
438 | 438 | * @return bool |
439 | 439 | */ |
440 | - public function checkTableAlias($name, $table) |
|
441 | - { |
|
440 | + public function checkTableAlias($name, $table) |
|
441 | + { |
|
442 | 442 | return isset($this->AddTable[$table][$name]); |
443 | 443 | } |
444 | 444 | |
@@ -450,8 +450,8 @@ discard block |
||
450 | 450 | * @param bool $nop создавать ли пустой объект запрашиваемого типа |
451 | 451 | * @return array|mixed|xNop |
452 | 452 | */ |
453 | - public function jsonDecode($json, $config = array(), $nop = false) |
|
454 | - { |
|
453 | + public function jsonDecode($json, $config = array(), $nop = false) |
|
454 | + { |
|
455 | 455 | $this->debug->debug('Decode JSON: ' . $this->debug->dumpData($json) . "\r\nwith config: " . $this->debug->dumpData($config), |
456 | 456 | 'jsonDecode', 2); |
457 | 457 | $config = jsonHelper::jsonDecode($json, $config, $nop); |
@@ -467,10 +467,10 @@ discard block |
||
467 | 467 | * @param $json string строка с JSON для записи в лог при отладке |
468 | 468 | * @return bool|string |
469 | 469 | */ |
470 | - public function isErrorJSON($json) |
|
471 | - { |
|
470 | + public function isErrorJSON($json) |
|
471 | + { |
|
472 | 472 | $error = jsonHelper::json_last_error_msg(); |
473 | - if (!in_array($error, array('error_none', 'other'))) { |
|
473 | + if (!in_array($error, array('error_none', 'other'))) { |
|
474 | 474 | $this->debug->error($this->getMsg('json.' . $error) . ": " . $this->debug->dumpData($json, 'code'), 'JSON'); |
475 | 475 | $error = true; |
476 | 476 | } |
@@ -482,20 +482,20 @@ discard block |
||
482 | 482 | * Проверка параметров и загрузка необходимых экстендеров |
483 | 483 | * return boolean статус загрузки |
484 | 484 | */ |
485 | - public function checkDL() |
|
486 | - { |
|
485 | + public function checkDL() |
|
486 | + { |
|
487 | 487 | $this->debug->debug('Check DocLister parameters', 'checkDL', 2); |
488 | 488 | $flag = true; |
489 | 489 | $extenders = $this->getCFGDef('extender', ''); |
490 | 490 | $extenders = explode(",", $extenders); |
491 | 491 | $tmp = $this->getCFGDef('requestActive', '') != '' || in_array('request', $extenders); |
492 | - if ($tmp && !$this->_loadExtender('request')) { |
|
492 | + if ($tmp && !$this->_loadExtender('request')) { |
|
493 | 493 | //OR request in extender's parameter |
494 | 494 | throw new Exception('Error load request extender'); |
495 | 495 | } |
496 | 496 | |
497 | 497 | $tmp = $this->getCFGDef('summary', '') != '' || in_array('summary', $extenders); |
498 | - if ($tmp && !$this->_loadExtender('summary')) { |
|
498 | + if ($tmp && !$this->_loadExtender('summary')) { |
|
499 | 499 | //OR summary in extender's parameter |
500 | 500 | throw new Exception('Error load summary extender'); |
501 | 501 | } |
@@ -508,15 +508,15 @@ discard block |
||
508 | 508 | $this->getCFGDef('pageLimit', '') != '' || $this->getCFGDef('pageAdjacents', '') != '' || |
509 | 509 | $this->getCFGDef('PaginateClass', '') != '' || $this->getCFGDef('TplNextP', '') != '' |
510 | 510 | ) && !$this->_loadExtender('paginate') |
511 | - ) { |
|
511 | + ) { |
|
512 | 512 | throw new Exception('Error load paginate extender'); |
513 | - } else { |
|
514 | - if ((int)$this->getCFGDef('display', 0) == 0) { |
|
513 | + } else { |
|
514 | + if ((int)$this->getCFGDef('display', 0) == 0) { |
|
515 | 515 | $extenders = $this->unsetArrayVal($extenders, 'paginate'); |
516 | 516 | } |
517 | 517 | } |
518 | 518 | |
519 | - if ($this->getCFGDef('prepare', '') != '' || $this->getCFGDef('prepareWrap') != '') { |
|
519 | + if ($this->getCFGDef('prepare', '') != '' || $this->getCFGDef('prepareWrap') != '') { |
|
520 | 520 | $this->_loadExtender('prepare'); |
521 | 521 | } |
522 | 522 | |
@@ -533,14 +533,14 @@ discard block |
||
533 | 533 | * @param mixed $val значение которые необходимо удалить из массива |
534 | 534 | * @return array отчищеный массив с данными |
535 | 535 | */ |
536 | - private function unsetArrayVal($data, $val) |
|
537 | - { |
|
536 | + private function unsetArrayVal($data, $val) |
|
537 | + { |
|
538 | 538 | $out = array(); |
539 | - if (is_array($data)) { |
|
540 | - foreach ($data as $item) { |
|
541 | - if ($item != $val) { |
|
539 | + if (is_array($data)) { |
|
540 | + foreach ($data as $item) { |
|
541 | + if ($item != $val) { |
|
542 | 542 | $out[] = $item; |
543 | - } else { |
|
543 | + } else { |
|
544 | 544 | continue; |
545 | 545 | } |
546 | 546 | } |
@@ -555,14 +555,14 @@ discard block |
||
555 | 555 | * @param int $id уникальный идентификатор страницы |
556 | 556 | * @return string URL страницы |
557 | 557 | */ |
558 | - public function getUrl($id = 0) |
|
559 | - { |
|
558 | + public function getUrl($id = 0) |
|
559 | + { |
|
560 | 560 | $id = ((int)$id > 0) ? (int)$id : $this->getCurrentMODXPageID(); |
561 | 561 | |
562 | 562 | $link = $this->checkExtender('request') ? $this->extender['request']->getLink() : $this->getRequest(); |
563 | - if ($id == $this->modx->config['site_start']) { |
|
563 | + if ($id == $this->modx->config['site_start']) { |
|
564 | 564 | $url = $this->modx->config['site_url'] . ($link != '' ? "?{$link}" : ""); |
565 | - } else { |
|
565 | + } else { |
|
566 | 566 | $url = $this->modx->makeUrl($id, '', $link, $this->getCFGDef('urlScheme', '')); |
567 | 567 | } |
568 | 568 | |
@@ -590,20 +590,20 @@ discard block |
||
590 | 590 | * @param string $tpl шаблон |
591 | 591 | * @return string |
592 | 592 | */ |
593 | - public function render($tpl = '') |
|
594 | - { |
|
593 | + public function render($tpl = '') |
|
594 | + { |
|
595 | 595 | $this->debug->debug(array('Render data with template ' => $tpl), 'render', 2, array('html')); |
596 | 596 | $out = ''; |
597 | - if (1 == $this->getCFGDef('tree', '0')) { |
|
598 | - foreach ($this->_tree as $item) { |
|
597 | + if (1 == $this->getCFGDef('tree', '0')) { |
|
598 | + foreach ($this->_tree as $item) { |
|
599 | 599 | $out .= $this->renderTree($item); |
600 | 600 | } |
601 | 601 | $out = $this->renderWrap($out); |
602 | - } else { |
|
602 | + } else { |
|
603 | 603 | $out = $this->_render($tpl); |
604 | 604 | } |
605 | 605 | |
606 | - if ($out) { |
|
606 | + if ($out) { |
|
607 | 607 | $this->outData = DLTemplate::getInstance($this->modx)->parseDocumentSource($out); |
608 | 608 | } |
609 | 609 | $this->debug->debugEnd('render'); |
@@ -620,8 +620,8 @@ discard block |
||
620 | 620 | * |
621 | 621 | * @return int |
622 | 622 | */ |
623 | - public function getCurrentMODXPageID() |
|
624 | - { |
|
623 | + public function getCurrentMODXPageID() |
|
624 | + { |
|
625 | 625 | $id = isset($this->modx->documentIdentifier) ? (int)$this->modx->documentIdentifier : 0; |
626 | 626 | $docData = isset($this->modx->documentObject) ? $this->modx->documentObject : array(); |
627 | 627 | |
@@ -637,9 +637,9 @@ discard block |
||
637 | 637 | * @param integer $line error on line |
638 | 638 | * @param array $trace stack trace |
639 | 639 | */ |
640 | - public function ErrorLogger($message, $code, $file, $line, $trace) |
|
641 | - { |
|
642 | - if (abs($this->getCFGDef('debug', '0')) == '1') { |
|
640 | + public function ErrorLogger($message, $code, $file, $line, $trace) |
|
641 | + { |
|
642 | + if (abs($this->getCFGDef('debug', '0')) == '1') { |
|
643 | 643 | $out = "CODE #" . $code . "<br />"; |
644 | 644 | $out .= "on file: " . $file . ":" . $line . "<br />"; |
645 | 645 | $out .= "<pre>"; |
@@ -656,8 +656,8 @@ discard block |
||
656 | 656 | * |
657 | 657 | * @return DocumentParser |
658 | 658 | */ |
659 | - public function getMODX() |
|
660 | - { |
|
659 | + public function getMODX() |
|
660 | + { |
|
661 | 661 | return $this->modx; |
662 | 662 | } |
663 | 663 | |
@@ -668,13 +668,13 @@ discard block |
||
668 | 668 | * @return boolean status load extenders |
669 | 669 | * @throws Exception |
670 | 670 | */ |
671 | - public function loadExtender($ext = '') |
|
672 | - { |
|
671 | + public function loadExtender($ext = '') |
|
672 | + { |
|
673 | 673 | $out = true; |
674 | - if ($ext != '') { |
|
674 | + if ($ext != '') { |
|
675 | 675 | $ext = explode(",", $ext); |
676 | - foreach ($ext as $item) { |
|
677 | - if ($item != '' && !$this->_loadExtender($item)) { |
|
676 | + foreach ($ext as $item) { |
|
677 | + if ($item != '' && !$this->_loadExtender($item)) { |
|
678 | 678 | throw new Exception('Error load ' . APIHelpers::e($item) . ' extender'); |
679 | 679 | } |
680 | 680 | } |
@@ -690,8 +690,8 @@ discard block |
||
690 | 690 | * @param mixed $def значение по умолчанию, если в конфиге нет искомого параметра |
691 | 691 | * @return mixed значение из конфига |
692 | 692 | */ |
693 | - public function getCFGDef($name, $def = null) |
|
694 | - { |
|
693 | + public function getCFGDef($name, $def = null) |
|
694 | + { |
|
695 | 695 | return $this->config->getCFGDef($name, $def); |
696 | 696 | } |
697 | 697 | |
@@ -703,15 +703,15 @@ discard block |
||
703 | 703 | * @param string $key ключ локального плейсхолдера |
704 | 704 | * @return string |
705 | 705 | */ |
706 | - public function toPlaceholders($data, $set = 0, $key = 'contentPlaceholder') |
|
707 | - { |
|
706 | + public function toPlaceholders($data, $set = 0, $key = 'contentPlaceholder') |
|
707 | + { |
|
708 | 708 | $this->debug->debug(null, 'toPlaceholders', 2); |
709 | - if ($set == 0) { |
|
709 | + if ($set == 0) { |
|
710 | 710 | $set = $this->getCFGDef('contentPlaceholder', 0); |
711 | 711 | } |
712 | 712 | $this->_plh[$key] = $data; |
713 | 713 | $id = $this->getCFGDef('id', ''); |
714 | - if ($id != '') { |
|
714 | + if ($id != '') { |
|
715 | 715 | $id .= "."; |
716 | 716 | } |
717 | 717 | $out = DLTemplate::getInstance($this->getMODX())->toPlaceholders($data, $set, $key, $id); |
@@ -733,14 +733,19 @@ discard block |
||
733 | 733 | * @param boolean $quote заключать ли данные на выходе в кавычки |
734 | 734 | * @return string обработанная строка |
735 | 735 | */ |
736 | - public function sanitarIn($data, $sep = ',', $quote = true) |
|
737 | - { |
|
738 | - if(is_scalar($data)) $data = explode($sep, $data); |
|
739 | - if(!is_array($data)) $data = array(); //@TODO: throw |
|
736 | + public function sanitarIn($data, $sep = ',', $quote = true) |
|
737 | + { |
|
738 | + if(is_scalar($data)) { |
|
739 | + $data = explode($sep, $data); |
|
740 | + } |
|
741 | + if(!is_array($data)) { |
|
742 | + $data = array(); |
|
743 | + } |
|
744 | + //@TODO: throw |
|
740 | 745 | |
741 | 746 | $out = array(); |
742 | - foreach ($data as $item) { |
|
743 | - if ($item !== '') { |
|
747 | + foreach ($data as $item) { |
|
748 | + if ($item !== '') { |
|
744 | 749 | $out[] = $this->modx->db->escape($item); |
745 | 750 | } |
746 | 751 | } |
@@ -761,12 +766,12 @@ discard block |
||
761 | 766 | * @param string $lang имя языкового пакета |
762 | 767 | * @return array |
763 | 768 | */ |
764 | - public function getCustomLang($lang = '') |
|
765 | - { |
|
766 | - if (empty($lang)) { |
|
769 | + public function getCustomLang($lang = '') |
|
770 | + { |
|
771 | + if (empty($lang)) { |
|
767 | 772 | $lang = $this->getCFGDef('lang', $this->modx->config['manager_language']); |
768 | 773 | } |
769 | - if (file_exists(dirname(dirname(__FILE__)) . "/lang/" . $lang . ".php")) { |
|
774 | + if (file_exists(dirname(dirname(__FILE__)) . "/lang/" . $lang . ".php")) { |
|
770 | 775 | $tmp = include(dirname(__FILE__) . "/lang/" . $lang . ".php"); |
771 | 776 | $this->_customLang = is_array($tmp) ? $tmp : array(); |
772 | 777 | } |
@@ -782,25 +787,25 @@ discard block |
||
782 | 787 | * @param boolean $rename Переименовывать ли элементы массива |
783 | 788 | * @return array массив с лексиконом |
784 | 789 | */ |
785 | - public function loadLang($name = 'core', $lang = '', $rename = true) |
|
786 | - { |
|
787 | - if (empty($lang)) { |
|
790 | + public function loadLang($name = 'core', $lang = '', $rename = true) |
|
791 | + { |
|
792 | + if (empty($lang)) { |
|
788 | 793 | $lang = $this->getCFGDef('lang', $this->modx->config['manager_language']); |
789 | 794 | } |
790 | 795 | |
791 | 796 | $this->debug->debug('Load language ' . $this->debug->dumpData($name) . "." . $this->debug->dumpData($lang), |
792 | 797 | 'loadlang', 2); |
793 | - if (is_scalar($name)) { |
|
798 | + if (is_scalar($name)) { |
|
794 | 799 | $name = array($name); |
795 | 800 | } |
796 | - foreach ($name as $n) { |
|
797 | - if (file_exists(dirname(__FILE__) . "/lang/" . $lang . "/" . $n . ".inc.php")) { |
|
801 | + foreach ($name as $n) { |
|
802 | + if (file_exists(dirname(__FILE__) . "/lang/" . $lang . "/" . $n . ".inc.php")) { |
|
798 | 803 | $tmp = include(dirname(__FILE__) . "/lang/" . $lang . "/" . $n . ".inc.php"); |
799 | - if (is_array($tmp)) { |
|
804 | + if (is_array($tmp)) { |
|
800 | 805 | /** |
801 | 806 | * Переименовыываем элементы массива из array('test'=>'data') в array('name.test'=>'data') |
802 | 807 | */ |
803 | - if ($rename) { |
|
808 | + if ($rename) { |
|
804 | 809 | $tmp = $this->renameKeyArr($tmp, $n, '', '.'); |
805 | 810 | } |
806 | 811 | $this->_lang = array_merge($this->_lang, $tmp); |
@@ -819,11 +824,11 @@ discard block |
||
819 | 824 | * @param string $def Строка по умолчанию, если запись в языковом пакете не будет обнаружена |
820 | 825 | * @return string строка в соответствии с текущими языковыми настройками |
821 | 826 | */ |
822 | - public function getMsg($name, $def = '') |
|
823 | - { |
|
824 | - if (isset($this->_customLang[$name])) { |
|
827 | + public function getMsg($name, $def = '') |
|
828 | + { |
|
829 | + if (isset($this->_customLang[$name])) { |
|
825 | 830 | $say = $this->_customLang[$name]; |
826 | - } else { |
|
831 | + } else { |
|
827 | 832 | $say = \APIHelpers::getkey($this->_lang, $name, $def); |
828 | 833 | } |
829 | 834 | |
@@ -839,8 +844,8 @@ discard block |
||
839 | 844 | * @param string $sep разделитель суффиксов, префиксов и ключей массива |
840 | 845 | * @return array массив с переименованными ключами |
841 | 846 | */ |
842 | - public function renameKeyArr($data, $prefix = '', $suffix = '', $sep = '.') |
|
843 | - { |
|
847 | + public function renameKeyArr($data, $prefix = '', $suffix = '', $sep = '.') |
|
848 | + { |
|
844 | 849 | return \APIHelpers::renameKeyArr($data, $prefix, $suffix, $sep); |
845 | 850 | } |
846 | 851 | |
@@ -850,12 +855,12 @@ discard block |
||
850 | 855 | * @param string $locale локаль |
851 | 856 | * @return string имя установленной локали |
852 | 857 | */ |
853 | - public function setLocate($locale = '') |
|
854 | - { |
|
855 | - if ('' == $locale) { |
|
858 | + public function setLocate($locale = '') |
|
859 | + { |
|
860 | + if ('' == $locale) { |
|
856 | 861 | $locale = $this->getCFGDef('locale', ''); |
857 | 862 | } |
858 | - if ('' != $locale) { |
|
863 | + if ('' != $locale) { |
|
859 | 864 | setlocale(LC_ALL, $locale); |
860 | 865 | } |
861 | 866 | |
@@ -869,11 +874,11 @@ discard block |
||
869 | 874 | * @param array $data массив сформированный как дерево |
870 | 875 | * @return string строка для отображения пользователю |
871 | 876 | */ |
872 | - protected function renderTree($data) |
|
873 | - { |
|
877 | + protected function renderTree($data) |
|
878 | + { |
|
874 | 879 | $out = ''; |
875 | - if (!empty($data['#childNodes'])) { |
|
876 | - foreach ($data['#childNodes'] as $item) { |
|
880 | + if (!empty($data['#childNodes'])) { |
|
881 | + foreach ($data['#childNodes'] as $item) { |
|
877 | 882 | $out .= $this->renderTree($item); |
878 | 883 | } |
879 | 884 | } |
@@ -890,8 +895,8 @@ discard block |
||
890 | 895 | * @param string $name Template: chunk name || @CODE: template || @FILE: file with template |
891 | 896 | * @return string html template with placeholders without data |
892 | 897 | */ |
893 | - private function _getChunk($name) |
|
894 | - { |
|
898 | + private function _getChunk($name) |
|
899 | + { |
|
895 | 900 | $this->debug->debug(array('Get chunk by name' => $name), "getChunk", 2, array('html')); |
896 | 901 | //without trim |
897 | 902 | $tpl = DLTemplate::getInstance($this->getMODX())->getChunk($name); |
@@ -908,18 +913,18 @@ discard block |
||
908 | 913 | * @param string $tpl HTML шаблон |
909 | 914 | * @return string |
910 | 915 | */ |
911 | - public function parseLang($tpl) |
|
912 | - { |
|
916 | + public function parseLang($tpl) |
|
917 | + { |
|
913 | 918 | $this->debug->debug(array("parseLang" => $tpl), "parseLang", 2, array('html')); |
914 | - if (is_scalar($tpl) && !empty($tpl)) { |
|
915 | - if (preg_match_all("/\[\%([a-zA-Z0-9\.\_\-]+)\%\]/", $tpl, $match)) { |
|
919 | + if (is_scalar($tpl) && !empty($tpl)) { |
|
920 | + if (preg_match_all("/\[\%([a-zA-Z0-9\.\_\-]+)\%\]/", $tpl, $match)) { |
|
916 | 921 | $langVal = array(); |
917 | - foreach ($match[1] as $item) { |
|
922 | + foreach ($match[1] as $item) { |
|
918 | 923 | $langVal[] = $this->getMsg($item); |
919 | 924 | } |
920 | 925 | $tpl = str_replace($match[0], $langVal, $tpl); |
921 | 926 | } |
922 | - } else { |
|
927 | + } else { |
|
923 | 928 | $tpl = ''; |
924 | 929 | } |
925 | 930 | $this->debug->debugEnd("parseLang"); |
@@ -935,8 +940,8 @@ discard block |
||
935 | 940 | * @param bool $parseDocumentSource render html template via DocumentParser::parseDocumentSource() |
936 | 941 | * @return string html template with data without placeholders |
937 | 942 | */ |
938 | - public function parseChunk($name, $data, $parseDocumentSource = false) |
|
939 | - { |
|
943 | + public function parseChunk($name, $data, $parseDocumentSource = false) |
|
944 | + { |
|
940 | 945 | $this->debug->debug( |
941 | 946 | array("parseChunk" => $name, "With data" => print_r($data, 1)), |
942 | 947 | "parseChunk", |
@@ -945,7 +950,7 @@ discard block |
||
945 | 950 | |
946 | 951 | $out = $this->DLTemplate->parseChunk($name, $data, $parseDocumentSource); |
947 | 952 | $out = $this->parseLang($out); |
948 | - if (empty($out)) { |
|
953 | + if (empty($out)) { |
|
949 | 954 | $this->debug->debug("Empty chunk: " . $this->debug->dumpData($name), '', 2); |
950 | 955 | } |
951 | 956 | $this->debug->debugEnd("parseChunk"); |
@@ -961,8 +966,8 @@ discard block |
||
961 | 966 | * |
962 | 967 | * @return string html template from parameter |
963 | 968 | */ |
964 | - public function getChunkByParam($name, $val = '') |
|
965 | - { |
|
969 | + public function getChunkByParam($name, $val = '') |
|
970 | + { |
|
966 | 971 | $data = $this->getCFGDef($name, $val); |
967 | 972 | $data = $this->_getChunk($data); |
968 | 973 | |
@@ -975,11 +980,11 @@ discard block |
||
975 | 980 | * @param string $data html код который нужно обернуть в ownerTPL |
976 | 981 | * @return string результатирующий html код |
977 | 982 | */ |
978 | - public function renderWrap($data) |
|
979 | - { |
|
983 | + public function renderWrap($data) |
|
984 | + { |
|
980 | 985 | $out = $data; |
981 | 986 | $docs = count($this->_docs) - $this->skippedDocs; |
982 | - if ((($this->getCFGDef("noneWrapOuter", "1") && $docs == 0) || $docs > 0) && !empty($this->ownerTPL)) { |
|
987 | + if ((($this->getCFGDef("noneWrapOuter", "1") && $docs == 0) || $docs > 0) && !empty($this->ownerTPL)) { |
|
983 | 988 | $this->debug->debug("", "renderWrapTPL", 2); |
984 | 989 | $parse = true; |
985 | 990 | $plh = array($this->getCFGDef("sysKey", "dl") . ".wrap" => $data); |
@@ -987,7 +992,7 @@ discard block |
||
987 | 992 | * @var $extPrepare prepare_DL_Extender |
988 | 993 | */ |
989 | 994 | $extPrepare = $this->getExtender('prepare'); |
990 | - if ($extPrepare) { |
|
995 | + if ($extPrepare) { |
|
991 | 996 | $params = $extPrepare->init($this, array( |
992 | 997 | 'data' => array( |
993 | 998 | 'docs' => $this->_docs, |
@@ -996,13 +1001,13 @@ discard block |
||
996 | 1001 | 'nameParam' => 'prepareWrap', |
997 | 1002 | 'return' => 'placeholders' |
998 | 1003 | )); |
999 | - if (is_bool($params) && $params === false) { |
|
1004 | + if (is_bool($params) && $params === false) { |
|
1000 | 1005 | $out = $data; |
1001 | 1006 | $parse = false; |
1002 | 1007 | } |
1003 | 1008 | $plh = $params; |
1004 | 1009 | } |
1005 | - if ($parse && !empty($this->ownerTPL)) { |
|
1010 | + if ($parse && !empty($this->ownerTPL)) { |
|
1006 | 1011 | $this->debug->updateMessage( |
1007 | 1012 | array("render ownerTPL" => $this->ownerTPL, "With data" => print_r($plh, 1)), |
1008 | 1013 | "renderWrapTPL", |
@@ -1010,7 +1015,7 @@ discard block |
||
1010 | 1015 | ); |
1011 | 1016 | $out = $this->parseChunk($this->ownerTPL, $plh); |
1012 | 1017 | } |
1013 | - if (empty($this->ownerTPL)) { |
|
1018 | + if (empty($this->ownerTPL)) { |
|
1014 | 1019 | $this->debug->updateMessage("empty ownerTPL", "renderWrapTPL"); |
1015 | 1020 | } |
1016 | 1021 | $this->debug->debugEnd("renderWrapTPL"); |
@@ -1026,8 +1031,8 @@ discard block |
||
1026 | 1031 | * @param int $i номер итерации в цикле |
1027 | 1032 | * @return array массив с данными которые можно использовать в цикле render метода |
1028 | 1033 | */ |
1029 | - protected function uniformPrepare(&$data, $i = 0) |
|
1030 | - { |
|
1034 | + protected function uniformPrepare(&$data, $i = 0) |
|
1035 | + { |
|
1031 | 1036 | $class = array(); |
1032 | 1037 | |
1033 | 1038 | $iterationName = ($i % 2 == 1) ? 'Odd' : 'Even'; |
@@ -1038,13 +1043,13 @@ discard block |
||
1038 | 1043 | $this->renderTPL = $this->getCFGDef('tpl' . $iterationName, $this->renderTPL); |
1039 | 1044 | $iteration = $i; |
1040 | 1045 | |
1041 | - if ($this->extPaginate) { |
|
1046 | + if ($this->extPaginate) { |
|
1042 | 1047 | $offset = $this->getCFGDef('reversePagination', |
1043 | 1048 | 0) && $this->extPaginate->currentPage() > 1 ? $this->extPaginate->totalPage() * $this->getCFGDef('display', |
1044 | 1049 | 0) - $this->extPaginate->totalDocs() : 0; |
1045 | 1050 | if ($this->getCFGDef('maxDocs', 0) && !$this->getCFGDef('reversePagination', |
1046 | 1051 | 0) && $this->extPaginate->currentPage() == $this->extPaginate->totalPage() |
1047 | - ) { |
|
1052 | + ) { |
|
1048 | 1053 | $iteration += $this->getCFGDef('display', 0); |
1049 | 1054 | } |
1050 | 1055 | $iteration += $this->getCFGDef('display', |
@@ -1054,20 +1059,20 @@ discard block |
||
1054 | 1059 | $data[$this->getCFGDef("sysKey", |
1055 | 1060 | "dl") . '.full_iteration'] = $iteration; |
1056 | 1061 | |
1057 | - if ($i == 1) { |
|
1062 | + if ($i == 1) { |
|
1058 | 1063 | $this->renderTPL = $this->getCFGDef('tplFirst', $this->renderTPL); |
1059 | 1064 | $class[] = $this->getCFGDef('firstClass', 'first'); |
1060 | 1065 | } |
1061 | - if ($i == (count($this->_docs) - $this->skippedDocs)) { |
|
1066 | + if ($i == (count($this->_docs) - $this->skippedDocs)) { |
|
1062 | 1067 | $this->renderTPL = $this->getCFGDef('tplLast', $this->renderTPL); |
1063 | 1068 | $class[] = $this->getCFGDef('lastClass', 'last'); |
1064 | 1069 | } |
1065 | - if ($this->modx->documentIdentifier == $data['id']) { |
|
1070 | + if ($this->modx->documentIdentifier == $data['id']) { |
|
1066 | 1071 | $this->renderTPL = $this->getCFGDef('tplCurrent', $this->renderTPL); |
1067 | 1072 | $data[$this->getCFGDef("sysKey", |
1068 | 1073 | "dl") . '.active'] = 1; //[+active+] - 1 if $modx->documentIdentifer equal ID this element |
1069 | 1074 | $class[] = $this->getCFGDef('currentClass', 'current'); |
1070 | - } else { |
|
1075 | + } else { |
|
1071 | 1076 | $data[$this->getCFGDef("sysKey", "dl") . '.active'] = 0; |
1072 | 1077 | } |
1073 | 1078 | |
@@ -1078,8 +1083,8 @@ discard block |
||
1078 | 1083 | * @var $extE e_DL_Extender |
1079 | 1084 | */ |
1080 | 1085 | $extE = $this->getExtender('e', true, true); |
1081 | - if ($out = $extE->init($this, compact('data'))) { |
|
1082 | - if (is_array($out)) { |
|
1086 | + if ($out = $extE->init($this, compact('data'))) { |
|
1087 | + if (is_array($out)) { |
|
1083 | 1088 | $data = $out; |
1084 | 1089 | } |
1085 | 1090 | } |
@@ -1095,42 +1100,43 @@ discard block |
||
1095 | 1100 | * @param array $array данные которые необходимо примешать к ответу на каждой записи $data |
1096 | 1101 | * @return string JSON строка |
1097 | 1102 | */ |
1098 | - public function getJSON($data, $fields, $array = array()) |
|
1099 | - { |
|
1103 | + public function getJSON($data, $fields, $array = array()) |
|
1104 | + { |
|
1100 | 1105 | $out = array(); |
1101 | 1106 | $fields = is_array($fields) ? $fields : explode(",", $fields); |
1102 | - if (is_array($array) && count($array) > 0) { |
|
1107 | + if (is_array($array) && count($array) > 0) { |
|
1103 | 1108 | $tmp = array(); |
1104 | - foreach ($data as $i => $v) { //array_merge not valid work with integer index key |
|
1109 | + foreach ($data as $i => $v) { |
|
1110 | +//array_merge not valid work with integer index key |
|
1105 | 1111 | $tmp[$i] = (isset($array[$i]) ? array_merge($v, $array[$i]) : $v); |
1106 | 1112 | } |
1107 | 1113 | $data = $tmp; |
1108 | 1114 | } |
1109 | 1115 | |
1110 | - foreach ($data as $num => $doc) { |
|
1116 | + foreach ($data as $num => $doc) { |
|
1111 | 1117 | $tmp = array(); |
1112 | - foreach ($doc as $name => $value) { |
|
1113 | - if (in_array($name, $fields) || (isset($fields[0]) && $fields[0] == '1')) { |
|
1118 | + foreach ($doc as $name => $value) { |
|
1119 | + if (in_array($name, $fields) || (isset($fields[0]) && $fields[0] == '1')) { |
|
1114 | 1120 | $tmp[str_replace(".", "_", $name)] = $value; //JSON element name without dot |
1115 | 1121 | } |
1116 | 1122 | } |
1117 | 1123 | $out[$num] = $tmp; |
1118 | 1124 | } |
1119 | 1125 | |
1120 | - if ('new' == $this->getCFGDef('JSONformat', 'old')) { |
|
1126 | + if ('new' == $this->getCFGDef('JSONformat', 'old')) { |
|
1121 | 1127 | $return = array(); |
1122 | 1128 | |
1123 | 1129 | $return['rows'] = array(); |
1124 | - foreach ($out as $key => $item) { |
|
1130 | + foreach ($out as $key => $item) { |
|
1125 | 1131 | $return['rows'][] = $item; |
1126 | 1132 | } |
1127 | 1133 | $return['total'] = $this->getChildrenCount(); |
1128 | - } elseif ('simple' == $this->getCFGDef('JSONformat', 'old')) { |
|
1134 | + } elseif ('simple' == $this->getCFGDef('JSONformat', 'old')) { |
|
1129 | 1135 | $return = array(); |
1130 | - foreach ($out as $key => $item) { |
|
1136 | + foreach ($out as $key => $item) { |
|
1131 | 1137 | $return[] = $item; |
1132 | 1138 | } |
1133 | - } else { |
|
1139 | + } else { |
|
1134 | 1140 | $return = $out; |
1135 | 1141 | } |
1136 | 1142 | $this->outData = json_encode($return); |
@@ -1146,11 +1152,11 @@ discard block |
||
1146 | 1152 | * @param string $contentField |
1147 | 1153 | * @return mixed|string |
1148 | 1154 | */ |
1149 | - protected function getSummary(array $item = array(), $extSummary = null, $introField = '', $contentField = '') |
|
1150 | - { |
|
1155 | + protected function getSummary(array $item = array(), $extSummary = null, $introField = '', $contentField = '') |
|
1156 | + { |
|
1151 | 1157 | $out = ''; |
1152 | 1158 | |
1153 | - if (is_null($extSummary)) { |
|
1159 | + if (is_null($extSummary)) { |
|
1154 | 1160 | /** |
1155 | 1161 | * @var $extSummary summary_DL_Extender |
1156 | 1162 | */ |
@@ -1159,10 +1165,10 @@ discard block |
||
1159 | 1165 | $introField = $this->getCFGDef("introField", $introField); |
1160 | 1166 | $contentField = $this->getCFGDef("contentField", $contentField); |
1161 | 1167 | |
1162 | - if (!empty($introField) && !empty($item[$introField]) && mb_strlen($item[$introField], 'UTF-8') > 0) { |
|
1168 | + if (!empty($introField) && !empty($item[$introField]) && mb_strlen($item[$introField], 'UTF-8') > 0) { |
|
1163 | 1169 | $out = $item[$introField]; |
1164 | - } else { |
|
1165 | - if (!empty($contentField) && !empty($item[$contentField]) && mb_strlen($item[$contentField], 'UTF-8') > 0) { |
|
1170 | + } else { |
|
1171 | + if (!empty($contentField) && !empty($item[$contentField]) && mb_strlen($item[$contentField], 'UTF-8') > 0) { |
|
1166 | 1172 | $out = $extSummary->init($this, array( |
1167 | 1173 | "content" => $item[$contentField], |
1168 | 1174 | "action" => $this->getCFGDef("summary", ""), |
@@ -1180,8 +1186,8 @@ discard block |
||
1180 | 1186 | * @param string $name extender name |
1181 | 1187 | * @return boolean status extender load |
1182 | 1188 | */ |
1183 | - public function checkExtender($name) |
|
1184 | - { |
|
1189 | + public function checkExtender($name) |
|
1190 | + { |
|
1185 | 1191 | return (isset($this->extender[$name]) && $this->extender[$name] instanceof $name . "_DL_Extender"); |
1186 | 1192 | } |
1187 | 1193 | |
@@ -1189,8 +1195,8 @@ discard block |
||
1189 | 1195 | * @param $name |
1190 | 1196 | * @param $obj |
1191 | 1197 | */ |
1192 | - public function setExtender($name, $obj) |
|
1193 | - { |
|
1198 | + public function setExtender($name, $obj) |
|
1199 | + { |
|
1194 | 1200 | $this->extender[$name] = $obj; |
1195 | 1201 | } |
1196 | 1202 | |
@@ -1202,13 +1208,13 @@ discard block |
||
1202 | 1208 | * @param bool $nop если экстендер не загружен, то загружать ли xNop |
1203 | 1209 | * @return null|xNop |
1204 | 1210 | */ |
1205 | - public function getExtender($name, $autoload = false, $nop = false) |
|
1206 | - { |
|
1211 | + public function getExtender($name, $autoload = false, $nop = false) |
|
1212 | + { |
|
1207 | 1213 | $out = null; |
1208 | - if ((is_scalar($name) && $this->checkExtender($name)) || ($autoload && $this->_loadExtender($name))) { |
|
1214 | + if ((is_scalar($name) && $this->checkExtender($name)) || ($autoload && $this->_loadExtender($name))) { |
|
1209 | 1215 | $out = $this->extender[$name]; |
1210 | 1216 | } |
1211 | - if ($nop && is_null($out)) { |
|
1217 | + if ($nop && is_null($out)) { |
|
1212 | 1218 | $out = new xNop(); |
1213 | 1219 | } |
1214 | 1220 | |
@@ -1221,27 +1227,27 @@ discard block |
||
1221 | 1227 | * @param string $name name extender |
1222 | 1228 | * @return boolean $flag status load extender |
1223 | 1229 | */ |
1224 | - protected function _loadExtender($name) |
|
1225 | - { |
|
1230 | + protected function _loadExtender($name) |
|
1231 | + { |
|
1226 | 1232 | $this->debug->debug('Load Extender ' . $this->debug->dumpData($name), 'LoadExtender', 2); |
1227 | 1233 | $flag = false; |
1228 | 1234 | |
1229 | 1235 | $classname = ($name != '') ? $name . "_DL_Extender" : ""; |
1230 | - if ($classname != '' && isset($this->extender[$name]) && $this->extender[$name] instanceof $classname) { |
|
1236 | + if ($classname != '' && isset($this->extender[$name]) && $this->extender[$name] instanceof $classname) { |
|
1231 | 1237 | $flag = true; |
1232 | 1238 | |
1233 | - } else { |
|
1234 | - if (!class_exists($classname, false) && $classname != '') { |
|
1235 | - if (file_exists(dirname(__FILE__) . "/extender/" . $name . ".extender.inc")) { |
|
1239 | + } else { |
|
1240 | + if (!class_exists($classname, false) && $classname != '') { |
|
1241 | + if (file_exists(dirname(__FILE__) . "/extender/" . $name . ".extender.inc")) { |
|
1236 | 1242 | include_once(dirname(__FILE__) . "/extender/" . $name . ".extender.inc"); |
1237 | 1243 | } |
1238 | 1244 | } |
1239 | - if (class_exists($classname, false) && $classname != '') { |
|
1245 | + if (class_exists($classname, false) && $classname != '') { |
|
1240 | 1246 | $this->extender[$name] = new $classname($this, $name); |
1241 | 1247 | $flag = true; |
1242 | 1248 | } |
1243 | 1249 | } |
1244 | - if (!$flag) { |
|
1250 | + if (!$flag) { |
|
1245 | 1251 | $this->debug->debug("Error load Extender " . $this->debug->dumpData($name)); |
1246 | 1252 | } |
1247 | 1253 | $this->debug->debugEnd('LoadExtender'); |
@@ -1259,16 +1265,16 @@ discard block |
||
1259 | 1265 | * @param mixed $IDs список id документов по которым необходима выборка |
1260 | 1266 | * @return array очищенный массив |
1261 | 1267 | */ |
1262 | - public function setIDs($IDs) |
|
1263 | - { |
|
1268 | + public function setIDs($IDs) |
|
1269 | + { |
|
1264 | 1270 | $this->debug->debug('set ID list ' . $this->debug->dumpData($IDs), 'setIDs', 2); |
1265 | 1271 | $IDs = $this->cleanIDs($IDs); |
1266 | 1272 | $type = $this->getCFGDef('idType', 'parents'); |
1267 | 1273 | $depth = $this->getCFGDef('depth', ''); |
1268 | - if ($type == 'parents' && $depth > 0) { |
|
1274 | + if ($type == 'parents' && $depth > 0) { |
|
1269 | 1275 | $tmp = $IDs; |
1270 | - do { |
|
1271 | - if (count($tmp) > 0) { |
|
1276 | + do { |
|
1277 | + if (count($tmp) > 0) { |
|
1272 | 1278 | $tmp = $this->getChildrenFolder($tmp); |
1273 | 1279 | $IDs = array_merge($IDs, $tmp); |
1274 | 1280 | } |
@@ -1282,8 +1288,8 @@ discard block |
||
1282 | 1288 | /** |
1283 | 1289 | * @return int |
1284 | 1290 | */ |
1285 | - public function getIDs() |
|
1286 | - { |
|
1291 | + public function getIDs() |
|
1292 | + { |
|
1287 | 1293 | return $this->IDs; |
1288 | 1294 | } |
1289 | 1295 | |
@@ -1294,17 +1300,18 @@ discard block |
||
1294 | 1300 | * @param string $sep разделитель |
1295 | 1301 | * @return array очищенный массив с данными |
1296 | 1302 | */ |
1297 | - public function cleanIDs($IDs, $sep = ',') |
|
1298 | - { |
|
1303 | + public function cleanIDs($IDs, $sep = ',') |
|
1304 | + { |
|
1299 | 1305 | $this->debug->debug('clean IDs ' . $this->debug->dumpData($IDs) . ' with separator ' . $this->debug->dumpData($sep), |
1300 | 1306 | 'cleanIDs', 2); |
1301 | 1307 | $out = array(); |
1302 | - if (!is_array($IDs)) { |
|
1308 | + if (!is_array($IDs)) { |
|
1303 | 1309 | $IDs = explode($sep, $IDs); |
1304 | 1310 | } |
1305 | - foreach ($IDs as $item) { |
|
1311 | + foreach ($IDs as $item) { |
|
1306 | 1312 | $item = trim($item); |
1307 | - if (is_numeric($item) && (int)$item >= 0) { //Fix 0xfffffffff |
|
1313 | + if (is_numeric($item) && (int)$item >= 0) { |
|
1314 | +//Fix 0xfffffffff |
|
1308 | 1315 | $out[] = (int)$item; |
1309 | 1316 | } |
1310 | 1317 | } |
@@ -1318,8 +1325,8 @@ discard block |
||
1318 | 1325 | * Проверка массива с id-шниками документов для выборки |
1319 | 1326 | * @return boolean пригодны ли данные для дальнейшего использования |
1320 | 1327 | */ |
1321 | - protected function checkIDs() |
|
1322 | - { |
|
1328 | + protected function checkIDs() |
|
1329 | + { |
|
1323 | 1330 | return (is_array($this->IDs) && count($this->IDs) > 0) ? true : false; |
1324 | 1331 | } |
1325 | 1332 | |
@@ -1331,11 +1338,11 @@ discard block |
||
1331 | 1338 | * @global array $_docs all documents |
1332 | 1339 | * @return array all field values |
1333 | 1340 | */ |
1334 | - public function getOneField($userField, $uniq = false) |
|
1335 | - { |
|
1341 | + public function getOneField($userField, $uniq = false) |
|
1342 | + { |
|
1336 | 1343 | $out = array(); |
1337 | - foreach ($this->_docs as $doc => $val) { |
|
1338 | - if (isset($val[$userField]) && (($uniq && !in_array($val[$userField], $out)) || !$uniq)) { |
|
1344 | + foreach ($this->_docs as $doc => $val) { |
|
1345 | + if (isset($val[$userField]) && (($uniq && !in_array($val[$userField], $out)) || !$uniq)) { |
|
1339 | 1346 | $out[$doc] = $val[$userField]; |
1340 | 1347 | } |
1341 | 1348 | } |
@@ -1346,8 +1353,8 @@ discard block |
||
1346 | 1353 | /** |
1347 | 1354 | * @return DLCollection |
1348 | 1355 | */ |
1349 | - public function docsCollection() |
|
1350 | - { |
|
1356 | + public function docsCollection() |
|
1357 | + { |
|
1351 | 1358 | return new DLCollection($this->modx, $this->_docs); |
1352 | 1359 | } |
1353 | 1360 | |
@@ -1375,10 +1382,10 @@ discard block |
||
1375 | 1382 | * @param string $group |
1376 | 1383 | * @return string |
1377 | 1384 | */ |
1378 | - protected function getGroupSQL($group = '') |
|
1379 | - { |
|
1385 | + protected function getGroupSQL($group = '') |
|
1386 | + { |
|
1380 | 1387 | $out = ''; |
1381 | - if ($group != '') { |
|
1388 | + if ($group != '') { |
|
1382 | 1389 | $out = 'GROUP BY ' . $group; |
1383 | 1390 | } |
1384 | 1391 | |
@@ -1397,12 +1404,12 @@ discard block |
||
1397 | 1404 | * |
1398 | 1405 | * @return string Order by for SQL |
1399 | 1406 | */ |
1400 | - protected function SortOrderSQL($sortName, $orderDef = 'DESC') |
|
1401 | - { |
|
1407 | + protected function SortOrderSQL($sortName, $orderDef = 'DESC') |
|
1408 | + { |
|
1402 | 1409 | $this->debug->debug('', 'sortORDER', 2); |
1403 | 1410 | |
1404 | 1411 | $sort = ''; |
1405 | - switch ($this->getCFGDef('sortType', '')) { |
|
1412 | + switch ($this->getCFGDef('sortType', '')) { |
|
1406 | 1413 | case 'none': |
1407 | 1414 | break; |
1408 | 1415 | case 'doclist': |
@@ -1413,10 +1420,10 @@ discard block |
||
1413 | 1420 | break; |
1414 | 1421 | default: |
1415 | 1422 | $out = array('orderBy' => '', 'order' => '', 'sortBy' => ''); |
1416 | - if (($tmp = $this->getCFGDef('orderBy', '')) != '') { |
|
1423 | + if (($tmp = $this->getCFGDef('orderBy', '')) != '') { |
|
1417 | 1424 | $out['orderBy'] = $tmp; |
1418 | - } else { |
|
1419 | - switch (true) { |
|
1425 | + } else { |
|
1426 | + switch (true) { |
|
1420 | 1427 | case ('' != ($tmp = $this->getCFGDef('sortDir', ''))): //higher priority than order |
1421 | 1428 | $out['order'] = $tmp; |
1422 | 1429 | // no break |
@@ -1424,7 +1431,7 @@ discard block |
||
1424 | 1431 | $out['order'] = $tmp; |
1425 | 1432 | // no break |
1426 | 1433 | } |
1427 | - if ('' == $out['order'] || !in_array(strtoupper($out['order']), array('ASC', 'DESC'))) { |
|
1434 | + if ('' == $out['order'] || !in_array(strtoupper($out['order']), array('ASC', 'DESC'))) { |
|
1428 | 1435 | $out['order'] = $orderDef; //Default |
1429 | 1436 | } |
1430 | 1437 | |
@@ -1445,30 +1452,30 @@ discard block |
||
1445 | 1452 | * |
1446 | 1453 | * @return string LIMIT вставка в SQL запрос |
1447 | 1454 | */ |
1448 | - protected function LimitSQL($limit = 0, $offset = 0) |
|
1449 | - { |
|
1455 | + protected function LimitSQL($limit = 0, $offset = 0) |
|
1456 | + { |
|
1450 | 1457 | $this->debug->debug('', 'limitSQL', 2); |
1451 | 1458 | $ret = ''; |
1452 | - if ($limit == 0) { |
|
1459 | + if ($limit == 0) { |
|
1453 | 1460 | $limit = $this->getCFGDef('display', 0); |
1454 | 1461 | } |
1455 | 1462 | $maxDocs = $this->getCFGDef('maxDocs', 0); |
1456 | - if ($maxDocs > 0 && $limit > $maxDocs) { |
|
1463 | + if ($maxDocs > 0 && $limit > $maxDocs) { |
|
1457 | 1464 | $limit = $maxDocs; |
1458 | 1465 | } |
1459 | - if ($offset == 0) { |
|
1466 | + if ($offset == 0) { |
|
1460 | 1467 | $offset = $this->getCFGDef('offset', 0); |
1461 | 1468 | } |
1462 | 1469 | $offset += $this->getCFGDef('start', 0); |
1463 | 1470 | $total = $this->getCFGDef('total', 0); |
1464 | - if ($limit < ($total - $limit)) { |
|
1471 | + if ($limit < ($total - $limit)) { |
|
1465 | 1472 | $limit = $total - $offset; |
1466 | 1473 | } |
1467 | 1474 | |
1468 | - if ($limit != 0) { |
|
1475 | + if ($limit != 0) { |
|
1469 | 1476 | $ret = "LIMIT " . (int)$offset . "," . (int)$limit; |
1470 | - } else { |
|
1471 | - if ($offset != 0) { |
|
1477 | + } else { |
|
1478 | + if ($offset != 0) { |
|
1472 | 1479 | /** |
1473 | 1480 | * 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 |
1474 | 1481 | * @see http://dev.mysql.com/doc/refman/5.0/en/select.html |
@@ -1488,8 +1495,8 @@ discard block |
||
1488 | 1495 | * @param string $charset |
1489 | 1496 | * @return string Clear string |
1490 | 1497 | */ |
1491 | - public function sanitarData($data, $charset = 'UTF-8') |
|
1492 | - { |
|
1498 | + public function sanitarData($data, $charset = 'UTF-8') |
|
1499 | + { |
|
1493 | 1500 | return APIHelpers::sanitarTag($data, $charset); |
1494 | 1501 | } |
1495 | 1502 | |
@@ -1500,8 +1507,8 @@ discard block |
||
1500 | 1507 | * @param string $parentField default name parent field |
1501 | 1508 | * @return array |
1502 | 1509 | */ |
1503 | - public function treeBuild($idField = 'id', $parentField = 'parent') |
|
1504 | - { |
|
1510 | + public function treeBuild($idField = 'id', $parentField = 'parent') |
|
1511 | + { |
|
1505 | 1512 | return $this->_treeBuild($this->_docs, $this->getCFGDef('idField', $idField), |
1506 | 1513 | $this->getCFGDef('parentField', $parentField)); |
1507 | 1514 | } |
@@ -1514,16 +1521,16 @@ discard block |
||
1514 | 1521 | * @param string $pidName name parent field in associative data array |
1515 | 1522 | * @return array |
1516 | 1523 | */ |
1517 | - private function _treeBuild($data, $idName, $pidName) |
|
1518 | - { |
|
1524 | + private function _treeBuild($data, $idName, $pidName) |
|
1525 | + { |
|
1519 | 1526 | $children = array(); // children of each ID |
1520 | 1527 | $ids = array(); |
1521 | - foreach ($data as $i => $r) { |
|
1528 | + foreach ($data as $i => $r) { |
|
1522 | 1529 | $row =& $data[$i]; |
1523 | 1530 | $id = $row[$idName]; |
1524 | 1531 | $pid = $row[$pidName]; |
1525 | 1532 | $children[$pid][$id] =& $row; |
1526 | - if (!isset($children[$id])) { |
|
1533 | + if (!isset($children[$id])) { |
|
1527 | 1534 | $children[$id] = array(); |
1528 | 1535 | } |
1529 | 1536 | $row['#childNodes'] =& $children[$id]; |
@@ -1531,9 +1538,9 @@ discard block |
||
1531 | 1538 | } |
1532 | 1539 | // Root elements are elements with non-found PIDs. |
1533 | 1540 | $this->_tree = array(); |
1534 | - foreach ($data as $i => $r) { |
|
1541 | + foreach ($data as $i => $r) { |
|
1535 | 1542 | $row =& $data[$i]; |
1536 | - if (!isset($ids[$row[$pidName]])) { |
|
1543 | + if (!isset($ids[$row[$pidName]])) { |
|
1537 | 1544 | $this->_tree[$row[$idName]] = $row; |
1538 | 1545 | } |
1539 | 1546 | } |
@@ -1547,12 +1554,12 @@ discard block |
||
1547 | 1554 | * @param bool $full если true то возвращается значение для подстановки в запрос |
1548 | 1555 | * @return string PrimaryKey основной таблицы |
1549 | 1556 | */ |
1550 | - public function getPK($full = true) |
|
1551 | - { |
|
1557 | + public function getPK($full = true) |
|
1558 | + { |
|
1552 | 1559 | $idField = isset($this->idField) ? $this->idField: 'id'; |
1553 | - if ($full) { |
|
1560 | + if ($full) { |
|
1554 | 1561 | $idField = '`' . $idField . '`'; |
1555 | - if (!empty($this->alias)) { |
|
1562 | + if (!empty($this->alias)) { |
|
1556 | 1563 | $idField = '`' . $this->alias . '`.' . $idField; |
1557 | 1564 | } |
1558 | 1565 | } |
@@ -1566,12 +1573,12 @@ discard block |
||
1566 | 1573 | * @param bool $full если true то возвращается значение для подстановки в запрос |
1567 | 1574 | * @return string Parent Key основной таблицы |
1568 | 1575 | */ |
1569 | - public function getParentField($full = true) |
|
1570 | - { |
|
1576 | + public function getParentField($full = true) |
|
1577 | + { |
|
1571 | 1578 | $parentField = isset($this->parentField) ? $this->parentField : ''; |
1572 | - if ($full && !empty($parentField)) { |
|
1579 | + if ($full && !empty($parentField)) { |
|
1573 | 1580 | $parentField = '`' . $parentField . '`'; |
1574 | - if (!empty($this->alias)) { |
|
1581 | + if (!empty($this->alias)) { |
|
1575 | 1582 | $parentField = '`' . $this->alias . '`.' . $parentField; |
1576 | 1583 | } |
1577 | 1584 | } |
@@ -1586,31 +1593,31 @@ discard block |
||
1586 | 1593 | * @param string $filter_string строка со всеми фильтрами |
1587 | 1594 | * @return mixed результат разбора фильтров |
1588 | 1595 | */ |
1589 | - protected function getFilters($filter_string) |
|
1590 | - { |
|
1596 | + protected function getFilters($filter_string) |
|
1597 | + { |
|
1591 | 1598 | $this->debug->debug("getFilters: " . $this->debug->dumpData($filter_string), 'getFilter', 1); |
1592 | 1599 | // the filter parameter tells us, which filters can be used in this query |
1593 | 1600 | $filter_string = trim($filter_string, ' ;'); |
1594 | - if (!$filter_string) { |
|
1601 | + if (!$filter_string) { |
|
1595 | 1602 | return; |
1596 | 1603 | } |
1597 | 1604 | $output = array('join' => '', 'where' => ''); |
1598 | 1605 | $logic_op_found = false; |
1599 | 1606 | $joins = $wheres = array(); |
1600 | - foreach ($this->_logic_ops as $op => $sql) { |
|
1601 | - if (strpos($filter_string, $op) === 0) { |
|
1607 | + foreach ($this->_logic_ops as $op => $sql) { |
|
1608 | + if (strpos($filter_string, $op) === 0) { |
|
1602 | 1609 | $logic_op_found = true; |
1603 | 1610 | $subfilters = mb_substr($filter_string, strlen($op) + 1, mb_strlen($filter_string, "UTF-8"), "UTF-8"); |
1604 | 1611 | $subfilters = $this->smartSplit($subfilters); |
1605 | - foreach ($subfilters as $subfilter) { |
|
1612 | + foreach ($subfilters as $subfilter) { |
|
1606 | 1613 | $subfilter = $this->getFilters(trim($subfilter)); |
1607 | - if (!$subfilter) { |
|
1614 | + if (!$subfilter) { |
|
1608 | 1615 | continue; |
1609 | 1616 | } |
1610 | - if ($subfilter['join']) { |
|
1617 | + if ($subfilter['join']) { |
|
1611 | 1618 | $joins[] = $subfilter['join']; |
1612 | 1619 | } |
1613 | - if ($subfilter['where']) { |
|
1620 | + if ($subfilter['where']) { |
|
1614 | 1621 | $wheres[] = $subfilter['where']; |
1615 | 1622 | } |
1616 | 1623 | } |
@@ -1619,12 +1626,12 @@ discard block |
||
1619 | 1626 | } |
1620 | 1627 | } |
1621 | 1628 | |
1622 | - if (!$logic_op_found) { |
|
1629 | + if (!$logic_op_found) { |
|
1623 | 1630 | $filter = $this->loadFilter($filter_string); |
1624 | - if (!$filter) { |
|
1631 | + if (!$filter) { |
|
1625 | 1632 | $this->debug->warning('Error while loading DocLister filter "' . $this->debug->dumpData($filter_string) . '": check syntax!'); |
1626 | 1633 | $output = false; |
1627 | - } else { |
|
1634 | + } else { |
|
1628 | 1635 | $output['join'] = $filter->get_join(); |
1629 | 1636 | $output['where'] = stripslashes($filter->get_where()); |
1630 | 1637 | } |
@@ -1637,16 +1644,16 @@ discard block |
||
1637 | 1644 | /** |
1638 | 1645 | * @return mixed |
1639 | 1646 | */ |
1640 | - public function filtersWhere() |
|
1641 | - { |
|
1647 | + public function filtersWhere() |
|
1648 | + { |
|
1642 | 1649 | return APIHelpers::getkey($this->_filters, 'where', ''); |
1643 | 1650 | } |
1644 | 1651 | |
1645 | 1652 | /** |
1646 | 1653 | * @return mixed |
1647 | 1654 | */ |
1648 | - public function filtersJoin() |
|
1649 | - { |
|
1655 | + public function filtersJoin() |
|
1656 | + { |
|
1650 | 1657 | return APIHelpers::getkey($this->_filters, 'join', ''); |
1651 | 1658 | } |
1652 | 1659 | |
@@ -1654,11 +1661,12 @@ discard block |
||
1654 | 1661 | * @param string $join |
1655 | 1662 | * @return $this |
1656 | 1663 | */ |
1657 | - public function setFiltersJoin($join = '') { |
|
1658 | - if (!empty($join)) { |
|
1659 | - if (!empty($this->_filters['join'])) { |
|
1664 | + public function setFiltersJoin($join = '') |
|
1665 | + { |
|
1666 | + if (!empty($join)) { |
|
1667 | + if (!empty($this->_filters['join'])) { |
|
1660 | 1668 | $this->_filters['join'] .= ' ' . $join; |
1661 | - } else { |
|
1669 | + } else { |
|
1662 | 1670 | $this->_filters['join'] = $join; |
1663 | 1671 | } |
1664 | 1672 | } |
@@ -1673,10 +1681,10 @@ discard block |
||
1673 | 1681 | * @param $type string тип фильтрации |
1674 | 1682 | * @return string имя поля с учетом приведения типа |
1675 | 1683 | */ |
1676 | - public function changeSortType($field, $type) |
|
1677 | - { |
|
1684 | + public function changeSortType($field, $type) |
|
1685 | + { |
|
1678 | 1686 | $type = trim($type); |
1679 | - switch (strtoupper($type)) { |
|
1687 | + switch (strtoupper($type)) { |
|
1680 | 1688 | case 'DECIMAL': |
1681 | 1689 | $field = 'CAST(' . $field . ' as DECIMAL(10,2))'; |
1682 | 1690 | break; |
@@ -1702,8 +1710,8 @@ discard block |
||
1702 | 1710 | * @param string $filter срока с параметрами фильтрации |
1703 | 1711 | * @return bool |
1704 | 1712 | */ |
1705 | - protected function loadFilter($filter) |
|
1706 | - { |
|
1713 | + protected function loadFilter($filter) |
|
1714 | + { |
|
1707 | 1715 | $this->debug->debug('Load filter ' . $this->debug->dumpData($filter), 'loadFilter', 2); |
1708 | 1716 | $out = false; |
1709 | 1717 | $fltr_params = explode(':', $filter, 2); |
@@ -1713,21 +1721,21 @@ discard block |
||
1713 | 1721 | */ |
1714 | 1722 | $fltr_class = $fltr . '_DL_filter'; |
1715 | 1723 | // check if the filter is implemented |
1716 | - if (!is_null($fltr)) { |
|
1717 | - if (!class_exists($fltr_class) && file_exists(__DIR__ . '/filter/' . $fltr . '.filter.php')) { |
|
1724 | + if (!is_null($fltr)) { |
|
1725 | + if (!class_exists($fltr_class) && file_exists(__DIR__ . '/filter/' . $fltr . '.filter.php')) { |
|
1718 | 1726 | require_once dirname(__FILE__) . '/filter/' . $fltr . '.filter.php'; |
1719 | 1727 | } |
1720 | - if (class_exists($fltr_class)) { |
|
1728 | + if (class_exists($fltr_class)) { |
|
1721 | 1729 | $this->totalFilters++; |
1722 | 1730 | $fltr_obj = new $fltr_class(); |
1723 | - if ($fltr_obj->init($this, $filter)) { |
|
1731 | + if ($fltr_obj->init($this, $filter)) { |
|
1724 | 1732 | $out = $fltr_obj; |
1725 | - } else { |
|
1733 | + } else { |
|
1726 | 1734 | $this->debug->error("Wrong filter parameter: '{$this->debug->dumpData($filter)}'", 'Filter'); |
1727 | 1735 | } |
1728 | 1736 | } |
1729 | 1737 | } |
1730 | - if (!$out) { |
|
1738 | + if (!$out) { |
|
1731 | 1739 | $this->debug->error("Error load Filter: '{$this->debug->dumpData($filter)}'", 'Filter'); |
1732 | 1740 | } |
1733 | 1741 | |
@@ -1740,8 +1748,8 @@ discard block |
||
1740 | 1748 | * Общее число фильтров |
1741 | 1749 | * @return int |
1742 | 1750 | */ |
1743 | - public function getCountFilters() |
|
1744 | - { |
|
1751 | + public function getCountFilters() |
|
1752 | + { |
|
1745 | 1753 | return (int)$this->totalFilters; |
1746 | 1754 | } |
1747 | 1755 | |
@@ -1749,8 +1757,8 @@ discard block |
||
1749 | 1757 | * Выполнить SQL запрос |
1750 | 1758 | * @param string $q SQL запрос |
1751 | 1759 | */ |
1752 | - public function dbQuery($q) |
|
1753 | - { |
|
1760 | + public function dbQuery($q) |
|
1761 | + { |
|
1754 | 1762 | $this->debug->debug($q, "query", 1, 'sql'); |
1755 | 1763 | $out = $this->modx->db->query($q); |
1756 | 1764 | $this->debug->debugEnd("query"); |
@@ -1768,8 +1776,8 @@ discard block |
||
1768 | 1776 | * @param string $tpl шаблон подстановки значения в SQL запрос |
1769 | 1777 | * @return string строка для подстановки в SQL запрос |
1770 | 1778 | */ |
1771 | - public function LikeEscape($field, $value, $escape = '=', $tpl = '%[+value+]%') |
|
1772 | - { |
|
1779 | + public function LikeEscape($field, $value, $escape = '=', $tpl = '%[+value+]%') |
|
1780 | + { |
|
1773 | 1781 | return sqlHelper::LikeEscape($this->modx, $field, $value, $escape, $tpl); |
1774 | 1782 | } |
1775 | 1783 | |
@@ -1777,8 +1785,8 @@ discard block |
||
1777 | 1785 | * Получение REQUEST_URI без GET-ключа с |
1778 | 1786 | * @return string |
1779 | 1787 | */ |
1780 | - public function getRequest() |
|
1781 | - { |
|
1788 | + public function getRequest() |
|
1789 | + { |
|
1782 | 1790 | $URL = null; |
1783 | 1791 | parse_str(parse_url(MODX_SITE_URL . $_SERVER['REQUEST_URI'], PHP_URL_QUERY), $URL); |
1784 | 1792 |
@@ -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|array|string $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 |
@@ -13,8 +13,8 @@ discard block |
||
13 | 13 | public static function tildeField($field, $table = '') |
14 | 14 | { |
15 | 15 | $out = ''; |
16 | - if (!empty($field) && is_scalar($field)) { |
|
17 | - if (!empty($table) && is_scalar($table) && $tmp = strpos($field, $table)) { |
|
16 | + if ( ! empty($field) && is_scalar($field)) { |
|
17 | + if ( ! empty($table) && is_scalar($table) && $tmp = strpos($field, $table)) { |
|
18 | 18 | $tmp = substr($field, $tmp + strlen($table), 1); |
19 | 19 | if ($tmp != '.' && $tmp != '`') { |
20 | 20 | $field = $table . "." . $field; |
@@ -74,9 +74,9 @@ discard block |
||
74 | 74 | { |
75 | 75 | $str = ''; |
76 | 76 | $escaped = false; |
77 | - if (!empty($field) && is_string($field) && is_scalar($value) && $value !== '') { |
|
77 | + if ( ! empty($field) && is_string($field) && is_scalar($value) && $value !== '') { |
|
78 | 78 | $field = sqlHelper::tildeField($field); |
79 | - if (is_scalar($escape) && !empty($escape) && !in_array($escape, array("_", "%", "'"))) { |
|
79 | + if (is_scalar($escape) && ! empty($escape) && ! in_array($escape, array("_", "%", "'"))) { |
|
80 | 80 | $str = str_replace(array($escape, '_', '%'), array($escape . $escape, $escape . '_', $escape . '%'), |
81 | 81 | $value); |
82 | 82 | $escaped = true; |
@@ -3,30 +3,30 @@ discard block |
||
3 | 3 | /** |
4 | 4 | * Class sqlHelper |
5 | 5 | */ |
6 | -class sqlHelper |
|
7 | -{ |
|
6 | +class sqlHelper |
|
7 | +{ |
|
8 | 8 | /** |
9 | 9 | * @param $field |
10 | 10 | * @param string $table |
11 | 11 | * @return bool|float|int|string |
12 | 12 | */ |
13 | - public static function tildeField($field, $table = '') |
|
14 | - { |
|
13 | + public static function tildeField($field, $table = '') |
|
14 | + { |
|
15 | 15 | $out = ''; |
16 | - if (!empty($field) && is_scalar($field)) { |
|
17 | - if (!empty($table) && is_scalar($table) && $tmp = strpos($field, $table)) { |
|
16 | + if (!empty($field) && is_scalar($field)) { |
|
17 | + if (!empty($table) && is_scalar($table) && $tmp = strpos($field, $table)) { |
|
18 | 18 | $tmp = substr($field, $tmp + strlen($table), 1); |
19 | - if ($tmp != '.' && $tmp != '`') { |
|
19 | + if ($tmp != '.' && $tmp != '`') { |
|
20 | 20 | $field = $table . "." . $field; |
21 | - } else { |
|
21 | + } else { |
|
22 | 22 | $out = $field; |
23 | 23 | } |
24 | - } elseif (empty($table) && strpos($field, "`")) { |
|
24 | + } elseif (empty($table) && strpos($field, "`")) { |
|
25 | 25 | $out = $field; |
26 | 26 | } |
27 | - if (empty($out)) { |
|
27 | + if (empty($out)) { |
|
28 | 28 | $field = explode(".", $field); |
29 | - foreach ($field as &$f) { |
|
29 | + foreach ($field as &$f) { |
|
30 | 30 | $f = "`" . str_replace("`", "", $f) . "`"; |
31 | 31 | } |
32 | 32 | $out = implode(".", $field); |
@@ -41,10 +41,10 @@ discard block |
||
41 | 41 | * @param string $mode |
42 | 42 | * @return mixed|string |
43 | 43 | */ |
44 | - public static function trimLogicalOp($string, $mode = '') |
|
45 | - { |
|
44 | + public static function trimLogicalOp($string, $mode = '') |
|
45 | + { |
|
46 | 46 | $regex = 'AND|and|OR|or|\&\&|\|\||NOT|not|\!'; |
47 | - switch ($mode) { |
|
47 | + switch ($mode) { |
|
48 | 48 | case 'right': |
49 | 49 | $regex = '\s+(' . $regex . ')\s*$'; |
50 | 50 | break; |
@@ -70,13 +70,13 @@ discard block |
||
70 | 70 | * @param string $tpl шаблон подстановки значения в SQL запрос |
71 | 71 | * @return string строка для подстановки в SQL запрос |
72 | 72 | */ |
73 | - public static function LikeEscape(DocumentParser $modx, $field, $value, $escape = '=', $tpl = '%[+value+]%') |
|
74 | - { |
|
73 | + public static function LikeEscape(DocumentParser $modx, $field, $value, $escape = '=', $tpl = '%[+value+]%') |
|
74 | + { |
|
75 | 75 | $str = ''; |
76 | 76 | $escaped = false; |
77 | - if (!empty($field) && is_string($field) && is_scalar($value) && $value !== '') { |
|
77 | + if (!empty($field) && is_string($field) && is_scalar($value) && $value !== '') { |
|
78 | 78 | $field = sqlHelper::tildeField($field); |
79 | - if (is_scalar($escape) && !empty($escape) && !in_array($escape, array("_", "%", "'"))) { |
|
79 | + if (is_scalar($escape) && !empty($escape) && !in_array($escape, array("_", "%", "'"))) { |
|
80 | 80 | $str = str_replace(array($escape, '_', '%'), array($escape . $escape, $escape . '_', $escape . '%'), |
81 | 81 | $value); |
82 | 82 | $escaped = true; |
@@ -84,9 +84,9 @@ discard block |
||
84 | 84 | $str = $modx->db->escape($str); |
85 | 85 | $str = str_replace('[+value+]', $str, $tpl); |
86 | 86 | |
87 | - if ($escaped) { |
|
87 | + if ($escaped) { |
|
88 | 88 | $str = "{$field} LIKE '{$str}' ESCAPE '{$escape}'"; |
89 | - } else { |
|
89 | + } else { |
|
90 | 90 | $str = "{$field} LIKE '{$str}'"; |
91 | 91 | } |
92 | 92 | } |