Completed
Push — master ( 6afa36...8868df )
by
unknown
04:46
created
assets/lib/Formatter/SqlFormatter.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -330,8 +330,8 @@
 block discarded – undo
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
     {
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -862,7 +862,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Braces   +184 added lines, -182 removed lines patch added patch discarded remove patch
@@ -12,8 +12,8 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
     }
Please login to merge, or discard this patch.
assets/snippets/DocLister/snippet.DLReflect.php 3 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -44,10 +44,10 @@
 block discarded – undo
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 () {
Please login to merge, or discard this patch.
Braces   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
         );
Please login to merge, or discard this patch.
assets/snippets/DocLister/core/DocLister.abstract.php 3 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -399,8 +399,8 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (!defined('MODX_BASE_PATH')) {
2
+if ( ! defined('MODX_BASE_PATH')) {
3 3
     die('HACK???');
4 4
 }
5 5
 /**
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
             $this->modx = $modx;
197 197
             $this->setDebug(1);
198 198
 
199
-            if (!is_array($cfg) || empty($cfg)) {
199
+            if ( ! is_array($cfg) || empty($cfg)) {
200 200
                 $cfg = $this->modx->Event->params;
201 201
             }
202 202
         } else {
@@ -384,11 +384,11 @@  discard block
 block discarded – undo
384 384
      */
385 385
     public function getTable($name, $alias = '')
386 386
     {
387
-        if (!isset($this->_table[$name])) {
387
+        if ( ! isset($this->_table[$name])) {
388 388
             $this->_table[$name] = $this->modx->getFullTableName($name);
389 389
         }
390 390
         $table = $this->_table[$name];
391
-        if (!empty($alias) && is_scalar($alias)) {
391
+        if ( ! empty($alias) && is_scalar($alias)) {
392 392
             $table .= " as `" . $alias . "`";
393 393
         }
394 394
 
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
      */
404 404
     public function TableAlias($name, $table, $alias)
405 405
     {
406
-        if (!$this->checkTableAlias($name, $table)) {
406
+        if ( ! $this->checkTableAlias($name, $table)) {
407 407
             $this->AddTable[$table][$name] = $alias;
408 408
         }
409 409
 
@@ -448,7 +448,7 @@  discard block
 block discarded – undo
448 448
     public function isErrorJSON($json)
449 449
     {
450 450
         $error = jsonHelper::json_last_error_msg();
451
-        if (!in_array($error, array('error_none', 'other'))) {
451
+        if ( ! in_array($error, array('error_none', 'other'))) {
452 452
             $this->debug->error($this->getMsg('json.' . $error) . ": " . $this->debug->dumpData($json, 'code'), 'JSON');
453 453
             $error = true;
454 454
         }
@@ -467,13 +467,13 @@  discard block
 block discarded – undo
467 467
         $extenders = $this->getCFGDef('extender', '');
468 468
         $extenders = explode(",", $extenders);
469 469
         $tmp = $this->getCFGDef('requestActive', '') != '' || in_array('request', $extenders);
470
-        if ($tmp && !$this->_loadExtender('request')) {
470
+        if ($tmp && ! $this->_loadExtender('request')) {
471 471
             //OR request in extender's parameter
472 472
             throw new Exception('Error load request extender');
473 473
         }
474 474
 
475 475
         $tmp = $this->getCFGDef('summary', '') != '' || in_array('summary', $extenders);
476
-        if ($tmp && !$this->_loadExtender('summary')) {
476
+        if ($tmp && ! $this->_loadExtender('summary')) {
477 477
             //OR summary in extender's parameter
478 478
             throw new Exception('Error load summary extender');
479 479
         }
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
                 $this->getCFGDef('TplCurrentPage', '') != '' || $this->getCFGDef('TplWrapPaginate', '') != '' ||
486 486
                 $this->getCFGDef('pageLimit', '') != '' || $this->getCFGDef('pageAdjacents', '') != '' ||
487 487
                 $this->getCFGDef('PaginateClass', '') != '' || $this->getCFGDef('TplNextP', '') != ''
488
-            ) && !$this->_loadExtender('paginate')
488
+            ) && ! $this->_loadExtender('paginate')
489 489
         ) {
490 490
             throw new Exception('Error load paginate extender');
491 491
         } else {
@@ -650,7 +650,7 @@  discard block
 block discarded – undo
650 650
         if ($ext != '') {
651 651
             $ext = explode(",", $ext);
652 652
             foreach ($ext as $item) {
653
-                if ($item != '' && !$this->_loadExtender($item)) {
653
+                if ($item != '' && ! $this->_loadExtender($item)) {
654 654
                     throw new Exception('Error load ' . APIHelpers::e($item) . ' extender');
655 655
                 }
656 656
             }
@@ -711,7 +711,7 @@  discard block
 block discarded – undo
711 711
      */
712 712
     public function sanitarIn($data, $sep = ',', $quote = true)
713 713
     {
714
-        if (!is_array($data)) {
714
+        if ( ! is_array($data)) {
715 715
             $data = explode($sep, $data);
716 716
         }
717 717
         $out = array();
@@ -848,7 +848,7 @@  discard block
 block discarded – undo
848 848
     protected function renderTree($data)
849 849
     {
850 850
         $out = '';
851
-        if (!empty($data['#childNodes'])) {
851
+        if ( ! empty($data['#childNodes'])) {
852 852
             foreach ($data['#childNodes'] as $item) {
853 853
                 $out .= $this->renderTree($item);
854 854
             }
@@ -887,7 +887,7 @@  discard block
 block discarded – undo
887 887
     public function parseLang($tpl)
888 888
     {
889 889
         $this->debug->debug(array("parseLang" => $tpl), "parseLang", 2, array('html'));
890
-        if (is_scalar($tpl) && !empty($tpl)) {
890
+        if (is_scalar($tpl) && ! empty($tpl)) {
891 891
             if (preg_match_all("/\[\%([a-zA-Z0-9\.\_\-]+)\%\]/", $tpl, $match)) {
892 892
                 $langVal = array();
893 893
                 foreach ($match[1] as $item) {
@@ -958,7 +958,7 @@  discard block
 block discarded – undo
958 958
     {
959 959
         $out = $data;
960 960
         $docs = count($this->_docs) - $this->skippedDocs;
961
-        if ((($this->getCFGDef("noneWrapOuter", "1") && $docs == 0) || $docs > 0) && !empty($this->ownerTPL)) {
961
+        if ((($this->getCFGDef("noneWrapOuter", "1") && $docs == 0) || $docs > 0) && ! empty($this->ownerTPL)) {
962 962
             $this->debug->debug("", "renderWrapTPL", 2);
963 963
             $parse = true;
964 964
             $plh = array($this->getCFGDef("sysKey", "dl") . ".wrap" => $data);
@@ -981,7 +981,7 @@  discard block
 block discarded – undo
981 981
                 }
982 982
                 $plh = $params;
983 983
             }
984
-            if ($parse && !empty($this->ownerTPL)) {
984
+            if ($parse && ! empty($this->ownerTPL)) {
985 985
                 $this->debug->updateMessage(
986 986
                     array("render ownerTPL" => $this->ownerTPL, "With data" => print_r($plh, 1)),
987 987
                     "renderWrapTPL",
@@ -1120,10 +1120,10 @@  discard block
 block discarded – undo
1120 1120
         $introField = $this->getCFGDef("introField", $introField);
1121 1121
         $contentField = $this->getCFGDef("contentField", $contentField);
1122 1122
 
1123
-        if (!empty($introField) && !empty($item[$introField]) && mb_strlen($item[$introField], 'UTF-8') > 0) {
1123
+        if ( ! empty($introField) && ! empty($item[$introField]) && mb_strlen($item[$introField], 'UTF-8') > 0) {
1124 1124
             $out = $item[$introField];
1125 1125
         } else {
1126
-            if (!empty($contentField) && !empty($item[$contentField]) && mb_strlen($item[$contentField], 'UTF-8') > 0) {
1126
+            if ( ! empty($contentField) && ! empty($item[$contentField]) && mb_strlen($item[$contentField], 'UTF-8') > 0) {
1127 1127
                 $out = $extSummary->init($this, array(
1128 1128
                     "content"      => $item[$contentField],
1129 1129
                     "action"       => $this->getCFGDef("summary", ""),
@@ -1192,7 +1192,7 @@  discard block
 block discarded – undo
1192 1192
             $flag = true;
1193 1193
 
1194 1194
         } else {
1195
-            if (!class_exists($classname, false) && $classname != '') {
1195
+            if ( ! class_exists($classname, false) && $classname != '') {
1196 1196
                 if (file_exists(dirname(__FILE__) . "/extender/" . $name . ".extender.inc")) {
1197 1197
                     include_once(dirname(__FILE__) . "/extender/" . $name . ".extender.inc");
1198 1198
                 }
@@ -1202,7 +1202,7 @@  discard block
 block discarded – undo
1202 1202
                 $flag = true;
1203 1203
             }
1204 1204
         }
1205
-        if (!$flag) {
1205
+        if ( ! $flag) {
1206 1206
             $this->debug->debug("Error load Extender " . $this->debug->dumpData($name));
1207 1207
         }
1208 1208
         $this->debug->debugEnd('LoadExtender');
@@ -1260,7 +1260,7 @@  discard block
 block discarded – undo
1260 1260
         $this->debug->debug('clean IDs ' . $this->debug->dumpData($IDs) . ' with separator ' . $this->debug->dumpData($sep),
1261 1261
             'cleanIDs', 2);
1262 1262
         $out = array();
1263
-        if (!is_array($IDs)) {
1263
+        if ( ! is_array($IDs)) {
1264 1264
             $IDs = explode($sep, $IDs);
1265 1265
         }
1266 1266
         foreach ($IDs as $item) {
@@ -1296,7 +1296,7 @@  discard block
 block discarded – undo
1296 1296
     {
1297 1297
         $out = array();
1298 1298
         foreach ($this->_docs as $doc => $val) {
1299
-            if (isset($val[$userField]) && (($uniq && !in_array($val[$userField], $out)) || !$uniq)) {
1299
+            if (isset($val[$userField]) && (($uniq && ! in_array($val[$userField], $out)) || ! $uniq)) {
1300 1300
                 $out[$doc] = $val[$userField];
1301 1301
             }
1302 1302
         }
@@ -1385,7 +1385,7 @@  discard block
 block discarded – undo
1385 1385
                             $out['order'] = $tmp;
1386 1386
                         // no break
1387 1387
                     }
1388
-                    if ('' == $out['order'] || !in_array(strtoupper($out['order']), array('ASC', 'DESC'))) {
1388
+                    if ('' == $out['order'] || ! in_array(strtoupper($out['order']), array('ASC', 'DESC'))) {
1389 1389
                         $out['order'] = $orderDef; //Default
1390 1390
                     }
1391 1391
 
@@ -1476,21 +1476,21 @@  discard block
 block discarded – undo
1476 1476
         $children = array(); // children of each ID
1477 1477
         $ids = array();
1478 1478
         foreach ($data as $i => $r) {
1479
-            $row =& $data[$i];
1479
+            $row = & $data[$i];
1480 1480
             $id = $row[$idName];
1481 1481
             $pid = $row[$pidName];
1482
-            $children[$pid][$id] =& $row;
1483
-            if (!isset($children[$id])) {
1482
+            $children[$pid][$id] = & $row;
1483
+            if ( ! isset($children[$id])) {
1484 1484
                 $children[$id] = array();
1485 1485
             }
1486
-            $row['#childNodes'] =& $children[$id];
1486
+            $row['#childNodes'] = & $children[$id];
1487 1487
             $ids[$row[$idName]] = true;
1488 1488
         }
1489 1489
         // Root elements are elements with non-found PIDs.
1490 1490
         $this->_tree = array();
1491 1491
         foreach ($data as $i => $r) {
1492
-            $row =& $data[$i];
1493
-            if (!isset($ids[$row[$pidName]])) {
1492
+            $row = & $data[$i];
1493
+            if ( ! isset($ids[$row[$pidName]])) {
1494 1494
                 $this->_tree[$row[$idName]] = $row;
1495 1495
             }
1496 1496
         }
@@ -1531,7 +1531,7 @@  discard block
 block discarded – undo
1531 1531
         $this->debug->debug("getFilters: " . $this->debug->dumpData($filter_string), 'getFilter', 1);
1532 1532
         // the filter parameter tells us, which filters can be used in this query
1533 1533
         $filter_string = trim($filter_string, ' ;');
1534
-        if (!$filter_string) {
1534
+        if ( ! $filter_string) {
1535 1535
             return;
1536 1536
         }
1537 1537
         $output = array('join' => '', 'where' => '');
@@ -1544,7 +1544,7 @@  discard block
 block discarded – undo
1544 1544
                 $subfilters = $this->smartSplit($subfilters);
1545 1545
                 foreach ($subfilters as $subfilter) {
1546 1546
                     $subfilter = $this->getFilters(trim($subfilter));
1547
-                    if (!$subfilter) {
1547
+                    if ( ! $subfilter) {
1548 1548
                         continue;
1549 1549
                     }
1550 1550
                     if ($subfilter['join']) {
@@ -1554,14 +1554,14 @@  discard block
 block discarded – undo
1554 1554
                         $wheres[] = $subfilter['where'];
1555 1555
                     }
1556 1556
                 }
1557
-                $output['join'] = !empty($joins) ? implode(' ', $joins) : '';
1558
-                $output['where'] = !empty($wheres) ? '(' . implode($sql, $wheres) . ')' : '';
1557
+                $output['join'] = ! empty($joins) ? implode(' ', $joins) : '';
1558
+                $output['where'] = ! empty($wheres) ? '(' . implode($sql, $wheres) . ')' : '';
1559 1559
             }
1560 1560
         }
1561 1561
 
1562
-        if (!$logic_op_found) {
1562
+        if ( ! $logic_op_found) {
1563 1563
             $filter = $this->loadFilter($filter_string);
1564
-            if (!$filter) {
1564
+            if ( ! $filter) {
1565 1565
                 $this->debug->warning('Error while loading DocLister filter "' . $this->debug->dumpData($filter_string) . '": check syntax!');
1566 1566
                 $output = false;
1567 1567
             } else {
@@ -1633,7 +1633,7 @@  discard block
 block discarded – undo
1633 1633
         $fltr_params = explode(':', $filter, 2);
1634 1634
         $fltr = APIHelpers::getkey($fltr_params, 0, null);
1635 1635
         // check if the filter is implemented
1636
-        if (!is_null($fltr) && file_exists(dirname(__FILE__) . '/filter/' . $fltr . '.filter.php')) {
1636
+        if ( ! is_null($fltr) && file_exists(dirname(__FILE__) . '/filter/' . $fltr . '.filter.php')) {
1637 1637
             require_once dirname(__FILE__) . '/filter/' . $fltr . '.filter.php';
1638 1638
             /**
1639 1639
              * @var tv_DL_filter|content_DL_filter $fltr_class
Please login to merge, or discard this patch.
Braces   +284 added lines, -278 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (!defined('MODX_BASE_PATH')) {
2
+if (!defined('MODX_BASE_PATH')) {
3 3
     die('HACK???');
4 4
 }
5 5
 /**
@@ -20,8 +20,8 @@  discard block
 block discarded – undo
20 20
 /**
21 21
  * Class DocLister
22 22
  */
23
-abstract class DocLister
24
-{
23
+abstract class DocLister
24
+{
25 25
     /**
26 26
      * Ключ в массиве $_REQUEST в котором находится алиас запрашиваемого документа
27 27
      */
@@ -182,48 +182,48 @@  discard block
 block discarded – undo
182 182
      * @param int $startTime время запуска сниппета
183 183
      * @throws Exception
184 184
      */
185
-    public function __construct($modx, $cfg = array(), $startTime = null)
186
-    {
185
+    public function __construct($modx, $cfg = array(), $startTime = null)
186
+    {
187 187
         $this->setTimeStart($startTime);
188 188
 
189
-        if (extension_loaded('mbstring')) {
189
+        if (extension_loaded('mbstring')) {
190 190
             mb_internal_encoding("UTF-8");
191
-        } else {
191
+        } else {
192 192
             throw new Exception('Not found php extension mbstring');
193 193
         }
194 194
 
195
-        if ($modx instanceof DocumentParser) {
195
+        if ($modx instanceof DocumentParser) {
196 196
             $this->modx = $modx;
197 197
             $this->setDebug(1);
198 198
 
199
-            if (!is_array($cfg) || empty($cfg)) {
199
+            if (!is_array($cfg) || empty($cfg)) {
200 200
                 $cfg = $this->modx->Event->params;
201 201
             }
202
-        } else {
202
+        } else {
203 203
             throw new Exception('MODX var is not instaceof DocumentParser');
204 204
         }
205 205
 
206 206
         $this->FS = \Helpers\FS::getInstance();
207 207
         $this->config = new \Helpers\Config($cfg);
208 208
 
209
-        if (isset($cfg['config'])) {
209
+        if (isset($cfg['config'])) {
210 210
             $this->config->setPath(dirname(__DIR__))->loadConfig($cfg['config']);
211 211
         }
212 212
 
213
-        if ($this->config->setConfig($cfg) === false) {
213
+        if ($this->config->setConfig($cfg) === false) {
214 214
             throw new Exception('no parameters to run DocLister');
215 215
         }
216 216
 
217 217
         $this->loadLang(array('core', 'json'));
218 218
         $this->setDebug($this->getCFGDef('debug', 0));
219 219
 
220
-        if ($this->checkDL()) {
220
+        if ($this->checkDL()) {
221 221
             $cfg = array();
222 222
             $idType = $this->getCFGDef('idType', '');
223
-            if (empty($idType) && $this->getCFGDef('documents', '') != '') {
223
+            if (empty($idType) && $this->getCFGDef('documents', '') != '') {
224 224
                 $idType = 'documents';
225 225
             }
226
-            switch ($idType) {
226
+            switch ($idType) {
227 227
                 case 'documents':
228 228
                     $IDs = $this->getCFGDef('documents');
229 229
                     $cfg['idType'] = "documents";
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
                 case 'parents':
232 232
                 default:
233 233
                     $cfg['idType'] = "parents";
234
-                    if (($IDs = $this->getCFGDef('parents')) === null) {
234
+                    if (($IDs = $this->getCFGDef('parents')) === null) {
235 235
                         $IDs = $this->getCurrentMODXPageID();
236 236
                     }
237 237
                     break;
@@ -247,12 +247,12 @@  discard block
 block discarded – undo
247 247
 
248 248
         $this->setLocate();
249 249
 
250
-        if ($this->getCFGDef("customLang")) {
250
+        if ($this->getCFGDef("customLang")) {
251 251
             $this->getCustomLang();
252 252
         }
253 253
         $this->loadExtender($this->getCFGDef("extender", ""));
254 254
 
255
-        if ($this->checkExtender('request')) {
255
+        if ($this->checkExtender('request')) {
256 256
             $this->extender['request']->init($this, $this->getCFGDef("requestActive", ""));
257 257
         }
258 258
         $this->_filters = $this->getFilters($this->getCFGDef('filters', ''));
@@ -264,21 +264,21 @@  discard block
 block discarded – undo
264 264
      * @param string $str строка с фильтром
265 265
      * @return array массив субфильтров
266 266
      */
267
-    public function smartSplit($str)
268
-    {
267
+    public function smartSplit($str)
268
+    {
269 269
         $res = array();
270 270
         $cur = '';
271 271
         $open = 0;
272 272
         $strlen = mb_strlen($str, 'UTF-8');
273
-        for ($i = 0; $i <= $strlen; $i++) {
273
+        for ($i = 0; $i <= $strlen; $i++) {
274 274
             $e = mb_substr($str, $i, 1, 'UTF-8');
275
-            switch ($e) {
275
+            switch ($e) {
276 276
                 case ')':
277 277
                     $open--;
278
-                    if ($open == 0) {
278
+                    if ($open == 0) {
279 279
                         $res[] = $cur . ')';
280 280
                         $cur = '';
281
-                    } else {
281
+                    } else {
282 282
                         $cur .= $e;
283 283
                     }
284 284
                     break;
@@ -287,10 +287,10 @@  discard block
 block discarded – undo
287 287
                     $cur .= $e;
288 288
                     break;
289 289
                 case ';':
290
-                    if ($open == 0) {
290
+                    if ($open == 0) {
291 291
                         $res[] = $cur;
292 292
                         $cur = '';
293
-                    } else {
293
+                    } else {
294 294
                         $cur .= $e;
295 295
                     }
296 296
                     break;
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
             }
300 300
         }
301 301
         $cur = preg_replace("/(\))$/u", '', $cur);
302
-        if ($cur != '') {
302
+        if ($cur != '') {
303 303
             $res[] = $cur;
304 304
         }
305 305
 
@@ -310,8 +310,8 @@  discard block
 block discarded – undo
310 310
      * Трансформация объекта в строку
311 311
      * @return string последний ответ от DocLister'а
312 312
      */
313
-    public function __toString()
314
-    {
313
+    public function __toString()
314
+    {
315 315
         return $this->outData;
316 316
     }
317 317
 
@@ -319,8 +319,8 @@  discard block
 block discarded – undo
319 319
      * Установить время запуска сниппета
320 320
      * @param float|null $time
321 321
      */
322
-    public function setTimeStart($time = null)
323
-    {
322
+    public function setTimeStart($time = null)
323
+    {
324 324
         $this->_timeStart = is_null($time) ? microtime(true) : $time;
325 325
     }
326 326
 
@@ -329,8 +329,8 @@  discard block
 block discarded – undo
329 329
      *
330 330
      * @return int
331 331
      */
332
-    public function getTimeStart()
333
-    {
332
+    public function getTimeStart()
333
+    {
334 334
         return $this->_timeStart;
335 335
     }
336 336
 
@@ -338,27 +338,27 @@  discard block
 block discarded – undo
338 338
      * Установка режима отладки
339 339
      * @param int $flag режим отладки
340 340
      */
341
-    public function setDebug($flag = 0)
342
-    {
341
+    public function setDebug($flag = 0)
342
+    {
343 343
         $flag = abs((int)$flag);
344
-        if ($this->_debugMode != $flag) {
344
+        if ($this->_debugMode != $flag) {
345 345
             $this->_debugMode = $flag;
346 346
             $this->debug = null;
347
-            if ($this->_debugMode > 0) {
348
-                if (isset($_SESSION['usertype']) && $_SESSION['usertype'] == 'manager') {
347
+            if ($this->_debugMode > 0) {
348
+                if (isset($_SESSION['usertype']) && $_SESSION['usertype'] == 'manager') {
349 349
                     error_reporting(E_ALL ^ E_NOTICE);
350 350
                     ini_set('display_errors', 1);
351 351
                 }
352 352
                 $dir = dirname(dirname(__FILE__));
353
-                if (file_exists($dir . "/lib/DLdebug.class.php")) {
353
+                if (file_exists($dir . "/lib/DLdebug.class.php")) {
354 354
                     include_once($dir . "/lib/DLdebug.class.php");
355
-                    if (class_exists("DLdebug", false)) {
355
+                    if (class_exists("DLdebug", false)) {
356 356
                         $this->debug = new DLdebug($this);
357 357
                     }
358 358
                 }
359 359
             }
360 360
 
361
-            if (is_null($this->debug)) {
361
+            if (is_null($this->debug)) {
362 362
                 $this->debug = new xNop();
363 363
                 $this->_debugMode = 0;
364 364
                 error_reporting(0);
@@ -370,8 +370,8 @@  discard block
 block discarded – undo
370 370
     /**
371 371
      * Информация о режиме отладки
372 372
      */
373
-    public function getDebug()
374
-    {
373
+    public function getDebug()
374
+    {
375 375
         return $this->_debugMode;
376 376
     }
377 377
 
@@ -382,13 +382,13 @@  discard block
 block discarded – undo
382 382
      * @param string $alias желаемый алиас таблицы
383 383
      * @return string имя таблицы с префиксом и алиасом
384 384
      */
385
-    public function getTable($name, $alias = '')
386
-    {
387
-        if (!isset($this->_table[$name])) {
385
+    public function getTable($name, $alias = '')
386
+    {
387
+        if (!isset($this->_table[$name])) {
388 388
             $this->_table[$name] = $this->modx->getFullTableName($name);
389 389
         }
390 390
         $table = $this->_table[$name];
391
-        if (!empty($alias) && is_scalar($alias)) {
391
+        if (!empty($alias) && is_scalar($alias)) {
392 392
             $table .= " as `" . $alias . "`";
393 393
         }
394 394
 
@@ -401,9 +401,9 @@  discard block
 block discarded – undo
401 401
      * @param $alias
402 402
      * @return mixed
403 403
      */
404
-    public function TableAlias($name, $table, $alias)
405
-    {
406
-        if (!$this->checkTableAlias($name, $table)) {
404
+    public function TableAlias($name, $table, $alias)
405
+    {
406
+        if (!$this->checkTableAlias($name, $table)) {
407 407
             $this->AddTable[$table][$name] = $alias;
408 408
         }
409 409
 
@@ -415,8 +415,8 @@  discard block
 block discarded – undo
415 415
      * @param $table
416 416
      * @return bool
417 417
      */
418
-    public function checkTableAlias($name, $table)
419
-    {
418
+    public function checkTableAlias($name, $table)
419
+    {
420 420
         return isset($this->AddTable[$table][$name]);
421 421
     }
422 422
 
@@ -428,8 +428,8 @@  discard block
 block discarded – undo
428 428
      * @param bool $nop создавать ли пустой объект запрашиваемого типа
429 429
      * @return array|mixed|xNop
430 430
      */
431
-    public function jsonDecode($json, $config = array(), $nop = false)
432
-    {
431
+    public function jsonDecode($json, $config = array(), $nop = false)
432
+    {
433 433
         $this->debug->debug('Decode JSON: ' . $this->debug->dumpData($json) . "\r\nwith config: " . $this->debug->dumpData($config),
434 434
             'jsonDecode', 2);
435 435
         $config = jsonHelper::jsonDecode($json, $config, $nop);
@@ -445,10 +445,10 @@  discard block
 block discarded – undo
445 445
      * @param $json string строка с JSON для записи в лог при отладке
446 446
      * @return bool|string
447 447
      */
448
-    public function isErrorJSON($json)
449
-    {
448
+    public function isErrorJSON($json)
449
+    {
450 450
         $error = jsonHelper::json_last_error_msg();
451
-        if (!in_array($error, array('error_none', 'other'))) {
451
+        if (!in_array($error, array('error_none', 'other'))) {
452 452
             $this->debug->error($this->getMsg('json.' . $error) . ": " . $this->debug->dumpData($json, 'code'), 'JSON');
453 453
             $error = true;
454 454
         }
@@ -460,20 +460,20 @@  discard block
 block discarded – undo
460 460
      * Проверка параметров и загрузка необходимых экстендеров
461 461
      * return boolean статус загрузки
462 462
      */
463
-    public function checkDL()
464
-    {
463
+    public function checkDL()
464
+    {
465 465
         $this->debug->debug('Check DocLister parameters', 'checkDL', 2);
466 466
         $flag = true;
467 467
         $extenders = $this->getCFGDef('extender', '');
468 468
         $extenders = explode(",", $extenders);
469 469
         $tmp = $this->getCFGDef('requestActive', '') != '' || in_array('request', $extenders);
470
-        if ($tmp && !$this->_loadExtender('request')) {
470
+        if ($tmp && !$this->_loadExtender('request')) {
471 471
             //OR request in extender's parameter
472 472
             throw new Exception('Error load request extender');
473 473
         }
474 474
 
475 475
         $tmp = $this->getCFGDef('summary', '') != '' || in_array('summary', $extenders);
476
-        if ($tmp && !$this->_loadExtender('summary')) {
476
+        if ($tmp && !$this->_loadExtender('summary')) {
477 477
             //OR summary in extender's parameter
478 478
             throw new Exception('Error load summary extender');
479 479
         }
@@ -486,15 +486,15 @@  discard block
 block discarded – undo
486 486
                 $this->getCFGDef('pageLimit', '') != '' || $this->getCFGDef('pageAdjacents', '') != '' ||
487 487
                 $this->getCFGDef('PaginateClass', '') != '' || $this->getCFGDef('TplNextP', '') != ''
488 488
             ) && !$this->_loadExtender('paginate')
489
-        ) {
489
+        ) {
490 490
             throw new Exception('Error load paginate extender');
491
-        } else {
492
-            if ((int)$this->getCFGDef('display', 0) == 0) {
491
+        } else {
492
+            if ((int)$this->getCFGDef('display', 0) == 0) {
493 493
                 $extenders = $this->unsetArrayVal($extenders, 'paginate');
494 494
             }
495 495
         }
496 496
 
497
-        if ($this->getCFGDef('prepare', '') != '' || $this->getCFGDef('prepareWrap') != '') {
497
+        if ($this->getCFGDef('prepare', '') != '' || $this->getCFGDef('prepareWrap') != '') {
498 498
             $this->_loadExtender('prepare');
499 499
         }
500 500
 
@@ -511,14 +511,14 @@  discard block
 block discarded – undo
511 511
      * @param mixed $val значение которые необходимо удалить из массива
512 512
      * @return array отчищеный массив с данными
513 513
      */
514
-    private function unsetArrayVal($data, $val)
515
-    {
514
+    private function unsetArrayVal($data, $val)
515
+    {
516 516
         $out = array();
517
-        if (is_array($data)) {
518
-            foreach ($data as $item) {
519
-                if ($item != $val) {
517
+        if (is_array($data)) {
518
+            foreach ($data as $item) {
519
+                if ($item != $val) {
520 520
                     $out[] = $item;
521
-                } else {
521
+                } else {
522 522
                     continue;
523 523
                 }
524 524
             }
@@ -533,14 +533,14 @@  discard block
 block discarded – undo
533 533
      * @param int $id уникальный идентификатор страницы
534 534
      * @return string URL страницы
535 535
      */
536
-    public function getUrl($id = 0)
537
-    {
536
+    public function getUrl($id = 0)
537
+    {
538 538
         $id = ((int)$id > 0) ? (int)$id : $this->getCurrentMODXPageID();
539 539
 
540 540
         $link = $this->checkExtender('request') ? $this->extender['request']->getLink() : $this->getRequest();
541
-        if ($id == $this->modx->config['site_start']) {
541
+        if ($id == $this->modx->config['site_start']) {
542 542
             $url = $this->modx->config['site_url'] . ($link != '' ? "?{$link}" : "");
543
-        } else {
543
+        } else {
544 544
             $url = $this->modx->makeUrl($id, '', $link, $this->getCFGDef('urlScheme', ''));
545 545
         }
546 546
 
@@ -568,16 +568,16 @@  discard block
 block discarded – undo
568 568
      * @param string $tpl шаблон
569 569
      * @return string
570 570
      */
571
-    public function render($tpl = '')
572
-    {
571
+    public function render($tpl = '')
572
+    {
573 573
         $this->debug->debug(array('Render data with template ' => $tpl), 'render', 2, array('html'));
574 574
         $out = '';
575
-        if (1 == $this->getCFGDef('tree', '0')) {
576
-            foreach ($this->_tree as $item) {
575
+        if (1 == $this->getCFGDef('tree', '0')) {
576
+            foreach ($this->_tree as $item) {
577 577
                 $out .= $this->renderTree($item);
578 578
             }
579 579
             $out = $this->renderWrap($out);
580
-        } else {
580
+        } else {
581 581
             $out = $this->_render($tpl);
582 582
         }
583 583
 
@@ -596,8 +596,8 @@  discard block
 block discarded – undo
596 596
      *
597 597
      * @return int
598 598
      */
599
-    public function getCurrentMODXPageID()
600
-    {
599
+    public function getCurrentMODXPageID()
600
+    {
601 601
         $id = isset($this->modx->documentIdentifier) ? (int)$this->modx->documentIdentifier : 0;
602 602
         $docData = isset($this->modx->documentObject) ? $this->modx->documentObject : array();
603 603
 
@@ -613,9 +613,9 @@  discard block
 block discarded – undo
613 613
      * @param integer $line error on line
614 614
      * @param array $trace stack trace
615 615
      */
616
-    public function ErrorLogger($message, $code, $file, $line, $trace)
617
-    {
618
-        if (abs($this->getCFGDef('debug', '0')) == '1') {
616
+    public function ErrorLogger($message, $code, $file, $line, $trace)
617
+    {
618
+        if (abs($this->getCFGDef('debug', '0')) == '1') {
619 619
             $out = "CODE #" . $code . "<br />";
620 620
             $out .= "on file: " . $file . ":" . $line . "<br />";
621 621
             $out .= "<pre>";
@@ -632,8 +632,8 @@  discard block
 block discarded – undo
632 632
      *
633 633
      * @return DocumentParser
634 634
      */
635
-    public function getMODX()
636
-    {
635
+    public function getMODX()
636
+    {
637 637
         return $this->modx;
638 638
     }
639 639
 
@@ -644,13 +644,13 @@  discard block
 block discarded – undo
644 644
      * @return boolean status load extenders
645 645
      * @throws Exception
646 646
      */
647
-    public function loadExtender($ext = '')
648
-    {
647
+    public function loadExtender($ext = '')
648
+    {
649 649
         $out = true;
650
-        if ($ext != '') {
650
+        if ($ext != '') {
651 651
             $ext = explode(",", $ext);
652
-            foreach ($ext as $item) {
653
-                if ($item != '' && !$this->_loadExtender($item)) {
652
+            foreach ($ext as $item) {
653
+                if ($item != '' && !$this->_loadExtender($item)) {
654 654
                     throw new Exception('Error load ' . APIHelpers::e($item) . ' extender');
655 655
                 }
656 656
             }
@@ -666,8 +666,8 @@  discard block
 block discarded – undo
666 666
      * @param mixed $def значение по умолчанию, если в конфиге нет искомого параметра
667 667
      * @return mixed значение из конфига
668 668
      */
669
-    public function getCFGDef($name, $def = null)
670
-    {
669
+    public function getCFGDef($name, $def = null)
670
+    {
671 671
         return $this->config->getCFGDef($name, $def);
672 672
     }
673 673
 
@@ -679,15 +679,15 @@  discard block
 block discarded – undo
679 679
      * @param string $key ключ локального плейсхолдера
680 680
      * @return string
681 681
      */
682
-    public function toPlaceholders($data, $set = 0, $key = 'contentPlaceholder')
683
-    {
682
+    public function toPlaceholders($data, $set = 0, $key = 'contentPlaceholder')
683
+    {
684 684
         $this->debug->debug(null, 'toPlaceholders', 2);
685
-        if ($set == 0) {
685
+        if ($set == 0) {
686 686
             $set = $this->getCFGDef('contentPlaceholder', 0);
687 687
         }
688 688
         $this->_plh[$key] = $data;
689 689
         $id = $this->getCFGDef('id', '');
690
-        if ($id != '') {
690
+        if ($id != '') {
691 691
             $id .= ".";
692 692
         }
693 693
         $out = DLTemplate::getInstance($this->getMODX())->toPlaceholders($data, $set, $key, $id);
@@ -709,14 +709,14 @@  discard block
 block discarded – undo
709 709
      * @param boolean $quote заключать ли данные на выходе в кавычки
710 710
      * @return string обработанная строка
711 711
      */
712
-    public function sanitarIn($data, $sep = ',', $quote = true)
713
-    {
714
-        if (!is_array($data)) {
712
+    public function sanitarIn($data, $sep = ',', $quote = true)
713
+    {
714
+        if (!is_array($data)) {
715 715
             $data = explode($sep, $data);
716 716
         }
717 717
         $out = array();
718
-        foreach ($data as $item) {
719
-            if ($item !== '') {
718
+        foreach ($data as $item) {
719
+            if ($item !== '') {
720 720
                 $out[] = $this->modx->db->escape($item);
721 721
             }
722 722
         }
@@ -737,12 +737,12 @@  discard block
 block discarded – undo
737 737
      * @param string $lang имя языкового пакета
738 738
      * @return array
739 739
      */
740
-    public function getCustomLang($lang = '')
741
-    {
742
-        if (empty($lang)) {
740
+    public function getCustomLang($lang = '')
741
+    {
742
+        if (empty($lang)) {
743 743
             $lang = $this->getCFGDef('lang', $this->modx->config['manager_language']);
744 744
         }
745
-        if (file_exists(dirname(dirname(__FILE__)) . "/lang/" . $lang . ".php")) {
745
+        if (file_exists(dirname(dirname(__FILE__)) . "/lang/" . $lang . ".php")) {
746 746
             $tmp = include(dirname(__FILE__) . "/lang/" . $lang . ".php");
747 747
             $this->_customLang = is_array($tmp) ? $tmp : array();
748 748
         }
@@ -758,25 +758,25 @@  discard block
 block discarded – undo
758 758
      * @param boolean $rename Переименовывать ли элементы массива
759 759
      * @return array массив с лексиконом
760 760
      */
761
-    public function loadLang($name = 'core', $lang = '', $rename = true)
762
-    {
763
-        if (empty($lang)) {
761
+    public function loadLang($name = 'core', $lang = '', $rename = true)
762
+    {
763
+        if (empty($lang)) {
764 764
             $lang = $this->getCFGDef('lang', $this->modx->config['manager_language']);
765 765
         }
766 766
 
767 767
         $this->debug->debug('Load language ' . $this->debug->dumpData($name) . "." . $this->debug->dumpData($lang),
768 768
             'loadlang', 2);
769
-        if (is_scalar($name)) {
769
+        if (is_scalar($name)) {
770 770
             $name = array($name);
771 771
         }
772
-        foreach ($name as $n) {
773
-            if (file_exists(dirname(__FILE__) . "/lang/" . $lang . "/" . $n . ".inc.php")) {
772
+        foreach ($name as $n) {
773
+            if (file_exists(dirname(__FILE__) . "/lang/" . $lang . "/" . $n . ".inc.php")) {
774 774
                 $tmp = include(dirname(__FILE__) . "/lang/" . $lang . "/" . $n . ".inc.php");
775
-                if (is_array($tmp)) {
775
+                if (is_array($tmp)) {
776 776
                     /**
777 777
                      * Переименовыываем элементы массива из array('test'=>'data') в array('name.test'=>'data')
778 778
                      */
779
-                    if ($rename) {
779
+                    if ($rename) {
780 780
                         $tmp = $this->renameKeyArr($tmp, $n, '', '.');
781 781
                     }
782 782
                     $this->_lang = array_merge($this->_lang, $tmp);
@@ -795,11 +795,11 @@  discard block
 block discarded – undo
795 795
      * @param string $def Строка по умолчанию, если запись в языковом пакете не будет обнаружена
796 796
      * @return string строка в соответствии с текущими языковыми настройками
797 797
      */
798
-    public function getMsg($name, $def = '')
799
-    {
800
-        if (isset($this->_customLang[$name])) {
798
+    public function getMsg($name, $def = '')
799
+    {
800
+        if (isset($this->_customLang[$name])) {
801 801
             $say = $this->_customLang[$name];
802
-        } else {
802
+        } else {
803 803
             $say = \APIHelpers::getkey($this->_lang, $name, $def);
804 804
         }
805 805
 
@@ -815,8 +815,8 @@  discard block
 block discarded – undo
815 815
      * @param string $sep разделитель суффиксов, префиксов и ключей массива
816 816
      * @return array массив с переименованными ключами
817 817
      */
818
-    public function renameKeyArr($data, $prefix = '', $suffix = '', $sep = '.')
819
-    {
818
+    public function renameKeyArr($data, $prefix = '', $suffix = '', $sep = '.')
819
+    {
820 820
         return \APIHelpers::renameKeyArr($data, $prefix, $suffix, $sep);
821 821
     }
822 822
 
@@ -826,12 +826,12 @@  discard block
 block discarded – undo
826 826
      * @param string $locale локаль
827 827
      * @return string имя установленной локали
828 828
      */
829
-    public function setLocate($locale = '')
830
-    {
831
-        if ('' == $locale) {
829
+    public function setLocate($locale = '')
830
+    {
831
+        if ('' == $locale) {
832 832
             $locale = $this->getCFGDef('locale', '');
833 833
         }
834
-        if ('' != $locale) {
834
+        if ('' != $locale) {
835 835
             setlocale(LC_ALL, $locale);
836 836
         }
837 837
 
@@ -845,11 +845,11 @@  discard block
 block discarded – undo
845 845
      * @param array $data массив сформированный как дерево
846 846
      * @return string строка для отображения пользователю
847 847
      */
848
-    protected function renderTree($data)
849
-    {
848
+    protected function renderTree($data)
849
+    {
850 850
         $out = '';
851
-        if (!empty($data['#childNodes'])) {
852
-            foreach ($data['#childNodes'] as $item) {
851
+        if (!empty($data['#childNodes'])) {
852
+            foreach ($data['#childNodes'] as $item) {
853 853
                 $out .= $this->renderTree($item);
854 854
             }
855 855
         }
@@ -866,8 +866,8 @@  discard block
 block discarded – undo
866 866
      * @param string $name Template: chunk name || @CODE: template || @FILE: file with template
867 867
      * @return string html template with placeholders without data
868 868
      */
869
-    private function _getChunk($name)
870
-    {
869
+    private function _getChunk($name)
870
+    {
871 871
         $this->debug->debug(array('Get chunk by name' => $name), "getChunk", 2, array('html'));
872 872
         //without trim
873 873
         $tpl = DLTemplate::getInstance($this->getMODX())->getChunk($name);
@@ -884,18 +884,18 @@  discard block
 block discarded – undo
884 884
      * @param string $tpl HTML шаблон
885 885
      * @return string
886 886
      */
887
-    public function parseLang($tpl)
888
-    {
887
+    public function parseLang($tpl)
888
+    {
889 889
         $this->debug->debug(array("parseLang" => $tpl), "parseLang", 2, array('html'));
890
-        if (is_scalar($tpl) && !empty($tpl)) {
891
-            if (preg_match_all("/\[\%([a-zA-Z0-9\.\_\-]+)\%\]/", $tpl, $match)) {
890
+        if (is_scalar($tpl) && !empty($tpl)) {
891
+            if (preg_match_all("/\[\%([a-zA-Z0-9\.\_\-]+)\%\]/", $tpl, $match)) {
892 892
                 $langVal = array();
893
-                foreach ($match[1] as $item) {
893
+                foreach ($match[1] as $item) {
894 894
                     $langVal[] = $this->getMsg($item);
895 895
                 }
896 896
                 $tpl = str_replace($match[0], $langVal, $tpl);
897 897
             }
898
-        } else {
898
+        } else {
899 899
             $tpl = '';
900 900
         }
901 901
         $this->debug->debugEnd("parseLang");
@@ -911,20 +911,24 @@  discard block
 block discarded – undo
911 911
      * @param bool $parseDocumentSource render html template via DocumentParser::parseDocumentSource()
912 912
      * @return string html template with data without placeholders
913 913
      */
914
-    public function parseChunk($name, $data, $parseDocumentSource = false)
915
-    {
914
+    public function parseChunk($name, $data, $parseDocumentSource = false)
915
+    {
916 916
         $this->debug->debug(
917 917
             array("parseChunk" => $name, "With data" => print_r($data, 1)),
918 918
             "parseChunk",
919 919
             2, array('html', null)
920 920
         );
921 921
         $DLTemplate = DLTemplate::getInstance($this->getMODX());
922
-        if ($path = $this->getCFGDef('templatePath')) $DLTemplate->setTemplatePath($path);
923
-        if ($ext = $this->getCFGDef('templateExtension')) $DLTemplate->setTemplateExtension($ext);
922
+        if ($path = $this->getCFGDef('templatePath')) {
923
+            $DLTemplate->setTemplatePath($path);
924
+        }
925
+        if ($ext = $this->getCFGDef('templateExtension')) {
926
+            $DLTemplate->setTemplateExtension($ext);
927
+        }
924 928
         $DLTemplate->setTwigTemplateVars(array('DocLister'=>$this));
925 929
         $out = $DLTemplate->parseChunk($name, $data, $parseDocumentSource);
926 930
         $out = $this->parseLang($out);
927
-        if (empty($out)) {
931
+        if (empty($out)) {
928 932
             $this->debug->debug("Empty chunk: " . $this->debug->dumpData($name), '', 2);
929 933
         }
930 934
         $this->debug->debugEnd("parseChunk");
@@ -940,8 +944,8 @@  discard block
 block discarded – undo
940 944
      *
941 945
      * @return string html template from parameter
942 946
      */
943
-    public function getChunkByParam($name, $val = '')
944
-    {
947
+    public function getChunkByParam($name, $val = '')
948
+    {
945 949
         $data = $this->getCFGDef($name, $val);
946 950
         $data = $this->_getChunk($data);
947 951
 
@@ -954,11 +958,11 @@  discard block
 block discarded – undo
954 958
      * @param string $data html код который нужно обернуть в ownerTPL
955 959
      * @return string результатирующий html код
956 960
      */
957
-    public function renderWrap($data)
958
-    {
961
+    public function renderWrap($data)
962
+    {
959 963
         $out = $data;
960 964
         $docs = count($this->_docs) - $this->skippedDocs;
961
-        if ((($this->getCFGDef("noneWrapOuter", "1") && $docs == 0) || $docs > 0) && !empty($this->ownerTPL)) {
965
+        if ((($this->getCFGDef("noneWrapOuter", "1") && $docs == 0) || $docs > 0) && !empty($this->ownerTPL)) {
962 966
             $this->debug->debug("", "renderWrapTPL", 2);
963 967
             $parse = true;
964 968
             $plh = array($this->getCFGDef("sysKey", "dl") . ".wrap" => $data);
@@ -966,7 +970,7 @@  discard block
 block discarded – undo
966 970
              * @var $extPrepare prepare_DL_Extender
967 971
              */
968 972
             $extPrepare = $this->getExtender('prepare');
969
-            if ($extPrepare) {
973
+            if ($extPrepare) {
970 974
                 $params = $extPrepare->init($this, array(
971 975
                     'data'      => array(
972 976
                         'docs'         => $this->_docs,
@@ -975,13 +979,13 @@  discard block
 block discarded – undo
975 979
                     'nameParam' => 'prepareWrap',
976 980
                     'return'    => 'placeholders'
977 981
                 ));
978
-                if (is_bool($params) && $params === false) {
982
+                if (is_bool($params) && $params === false) {
979 983
                     $out = $data;
980 984
                     $parse = false;
981 985
                 }
982 986
                 $plh = $params;
983 987
             }
984
-            if ($parse && !empty($this->ownerTPL)) {
988
+            if ($parse && !empty($this->ownerTPL)) {
985 989
                 $this->debug->updateMessage(
986 990
                     array("render ownerTPL" => $this->ownerTPL, "With data" => print_r($plh, 1)),
987 991
                     "renderWrapTPL",
@@ -989,7 +993,7 @@  discard block
 block discarded – undo
989 993
                 );
990 994
                 $out = $this->parseChunk($this->ownerTPL, $plh);
991 995
             }
992
-            if (empty($this->ownerTPL)) {
996
+            if (empty($this->ownerTPL)) {
993 997
                 $this->debug->updateMessage("empty ownerTPL", "renderWrapTPL");
994 998
             }
995 999
             $this->debug->debugEnd("renderWrapTPL");
@@ -1005,8 +1009,8 @@  discard block
 block discarded – undo
1005 1009
      * @param int $i номер итерации в цикле
1006 1010
      * @return array массив с данными которые можно использовать в цикле render метода
1007 1011
      */
1008
-    protected function uniformPrepare(&$data, $i = 0)
1009
-    {
1012
+    protected function uniformPrepare(&$data, $i = 0)
1013
+    {
1010 1014
         $class = array();
1011 1015
 
1012 1016
         $iterationName = ($i % 2 == 1) ? 'Odd' : 'Even';
@@ -1020,20 +1024,20 @@  discard block
 block discarded – undo
1020 1024
             "dl") . '.full_iteration'] = ($this->extPaginate) ? ($i + $this->getCFGDef('display',
1021 1025
                 0) * ($this->extPaginate->currentPage() - 1)) : $i;
1022 1026
 
1023
-        if ($i == 1) {
1027
+        if ($i == 1) {
1024 1028
             $this->renderTPL = $this->getCFGDef('tplFirst', $this->renderTPL);
1025 1029
             $class[] = $this->getCFGDef('firstClass', 'first');
1026 1030
         }
1027
-        if ($i == (count($this->_docs) - $this->skippedDocs)) {
1031
+        if ($i == (count($this->_docs) - $this->skippedDocs)) {
1028 1032
             $this->renderTPL = $this->getCFGDef('tplLast', $this->renderTPL);
1029 1033
             $class[] = $this->getCFGDef('lastClass', 'last');
1030 1034
         }
1031
-        if ($this->modx->documentIdentifier == $data['id']) {
1035
+        if ($this->modx->documentIdentifier == $data['id']) {
1032 1036
             $this->renderTPL = $this->getCFGDef('tplCurrent', $this->renderTPL);
1033 1037
             $data[$this->getCFGDef("sysKey",
1034 1038
                 "dl") . '.active'] = 1; //[+active+] - 1 if $modx->documentIdentifer equal ID this element
1035 1039
             $class[] = $this->getCFGDef('currentClass', 'current');
1036
-        } else {
1040
+        } else {
1037 1041
             $data[$this->getCFGDef("sysKey", "dl") . '.active'] = 0;
1038 1042
         }
1039 1043
 
@@ -1044,8 +1048,8 @@  discard block
 block discarded – undo
1044 1048
          * @var $extE e_DL_Extender
1045 1049
          */
1046 1050
         $extE = $this->getExtender('e', true, true);
1047
-        if ($out = $extE->init($this, compact('data'))) {
1048
-            if (is_array($out)) {
1051
+        if ($out = $extE->init($this, compact('data'))) {
1052
+            if (is_array($out)) {
1049 1053
                 $data = $out;
1050 1054
             }
1051 1055
         }
@@ -1061,42 +1065,43 @@  discard block
 block discarded – undo
1061 1065
      * @param array $array данные которые необходимо примешать к ответу на каждой записи $data
1062 1066
      * @return string JSON строка
1063 1067
      */
1064
-    public function getJSON($data, $fields, $array = array())
1065
-    {
1068
+    public function getJSON($data, $fields, $array = array())
1069
+    {
1066 1070
         $out = array();
1067 1071
         $fields = is_array($fields) ? $fields : explode(",", $fields);
1068
-        if (is_array($array) && count($array) > 0) {
1072
+        if (is_array($array) && count($array) > 0) {
1069 1073
             $tmp = array();
1070
-            foreach ($data as $i => $v) { //array_merge not valid work with integer index key
1074
+            foreach ($data as $i => $v) {
1075
+//array_merge not valid work with integer index key
1071 1076
                 $tmp[$i] = (isset($array[$i]) ? array_merge($v, $array[$i]) : $v);
1072 1077
             }
1073 1078
             $data = $tmp;
1074 1079
         }
1075 1080
 
1076
-        foreach ($data as $num => $doc) {
1081
+        foreach ($data as $num => $doc) {
1077 1082
             $tmp = array();
1078
-            foreach ($doc as $name => $value) {
1079
-                if (in_array($name, $fields) || (isset($fields[0]) && $fields[0] == '1')) {
1083
+            foreach ($doc as $name => $value) {
1084
+                if (in_array($name, $fields) || (isset($fields[0]) && $fields[0] == '1')) {
1080 1085
                     $tmp[str_replace(".", "_", $name)] = $value; //JSON element name without dot
1081 1086
                 }
1082 1087
             }
1083 1088
             $out[$num] = $tmp;
1084 1089
         }
1085 1090
 
1086
-        if ('new' == $this->getCFGDef('JSONformat', 'old')) {
1091
+        if ('new' == $this->getCFGDef('JSONformat', 'old')) {
1087 1092
             $return = array();
1088 1093
 
1089 1094
             $return['rows'] = array();
1090
-            foreach ($out as $key => $item) {
1095
+            foreach ($out as $key => $item) {
1091 1096
                 $return['rows'][] = APIHelpers::getkey($item, $key, $item);
1092 1097
             }
1093 1098
             $return['total'] = $this->getChildrenCount();
1094
-        }elseif ('simple' == $this->getCFGDef('JSONformat', 'old')) {
1099
+        } elseif ('simple' == $this->getCFGDef('JSONformat', 'old')) {
1095 1100
             $return = array();
1096
-            foreach ($out as $key => $item) {
1101
+            foreach ($out as $key => $item) {
1097 1102
                 $return[] = APIHelpers::getkey($item, $key, $item);
1098 1103
             }
1099
-        } else {
1104
+        } else {
1100 1105
             $return = $out;
1101 1106
         }
1102 1107
         $this->outData = json_encode($return);
@@ -1112,11 +1117,11 @@  discard block
 block discarded – undo
1112 1117
      * @param string $contentField
1113 1118
      * @return mixed|string
1114 1119
      */
1115
-    protected function getSummary(array $item = array(), $extSummary = null, $introField = '', $contentField = '')
1116
-    {
1120
+    protected function getSummary(array $item = array(), $extSummary = null, $introField = '', $contentField = '')
1121
+    {
1117 1122
         $out = '';
1118 1123
 
1119
-        if (is_null($extSummary)) {
1124
+        if (is_null($extSummary)) {
1120 1125
             /**
1121 1126
              * @var $extSummary summary_DL_Extender
1122 1127
              */
@@ -1125,10 +1130,10 @@  discard block
 block discarded – undo
1125 1130
         $introField = $this->getCFGDef("introField", $introField);
1126 1131
         $contentField = $this->getCFGDef("contentField", $contentField);
1127 1132
 
1128
-        if (!empty($introField) && !empty($item[$introField]) && mb_strlen($item[$introField], 'UTF-8') > 0) {
1133
+        if (!empty($introField) && !empty($item[$introField]) && mb_strlen($item[$introField], 'UTF-8') > 0) {
1129 1134
             $out = $item[$introField];
1130
-        } else {
1131
-            if (!empty($contentField) && !empty($item[$contentField]) && mb_strlen($item[$contentField], 'UTF-8') > 0) {
1135
+        } else {
1136
+            if (!empty($contentField) && !empty($item[$contentField]) && mb_strlen($item[$contentField], 'UTF-8') > 0) {
1132 1137
                 $out = $extSummary->init($this, array(
1133 1138
                     "content"      => $item[$contentField],
1134 1139
                     "action"       => $this->getCFGDef("summary", ""),
@@ -1146,8 +1151,8 @@  discard block
 block discarded – undo
1146 1151
      * @param string $name extender name
1147 1152
      * @return boolean status extender load
1148 1153
      */
1149
-    public function checkExtender($name)
1150
-    {
1154
+    public function checkExtender($name)
1155
+    {
1151 1156
         return (isset($this->extender[$name]) && $this->extender[$name] instanceof $name . "_DL_Extender");
1152 1157
     }
1153 1158
 
@@ -1155,8 +1160,8 @@  discard block
 block discarded – undo
1155 1160
      * @param $name
1156 1161
      * @param $obj
1157 1162
      */
1158
-    public function setExtender($name, $obj)
1159
-    {
1163
+    public function setExtender($name, $obj)
1164
+    {
1160 1165
         $this->extender[$name] = $obj;
1161 1166
     }
1162 1167
 
@@ -1168,13 +1173,13 @@  discard block
 block discarded – undo
1168 1173
      * @param bool $nop если экстендер не загружен, то загружать ли xNop
1169 1174
      * @return null|xNop
1170 1175
      */
1171
-    public function getExtender($name, $autoload = false, $nop = false)
1172
-    {
1176
+    public function getExtender($name, $autoload = false, $nop = false)
1177
+    {
1173 1178
         $out = null;
1174
-        if ((is_scalar($name) && $this->checkExtender($name)) || ($autoload && $this->_loadExtender($name))) {
1179
+        if ((is_scalar($name) && $this->checkExtender($name)) || ($autoload && $this->_loadExtender($name))) {
1175 1180
             $out = $this->extender[$name];
1176 1181
         }
1177
-        if ($nop && is_null($out)) {
1182
+        if ($nop && is_null($out)) {
1178 1183
             $out = new xNop();
1179 1184
         }
1180 1185
 
@@ -1187,27 +1192,27 @@  discard block
 block discarded – undo
1187 1192
      * @param string $name name extender
1188 1193
      * @return boolean $flag status load extender
1189 1194
      */
1190
-    protected function _loadExtender($name)
1191
-    {
1195
+    protected function _loadExtender($name)
1196
+    {
1192 1197
         $this->debug->debug('Load Extender ' . $this->debug->dumpData($name), 'LoadExtender', 2);
1193 1198
         $flag = false;
1194 1199
 
1195 1200
         $classname = ($name != '') ? $name . "_DL_Extender" : "";
1196
-        if ($classname != '' && isset($this->extender[$name]) && $this->extender[$name] instanceof $classname) {
1201
+        if ($classname != '' && isset($this->extender[$name]) && $this->extender[$name] instanceof $classname) {
1197 1202
             $flag = true;
1198 1203
 
1199
-        } else {
1200
-            if (!class_exists($classname, false) && $classname != '') {
1201
-                if (file_exists(dirname(__FILE__) . "/extender/" . $name . ".extender.inc")) {
1204
+        } else {
1205
+            if (!class_exists($classname, false) && $classname != '') {
1206
+                if (file_exists(dirname(__FILE__) . "/extender/" . $name . ".extender.inc")) {
1202 1207
                     include_once(dirname(__FILE__) . "/extender/" . $name . ".extender.inc");
1203 1208
                 }
1204 1209
             }
1205
-            if (class_exists($classname, false) && $classname != '') {
1210
+            if (class_exists($classname, false) && $classname != '') {
1206 1211
                 $this->extender[$name] = new $classname($this, $name);
1207 1212
                 $flag = true;
1208 1213
             }
1209 1214
         }
1210
-        if (!$flag) {
1215
+        if (!$flag) {
1211 1216
             $this->debug->debug("Error load Extender " . $this->debug->dumpData($name));
1212 1217
         }
1213 1218
         $this->debug->debugEnd('LoadExtender');
@@ -1225,16 +1230,16 @@  discard block
 block discarded – undo
1225 1230
      * @param mixed $IDs список id документов по которым необходима выборка
1226 1231
      * @return array очищенный массив
1227 1232
      */
1228
-    public function setIDs($IDs)
1229
-    {
1233
+    public function setIDs($IDs)
1234
+    {
1230 1235
         $this->debug->debug('set ID list ' . $this->debug->dumpData($IDs), 'setIDs', 2);
1231 1236
         $IDs = $this->cleanIDs($IDs);
1232 1237
         $type = $this->getCFGDef('idType', 'parents');
1233 1238
         $depth = $this->getCFGDef('depth', '');
1234
-        if ($type == 'parents' && $depth > 0) {
1239
+        if ($type == 'parents' && $depth > 0) {
1235 1240
             $tmp = $IDs;
1236
-            do {
1237
-                if (count($tmp) > 0) {
1241
+            do {
1242
+                if (count($tmp) > 0) {
1238 1243
                     $tmp = $this->getChildrenFolder($tmp);
1239 1244
                     $IDs = array_merge($IDs, $tmp);
1240 1245
                 }
@@ -1248,8 +1253,8 @@  discard block
 block discarded – undo
1248 1253
     /**
1249 1254
      * @return int
1250 1255
      */
1251
-    public function getIDs()
1252
-    {
1256
+    public function getIDs()
1257
+    {
1253 1258
         return $this->IDs;
1254 1259
     }
1255 1260
 
@@ -1260,17 +1265,18 @@  discard block
 block discarded – undo
1260 1265
      * @param string $sep разделитель
1261 1266
      * @return array очищенный массив с данными
1262 1267
      */
1263
-    public function cleanIDs($IDs, $sep = ',')
1264
-    {
1268
+    public function cleanIDs($IDs, $sep = ',')
1269
+    {
1265 1270
         $this->debug->debug('clean IDs ' . $this->debug->dumpData($IDs) . ' with separator ' . $this->debug->dumpData($sep),
1266 1271
             'cleanIDs', 2);
1267 1272
         $out = array();
1268
-        if (!is_array($IDs)) {
1273
+        if (!is_array($IDs)) {
1269 1274
             $IDs = explode($sep, $IDs);
1270 1275
         }
1271
-        foreach ($IDs as $item) {
1276
+        foreach ($IDs as $item) {
1272 1277
             $item = trim($item);
1273
-            if (is_numeric($item) && (int)$item >= 0) { //Fix 0xfffffffff
1278
+            if (is_numeric($item) && (int)$item >= 0) {
1279
+//Fix 0xfffffffff
1274 1280
                 $out[] = (int)$item;
1275 1281
             }
1276 1282
         }
@@ -1284,8 +1290,8 @@  discard block
 block discarded – undo
1284 1290
      * Проверка массива с id-шниками документов для выборки
1285 1291
      * @return boolean пригодны ли данные для дальнейшего использования
1286 1292
      */
1287
-    protected function checkIDs()
1288
-    {
1293
+    protected function checkIDs()
1294
+    {
1289 1295
         return (is_array($this->IDs) && count($this->IDs) > 0) ? true : false;
1290 1296
     }
1291 1297
 
@@ -1297,11 +1303,11 @@  discard block
 block discarded – undo
1297 1303
      * @global array $_docs all documents
1298 1304
      * @return array all field values
1299 1305
      */
1300
-    public function getOneField($userField, $uniq = false)
1301
-    {
1306
+    public function getOneField($userField, $uniq = false)
1307
+    {
1302 1308
         $out = array();
1303
-        foreach ($this->_docs as $doc => $val) {
1304
-            if (isset($val[$userField]) && (($uniq && !in_array($val[$userField], $out)) || !$uniq)) {
1309
+        foreach ($this->_docs as $doc => $val) {
1310
+            if (isset($val[$userField]) && (($uniq && !in_array($val[$userField], $out)) || !$uniq)) {
1305 1311
                 $out[$doc] = $val[$userField];
1306 1312
             }
1307 1313
         }
@@ -1312,8 +1318,8 @@  discard block
 block discarded – undo
1312 1318
     /**
1313 1319
      * @return DLCollection
1314 1320
      */
1315
-    public function docsCollection()
1316
-    {
1321
+    public function docsCollection()
1322
+    {
1317 1323
         return new DLCollection($this->modx, $this->_docs);
1318 1324
     }
1319 1325
 
@@ -1341,10 +1347,10 @@  discard block
 block discarded – undo
1341 1347
      * @param string $group
1342 1348
      * @return string
1343 1349
      */
1344
-    protected function getGroupSQL($group = '')
1345
-    {
1350
+    protected function getGroupSQL($group = '')
1351
+    {
1346 1352
         $out = '';
1347
-        if ($group != '') {
1353
+        if ($group != '') {
1348 1354
             $out = 'GROUP BY ' . $group;
1349 1355
         }
1350 1356
 
@@ -1363,12 +1369,12 @@  discard block
 block discarded – undo
1363 1369
      *
1364 1370
      * @return string Order by for SQL
1365 1371
      */
1366
-    protected function SortOrderSQL($sortName, $orderDef = 'DESC')
1367
-    {
1372
+    protected function SortOrderSQL($sortName, $orderDef = 'DESC')
1373
+    {
1368 1374
         $this->debug->debug('', 'sortORDER', 2);
1369 1375
 
1370 1376
         $sort = '';
1371
-        switch ($this->getCFGDef('sortType', '')) {
1377
+        switch ($this->getCFGDef('sortType', '')) {
1372 1378
             case 'none':
1373 1379
                 break;
1374 1380
             case 'doclist':
@@ -1379,10 +1385,10 @@  discard block
 block discarded – undo
1379 1385
                 break;
1380 1386
             default:
1381 1387
                 $out = array('orderBy' => '', 'order' => '', 'sortBy' => '');
1382
-                if (($tmp = $this->getCFGDef('orderBy', '')) != '') {
1388
+                if (($tmp = $this->getCFGDef('orderBy', '')) != '') {
1383 1389
                     $out['orderBy'] = $tmp;
1384
-                } else {
1385
-                    switch (true) {
1390
+                } else {
1391
+                    switch (true) {
1386 1392
                         case ('' != ($tmp = $this->getCFGDef('sortDir', ''))): //higher priority than order
1387 1393
                             $out['order'] = $tmp;
1388 1394
                         // no break
@@ -1390,7 +1396,7 @@  discard block
 block discarded – undo
1390 1396
                             $out['order'] = $tmp;
1391 1397
                         // no break
1392 1398
                     }
1393
-                    if ('' == $out['order'] || !in_array(strtoupper($out['order']), array('ASC', 'DESC'))) {
1399
+                    if ('' == $out['order'] || !in_array(strtoupper($out['order']), array('ASC', 'DESC'))) {
1394 1400
                         $out['order'] = $orderDef; //Default
1395 1401
                     }
1396 1402
 
@@ -1411,26 +1417,26 @@  discard block
 block discarded – undo
1411 1417
      *
1412 1418
      * @return string LIMIT вставка в SQL запрос
1413 1419
      */
1414
-    protected function LimitSQL($limit = 0, $offset = 0)
1415
-    {
1420
+    protected function LimitSQL($limit = 0, $offset = 0)
1421
+    {
1416 1422
         $this->debug->debug('', 'limitSQL', 2);
1417 1423
         $ret = '';
1418
-        if ($limit == 0) {
1424
+        if ($limit == 0) {
1419 1425
             $limit = $this->getCFGDef('display', 0);
1420 1426
         }
1421
-        if ($offset == 0) {
1427
+        if ($offset == 0) {
1422 1428
             $offset = $this->getCFGDef('offset', 0);
1423 1429
         }
1424 1430
         $offset += $this->getCFGDef('start', 0);
1425 1431
         $total = $this->getCFGDef('total', 0);
1426
-        if ($limit < ($total - $limit)) {
1432
+        if ($limit < ($total - $limit)) {
1427 1433
             $limit = $total - $offset;
1428 1434
         }
1429 1435
 
1430
-        if ($limit != 0) {
1436
+        if ($limit != 0) {
1431 1437
             $ret = "LIMIT " . (int)$offset . "," . (int)$limit;
1432
-        } else {
1433
-            if ($offset != 0) {
1438
+        } else {
1439
+            if ($offset != 0) {
1434 1440
                 /**
1435 1441
                  * 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
1436 1442
                  * @see http://dev.mysql.com/doc/refman/5.0/en/select.html
@@ -1450,8 +1456,8 @@  discard block
 block discarded – undo
1450 1456
      * @param string $charset
1451 1457
      * @return string Clear string
1452 1458
      */
1453
-    public function sanitarData($data, $charset = 'UTF-8')
1454
-    {
1459
+    public function sanitarData($data, $charset = 'UTF-8')
1460
+    {
1455 1461
         return APIHelpers::sanitarTag($data, $charset);
1456 1462
     }
1457 1463
 
@@ -1462,8 +1468,8 @@  discard block
 block discarded – undo
1462 1468
      * @param string $parentField default name parent field
1463 1469
      * @return array
1464 1470
      */
1465
-    public function treeBuild($idField = 'id', $parentField = 'parent')
1466
-    {
1471
+    public function treeBuild($idField = 'id', $parentField = 'parent')
1472
+    {
1467 1473
         return $this->_treeBuild($this->_docs, $this->getCFGDef('idField', $idField),
1468 1474
             $this->getCFGDef('parentField', $parentField));
1469 1475
     }
@@ -1476,16 +1482,16 @@  discard block
 block discarded – undo
1476 1482
      * @param string $pidName name parent field in associative data array
1477 1483
      * @return array
1478 1484
      */
1479
-    private function _treeBuild($data, $idName, $pidName)
1480
-    {
1485
+    private function _treeBuild($data, $idName, $pidName)
1486
+    {
1481 1487
         $children = array(); // children of each ID
1482 1488
         $ids = array();
1483
-        foreach ($data as $i => $r) {
1489
+        foreach ($data as $i => $r) {
1484 1490
             $row =& $data[$i];
1485 1491
             $id = $row[$idName];
1486 1492
             $pid = $row[$pidName];
1487 1493
             $children[$pid][$id] =& $row;
1488
-            if (!isset($children[$id])) {
1494
+            if (!isset($children[$id])) {
1489 1495
                 $children[$id] = array();
1490 1496
             }
1491 1497
             $row['#childNodes'] =& $children[$id];
@@ -1493,9 +1499,9 @@  discard block
 block discarded – undo
1493 1499
         }
1494 1500
         // Root elements are elements with non-found PIDs.
1495 1501
         $this->_tree = array();
1496
-        foreach ($data as $i => $r) {
1502
+        foreach ($data as $i => $r) {
1497 1503
             $row =& $data[$i];
1498
-            if (!isset($ids[$row[$pidName]])) {
1504
+            if (!isset($ids[$row[$pidName]])) {
1499 1505
                 $this->_tree[$row[$idName]] = $row;
1500 1506
             }
1501 1507
         }
@@ -1509,8 +1515,8 @@  discard block
 block discarded – undo
1509 1515
      *
1510 1516
      * @return string PrimaryKey основной таблицы
1511 1517
      */
1512
-    public function getPK()
1513
-    {
1518
+    public function getPK()
1519
+    {
1514 1520
         return isset($this->idField) ? $this->idField : 'id';
1515 1521
     }
1516 1522
 
@@ -1519,8 +1525,8 @@  discard block
 block discarded – undo
1519 1525
      * По умолчанию это parent. Переопределить можно в контроллере присвоив другое значение переменной parentField
1520 1526
      * @return string Parent Key основной таблицы
1521 1527
      */
1522
-    public function getParentField()
1523
-    {
1528
+    public function getParentField()
1529
+    {
1524 1530
         return isset($this->parentField) ? $this->parentField : '';
1525 1531
     }
1526 1532
 
@@ -1531,31 +1537,31 @@  discard block
 block discarded – undo
1531 1537
      * @param string $filter_string строка со всеми фильтрами
1532 1538
      * @return mixed результат разбора фильтров
1533 1539
      */
1534
-    protected function getFilters($filter_string)
1535
-    {
1540
+    protected function getFilters($filter_string)
1541
+    {
1536 1542
         $this->debug->debug("getFilters: " . $this->debug->dumpData($filter_string), 'getFilter', 1);
1537 1543
         // the filter parameter tells us, which filters can be used in this query
1538 1544
         $filter_string = trim($filter_string, ' ;');
1539
-        if (!$filter_string) {
1545
+        if (!$filter_string) {
1540 1546
             return;
1541 1547
         }
1542 1548
         $output = array('join' => '', 'where' => '');
1543 1549
         $logic_op_found = false;
1544 1550
         $joins = $wheres = array();
1545
-        foreach ($this->_logic_ops as $op => $sql) {
1546
-            if (strpos($filter_string, $op) === 0) {
1551
+        foreach ($this->_logic_ops as $op => $sql) {
1552
+            if (strpos($filter_string, $op) === 0) {
1547 1553
                 $logic_op_found = true;
1548 1554
                 $subfilters = mb_substr($filter_string, strlen($op) + 1, mb_strlen($filter_string, "UTF-8"), "UTF-8");
1549 1555
                 $subfilters = $this->smartSplit($subfilters);
1550
-                foreach ($subfilters as $subfilter) {
1556
+                foreach ($subfilters as $subfilter) {
1551 1557
                     $subfilter = $this->getFilters(trim($subfilter));
1552
-                    if (!$subfilter) {
1558
+                    if (!$subfilter) {
1553 1559
                         continue;
1554 1560
                     }
1555
-                    if ($subfilter['join']) {
1561
+                    if ($subfilter['join']) {
1556 1562
                         $joins[] = $subfilter['join'];
1557 1563
                     }
1558
-                    if ($subfilter['where']) {
1564
+                    if ($subfilter['where']) {
1559 1565
                         $wheres[] = $subfilter['where'];
1560 1566
                     }
1561 1567
                 }
@@ -1564,12 +1570,12 @@  discard block
 block discarded – undo
1564 1570
             }
1565 1571
         }
1566 1572
 
1567
-        if (!$logic_op_found) {
1573
+        if (!$logic_op_found) {
1568 1574
             $filter = $this->loadFilter($filter_string);
1569
-            if (!$filter) {
1575
+            if (!$filter) {
1570 1576
                 $this->debug->warning('Error while loading DocLister filter "' . $this->debug->dumpData($filter_string) . '": check syntax!');
1571 1577
                 $output = false;
1572
-            } else {
1578
+            } else {
1573 1579
                 $output['join'] = $filter->get_join();
1574 1580
                 $output['where'] = $filter->get_where();
1575 1581
             }
@@ -1582,16 +1588,16 @@  discard block
 block discarded – undo
1582 1588
     /**
1583 1589
      * @return mixed
1584 1590
      */
1585
-    public function filtersWhere()
1586
-    {
1591
+    public function filtersWhere()
1592
+    {
1587 1593
         return APIHelpers::getkey($this->_filters, 'where', '');
1588 1594
     }
1589 1595
 
1590 1596
     /**
1591 1597
      * @return mixed
1592 1598
      */
1593
-    public function filtersJoin()
1594
-    {
1599
+    public function filtersJoin()
1600
+    {
1595 1601
         return APIHelpers::getkey($this->_filters, 'join', '');
1596 1602
     }
1597 1603
 
@@ -1602,10 +1608,10 @@  discard block
 block discarded – undo
1602 1608
      * @param $type string тип фильтрации
1603 1609
      * @return string имя поля с учетом приведения типа
1604 1610
      */
1605
-    public function changeSortType($field, $type)
1606
-    {
1611
+    public function changeSortType($field, $type)
1612
+    {
1607 1613
         $type = trim($type);
1608
-        switch (strtoupper($type)) {
1614
+        switch (strtoupper($type)) {
1609 1615
             case 'DECIMAL':
1610 1616
                 $field = 'CAST(' . $field . ' as DECIMAL(10,2))';
1611 1617
                 break;
@@ -1631,14 +1637,14 @@  discard block
 block discarded – undo
1631 1637
      * @param string $filter срока с параметрами фильтрации
1632 1638
      * @return bool
1633 1639
      */
1634
-    protected function loadFilter($filter)
1635
-    {
1640
+    protected function loadFilter($filter)
1641
+    {
1636 1642
         $this->debug->debug('Load filter ' . $this->debug->dumpData($filter), 'loadFilter', 2);
1637 1643
         $out = false;
1638 1644
         $fltr_params = explode(':', $filter, 2);
1639 1645
         $fltr = APIHelpers::getkey($fltr_params, 0, null);
1640 1646
         // check if the filter is implemented
1641
-        if (!is_null($fltr) && file_exists(dirname(__FILE__) . '/filter/' . $fltr . '.filter.php')) {
1647
+        if (!is_null($fltr) && file_exists(dirname(__FILE__) . '/filter/' . $fltr . '.filter.php')) {
1642 1648
             require_once dirname(__FILE__) . '/filter/' . $fltr . '.filter.php';
1643 1649
             /**
1644 1650
              * @var tv_DL_filter|content_DL_filter $fltr_class
@@ -1646,12 +1652,12 @@  discard block
 block discarded – undo
1646 1652
             $fltr_class = $fltr . '_DL_filter';
1647 1653
             $this->totalFilters++;
1648 1654
             $fltr_obj = new $fltr_class();
1649
-            if ($fltr_obj->init($this, $filter)) {
1655
+            if ($fltr_obj->init($this, $filter)) {
1650 1656
                 $out = $fltr_obj;
1651
-            } else {
1657
+            } else {
1652 1658
                 $this->debug->error("Wrong filter parameter: '{$this->debug->dumpData($filter)}'", 'Filter');
1653 1659
             }
1654
-        } else {
1660
+        } else {
1655 1661
             $this->debug->error("Error load Filter: '{$this->debug->dumpData($filter)}'", 'Filter');
1656 1662
         }
1657 1663
         $this->debug->debugEnd("loadFilter");
@@ -1663,8 +1669,8 @@  discard block
 block discarded – undo
1663 1669
      * Общее число фильтров
1664 1670
      * @return int
1665 1671
      */
1666
-    public function getCountFilters()
1667
-    {
1672
+    public function getCountFilters()
1673
+    {
1668 1674
         return (int)$this->totalFilters;
1669 1675
     }
1670 1676
 
@@ -1672,8 +1678,8 @@  discard block
 block discarded – undo
1672 1678
      * Выполнить SQL запрос
1673 1679
      * @param string $q SQL запрос
1674 1680
      */
1675
-    public function dbQuery($q)
1676
-    {
1681
+    public function dbQuery($q)
1682
+    {
1677 1683
         $this->debug->debug($q, "query", 1, 'sql');
1678 1684
         $out = $this->modx->db->query($q);
1679 1685
         $this->debug->debugEnd("query");
@@ -1691,8 +1697,8 @@  discard block
 block discarded – undo
1691 1697
      * @param string $tpl шаблон подстановки значения в SQL запрос
1692 1698
      * @return string строка для подстановки в SQL запрос
1693 1699
      */
1694
-    public function LikeEscape($field, $value, $escape = '=', $tpl = '%[+value+]%')
1695
-    {
1700
+    public function LikeEscape($field, $value, $escape = '=', $tpl = '%[+value+]%')
1701
+    {
1696 1702
         return sqlHelper::LikeEscape($this->modx, $field, $value, $escape, $tpl);
1697 1703
     }
1698 1704
 
@@ -1700,8 +1706,8 @@  discard block
 block discarded – undo
1700 1706
      * Получение REQUEST_URI без GET-ключа с
1701 1707
      * @return string
1702 1708
      */
1703
-    public function getRequest()
1704
-    {
1709
+    public function getRequest()
1710
+    {
1705 1711
         $URL = null;
1706 1712
         parse_str(parse_url(MODX_SITE_URL . $_SERVER['REQUEST_URI'], PHP_URL_QUERY), $URL);
1707 1713
 
Please login to merge, or discard this patch.
assets/snippets/DLUsers/plugin.DLLogout.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@
 block discarded – undo
1 1
 <?php
2
-if (!defined('MODX_BASE_PATH')) {
2
+if ( ! defined('MODX_BASE_PATH')) {
3 3
     die('What are you doing? Get out of here!');
4 4
 }
5 5
 if ($modx->event->name == 'OnWebPagePrerender' && $modx->getLoginUserID('web')) {
Please login to merge, or discard this patch.
Braces   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@
 block discarded – undo
1 1
 <?php
2
-if (!defined('MODX_BASE_PATH')) {
2
+if (!defined('MODX_BASE_PATH')) {
3 3
     die('What are you doing? Get out of here!');
4 4
 }
5
-if ($modx->event->name == 'OnWebPagePrerender' && $modx->getLoginUserID('web')) {
5
+if ($modx->event->name == 'OnWebPagePrerender' && $modx->getLoginUserID('web')) {
6 6
     $snippetName = (isset($snippetName) && is_string($snippetName)) ? $snippetName : 'DLUsers';
7 7
     $modx->runSnippet($snippetName, array(
8 8
         'action' => 'logout'
Please login to merge, or discard this patch.
assets/snippets/DocLister/snippet.DLcrumbs.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -5,13 +5,13 @@  discard block
 block discarded – undo
5 5
  * @license GNU General Public License (GPL), http://www.gnu.org/copyleft/gpl.html
6 6
  * @author Agel_Nash <[email protected]>
7 7
  */
8
-if (!defined('MODX_BASE_PATH')) {
8
+if ( ! defined('MODX_BASE_PATH')) {
9 9
     die('HACK???');
10 10
 }
11 11
 $_out = '';
12 12
 
13 13
 $_parents = array();
14
-$hideMain = (!isset($hideMain) || (int)$hideMain == 0);
14
+$hideMain = ( ! isset($hideMain) || (int)$hideMain == 0);
15 15
 if ($hideMain) {
16 16
     $_parents[] = $modx->config['site_start'];
17 17
 }
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 $tmp = $modx->getParentIds($id);
20 20
 $_parents = array_merge($_parents, array_reverse(array_values($tmp)));
21 21
 foreach ($_parents as $i => $num) {
22
-    if ($num == $modx->config['site_start'] && !$hideMain) {
22
+    if ($num == $modx->config['site_start'] && ! $hideMain) {
23 23
         unset($_parents[$i]);
24 24
     }
25 25
 }
@@ -27,12 +27,12 @@  discard block
 block discarded – undo
27 27
 if (isset($showCurrent) && (int)$showCurrent > 0) {
28 28
     $_parents[] = $id;
29 29
 }
30
-if (!empty($_parents) && count($_parents) >= (empty($minDocs) ? 0 : (int)$minDocs)) {
30
+if ( ! empty($_parents) && count($_parents) >= (empty($minDocs) ? 0 : (int)$minDocs)) {
31 31
     $_options = array_merge(
32 32
         array(
33 33
             'config' => 'crumbs:core'
34 34
         ),
35
-        !empty($modx->event->params) ? $modx->event->params : array(),
35
+        ! empty($modx->event->params) ? $modx->event->params : array(),
36 36
         array(
37 37
             'idType'    => 'documents',
38 38
             'sortType'  => 'doclist',
Please login to merge, or discard this patch.
Braces   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -5,29 +5,29 @@
 block discarded – undo
5 5
  * @license GNU General Public License (GPL), http://www.gnu.org/copyleft/gpl.html
6 6
  * @author Agel_Nash <[email protected]>
7 7
  */
8
-if (!defined('MODX_BASE_PATH')) {
8
+if (!defined('MODX_BASE_PATH')) {
9 9
     die('HACK???');
10 10
 }
11 11
 $_out = '';
12 12
 
13 13
 $_parents = array();
14 14
 $hideMain = (!isset($hideMain) || (int)$hideMain == 0);
15
-if ($hideMain) {
15
+if ($hideMain) {
16 16
     $_parents[] = $modx->config['site_start'];
17 17
 }
18 18
 $id = isset($id) ? $id : $modx->documentObject['id'];
19 19
 $tmp = $modx->getParentIds($id);
20 20
 $_parents = array_merge($_parents, array_reverse(array_values($tmp)));
21
-foreach ($_parents as $i => $num) {
22
-    if ($num == $modx->config['site_start'] && !$hideMain) {
21
+foreach ($_parents as $i => $num) {
22
+    if ($num == $modx->config['site_start'] && !$hideMain) {
23 23
         unset($_parents[$i]);
24 24
     }
25 25
 }
26 26
 
27
-if (isset($showCurrent) && (int)$showCurrent > 0) {
27
+if (isset($showCurrent) && (int)$showCurrent > 0) {
28 28
     $_parents[] = $id;
29 29
 }
30
-if (!empty($_parents) && count($_parents) >= (empty($minDocs) ? 0 : (int)$minDocs)) {
30
+if (!empty($_parents) && count($_parents) >= (empty($minDocs) ? 0 : (int)$minDocs)) {
31 31
     $_options = array_merge(
32 32
         array(
33 33
             'config' => 'crumbs:core'
Please login to merge, or discard this patch.
assets/snippets/DocLister/snippet.DLBeforeAfter.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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),
Please login to merge, or discard this patch.
Braces   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -1,14 +1,14 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
assets/snippets/DocLister/snippet.DLReflectFilter.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -26,13 +26,13 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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 {
Please login to merge, or discard this patch.
Braces   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -26,13 +26,13 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
assets/snippets/DocLister/lib/DLdebug.class.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Braces   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -5,8 +5,8 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
79 79
      * @param int $mode
80 80
      * @param bool $format
81 81
      */
82
-    public function debug($message, $key = null, $mode = 0, $format = false)
83
-    {
82
+    public function debug($message, $key = null, $mode = 0, $format = false)
83
+    {
84 84
         $mode = (int)$mode;
85
-        if ($mode > 0 && $this->DocLister->getDebug() >= $mode) {
85
+        if ($mode > 0 && $this->DocLister->getDebug() >= $mode) {
86 86
             $data = array(
87 87
                 'msg'    => $message,
88 88
                 'format' => $format,
89 89
                 'start'  => microtime(true) - $this->DocLister->getTimeStart()
90 90
             );
91
-            if (is_scalar($key) && !empty($key)) {
91
+            if (is_scalar($key) && !empty($key)) {
92 92
                 $data['time'] = microtime(true);
93 93
                 $this->_calcLog[$key] = $data;
94
-            } else {
94
+            } else {
95 95
                 $this->_log[$this->countLog()] = $data;
96 96
             }
97 97
         }
@@ -102,11 +102,11 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
assets/snippets/DocLister/lib/DLReflect.class.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
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
      */
Please login to merge, or discard this patch.
Braces   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,19 +1,19 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.