@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | * @license GNU General Public License (GPL), http://www.gnu.org/copyleft/gpl.html |
71 | 71 | * @param string $email проверяемый email |
72 | 72 | * @param boolean $dns проверять ли DNS записи |
73 | - * @return boolean Результат проверки почтового ящика |
|
73 | + * @return false|string Результат проверки почтового ящика |
|
74 | 74 | * @author Anton Shevchuk |
75 | 75 | */ |
76 | 76 | public static function emailValidate($email, $dns = true) |
@@ -142,6 +142,9 @@ discard block |
||
142 | 142 | return $pass; |
143 | 143 | } |
144 | 144 | |
145 | + /** |
|
146 | + * @param string $data |
|
147 | + */ |
|
145 | 148 | private function _getEnv($data) |
146 | 149 | { |
147 | 150 | $out = false; |
@@ -125,7 +125,7 @@ |
||
125 | 125 | for ($i = $len; $i > 0; $i--) { |
126 | 126 | switch ($data[rand(0, ($opt - 1))]) { |
127 | 127 | case 'A': |
128 | - $tmp = rand(65, 90); |
|
128 | + $tmp = rand(65, 90); |
|
129 | 129 | break; |
130 | 130 | case 'a': |
131 | 131 | $tmp = rand(97, 122); |
@@ -41,7 +41,7 @@ |
||
41 | 41 | $text = mb_substr($text, 0, $len+1, $encoding); |
42 | 42 | if(mb_substr($text, -1, null, $encoding) == ' '){ |
43 | 43 | $out = trim($text); |
44 | - }else{ |
|
44 | + } else{ |
|
45 | 45 | $out = mb_substr($text, 0, mb_strripos($text, ' ', null, $encoding), $encoding); |
46 | 46 | } |
47 | 47 | return preg_replace("/(([\.,\-:!?;\s])|(&\w+;))+$/ui", "", $out); |
@@ -8,8 +8,8 @@ discard block |
||
8 | 8 | * @param string $encoding - кодировка, по-умолчанию UTF-8 |
9 | 9 | * @return string |
10 | 10 | */ |
11 | - public static function mb_lcfirst($str, $encoding='UTF-8'){ |
|
12 | - return mb_strtolower(mb_substr($str, 0, 1, $encoding), $encoding).mb_substr($str,1, mb_strlen($str), $encoding); |
|
11 | + public static function mb_lcfirst($str, $encoding = 'UTF-8') { |
|
12 | + return mb_strtolower(mb_substr($str, 0, 1, $encoding), $encoding).mb_substr($str, 1, mb_strlen($str), $encoding); |
|
13 | 13 | } |
14 | 14 | |
15 | 15 | /** |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * @param string $encoding - кодировка, по-умолчанию UTF-8 |
19 | 19 | * @return string |
20 | 20 | */ |
21 | - public static function mb_ucfirst($str, $encoding='UTF-8') |
|
21 | + public static function mb_ucfirst($str, $encoding = 'UTF-8') |
|
22 | 22 | { |
23 | 23 | $str = mb_ereg_replace('^[\ ]+', '', $str); |
24 | 24 | $str = mb_strtoupper(mb_substr($str, 0, 1, $encoding), $encoding).mb_substr($str, 1, mb_strlen($str), $encoding); |
@@ -36,12 +36,12 @@ discard block |
||
36 | 36 | * @param string $encoding кодировка |
37 | 37 | * @return string |
38 | 38 | */ |
39 | - public static function mb_trim_word($html, $len, $encoding = 'UTF-8'){ |
|
39 | + public static function mb_trim_word($html, $len, $encoding = 'UTF-8') { |
|
40 | 40 | $text = trim(preg_replace('|\s+|', ' ', strip_tags($html))); |
41 | - $text = mb_substr($text, 0, $len+1, $encoding); |
|
42 | - if(mb_substr($text, -1, null, $encoding) == ' '){ |
|
41 | + $text = mb_substr($text, 0, $len + 1, $encoding); |
|
42 | + if (mb_substr($text, -1, null, $encoding) == ' ') { |
|
43 | 43 | $out = trim($text); |
44 | - }else{ |
|
44 | + } else { |
|
45 | 45 | $out = mb_substr($text, 0, mb_strripos($text, ' ', null, $encoding), $encoding); |
46 | 46 | } |
47 | 47 | return preg_replace("/(([\.,\-:!?;\s])|(&\w+;))+$/ui", "", $out); |
@@ -216,8 +216,8 @@ discard block |
||
216 | 216 | '[' => '[', '%5B' => '[', ']' => ']', '%5D' => ']', |
217 | 217 | '{' => '{', '%7B' => '{', '}' => '}', '%7D' => '}', |
218 | 218 | '`' => '`', '%60' => '`' |
219 | - )){ |
|
220 | - switch(true){ |
|
219 | + )) { |
|
220 | + switch (true) { |
|
221 | 221 | case is_scalar($data): |
222 | 222 | $out = str_replace( |
223 | 223 | array_keys($chars), |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | break; |
228 | 228 | case is_array($data): |
229 | 229 | $out = $data; |
230 | - foreach($out as $key => &$val){ |
|
230 | + foreach ($out as $key => &$val) { |
|
231 | 231 | $val = self::sanitarTag($val, $charset, $chars); |
232 | 232 | } |
233 | 233 | break; |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | return $out; |
238 | 238 | } |
239 | 239 | |
240 | - public static function e($text, $charset = 'UTF-8'){ |
|
240 | + public static function e($text, $charset = 'UTF-8') { |
|
241 | 241 | return is_scalar($text) ? htmlspecialchars($text, ENT_QUOTES, $charset, false) : ''; |
242 | 242 | } |
243 | 243 | /** |
@@ -319,12 +319,12 @@ discard block |
||
319 | 319 | if ($prefix == '' && $suffix == '') { |
320 | 320 | $out = $data; |
321 | 321 | } else { |
322 | - $InsertPrefix = ($prefix != '') ? ($prefix . $addPS) : ''; |
|
323 | - $InsertSuffix = ($suffix != '') ? ($addPS. $suffix) : ''; |
|
322 | + $InsertPrefix = ($prefix != '') ? ($prefix.$addPS) : ''; |
|
323 | + $InsertSuffix = ($suffix != '') ? ($addPS.$suffix) : ''; |
|
324 | 324 | foreach ($data as $key => $item) { |
325 | - $key = $InsertPrefix . $key; |
|
325 | + $key = $InsertPrefix.$key; |
|
326 | 326 | $val = null; |
327 | - switch(true){ |
|
327 | + switch (true) { |
|
328 | 328 | case is_scalar($item): |
329 | 329 | $val = $item; |
330 | 330 | break; |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | $val = ''; |
335 | 335 | break; |
336 | 336 | } |
337 | - $out[$key . $InsertSuffix] = $val; |
|
337 | + $out[$key.$InsertSuffix] = $val; |
|
338 | 338 | } |
339 | 339 | } |
340 | 340 | return $out; |
@@ -101,6 +101,10 @@ discard block |
||
101 | 101 | return $summary; |
102 | 102 | } |
103 | 103 | |
104 | + /** |
|
105 | + * @param integer $truncOffset |
|
106 | + * @param boolean $truncChars |
|
107 | + */ |
|
104 | 108 | protected function summary($resource, $truncLen, $truncOffset, $truncChars, $splitter = '') |
105 | 109 | { |
106 | 110 | if (isset($this->_useCut) && $splitter != '' && mb_strstr($resource, $splitter, 'UTF-8')) { |
@@ -180,6 +184,10 @@ discard block |
||
180 | 184 | * @see summary extender for Ditto (truncate::textTrunc) |
181 | 185 | * @link https://github.com/modxcms/evolution/blob/develop/assets/snippets/ditto/extenders/summary.extender.inc.php#L213 |
182 | 186 | */ |
187 | + |
|
188 | + /** |
|
189 | + * @param integer $limit |
|
190 | + */ |
|
183 | 191 | protected function textTrunc($string, $limit, $break = ". ") |
184 | 192 | { |
185 | 193 | // Original PHP code from The Art of Web: www.the-art-of-web.com |
@@ -198,6 +206,9 @@ discard block |
||
198 | 206 | return $string; |
199 | 207 | } |
200 | 208 | |
209 | + /** |
|
210 | + * @param string $str |
|
211 | + */ |
|
201 | 212 | protected function rTriming($str) |
202 | 213 | { |
203 | 214 | $str = preg_replace('/[\r\n]++/', ' ', $str); |
@@ -108,7 +108,9 @@ discard block |
||
108 | 108 | } else if ($this->_useCut !== true && (mb_strlen($resource, 'UTF-8') > $truncLen)) { |
109 | 109 | |
110 | 110 | $summary = $this->html_substr($resource, $truncLen, $truncOffset, $truncChars); |
111 | - if ($resource != $summary) $this->_useSubstr = true; |
|
111 | + if ($resource != $summary) { |
|
112 | + $this->_useSubstr = true; |
|
113 | + } |
|
112 | 114 | } else { |
113 | 115 | $summary = $resource; |
114 | 116 | } |
@@ -149,15 +151,23 @@ discard block |
||
149 | 151 | } |
150 | 152 | // Slash signifies an ending (like </a> or ... />) |
151 | 153 | // substract 2 |
152 | - if ($current_char == '/' && $tag_counter <> 0) $tag_counter -= 2; |
|
154 | + if ($current_char == '/' && $tag_counter <> 0) { |
|
155 | + $tag_counter -= 2; |
|
156 | + } |
|
153 | 157 | // On a ">" substract 1 |
154 | - if ($current_char == '>') $tag_counter -= 1; |
|
158 | + if ($current_char == '>') { |
|
159 | + $tag_counter -= 1; |
|
160 | + } |
|
155 | 161 | // If quotes are encountered, start ignoring the tags |
156 | 162 | // (for directory slashes) |
157 | - if ($current_char == '"') $quotes_on = TRUE; |
|
163 | + if ($current_char == '"') { |
|
164 | + $quotes_on = TRUE; |
|
165 | + } |
|
158 | 166 | } else { |
159 | 167 | // IF quotes are encountered again, turn it back off |
160 | - if ($current_char == '"') $quotes_on = FALSE; |
|
168 | + if ($current_char == '"') { |
|
169 | + $quotes_on = FALSE; |
|
170 | + } |
|
161 | 171 | } |
162 | 172 | |
163 | 173 | // Count only the chars outside html tags |
@@ -185,7 +195,9 @@ discard block |
||
185 | 195 | // Original PHP code from The Art of Web: www.the-art-of-web.com |
186 | 196 | |
187 | 197 | // return with no change if string is shorter than $limit |
188 | - if (mb_strlen($string, 'UTF-8') < $limit) return $string; |
|
198 | + if (mb_strlen($string, 'UTF-8') < $limit) { |
|
199 | + return $string; |
|
200 | + } |
|
189 | 201 | |
190 | 202 | $string = mb_substr($string, 0, $limit, 'UTF-8'); |
191 | 203 | if (false !== ($breakpoint = mb_strrpos($string, $break, 'UTF-8'))) { |
@@ -65,7 +65,7 @@ |
||
65 | 65 | $process = explode(":", $doing); |
66 | 66 | switch ($process[0]) { |
67 | 67 | case 'notags': |
68 | - $this->_cfg['content'] = strip_tags($this->_cfg['content']); |
|
68 | + $this->_cfg['content'] = strip_tags($this->_cfg['content']); |
|
69 | 69 | break; |
70 | 70 | case 'noparser': |
71 | 71 | $this->_cfg['content'] = APIhelpers::sanitarTag($this->_cfg['content']); |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * @date 31.07.2013 |
13 | 13 | * @version 1.0.3 |
14 | 14 | */ |
15 | -include_once(MODX_BASE_PATH . 'assets/lib/APIHelpers.class.php'); |
|
15 | +include_once(MODX_BASE_PATH.'assets/lib/APIHelpers.class.php'); |
|
16 | 16 | class SummaryText |
17 | 17 | { |
18 | 18 | private $_cfg = array('content' => '', 'summary' => '', 'original' => '', 'break' => ''); |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | protected function beforeCut($resource, $splitter = '') |
92 | 92 | { |
93 | 93 | if ($splitter !== '') { |
94 | - $summary = str_replace('<p>' . $splitter . '</p>', $splitter, $resource); // For TinyMCE or if it isn't wrapped inside paragraph tags |
|
94 | + $summary = str_replace('<p>'.$splitter.'</p>', $splitter, $resource); // For TinyMCE or if it isn't wrapped inside paragraph tags |
|
95 | 95 | $summary = explode($splitter, $summary, 2); |
96 | 96 | $this->_useCut = isset($summary[1]); |
97 | 97 | $summary = $summary['0']; |
@@ -252,10 +252,10 @@ discard block |
||
252 | 252 | $tag = mb_substr($tag, 0, strpos($tag, ' '), 'UTF-8'); |
253 | 253 | } |
254 | 254 | if (!mb_stristr($tag, 'br', 'UTF-8') && !mb_stristr($tag, 'img', 'UTF-8') && !empty ($tag)) { |
255 | - $endTags .= '</' . $tag . '>'; |
|
255 | + $endTags .= '</'.$tag.'>'; |
|
256 | 256 | } |
257 | 257 | } |
258 | 258 | } |
259 | - return $text . $endTags; |
|
259 | + return $text.$endTags; |
|
260 | 260 | } |
261 | 261 | } |
262 | 262 | \ No newline at end of file |
@@ -329,6 +329,9 @@ |
||
329 | 329 | ); |
330 | 330 | } |
331 | 331 | |
332 | + /** |
|
333 | + * @param string $string |
|
334 | + */ |
|
332 | 335 | protected static function getQuotedString($string) |
333 | 336 | { |
334 | 337 | $ret = null; |
@@ -176,7 +176,9 @@ discard block |
||
176 | 176 | */ |
177 | 177 | protected static function init() |
178 | 178 | { |
179 | - if (self::$init) return; |
|
179 | + if (self::$init) { |
|
180 | + return; |
|
181 | + } |
|
180 | 182 | |
181 | 183 | // Sort reserved word list from longest word to shortest, 3x faster than usort |
182 | 184 | $reservedMap = array_combine(self::$reserved, array_map('strlen', self::$reserved)); |
@@ -263,7 +265,9 @@ discard block |
||
263 | 265 | } |
264 | 266 | } |
265 | 267 | |
266 | - if($ret[self::TOKEN_VALUE] !== null) return $ret; |
|
268 | + if($ret[self::TOKEN_VALUE] !== null) { |
|
269 | + return $ret; |
|
270 | + } |
|
267 | 271 | } |
268 | 272 | |
269 | 273 | // Number (decimal, binary, or hex) |
@@ -536,7 +540,9 @@ discard block |
||
536 | 540 | $length = 0; |
537 | 541 | for ($j=1;$j<=250;$j++) { |
538 | 542 | // Reached end of string |
539 | - if (!isset($tokens[$i+$j])) break; |
|
543 | + if (!isset($tokens[$i+$j])) { |
|
544 | + break; |
|
545 | + } |
|
540 | 546 | |
541 | 547 | $next = $tokens[$i+$j]; |
542 | 548 | |
@@ -954,7 +960,9 @@ discard block |
||
954 | 960 | */ |
955 | 961 | protected static function highlightBoundary($value) |
956 | 962 | { |
957 | - if ($value==='(' || $value===')') return $value; |
|
963 | + if ($value==='(' || $value===')') { |
|
964 | + return $value; |
|
965 | + } |
|
958 | 966 | |
959 | 967 | if (self::is_cli()) { |
960 | 968 | return self::$cli_boundary . $value . "\x1b[0m"; |
@@ -1078,8 +1086,11 @@ discard block |
||
1078 | 1086 | |
1079 | 1087 | private static function is_cli() |
1080 | 1088 | { |
1081 | - if (isset(self::$cli)) return self::$cli; |
|
1082 | - else return php_sapi_name() === 'cli'; |
|
1089 | + if (isset(self::$cli)) { |
|
1090 | + return self::$cli; |
|
1091 | + } else { |
|
1092 | + return php_sapi_name() === 'cli'; |
|
1093 | + } |
|
1083 | 1094 | } |
1084 | 1095 | |
1085 | 1096 | } |
1086 | 1097 | \ No newline at end of file |
@@ -862,9 +862,9 @@ |
||
862 | 862 | $token = $token[self::TOKEN_VALUE]; |
863 | 863 | } else { |
864 | 864 | if (defined('ENT_IGNORE')) { |
865 | - $token = htmlentities($token[self::TOKEN_VALUE],ENT_COMPAT | ENT_IGNORE ,'UTF-8'); |
|
865 | + $token = htmlentities($token[self::TOKEN_VALUE],ENT_COMPAT | ENT_IGNORE ,'UTF-8'); |
|
866 | 866 | } else { |
867 | - $token = htmlentities($token[self::TOKEN_VALUE],ENT_COMPAT,'UTF-8'); |
|
867 | + $token = htmlentities($token[self::TOKEN_VALUE],ENT_COMPAT,'UTF-8'); |
|
868 | 868 | } |
869 | 869 | } |
870 | 870 |
@@ -45,14 +45,14 @@ discard block |
||
45 | 45 | 'HOUR_SECOND', 'IDENTIFIED', 'IF', 'IFNULL', 'IGNORE', 'IN', 'INDEX', 'INDEXES', 'INFILE', 'INSERT', 'INSERT_ID', 'INSERT_METHOD', 'INTERVAL', |
46 | 46 | 'INTO', 'INVOKER', 'IS', 'ISOLATION', 'KEY', 'KEYS', 'KILL', 'LAST_INSERT_ID', 'LEADING', 'LEVEL', 'LIKE', 'LINEAR', |
47 | 47 | 'LINES', 'LOAD', 'LOCAL', 'LOCK', 'LOCKS', 'LOGS', 'LOW_PRIORITY', 'MARIA', 'MASTER', 'MASTER_CONNECT_RETRY', 'MASTER_HOST', 'MASTER_LOG_FILE', |
48 | - 'MATCH','MAX_CONNECTIONS_PER_HOUR', 'MAX_QUERIES_PER_HOUR', 'MAX_ROWS', 'MAX_UPDATES_PER_HOUR', 'MAX_USER_CONNECTIONS', |
|
48 | + 'MATCH', 'MAX_CONNECTIONS_PER_HOUR', 'MAX_QUERIES_PER_HOUR', 'MAX_ROWS', 'MAX_UPDATES_PER_HOUR', 'MAX_USER_CONNECTIONS', |
|
49 | 49 | 'MEDIUM', 'MERGE', 'MINUTE', 'MINUTE_SECOND', 'MIN_ROWS', 'MODE', 'MODIFY', |
50 | - 'MONTH', 'MRG_MYISAM', 'MYISAM', 'NAMES', 'NATURAL', 'NOT', 'NOW()','NULL', 'OFFSET', 'ON', 'OPEN', 'OPTIMIZE', 'OPTION', 'OPTIONALLY', |
|
50 | + 'MONTH', 'MRG_MYISAM', 'MYISAM', 'NAMES', 'NATURAL', 'NOT', 'NOW()', 'NULL', 'OFFSET', 'ON', 'OPEN', 'OPTIMIZE', 'OPTION', 'OPTIONALLY', |
|
51 | 51 | 'ON UPDATE', 'ON DELETE', 'OUTFILE', 'PACK_KEYS', 'PAGE', 'PARTIAL', 'PARTITION', 'PARTITIONS', 'PASSWORD', 'PRIMARY', 'PRIVILEGES', 'PROCEDURE', |
52 | - 'PROCESS', 'PROCESSLIST', 'PURGE', 'QUICK', 'RANGE', 'RAID0', 'RAID_CHUNKS', 'RAID_CHUNKSIZE','RAID_TYPE', 'READ', 'READ_ONLY', |
|
52 | + 'PROCESS', 'PROCESSLIST', 'PURGE', 'QUICK', 'RANGE', 'RAID0', 'RAID_CHUNKS', 'RAID_CHUNKSIZE', 'RAID_TYPE', 'READ', 'READ_ONLY', |
|
53 | 53 | 'READ_WRITE', 'REFERENCES', 'REGEXP', 'RELOAD', 'RENAME', 'REPAIR', 'REPEATABLE', 'REPLACE', 'REPLICATION', 'RESET', 'RESTORE', 'RESTRICT', |
54 | 54 | 'RETURN', 'RETURNS', 'REVOKE', 'RLIKE', 'ROLLBACK', 'ROW', 'ROWS', 'ROW_FORMAT', 'SECOND', 'SECURITY', 'SEPARATOR', |
55 | - 'SERIALIZABLE', 'SESSION', 'SHARE', 'SHOW', 'SHUTDOWN', 'SLAVE', 'SONAME', 'SOUNDS', 'SQL', 'SQL_AUTO_IS_NULL', 'SQL_BIG_RESULT', |
|
55 | + 'SERIALIZABLE', 'SESSION', 'SHARE', 'SHOW', 'SHUTDOWN', 'SLAVE', 'SONAME', 'SOUNDS', 'SQL', 'SQL_AUTO_IS_NULL', 'SQL_BIG_RESULT', |
|
56 | 56 | 'SQL_BIG_SELECTS', 'SQL_BIG_TABLES', 'SQL_BUFFER_RESULT', 'SQL_CALC_FOUND_ROWS', 'SQL_LOG_BIN', 'SQL_LOG_OFF', 'SQL_LOG_UPDATE', |
57 | 57 | 'SQL_LOW_PRIORITY_UPDATES', 'SQL_MAX_JOIN_SIZE', 'SQL_QUOTE_SHOW_CREATE', 'SQL_SAFE_UPDATES', 'SQL_SELECT_LIMIT', 'SQL_SLAVE_SKIP_COUNTER', |
58 | 58 | 'SQL_SMALL_RESULT', 'SQL_WARNINGS', 'SQL_CACHE', 'SQL_NO_CACHE', 'START', 'STARTING', 'STATUS', 'STOP', 'STORAGE', |
@@ -72,25 +72,25 @@ discard block |
||
72 | 72 | 'LEFT OUTER JOIN', 'RIGHT OUTER JOIN', 'LEFT JOIN', 'RIGHT JOIN', 'OUTER JOIN', 'INNER JOIN', 'JOIN', 'XOR', 'OR', 'AND' |
73 | 73 | ); |
74 | 74 | |
75 | - protected static $functions = array ( |
|
75 | + protected static $functions = array( |
|
76 | 76 | 'ABS', 'ACOS', 'ADDDATE', 'ADDTIME', 'AES_DECRYPT', 'AES_ENCRYPT', 'AREA', 'ASBINARY', 'ASCII', 'ASIN', 'ASTEXT', 'ATAN', 'ATAN2', |
77 | - 'AVG', 'BDMPOLYFROMTEXT', 'BDMPOLYFROMWKB', 'BDPOLYFROMTEXT', 'BDPOLYFROMWKB', 'BENCHMARK', 'BIN', 'BIT_AND', 'BIT_COUNT', 'BIT_LENGTH', |
|
78 | - 'BIT_OR', 'BIT_XOR', 'BOUNDARY', 'BUFFER', 'CAST', 'CEIL', 'CEILING', 'CENTROID', 'CHAR', 'CHARACTER_LENGTH', 'CHARSET', 'CHAR_LENGTH', |
|
79 | - 'COALESCE', 'COERCIBILITY', 'COLLATION', 'COMPRESS', 'CONCAT', 'CONCAT_WS', 'CONNECTION_ID', 'CONTAINS', 'CONV', 'CONVERT', 'CONVERT_TZ', |
|
80 | - 'CONVEXHULL', 'COS', 'COT', 'COUNT', 'CRC32', 'CROSSES', 'CURDATE', 'CURRENT_DATE', 'CURRENT_TIME', 'CURRENT_TIMESTAMP', 'CURRENT_USER', |
|
77 | + 'AVG', 'BDMPOLYFROMTEXT', 'BDMPOLYFROMWKB', 'BDPOLYFROMTEXT', 'BDPOLYFROMWKB', 'BENCHMARK', 'BIN', 'BIT_AND', 'BIT_COUNT', 'BIT_LENGTH', |
|
78 | + 'BIT_OR', 'BIT_XOR', 'BOUNDARY', 'BUFFER', 'CAST', 'CEIL', 'CEILING', 'CENTROID', 'CHAR', 'CHARACTER_LENGTH', 'CHARSET', 'CHAR_LENGTH', |
|
79 | + 'COALESCE', 'COERCIBILITY', 'COLLATION', 'COMPRESS', 'CONCAT', 'CONCAT_WS', 'CONNECTION_ID', 'CONTAINS', 'CONV', 'CONVERT', 'CONVERT_TZ', |
|
80 | + 'CONVEXHULL', 'COS', 'COT', 'COUNT', 'CRC32', 'CROSSES', 'CURDATE', 'CURRENT_DATE', 'CURRENT_TIME', 'CURRENT_TIMESTAMP', 'CURRENT_USER', |
|
81 | 81 | 'CURTIME', 'DATABASE', 'DATE', 'DATEDIFF', 'DATE_ADD', 'DATE_DIFF', 'DATE_FORMAT', 'DATE_SUB', 'DAY', 'DAYNAME', 'DAYOFMONTH', 'DAYOFWEEK', |
82 | 82 | 'DAYOFYEAR', 'DECODE', 'DEFAULT', 'DEGREES', 'DES_DECRYPT', 'DES_ENCRYPT', 'DIFFERENCE', 'DIMENSION', 'DISJOINT', 'DISTANCE', 'ELT', 'ENCODE', |
83 | 83 | 'ENCRYPT', 'ENDPOINT', 'ENVELOPE', 'EQUALS', 'EXP', 'EXPORT_SET', 'EXTERIORRING', 'EXTRACT', 'EXTRACTVALUE', 'FIELD', 'FIND_IN_SET', 'FLOOR', |
84 | 84 | 'FORMAT', 'FOUND_ROWS', 'FROM_DAYS', 'FROM_UNIXTIME', 'GEOMCOLLFROMTEXT', 'GEOMCOLLFROMWKB', 'GEOMETRYCOLLECTION', 'GEOMETRYCOLLECTIONFROMTEXT', |
85 | 85 | 'GEOMETRYCOLLECTIONFROMWKB', 'GEOMETRYFROMTEXT', 'GEOMETRYFROMWKB', 'GEOMETRYN', 'GEOMETRYTYPE', 'GEOMFROMTEXT', 'GEOMFROMWKB', 'GET_FORMAT', |
86 | 86 | 'GET_LOCK', 'GLENGTH', 'GREATEST', 'GROUP_CONCAT', 'GROUP_UNIQUE_USERS', 'HEX', 'HOUR', 'IF', 'IFNULL', 'INET_ATON', 'INET_NTOA', 'INSERT', 'INSTR', |
87 | - 'INTERIORRINGN', 'INTERSECTION', 'INTERSECTS', 'INTERVAL', 'ISCLOSED', 'ISEMPTY', 'ISNULL', 'ISRING', 'ISSIMPLE', 'IS_FREE_LOCK', 'IS_USED_LOCK', |
|
87 | + 'INTERIORRINGN', 'INTERSECTION', 'INTERSECTS', 'INTERVAL', 'ISCLOSED', 'ISEMPTY', 'ISNULL', 'ISRING', 'ISSIMPLE', 'IS_FREE_LOCK', 'IS_USED_LOCK', |
|
88 | 88 | 'LAST_DAY', 'LAST_INSERT_ID', 'LCASE', 'LEAST', 'LEFT', 'LENGTH', 'LINEFROMTEXT', 'LINEFROMWKB', 'LINESTRING', 'LINESTRINGFROMTEXT', 'LINESTRINGFROMWKB', |
89 | 89 | 'LN', 'LOAD_FILE', 'LOCALTIME', 'LOCALTIMESTAMP', 'LOCATE', 'LOG', 'LOG10', 'LOG2', 'LOWER', 'LPAD', 'LTRIM', 'MAKEDATE', 'MAKETIME', 'MAKE_SET', |
90 | 90 | 'MASTER_POS_WAIT', 'MAX', 'MBRCONTAINS', 'MBRDISJOINT', 'MBREQUAL', 'MBRINTERSECTS', 'MBROVERLAPS', 'MBRTOUCHES', 'MBRWITHIN', 'MD5', 'MICROSECOND', |
91 | 91 | 'MID', 'MIN', 'MINUTE', 'MLINEFROMTEXT', 'MLINEFROMWKB', 'MOD', 'MONTH', 'MONTHNAME', 'MPOINTFROMTEXT', 'MPOINTFROMWKB', 'MPOLYFROMTEXT', 'MPOLYFROMWKB', |
92 | - 'MULTILINESTRING', 'MULTILINESTRINGFROMTEXT', 'MULTILINESTRINGFROMWKB', 'MULTIPOINT', 'MULTIPOINTFROMTEXT', 'MULTIPOINTFROMWKB', 'MULTIPOLYGON', |
|
93 | - 'MULTIPOLYGONFROMTEXT', 'MULTIPOLYGONFROMWKB', 'NAME_CONST', 'NULLIF', 'NUMGEOMETRIES', 'NUMINTERIORRINGS', 'NUMPOINTS', 'OCT', 'OCTET_LENGTH', |
|
92 | + 'MULTILINESTRING', 'MULTILINESTRINGFROMTEXT', 'MULTILINESTRINGFROMWKB', 'MULTIPOINT', 'MULTIPOINTFROMTEXT', 'MULTIPOINTFROMWKB', 'MULTIPOLYGON', |
|
93 | + 'MULTIPOLYGONFROMTEXT', 'MULTIPOLYGONFROMWKB', 'NAME_CONST', 'NULLIF', 'NUMGEOMETRIES', 'NUMINTERIORRINGS', 'NUMPOINTS', 'OCT', 'OCTET_LENGTH', |
|
94 | 94 | 'OLD_PASSWORD', 'ORD', 'OVERLAPS', 'PASSWORD', 'PERIOD_ADD', 'PERIOD_DIFF', 'PI', 'POINT', 'POINTFROMTEXT', 'POINTFROMWKB', 'POINTN', 'POINTONSURFACE', |
95 | 95 | 'POLYFROMTEXT', 'POLYFROMWKB', 'POLYGON', 'POLYGONFROMTEXT', 'POLYGONFROMWKB', 'POSITION', 'POW', 'POWER', 'QUARTER', 'QUOTE', 'RADIANS', 'RAND', |
96 | 96 | 'RELATED', 'RELEASE_LOCK', 'REPEAT', 'REPLACE', 'REVERSE', 'RIGHT', 'ROUND', 'ROW_COUNT', 'RPAD', 'RTRIM', 'SCHEMA', 'SECOND', 'SEC_TO_TIME', |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | ); |
103 | 103 | |
104 | 104 | // Punctuation that can be used as a boundary between other tokens |
105 | - protected static $boundaries = array(',', ';',':', ')', '(', '.', '=', '<', '>', '+', '-', '*', '/', '!', '^', '%', '|', '&', '#'); |
|
105 | + protected static $boundaries = array(',', ';', ':', ')', '(', '.', '=', '<', '>', '+', '-', '*', '/', '!', '^', '%', '|', '&', '#'); |
|
106 | 106 | |
107 | 107 | // For HTML syntax highlighting |
108 | 108 | // Styles applied to different token types |
@@ -184,12 +184,12 @@ discard block |
||
184 | 184 | self::$reserved = array_keys($reservedMap); |
185 | 185 | |
186 | 186 | // Set up regular expressions |
187 | - self::$regex_boundaries = '('.implode('|',array_map(array(__CLASS__, 'quote_regex'),self::$boundaries)).')'; |
|
188 | - self::$regex_reserved = '('.implode('|',array_map(array(__CLASS__, 'quote_regex'),self::$reserved)).')'; |
|
189 | - self::$regex_reserved_toplevel = str_replace(' ','\\s+','('.implode('|',array_map(array(__CLASS__, 'quote_regex'),self::$reserved_toplevel)).')'); |
|
190 | - self::$regex_reserved_newline = str_replace(' ','\\s+','('.implode('|',array_map(array(__CLASS__, 'quote_regex'),self::$reserved_newline)).')'); |
|
187 | + self::$regex_boundaries = '('.implode('|', array_map(array(__CLASS__, 'quote_regex'), self::$boundaries)).')'; |
|
188 | + self::$regex_reserved = '('.implode('|', array_map(array(__CLASS__, 'quote_regex'), self::$reserved)).')'; |
|
189 | + self::$regex_reserved_toplevel = str_replace(' ', '\\s+', '('.implode('|', array_map(array(__CLASS__, 'quote_regex'), self::$reserved_toplevel)).')'); |
|
190 | + self::$regex_reserved_newline = str_replace(' ', '\\s+', '('.implode('|', array_map(array(__CLASS__, 'quote_regex'), self::$reserved_newline)).')'); |
|
191 | 191 | |
192 | - self::$regex_function = '('.implode('|',array_map(array(__CLASS__, 'quote_regex'),self::$functions)).')'; |
|
192 | + self::$regex_function = '('.implode('|', array_map(array(__CLASS__, 'quote_regex'), self::$functions)).')'; |
|
193 | 193 | |
194 | 194 | self::$init = true; |
195 | 195 | } |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | protected static function getNextToken($string, $previous = null) |
207 | 207 | { |
208 | 208 | // Whitespace |
209 | - if (preg_match('/^\s+/',$string,$matches)) { |
|
209 | + if (preg_match('/^\s+/', $string, $matches)) { |
|
210 | 210 | return array( |
211 | 211 | self::TOKEN_VALUE => $matches[0], |
212 | 212 | self::TOKEN_TYPE=>self::TOKEN_TYPE_WHITESPACE |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | } |
215 | 215 | |
216 | 216 | // Comment |
217 | - if ($string[0] === '#' || (isset($string[1])&&($string[0]==='-'&&$string[1]==='-') || ($string[0]==='/'&&$string[1]==='*'))) { |
|
217 | + if ($string[0] === '#' || (isset($string[1]) && ($string[0] === '-' && $string[1] === '-') || ($string[0] === '/' && $string[1] === '*'))) { |
|
218 | 218 | // Comment until end of line |
219 | 219 | if ($string[0] === '-' || $string[0] === '#') { |
220 | 220 | $last = strpos($string, "\n"); |
@@ -235,9 +235,9 @@ discard block |
||
235 | 235 | } |
236 | 236 | |
237 | 237 | // Quoted String |
238 | - if ($string[0]==='"' || $string[0]==='\'' || $string[0]==='`' || $string[0]==='[') { |
|
238 | + if ($string[0] === '"' || $string[0] === '\'' || $string[0] === '`' || $string[0] === '[') { |
|
239 | 239 | $return = array( |
240 | - self::TOKEN_TYPE => (($string[0]==='`' || $string[0]==='[')? self::TOKEN_TYPE_BACKTICK_QUOTE : self::TOKEN_TYPE_QUOTE), |
|
240 | + self::TOKEN_TYPE => (($string[0] === '`' || $string[0] === '[') ? self::TOKEN_TYPE_BACKTICK_QUOTE : self::TOKEN_TYPE_QUOTE), |
|
241 | 241 | self::TOKEN_VALUE => self::getQuotedString($string) |
242 | 242 | ); |
243 | 243 | |
@@ -252,22 +252,22 @@ discard block |
||
252 | 252 | ); |
253 | 253 | |
254 | 254 | // If the variable name is quoted |
255 | - if ($string[1]==='"' || $string[1]==='\'' || $string[1]==='`') { |
|
256 | - $ret[self::TOKEN_VALUE] = $string[0].self::getQuotedString(substr($string,1)); |
|
255 | + if ($string[1] === '"' || $string[1] === '\'' || $string[1] === '`') { |
|
256 | + $ret[self::TOKEN_VALUE] = $string[0].self::getQuotedString(substr($string, 1)); |
|
257 | 257 | } |
258 | 258 | // Non-quoted variable name |
259 | 259 | else { |
260 | - preg_match('/^('.$string[0].'[a-zA-Z0-9\._\$]+)/',$string,$matches); |
|
260 | + preg_match('/^('.$string[0].'[a-zA-Z0-9\._\$]+)/', $string, $matches); |
|
261 | 261 | if ($matches) { |
262 | 262 | $ret[self::TOKEN_VALUE] = $matches[1]; |
263 | 263 | } |
264 | 264 | } |
265 | 265 | |
266 | - if($ret[self::TOKEN_VALUE] !== null) return $ret; |
|
266 | + if ($ret[self::TOKEN_VALUE] !== null) return $ret; |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | // Number (decimal, binary, or hex) |
270 | - if (preg_match('/^([0-9]+(\.[0-9]+)?|0x[0-9a-fA-F]+|0b[01]+)($|\s|"\'`|'.self::$regex_boundaries.')/',$string,$matches)) { |
|
270 | + if (preg_match('/^([0-9]+(\.[0-9]+)?|0x[0-9a-fA-F]+|0b[01]+)($|\s|"\'`|'.self::$regex_boundaries.')/', $string, $matches)) { |
|
271 | 271 | return array( |
272 | 272 | self::TOKEN_VALUE => $matches[1], |
273 | 273 | self::TOKEN_TYPE=>self::TOKEN_TYPE_NUMBER |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | } |
276 | 276 | |
277 | 277 | // Boundary Character (punctuation and symbols) |
278 | - if (preg_match('/^('.self::$regex_boundaries.')/',$string,$matches)) { |
|
278 | + if (preg_match('/^('.self::$regex_boundaries.')/', $string, $matches)) { |
|
279 | 279 | return array( |
280 | 280 | self::TOKEN_VALUE => $matches[1], |
281 | 281 | self::TOKEN_TYPE => self::TOKEN_TYPE_BOUNDARY |
@@ -287,24 +287,24 @@ discard block |
||
287 | 287 | if (!$previous || !isset($previous[self::TOKEN_VALUE]) || $previous[self::TOKEN_VALUE] !== '.') { |
288 | 288 | $upper = strtoupper($string); |
289 | 289 | // Top Level Reserved Word |
290 | - if (preg_match('/^('.self::$regex_reserved_toplevel.')($|\s|'.self::$regex_boundaries.')/', $upper,$matches)) { |
|
290 | + if (preg_match('/^('.self::$regex_reserved_toplevel.')($|\s|'.self::$regex_boundaries.')/', $upper, $matches)) { |
|
291 | 291 | return array( |
292 | 292 | self::TOKEN_TYPE=>self::TOKEN_TYPE_RESERVED_TOPLEVEL, |
293 | - self::TOKEN_VALUE=>substr($string,0,strlen($matches[1])) |
|
293 | + self::TOKEN_VALUE=>substr($string, 0, strlen($matches[1])) |
|
294 | 294 | ); |
295 | 295 | } |
296 | 296 | // Newline Reserved Word |
297 | - if (preg_match('/^('.self::$regex_reserved_newline.')($|\s|'.self::$regex_boundaries.')/', $upper,$matches)) { |
|
297 | + if (preg_match('/^('.self::$regex_reserved_newline.')($|\s|'.self::$regex_boundaries.')/', $upper, $matches)) { |
|
298 | 298 | return array( |
299 | 299 | self::TOKEN_TYPE=>self::TOKEN_TYPE_RESERVED_NEWLINE, |
300 | - self::TOKEN_VALUE=>substr($string,0,strlen($matches[1])) |
|
300 | + self::TOKEN_VALUE=>substr($string, 0, strlen($matches[1])) |
|
301 | 301 | ); |
302 | 302 | } |
303 | 303 | // Other Reserved Word |
304 | - if (preg_match('/^('.self::$regex_reserved.')($|\s|'.self::$regex_boundaries.')/', $upper,$matches)) { |
|
304 | + if (preg_match('/^('.self::$regex_reserved.')($|\s|'.self::$regex_boundaries.')/', $upper, $matches)) { |
|
305 | 305 | return array( |
306 | 306 | self::TOKEN_TYPE=>self::TOKEN_TYPE_RESERVED, |
307 | - self::TOKEN_VALUE=>substr($string,0,strlen($matches[1])) |
|
307 | + self::TOKEN_VALUE=>substr($string, 0, strlen($matches[1])) |
|
308 | 308 | ); |
309 | 309 | } |
310 | 310 | } |
@@ -313,15 +313,15 @@ discard block |
||
313 | 313 | // this makes it so "count(" is considered a function, but "count" alone is not |
314 | 314 | $upper = strtoupper($string); |
315 | 315 | // function |
316 | - if (preg_match('/^('.self::$regex_function.'[(]|\s|[)])/', $upper,$matches)) { |
|
316 | + if (preg_match('/^('.self::$regex_function.'[(]|\s|[)])/', $upper, $matches)) { |
|
317 | 317 | return array( |
318 | 318 | self::TOKEN_TYPE=>self::TOKEN_TYPE_RESERVED, |
319 | - self::TOKEN_VALUE=>substr($string,0,strlen($matches[1])-1) |
|
319 | + self::TOKEN_VALUE=>substr($string, 0, strlen($matches[1]) - 1) |
|
320 | 320 | ); |
321 | 321 | } |
322 | 322 | |
323 | 323 | // Non reserved word |
324 | - preg_match('/^(.*?)($|\s|["\'`]|'.self::$regex_boundaries.')/',$string,$matches); |
|
324 | + preg_match('/^(.*?)($|\s|["\'`]|'.self::$regex_boundaries.')/', $string, $matches); |
|
325 | 325 | |
326 | 326 | return array( |
327 | 327 | self::TOKEN_VALUE => $matches[1], |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | // 2. square bracket quoted string (SQL Server) using ]] to escape |
339 | 339 | // 3. double quoted string using "" or \" to escape |
340 | 340 | // 4. single quoted string using '' or \' to escape |
341 | - if ( preg_match('/^(((`[^`]*($|`))+)|((\[[^\]]*($|\]))(\][^\]]*($|\]))*)|(("[^"\\\\]*(?:\\\\.[^"\\\\]*)*("|$))+)|((\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*(\'|$))+))/s', $string, $matches)) { |
|
341 | + if (preg_match('/^(((`[^`]*($|`))+)|((\[[^\]]*($|\]))(\][^\]]*($|\]))*)|(("[^"\\\\]*(?:\\\\.[^"\\\\]*)*("|$))+)|((\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*(\'|$))+))/s', $string, $matches)) { |
|
342 | 342 | $ret = $matches[1]; |
343 | 343 | } |
344 | 344 | |
@@ -377,11 +377,11 @@ discard block |
||
377 | 377 | |
378 | 378 | return $tokens; |
379 | 379 | } |
380 | - $old_string_len = $current_length; |
|
380 | + $old_string_len = $current_length; |
|
381 | 381 | |
382 | 382 | // Determine if we can use caching |
383 | 383 | if ($current_length >= self::$max_cachekey_size) { |
384 | - $cacheKey = substr($string,0,self::$max_cachekey_size); |
|
384 | + $cacheKey = substr($string, 0, self::$max_cachekey_size); |
|
385 | 385 | } else { |
386 | 386 | $cacheKey = false; |
387 | 387 | } |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | * |
424 | 424 | * @return String The SQL string with HTML styles and formatting wrapped in a <pre> tag |
425 | 425 | */ |
426 | - public static function format($string, $highlight=true) |
|
426 | + public static function format($string, $highlight = true) |
|
427 | 427 | { |
428 | 428 | // This variable will be populated with formatted html |
429 | 429 | $return = ''; |
@@ -466,18 +466,18 @@ discard block |
||
466 | 466 | if ($increase_special_indent) { |
467 | 467 | $indent_level++; |
468 | 468 | $increase_special_indent = false; |
469 | - array_unshift($indent_types,'special'); |
|
469 | + array_unshift($indent_types, 'special'); |
|
470 | 470 | } |
471 | 471 | // If we are increasing the block indent level now |
472 | 472 | if ($increase_block_indent) { |
473 | 473 | $indent_level++; |
474 | 474 | $increase_block_indent = false; |
475 | - array_unshift($indent_types,'block'); |
|
475 | + array_unshift($indent_types, 'block'); |
|
476 | 476 | } |
477 | 477 | |
478 | 478 | // If we need a new line before the token |
479 | 479 | if ($newline) { |
480 | - $return .= "\n" . str_repeat($tab, $indent_level); |
|
480 | + $return .= "\n".str_repeat($tab, $indent_level); |
|
481 | 481 | $newline = false; |
482 | 482 | $added_newline = true; |
483 | 483 | } else { |
@@ -487,9 +487,9 @@ discard block |
||
487 | 487 | // Display comments directly where they appear in the source |
488 | 488 | if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) { |
489 | 489 | if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) { |
490 | - $indent = str_repeat($tab,$indent_level); |
|
491 | - $return .= "\n" . $indent; |
|
492 | - $highlighted = str_replace("\n","\n".$indent,$highlighted); |
|
490 | + $indent = str_repeat($tab, $indent_level); |
|
491 | + $return .= "\n".$indent; |
|
492 | + $highlighted = str_replace("\n", "\n".$indent, $highlighted); |
|
493 | 493 | } |
494 | 494 | |
495 | 495 | $return .= $highlighted; |
@@ -500,17 +500,17 @@ discard block |
||
500 | 500 | if ($inline_parentheses) { |
501 | 501 | // End of inline parentheses |
502 | 502 | if ($token[self::TOKEN_VALUE] === ')') { |
503 | - $return = rtrim($return,' '); |
|
503 | + $return = rtrim($return, ' '); |
|
504 | 504 | |
505 | 505 | if ($inline_indented) { |
506 | 506 | array_shift($indent_types); |
507 | - $indent_level --; |
|
508 | - $return .= "\n" . str_repeat($tab, $indent_level); |
|
507 | + $indent_level--; |
|
508 | + $return .= "\n".str_repeat($tab, $indent_level); |
|
509 | 509 | } |
510 | 510 | |
511 | 511 | $inline_parentheses = false; |
512 | 512 | |
513 | - $return .= $highlighted . ' '; |
|
513 | + $return .= $highlighted.' '; |
|
514 | 514 | continue; |
515 | 515 | } |
516 | 516 | |
@@ -530,11 +530,11 @@ discard block |
||
530 | 530 | // Examples are "NOW()", "COUNT(*)", "int(10)", key(`somecolumn`), DECIMAL(7,2) |
531 | 531 | // Allow up to 3 non-whitespace tokens inside inline parentheses |
532 | 532 | $length = 0; |
533 | - for ($j=1;$j<=250;$j++) { |
|
533 | + for ($j = 1; $j <= 250; $j++) { |
|
534 | 534 | // Reached end of string |
535 | - if (!isset($tokens[$i+$j])) break; |
|
535 | + if (!isset($tokens[$i + $j])) break; |
|
536 | 536 | |
537 | - $next = $tokens[$i+$j]; |
|
537 | + $next = $tokens[$i + $j]; |
|
538 | 538 | |
539 | 539 | // Reached closing parentheses, able to inline it |
540 | 540 | if ($next[self::TOKEN_VALUE] === ')') { |
@@ -545,12 +545,12 @@ discard block |
||
545 | 545 | } |
546 | 546 | |
547 | 547 | // Reached an invalid token for inline parentheses |
548 | - if ($next[self::TOKEN_VALUE]===';' || $next[self::TOKEN_VALUE]==='(') { |
|
548 | + if ($next[self::TOKEN_VALUE] === ';' || $next[self::TOKEN_VALUE] === '(') { |
|
549 | 549 | break; |
550 | 550 | } |
551 | 551 | |
552 | 552 | // Reached an invalid token type for inline parentheses |
553 | - 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) { |
|
553 | + 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) { |
|
554 | 554 | break; |
555 | 555 | } |
556 | 556 | |
@@ -564,8 +564,8 @@ discard block |
||
564 | 564 | } |
565 | 565 | |
566 | 566 | // Take out the preceding space unless there was whitespace there in the original query |
567 | - if (isset($original_tokens[$token['i']-1]) && $original_tokens[$token['i']-1][self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) { |
|
568 | - $return = rtrim($return,' '); |
|
567 | + if (isset($original_tokens[$token['i'] - 1]) && $original_tokens[$token['i'] - 1][self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) { |
|
568 | + $return = rtrim($return, ' '); |
|
569 | 569 | } |
570 | 570 | |
571 | 571 | if (!$inline_parentheses) { |
@@ -579,13 +579,13 @@ discard block |
||
579 | 579 | // Closing parentheses decrease the block indent level |
580 | 580 | elseif ($token[self::TOKEN_VALUE] === ')') { |
581 | 581 | // Remove whitespace before the closing parentheses |
582 | - $return = rtrim($return,' '); |
|
582 | + $return = rtrim($return, ' '); |
|
583 | 583 | |
584 | 584 | $indent_level--; |
585 | 585 | |
586 | 586 | // Reset indent level |
587 | - while ($j=array_shift($indent_types)) { |
|
588 | - if ($j==='special') { |
|
587 | + while ($j = array_shift($indent_types)) { |
|
588 | + if ($j === 'special') { |
|
589 | 589 | $indent_level--; |
590 | 590 | } else { |
591 | 591 | break; |
@@ -604,7 +604,7 @@ discard block |
||
604 | 604 | |
605 | 605 | // Add a newline before the closing parentheses (if not already added) |
606 | 606 | if (!$added_newline) { |
607 | - $return .= "\n" . str_repeat($tab, $indent_level); |
|
607 | + $return .= "\n".str_repeat($tab, $indent_level); |
|
608 | 608 | } |
609 | 609 | } |
610 | 610 | |
@@ -614,7 +614,7 @@ discard block |
||
614 | 614 | |
615 | 615 | // If the last indent type was 'special', decrease the special indent for this round |
616 | 616 | reset($indent_types); |
617 | - if (current($indent_types)==='special') { |
|
617 | + if (current($indent_types) === 'special') { |
|
618 | 618 | $indent_level--; |
619 | 619 | array_shift($indent_types); |
620 | 620 | } |
@@ -623,16 +623,16 @@ discard block |
||
623 | 623 | $newline = true; |
624 | 624 | // Add a newline before the top level reserved word (if not already added) |
625 | 625 | if (!$added_newline) { |
626 | - $return .= "\n" . str_repeat($tab, $indent_level); |
|
626 | + $return .= "\n".str_repeat($tab, $indent_level); |
|
627 | 627 | } |
628 | 628 | // If we already added a newline, redo the indentation since it may be different now |
629 | 629 | else { |
630 | - $return = rtrim($return,$tab).str_repeat($tab, $indent_level); |
|
630 | + $return = rtrim($return, $tab).str_repeat($tab, $indent_level); |
|
631 | 631 | } |
632 | 632 | |
633 | 633 | // If the token may have extra whitespace |
634 | - if (strpos($token[self::TOKEN_VALUE],' ')!==false || strpos($token[self::TOKEN_VALUE],"\n")!==false || strpos($token[self::TOKEN_VALUE],"\t")!==false) { |
|
635 | - $highlighted = preg_replace('/\s+/',' ',$highlighted); |
|
634 | + if (strpos($token[self::TOKEN_VALUE], ' ') !== false || strpos($token[self::TOKEN_VALUE], "\n") !== false || strpos($token[self::TOKEN_VALUE], "\t") !== false) { |
|
635 | + $highlighted = preg_replace('/\s+/', ' ', $highlighted); |
|
636 | 636 | } |
637 | 637 | //if SQL 'LIMIT' clause, start variable to reset newline |
638 | 638 | if ($token[self::TOKEN_VALUE] === 'LIMIT' && !$inline_parentheses) { |
@@ -662,20 +662,20 @@ discard block |
||
662 | 662 | elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE) { |
663 | 663 | // Add a newline before the reserved word (if not already added) |
664 | 664 | if (!$added_newline) { |
665 | - $return .= "\n" . str_repeat($tab, $indent_level); |
|
665 | + $return .= "\n".str_repeat($tab, $indent_level); |
|
666 | 666 | } |
667 | 667 | |
668 | 668 | // If the token may have extra whitespace |
669 | - if (strpos($token[self::TOKEN_VALUE],' ')!==false || strpos($token[self::TOKEN_VALUE],"\n")!==false || strpos($token[self::TOKEN_VALUE],"\t")!==false) { |
|
670 | - $highlighted = preg_replace('/\s+/',' ',$highlighted); |
|
669 | + if (strpos($token[self::TOKEN_VALUE], ' ') !== false || strpos($token[self::TOKEN_VALUE], "\n") !== false || strpos($token[self::TOKEN_VALUE], "\t") !== false) { |
|
670 | + $highlighted = preg_replace('/\s+/', ' ', $highlighted); |
|
671 | 671 | } |
672 | 672 | } |
673 | 673 | |
674 | 674 | // Multiple boundary characters in a row should not have spaces between them (not including parentheses) |
675 | 675 | elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BOUNDARY) { |
676 | - if (isset($tokens[$i-1]) && $tokens[$i-1][self::TOKEN_TYPE] === self::TOKEN_TYPE_BOUNDARY) { |
|
677 | - if (isset($original_tokens[$token['i']-1]) && $original_tokens[$token['i']-1][self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) { |
|
678 | - $return = rtrim($return,' '); |
|
676 | + if (isset($tokens[$i - 1]) && $tokens[$i - 1][self::TOKEN_TYPE] === self::TOKEN_TYPE_BOUNDARY) { |
|
677 | + if (isset($original_tokens[$token['i'] - 1]) && $original_tokens[$token['i'] - 1][self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) { |
|
678 | + $return = rtrim($return, ' '); |
|
679 | 679 | } |
680 | 680 | } |
681 | 681 | } |
@@ -689,25 +689,25 @@ discard block |
||
689 | 689 | |
690 | 690 | // If the token shouldn't have a space after it |
691 | 691 | if ($token[self::TOKEN_VALUE] === '(' || $token[self::TOKEN_VALUE] === '.') { |
692 | - $return = rtrim($return,' '); |
|
692 | + $return = rtrim($return, ' '); |
|
693 | 693 | } |
694 | 694 | |
695 | 695 | // If this is the "-" of a negative number, it shouldn't have a space after it |
696 | - if($token[self::TOKEN_VALUE] === '-' && isset($tokens[$i+1]) && $tokens[$i+1][self::TOKEN_TYPE] === self::TOKEN_TYPE_NUMBER && isset($tokens[$i-1])) { |
|
697 | - $prev = $tokens[$i-1][self::TOKEN_TYPE]; |
|
698 | - if($prev !== self::TOKEN_TYPE_QUOTE && $prev !== self::TOKEN_TYPE_BACKTICK_QUOTE && $prev !== self::TOKEN_TYPE_WORD && $prev !== self::TOKEN_TYPE_NUMBER) { |
|
699 | - $return = rtrim($return,' '); |
|
696 | + if ($token[self::TOKEN_VALUE] === '-' && isset($tokens[$i + 1]) && $tokens[$i + 1][self::TOKEN_TYPE] === self::TOKEN_TYPE_NUMBER && isset($tokens[$i - 1])) { |
|
697 | + $prev = $tokens[$i - 1][self::TOKEN_TYPE]; |
|
698 | + if ($prev !== self::TOKEN_TYPE_QUOTE && $prev !== self::TOKEN_TYPE_BACKTICK_QUOTE && $prev !== self::TOKEN_TYPE_WORD && $prev !== self::TOKEN_TYPE_NUMBER) { |
|
699 | + $return = rtrim($return, ' '); |
|
700 | 700 | } |
701 | 701 | } |
702 | 702 | } |
703 | 703 | |
704 | 704 | // If there are unmatched parentheses |
705 | - if ($highlight && array_search('block',$indent_types) !== false) { |
|
705 | + if ($highlight && array_search('block', $indent_types) !== false) { |
|
706 | 706 | $return .= "\n".self::highlightError("WARNING: unclosed parentheses or section"); |
707 | 707 | } |
708 | 708 | |
709 | 709 | // Replace tab characters with the configuration tab character |
710 | - $return = trim(str_replace("\t",self::$tab,$return)); |
|
710 | + $return = trim(str_replace("\t", self::$tab, $return)); |
|
711 | 711 | |
712 | 712 | if ($highlight) { |
713 | 713 | $return = self::output($return); |
@@ -799,7 +799,7 @@ discard block |
||
799 | 799 | |
800 | 800 | $result .= $token[self::TOKEN_VALUE]; |
801 | 801 | } |
802 | - $result = self::format( $result,false); |
|
802 | + $result = self::format($result, false); |
|
803 | 803 | |
804 | 804 | return $result; |
805 | 805 | } |
@@ -825,7 +825,7 @@ discard block |
||
825 | 825 | } |
826 | 826 | // Remove extra whitespace in reserved words (e.g "OUTER JOIN" becomes "OUTER JOIN") |
827 | 827 | 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) { |
828 | - $token[self::TOKEN_VALUE] = preg_replace('/\s+/',' ',$token[self::TOKEN_VALUE]); |
|
828 | + $token[self::TOKEN_VALUE] = preg_replace('/\s+/', ' ', $token[self::TOKEN_VALUE]); |
|
829 | 829 | } |
830 | 830 | |
831 | 831 | if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_WHITESPACE) { |
@@ -862,31 +862,31 @@ discard block |
||
862 | 862 | $token = $token[self::TOKEN_VALUE]; |
863 | 863 | } else { |
864 | 864 | if (defined('ENT_IGNORE')) { |
865 | - $token = htmlentities($token[self::TOKEN_VALUE],ENT_COMPAT | ENT_IGNORE ,'UTF-8'); |
|
865 | + $token = htmlentities($token[self::TOKEN_VALUE], ENT_COMPAT | ENT_IGNORE, 'UTF-8'); |
|
866 | 866 | } else { |
867 | - $token = htmlentities($token[self::TOKEN_VALUE],ENT_COMPAT,'UTF-8'); |
|
867 | + $token = htmlentities($token[self::TOKEN_VALUE], ENT_COMPAT, 'UTF-8'); |
|
868 | 868 | } |
869 | 869 | } |
870 | 870 | |
871 | - if ($type===self::TOKEN_TYPE_BOUNDARY) { |
|
871 | + if ($type === self::TOKEN_TYPE_BOUNDARY) { |
|
872 | 872 | return self::highlightBoundary($token); |
873 | - } elseif ($type===self::TOKEN_TYPE_WORD) { |
|
873 | + } elseif ($type === self::TOKEN_TYPE_WORD) { |
|
874 | 874 | return self::highlightWord($token); |
875 | - } elseif ($type===self::TOKEN_TYPE_BACKTICK_QUOTE) { |
|
875 | + } elseif ($type === self::TOKEN_TYPE_BACKTICK_QUOTE) { |
|
876 | 876 | return self::highlightBacktickQuote($token); |
877 | - } elseif ($type===self::TOKEN_TYPE_QUOTE) { |
|
877 | + } elseif ($type === self::TOKEN_TYPE_QUOTE) { |
|
878 | 878 | return self::highlightQuote($token); |
879 | - } elseif ($type===self::TOKEN_TYPE_RESERVED) { |
|
879 | + } elseif ($type === self::TOKEN_TYPE_RESERVED) { |
|
880 | 880 | return self::highlightReservedWord($token); |
881 | - } elseif ($type===self::TOKEN_TYPE_RESERVED_TOPLEVEL) { |
|
881 | + } elseif ($type === self::TOKEN_TYPE_RESERVED_TOPLEVEL) { |
|
882 | 882 | return self::highlightReservedWord($token); |
883 | - } elseif ($type===self::TOKEN_TYPE_RESERVED_NEWLINE) { |
|
883 | + } elseif ($type === self::TOKEN_TYPE_RESERVED_NEWLINE) { |
|
884 | 884 | return self::highlightReservedWord($token); |
885 | - } elseif ($type===self::TOKEN_TYPE_NUMBER) { |
|
885 | + } elseif ($type === self::TOKEN_TYPE_NUMBER) { |
|
886 | 886 | return self::highlightNumber($token); |
887 | - } elseif ($type===self::TOKEN_TYPE_VARIABLE) { |
|
887 | + } elseif ($type === self::TOKEN_TYPE_VARIABLE) { |
|
888 | 888 | return self::highlightVariable($token); |
889 | - } elseif ($type===self::TOKEN_TYPE_COMMENT || $type===self::TOKEN_TYPE_BLOCK_COMMENT) { |
|
889 | + } elseif ($type === self::TOKEN_TYPE_COMMENT || $type === self::TOKEN_TYPE_BLOCK_COMMENT) { |
|
890 | 890 | return self::highlightComment($token); |
891 | 891 | } |
892 | 892 | |
@@ -903,9 +903,9 @@ discard block |
||
903 | 903 | protected static function highlightQuote($value) |
904 | 904 | { |
905 | 905 | if (self::is_cli()) { |
906 | - return self::$cli_quote . $value . "\x1b[0m"; |
|
906 | + return self::$cli_quote.$value."\x1b[0m"; |
|
907 | 907 | } else { |
908 | - return '<span ' . self::$quote_attributes . '>' . $value . '</span>'; |
|
908 | + return '<span '.self::$quote_attributes.'>'.$value.'</span>'; |
|
909 | 909 | } |
910 | 910 | } |
911 | 911 | |
@@ -919,9 +919,9 @@ discard block |
||
919 | 919 | protected static function highlightBacktickQuote($value) |
920 | 920 | { |
921 | 921 | if (self::is_cli()) { |
922 | - return self::$cli_backtick_quote . $value . "\x1b[0m"; |
|
922 | + return self::$cli_backtick_quote.$value."\x1b[0m"; |
|
923 | 923 | } else { |
924 | - return '<span ' . self::$backtick_quote_attributes . '>' . $value . '</span>'; |
|
924 | + return '<span '.self::$backtick_quote_attributes.'>'.$value.'</span>'; |
|
925 | 925 | } |
926 | 926 | } |
927 | 927 | |
@@ -935,9 +935,9 @@ discard block |
||
935 | 935 | protected static function highlightReservedWord($value) |
936 | 936 | { |
937 | 937 | if (self::is_cli()) { |
938 | - return self::$cli_reserved . $value . "\x1b[0m"; |
|
938 | + return self::$cli_reserved.$value."\x1b[0m"; |
|
939 | 939 | } else { |
940 | - return '<span ' . self::$reserved_attributes . '>' . $value . '</span>'; |
|
940 | + return '<span '.self::$reserved_attributes.'>'.$value.'</span>'; |
|
941 | 941 | } |
942 | 942 | } |
943 | 943 | |
@@ -950,12 +950,12 @@ discard block |
||
950 | 950 | */ |
951 | 951 | protected static function highlightBoundary($value) |
952 | 952 | { |
953 | - if ($value==='(' || $value===')') return $value; |
|
953 | + if ($value === '(' || $value === ')') return $value; |
|
954 | 954 | |
955 | 955 | if (self::is_cli()) { |
956 | - return self::$cli_boundary . $value . "\x1b[0m"; |
|
956 | + return self::$cli_boundary.$value."\x1b[0m"; |
|
957 | 957 | } else { |
958 | - return '<span ' . self::$boundary_attributes . '>' . $value . '</span>'; |
|
958 | + return '<span '.self::$boundary_attributes.'>'.$value.'</span>'; |
|
959 | 959 | } |
960 | 960 | } |
961 | 961 | |
@@ -969,9 +969,9 @@ discard block |
||
969 | 969 | protected static function highlightNumber($value) |
970 | 970 | { |
971 | 971 | if (self::is_cli()) { |
972 | - return self::$cli_number . $value . "\x1b[0m"; |
|
972 | + return self::$cli_number.$value."\x1b[0m"; |
|
973 | 973 | } else { |
974 | - return '<span ' . self::$number_attributes . '>' . $value . '</span>'; |
|
974 | + return '<span '.self::$number_attributes.'>'.$value.'</span>'; |
|
975 | 975 | } |
976 | 976 | } |
977 | 977 | |
@@ -985,9 +985,9 @@ discard block |
||
985 | 985 | protected static function highlightError($value) |
986 | 986 | { |
987 | 987 | if (self::is_cli()) { |
988 | - return self::$cli_error . $value . "\x1b[0m"; |
|
988 | + return self::$cli_error.$value."\x1b[0m"; |
|
989 | 989 | } else { |
990 | - return '<span ' . self::$error_attributes . '>' . $value . '</span>'; |
|
990 | + return '<span '.self::$error_attributes.'>'.$value.'</span>'; |
|
991 | 991 | } |
992 | 992 | } |
993 | 993 | |
@@ -1001,9 +1001,9 @@ discard block |
||
1001 | 1001 | protected static function highlightComment($value) |
1002 | 1002 | { |
1003 | 1003 | if (self::is_cli()) { |
1004 | - return self::$cli_comment . $value . "\x1b[0m"; |
|
1004 | + return self::$cli_comment.$value."\x1b[0m"; |
|
1005 | 1005 | } else { |
1006 | - return '<span ' . self::$comment_attributes . '>' . $value . '</span>'; |
|
1006 | + return '<span '.self::$comment_attributes.'>'.$value.'</span>'; |
|
1007 | 1007 | } |
1008 | 1008 | } |
1009 | 1009 | |
@@ -1017,9 +1017,9 @@ discard block |
||
1017 | 1017 | protected static function highlightWord($value) |
1018 | 1018 | { |
1019 | 1019 | if (self::is_cli()) { |
1020 | - return self::$cli_word . $value . "\x1b[0m"; |
|
1020 | + return self::$cli_word.$value."\x1b[0m"; |
|
1021 | 1021 | } else { |
1022 | - return '<span ' . self::$word_attributes . '>' . $value . '</span>'; |
|
1022 | + return '<span '.self::$word_attributes.'>'.$value.'</span>'; |
|
1023 | 1023 | } |
1024 | 1024 | } |
1025 | 1025 | |
@@ -1033,9 +1033,9 @@ discard block |
||
1033 | 1033 | protected static function highlightVariable($value) |
1034 | 1034 | { |
1035 | 1035 | if (self::is_cli()) { |
1036 | - return self::$cli_variable . $value . "\x1b[0m"; |
|
1036 | + return self::$cli_variable.$value."\x1b[0m"; |
|
1037 | 1037 | } else { |
1038 | - return '<span ' . self::$variable_attributes . '>' . $value . '</span>'; |
|
1038 | + return '<span '.self::$variable_attributes.'>'.$value.'</span>'; |
|
1039 | 1039 | } |
1040 | 1040 | } |
1041 | 1041 | |
@@ -1048,7 +1048,7 @@ discard block |
||
1048 | 1048 | */ |
1049 | 1049 | private static function quote_regex($a) |
1050 | 1050 | { |
1051 | - return preg_quote($a,'/'); |
|
1051 | + return preg_quote($a, '/'); |
|
1052 | 1052 | } |
1053 | 1053 | |
1054 | 1054 | /** |
@@ -1063,12 +1063,12 @@ discard block |
||
1063 | 1063 | if (self::is_cli()) { |
1064 | 1064 | return $string."\n"; |
1065 | 1065 | } else { |
1066 | - $string=trim($string); |
|
1066 | + $string = trim($string); |
|
1067 | 1067 | if (!self::$use_pre) { |
1068 | 1068 | return $string; |
1069 | 1069 | } |
1070 | 1070 | |
1071 | - return '<pre '.self::$pre_attributes.'>' . $string . '</pre>'; |
|
1071 | + return '<pre '.self::$pre_attributes.'>'.$string.'</pre>'; |
|
1072 | 1072 | } |
1073 | 1073 | } |
1074 | 1074 |
@@ -212,7 +212,7 @@ |
||
212 | 212 | /** |
213 | 213 | * Reduce the collection to a single value. |
214 | 214 | * |
215 | - * @param callable $callback |
|
215 | + * @param Closure $callback |
|
216 | 216 | * @param mixed $initial |
217 | 217 | * @return mixed |
218 | 218 | */ |
@@ -9,10 +9,10 @@ discard block |
||
9 | 9 | class Collection implements \Countable, \IteratorAggregate, \ArrayAccess{ |
10 | 10 | protected $data = array(); |
11 | 11 | |
12 | - public function __construct(array $data = array()){ |
|
12 | + public function __construct(array $data = array()) { |
|
13 | 13 | $this->data = $data; |
14 | 14 | } |
15 | - public function create(array $data = array()){ |
|
15 | + public function create(array $data = array()) { |
|
16 | 16 | return new static($data); |
17 | 17 | } |
18 | 18 | public function getIterator() |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | public function forAll(Closure $p) |
39 | 39 | { |
40 | 40 | foreach ($this->data as $key => $element) { |
41 | - if ( ! $p($key, $element)) { |
|
41 | + if (!$p($key, $element)) { |
|
42 | 42 | return false; |
43 | 43 | } |
44 | 44 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | { |
65 | 65 | return empty($this->data); |
66 | 66 | } |
67 | - public function clear(){ |
|
67 | + public function clear() { |
|
68 | 68 | $this->data = array(); |
69 | 69 | return $this; |
70 | 70 | } |
@@ -72,20 +72,20 @@ discard block |
||
72 | 72 | $this->data[] = $value; |
73 | 73 | return $this; |
74 | 74 | } |
75 | - public function add($data, $id = null){ |
|
76 | - if((is_int($id) || is_string($id)) && $id !== ''){ |
|
75 | + public function add($data, $id = null) { |
|
76 | + if ((is_int($id) || is_string($id)) && $id !== '') { |
|
77 | 77 | $this->data[$id] = $data; |
78 | - }else{ |
|
78 | + } else { |
|
79 | 79 | $this->append($data); |
80 | 80 | } |
81 | 81 | return $this; |
82 | 82 | } |
83 | - public function count(){ |
|
83 | + public function count() { |
|
84 | 84 | return count($this->data); |
85 | 85 | } |
86 | - public function get($id){ |
|
86 | + public function get($id) { |
|
87 | 87 | $out = null; |
88 | - if(is_scalar($id) && $id!=='' && $this->containsKey($id)){ |
|
88 | + if (is_scalar($id) && $id !== '' && $this->containsKey($id)) { |
|
89 | 89 | $out = $this->data[$id]; |
90 | 90 | } |
91 | 91 | return $out; |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | { |
109 | 109 | return key($this->data); |
110 | 110 | } |
111 | - public function prev(){ |
|
111 | + public function prev() { |
|
112 | 112 | return prev($this->data); |
113 | 113 | } |
114 | 114 | |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | |
125 | 125 | public function remove($key) |
126 | 126 | { |
127 | - if ( ! isset($this->data[$key]) && ! array_key_exists($key, $this->data)) { |
|
127 | + if (!isset($this->data[$key]) && !array_key_exists($key, $this->data)) { |
|
128 | 128 | return null; |
129 | 129 | } |
130 | 130 | $removed = $this->data[$key]; |
@@ -146,10 +146,10 @@ discard block |
||
146 | 146 | { |
147 | 147 | return $this->containsKey($offset); |
148 | 148 | } |
149 | - public function dump(){ |
|
149 | + public function dump() { |
|
150 | 150 | return var_dump($this->data); |
151 | 151 | } |
152 | - public function show(){ |
|
152 | + public function show() { |
|
153 | 153 | print_r($this->data); |
154 | 154 | } |
155 | 155 | |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | |
161 | 161 | public function offsetSet($offset, $value) |
162 | 162 | { |
163 | - if ( ! isset($offset)) { |
|
163 | + if (!isset($offset)) { |
|
164 | 164 | return $this->add($value); |
165 | 165 | } |
166 | 166 | $this->set($offset, $value); |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | return array_values($this->data); |
206 | 206 | } |
207 | 207 | |
208 | - public function toArray(){ |
|
208 | + public function toArray() { |
|
209 | 209 | return $this->data; |
210 | 210 | } |
211 | 211 | |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | return $this; |
271 | 271 | } |
272 | 272 | |
273 | - public function reindex(){ |
|
273 | + public function reindex() { |
|
274 | 274 | $this->data = array_values($this->data); |
275 | 275 | return $this; |
276 | 276 | } |
@@ -75,7 +75,7 @@ |
||
75 | 75 | public function add($data, $id = null){ |
76 | 76 | if((is_int($id) || is_string($id)) && $id !== ''){ |
77 | 77 | $this->data[$id] = $data; |
78 | - }else{ |
|
78 | + } else{ |
|
79 | 79 | $this->append($data); |
80 | 80 | } |
81 | 81 | return $this; |
@@ -15,6 +15,10 @@ discard block |
||
15 | 15 | $this->fs = FS::getInstance(); |
16 | 16 | } |
17 | 17 | |
18 | + /** |
|
19 | + * @param string $inputFile |
|
20 | + * @param string $outputFile |
|
21 | + */ |
|
18 | 22 | public function create($inputFile, $outputFile, $options) { |
19 | 23 | $this->thumb->sourceFilename = $inputFile; |
20 | 24 | $ext = explode('.',$inputFile); |
@@ -48,6 +52,9 @@ discard block |
||
48 | 52 | } |
49 | 53 | } |
50 | 54 | |
55 | + /** |
|
56 | + * @param string $options |
|
57 | + */ |
|
51 | 58 | private function setOptions($options) { |
52 | 59 | $options = strtr($options, Array("," => "&", "_" => "=", '{' => '[', '}' => ']')); |
53 | 60 | parse_str($options, $params); |
@@ -7,17 +7,17 @@ discard block |
||
7 | 7 | |
8 | 8 | private $thumb = null; |
9 | 9 | protected $fs = null; |
10 | - public $debugMessages = ''; |
|
10 | + public $debugMessages = ''; |
|
11 | 11 | |
12 | 12 | public function __construct() |
13 | 13 | { |
14 | - $this->thumb = new \phpthumb(); |
|
15 | - $this->fs = FS::getInstance(); |
|
14 | + $this->thumb = new \phpthumb(); |
|
15 | + $this->fs = FS::getInstance(); |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | public function create($inputFile, $outputFile, $options) { |
19 | 19 | $this->thumb->sourceFilename = $inputFile; |
20 | - $ext = explode('.',$inputFile); |
|
20 | + $ext = explode('.',$inputFile); |
|
21 | 21 | $ext = str_replace('jpeg','jpg',strtolower(array_pop($ext))); |
22 | 22 | $options = 'f='.$ext.'&'.$options; |
23 | 23 | $this->setOptions($options); |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | public function optimize($file, $type = 'jpg') { |
33 | 33 | switch ($type) { |
34 | 34 | case 'jpg': |
35 | - $ext = $this->fs->takeFileExt($file); |
|
35 | + $ext = $this->fs->takeFileExt($file); |
|
36 | 36 | if ($ext == 'jpeg' || $ext == 'jpg') { |
37 | 37 | $cmd = '/usr/bin/jpegtran -optimize -progressive -copy none -outfile '.escapeshellarg($file.'_').' '.escapeshellarg($file); |
38 | 38 | exec($cmd, $result, $return_var); |
@@ -1,9 +1,9 @@ discard block |
||
1 | 1 | <?php namespace Helpers; |
2 | 2 | |
3 | 3 | include_once(MODX_BASE_PATH.'assets/snippets/phpthumb/phpthumb.class.php'); |
4 | -require_once(MODX_BASE_PATH . 'assets/lib/Helpers/FS.php'); |
|
4 | +require_once(MODX_BASE_PATH.'assets/lib/Helpers/FS.php'); |
|
5 | 5 | |
6 | -class PHPThumb{ |
|
6 | +class PHPThumb { |
|
7 | 7 | |
8 | 8 | private $thumb = null; |
9 | 9 | protected $fs = null; |
@@ -17,8 +17,8 @@ discard block |
||
17 | 17 | |
18 | 18 | public function create($inputFile, $outputFile, $options) { |
19 | 19 | $this->thumb->sourceFilename = $inputFile; |
20 | - $ext = explode('.',$inputFile); |
|
21 | - $ext = str_replace('jpeg','jpg',strtolower(array_pop($ext))); |
|
20 | + $ext = explode('.', $inputFile); |
|
21 | + $ext = str_replace('jpeg', 'jpg', strtolower(array_pop($ext))); |
|
22 | 22 | $options = 'f='.$ext.'&'.$options; |
23 | 23 | $this->setOptions($options); |
24 | 24 | if ($this->thumb->GenerateThumbnail() && $this->thumb->RenderToFile($outputFile)) { |
@@ -15,11 +15,17 @@ discard block |
||
15 | 15 | return self::$mode; |
16 | 16 | } |
17 | 17 | |
18 | + /** |
|
19 | + * @param string $text |
|
20 | + */ |
|
18 | 21 | public static function setMode($text) |
19 | 22 | { |
20 | 23 | self::$mode = $text; |
21 | 24 | } |
22 | 25 | |
26 | + /** |
|
27 | + * @param string $from |
|
28 | + */ |
|
23 | 29 | protected static function _counter($from, $where = ''){ |
24 | 30 | $q = self::$modx->db->select('count(id)', self::$modx->getFullTableName($from), $where); |
25 | 31 | return self::$modx->db->getValue($q); |
@@ -71,6 +77,9 @@ discard block |
||
71 | 77 | return $error; |
72 | 78 | } |
73 | 79 | |
80 | + /** |
|
81 | + * @param \Closure $callback |
|
82 | + */ |
|
74 | 83 | public static function readFileLine($path, $callback, array $callbackParams = array(), $lines = 0, $size = 4096) |
75 | 84 | { |
76 | 85 | $handle = fopen($path, "r"); |
@@ -3,22 +3,22 @@ discard block |
||
3 | 3 | include_once(dirname(dirname(__FILE__)).'/APIHelpers.class.php'); |
4 | 4 | class Helper extends \APIhelpers{ |
5 | 5 | protected static $modx = null; |
6 | - protected static $mode = 'list'; |
|
6 | + protected static $mode = 'list'; |
|
7 | 7 | |
8 | 8 | public static function init(\DocumentParser $modx, $mode = 'list'){ |
9 | 9 | self::$modx = $modx; |
10 | - self::setMode($mode); |
|
10 | + self::setMode($mode); |
|
11 | 11 | } |
12 | 12 | |
13 | - public static function getMode() |
|
14 | - { |
|
15 | - return self::$mode; |
|
16 | - } |
|
13 | + public static function getMode() |
|
14 | + { |
|
15 | + return self::$mode; |
|
16 | + } |
|
17 | 17 | |
18 | - public static function setMode($text) |
|
19 | - { |
|
20 | - self::$mode = $text; |
|
21 | - } |
|
18 | + public static function setMode($text) |
|
19 | + { |
|
20 | + self::$mode = $text; |
|
21 | + } |
|
22 | 22 | |
23 | 23 | protected static function _counter($from, $where = ''){ |
24 | 24 | $q = self::$modx->db->select('count(id)', self::$modx->getFullTableName($from), $where); |
@@ -26,70 +26,70 @@ discard block |
||
26 | 26 | } |
27 | 27 | |
28 | 28 | public static function jeditable($key = 'id', $post = true){ |
29 | - $data = array(); |
|
30 | - $request = $post ? $_POST : $_GET; |
|
31 | - $match = (isset($request[$key]) && is_scalar($request[$key]) && preg_match("/^(.*)_(\d+)$/i", $request[$key], $match)) ? $match : array(); |
|
32 | - if(!empty($match)){ |
|
33 | - $data = array( |
|
34 | - 'key' => $match[1], |
|
35 | - 'id' => $match[2] |
|
36 | - ); |
|
37 | - } |
|
38 | - return $data; |
|
29 | + $data = array(); |
|
30 | + $request = $post ? $_POST : $_GET; |
|
31 | + $match = (isset($request[$key]) && is_scalar($request[$key]) && preg_match("/^(.*)_(\d+)$/i", $request[$key], $match)) ? $match : array(); |
|
32 | + if(!empty($match)){ |
|
33 | + $data = array( |
|
34 | + 'key' => $match[1], |
|
35 | + 'id' => $match[2] |
|
36 | + ); |
|
37 | + } |
|
38 | + return $data; |
|
39 | 39 | } |
40 | 40 | |
41 | - public static function curl($url, $data = '', $post = false, array $header = array()) |
|
42 | - { |
|
43 | - $ch = curl_init(); |
|
44 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
45 | - $post = (bool)$post; |
|
46 | - curl_setopt($ch, CURLOPT_POST, $post); |
|
47 | - if ($post) { |
|
48 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $data); |
|
49 | - } |
|
50 | - if (!empty($header)) { |
|
51 | - curl_setopt($ch, CURLOPT_HTTPHEADER, $header); |
|
52 | - } |
|
53 | - curl_setopt($ch, CURLOPT_TIMEOUT, 10); |
|
54 | - curl_setopt($ch, CURLOPT_URL, $url); |
|
55 | - return curl_exec($ch); |
|
56 | - } |
|
41 | + public static function curl($url, $data = '', $post = false, array $header = array()) |
|
42 | + { |
|
43 | + $ch = curl_init(); |
|
44 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
45 | + $post = (bool)$post; |
|
46 | + curl_setopt($ch, CURLOPT_POST, $post); |
|
47 | + if ($post) { |
|
48 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $data); |
|
49 | + } |
|
50 | + if (!empty($header)) { |
|
51 | + curl_setopt($ch, CURLOPT_HTTPHEADER, $header); |
|
52 | + } |
|
53 | + curl_setopt($ch, CURLOPT_TIMEOUT, 10); |
|
54 | + curl_setopt($ch, CURLOPT_URL, $url); |
|
55 | + return curl_exec($ch); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Были ли ошибки во время работы с JSON |
|
60 | - * |
|
61 | - * @param $json string строка с JSON для записи в лог при отладке |
|
62 | - * @return bool|string |
|
63 | - */ |
|
64 | - public function isErrorJSON($json) |
|
65 | - { |
|
66 | - require_once(MODX_BASE_PATH . "assets/snippets/DocLister/lib/jsonHelper.class.php"); |
|
67 | - $error = \jsonHelper::json_last_error_msg(); |
|
68 | - if (!in_array($error, array('error_none', 'other'))) { |
|
69 | - $error = true; |
|
70 | - } |
|
71 | - return $error; |
|
72 | - } |
|
58 | + /** |
|
59 | + * Были ли ошибки во время работы с JSON |
|
60 | + * |
|
61 | + * @param $json string строка с JSON для записи в лог при отладке |
|
62 | + * @return bool|string |
|
63 | + */ |
|
64 | + public function isErrorJSON($json) |
|
65 | + { |
|
66 | + require_once(MODX_BASE_PATH . "assets/snippets/DocLister/lib/jsonHelper.class.php"); |
|
67 | + $error = \jsonHelper::json_last_error_msg(); |
|
68 | + if (!in_array($error, array('error_none', 'other'))) { |
|
69 | + $error = true; |
|
70 | + } |
|
71 | + return $error; |
|
72 | + } |
|
73 | 73 | |
74 | - public static function readFileLine($path, $callback, array $callbackParams = array(), $lines = 0, $size = 4096) |
|
75 | - { |
|
76 | - $handle = fopen($path, "r"); |
|
77 | - $i = $total = 0; |
|
78 | - while (!feof($handle)) { |
|
79 | - $i++; |
|
80 | - $buffer = fgets($handle, $size); |
|
81 | - if (is_callable($callback)) { |
|
82 | - $callbackParams['line'] = $buffer; |
|
83 | - $callbackParams['numLine'] = $i; |
|
84 | - if (call_user_func($callback, $callbackParams)) { |
|
85 | - $total++; |
|
86 | - } |
|
87 | - } |
|
88 | - if ($lines > 0 && $i >= $lines) { |
|
89 | - break; |
|
90 | - } |
|
91 | - } |
|
92 | - fclose($handle); |
|
93 | - return array('line' => $i, 'add' => $total); |
|
94 | - } |
|
74 | + public static function readFileLine($path, $callback, array $callbackParams = array(), $lines = 0, $size = 4096) |
|
75 | + { |
|
76 | + $handle = fopen($path, "r"); |
|
77 | + $i = $total = 0; |
|
78 | + while (!feof($handle)) { |
|
79 | + $i++; |
|
80 | + $buffer = fgets($handle, $size); |
|
81 | + if (is_callable($callback)) { |
|
82 | + $callbackParams['line'] = $buffer; |
|
83 | + $callbackParams['numLine'] = $i; |
|
84 | + if (call_user_func($callback, $callbackParams)) { |
|
85 | + $total++; |
|
86 | + } |
|
87 | + } |
|
88 | + if ($lines > 0 && $i >= $lines) { |
|
89 | + break; |
|
90 | + } |
|
91 | + } |
|
92 | + fclose($handle); |
|
93 | + return array('line' => $i, 'add' => $total); |
|
94 | + } |
|
95 | 95 | } |
96 | 96 | \ No newline at end of file |
@@ -1,11 +1,11 @@ discard block |
||
1 | 1 | <?php namespace Module; |
2 | 2 | |
3 | 3 | include_once(dirname(dirname(__FILE__)).'/APIHelpers.class.php'); |
4 | -class Helper extends \APIhelpers{ |
|
4 | +class Helper extends \APIhelpers { |
|
5 | 5 | protected static $modx = null; |
6 | 6 | protected static $mode = 'list'; |
7 | 7 | |
8 | - public static function init(\DocumentParser $modx, $mode = 'list'){ |
|
8 | + public static function init(\DocumentParser $modx, $mode = 'list') { |
|
9 | 9 | self::$modx = $modx; |
10 | 10 | self::setMode($mode); |
11 | 11 | } |
@@ -20,16 +20,16 @@ discard block |
||
20 | 20 | self::$mode = $text; |
21 | 21 | } |
22 | 22 | |
23 | - protected static function _counter($from, $where = ''){ |
|
23 | + protected static function _counter($from, $where = '') { |
|
24 | 24 | $q = self::$modx->db->select('count(id)', self::$modx->getFullTableName($from), $where); |
25 | 25 | return self::$modx->db->getValue($q); |
26 | 26 | } |
27 | 27 | |
28 | - public static function jeditable($key = 'id', $post = true){ |
|
28 | + public static function jeditable($key = 'id', $post = true) { |
|
29 | 29 | $data = array(); |
30 | 30 | $request = $post ? $_POST : $_GET; |
31 | 31 | $match = (isset($request[$key]) && is_scalar($request[$key]) && preg_match("/^(.*)_(\d+)$/i", $request[$key], $match)) ? $match : array(); |
32 | - if(!empty($match)){ |
|
32 | + if (!empty($match)) { |
|
33 | 33 | $data = array( |
34 | 34 | 'key' => $match[1], |
35 | 35 | 'id' => $match[2] |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | */ |
64 | 64 | public function isErrorJSON($json) |
65 | 65 | { |
66 | - require_once(MODX_BASE_PATH . "assets/snippets/DocLister/lib/jsonHelper.class.php"); |
|
66 | + require_once(MODX_BASE_PATH."assets/snippets/DocLister/lib/jsonHelper.class.php"); |
|
67 | 67 | $error = \jsonHelper::json_last_error_msg(); |
68 | 68 | if (!in_array($error, array('error_none', 'other'))) { |
69 | 69 | $error = true; |
@@ -171,6 +171,9 @@ discard block |
||
171 | 171 | return $out; |
172 | 172 | } |
173 | 173 | |
174 | + /** |
|
175 | + * @param string $key |
|
176 | + */ |
|
174 | 177 | public function set($key, $value) |
175 | 178 | { |
176 | 179 | if (is_scalar($value) && is_scalar($key) && !empty($key)) { |
@@ -261,6 +264,9 @@ discard block |
||
261 | 264 | return $value; |
262 | 265 | } |
263 | 266 | |
267 | + /** |
|
268 | + * @param integer $data |
|
269 | + */ |
|
264 | 270 | protected function findUserBy($data) |
265 | 271 | { |
266 | 272 | switch (true) { |
@@ -568,6 +574,10 @@ discard block |
||
568 | 574 | } |
569 | 575 | return $this; |
570 | 576 | } |
577 | + |
|
578 | + /** |
|
579 | + * @param string $tpl |
|
580 | + */ |
|
571 | 581 | public function setTemplate($tpl) |
572 | 582 | { |
573 | 583 | if (!is_numeric($tpl) || $tpl != (int)$tpl) { |
@@ -115,21 +115,21 @@ discard block |
||
115 | 115 | ); |
116 | 116 | return \APIhelpers::renameKeyArr($out, $prefix, $suffix, $sep); |
117 | 117 | } |
118 | - public function getUrl(){ |
|
119 | - $out = null; |
|
120 | - $id = (int)$this->getID(); |
|
121 | - if(!empty($id)){ |
|
122 | - $out = $this->modx->makeUrl($id); |
|
123 | - } |
|
124 | - return $out; |
|
125 | - } |
|
126 | - public function getTitle($main = 'menutitle', $second = 'pagetitle'){ |
|
127 | - $title = $this->get($main); |
|
128 | - if(empty($title) && $title !== '0'){ |
|
129 | - $title = $this->get($second); |
|
130 | - } |
|
131 | - return $title; |
|
132 | - } |
|
118 | + public function getUrl(){ |
|
119 | + $out = null; |
|
120 | + $id = (int)$this->getID(); |
|
121 | + if(!empty($id)){ |
|
122 | + $out = $this->modx->makeUrl($id); |
|
123 | + } |
|
124 | + return $out; |
|
125 | + } |
|
126 | + public function getTitle($main = 'menutitle', $second = 'pagetitle'){ |
|
127 | + $title = $this->get($main); |
|
128 | + if(empty($title) && $title !== '0'){ |
|
129 | + $title = $this->get($second); |
|
130 | + } |
|
131 | + return $title; |
|
132 | + } |
|
133 | 133 | |
134 | 134 | public function isWebShow() |
135 | 135 | { |
@@ -432,9 +432,9 @@ discard block |
||
432 | 432 | $ignore = $this->systemID(); |
433 | 433 | $_ids = $this->cleanIDs($ids, ',', $ignore); |
434 | 434 | if (is_array($_ids) && $_ids != array()) { |
435 | - $id = $this->sanitarIn($_ids); |
|
435 | + $id = $this->sanitarIn($_ids); |
|
436 | 436 | $this->query("UPDATE {$this->makeTable('site_content')} SET `deleted`='1' WHERE `id` IN ({$id})"); |
437 | - } else throw new Exception('Invalid IDs list for mark trash: <pre>' . print_r($ids, 1) . '</pre> please, check ignore list: <pre>' . print_r($ignore, 1) . '</pre>'); |
|
437 | + } else throw new Exception('Invalid IDs list for mark trash: <pre>' . print_r($ids, 1) . '</pre> please, check ignore list: <pre>' . print_r($ignore, 1) . '</pre>'); |
|
438 | 438 | return $this; |
439 | 439 | } |
440 | 440 | public function clearTrash($fire_events = null){ |
@@ -442,7 +442,7 @@ discard block |
||
442 | 442 | $q = $this->modx->makeArray($q); |
443 | 443 | $_ids = array(); |
444 | 444 | foreach($q as $item){ |
445 | - $_ids[] = $item['id']; |
|
445 | + $_ids[] = $item['id']; |
|
446 | 446 | } |
447 | 447 | if (is_array($_ids) && $_ids != array()) { |
448 | 448 | $this->invokeEvent('OnBeforeEmptyTrash', array( |
@@ -465,19 +465,19 @@ discard block |
||
465 | 465 | $ignore = $this->systemID(); |
466 | 466 | $_ids = $this->cleanIDs($ids, ',', $ignore); |
467 | 467 | if (is_array($_ids) && $_ids != array()) { |
468 | - $this->invokeEvent('OnBeforeEmptyTrash', array( |
|
469 | - "ids" => $_ids |
|
470 | - ), $fire_events); |
|
471 | - |
|
472 | - $id = $this->sanitarIn($_ids); |
|
473 | - if(!empty($id)){ |
|
474 | - $this->query("DELETE from {$this->makeTable('site_content')} where `id` IN ({$id})"); |
|
475 | - $this->query("DELETE from {$this->makeTable('site_tmplvar_contentvalues')} where `contentid` IN ({$id})"); |
|
476 | - $this->invokeEvent('OnEmptyTrash', array( |
|
477 | - "ids" => $_ids |
|
478 | - ), $fire_events); |
|
479 | - } |
|
480 | - } else throw new Exception('Invalid IDs list for delete: <pre>' . print_r($ids, 1) . '</pre> please, check ignore list: <pre>' . print_r($ignore, 1) . '</pre>'); |
|
468 | + $this->invokeEvent('OnBeforeEmptyTrash', array( |
|
469 | + "ids" => $_ids |
|
470 | + ), $fire_events); |
|
471 | + |
|
472 | + $id = $this->sanitarIn($_ids); |
|
473 | + if(!empty($id)){ |
|
474 | + $this->query("DELETE from {$this->makeTable('site_content')} where `id` IN ({$id})"); |
|
475 | + $this->query("DELETE from {$this->makeTable('site_tmplvar_contentvalues')} where `contentid` IN ({$id})"); |
|
476 | + $this->invokeEvent('OnEmptyTrash', array( |
|
477 | + "ids" => $_ids |
|
478 | + ), $fire_events); |
|
479 | + } |
|
480 | + } else throw new Exception('Invalid IDs list for delete: <pre>' . print_r($ids, 1) . '</pre> please, check ignore list: <pre>' . print_r($ignore, 1) . '</pre>'); |
|
481 | 481 | |
482 | 482 | return $this; |
483 | 483 | } |
@@ -572,13 +572,13 @@ discard block |
||
572 | 572 | { |
573 | 573 | if (!is_numeric($tpl) || $tpl != (int)$tpl) { |
574 | 574 | if (is_scalar($tpl)) { |
575 | - $sql = "SELECT `id` FROM {$this->makeTable('site_templates')} WHERE `templatename` = '".$this->escape($tpl)."'"; |
|
576 | - $rs = $this->query($sql); |
|
577 | - if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) throw new Exception("Template {$tpl} is not exists"); |
|
578 | - $tpl = $this->modx->db->getValue($rs); |
|
579 | - } else { |
|
580 | - throw new Exception("Invalid template name: " . print_r($tpl, 1)); |
|
581 | - } |
|
575 | + $sql = "SELECT `id` FROM {$this->makeTable('site_templates')} WHERE `templatename` = '".$this->escape($tpl)."'"; |
|
576 | + $rs = $this->query($sql); |
|
577 | + if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) throw new Exception("Template {$tpl} is not exists"); |
|
578 | + $tpl = $this->modx->db->getValue($rs); |
|
579 | + } else { |
|
580 | + throw new Exception("Invalid template name: " . print_r($tpl, 1)); |
|
581 | + } |
|
582 | 582 | } |
583 | 583 | return (int)$tpl; |
584 | 584 | } |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | $value = (int)((bool)$value); |
213 | 213 | if($value){ |
214 | 214 | $this->field['deletedon'] = time() + $this->modxConfig('server_offset_time'); |
215 | - }else{ |
|
215 | + } else{ |
|
216 | 216 | $this->field['deletedon'] = 0; |
217 | 217 | } |
218 | 218 | break; |
@@ -402,7 +402,9 @@ discard block |
||
402 | 402 | } |
403 | 403 | |
404 | 404 | foreach ($fld as $key => $value) { |
405 | - if (empty($this->tv[$key])) continue; |
|
405 | + if (empty($this->tv[$key])) { |
|
406 | + continue; |
|
407 | + } |
|
406 | 408 | if ($value === '') { |
407 | 409 | $this->query("DELETE FROM {$this->makeTable('site_tmplvar_contentvalues')} WHERE `contentid` = '{$this->id}' AND `tmplvarid` = '{$this->tv[$key]}'"); |
408 | 410 | } else { |
@@ -434,7 +436,9 @@ discard block |
||
434 | 436 | if (is_array($_ids) && $_ids != array()) { |
435 | 437 | $id = $this->sanitarIn($_ids); |
436 | 438 | $this->query("UPDATE {$this->makeTable('site_content')} SET `deleted`='1' WHERE `id` IN ({$id})"); |
437 | - } else throw new Exception('Invalid IDs list for mark trash: <pre>' . print_r($ids, 1) . '</pre> please, check ignore list: <pre>' . print_r($ignore, 1) . '</pre>'); |
|
439 | + } else { |
|
440 | + throw new Exception('Invalid IDs list for mark trash: <pre>' . print_r($ids, 1) . '</pre> please, check ignore list: <pre>' . print_r($ignore, 1) . '</pre>'); |
|
441 | + } |
|
438 | 442 | return $this; |
439 | 443 | } |
440 | 444 | public function clearTrash($fire_events = null){ |
@@ -477,7 +481,9 @@ discard block |
||
477 | 481 | "ids" => $_ids |
478 | 482 | ), $fire_events); |
479 | 483 | } |
480 | - } else throw new Exception('Invalid IDs list for delete: <pre>' . print_r($ids, 1) . '</pre> please, check ignore list: <pre>' . print_r($ignore, 1) . '</pre>'); |
|
484 | + } else { |
|
485 | + throw new Exception('Invalid IDs list for delete: <pre>' . print_r($ids, 1) . '</pre> please, check ignore list: <pre>' . print_r($ignore, 1) . '</pre>'); |
|
486 | + } |
|
481 | 487 | |
482 | 488 | return $this; |
483 | 489 | } |
@@ -574,7 +580,9 @@ discard block |
||
574 | 580 | if (is_scalar($tpl)) { |
575 | 581 | $sql = "SELECT `id` FROM {$this->makeTable('site_templates')} WHERE `templatename` = '".$this->escape($tpl)."'"; |
576 | 582 | $rs = $this->query($sql); |
577 | - if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) throw new Exception("Template {$tpl} is not exists"); |
|
583 | + if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) { |
|
584 | + throw new Exception("Template {$tpl} is not exists"); |
|
585 | + } |
|
578 | 586 | $tpl = $this->modx->db->getValue($rs); |
579 | 587 | } else { |
580 | 588 | throw new Exception("Invalid template name: " . print_r($tpl, 1)); |
@@ -95,20 +95,20 @@ discard block |
||
95 | 95 | $out = array_diff_key(parent::toArray(), $this->default_field); |
96 | 96 | $tpl = $this->get('template'); |
97 | 97 | $tvTPL = APIHelpers::getkey($this->tvTpl, $tpl, array()); |
98 | - foreach($tvTPL as $item){ |
|
99 | - if(isset($this->tvid[$item]) && !array_key_exists($this->tvid[$item], $out)){ |
|
98 | + foreach ($tvTPL as $item) { |
|
99 | + if (isset($this->tvid[$item]) && !array_key_exists($this->tvid[$item], $out)) { |
|
100 | 100 | $out[$this->tvid[$item]] = $this->get($this->tvid[$item]); |
101 | 101 | } |
102 | 102 | } |
103 | - if($render){ |
|
104 | - foreach($out as $key => $val){ |
|
103 | + if ($render) { |
|
104 | + foreach ($out as $key => $val) { |
|
105 | 105 | $out[$key] = $this->renderTV($key); |
106 | 106 | } |
107 | 107 | } |
108 | 108 | return $out; |
109 | 109 | } |
110 | 110 | |
111 | - public function toArray($prefix = '', $suffix = '', $sep = '_', $render = true){ |
|
111 | + public function toArray($prefix = '', $suffix = '', $sep = '_', $render = true) { |
|
112 | 112 | $out = array_merge( |
113 | 113 | $this->toArrayMain(), |
114 | 114 | $this->toArrayTV($render), |
@@ -116,17 +116,17 @@ discard block |
||
116 | 116 | ); |
117 | 117 | return \APIhelpers::renameKeyArr($out, $prefix, $suffix, $sep); |
118 | 118 | } |
119 | - public function getUrl(){ |
|
119 | + public function getUrl() { |
|
120 | 120 | $out = null; |
121 | 121 | $id = (int)$this->getID(); |
122 | - if(!empty($id)){ |
|
122 | + if (!empty($id)) { |
|
123 | 123 | $out = $this->modx->makeUrl($id); |
124 | 124 | } |
125 | 125 | return $out; |
126 | 126 | } |
127 | - public function getTitle($main = 'menutitle', $second = 'pagetitle'){ |
|
127 | + public function getTitle($main = 'menutitle', $second = 'pagetitle') { |
|
128 | 128 | $title = $this->get($main); |
129 | - if(empty($title) && $title !== '0'){ |
|
129 | + if (empty($title) && $title !== '0') { |
|
130 | 130 | $title = $this->get($second); |
131 | 131 | } |
132 | 132 | return $title; |
@@ -139,16 +139,16 @@ discard block |
||
139 | 139 | $del = ($this->get('deleted') == 0 && ($this->get('deletedon') == 0 || $this->get('deletedon') > time())); |
140 | 140 | return ($pub && $unpub && $del); |
141 | 141 | } |
142 | - public function touch(){ |
|
142 | + public function touch() { |
|
143 | 143 | $this->set('editedon', time()); |
144 | 144 | return $this; |
145 | 145 | } |
146 | 146 | |
147 | - public function renderTV($tvname){ |
|
147 | + public function renderTV($tvname) { |
|
148 | 148 | $out = null; |
149 | - if($this->getID() > 0){ |
|
150 | - include_once MODX_MANAGER_PATH . "includes/tmplvars.format.inc.php"; |
|
151 | - include_once MODX_MANAGER_PATH . "includes/tmplvars.commands.inc.php"; |
|
149 | + if ($this->getID() > 0) { |
|
150 | + include_once MODX_MANAGER_PATH."includes/tmplvars.format.inc.php"; |
|
151 | + include_once MODX_MANAGER_PATH."includes/tmplvars.commands.inc.php"; |
|
152 | 152 | $tvval = $this->get($tvname); |
153 | 153 | $param = APIHelpers::getkey($this->tvd, $tvname, array()); |
154 | 154 | $display = APIHelpers::getkey($param, 'display', ''); |
@@ -159,13 +159,13 @@ discard block |
||
159 | 159 | return $out; |
160 | 160 | } |
161 | 161 | |
162 | - public function get($key){ |
|
162 | + public function get($key) { |
|
163 | 163 | $out = parent::get($key); |
164 | - if(isset($this->tv[$key])){ |
|
164 | + if (isset($this->tv[$key])) { |
|
165 | 165 | $tpl = $this->get('template'); |
166 | 166 | $tvTPL = APIHelpers::getkey($this->tvTpl, $tpl, array()); |
167 | 167 | $tvID = APIHelpers::getkey($this->tv, $key, 0); |
168 | - if(in_array($tvID, $tvTPL) && is_null($out)){ |
|
168 | + if (in_array($tvID, $tvTPL) && is_null($out)) { |
|
169 | 169 | $out = APIHelpers::getkey($this->tvd[$key], 'value', null); |
170 | 170 | } |
171 | 171 | } |
@@ -185,38 +185,38 @@ discard block |
||
185 | 185 | break; |
186 | 186 | case 'published': |
187 | 187 | $value = (int)((bool)$value); |
188 | - if($value){ |
|
188 | + if ($value) { |
|
189 | 189 | $this->field['publishedon'] = time() + $this->modxConfig('server_offset_time'); |
190 | 190 | } |
191 | 191 | break; |
192 | 192 | case 'pub_date': |
193 | 193 | $value = $this->getTime($value); |
194 | - if($value > 0 && time() + $this->modxConfig('server_offset_time') > $value){ |
|
194 | + if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) { |
|
195 | 195 | $this->field['published'] = 1; |
196 | 196 | $this->field['publishedon'] = $value; |
197 | 197 | } |
198 | 198 | break; |
199 | 199 | case 'unpub_date': |
200 | 200 | $value = $this->getTime($value); |
201 | - if($value > 0 && time() + $this->modxConfig('server_offset_time') > $value){ |
|
201 | + if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) { |
|
202 | 202 | $this->field['published'] = 0; |
203 | 203 | $this->field['publishedon'] = 0; |
204 | 204 | } |
205 | 205 | break; |
206 | 206 | case 'deleted': |
207 | 207 | $value = (int)((bool)$value); |
208 | - if($value){ |
|
208 | + if ($value) { |
|
209 | 209 | $this->field['deletedon'] = time() + $this->modxConfig('server_offset_time'); |
210 | - }else{ |
|
210 | + } else { |
|
211 | 211 | $this->field['deletedon'] = 0; |
212 | 212 | } |
213 | 213 | break; |
214 | 214 | case 'deletedon': |
215 | 215 | $value = $this->getTime($value); |
216 | - if($value > 0 && time() + $this->modxConfig('server_offset_time') < $value){ |
|
216 | + if ($value > 0 && time() + $this->modxConfig('server_offset_time') < $value) { |
|
217 | 217 | $value = 0; |
218 | 218 | } |
219 | - if($value){ |
|
219 | + if ($value) { |
|
220 | 220 | $this->field['deleted'] = 1; |
221 | 221 | } |
222 | 222 | break; |
@@ -237,19 +237,19 @@ discard block |
||
237 | 237 | return $this; |
238 | 238 | } |
239 | 239 | |
240 | - protected function getUser($value, $default = 0){ |
|
240 | + protected function getUser($value, $default = 0) { |
|
241 | 241 | $currentAdmin = APIHelpers::getkey($_SESSION, 'mgrInternalKey', 0); |
242 | 242 | $value = (int)$value; |
243 | - if(!empty($value)){ |
|
243 | + if (!empty($value)) { |
|
244 | 244 | $by = $this->findUserBy($value); |
245 | 245 | $exists = $this->managerUsers->exists(function($key, $val) use ($by, $value){ |
246 | 246 | return ($val->containsKey($by) && $val->get($by) === (string)$value); |
247 | 247 | }); |
248 | - if(!$exists){ |
|
248 | + if (!$exists) { |
|
249 | 249 | $value = 0; |
250 | 250 | } |
251 | 251 | } |
252 | - if(empty($value)){ |
|
252 | + if (empty($value)) { |
|
253 | 253 | $value = empty($currentAdmin) ? $default : $currentAdmin; |
254 | 254 | } |
255 | 255 | return $value; |
@@ -273,13 +273,13 @@ discard block |
||
273 | 273 | return $find; |
274 | 274 | } |
275 | 275 | |
276 | - protected function getTime($value){ |
|
276 | + protected function getTime($value) { |
|
277 | 277 | $value = trim($value); |
278 | - if(!empty($value)){ |
|
279 | - if(!is_numeric($value)){ |
|
278 | + if (!empty($value)) { |
|
279 | + if (!is_numeric($value)) { |
|
280 | 280 | $value = (int)strtotime($value); |
281 | 281 | } |
282 | - if(!empty($value)){ |
|
282 | + if (!empty($value)) { |
|
283 | 283 | $value += $this->modxConfig('server_offset_time'); |
284 | 284 | } |
285 | 285 | } |
@@ -302,9 +302,9 @@ discard block |
||
302 | 302 | $this->close(); |
303 | 303 | $this->newDoc = false; |
304 | 304 | |
305 | - $result = $this->query("SELECT * from {$this->makeTable('site_content')} where `id`=" . (int)$id); |
|
305 | + $result = $this->query("SELECT * from {$this->makeTable('site_content')} where `id`=".(int)$id); |
|
306 | 306 | $this->fromArray($this->modx->db->getRow($result)); |
307 | - $result = $this->query("SELECT * from {$this->makeTable('site_tmplvar_contentvalues')} where `contentid`=" . (int)$id); |
|
307 | + $result = $this->query("SELECT * from {$this->makeTable('site_tmplvar_contentvalues')} where `contentid`=".(int)$id); |
|
308 | 308 | while ($row = $this->modx->db->getRow($result)) { |
309 | 309 | $this->field[$this->tvid[$row['tmplvarid']]] = $row['value']; |
310 | 310 | } |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | { |
324 | 324 | $parent = null; |
325 | 325 | if ($this->field['pagetitle'] == '') { |
326 | - $this->log['emptyPagetitle'] = 'Pagetitle is empty in <pre>' . print_r($this->field, true) . '</pre>'; |
|
326 | + $this->log['emptyPagetitle'] = 'Pagetitle is empty in <pre>'.print_r($this->field, true).'</pre>'; |
|
327 | 327 | return false; |
328 | 328 | } |
329 | 329 | |
@@ -339,8 +339,8 @@ discard block |
||
339 | 339 | $fld = $this->toArray(null, null, null, false); |
340 | 340 | foreach ($this->default_field as $key => $value) { |
341 | 341 | $tmp = $this->get($key); |
342 | - if ($this->newDoc && ( !is_int($tmp) && $tmp=='')) { |
|
343 | - if($tmp == $value){ |
|
342 | + if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
343 | + if ($tmp == $value) { |
|
344 | 344 | switch ($key) { |
345 | 345 | case 'cacheable': |
346 | 346 | $value = $this->modxConfig('cache_default'); |
@@ -361,11 +361,11 @@ discard block |
||
361 | 361 | } |
362 | 362 | $this->field[$key] = $value; |
363 | 363 | } |
364 | - switch(true){ |
|
364 | + switch (true) { |
|
365 | 365 | case $key == 'parent': |
366 | 366 | $parent = (int)$this->get($key); |
367 | 367 | $q = $this->query("SELECT count(`id`) FROM {$this->makeTable('site_content')} WHERE `id`='{$parent}'"); |
368 | - if($this->modx->db->getValue($q)!=1){ |
|
368 | + if ($this->modx->db->getValue($q) != 1) { |
|
369 | 369 | $parent = $value; |
370 | 370 | } |
371 | 371 | $this->field[$key] = $parent; |
@@ -382,9 +382,9 @@ discard block |
||
382 | 382 | |
383 | 383 | if (!empty($this->set)) { |
384 | 384 | if ($this->newDoc) { |
385 | - $SQL = "INSERT into {$this->makeTable('site_content')} SET " . implode(', ', $this->set); |
|
385 | + $SQL = "INSERT into {$this->makeTable('site_content')} SET ".implode(', ', $this->set); |
|
386 | 386 | } else { |
387 | - $SQL = "UPDATE {$this->makeTable('site_content')} SET " . implode(', ', $this->set) . " WHERE `id` = " . $this->id; |
|
387 | + $SQL = "UPDATE {$this->makeTable('site_content')} SET ".implode(', ', $this->set)." WHERE `id` = ".$this->id; |
|
388 | 388 | } |
389 | 389 | $this->query($SQL); |
390 | 390 | |
@@ -428,20 +428,20 @@ discard block |
||
428 | 428 | return $this->id; |
429 | 429 | } |
430 | 430 | |
431 | - public function toTrash($ids){ |
|
431 | + public function toTrash($ids) { |
|
432 | 432 | $ignore = $this->systemID(); |
433 | 433 | $_ids = $this->cleanIDs($ids, ',', $ignore); |
434 | 434 | if (is_array($_ids) && $_ids != array()) { |
435 | 435 | $id = $this->sanitarIn($_ids); |
436 | 436 | $this->query("UPDATE {$this->makeTable('site_content')} SET `deleted`='1' WHERE `id` IN ({$id})"); |
437 | - } else throw new Exception('Invalid IDs list for mark trash: <pre>' . print_r($ids, 1) . '</pre> please, check ignore list: <pre>' . print_r($ignore, 1) . '</pre>'); |
|
437 | + } else throw new Exception('Invalid IDs list for mark trash: <pre>'.print_r($ids, 1).'</pre> please, check ignore list: <pre>'.print_r($ignore, 1).'</pre>'); |
|
438 | 438 | return $this; |
439 | 439 | } |
440 | - public function clearTrash($fire_events = null){ |
|
440 | + public function clearTrash($fire_events = null) { |
|
441 | 441 | $q = $this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `deleted`='1'"); |
442 | 442 | $q = $this->modx->makeArray($q); |
443 | 443 | $_ids = array(); |
444 | - foreach($q as $item){ |
|
444 | + foreach ($q as $item) { |
|
445 | 445 | $_ids[] = $item['id']; |
446 | 446 | } |
447 | 447 | if (is_array($_ids) && $_ids != array()) { |
@@ -465,10 +465,10 @@ discard block |
||
465 | 465 | $_ids = $this->cleanIDs($ids, ','); |
466 | 466 | if (is_array($_ids) && $_ids != array()) { |
467 | 467 | $id = $this->sanitarIn($_ids); |
468 | - if(!empty($id)) { |
|
468 | + if (!empty($id)) { |
|
469 | 469 | $q = $this->query("SELECT `id` FROM {$this->makeTable('site_content')} where `parent` IN ({$id})"); |
470 | 470 | $id = $this->modx->db->getColumn('id', $q); |
471 | - if($depth > 0 || (is_bool($depth) && $depth == true)){ |
|
471 | + if ($depth > 0 || (is_bool($depth) && $depth == true)) { |
|
472 | 472 | $id = $this->childrens($id, is_bool($depth) ? $depth : ($depth - 1)); |
473 | 473 | } |
474 | 474 | $_ids = array_merge($_ids, $id); |
@@ -487,14 +487,14 @@ discard block |
||
487 | 487 | ), $fire_events); |
488 | 488 | |
489 | 489 | $id = $this->sanitarIn($_ids); |
490 | - if(!empty($id)){ |
|
490 | + if (!empty($id)) { |
|
491 | 491 | $this->query("DELETE from {$this->makeTable('site_content')} where `id` IN ({$id})"); |
492 | 492 | $this->query("DELETE from {$this->makeTable('site_tmplvar_contentvalues')} where `contentid` IN ({$id})"); |
493 | 493 | $this->invokeEvent('OnEmptyTrash', array( |
494 | 494 | "ids" => $_ids |
495 | 495 | ), $fire_events); |
496 | 496 | } |
497 | - } else throw new Exception('Invalid IDs list for delete: <pre>' . print_r($ids, 1) . '</pre> please, check ignore list: <pre>' . print_r($ignore, 1) . '</pre>'); |
|
497 | + } else throw new Exception('Invalid IDs list for delete: <pre>'.print_r($ids, 1).'</pre> please, check ignore list: <pre>'.print_r($ignore, 1).'</pre>'); |
|
498 | 498 | |
499 | 499 | return $this; |
500 | 500 | } |
@@ -531,7 +531,7 @@ discard block |
||
531 | 531 | $suffix = substr($alias, -2); |
532 | 532 | if (preg_match('/-(\d+)/', $suffix, $tmp) && isset($tmp[1]) && (int)$tmp[1] > 1) { |
533 | 533 | $suffix = (int)$tmp[1] + 1; |
534 | - $alias = substr($alias, 0, -2) . '-' . $suffix; |
|
534 | + $alias = substr($alias, 0, -2).'-'.$suffix; |
|
535 | 535 | } else { |
536 | 536 | $alias .= '-2'; |
537 | 537 | } |
@@ -549,30 +549,30 @@ discard block |
||
549 | 549 | protected function get_TV($reload = false) |
550 | 550 | { |
551 | 551 | if (empty($this->modx->_TVnames) || $reload) { |
552 | - $result = $this->query('SELECT `id`,`name` FROM ' . $this->makeTable('site_tmplvars')); |
|
552 | + $result = $this->query('SELECT `id`,`name` FROM '.$this->makeTable('site_tmplvars')); |
|
553 | 553 | while ($row = $this->modx->db->GetRow($result)) { |
554 | 554 | $this->modx->_TVnames[$row['name']] = $row['id']; |
555 | 555 | } |
556 | 556 | } |
557 | - foreach($this->modx->_TVnames as $name => $id){ |
|
557 | + foreach ($this->modx->_TVnames as $name => $id) { |
|
558 | 558 | $this->tvid[$id] = $name; |
559 | 559 | $this->tv[$name] = $id; |
560 | 560 | } |
561 | 561 | $this->loadTVTemplate()->loadTVDefault(array_values($this->tv)); |
562 | 562 | return $this; |
563 | 563 | } |
564 | - protected function loadTVTemplate(){ |
|
564 | + protected function loadTVTemplate() { |
|
565 | 565 | $q = $this->query("SELECT `tmplvarid`, `templateid` FROM ".$this->makeTable('site_tmplvar_templates')); |
566 | 566 | $q = $this->modx->db->makeArray($q); |
567 | 567 | $this->tvTpl = array(); |
568 | - foreach($q as $item){ |
|
568 | + foreach ($q as $item) { |
|
569 | 569 | $this->tvTpl[$item['templateid']][] = $item['tmplvarid']; |
570 | 570 | } |
571 | 571 | return $this; |
572 | 572 | } |
573 | 573 | protected function loadTVDefault(array $tvId = array()) |
574 | 574 | { |
575 | - if(is_array($tvId) && !empty($tvId)){ |
|
575 | + if (is_array($tvId) && !empty($tvId)) { |
|
576 | 576 | $tbl_site_tmplvars = $this->makeTable('site_tmplvars'); |
577 | 577 | $fields = 'id,name,default_text as value,display,display_params,type'; |
578 | 578 | $implodeTvId = implode(',', $tvId); |
@@ -594,7 +594,7 @@ discard block |
||
594 | 594 | if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) throw new Exception("Template {$tpl} is not exists"); |
595 | 595 | $tpl = $this->modx->db->getValue($rs); |
596 | 596 | } else { |
597 | - throw new Exception("Invalid template name: " . print_r($tpl, 1)); |
|
597 | + throw new Exception("Invalid template name: ".print_r($tpl, 1)); |
|
598 | 598 | } |
599 | 599 | } |
600 | 600 | return (int)$tpl; |
@@ -46,6 +46,8 @@ discard block |
||
46 | 46 | /** |
47 | 47 | * is not allowed to call from outside: private! |
48 | 48 | * |
49 | + * @param string $userClass |
|
50 | + * @param boolean $debug |
|
49 | 51 | */ |
50 | 52 | private function __construct(DocumentParser $modx, $userClass, $debug) |
51 | 53 | { |
@@ -277,6 +279,12 @@ discard block |
||
277 | 279 | 'errorCode' => $errorCode |
278 | 280 | )); |
279 | 281 | } |
282 | + |
|
283 | + /** |
|
284 | + * @param string $method |
|
285 | + * @param string $error |
|
286 | + * @param string $errorCode |
|
287 | + */ |
|
280 | 288 | protected function Auth($pwdField, $emailField, $rememberField, $backUrl, $method, &$error, &$errorCode, $params = array()){ |
281 | 289 | $POST = array( |
282 | 290 | 'backUrl' => urlencode($backUrl) |
@@ -458,6 +466,10 @@ discard block |
||
458 | 466 | } |
459 | 467 | return $url; |
460 | 468 | } |
469 | + |
|
470 | + /** |
|
471 | + * @param string $name |
|
472 | + */ |
|
461 | 473 | protected function getTemplate($name){ |
462 | 474 | $out = ''; |
463 | 475 | $file = dirname(dirname(__FILE__)).'/tpl/'.$name.'.html'; |
@@ -6,7 +6,10 @@ |
||
6 | 6 | include_once(MODX_BASE_PATH . 'assets/snippets/DocLister/lib/DLTemplate.class.php'); |
7 | 7 | include_once(MODX_BASE_PATH . 'assets/snippets/DocLister/lib/DLCollection.class.php'); |
8 | 8 | |
9 | -use APIHelpers, DocumentParser, DLCollection, DLTemplate; |
|
9 | +use APIHelpers; |
|
10 | +use DocumentParser; |
|
11 | +use DLCollection; |
|
12 | +use DLTemplate; |
|
10 | 13 | use Helpers\FS; |
11 | 14 | |
12 | 15 | class Actions{ |
@@ -117,11 +117,11 @@ discard block |
||
117 | 117 | $start = $this->makeUrl($this->config['site_start']); |
118 | 118 | if($start == $go){ |
119 | 119 | $go = $this->config['site_url']; |
120 | - }else{ |
|
120 | + } else{ |
|
121 | 121 | $go = $this->config['site_url'].ltrim($go, '/'); |
122 | 122 | } |
123 | 123 | $this->moveTo(array('url' => $go)); |
124 | - }else{ |
|
124 | + } else{ |
|
125 | 125 | //Если юзер не авторизован, то показываем ему 404 ошибку |
126 | 126 | $this->modx->sendErrorPage(); |
127 | 127 | } |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | if(!empty($homeID)){ |
171 | 171 | $dataTPL['url.profile'] = $this->makeUrl($homeID); |
172 | 172 | } |
173 | - }else{ |
|
173 | + } else{ |
|
174 | 174 | $tpl = APIHelpers::getkey($params, 'tplForm', ''); |
175 | 175 | if(empty($tpl)){ |
176 | 176 | $tpl = $this->getTemplate('authForm'); |
@@ -220,12 +220,12 @@ discard block |
||
220 | 220 | * Thank you for super protection against hacking in protect.inc.php:-) |
221 | 221 | */ |
222 | 222 | $refer = htmlspecialchars_decode($_SERVER['HTTP_REFERER'], ENT_QUOTES); |
223 | - }else{ |
|
223 | + } else{ |
|
224 | 224 | $selfHost = rtrim(str_replace("http://", "", $this->config['site_url']), '/'); |
225 | 225 | if(empty( $request['host']) || $request['host']==$selfHost){ |
226 | 226 | $query = !empty($uri['query']) ? '?'.$uri['query'] : ''; |
227 | 227 | $refer = !empty($uri['path']) ? $uri['path'].$query : ''; |
228 | - }else{ |
|
228 | + } else{ |
|
229 | 229 | $refer = ''; |
230 | 230 | } |
231 | 231 | } |
@@ -234,21 +234,21 @@ discard block |
||
234 | 234 | $backUrl = APIHelpers::getkey($_POST, 'backUrl', $POST['backUrl']); |
235 | 235 | if(!is_scalar($backUrl)){ |
236 | 236 | $backUrl = $refer; |
237 | - }else{ |
|
237 | + } else{ |
|
238 | 238 | $backUrl = urldecode($backUrl); |
239 | 239 | } |
240 | - }else{ |
|
240 | + } else{ |
|
241 | 241 | $backUrl = $refer; |
242 | 242 | } |
243 | 243 | $backUrl = parse_url($backUrl); |
244 | 244 | if(!empty($backUrl['path']) && $request['path'] != $backUrl['path']){ |
245 | 245 | $POST['backUrl'] = $backUrl['path']; |
246 | - }else{ |
|
246 | + } else{ |
|
247 | 247 | $selfHost = rtrim(str_replace("http://", "", $this->config['site_url']), '/'); |
248 | 248 | if(empty($uri['host']) || $uri['host']==$selfHost){ |
249 | 249 | $query = !empty($uri['query']) ? '?'.$uri['query'] : ''; |
250 | 250 | $POST['backUrl'] = !empty($uri['path']) ? $uri['path'].$query : ''; |
251 | - }else{ |
|
251 | + } else{ |
|
252 | 252 | $POST['backUrl'] = ''; |
253 | 253 | } |
254 | 254 | } |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | 'url' => '/'.ltrim($POST['backUrl'], '/'), |
258 | 258 | 'validate' => true |
259 | 259 | )); |
260 | - }else{ |
|
260 | + } else{ |
|
261 | 261 | $idURL = 0; |
262 | 262 | } |
263 | 263 | if(empty($idURL)){ |
@@ -322,16 +322,16 @@ discard block |
||
322 | 322 | "rememberme" => $POST['remember'], |
323 | 323 | )); |
324 | 324 | $this->moveTo(array('url' => urldecode($POST['backUrl']))); |
325 | - }else{ |
|
325 | + } else{ |
|
326 | 326 | $userObj->set('failedlogincount', (int)$userObj->get('failedlogincount') + 1); |
327 | 327 | $userObj->save(false, false); |
328 | 328 | |
329 | 329 | $error = 'error.incorrect_password'; |
330 | 330 | } |
331 | - }else{ |
|
331 | + } else{ |
|
332 | 332 | $error = 'error.no_user'; |
333 | 333 | } |
334 | - }else{ |
|
334 | + } else{ |
|
335 | 335 | $error = 'error.incorrect_mail'; |
336 | 336 | $POST['email'] = ''; |
337 | 337 | } |
@@ -429,10 +429,10 @@ discard block |
||
429 | 429 | if(empty($out)){ |
430 | 430 | $uri = ''; |
431 | 431 | } |
432 | - }else{ |
|
432 | + } else{ |
|
433 | 433 | $uri = DLTemplate::getInstance($this->modx)->sanitarTag($uri); |
434 | 434 | } |
435 | - }else{ |
|
435 | + } else{ |
|
436 | 436 | //$modx->sendRedirect($url, 0, 'REDIRECT_HEADER', 'HTTP/1.1 307 Temporary Redirect'); |
437 | 437 | header("Location: ".$uri, true, ($code>0 ? $code : 307)); |
438 | 438 | } |
@@ -452,7 +452,7 @@ discard block |
||
452 | 452 | } |
453 | 453 | if($this->url->containsKey($id)){ |
454 | 454 | $url = $this->url->get($id); |
455 | - }else{ |
|
455 | + } else{ |
|
456 | 456 | $url = $this->modx->makeUrl($id); |
457 | 457 | $this->url->set($id, $url); |
458 | 458 | } |
@@ -475,7 +475,7 @@ discard block |
||
475 | 475 | static::$langDic[$lang] = include_once($file); |
476 | 476 | if(is_array(static::$langDic[$lang])){ |
477 | 477 | static::$langDic[$lang] = APIHelpers::renameKeyArr(static::$langDic[$lang], $lang); |
478 | - }else{ |
|
478 | + } else{ |
|
479 | 479 | static::$langDic[$lang] = array(); |
480 | 480 | } |
481 | 481 | } |
@@ -12,9 +12,9 @@ discard block |
||
12 | 12 | class Actions{ |
13 | 13 | protected $modx = null; |
14 | 14 | public $userObj = null; |
15 | - /** |
|
16 | - * @var DLCollection |
|
17 | - */ |
|
15 | + /** |
|
16 | + * @var DLCollection |
|
17 | + */ |
|
18 | 18 | public $url; |
19 | 19 | protected static $lang = null; |
20 | 20 | protected static $langDic = array(); |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | */ |
24 | 24 | protected static $instance; |
25 | 25 | |
26 | - protected $config = array(); |
|
26 | + protected $config = array(); |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * gets the instance via lazy initialization (created on first usage) |
@@ -50,15 +50,15 @@ discard block |
||
50 | 50 | private function __construct(DocumentParser $modx, $userClass, $debug) |
51 | 51 | { |
52 | 52 | $this->modx = $modx; |
53 | - $this->userObj = new $userClass($this->modx, $debug); |
|
54 | - $this->url = new DLCollection($this->modx); |
|
53 | + $this->userObj = new $userClass($this->modx, $debug); |
|
54 | + $this->url = new DLCollection($this->modx); |
|
55 | 55 | |
56 | - $site_url = $this->modx->getConfig('site_url'); |
|
57 | - $site_start = $this->modx->getConfig('site_start', 1); |
|
58 | - $error_page = $this->modx->getConfig('error_page', $site_start); |
|
59 | - $unauthorized_page = $this->modx->getConfig('unauthorized_page', $error_page); |
|
56 | + $site_url = $this->modx->getConfig('site_url'); |
|
57 | + $site_start = $this->modx->getConfig('site_start', 1); |
|
58 | + $error_page = $this->modx->getConfig('error_page', $site_start); |
|
59 | + $unauthorized_page = $this->modx->getConfig('unauthorized_page', $error_page); |
|
60 | 60 | |
61 | - $this->config = compact('site_url', 'site_start', 'error_page', 'unauthorized_page'); |
|
61 | + $this->config = compact('site_url', 'site_start', 'error_page', 'unauthorized_page'); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -85,47 +85,47 @@ discard block |
||
85 | 85 | * Сброс авторизации и обновление страницы |
86 | 86 | */ |
87 | 87 | public function logout($params){ |
88 | - $LogoutName = APIHelpers::getkey($params, 'LogoutName', 'logout'); |
|
89 | - if(is_scalar($LogoutName) && !empty($LogoutName) && isset($_GET[$LogoutName])){ |
|
90 | - $userID = $this->UserID('web'); |
|
91 | - if($userID){ |
|
92 | - $this->userObj->edit($userID); |
|
93 | - if($this->userObj->getID()){ |
|
94 | - $this->modx->invokeEvent("OnBeforeWebLogout", array( |
|
95 | - "userid" => $this->userObj->getID(), |
|
96 | - "username" => $this->userObj->get('username') |
|
97 | - )); |
|
98 | - } |
|
99 | - $this->userObj->logOut(); |
|
100 | - if($this->userObj->getID()){ |
|
101 | - $this->modx->invokeEvent("OnWebLogout", array( |
|
102 | - "userid" => $this->userObj->getID(), |
|
103 | - "username" => $this->userObj->get('username') |
|
104 | - )); |
|
105 | - } |
|
106 | - |
|
107 | - $go = APIHelpers::getkey($params, 'url', ''); |
|
108 | - if(empty($go)){ |
|
109 | - $go = str_replace( |
|
110 | - array("?".$LogoutName, "&".$LogoutName), |
|
111 | - array("", ""), |
|
112 | - $_SERVER['REQUEST_URI'] |
|
113 | - ); |
|
114 | - } |
|
115 | - |
|
116 | - $start = $this->makeUrl($this->config['site_start']); |
|
117 | - if($start == $go){ |
|
118 | - $go = $this->config['site_url']; |
|
119 | - }else{ |
|
120 | - $go = $this->config['site_url'].ltrim($go, '/'); |
|
121 | - } |
|
122 | - $this->moveTo(array('url' => $go)); |
|
123 | - }else{ |
|
124 | - //Если юзер не авторизован, то показываем ему 404 ошибку |
|
125 | - $this->modx->sendErrorPage(); |
|
126 | - } |
|
127 | - } |
|
128 | - return true; |
|
88 | + $LogoutName = APIHelpers::getkey($params, 'LogoutName', 'logout'); |
|
89 | + if(is_scalar($LogoutName) && !empty($LogoutName) && isset($_GET[$LogoutName])){ |
|
90 | + $userID = $this->UserID('web'); |
|
91 | + if($userID){ |
|
92 | + $this->userObj->edit($userID); |
|
93 | + if($this->userObj->getID()){ |
|
94 | + $this->modx->invokeEvent("OnBeforeWebLogout", array( |
|
95 | + "userid" => $this->userObj->getID(), |
|
96 | + "username" => $this->userObj->get('username') |
|
97 | + )); |
|
98 | + } |
|
99 | + $this->userObj->logOut(); |
|
100 | + if($this->userObj->getID()){ |
|
101 | + $this->modx->invokeEvent("OnWebLogout", array( |
|
102 | + "userid" => $this->userObj->getID(), |
|
103 | + "username" => $this->userObj->get('username') |
|
104 | + )); |
|
105 | + } |
|
106 | + |
|
107 | + $go = APIHelpers::getkey($params, 'url', ''); |
|
108 | + if(empty($go)){ |
|
109 | + $go = str_replace( |
|
110 | + array("?".$LogoutName, "&".$LogoutName), |
|
111 | + array("", ""), |
|
112 | + $_SERVER['REQUEST_URI'] |
|
113 | + ); |
|
114 | + } |
|
115 | + |
|
116 | + $start = $this->makeUrl($this->config['site_start']); |
|
117 | + if($start == $go){ |
|
118 | + $go = $this->config['site_url']; |
|
119 | + }else{ |
|
120 | + $go = $this->config['site_url'].ltrim($go, '/'); |
|
121 | + } |
|
122 | + $this->moveTo(array('url' => $go)); |
|
123 | + }else{ |
|
124 | + //Если юзер не авторизован, то показываем ему 404 ошибку |
|
125 | + $this->modx->sendErrorPage(); |
|
126 | + } |
|
127 | + } |
|
128 | + return true; |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -133,14 +133,14 @@ discard block |
||
133 | 133 | * @return string |
134 | 134 | */ |
135 | 135 | public function logoutUrl($params){ |
136 | - $LogoutName = APIHelpers::getkey($params, 'LogoutName', 'logout'); |
|
137 | - $request = parse_url($_SERVER['REQUEST_URI']); |
|
136 | + $LogoutName = APIHelpers::getkey($params, 'LogoutName', 'logout'); |
|
137 | + $request = parse_url($_SERVER['REQUEST_URI']); |
|
138 | 138 | |
139 | - //Во избежании XSS мы не сохраняем весь REQUEST_URI, а берем только path |
|
140 | - /*$query = (!empty($request['query'])) ? $request['query'].'&' : '';*/ |
|
141 | - $query = '?'.$LogoutName; |
|
139 | + //Во избежании XSS мы не сохраняем весь REQUEST_URI, а берем только path |
|
140 | + /*$query = (!empty($request['query'])) ? $request['query'].'&' : '';*/ |
|
141 | + $query = '?'.$LogoutName; |
|
142 | 142 | |
143 | - return $request['path'].$query; |
|
143 | + return $request['path'].$query; |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -149,343 +149,343 @@ discard block |
||
149 | 149 | * В противном случае вся работа происходит внутри самого блока |
150 | 150 | */ |
151 | 151 | public function AuthBlock($params){ |
152 | - $POST = array('backUrl' => $_SERVER['REQUEST_URI']); |
|
153 | - |
|
154 | - $error = $errorCode = ''; |
|
155 | - |
|
156 | - $pwdField = APIHelpers::getkey($params, 'pwdField', 'password'); |
|
157 | - $emailField = APIHelpers::getkey($params, 'emailField', 'email'); |
|
158 | - $rememberField = APIHelpers::getkey($params, 'rememberField', 'remember'); |
|
159 | - |
|
160 | - if($this->UserID('web')){ |
|
161 | - $tpl = APIHelpers::getkey($params, 'tplProfile', ''); |
|
162 | - if(empty($tpl)){ |
|
163 | - $tpl = $this->getTemplate('tplProfile'); |
|
164 | - } |
|
165 | - $dataTPL = $this->userObj->toArray(); |
|
166 | - $dataTPL['url.logout'] = $this->logoutUrl($params); |
|
167 | - $homeID = APIHelpers::getkey($params, 'homeID'); |
|
168 | - if(!empty($homeID)){ |
|
169 | - $dataTPL['url.profile'] = $this->makeUrl($homeID); |
|
170 | - } |
|
171 | - }else{ |
|
172 | - $tpl = APIHelpers::getkey($params, 'tplForm', ''); |
|
173 | - if(empty($tpl)){ |
|
174 | - $tpl = $this->getTemplate('authForm'); |
|
175 | - } |
|
176 | - $POST = $this->Auth($pwdField, $emailField, $rememberField, $POST['backUrl'], __METHOD__, $error, $errorCode, $params); |
|
177 | - $dataTPL = array( |
|
178 | - 'backUrl' => APIHelpers::getkey($POST, 'backUrl', ''), |
|
179 | - 'emailValue' => APIHelpers::getkey($POST, 'email', ''), |
|
180 | - 'emailField' => $emailField, |
|
181 | - 'pwdField' => $pwdField, |
|
182 | - 'method' => strtolower(__METHOD__), |
|
183 | - 'error' => $error, |
|
184 | - 'errorCode' => $errorCode |
|
185 | - ); |
|
186 | - $authId = APIHelpers::getkey($params, 'authId'); |
|
187 | - if(!empty($authId)){ |
|
188 | - $dataTPL['authPage'] = $this->makeUrl($authId); |
|
189 | - $dataTPL['method'] = strtolower(__CLASS__ . '::'. 'authpage'); |
|
190 | - } |
|
191 | - } |
|
192 | - return DLTemplate::getInstance($this->modx)->parseChunk($tpl, $dataTPL); |
|
152 | + $POST = array('backUrl' => $_SERVER['REQUEST_URI']); |
|
153 | + |
|
154 | + $error = $errorCode = ''; |
|
155 | + |
|
156 | + $pwdField = APIHelpers::getkey($params, 'pwdField', 'password'); |
|
157 | + $emailField = APIHelpers::getkey($params, 'emailField', 'email'); |
|
158 | + $rememberField = APIHelpers::getkey($params, 'rememberField', 'remember'); |
|
159 | + |
|
160 | + if($this->UserID('web')){ |
|
161 | + $tpl = APIHelpers::getkey($params, 'tplProfile', ''); |
|
162 | + if(empty($tpl)){ |
|
163 | + $tpl = $this->getTemplate('tplProfile'); |
|
164 | + } |
|
165 | + $dataTPL = $this->userObj->toArray(); |
|
166 | + $dataTPL['url.logout'] = $this->logoutUrl($params); |
|
167 | + $homeID = APIHelpers::getkey($params, 'homeID'); |
|
168 | + if(!empty($homeID)){ |
|
169 | + $dataTPL['url.profile'] = $this->makeUrl($homeID); |
|
170 | + } |
|
171 | + }else{ |
|
172 | + $tpl = APIHelpers::getkey($params, 'tplForm', ''); |
|
173 | + if(empty($tpl)){ |
|
174 | + $tpl = $this->getTemplate('authForm'); |
|
175 | + } |
|
176 | + $POST = $this->Auth($pwdField, $emailField, $rememberField, $POST['backUrl'], __METHOD__, $error, $errorCode, $params); |
|
177 | + $dataTPL = array( |
|
178 | + 'backUrl' => APIHelpers::getkey($POST, 'backUrl', ''), |
|
179 | + 'emailValue' => APIHelpers::getkey($POST, 'email', ''), |
|
180 | + 'emailField' => $emailField, |
|
181 | + 'pwdField' => $pwdField, |
|
182 | + 'method' => strtolower(__METHOD__), |
|
183 | + 'error' => $error, |
|
184 | + 'errorCode' => $errorCode |
|
185 | + ); |
|
186 | + $authId = APIHelpers::getkey($params, 'authId'); |
|
187 | + if(!empty($authId)){ |
|
188 | + $dataTPL['authPage'] = $this->makeUrl($authId); |
|
189 | + $dataTPL['method'] = strtolower(__CLASS__ . '::'. 'authpage'); |
|
190 | + } |
|
191 | + } |
|
192 | + return DLTemplate::getInstance($this->modx)->parseChunk($tpl, $dataTPL); |
|
193 | 193 | } |
194 | 194 | |
195 | - /** |
|
196 | - * Авторизация на сайте со страницы авторизации |
|
197 | - * [!Auth? &login=`password` &pwdField=`password` &homeID=`72`!] |
|
198 | - */ |
|
199 | - public function AuthPage($params){ |
|
200 | - $homeID = APIHelpers::getkey($params, 'homeID'); |
|
201 | - $this->isAuthGoHome(array('id' => $homeID)); |
|
202 | - |
|
203 | - $error = $errorCode = ''; |
|
204 | - $POST = array('backUrl' => ''); |
|
205 | - |
|
206 | - $pwdField = APIHelpers::getkey($params, 'pwdField', 'password'); |
|
207 | - $emailField = APIHelpers::getkey($params, 'emailField', 'email'); |
|
208 | - $rememberField = APIHelpers::getkey($params, 'rememberField', 'remember'); |
|
209 | - |
|
210 | - $tpl = APIHelpers::getkey($params, 'tpl', ''); |
|
211 | - if(empty($tpl)){ |
|
212 | - $tpl = $this->getTemplate('authForm'); |
|
213 | - } |
|
214 | - |
|
215 | - $request = parse_url($_SERVER['REQUEST_URI']); |
|
216 | - if(!empty($_SERVER['HTTP_REFERER'])){ |
|
217 | - /** |
|
218 | - * Thank you for super protection against hacking in protect.inc.php:-) |
|
219 | - */ |
|
220 | - $refer = htmlspecialchars_decode($_SERVER['HTTP_REFERER'], ENT_QUOTES); |
|
221 | - }else{ |
|
222 | - $selfHost = rtrim(str_replace("http://", "", $this->config['site_url']), '/'); |
|
223 | - if(empty( $request['host']) || $request['host']==$selfHost){ |
|
224 | - $query = !empty($request['query']) ? '?'.$request['query'] : ''; |
|
225 | - $refer = !empty($request['path']) ? $request['path'].$query : ''; |
|
226 | - }else{ |
|
227 | - $refer = ''; |
|
228 | - } |
|
229 | - } |
|
230 | - |
|
231 | - if($_SERVER['REQUEST_METHOD'] == 'POST'){ |
|
232 | - $backUrl = APIHelpers::getkey($_POST, 'backUrl', $POST['backUrl']); |
|
233 | - if(!is_scalar($backUrl)){ |
|
234 | - $backUrl = $refer; |
|
235 | - }else{ |
|
236 | - $backUrl = urldecode($backUrl); |
|
237 | - } |
|
238 | - }else{ |
|
239 | - $backUrl = $refer; |
|
240 | - } |
|
241 | - $backUrl = parse_url($backUrl); |
|
242 | - if(!empty($backUrl['path']) && $request['path'] != $backUrl['path']){ |
|
243 | - $POST['backUrl'] = $backUrl['path']; |
|
244 | - }else{ |
|
245 | - $selfHost = rtrim(str_replace("http://", "", $this->config['site_url']), '/'); |
|
246 | - if(empty($backUrl['host']) || $backUrl['host']==$selfHost){ |
|
247 | - $query = !empty($backUrl['query']) ? '?'.$backUrl['query'] : ''; |
|
248 | - $POST['backUrl'] = !empty($backUrl['path']) ? $backUrl['path'].$query : ''; |
|
249 | - }else{ |
|
250 | - $POST['backUrl'] = ''; |
|
251 | - } |
|
252 | - } |
|
253 | - if(!empty($POST['backUrl'])){ |
|
254 | - $idURL = $this->moveTo(array( |
|
255 | - 'url' => '/'.ltrim($POST['backUrl'], '/'), |
|
256 | - 'validate' => true |
|
257 | - )); |
|
258 | - }else{ |
|
259 | - $idURL = 0; |
|
260 | - } |
|
261 | - if(empty($idURL)){ |
|
262 | - if(empty($homeID)){ |
|
263 | - $homeID = $this->config['site_start']; |
|
264 | - } |
|
265 | - $POST['backUrl'] = $this->makeUrl($homeID); |
|
266 | - } |
|
267 | - $POST = $this->Auth($pwdField, $emailField, $rememberField, $POST['backUrl'], __METHOD__, $error, $errorCode, $params); |
|
268 | - return DLTemplate::getInstance($this->modx)->parseChunk($tpl, array( |
|
269 | - 'backUrl' => APIHelpers::getkey($POST, 'backUrl', ''), |
|
270 | - 'emailValue' => APIHelpers::getkey($POST, 'email', ''), |
|
271 | - 'emailField' => $emailField, |
|
272 | - 'pwdField' => $pwdField, |
|
273 | - 'method' => strtolower(__METHOD__), |
|
274 | - 'error' => $error, |
|
275 | - 'errorCode' => $errorCode |
|
276 | - )); |
|
277 | - } |
|
278 | - protected function Auth($pwdField, $emailField, $rememberField, $backUrl, $method, &$error, &$errorCode, $params = array()){ |
|
279 | - $POST = array( |
|
280 | - 'backUrl' => urlencode($backUrl) |
|
281 | - ); |
|
282 | - $userObj = &$this->userObj; |
|
283 | - if($_SERVER['REQUEST_METHOD']=='POST' && APIHelpers::getkey($_POST, 'method', '') == strtolower($method)){ |
|
284 | - $POST = array_merge($POST, array( |
|
285 | - 'password' => APIHelpers::getkey($_POST, $pwdField, ''), |
|
286 | - 'email' => APIHelpers::getkey($_POST, $emailField, ''), |
|
287 | - 'remember' => (bool)((int)APIHelpers::getkey($_POST, $rememberField, 0)) |
|
288 | - )); |
|
289 | - if(!empty($POST['email']) && is_scalar($POST['email']) && !$userObj->emailValidate($POST['email'], false)){ |
|
290 | - $userObj->edit($POST['email']); |
|
291 | - |
|
292 | - $this->modx->invokeEvent("OnBeforeWebLogin", array( |
|
293 | - "username" => $POST['email'], |
|
294 | - "userpassword" => $POST['password'], |
|
295 | - "rememberme" => $POST['remember'], |
|
296 | - 'userObj' => $userObj |
|
297 | - )); |
|
298 | - if($userObj->getID() && !$userObj->checkBlock($userObj->getID())){ |
|
299 | - $pluginFlag = $this->modx->invokeEvent("OnWebAuthentication", array( |
|
300 | - "userid" => $userObj->getID(), |
|
301 | - "username" => $userObj->get('username'), |
|
302 | - "userpassword" => $POST['password'], |
|
303 | - "savedpassword" => $userObj->get('password'), |
|
304 | - "rememberme" => $POST['remember'], |
|
305 | - )); |
|
306 | - if( |
|
307 | - ($pluginFlag === true || $userObj->testAuth($userObj->getID(), $POST['password'], 0)) |
|
308 | - && |
|
309 | - $userObj->authUser($userObj->getID(), $POST['remember']) |
|
310 | - ){ |
|
311 | - $userObj->set('logincount', (int)$userObj->get('logincount') + 1); |
|
312 | - $userObj->set('lastlogin', time()); |
|
313 | - $userObj->set('failedlogincount', 0); |
|
314 | - $userObj->save(false, false); |
|
315 | - |
|
316 | - $this->modx->invokeEvent("OnWebLogin", array( |
|
317 | - "userid" => $userObj->getID(), |
|
318 | - "username" => $userObj->get('username'), |
|
319 | - "userpassword" => $POST['password'], |
|
320 | - "rememberme" => $POST['remember'], |
|
321 | - )); |
|
322 | - $this->moveTo(array('url' => urldecode($POST['backUrl']))); |
|
323 | - }else{ |
|
324 | - $userObj->set('failedlogincount', (int)$userObj->get('failedlogincount') + 1); |
|
325 | - $userObj->save(false, false); |
|
326 | - |
|
327 | - $error = 'error.incorrect_password'; |
|
328 | - } |
|
329 | - }else{ |
|
330 | - $error = 'error.no_user'; |
|
331 | - } |
|
332 | - }else{ |
|
333 | - $error = 'error.incorrect_mail'; |
|
334 | - $POST['email'] = ''; |
|
335 | - } |
|
336 | - } |
|
337 | - if(!empty($error)){ |
|
338 | - $errorCode = $error; |
|
339 | - $error = APIHelpers::getkey($params, $error, ''); |
|
340 | - $error = static::getLangMsg($error, $error); |
|
341 | - } |
|
342 | - return $POST; |
|
343 | - } |
|
344 | - /** |
|
345 | - * Информация о пользователе |
|
346 | - * [!DLUsers? &action=`UserInfo` &field=`fullname` &id=`2`!] |
|
347 | - */ |
|
348 | - public function UserInfo($params){ |
|
349 | - $out = ''; |
|
350 | - $userID = APIHelpers::getkey($params, 'id', 0); |
|
351 | - if(empty($userID)){ |
|
352 | - $userID = $this->UserID('web'); |
|
353 | - } |
|
354 | - $field = APIHelpers::getkey($params, 'field', 'username'); |
|
355 | - if($userID > 0){ |
|
356 | - $this->userObj->edit($userID); |
|
357 | - switch(true){ |
|
358 | - case ($field == $this->userObj->fieldPKName()): |
|
359 | - $out = $this->userObj->getID(); |
|
360 | - break; |
|
361 | - case ($this->userObj->issetField($field)): |
|
362 | - $out = $this->userObj->get($field); |
|
363 | - break; |
|
364 | - } |
|
365 | - } |
|
366 | - return $out; |
|
367 | - } |
|
368 | - /** |
|
369 | - * ID пользователя |
|
370 | - */ |
|
371 | - public function UserID($type = 'web'){ |
|
372 | - return $this->modx->getLoginUserID($type); |
|
373 | - } |
|
374 | - /** |
|
375 | - * Если не авторизован - то отправить на страницу |
|
376 | - */ |
|
377 | - public function isGuestGoHome($params){ |
|
378 | - if(!$this->UserID('web')){ |
|
379 | - /** |
|
380 | - * @see : http://modx.im/blog/triks/105.html |
|
381 | - */ |
|
382 | - $this->modx->invokeEvent('OnPageUnauthorized'); |
|
383 | - $id = APIHelpers::getkey($params, 'id', $this->config['unauthorized_page']); |
|
384 | - $this->moveTo(compact('id')); |
|
385 | - } |
|
386 | - return; |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * Если авторизован - то открыть личный кабинет |
|
391 | - */ |
|
392 | - public function isAuthGoHome($params){ |
|
393 | - $userID = $this->UserID('web'); |
|
394 | - if($userID>0){ |
|
395 | - $id = APIHelpers::getkey($params, 'homeID'); |
|
396 | - if(empty($id)){ |
|
397 | - $id = $this->modx->getConfig('login_home', $this->config['site_start']); |
|
398 | - } |
|
399 | - $this->moveTo(compact('id')); |
|
400 | - } |
|
401 | - return; |
|
402 | - } |
|
403 | - |
|
404 | - /** |
|
405 | - * Редирект |
|
406 | - */ |
|
407 | - public function moveTo($params){ |
|
408 | - $id = (int)APIHelpers::getkey($params, 'id', 0); |
|
409 | - $uri = APIHelpers::getkey($params, 'url', ''); |
|
410 | - if((empty($uri) && !empty($id)) || !is_string($uri)){ |
|
411 | - $uri = $this->makeUrl($id); |
|
412 | - } |
|
413 | - $code = (int)APIHelpers::getkey($params, 'code', 0); |
|
414 | - $addUrl = APIHelpers::getkey($params, 'addUrl', ''); |
|
415 | - if(is_scalar($addUrl) && $addUrl!=''){ |
|
416 | - $uri .= "?".$addUrl; |
|
417 | - } |
|
418 | - if(APIHelpers::getkey($params, 'validate', false)){ |
|
419 | - if(isset($this->modx->snippetCache['getPageID'])){ |
|
420 | - $out = $this->modx->runSnippet('getPageID', compact('uri')); |
|
421 | - if(empty($out)){ |
|
422 | - $uri = ''; |
|
423 | - } |
|
424 | - }else{ |
|
425 | - $uri = APIhelpers::sanitarTag($uri); |
|
426 | - } |
|
427 | - }else{ |
|
428 | - //$modx->sendRedirect($url, 0, 'REDIRECT_HEADER', 'HTTP/1.1 307 Temporary Redirect'); |
|
429 | - header("Location: ".$uri, true, ($code>0 ? $code : 307)); |
|
430 | - } |
|
431 | - return $uri; |
|
432 | - } |
|
433 | - |
|
434 | - /** |
|
435 | - * Создание ссылки на страницу |
|
436 | - * |
|
437 | - * @param int $id ID документа |
|
438 | - * @return string |
|
439 | - */ |
|
440 | - protected function makeUrl($id = null){ |
|
441 | - $id = (int)$id; |
|
442 | - if($id <= 0){ |
|
443 | - $id = $this->modx->documentObject['id']; |
|
444 | - } |
|
445 | - if($this->url->containsKey($id)){ |
|
446 | - $url = $this->url->get($id); |
|
447 | - }else{ |
|
448 | - $url = $this->modx->makeUrl($id); |
|
449 | - $this->url->set($id, $url); |
|
450 | - } |
|
451 | - return $url; |
|
452 | - } |
|
453 | - protected function getTemplate($name){ |
|
454 | - $out = ''; |
|
455 | - $file = dirname(dirname(__FILE__)).'/tpl/'.$name.'.html'; |
|
456 | - if( FS::getInstance()->checkFile($file)){ |
|
457 | - $out = '@CODE: '.file_get_contents($file); |
|
458 | - } |
|
459 | - return $out; |
|
460 | - } |
|
461 | - protected static function loadLang($lang){ |
|
462 | - $file = dirname(dirname(__FILE__)).'/lang/'.$lang.'.php'; |
|
463 | - if( ! FS::getInstance()->checkFile($file)){ |
|
464 | - $file = false; |
|
465 | - } |
|
466 | - if(!empty($lang) && !isset(static::$langDic[$lang]) && !empty($file)){ |
|
467 | - static::$langDic[$lang] = include_once($file); |
|
468 | - if(is_array(static::$langDic[$lang])){ |
|
469 | - static::$langDic[$lang] = APIHelpers::renameKeyArr(static::$langDic[$lang], $lang); |
|
470 | - }else{ |
|
471 | - static::$langDic[$lang] = array(); |
|
472 | - } |
|
473 | - } |
|
474 | - return !(empty($lang) || empty(static::$langDic[$lang])); |
|
475 | - } |
|
476 | - protected static function getLangMsg($key, $default){ |
|
477 | - $out = $default; |
|
478 | - $lng = static::$lang; |
|
479 | - $dic = static::$langDic; |
|
480 | - if(isset($dic[$lng], $dic[$lng][$lng.'.'.$key])){ |
|
481 | - $out = $dic[$lng][$lng.'.'.$key]; |
|
482 | - } |
|
483 | - if(class_exists('evoBabel', false) && isset(self::$instance->modx->snippetCache['lang'])){ |
|
484 | - $msg = self::$instance->modx->runSnippet('lang', array('a' => 'DLUsers.'.$key)); |
|
485 | - if(!empty($msg)){ |
|
486 | - $out = $msg; |
|
487 | - } |
|
488 | - } |
|
489 | - return $out; |
|
490 | - } |
|
195 | + /** |
|
196 | + * Авторизация на сайте со страницы авторизации |
|
197 | + * [!Auth? &login=`password` &pwdField=`password` &homeID=`72`!] |
|
198 | + */ |
|
199 | + public function AuthPage($params){ |
|
200 | + $homeID = APIHelpers::getkey($params, 'homeID'); |
|
201 | + $this->isAuthGoHome(array('id' => $homeID)); |
|
202 | + |
|
203 | + $error = $errorCode = ''; |
|
204 | + $POST = array('backUrl' => ''); |
|
205 | + |
|
206 | + $pwdField = APIHelpers::getkey($params, 'pwdField', 'password'); |
|
207 | + $emailField = APIHelpers::getkey($params, 'emailField', 'email'); |
|
208 | + $rememberField = APIHelpers::getkey($params, 'rememberField', 'remember'); |
|
209 | + |
|
210 | + $tpl = APIHelpers::getkey($params, 'tpl', ''); |
|
211 | + if(empty($tpl)){ |
|
212 | + $tpl = $this->getTemplate('authForm'); |
|
213 | + } |
|
214 | + |
|
215 | + $request = parse_url($_SERVER['REQUEST_URI']); |
|
216 | + if(!empty($_SERVER['HTTP_REFERER'])){ |
|
217 | + /** |
|
218 | + * Thank you for super protection against hacking in protect.inc.php:-) |
|
219 | + */ |
|
220 | + $refer = htmlspecialchars_decode($_SERVER['HTTP_REFERER'], ENT_QUOTES); |
|
221 | + }else{ |
|
222 | + $selfHost = rtrim(str_replace("http://", "", $this->config['site_url']), '/'); |
|
223 | + if(empty( $request['host']) || $request['host']==$selfHost){ |
|
224 | + $query = !empty($request['query']) ? '?'.$request['query'] : ''; |
|
225 | + $refer = !empty($request['path']) ? $request['path'].$query : ''; |
|
226 | + }else{ |
|
227 | + $refer = ''; |
|
228 | + } |
|
229 | + } |
|
230 | + |
|
231 | + if($_SERVER['REQUEST_METHOD'] == 'POST'){ |
|
232 | + $backUrl = APIHelpers::getkey($_POST, 'backUrl', $POST['backUrl']); |
|
233 | + if(!is_scalar($backUrl)){ |
|
234 | + $backUrl = $refer; |
|
235 | + }else{ |
|
236 | + $backUrl = urldecode($backUrl); |
|
237 | + } |
|
238 | + }else{ |
|
239 | + $backUrl = $refer; |
|
240 | + } |
|
241 | + $backUrl = parse_url($backUrl); |
|
242 | + if(!empty($backUrl['path']) && $request['path'] != $backUrl['path']){ |
|
243 | + $POST['backUrl'] = $backUrl['path']; |
|
244 | + }else{ |
|
245 | + $selfHost = rtrim(str_replace("http://", "", $this->config['site_url']), '/'); |
|
246 | + if(empty($backUrl['host']) || $backUrl['host']==$selfHost){ |
|
247 | + $query = !empty($backUrl['query']) ? '?'.$backUrl['query'] : ''; |
|
248 | + $POST['backUrl'] = !empty($backUrl['path']) ? $backUrl['path'].$query : ''; |
|
249 | + }else{ |
|
250 | + $POST['backUrl'] = ''; |
|
251 | + } |
|
252 | + } |
|
253 | + if(!empty($POST['backUrl'])){ |
|
254 | + $idURL = $this->moveTo(array( |
|
255 | + 'url' => '/'.ltrim($POST['backUrl'], '/'), |
|
256 | + 'validate' => true |
|
257 | + )); |
|
258 | + }else{ |
|
259 | + $idURL = 0; |
|
260 | + } |
|
261 | + if(empty($idURL)){ |
|
262 | + if(empty($homeID)){ |
|
263 | + $homeID = $this->config['site_start']; |
|
264 | + } |
|
265 | + $POST['backUrl'] = $this->makeUrl($homeID); |
|
266 | + } |
|
267 | + $POST = $this->Auth($pwdField, $emailField, $rememberField, $POST['backUrl'], __METHOD__, $error, $errorCode, $params); |
|
268 | + return DLTemplate::getInstance($this->modx)->parseChunk($tpl, array( |
|
269 | + 'backUrl' => APIHelpers::getkey($POST, 'backUrl', ''), |
|
270 | + 'emailValue' => APIHelpers::getkey($POST, 'email', ''), |
|
271 | + 'emailField' => $emailField, |
|
272 | + 'pwdField' => $pwdField, |
|
273 | + 'method' => strtolower(__METHOD__), |
|
274 | + 'error' => $error, |
|
275 | + 'errorCode' => $errorCode |
|
276 | + )); |
|
277 | + } |
|
278 | + protected function Auth($pwdField, $emailField, $rememberField, $backUrl, $method, &$error, &$errorCode, $params = array()){ |
|
279 | + $POST = array( |
|
280 | + 'backUrl' => urlencode($backUrl) |
|
281 | + ); |
|
282 | + $userObj = &$this->userObj; |
|
283 | + if($_SERVER['REQUEST_METHOD']=='POST' && APIHelpers::getkey($_POST, 'method', '') == strtolower($method)){ |
|
284 | + $POST = array_merge($POST, array( |
|
285 | + 'password' => APIHelpers::getkey($_POST, $pwdField, ''), |
|
286 | + 'email' => APIHelpers::getkey($_POST, $emailField, ''), |
|
287 | + 'remember' => (bool)((int)APIHelpers::getkey($_POST, $rememberField, 0)) |
|
288 | + )); |
|
289 | + if(!empty($POST['email']) && is_scalar($POST['email']) && !$userObj->emailValidate($POST['email'], false)){ |
|
290 | + $userObj->edit($POST['email']); |
|
291 | + |
|
292 | + $this->modx->invokeEvent("OnBeforeWebLogin", array( |
|
293 | + "username" => $POST['email'], |
|
294 | + "userpassword" => $POST['password'], |
|
295 | + "rememberme" => $POST['remember'], |
|
296 | + 'userObj' => $userObj |
|
297 | + )); |
|
298 | + if($userObj->getID() && !$userObj->checkBlock($userObj->getID())){ |
|
299 | + $pluginFlag = $this->modx->invokeEvent("OnWebAuthentication", array( |
|
300 | + "userid" => $userObj->getID(), |
|
301 | + "username" => $userObj->get('username'), |
|
302 | + "userpassword" => $POST['password'], |
|
303 | + "savedpassword" => $userObj->get('password'), |
|
304 | + "rememberme" => $POST['remember'], |
|
305 | + )); |
|
306 | + if( |
|
307 | + ($pluginFlag === true || $userObj->testAuth($userObj->getID(), $POST['password'], 0)) |
|
308 | + && |
|
309 | + $userObj->authUser($userObj->getID(), $POST['remember']) |
|
310 | + ){ |
|
311 | + $userObj->set('logincount', (int)$userObj->get('logincount') + 1); |
|
312 | + $userObj->set('lastlogin', time()); |
|
313 | + $userObj->set('failedlogincount', 0); |
|
314 | + $userObj->save(false, false); |
|
315 | + |
|
316 | + $this->modx->invokeEvent("OnWebLogin", array( |
|
317 | + "userid" => $userObj->getID(), |
|
318 | + "username" => $userObj->get('username'), |
|
319 | + "userpassword" => $POST['password'], |
|
320 | + "rememberme" => $POST['remember'], |
|
321 | + )); |
|
322 | + $this->moveTo(array('url' => urldecode($POST['backUrl']))); |
|
323 | + }else{ |
|
324 | + $userObj->set('failedlogincount', (int)$userObj->get('failedlogincount') + 1); |
|
325 | + $userObj->save(false, false); |
|
326 | + |
|
327 | + $error = 'error.incorrect_password'; |
|
328 | + } |
|
329 | + }else{ |
|
330 | + $error = 'error.no_user'; |
|
331 | + } |
|
332 | + }else{ |
|
333 | + $error = 'error.incorrect_mail'; |
|
334 | + $POST['email'] = ''; |
|
335 | + } |
|
336 | + } |
|
337 | + if(!empty($error)){ |
|
338 | + $errorCode = $error; |
|
339 | + $error = APIHelpers::getkey($params, $error, ''); |
|
340 | + $error = static::getLangMsg($error, $error); |
|
341 | + } |
|
342 | + return $POST; |
|
343 | + } |
|
344 | + /** |
|
345 | + * Информация о пользователе |
|
346 | + * [!DLUsers? &action=`UserInfo` &field=`fullname` &id=`2`!] |
|
347 | + */ |
|
348 | + public function UserInfo($params){ |
|
349 | + $out = ''; |
|
350 | + $userID = APIHelpers::getkey($params, 'id', 0); |
|
351 | + if(empty($userID)){ |
|
352 | + $userID = $this->UserID('web'); |
|
353 | + } |
|
354 | + $field = APIHelpers::getkey($params, 'field', 'username'); |
|
355 | + if($userID > 0){ |
|
356 | + $this->userObj->edit($userID); |
|
357 | + switch(true){ |
|
358 | + case ($field == $this->userObj->fieldPKName()): |
|
359 | + $out = $this->userObj->getID(); |
|
360 | + break; |
|
361 | + case ($this->userObj->issetField($field)): |
|
362 | + $out = $this->userObj->get($field); |
|
363 | + break; |
|
364 | + } |
|
365 | + } |
|
366 | + return $out; |
|
367 | + } |
|
368 | + /** |
|
369 | + * ID пользователя |
|
370 | + */ |
|
371 | + public function UserID($type = 'web'){ |
|
372 | + return $this->modx->getLoginUserID($type); |
|
373 | + } |
|
374 | + /** |
|
375 | + * Если не авторизован - то отправить на страницу |
|
376 | + */ |
|
377 | + public function isGuestGoHome($params){ |
|
378 | + if(!$this->UserID('web')){ |
|
379 | + /** |
|
380 | + * @see : http://modx.im/blog/triks/105.html |
|
381 | + */ |
|
382 | + $this->modx->invokeEvent('OnPageUnauthorized'); |
|
383 | + $id = APIHelpers::getkey($params, 'id', $this->config['unauthorized_page']); |
|
384 | + $this->moveTo(compact('id')); |
|
385 | + } |
|
386 | + return; |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * Если авторизован - то открыть личный кабинет |
|
391 | + */ |
|
392 | + public function isAuthGoHome($params){ |
|
393 | + $userID = $this->UserID('web'); |
|
394 | + if($userID>0){ |
|
395 | + $id = APIHelpers::getkey($params, 'homeID'); |
|
396 | + if(empty($id)){ |
|
397 | + $id = $this->modx->getConfig('login_home', $this->config['site_start']); |
|
398 | + } |
|
399 | + $this->moveTo(compact('id')); |
|
400 | + } |
|
401 | + return; |
|
402 | + } |
|
403 | + |
|
404 | + /** |
|
405 | + * Редирект |
|
406 | + */ |
|
407 | + public function moveTo($params){ |
|
408 | + $id = (int)APIHelpers::getkey($params, 'id', 0); |
|
409 | + $uri = APIHelpers::getkey($params, 'url', ''); |
|
410 | + if((empty($uri) && !empty($id)) || !is_string($uri)){ |
|
411 | + $uri = $this->makeUrl($id); |
|
412 | + } |
|
413 | + $code = (int)APIHelpers::getkey($params, 'code', 0); |
|
414 | + $addUrl = APIHelpers::getkey($params, 'addUrl', ''); |
|
415 | + if(is_scalar($addUrl) && $addUrl!=''){ |
|
416 | + $uri .= "?".$addUrl; |
|
417 | + } |
|
418 | + if(APIHelpers::getkey($params, 'validate', false)){ |
|
419 | + if(isset($this->modx->snippetCache['getPageID'])){ |
|
420 | + $out = $this->modx->runSnippet('getPageID', compact('uri')); |
|
421 | + if(empty($out)){ |
|
422 | + $uri = ''; |
|
423 | + } |
|
424 | + }else{ |
|
425 | + $uri = APIhelpers::sanitarTag($uri); |
|
426 | + } |
|
427 | + }else{ |
|
428 | + //$modx->sendRedirect($url, 0, 'REDIRECT_HEADER', 'HTTP/1.1 307 Temporary Redirect'); |
|
429 | + header("Location: ".$uri, true, ($code>0 ? $code : 307)); |
|
430 | + } |
|
431 | + return $uri; |
|
432 | + } |
|
433 | + |
|
434 | + /** |
|
435 | + * Создание ссылки на страницу |
|
436 | + * |
|
437 | + * @param int $id ID документа |
|
438 | + * @return string |
|
439 | + */ |
|
440 | + protected function makeUrl($id = null){ |
|
441 | + $id = (int)$id; |
|
442 | + if($id <= 0){ |
|
443 | + $id = $this->modx->documentObject['id']; |
|
444 | + } |
|
445 | + if($this->url->containsKey($id)){ |
|
446 | + $url = $this->url->get($id); |
|
447 | + }else{ |
|
448 | + $url = $this->modx->makeUrl($id); |
|
449 | + $this->url->set($id, $url); |
|
450 | + } |
|
451 | + return $url; |
|
452 | + } |
|
453 | + protected function getTemplate($name){ |
|
454 | + $out = ''; |
|
455 | + $file = dirname(dirname(__FILE__)).'/tpl/'.$name.'.html'; |
|
456 | + if( FS::getInstance()->checkFile($file)){ |
|
457 | + $out = '@CODE: '.file_get_contents($file); |
|
458 | + } |
|
459 | + return $out; |
|
460 | + } |
|
461 | + protected static function loadLang($lang){ |
|
462 | + $file = dirname(dirname(__FILE__)).'/lang/'.$lang.'.php'; |
|
463 | + if( ! FS::getInstance()->checkFile($file)){ |
|
464 | + $file = false; |
|
465 | + } |
|
466 | + if(!empty($lang) && !isset(static::$langDic[$lang]) && !empty($file)){ |
|
467 | + static::$langDic[$lang] = include_once($file); |
|
468 | + if(is_array(static::$langDic[$lang])){ |
|
469 | + static::$langDic[$lang] = APIHelpers::renameKeyArr(static::$langDic[$lang], $lang); |
|
470 | + }else{ |
|
471 | + static::$langDic[$lang] = array(); |
|
472 | + } |
|
473 | + } |
|
474 | + return !(empty($lang) || empty(static::$langDic[$lang])); |
|
475 | + } |
|
476 | + protected static function getLangMsg($key, $default){ |
|
477 | + $out = $default; |
|
478 | + $lng = static::$lang; |
|
479 | + $dic = static::$langDic; |
|
480 | + if(isset($dic[$lng], $dic[$lng][$lng.'.'.$key])){ |
|
481 | + $out = $dic[$lng][$lng.'.'.$key]; |
|
482 | + } |
|
483 | + if(class_exists('evoBabel', false) && isset(self::$instance->modx->snippetCache['lang'])){ |
|
484 | + $msg = self::$instance->modx->runSnippet('lang', array('a' => 'DLUsers.'.$key)); |
|
485 | + if(!empty($msg)){ |
|
486 | + $out = $msg; |
|
487 | + } |
|
488 | + } |
|
489 | + return $out; |
|
490 | + } |
|
491 | 491 | } |
492 | 492 | \ No newline at end of file |
@@ -1,15 +1,15 @@ discard block |
||
1 | 1 | <?php namespace DLUsers; |
2 | 2 | |
3 | -include_once(MODX_BASE_PATH . 'assets/lib/APIHelpers.class.php'); |
|
4 | -include_once(MODX_BASE_PATH . 'assets/lib/Helpers/FS.php'); |
|
5 | -include_once(MODX_BASE_PATH . 'assets/lib/MODxAPI/modUsers.php'); |
|
6 | -include_once(MODX_BASE_PATH . 'assets/snippets/DocLister/lib/DLTemplate.class.php'); |
|
7 | -include_once(MODX_BASE_PATH . 'assets/snippets/DocLister/lib/DLCollection.class.php'); |
|
3 | +include_once(MODX_BASE_PATH.'assets/lib/APIHelpers.class.php'); |
|
4 | +include_once(MODX_BASE_PATH.'assets/lib/Helpers/FS.php'); |
|
5 | +include_once(MODX_BASE_PATH.'assets/lib/MODxAPI/modUsers.php'); |
|
6 | +include_once(MODX_BASE_PATH.'assets/snippets/DocLister/lib/DLTemplate.class.php'); |
|
7 | +include_once(MODX_BASE_PATH.'assets/snippets/DocLister/lib/DLCollection.class.php'); |
|
8 | 8 | |
9 | 9 | use APIHelpers, DocumentParser, DLCollection, DLTemplate; |
10 | 10 | use Helpers\FS; |
11 | 11 | |
12 | -class Actions{ |
|
12 | +class Actions { |
|
13 | 13 | protected $modx = null; |
14 | 14 | public $userObj = null; |
15 | 15 | /** |
@@ -84,20 +84,20 @@ discard block |
||
84 | 84 | /** |
85 | 85 | * Сброс авторизации и обновление страницы |
86 | 86 | */ |
87 | - public function logout($params){ |
|
87 | + public function logout($params) { |
|
88 | 88 | $LogoutName = APIHelpers::getkey($params, 'LogoutName', 'logout'); |
89 | - if(is_scalar($LogoutName) && !empty($LogoutName) && isset($_GET[$LogoutName])){ |
|
89 | + if (is_scalar($LogoutName) && !empty($LogoutName) && isset($_GET[$LogoutName])) { |
|
90 | 90 | $userID = $this->UserID('web'); |
91 | - if($userID){ |
|
91 | + if ($userID) { |
|
92 | 92 | $this->userObj->edit($userID); |
93 | - if($this->userObj->getID()){ |
|
93 | + if ($this->userObj->getID()) { |
|
94 | 94 | $this->modx->invokeEvent("OnBeforeWebLogout", array( |
95 | 95 | "userid" => $this->userObj->getID(), |
96 | 96 | "username" => $this->userObj->get('username') |
97 | 97 | )); |
98 | 98 | } |
99 | 99 | $this->userObj->logOut(); |
100 | - if($this->userObj->getID()){ |
|
100 | + if ($this->userObj->getID()) { |
|
101 | 101 | $this->modx->invokeEvent("OnWebLogout", array( |
102 | 102 | "userid" => $this->userObj->getID(), |
103 | 103 | "username" => $this->userObj->get('username') |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | } |
106 | 106 | |
107 | 107 | $go = APIHelpers::getkey($params, 'url', ''); |
108 | - if(empty($go)){ |
|
108 | + if (empty($go)) { |
|
109 | 109 | $go = str_replace( |
110 | 110 | array("?".$LogoutName, "&".$LogoutName), |
111 | 111 | array("", ""), |
@@ -114,13 +114,13 @@ discard block |
||
114 | 114 | } |
115 | 115 | |
116 | 116 | $start = $this->makeUrl($this->config['site_start']); |
117 | - if($start == $go){ |
|
117 | + if ($start == $go) { |
|
118 | 118 | $go = $this->config['site_url']; |
119 | - }else{ |
|
119 | + } else { |
|
120 | 120 | $go = $this->config['site_url'].ltrim($go, '/'); |
121 | 121 | } |
122 | 122 | $this->moveTo(array('url' => $go)); |
123 | - }else{ |
|
123 | + } else { |
|
124 | 124 | //Если юзер не авторизован, то показываем ему 404 ошибку |
125 | 125 | $this->modx->sendErrorPage(); |
126 | 126 | } |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | * Генерация ссылки под кнопку выход |
133 | 133 | * @return string |
134 | 134 | */ |
135 | - public function logoutUrl($params){ |
|
135 | + public function logoutUrl($params) { |
|
136 | 136 | $LogoutName = APIHelpers::getkey($params, 'LogoutName', 'logout'); |
137 | 137 | $request = parse_url($_SERVER['REQUEST_URI']); |
138 | 138 | |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | * если указан параметр authId, то данные из формы перекидываются в метод AuthPage |
149 | 149 | * В противном случае вся работа происходит внутри самого блока |
150 | 150 | */ |
151 | - public function AuthBlock($params){ |
|
151 | + public function AuthBlock($params) { |
|
152 | 152 | $POST = array('backUrl' => $_SERVER['REQUEST_URI']); |
153 | 153 | |
154 | 154 | $error = $errorCode = ''; |
@@ -157,20 +157,20 @@ discard block |
||
157 | 157 | $emailField = APIHelpers::getkey($params, 'emailField', 'email'); |
158 | 158 | $rememberField = APIHelpers::getkey($params, 'rememberField', 'remember'); |
159 | 159 | |
160 | - if($this->UserID('web')){ |
|
160 | + if ($this->UserID('web')) { |
|
161 | 161 | $tpl = APIHelpers::getkey($params, 'tplProfile', ''); |
162 | - if(empty($tpl)){ |
|
162 | + if (empty($tpl)) { |
|
163 | 163 | $tpl = $this->getTemplate('tplProfile'); |
164 | 164 | } |
165 | 165 | $dataTPL = $this->userObj->toArray(); |
166 | 166 | $dataTPL['url.logout'] = $this->logoutUrl($params); |
167 | 167 | $homeID = APIHelpers::getkey($params, 'homeID'); |
168 | - if(!empty($homeID)){ |
|
168 | + if (!empty($homeID)) { |
|
169 | 169 | $dataTPL['url.profile'] = $this->makeUrl($homeID); |
170 | 170 | } |
171 | - }else{ |
|
171 | + } else { |
|
172 | 172 | $tpl = APIHelpers::getkey($params, 'tplForm', ''); |
173 | - if(empty($tpl)){ |
|
173 | + if (empty($tpl)) { |
|
174 | 174 | $tpl = $this->getTemplate('authForm'); |
175 | 175 | } |
176 | 176 | $POST = $this->Auth($pwdField, $emailField, $rememberField, $POST['backUrl'], __METHOD__, $error, $errorCode, $params); |
@@ -184,9 +184,9 @@ discard block |
||
184 | 184 | 'errorCode' => $errorCode |
185 | 185 | ); |
186 | 186 | $authId = APIHelpers::getkey($params, 'authId'); |
187 | - if(!empty($authId)){ |
|
187 | + if (!empty($authId)) { |
|
188 | 188 | $dataTPL['authPage'] = $this->makeUrl($authId); |
189 | - $dataTPL['method'] = strtolower(__CLASS__ . '::'. 'authpage'); |
|
189 | + $dataTPL['method'] = strtolower(__CLASS__.'::'.'authpage'); |
|
190 | 190 | } |
191 | 191 | } |
192 | 192 | return DLTemplate::getInstance($this->modx)->parseChunk($tpl, $dataTPL); |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | * Авторизация на сайте со страницы авторизации |
197 | 197 | * [!Auth? &login=`password` &pwdField=`password` &homeID=`72`!] |
198 | 198 | */ |
199 | - public function AuthPage($params){ |
|
199 | + public function AuthPage($params) { |
|
200 | 200 | $homeID = APIHelpers::getkey($params, 'homeID'); |
201 | 201 | $this->isAuthGoHome(array('id' => $homeID)); |
202 | 202 | |
@@ -208,58 +208,58 @@ discard block |
||
208 | 208 | $rememberField = APIHelpers::getkey($params, 'rememberField', 'remember'); |
209 | 209 | |
210 | 210 | $tpl = APIHelpers::getkey($params, 'tpl', ''); |
211 | - if(empty($tpl)){ |
|
211 | + if (empty($tpl)) { |
|
212 | 212 | $tpl = $this->getTemplate('authForm'); |
213 | 213 | } |
214 | 214 | |
215 | 215 | $request = parse_url($_SERVER['REQUEST_URI']); |
216 | - if(!empty($_SERVER['HTTP_REFERER'])){ |
|
216 | + if (!empty($_SERVER['HTTP_REFERER'])) { |
|
217 | 217 | /** |
218 | 218 | * Thank you for super protection against hacking in protect.inc.php:-) |
219 | 219 | */ |
220 | 220 | $refer = htmlspecialchars_decode($_SERVER['HTTP_REFERER'], ENT_QUOTES); |
221 | - }else{ |
|
221 | + } else { |
|
222 | 222 | $selfHost = rtrim(str_replace("http://", "", $this->config['site_url']), '/'); |
223 | - if(empty( $request['host']) || $request['host']==$selfHost){ |
|
223 | + if (empty($request['host']) || $request['host'] == $selfHost) { |
|
224 | 224 | $query = !empty($request['query']) ? '?'.$request['query'] : ''; |
225 | 225 | $refer = !empty($request['path']) ? $request['path'].$query : ''; |
226 | - }else{ |
|
226 | + } else { |
|
227 | 227 | $refer = ''; |
228 | 228 | } |
229 | 229 | } |
230 | 230 | |
231 | - if($_SERVER['REQUEST_METHOD'] == 'POST'){ |
|
231 | + if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
232 | 232 | $backUrl = APIHelpers::getkey($_POST, 'backUrl', $POST['backUrl']); |
233 | - if(!is_scalar($backUrl)){ |
|
233 | + if (!is_scalar($backUrl)) { |
|
234 | 234 | $backUrl = $refer; |
235 | - }else{ |
|
235 | + } else { |
|
236 | 236 | $backUrl = urldecode($backUrl); |
237 | 237 | } |
238 | - }else{ |
|
238 | + } else { |
|
239 | 239 | $backUrl = $refer; |
240 | 240 | } |
241 | 241 | $backUrl = parse_url($backUrl); |
242 | - if(!empty($backUrl['path']) && $request['path'] != $backUrl['path']){ |
|
242 | + if (!empty($backUrl['path']) && $request['path'] != $backUrl['path']) { |
|
243 | 243 | $POST['backUrl'] = $backUrl['path']; |
244 | - }else{ |
|
244 | + } else { |
|
245 | 245 | $selfHost = rtrim(str_replace("http://", "", $this->config['site_url']), '/'); |
246 | - if(empty($backUrl['host']) || $backUrl['host']==$selfHost){ |
|
246 | + if (empty($backUrl['host']) || $backUrl['host'] == $selfHost) { |
|
247 | 247 | $query = !empty($backUrl['query']) ? '?'.$backUrl['query'] : ''; |
248 | 248 | $POST['backUrl'] = !empty($backUrl['path']) ? $backUrl['path'].$query : ''; |
249 | - }else{ |
|
249 | + } else { |
|
250 | 250 | $POST['backUrl'] = ''; |
251 | 251 | } |
252 | 252 | } |
253 | - if(!empty($POST['backUrl'])){ |
|
253 | + if (!empty($POST['backUrl'])) { |
|
254 | 254 | $idURL = $this->moveTo(array( |
255 | 255 | 'url' => '/'.ltrim($POST['backUrl'], '/'), |
256 | 256 | 'validate' => true |
257 | 257 | )); |
258 | - }else{ |
|
258 | + } else { |
|
259 | 259 | $idURL = 0; |
260 | 260 | } |
261 | - if(empty($idURL)){ |
|
262 | - if(empty($homeID)){ |
|
261 | + if (empty($idURL)) { |
|
262 | + if (empty($homeID)) { |
|
263 | 263 | $homeID = $this->config['site_start']; |
264 | 264 | } |
265 | 265 | $POST['backUrl'] = $this->makeUrl($homeID); |
@@ -275,18 +275,18 @@ discard block |
||
275 | 275 | 'errorCode' => $errorCode |
276 | 276 | )); |
277 | 277 | } |
278 | - protected function Auth($pwdField, $emailField, $rememberField, $backUrl, $method, &$error, &$errorCode, $params = array()){ |
|
278 | + protected function Auth($pwdField, $emailField, $rememberField, $backUrl, $method, &$error, &$errorCode, $params = array()) { |
|
279 | 279 | $POST = array( |
280 | 280 | 'backUrl' => urlencode($backUrl) |
281 | 281 | ); |
282 | 282 | $userObj = &$this->userObj; |
283 | - if($_SERVER['REQUEST_METHOD']=='POST' && APIHelpers::getkey($_POST, 'method', '') == strtolower($method)){ |
|
283 | + if ($_SERVER['REQUEST_METHOD'] == 'POST' && APIHelpers::getkey($_POST, 'method', '') == strtolower($method)) { |
|
284 | 284 | $POST = array_merge($POST, array( |
285 | 285 | 'password' => APIHelpers::getkey($_POST, $pwdField, ''), |
286 | 286 | 'email' => APIHelpers::getkey($_POST, $emailField, ''), |
287 | 287 | 'remember' => (bool)((int)APIHelpers::getkey($_POST, $rememberField, 0)) |
288 | 288 | )); |
289 | - if(!empty($POST['email']) && is_scalar($POST['email']) && !$userObj->emailValidate($POST['email'], false)){ |
|
289 | + if (!empty($POST['email']) && is_scalar($POST['email']) && !$userObj->emailValidate($POST['email'], false)) { |
|
290 | 290 | $userObj->edit($POST['email']); |
291 | 291 | |
292 | 292 | $this->modx->invokeEvent("OnBeforeWebLogin", array( |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | "rememberme" => $POST['remember'], |
296 | 296 | 'userObj' => $userObj |
297 | 297 | )); |
298 | - if($userObj->getID() && !$userObj->checkBlock($userObj->getID())){ |
|
298 | + if ($userObj->getID() && !$userObj->checkBlock($userObj->getID())) { |
|
299 | 299 | $pluginFlag = $this->modx->invokeEvent("OnWebAuthentication", array( |
300 | 300 | "userid" => $userObj->getID(), |
301 | 301 | "username" => $userObj->get('username'), |
@@ -303,11 +303,11 @@ discard block |
||
303 | 303 | "savedpassword" => $userObj->get('password'), |
304 | 304 | "rememberme" => $POST['remember'], |
305 | 305 | )); |
306 | - if( |
|
306 | + if ( |
|
307 | 307 | ($pluginFlag === true || $userObj->testAuth($userObj->getID(), $POST['password'], 0)) |
308 | 308 | && |
309 | 309 | $userObj->authUser($userObj->getID(), $POST['remember']) |
310 | - ){ |
|
310 | + ) { |
|
311 | 311 | $userObj->set('logincount', (int)$userObj->get('logincount') + 1); |
312 | 312 | $userObj->set('lastlogin', time()); |
313 | 313 | $userObj->set('failedlogincount', 0); |
@@ -320,21 +320,21 @@ discard block |
||
320 | 320 | "rememberme" => $POST['remember'], |
321 | 321 | )); |
322 | 322 | $this->moveTo(array('url' => urldecode($POST['backUrl']))); |
323 | - }else{ |
|
323 | + } else { |
|
324 | 324 | $userObj->set('failedlogincount', (int)$userObj->get('failedlogincount') + 1); |
325 | 325 | $userObj->save(false, false); |
326 | 326 | |
327 | 327 | $error = 'error.incorrect_password'; |
328 | 328 | } |
329 | - }else{ |
|
329 | + } else { |
|
330 | 330 | $error = 'error.no_user'; |
331 | 331 | } |
332 | - }else{ |
|
332 | + } else { |
|
333 | 333 | $error = 'error.incorrect_mail'; |
334 | 334 | $POST['email'] = ''; |
335 | 335 | } |
336 | 336 | } |
337 | - if(!empty($error)){ |
|
337 | + if (!empty($error)) { |
|
338 | 338 | $errorCode = $error; |
339 | 339 | $error = APIHelpers::getkey($params, $error, ''); |
340 | 340 | $error = static::getLangMsg($error, $error); |
@@ -345,16 +345,16 @@ discard block |
||
345 | 345 | * Информация о пользователе |
346 | 346 | * [!DLUsers? &action=`UserInfo` &field=`fullname` &id=`2`!] |
347 | 347 | */ |
348 | - public function UserInfo($params){ |
|
348 | + public function UserInfo($params) { |
|
349 | 349 | $out = ''; |
350 | 350 | $userID = APIHelpers::getkey($params, 'id', 0); |
351 | - if(empty($userID)){ |
|
351 | + if (empty($userID)) { |
|
352 | 352 | $userID = $this->UserID('web'); |
353 | 353 | } |
354 | 354 | $field = APIHelpers::getkey($params, 'field', 'username'); |
355 | - if($userID > 0){ |
|
355 | + if ($userID > 0) { |
|
356 | 356 | $this->userObj->edit($userID); |
357 | - switch(true){ |
|
357 | + switch (true) { |
|
358 | 358 | case ($field == $this->userObj->fieldPKName()): |
359 | 359 | $out = $this->userObj->getID(); |
360 | 360 | break; |
@@ -368,14 +368,14 @@ discard block |
||
368 | 368 | /** |
369 | 369 | * ID пользователя |
370 | 370 | */ |
371 | - public function UserID($type = 'web'){ |
|
371 | + public function UserID($type = 'web') { |
|
372 | 372 | return $this->modx->getLoginUserID($type); |
373 | 373 | } |
374 | 374 | /** |
375 | 375 | * Если не авторизован - то отправить на страницу |
376 | 376 | */ |
377 | - public function isGuestGoHome($params){ |
|
378 | - if(!$this->UserID('web')){ |
|
377 | + public function isGuestGoHome($params) { |
|
378 | + if (!$this->UserID('web')) { |
|
379 | 379 | /** |
380 | 380 | * @see : http://modx.im/blog/triks/105.html |
381 | 381 | */ |
@@ -389,11 +389,11 @@ discard block |
||
389 | 389 | /** |
390 | 390 | * Если авторизован - то открыть личный кабинет |
391 | 391 | */ |
392 | - public function isAuthGoHome($params){ |
|
392 | + public function isAuthGoHome($params) { |
|
393 | 393 | $userID = $this->UserID('web'); |
394 | - if($userID>0){ |
|
394 | + if ($userID > 0) { |
|
395 | 395 | $id = APIHelpers::getkey($params, 'homeID'); |
396 | - if(empty($id)){ |
|
396 | + if (empty($id)) { |
|
397 | 397 | $id = $this->modx->getConfig('login_home', $this->config['site_start']); |
398 | 398 | } |
399 | 399 | $this->moveTo(compact('id')); |
@@ -404,29 +404,29 @@ discard block |
||
404 | 404 | /** |
405 | 405 | * Редирект |
406 | 406 | */ |
407 | - public function moveTo($params){ |
|
407 | + public function moveTo($params) { |
|
408 | 408 | $id = (int)APIHelpers::getkey($params, 'id', 0); |
409 | 409 | $uri = APIHelpers::getkey($params, 'url', ''); |
410 | - if((empty($uri) && !empty($id)) || !is_string($uri)){ |
|
410 | + if ((empty($uri) && !empty($id)) || !is_string($uri)) { |
|
411 | 411 | $uri = $this->makeUrl($id); |
412 | 412 | } |
413 | 413 | $code = (int)APIHelpers::getkey($params, 'code', 0); |
414 | 414 | $addUrl = APIHelpers::getkey($params, 'addUrl', ''); |
415 | - if(is_scalar($addUrl) && $addUrl!=''){ |
|
415 | + if (is_scalar($addUrl) && $addUrl != '') { |
|
416 | 416 | $uri .= "?".$addUrl; |
417 | 417 | } |
418 | - if(APIHelpers::getkey($params, 'validate', false)){ |
|
419 | - if(isset($this->modx->snippetCache['getPageID'])){ |
|
418 | + if (APIHelpers::getkey($params, 'validate', false)) { |
|
419 | + if (isset($this->modx->snippetCache['getPageID'])) { |
|
420 | 420 | $out = $this->modx->runSnippet('getPageID', compact('uri')); |
421 | - if(empty($out)){ |
|
421 | + if (empty($out)) { |
|
422 | 422 | $uri = ''; |
423 | 423 | } |
424 | - }else{ |
|
424 | + } else { |
|
425 | 425 | $uri = APIhelpers::sanitarTag($uri); |
426 | 426 | } |
427 | - }else{ |
|
427 | + } else { |
|
428 | 428 | //$modx->sendRedirect($url, 0, 'REDIRECT_HEADER', 'HTTP/1.1 307 Temporary Redirect'); |
429 | - header("Location: ".$uri, true, ($code>0 ? $code : 307)); |
|
429 | + header("Location: ".$uri, true, ($code > 0 ? $code : 307)); |
|
430 | 430 | } |
431 | 431 | return $uri; |
432 | 432 | } |
@@ -437,52 +437,52 @@ discard block |
||
437 | 437 | * @param int $id ID документа |
438 | 438 | * @return string |
439 | 439 | */ |
440 | - protected function makeUrl($id = null){ |
|
440 | + protected function makeUrl($id = null) { |
|
441 | 441 | $id = (int)$id; |
442 | - if($id <= 0){ |
|
442 | + if ($id <= 0) { |
|
443 | 443 | $id = $this->modx->documentObject['id']; |
444 | 444 | } |
445 | - if($this->url->containsKey($id)){ |
|
445 | + if ($this->url->containsKey($id)) { |
|
446 | 446 | $url = $this->url->get($id); |
447 | - }else{ |
|
447 | + } else { |
|
448 | 448 | $url = $this->modx->makeUrl($id); |
449 | 449 | $this->url->set($id, $url); |
450 | 450 | } |
451 | 451 | return $url; |
452 | 452 | } |
453 | - protected function getTemplate($name){ |
|
453 | + protected function getTemplate($name) { |
|
454 | 454 | $out = ''; |
455 | 455 | $file = dirname(dirname(__FILE__)).'/tpl/'.$name.'.html'; |
456 | - if( FS::getInstance()->checkFile($file)){ |
|
456 | + if (FS::getInstance()->checkFile($file)) { |
|
457 | 457 | $out = '@CODE: '.file_get_contents($file); |
458 | 458 | } |
459 | 459 | return $out; |
460 | 460 | } |
461 | - protected static function loadLang($lang){ |
|
461 | + protected static function loadLang($lang) { |
|
462 | 462 | $file = dirname(dirname(__FILE__)).'/lang/'.$lang.'.php'; |
463 | - if( ! FS::getInstance()->checkFile($file)){ |
|
463 | + if (!FS::getInstance()->checkFile($file)) { |
|
464 | 464 | $file = false; |
465 | 465 | } |
466 | - if(!empty($lang) && !isset(static::$langDic[$lang]) && !empty($file)){ |
|
466 | + if (!empty($lang) && !isset(static::$langDic[$lang]) && !empty($file)) { |
|
467 | 467 | static::$langDic[$lang] = include_once($file); |
468 | - if(is_array(static::$langDic[$lang])){ |
|
468 | + if (is_array(static::$langDic[$lang])) { |
|
469 | 469 | static::$langDic[$lang] = APIHelpers::renameKeyArr(static::$langDic[$lang], $lang); |
470 | - }else{ |
|
470 | + } else { |
|
471 | 471 | static::$langDic[$lang] = array(); |
472 | 472 | } |
473 | 473 | } |
474 | 474 | return !(empty($lang) || empty(static::$langDic[$lang])); |
475 | 475 | } |
476 | - protected static function getLangMsg($key, $default){ |
|
476 | + protected static function getLangMsg($key, $default) { |
|
477 | 477 | $out = $default; |
478 | 478 | $lng = static::$lang; |
479 | 479 | $dic = static::$langDic; |
480 | - if(isset($dic[$lng], $dic[$lng][$lng.'.'.$key])){ |
|
480 | + if (isset($dic[$lng], $dic[$lng][$lng.'.'.$key])) { |
|
481 | 481 | $out = $dic[$lng][$lng.'.'.$key]; |
482 | 482 | } |
483 | - if(class_exists('evoBabel', false) && isset(self::$instance->modx->snippetCache['lang'])){ |
|
483 | + if (class_exists('evoBabel', false) && isset(self::$instance->modx->snippetCache['lang'])) { |
|
484 | 484 | $msg = self::$instance->modx->runSnippet('lang', array('a' => 'DLUsers.'.$key)); |
485 | - if(!empty($msg)){ |
|
485 | + if (!empty($msg)) { |
|
486 | 486 | $out = $msg; |
487 | 487 | } |
488 | 488 | } |
@@ -436,6 +436,10 @@ |
||
436 | 436 | return $out; |
437 | 437 | } |
438 | 438 | |
439 | + /** |
|
440 | + * @param string $table |
|
441 | + * @param string $sort |
|
442 | + */ |
|
439 | 443 | protected function injectSortByTV($table, $sort) |
440 | 444 | { |
441 | 445 | $out = $this->getExtender('tv', true, true)->injectSortByTV($table, $sort); |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | $comments = $extJotCount->countComments(array_keys($this->_docs)); |
137 | 137 | } |
138 | 138 | |
139 | - $this->skippedDocs = 0; |
|
139 | + $this->skippedDocs = 0; |
|
140 | 140 | foreach ($this->_docs as $item) { |
141 | 141 | $this->renderTPL = $tpl; |
142 | 142 | if ($extUser) { |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | |
171 | 171 | $findTpl = $this->renderTPL; |
172 | 172 | $tmp = $this->uniformPrepare($item, $i); |
173 | - extract($tmp, EXTR_SKIP); |
|
173 | + extract($tmp, EXTR_SKIP); |
|
174 | 174 | if ($this->renderTPL == '') { |
175 | 175 | $this->renderTPL = $findTpl; |
176 | 176 | } |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | 'nameParam' => 'prepare' |
182 | 182 | )); |
183 | 183 | if (is_bool($item) && $item === false) { |
184 | - $this->skippedDocs++; |
|
184 | + $this->skippedDocs++; |
|
185 | 185 | continue; |
186 | 186 | } |
187 | 187 | } |
@@ -217,13 +217,13 @@ discard block |
||
217 | 217 | $extSummary = $this->getExtender('summary'); |
218 | 218 | |
219 | 219 | /** |
220 | - * @var $extPrepare prepare_DL_Extender |
|
221 | - */ |
|
220 | + * @var $extPrepare prepare_DL_Extender |
|
221 | + */ |
|
222 | 222 | $extPrepare = $this->getExtender('prepare'); |
223 | 223 | |
224 | 224 | /** |
225 | - * @var $extE e_DL_Extender |
|
226 | - */ |
|
225 | + * @var $extE e_DL_Extender |
|
226 | + */ |
|
227 | 227 | $extE = $this->getExtender('e', true, true); |
228 | 228 | |
229 | 229 | foreach ($data as $num => $item) { |
@@ -291,18 +291,18 @@ discard block |
||
291 | 291 | if ($sanitarInIDs != "''") { |
292 | 292 | switch ($this->getCFGDef('idType', 'parents')) { |
293 | 293 | case 'parents': |
294 | - switch($this->getCFGDef('showParent', '0')){ |
|
295 | - case '-1': |
|
296 | - $tmpWhere = "c.parent IN (" . $sanitarInIDs . ")"; |
|
297 | - break; |
|
298 | - case 0: |
|
299 | - $tmpWhere = "c.parent IN ({$sanitarInIDs}) AND c.id NOT IN({$sanitarInIDs})"; |
|
300 | - break; |
|
301 | - case 1: |
|
302 | - default: |
|
303 | - $tmpWhere = "(c.parent IN ({$sanitarInIDs}) OR c.id IN({$sanitarInIDs}))"; |
|
304 | - break; |
|
305 | - } |
|
294 | + switch($this->getCFGDef('showParent', '0')){ |
|
295 | + case '-1': |
|
296 | + $tmpWhere = "c.parent IN (" . $sanitarInIDs . ")"; |
|
297 | + break; |
|
298 | + case 0: |
|
299 | + $tmpWhere = "c.parent IN ({$sanitarInIDs}) AND c.id NOT IN({$sanitarInIDs})"; |
|
300 | + break; |
|
301 | + case 1: |
|
302 | + default: |
|
303 | + $tmpWhere = "(c.parent IN ({$sanitarInIDs}) OR c.id IN({$sanitarInIDs}))"; |
|
304 | + break; |
|
305 | + } |
|
306 | 306 | if (($addDocs = $this->getCFGDef('documents', '')) != '') { |
307 | 307 | $addDocs = $this->sanitarIn($this->cleanIDs($addDocs)); |
308 | 308 | $whereArr[] = "((" . $tmpWhere . ") OR c.id IN({$addDocs}))"; |
@@ -458,17 +458,17 @@ discard block |
||
458 | 458 | $tmpWhere = null; |
459 | 459 | if ($sanitarInIDs != "''") { |
460 | 460 | switch($this->getCFGDef('showParent', '0')){ |
461 | - case '-1': |
|
462 | - $tmpWhere = "c.parent IN (" . $sanitarInIDs . ")"; |
|
463 | - break; |
|
464 | - case 0: |
|
465 | - $tmpWhere = "c.parent IN (" . $sanitarInIDs . ") AND c.id NOT IN(" . $sanitarInIDs . ")"; |
|
466 | - break; |
|
467 | - case 1: |
|
468 | - default: |
|
469 | - $tmpWhere = "(c.parent IN (" . $sanitarInIDs . ") OR c.id IN({$sanitarInIDs}))"; |
|
470 | - break; |
|
471 | - } |
|
461 | + case '-1': |
|
462 | + $tmpWhere = "c.parent IN (" . $sanitarInIDs . ")"; |
|
463 | + break; |
|
464 | + case 0: |
|
465 | + $tmpWhere = "c.parent IN (" . $sanitarInIDs . ") AND c.id NOT IN(" . $sanitarInIDs . ")"; |
|
466 | + break; |
|
467 | + case 1: |
|
468 | + default: |
|
469 | + $tmpWhere = "(c.parent IN (" . $sanitarInIDs . ") OR c.id IN({$sanitarInIDs}))"; |
|
470 | + break; |
|
471 | + } |
|
472 | 472 | } |
473 | 473 | if (($addDocs = $this->getCFGDef('documents', '')) != '') { |
474 | 474 | $addDocs = $this->sanitarIn($this->cleanIDs($addDocs)); |
@@ -45,9 +45,9 @@ discard block |
||
45 | 45 | $id = ((int)$id > 0) ? (int)$id : $this->getCurrentMODXPageID(); |
46 | 46 | |
47 | 47 | $link = $this->checkExtender('request') ? $this->extender['request']->getLink() : $this->getRequest(); |
48 | - if($id == $this->modx->config['site_start']){ |
|
48 | + if ($id == $this->modx->config['site_start']) { |
|
49 | 49 | $url = $this->modx->config['site_url'].($link != '' ? "?{$link}" : ""); |
50 | - }else{ |
|
50 | + } else { |
|
51 | 51 | $url = $this->modx->makeUrl($id, '', $link, $this->getCFGDef('urlScheme', '')); |
52 | 52 | } |
53 | 53 | return $url; |
@@ -154,10 +154,10 @@ discard block |
||
154 | 154 | |
155 | 155 | $item['title'] = ($item['menutitle'] == '' ? $item['pagetitle'] : $item['menutitle']); |
156 | 156 | |
157 | - if($this->getCFGDef('makeUrl', 1)){ |
|
158 | - if($item['type'] == 'reference'){ |
|
157 | + if ($this->getCFGDef('makeUrl', 1)) { |
|
158 | + if ($item['type'] == 'reference') { |
|
159 | 159 | $item['url'] = is_numeric($item['content']) ? $this->modx->makeUrl($item['content'], '', '', $this->getCFGDef('urlScheme', '')) : $item['content']; |
160 | - }else{ |
|
160 | + } else { |
|
161 | 161 | $item['url'] = $this->modx->makeUrl($item['id'], '', '', $this->getCFGDef('urlScheme', '')); |
162 | 162 | } |
163 | 163 | } |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | $tmp = $this->parseChunk($this->renderTPL, $item); |
189 | 189 | |
190 | 190 | if ($this->getCFGDef('contentPlaceholder', 0) !== 0) { |
191 | - $this->toPlaceholders($tmp, 1, "item[" . $i . "]"); // [+item[x]+] – individual placeholder for each iteration documents on this page |
|
191 | + $this->toPlaceholders($tmp, 1, "item[".$i."]"); // [+item[x]+] – individual placeholder for each iteration documents on this page |
|
192 | 192 | } |
193 | 193 | $out .= $tmp; |
194 | 194 | $i++; |
@@ -228,25 +228,25 @@ discard block |
||
228 | 228 | |
229 | 229 | foreach ($data as $num => $item) { |
230 | 230 | $row = $item; |
231 | - if((array('1') == $fields || in_array('summary', $fields)) && $extSummary) { |
|
231 | + if ((array('1') == $fields || in_array('summary', $fields)) && $extSummary) { |
|
232 | 232 | $row['summary'] = $this->getSummary($this->_docs[$num], $extSummary, 'introtext', 'content'); |
233 | 233 | } |
234 | - if(array('1') == $fields || in_array('date', $fields)) { |
|
234 | + if (array('1') == $fields || in_array('date', $fields)) { |
|
235 | 235 | $tmp = (isset($this->_docs[$num][$date]) && $date != 'createdon' && $this->_docs[$num][$date] != 0 && $this->_docs[$num][$date] == (int)$this->_docs[$num][$date]) ? $this->_docs[$num][$date] : $this->_docs[$num]['createdon']; |
236 | 236 | $row['date'] = strftime($this->getCFGDef('dateFormat', '%d.%b.%y %H:%M'), $tmp + $this->modx->config['server_offset_time']); |
237 | 237 | } |
238 | - if(array('1') == $fields || in_array(array('menutitle', 'pagetitle'), $fields)) { |
|
238 | + if (array('1') == $fields || in_array(array('menutitle', 'pagetitle'), $fields)) { |
|
239 | 239 | $row['title'] = ($row['menutitle'] == '' ? $row['pagetitle'] : $row['menutitle']); |
240 | 240 | } |
241 | - if((bool)$this->getCFGDef('makeUrl', 1) && (array('1') == $fields || in_array(array('content', 'type'), $fields))){ |
|
242 | - if($row['type'] == 'reference'){ |
|
241 | + if ((bool)$this->getCFGDef('makeUrl', 1) && (array('1') == $fields || in_array(array('content', 'type'), $fields))) { |
|
242 | + if ($row['type'] == 'reference') { |
|
243 | 243 | $row['url'] = is_numeric($row['content']) ? $this->modx->makeUrl($row['content'], '', '', $this->getCFGDef('urlScheme', '')) : $row['content']; |
244 | - }else{ |
|
244 | + } else { |
|
245 | 245 | $row['url'] = $this->modx->makeUrl($row['id'], '', '', $this->getCFGDef('urlScheme', '')); |
246 | 246 | } |
247 | 247 | } |
248 | - if($extE && $tmp = $extE->init($this, array('data' => $row))){ |
|
249 | - if(is_array($tmp)){ |
|
248 | + if ($extE && $tmp = $extE->init($this, array('data' => $row))) { |
|
249 | + if (is_array($tmp)) { |
|
250 | 250 | $row = $tmp; |
251 | 251 | } |
252 | 252 | } |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
275 | 275 | $where = $this->getCFGDef('addWhereList', ''); |
276 | 276 | $where = sqlHelper::trimLogicalOp($where); |
277 | - $where = ($where ? $where . ' AND ' : '') . $this->_filters['where']; |
|
277 | + $where = ($where ? $where.' AND ' : '').$this->_filters['where']; |
|
278 | 278 | if ($where != '' && $this->_filters['where'] != '') { |
279 | 279 | $where .= " AND "; |
280 | 280 | } |
@@ -291,9 +291,9 @@ discard block |
||
291 | 291 | if ($sanitarInIDs != "''") { |
292 | 292 | switch ($this->getCFGDef('idType', 'parents')) { |
293 | 293 | case 'parents': |
294 | - switch($this->getCFGDef('showParent', '0')){ |
|
294 | + switch ($this->getCFGDef('showParent', '0')) { |
|
295 | 295 | case '-1': |
296 | - $tmpWhere = "c.parent IN (" . $sanitarInIDs . ")"; |
|
296 | + $tmpWhere = "c.parent IN (".$sanitarInIDs.")"; |
|
297 | 297 | break; |
298 | 298 | case 0: |
299 | 299 | $tmpWhere = "c.parent IN ({$sanitarInIDs}) AND c.id NOT IN({$sanitarInIDs})"; |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | } |
306 | 306 | if (($addDocs = $this->getCFGDef('documents', '')) != '') { |
307 | 307 | $addDocs = $this->sanitarIn($this->cleanIDs($addDocs)); |
308 | - $whereArr[] = "((" . $tmpWhere . ") OR c.id IN({$addDocs}))"; |
|
308 | + $whereArr[] = "((".$tmpWhere.") OR c.id IN({$addDocs}))"; |
|
309 | 309 | } else { |
310 | 310 | $whereArr[] = $tmpWhere; |
311 | 311 | } |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | break; |
317 | 317 | } |
318 | 318 | } |
319 | - $from = $tbl_site_content . " " . $this->_filters['join']; |
|
319 | + $from = $tbl_site_content." ".$this->_filters['join']; |
|
320 | 320 | $where = sqlHelper::trimLogicalOp($where); |
321 | 321 | |
322 | 322 | if (trim($where) != 'WHERE') { |
@@ -347,12 +347,12 @@ discard block |
||
347 | 347 | $where = $this->getCFGDef('addWhereList', ''); |
348 | 348 | $where = sqlHelper::trimLogicalOp($where); |
349 | 349 | |
350 | - $where = ($where ? $where . ' AND ' : '') . $this->_filters['where']; |
|
350 | + $where = ($where ? $where.' AND ' : '').$this->_filters['where']; |
|
351 | 351 | $where = sqlHelper::trimLogicalOp($where); |
352 | 352 | |
353 | 353 | $tbl_site_content = $this->getTable('site_content', 'c'); |
354 | 354 | if ($sanitarInIDs != "''") { |
355 | - $where .= ($where ? " AND " : "") . "c.id IN ({$sanitarInIDs}) AND"; |
|
355 | + $where .= ($where ? " AND " : "")."c.id IN ({$sanitarInIDs}) AND"; |
|
356 | 356 | } |
357 | 357 | $where = sqlHelper::trimLogicalOp($where); |
358 | 358 | |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | $fields = $this->getCFGDef('selectFields', 'c.*'); |
376 | 376 | $group = $this->getGroupSQL($this->getCFGDef('groupBy', 'c.id')); |
377 | 377 | $sort = $this->SortOrderSQL("if(c.pub_date=0,c.createdon,c.pub_date)"); |
378 | - list($tbl_site_content, $sort) = $this->injectSortByTV($tbl_site_content . ' ' . $this->_filters['join'], $sort); |
|
378 | + list($tbl_site_content, $sort) = $this->injectSortByTV($tbl_site_content.' '.$this->_filters['join'], $sort); |
|
379 | 379 | |
380 | 380 | $limit = $this->LimitSQL($this->getCFGDef('queryLimit', 0)); |
381 | 381 | |
@@ -452,30 +452,30 @@ discard block |
||
452 | 452 | $tbl_site_content = $this->getTable('site_content', 'c'); |
453 | 453 | |
454 | 454 | $sort = $this->SortOrderSQL("if(c.pub_date=0,c.createdon,c.pub_date)"); |
455 | - list($from, $sort) = $this->injectSortByTV($tbl_site_content . ' ' . $this->_filters['join'], $sort); |
|
455 | + list($from, $sort) = $this->injectSortByTV($tbl_site_content.' '.$this->_filters['join'], $sort); |
|
456 | 456 | $sanitarInIDs = $this->sanitarIn($this->IDs); |
457 | 457 | |
458 | 458 | $tmpWhere = null; |
459 | 459 | if ($sanitarInIDs != "''") { |
460 | - switch($this->getCFGDef('showParent', '0')){ |
|
460 | + switch ($this->getCFGDef('showParent', '0')) { |
|
461 | 461 | case '-1': |
462 | - $tmpWhere = "c.parent IN (" . $sanitarInIDs . ")"; |
|
462 | + $tmpWhere = "c.parent IN (".$sanitarInIDs.")"; |
|
463 | 463 | break; |
464 | 464 | case 0: |
465 | - $tmpWhere = "c.parent IN (" . $sanitarInIDs . ") AND c.id NOT IN(" . $sanitarInIDs . ")"; |
|
465 | + $tmpWhere = "c.parent IN (".$sanitarInIDs.") AND c.id NOT IN(".$sanitarInIDs.")"; |
|
466 | 466 | break; |
467 | 467 | case 1: |
468 | 468 | default: |
469 | - $tmpWhere = "(c.parent IN (" . $sanitarInIDs . ") OR c.id IN({$sanitarInIDs}))"; |
|
469 | + $tmpWhere = "(c.parent IN (".$sanitarInIDs.") OR c.id IN({$sanitarInIDs}))"; |
|
470 | 470 | break; |
471 | 471 | } |
472 | 472 | } |
473 | 473 | if (($addDocs = $this->getCFGDef('documents', '')) != '') { |
474 | 474 | $addDocs = $this->sanitarIn($this->cleanIDs($addDocs)); |
475 | - if(empty($tmpWhere)){ |
|
475 | + if (empty($tmpWhere)) { |
|
476 | 476 | $tmpWhere = "c.id IN({$addDocs})"; |
477 | - }else{ |
|
478 | - $tmpWhere = "((" . $tmpWhere . ") OR c.id IN({$addDocs}))"; |
|
477 | + } else { |
|
478 | + $tmpWhere = "((".$tmpWhere.") OR c.id IN({$addDocs}))"; |
|
479 | 479 | } |
480 | 480 | } |
481 | 481 | if (!empty($tmpWhere)) { |
@@ -485,7 +485,7 @@ discard block |
||
485 | 485 | $where[] = "c.deleted=0 AND c.published=1"; |
486 | 486 | } |
487 | 487 | if (!empty($where)) { |
488 | - $where = "WHERE " . implode(" AND ", $where); |
|
488 | + $where = "WHERE ".implode(" AND ", $where); |
|
489 | 489 | } else { |
490 | 490 | $where = ''; |
491 | 491 | } |
@@ -493,9 +493,9 @@ discard block |
||
493 | 493 | $group = $this->getGroupSQL($this->getCFGDef('groupBy', 'c.id')); |
494 | 494 | |
495 | 495 | if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) { |
496 | - $sql = $this->dbQuery("SELECT {$fields} FROM " . $from . " " . $where . " " . |
|
497 | - $group . " ". |
|
498 | - $sort . " " . |
|
496 | + $sql = $this->dbQuery("SELECT {$fields} FROM ".$from." ".$where." ". |
|
497 | + $group." ". |
|
498 | + $sort." ". |
|
499 | 499 | $this->LimitSQL($this->getCFGDef('queryLimit', 0)) |
500 | 500 | ); |
501 | 501 | |
@@ -513,7 +513,7 @@ discard block |
||
513 | 513 | $type = trim($type); |
514 | 514 | switch (strtoupper($type)) { |
515 | 515 | case 'TVDATETIME': |
516 | - $field = "STR_TO_DATE(" . $field . ",'%d-%m-%Y %H:%i:%s')"; |
|
516 | + $field = "STR_TO_DATE(".$field.",'%d-%m-%Y %H:%i:%s')"; |
|
517 | 517 | break; |
518 | 518 | default: |
519 | 519 | $field = parent::changeSortType($field, $type); |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | $link = $this->checkExtender('request') ? $this->extender['request']->getLink() : $this->getRequest(); |
48 | 48 | if($id == $this->modx->config['site_start']){ |
49 | 49 | $url = $this->modx->config['site_url'].($link != '' ? "?{$link}" : ""); |
50 | - }else{ |
|
50 | + } else{ |
|
51 | 51 | $url = $this->modx->makeUrl($id, '', $link, $this->getCFGDef('urlScheme', '')); |
52 | 52 | } |
53 | 53 | return $url; |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | if($this->getCFGDef('makeUrl', 1)){ |
158 | 158 | if($item['type'] == 'reference'){ |
159 | 159 | $item['url'] = is_numeric($item['content']) ? $this->modx->makeUrl($item['content'], '', '', $this->getCFGDef('urlScheme', '')) : $item['content']; |
160 | - }else{ |
|
160 | + } else{ |
|
161 | 161 | $item['url'] = $this->modx->makeUrl($item['id'], '', '', $this->getCFGDef('urlScheme', '')); |
162 | 162 | } |
163 | 163 | } |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | if((bool)$this->getCFGDef('makeUrl', 1) && (array('1') == $fields || in_array(array('content', 'type'), $fields))){ |
242 | 242 | if($row['type'] == 'reference'){ |
243 | 243 | $row['url'] = is_numeric($row['content']) ? $this->modx->makeUrl($row['content'], '', '', $this->getCFGDef('urlScheme', '')) : $row['content']; |
244 | - }else{ |
|
244 | + } else{ |
|
245 | 245 | $row['url'] = $this->modx->makeUrl($row['id'], '', '', $this->getCFGDef('urlScheme', '')); |
246 | 246 | } |
247 | 247 | } |
@@ -474,7 +474,7 @@ discard block |
||
474 | 474 | $addDocs = $this->sanitarIn($this->cleanIDs($addDocs)); |
475 | 475 | if(empty($tmpWhere)){ |
476 | 476 | $tmpWhere = "c.id IN({$addDocs})"; |
477 | - }else{ |
|
477 | + } else{ |
|
478 | 478 | $tmpWhere = "((" . $tmpWhere . ") OR c.id IN({$addDocs}))"; |
479 | 479 | } |
480 | 480 | } |