@@ -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); |
@@ -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,10 +18,10 @@ 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 | - $str = mb_strtoupper(mb_substr($str, 0, 1, $encoding), $encoding).mb_substr($str, 1, mb_strlen($str), $encoding); |
|
| 24 | + $str = mb_strtoupper(mb_substr($str, 0, 1, $encoding), $encoding) . mb_substr($str, 1, mb_strlen($str), $encoding); |
|
| 25 | 25 | return $str; |
| 26 | 26 | } |
| 27 | 27 | |
@@ -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); |
@@ -217,8 +217,8 @@ discard block |
||
| 217 | 217 | '[' => '[', '%5B' => '[', ']' => ']', '%5D' => ']', |
| 218 | 218 | '{' => '{', '%7B' => '{', '}' => '}', '%7D' => '}', |
| 219 | 219 | '`' => '`', '%60' => '`' |
| 220 | - )){ |
|
| 221 | - switch(true){ |
|
| 220 | + )) { |
|
| 221 | + switch (true) { |
|
| 222 | 222 | case is_scalar($data): |
| 223 | 223 | $out = str_replace( |
| 224 | 224 | array_keys($chars), |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | break; |
| 229 | 229 | case is_array($data): |
| 230 | 230 | $out = $data; |
| 231 | - foreach($out as $key => &$val){ |
|
| 231 | + foreach ($out as $key => &$val) { |
|
| 232 | 232 | $val = self::sanitarTag($val, $charset, $chars); |
| 233 | 233 | } |
| 234 | 234 | break; |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | return $out; |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - public static function e($text, $charset = 'UTF-8'){ |
|
| 241 | + public static function e($text, $charset = 'UTF-8') { |
|
| 242 | 242 | return is_scalar($text) ? htmlspecialchars($text, ENT_COMPAT, $charset, false) : ''; |
| 243 | 243 | } |
| 244 | 244 | /** |
@@ -321,16 +321,16 @@ discard block |
||
| 321 | 321 | $out = $data; |
| 322 | 322 | } else { |
| 323 | 323 | $InsertPrefix = ($prefix != '') ? ($prefix . $addPS) : ''; |
| 324 | - $InsertSuffix = ($suffix != '') ? ($addPS. $suffix) : ''; |
|
| 324 | + $InsertSuffix = ($suffix != '') ? ($addPS . $suffix) : ''; |
|
| 325 | 325 | foreach ($data as $key => $item) { |
| 326 | 326 | $key = $InsertPrefix . $key; |
| 327 | 327 | $val = null; |
| 328 | - switch(true){ |
|
| 328 | + switch (true) { |
|
| 329 | 329 | case is_scalar($item): |
| 330 | 330 | $val = $item; |
| 331 | 331 | break; |
| 332 | 332 | case is_array($item): |
| 333 | - $val = self::renameKeyArr($item, $key.$sep, $InsertSuffix, '', $sep); |
|
| 333 | + $val = self::renameKeyArr($item, $key . $sep, $InsertSuffix, '', $sep); |
|
| 334 | 334 | $out = array_merge($out, $val); |
| 335 | 335 | $val = ''; |
| 336 | 336 | break; |
@@ -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); |
@@ -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); |
@@ -1,17 +1,17 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * summary |
|
| 4 | - * Truncates the HTML string to the specified length |
|
| 5 | - * |
|
| 6 | - * Copyright 2013 by Agel_Nash <[email protected]> |
|
| 7 | - * |
|
| 8 | - * @category extender |
|
| 9 | - * @license GNU General Public License (GPL), http://www.gnu.org/copyleft/gpl.html |
|
| 10 | - * @author Agel_Nash <[email protected]> |
|
| 11 | - * @see http://blog.agel-nash.ru/addon/summary.html |
|
| 12 | - * @date 31.07.2013 |
|
| 13 | - * @version 1.0.3 |
|
| 14 | - */ |
|
| 3 | + * summary |
|
| 4 | + * Truncates the HTML string to the specified length |
|
| 5 | + * |
|
| 6 | + * Copyright 2013 by Agel_Nash <[email protected]> |
|
| 7 | + * |
|
| 8 | + * @category extender |
|
| 9 | + * @license GNU General Public License (GPL), http://www.gnu.org/copyleft/gpl.html |
|
| 10 | + * @author Agel_Nash <[email protected]> |
|
| 11 | + * @see http://blog.agel-nash.ru/addon/summary.html |
|
| 12 | + * @date 31.07.2013 |
|
| 13 | + * @version 1.0.3 |
|
| 14 | + */ |
|
| 15 | 15 | include_once(MODX_BASE_PATH . 'assets/lib/APIHelpers.class.php'); |
| 16 | 16 | class SummaryText |
| 17 | 17 | { |
@@ -65,7 +65,7 @@ discard block |
||
| 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']); |
@@ -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'))) { |
@@ -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; |
@@ -1,16 +1,16 @@ discard block |
||
| 1 | 1 | <?php namespace Formatter; |
| 2 | 2 | /** |
| 3 | - * SQL Formatter is a collection of utilities for debugging SQL queries. |
|
| 4 | - * It includes methods for formatting, syntax highlighting, removing comments, etc. |
|
| 5 | - * |
|
| 6 | - * @package SqlFormatter |
|
| 7 | - * @author Jeremy Dorn <[email protected]> |
|
| 8 | - * @author Florin Patan <[email protected]> |
|
| 9 | - * @copyright 2013 Jeremy Dorn |
|
| 10 | - * @license http://opensource.org/licenses/MIT |
|
| 11 | - * @link http://github.com/jdorn/sql-formatter |
|
| 12 | - * @version 1.2.18 |
|
| 13 | - */ |
|
| 3 | + * SQL Formatter is a collection of utilities for debugging SQL queries. |
|
| 4 | + * It includes methods for formatting, syntax highlighting, removing comments, etc. |
|
| 5 | + * |
|
| 6 | + * @package SqlFormatter |
|
| 7 | + * @author Jeremy Dorn <[email protected]> |
|
| 8 | + * @author Florin Patan <[email protected]> |
|
| 9 | + * @copyright 2013 Jeremy Dorn |
|
| 10 | + * @license http://opensource.org/licenses/MIT |
|
| 11 | + * @link http://github.com/jdorn/sql-formatter |
|
| 12 | + * @version 1.2.18 |
|
| 13 | + */ |
|
| 14 | 14 | class SqlFormatter |
| 15 | 15 | {
|
| 16 | 16 | // Constants for token types |
@@ -866,9 +866,9 @@ discard block |
||
| 866 | 866 | $token = $token[self::TOKEN_VALUE]; |
| 867 | 867 | } else {
|
| 868 | 868 | if (defined('ENT_IGNORE')) {
|
| 869 | - $token = htmlentities($token[self::TOKEN_VALUE],ENT_COMPAT | ENT_IGNORE ,'UTF-8'); |
|
| 869 | + $token = htmlentities($token[self::TOKEN_VALUE],ENT_COMPAT | ENT_IGNORE ,'UTF-8'); |
|
| 870 | 870 | } else {
|
| 871 | - $token = htmlentities($token[self::TOKEN_VALUE],ENT_COMPAT,'UTF-8'); |
|
| 871 | + $token = htmlentities($token[self::TOKEN_VALUE],ENT_COMPAT,'UTF-8'); |
|
| 872 | 872 | } |
| 873 | 873 | } |
| 874 | 874 | |
@@ -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 | |
@@ -380,11 +380,11 @@ discard block |
||
| 380 | 380 | |
| 381 | 381 | return $tokens; |
| 382 | 382 | } |
| 383 | - $old_string_len = $current_length; |
|
| 383 | + $old_string_len = $current_length; |
|
| 384 | 384 | |
| 385 | 385 | // Determine if we can use caching |
| 386 | 386 | if ($current_length >= self::$max_cachekey_size) {
|
| 387 | - $cacheKey = substr($string,0,self::$max_cachekey_size); |
|
| 387 | + $cacheKey = substr($string, 0, self::$max_cachekey_size); |
|
| 388 | 388 | } else {
|
| 389 | 389 | $cacheKey = false; |
| 390 | 390 | } |
@@ -426,7 +426,7 @@ discard block |
||
| 426 | 426 | * |
| 427 | 427 | * @return String The SQL string with HTML styles and formatting wrapped in a <pre> tag |
| 428 | 428 | */ |
| 429 | - public static function format($string, $highlight=true) |
|
| 429 | + public static function format($string, $highlight = true) |
|
| 430 | 430 | {
|
| 431 | 431 | // This variable will be populated with formatted html |
| 432 | 432 | $return = ''; |
@@ -470,13 +470,13 @@ discard block |
||
| 470 | 470 | if ($increase_special_indent) {
|
| 471 | 471 | $indent_level++; |
| 472 | 472 | $increase_special_indent = false; |
| 473 | - array_unshift($indent_types,'special'); |
|
| 473 | + array_unshift($indent_types, 'special'); |
|
| 474 | 474 | } |
| 475 | 475 | // If we are increasing the block indent level now |
| 476 | 476 | if ($increase_block_indent) {
|
| 477 | 477 | $indent_level++; |
| 478 | 478 | $increase_block_indent = false; |
| 479 | - array_unshift($indent_types,'block'); |
|
| 479 | + array_unshift($indent_types, 'block'); |
|
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | // If we need a new line before the token |
@@ -491,9 +491,9 @@ discard block |
||
| 491 | 491 | // Display comments directly where they appear in the source |
| 492 | 492 | if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
|
| 493 | 493 | if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
|
| 494 | - $indent = str_repeat($tab,$indent_level); |
|
| 494 | + $indent = str_repeat($tab, $indent_level); |
|
| 495 | 495 | $return .= "\n" . $indent; |
| 496 | - $highlighted = str_replace("\n","\n".$indent,$highlighted);
|
|
| 496 | + $highlighted = str_replace("\n", "\n" . $indent, $highlighted);
|
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | $return .= $highlighted; |
@@ -504,11 +504,11 @@ discard block |
||
| 504 | 504 | if ($inline_parentheses) {
|
| 505 | 505 | // End of inline parentheses |
| 506 | 506 | if ($token[self::TOKEN_VALUE] === ')') {
|
| 507 | - $return = rtrim($return,' '); |
|
| 507 | + $return = rtrim($return, ' '); |
|
| 508 | 508 | |
| 509 | 509 | if ($inline_indented) {
|
| 510 | 510 | array_shift($indent_types); |
| 511 | - $indent_level --; |
|
| 511 | + $indent_level--; |
|
| 512 | 512 | $return .= "\n" . str_repeat($tab, $indent_level); |
| 513 | 513 | } |
| 514 | 514 | |
@@ -534,11 +534,11 @@ discard block |
||
| 534 | 534 | // Examples are "NOW()", "COUNT(*)", "int(10)", key(`somecolumn`), DECIMAL(7,2) |
| 535 | 535 | // Allow up to 3 non-whitespace tokens inside inline parentheses |
| 536 | 536 | $length = 0; |
| 537 | - for ($j=1;$j<=250;$j++) {
|
|
| 537 | + for ($j = 1; $j <= 250; $j++) {
|
|
| 538 | 538 | // Reached end of string |
| 539 | - if (!isset($tokens[$i+$j])) break; |
|
| 539 | + if (!isset($tokens[$i + $j])) break; |
|
| 540 | 540 | |
| 541 | - $next = $tokens[$i+$j]; |
|
| 541 | + $next = $tokens[$i + $j]; |
|
| 542 | 542 | |
| 543 | 543 | // Reached closing parentheses, able to inline it |
| 544 | 544 | if ($next[self::TOKEN_VALUE] === ')') {
|
@@ -549,12 +549,12 @@ discard block |
||
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | // Reached an invalid token for inline parentheses |
| 552 | - if ($next[self::TOKEN_VALUE]===';' || $next[self::TOKEN_VALUE]==='(') {
|
|
| 552 | + if ($next[self::TOKEN_VALUE] === ';' || $next[self::TOKEN_VALUE] === '(') {
|
|
| 553 | 553 | break; |
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | // Reached an invalid token type for inline parentheses |
| 557 | - 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) {
|
|
| 557 | + 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) {
|
|
| 558 | 558 | break; |
| 559 | 559 | } |
| 560 | 560 | |
@@ -568,8 +568,8 @@ discard block |
||
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | // Take out the preceding space unless there was whitespace there in the original query |
| 571 | - if (isset($original_tokens[$token['i']-1]) && $original_tokens[$token['i']-1][self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
|
|
| 572 | - $return = rtrim($return,' '); |
|
| 571 | + if (isset($original_tokens[$token['i'] - 1]) && $original_tokens[$token['i'] - 1][self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
|
|
| 572 | + $return = rtrim($return, ' '); |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | if (!$inline_parentheses) {
|
@@ -583,13 +583,13 @@ discard block |
||
| 583 | 583 | // Closing parentheses decrease the block indent level |
| 584 | 584 | elseif ($token[self::TOKEN_VALUE] === ')') {
|
| 585 | 585 | // Remove whitespace before the closing parentheses |
| 586 | - $return = rtrim($return,' '); |
|
| 586 | + $return = rtrim($return, ' '); |
|
| 587 | 587 | |
| 588 | 588 | $indent_level--; |
| 589 | 589 | |
| 590 | 590 | // Reset indent level |
| 591 | - while ($j=array_shift($indent_types)) {
|
|
| 592 | - if ($j==='special') {
|
|
| 591 | + while ($j = array_shift($indent_types)) {
|
|
| 592 | + if ($j === 'special') {
|
|
| 593 | 593 | $indent_level--; |
| 594 | 594 | } else {
|
| 595 | 595 | break; |
@@ -601,7 +601,7 @@ discard block |
||
| 601 | 601 | $indent_level = 0; |
| 602 | 602 | |
| 603 | 603 | if ($highlight) {
|
| 604 | - $return .= "\n".self::highlightError($token[self::TOKEN_VALUE]); |
|
| 604 | + $return .= "\n" . self::highlightError($token[self::TOKEN_VALUE]); |
|
| 605 | 605 | continue; |
| 606 | 606 | } |
| 607 | 607 | } |
@@ -618,7 +618,7 @@ discard block |
||
| 618 | 618 | |
| 619 | 619 | // If the last indent type was 'special', decrease the special indent for this round |
| 620 | 620 | reset($indent_types); |
| 621 | - if (current($indent_types)==='special') {
|
|
| 621 | + if (current($indent_types) === 'special') {
|
|
| 622 | 622 | $indent_level--; |
| 623 | 623 | array_shift($indent_types); |
| 624 | 624 | } |
@@ -631,12 +631,12 @@ discard block |
||
| 631 | 631 | } |
| 632 | 632 | // If we already added a newline, redo the indentation since it may be different now |
| 633 | 633 | else {
|
| 634 | - $return = rtrim($return,$tab).str_repeat($tab, $indent_level); |
|
| 634 | + $return = rtrim($return, $tab) . str_repeat($tab, $indent_level); |
|
| 635 | 635 | } |
| 636 | 636 | |
| 637 | 637 | // If the token may have extra whitespace |
| 638 | - if (strpos($token[self::TOKEN_VALUE],' ')!==false || strpos($token[self::TOKEN_VALUE],"\n")!==false || strpos($token[self::TOKEN_VALUE],"\t")!==false) {
|
|
| 639 | - $highlighted = preg_replace('/\s+/',' ',$highlighted);
|
|
| 638 | + if (strpos($token[self::TOKEN_VALUE], ' ') !== false || strpos($token[self::TOKEN_VALUE], "\n") !== false || strpos($token[self::TOKEN_VALUE], "\t") !== false) {
|
|
| 639 | + $highlighted = preg_replace('/\s+/', ' ', $highlighted);
|
|
| 640 | 640 | } |
| 641 | 641 | //if SQL 'LIMIT' clause, start variable to reset newline |
| 642 | 642 | if ($token[self::TOKEN_VALUE] === 'LIMIT' && !$inline_parentheses) {
|
@@ -670,16 +670,16 @@ discard block |
||
| 670 | 670 | } |
| 671 | 671 | |
| 672 | 672 | // If the token may have extra whitespace |
| 673 | - if (strpos($token[self::TOKEN_VALUE],' ')!==false || strpos($token[self::TOKEN_VALUE],"\n")!==false || strpos($token[self::TOKEN_VALUE],"\t")!==false) {
|
|
| 674 | - $highlighted = preg_replace('/\s+/',' ',$highlighted);
|
|
| 673 | + if (strpos($token[self::TOKEN_VALUE], ' ') !== false || strpos($token[self::TOKEN_VALUE], "\n") !== false || strpos($token[self::TOKEN_VALUE], "\t") !== false) {
|
|
| 674 | + $highlighted = preg_replace('/\s+/', ' ', $highlighted);
|
|
| 675 | 675 | } |
| 676 | 676 | } |
| 677 | 677 | |
| 678 | 678 | // Multiple boundary characters in a row should not have spaces between them (not including parentheses) |
| 679 | 679 | elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BOUNDARY) {
|
| 680 | - if (isset($tokens[$i-1]) && $tokens[$i-1][self::TOKEN_TYPE] === self::TOKEN_TYPE_BOUNDARY) {
|
|
| 681 | - if (isset($original_tokens[$token['i']-1]) && $original_tokens[$token['i']-1][self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
|
|
| 682 | - $return = rtrim($return,' '); |
|
| 680 | + if (isset($tokens[$i - 1]) && $tokens[$i - 1][self::TOKEN_TYPE] === self::TOKEN_TYPE_BOUNDARY) {
|
|
| 681 | + if (isset($original_tokens[$token['i'] - 1]) && $original_tokens[$token['i'] - 1][self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
|
|
| 682 | + $return = rtrim($return, ' '); |
|
| 683 | 683 | } |
| 684 | 684 | } |
| 685 | 685 | } |
@@ -689,29 +689,29 @@ discard block |
||
| 689 | 689 | $return = rtrim($return, ' '); |
| 690 | 690 | } |
| 691 | 691 | |
| 692 | - $return .= $highlighted.' '; |
|
| 692 | + $return .= $highlighted . ' '; |
|
| 693 | 693 | |
| 694 | 694 | // If the token shouldn't have a space after it |
| 695 | 695 | if ($token[self::TOKEN_VALUE] === '(' || $token[self::TOKEN_VALUE] === '.') {
|
| 696 | - $return = rtrim($return,' '); |
|
| 696 | + $return = rtrim($return, ' '); |
|
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | // If this is the "-" of a negative number, it shouldn't have a space after it |
| 700 | - if($token[self::TOKEN_VALUE] === '-' && isset($tokens[$i+1]) && $tokens[$i+1][self::TOKEN_TYPE] === self::TOKEN_TYPE_NUMBER && isset($tokens[$i-1])) {
|
|
| 701 | - $prev = $tokens[$i-1][self::TOKEN_TYPE]; |
|
| 702 | - if($prev !== self::TOKEN_TYPE_QUOTE && $prev !== self::TOKEN_TYPE_BACKTICK_QUOTE && $prev !== self::TOKEN_TYPE_WORD && $prev !== self::TOKEN_TYPE_NUMBER) {
|
|
| 703 | - $return = rtrim($return,' '); |
|
| 700 | + if ($token[self::TOKEN_VALUE] === '-' && isset($tokens[$i + 1]) && $tokens[$i + 1][self::TOKEN_TYPE] === self::TOKEN_TYPE_NUMBER && isset($tokens[$i - 1])) {
|
|
| 701 | + $prev = $tokens[$i - 1][self::TOKEN_TYPE]; |
|
| 702 | + if ($prev !== self::TOKEN_TYPE_QUOTE && $prev !== self::TOKEN_TYPE_BACKTICK_QUOTE && $prev !== self::TOKEN_TYPE_WORD && $prev !== self::TOKEN_TYPE_NUMBER) {
|
|
| 703 | + $return = rtrim($return, ' '); |
|
| 704 | 704 | } |
| 705 | 705 | } |
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | // If there are unmatched parentheses |
| 709 | - if ($highlight && array_search('block',$indent_types) !== false) {
|
|
| 710 | - $return .= "\n".self::highlightError("WARNING: unclosed parentheses or section");
|
|
| 709 | + if ($highlight && array_search('block', $indent_types) !== false) {
|
|
| 710 | + $return .= "\n" . self::highlightError("WARNING: unclosed parentheses or section");
|
|
| 711 | 711 | } |
| 712 | 712 | |
| 713 | 713 | // Replace tab characters with the configuration tab character |
| 714 | - $return = trim(str_replace("\t",self::$tab,$return));
|
|
| 714 | + $return = trim(str_replace("\t", self::$tab, $return));
|
|
| 715 | 715 | |
| 716 | 716 | if ($highlight) {
|
| 717 | 717 | $return = self::output($return); |
@@ -760,7 +760,7 @@ discard block |
||
| 760 | 760 | // If this is a query separator |
| 761 | 761 | if ($token[self::TOKEN_VALUE] === ';') {
|
| 762 | 762 | if (!$empty) {
|
| 763 | - $queries[] = $current_query.';'; |
|
| 763 | + $queries[] = $current_query . ';'; |
|
| 764 | 764 | } |
| 765 | 765 | $current_query = ''; |
| 766 | 766 | $empty = true; |
@@ -803,7 +803,7 @@ discard block |
||
| 803 | 803 | |
| 804 | 804 | $result .= $token[self::TOKEN_VALUE]; |
| 805 | 805 | } |
| 806 | - $result = self::format( $result,false); |
|
| 806 | + $result = self::format($result, false); |
|
| 807 | 807 | |
| 808 | 808 | return $result; |
| 809 | 809 | } |
@@ -829,7 +829,7 @@ discard block |
||
| 829 | 829 | } |
| 830 | 830 | // Remove extra whitespace in reserved words (e.g "OUTER JOIN" becomes "OUTER JOIN") |
| 831 | 831 | 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) {
|
| 832 | - $token[self::TOKEN_VALUE] = preg_replace('/\s+/',' ',$token[self::TOKEN_VALUE]);
|
|
| 832 | + $token[self::TOKEN_VALUE] = preg_replace('/\s+/', ' ', $token[self::TOKEN_VALUE]);
|
|
| 833 | 833 | } |
| 834 | 834 | |
| 835 | 835 | if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_WHITESPACE) {
|
@@ -866,31 +866,31 @@ discard block |
||
| 866 | 866 | $token = $token[self::TOKEN_VALUE]; |
| 867 | 867 | } else {
|
| 868 | 868 | if (defined('ENT_IGNORE')) {
|
| 869 | - $token = htmlentities($token[self::TOKEN_VALUE],ENT_COMPAT | ENT_IGNORE ,'UTF-8'); |
|
| 869 | + $token = htmlentities($token[self::TOKEN_VALUE], ENT_COMPAT | ENT_IGNORE, 'UTF-8'); |
|
| 870 | 870 | } else {
|
| 871 | - $token = htmlentities($token[self::TOKEN_VALUE],ENT_COMPAT,'UTF-8'); |
|
| 871 | + $token = htmlentities($token[self::TOKEN_VALUE], ENT_COMPAT, 'UTF-8'); |
|
| 872 | 872 | } |
| 873 | 873 | } |
| 874 | 874 | |
| 875 | - if ($type===self::TOKEN_TYPE_BOUNDARY) {
|
|
| 875 | + if ($type === self::TOKEN_TYPE_BOUNDARY) {
|
|
| 876 | 876 | return self::highlightBoundary($token); |
| 877 | - } elseif ($type===self::TOKEN_TYPE_WORD) {
|
|
| 877 | + } elseif ($type === self::TOKEN_TYPE_WORD) {
|
|
| 878 | 878 | return self::highlightWord($token); |
| 879 | - } elseif ($type===self::TOKEN_TYPE_BACKTICK_QUOTE) {
|
|
| 879 | + } elseif ($type === self::TOKEN_TYPE_BACKTICK_QUOTE) {
|
|
| 880 | 880 | return self::highlightBacktickQuote($token); |
| 881 | - } elseif ($type===self::TOKEN_TYPE_QUOTE) {
|
|
| 881 | + } elseif ($type === self::TOKEN_TYPE_QUOTE) {
|
|
| 882 | 882 | return self::highlightQuote($token); |
| 883 | - } elseif ($type===self::TOKEN_TYPE_RESERVED) {
|
|
| 883 | + } elseif ($type === self::TOKEN_TYPE_RESERVED) {
|
|
| 884 | 884 | return self::highlightReservedWord($token); |
| 885 | - } elseif ($type===self::TOKEN_TYPE_RESERVED_TOPLEVEL) {
|
|
| 885 | + } elseif ($type === self::TOKEN_TYPE_RESERVED_TOPLEVEL) {
|
|
| 886 | 886 | return self::highlightReservedWord($token); |
| 887 | - } elseif ($type===self::TOKEN_TYPE_RESERVED_NEWLINE) {
|
|
| 887 | + } elseif ($type === self::TOKEN_TYPE_RESERVED_NEWLINE) {
|
|
| 888 | 888 | return self::highlightReservedWord($token); |
| 889 | - } elseif ($type===self::TOKEN_TYPE_NUMBER) {
|
|
| 889 | + } elseif ($type === self::TOKEN_TYPE_NUMBER) {
|
|
| 890 | 890 | return self::highlightNumber($token); |
| 891 | - } elseif ($type===self::TOKEN_TYPE_VARIABLE) {
|
|
| 891 | + } elseif ($type === self::TOKEN_TYPE_VARIABLE) {
|
|
| 892 | 892 | return self::highlightVariable($token); |
| 893 | - } elseif ($type===self::TOKEN_TYPE_COMMENT || $type===self::TOKEN_TYPE_BLOCK_COMMENT) {
|
|
| 893 | + } elseif ($type === self::TOKEN_TYPE_COMMENT || $type === self::TOKEN_TYPE_BLOCK_COMMENT) {
|
|
| 894 | 894 | return self::highlightComment($token); |
| 895 | 895 | } |
| 896 | 896 | |
@@ -954,7 +954,7 @@ discard block |
||
| 954 | 954 | */ |
| 955 | 955 | protected static function highlightBoundary($value) |
| 956 | 956 | {
|
| 957 | - if ($value==='(' || $value===')') return $value;
|
|
| 957 | + if ($value === '(' || $value === ')') return $value;
|
|
| 958 | 958 | |
| 959 | 959 | if (self::is_cli()) {
|
| 960 | 960 | return self::$cli_boundary . $value . "\x1b[0m"; |
@@ -1052,7 +1052,7 @@ discard block |
||
| 1052 | 1052 | */ |
| 1053 | 1053 | private static function quote_regex($a) |
| 1054 | 1054 | {
|
| 1055 | - return preg_quote($a,'/'); |
|
| 1055 | + return preg_quote($a, '/'); |
|
| 1056 | 1056 | } |
| 1057 | 1057 | |
| 1058 | 1058 | /** |
@@ -1065,14 +1065,14 @@ discard block |
||
| 1065 | 1065 | private static function output($string) |
| 1066 | 1066 | {
|
| 1067 | 1067 | if (self::is_cli()) {
|
| 1068 | - return $string."\n"; |
|
| 1068 | + return $string . "\n"; |
|
| 1069 | 1069 | } else {
|
| 1070 | - $string=trim($string); |
|
| 1070 | + $string = trim($string); |
|
| 1071 | 1071 | if (!self::$use_pre) {
|
| 1072 | 1072 | return $string; |
| 1073 | 1073 | } |
| 1074 | 1074 | |
| 1075 | - return '<pre '.self::$pre_attributes.'>' . $string . '</pre>'; |
|
| 1075 | + return '<pre ' . self::$pre_attributes . '>' . $string . '</pre>'; |
|
| 1076 | 1076 | } |
| 1077 | 1077 | } |
| 1078 | 1078 | |
@@ -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 |
@@ -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; |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | * Чтобы не дергать постоянно файл который обрабатываем |
| 50 | 50 | * |
| 51 | 51 | * @access private |
| 52 | - * @param string $name ключ |
|
| 52 | + * @param string $mode |
|
| 53 | 53 | * @return string информация из pathinfo о обрабатываемом файле input |
| 54 | 54 | */ |
| 55 | 55 | private function _pathinfo($file, $mode){
|
@@ -65,14 +65,23 @@ discard block |
||
| 65 | 65 | return $out; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | + /** |
|
| 69 | + * @param string $file |
|
| 70 | + */ |
|
| 68 | 71 | public function takeFileDir($file){
|
| 69 | 72 | return $this->_pathinfo($file, 'dirname'); |
| 70 | 73 | } |
| 71 | 74 | |
| 75 | + /** |
|
| 76 | + * @param string $file |
|
| 77 | + */ |
|
| 72 | 78 | public function takeFileBasename($file){ //file name with extension
|
| 73 | 79 | return $this->_pathinfo($file, 'basename'); |
| 74 | 80 | } |
| 75 | 81 | |
| 82 | + /** |
|
| 83 | + * @param string $file |
|
| 84 | + */ |
|
| 76 | 85 | public function takeFileName($file){
|
| 77 | 86 | return $this->_pathinfo($file, 'filename'); |
| 78 | 87 | } |
@@ -151,6 +160,9 @@ discard block |
||
| 151 | 160 | return $out; |
| 152 | 161 | } |
| 153 | 162 | |
| 163 | + /** |
|
| 164 | + * @param string $path |
|
| 165 | + */ |
|
| 154 | 166 | public function makeDir($path, $perm = 0755){
|
| 155 | 167 | if (!$this->checkDir($path)){
|
| 156 | 168 | $path = MODX_BASE_PATH . $this->relativePath($path); |
@@ -227,13 +239,16 @@ discard block |
||
| 227 | 239 | * '0755' => 493 |
| 228 | 240 | * '755' => 493 |
| 229 | 241 | * |
| 230 | - * @param mixed $chmod строка или число в восьмеричной/десятичной системе счисления |
|
| 242 | + * @param integer $chmod строка или число в восьмеричной/десятичной системе счисления |
|
| 231 | 243 | * @return int число в восьмеричной системе счисления |
| 232 | 244 | */ |
| 233 | 245 | public function toOct($chmod){
|
| 234 | 246 | return is_string($chmod) ? octdec($chmod) : $chmod; |
| 235 | 247 | } |
| 236 | 248 | |
| 249 | + /** |
|
| 250 | + * @param string $dirPath |
|
| 251 | + */ |
|
| 237 | 252 | public function rmDir($dirPath) {
|
| 238 | 253 | $flag = false; |
| 239 | 254 | $path = $_path = MODX_BASE_PATH . $this->relativePath($dirPath); |
@@ -248,6 +263,9 @@ discard block |
||
| 248 | 263 | return $flag; |
| 249 | 264 | } |
| 250 | 265 | |
| 266 | + /** |
|
| 267 | + * @param string $file |
|
| 268 | + */ |
|
| 251 | 269 | public function unlink($file){
|
| 252 | 270 | $flag = false; |
| 253 | 271 | if($this->checkFile($file)){
|
@@ -221,9 +221,9 @@ discard block |
||
| 221 | 221 | /** |
| 222 | 222 | * Перевод строки/числа из восьмеричной/десятичной системы счисления в 8-ричную систему счисления |
| 223 | 223 | * Если параметр является числом, то он остается без изменений. Обработка применяется только к строкам. |
| 224 | - * |
|
| 225 | - * 755 => 755 |
|
| 226 | - * 0755 => 493 |
|
| 224 | + * |
|
| 225 | + * 755 => 755 |
|
| 226 | + * 0755 => 493 |
|
| 227 | 227 | * '0755' => 493 |
| 228 | 228 | * '755' => 493 |
| 229 | 229 | * |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | public function rmDir($dirPath) {
|
| 238 | - $flag = false; |
|
| 238 | + $flag = false; |
|
| 239 | 239 | $path = $_path = MODX_BASE_PATH . $this->relativePath($dirPath); |
| 240 | 240 | if ($this->checkDir($path)) {
|
| 241 | 241 | $dirIterator = new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS); |
@@ -245,31 +245,31 @@ discard block |
||
| 245 | 245 | } |
| 246 | 246 | $flag = rmdir($_path); |
| 247 | 247 | } |
| 248 | - return $flag; |
|
| 248 | + return $flag; |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | - public function unlink($file){
|
|
| 252 | - $flag = false; |
|
| 251 | + public function unlink($file){
|
|
| 252 | + $flag = false; |
|
| 253 | 253 | if($this->checkFile($file)){
|
| 254 | - $flag = unlink(MODX_BASE_PATH . $this->relativePath($file)); |
|
| 254 | + $flag = unlink(MODX_BASE_PATH . $this->relativePath($file)); |
|
| 255 | 255 | } |
| 256 | - return $flag; |
|
| 256 | + return $flag; |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - public function delete($path){
|
|
| 260 | - $path = MODX_BASE_PATH . $this->relativePath($path); |
|
| 261 | - switch(true){
|
|
| 262 | - case $this->checkDir($path): |
|
| 263 | - $flag = $this->rmDir($path); |
|
| 264 | - break; |
|
| 265 | - case $this->checkFile($path): |
|
| 266 | - $flag = $this->unlink($path); |
|
| 267 | - break; |
|
| 268 | - default: |
|
| 269 | - $flag = false; |
|
| 270 | - } |
|
| 271 | - return $flag; |
|
| 272 | - } |
|
| 259 | + public function delete($path){
|
|
| 260 | + $path = MODX_BASE_PATH . $this->relativePath($path); |
|
| 261 | + switch(true){
|
|
| 262 | + case $this->checkDir($path): |
|
| 263 | + $flag = $this->rmDir($path); |
|
| 264 | + break; |
|
| 265 | + case $this->checkFile($path): |
|
| 266 | + $flag = $this->unlink($path); |
|
| 267 | + break; |
|
| 268 | + default: |
|
| 269 | + $flag = false; |
|
| 270 | + } |
|
| 271 | + return $flag; |
|
| 272 | + } |
|
| 273 | 273 | public function getInexistantFilename($file, $full = false) {
|
| 274 | 274 | $i = 1; |
| 275 | 275 | $file = $mainFile = MODX_BASE_PATH.$this->relativePath($file); |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php namespace Helpers; |
| 2 | 2 | |
| 3 | -class FS{
|
|
| 3 | +class FS {
|
|
| 4 | 4 | /** |
| 5 | 5 | * @var FS cached reference to singleton instance |
| 6 | 6 | */ |
@@ -52,52 +52,52 @@ discard block |
||
| 52 | 52 | * @param string $name ключ |
| 53 | 53 | * @return string информация из pathinfo о обрабатываемом файле input |
| 54 | 54 | */ |
| 55 | - private function _pathinfo($file, $mode){
|
|
| 56 | - if(!is_scalar($file) && !is_scalar($mode)){
|
|
| 55 | + private function _pathinfo($file, $mode) {
|
|
| 56 | + if (!is_scalar($file) && !is_scalar($mode)) {
|
|
| 57 | 57 | $file = $mode = ''; |
| 58 | 58 | } |
| 59 | 59 | $flag = !(empty($file) || empty($mode)); |
| 60 | 60 | $f = MODX_BASE_PATH . $this->relativePath($file); |
| 61 | - if($flag && !isset($this->_fileInfo[$f], $this->_fileInfo[$f][$mode])){
|
|
| 61 | + if ($flag && !isset($this->_fileInfo[$f], $this->_fileInfo[$f][$mode])) {
|
|
| 62 | 62 | $this->_fileInfo[$f] = pathinfo($f); |
| 63 | 63 | } |
| 64 | 64 | $out = $flag && isset($this->_fileInfo[$f][$mode]) ? $this->_fileInfo[$f][$mode] : ''; |
| 65 | 65 | return $out; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - public function takeFileDir($file){
|
|
| 68 | + public function takeFileDir($file) {
|
|
| 69 | 69 | return $this->_pathinfo($file, 'dirname'); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - public function takeFileBasename($file){ //file name with extension
|
|
| 72 | + public function takeFileBasename($file) { //file name with extension
|
|
| 73 | 73 | return $this->_pathinfo($file, 'basename'); |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - public function takeFileName($file){
|
|
| 76 | + public function takeFileName($file) {
|
|
| 77 | 77 | return $this->_pathinfo($file, 'filename'); |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - public function takeFileExt($file){
|
|
| 80 | + public function takeFileExt($file) {
|
|
| 81 | 81 | return strtolower($this->_pathinfo($file, 'extension')); |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - public function checkFile($file){
|
|
| 84 | + public function checkFile($file) {
|
|
| 85 | 85 | $f = is_scalar($file) ? MODX_BASE_PATH . $this->relativePath($file) : ''; |
| 86 | 86 | return (!empty($f) && is_file($f) && is_readable($f)); |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - public function checkDir($path){
|
|
| 89 | + public function checkDir($path) {
|
|
| 90 | 90 | $f = is_scalar($path) ? $this->relativePath($path) : ''; |
| 91 | 91 | return (!empty($f) && is_dir(MODX_BASE_PATH . $f) && is_readable(MODX_BASE_PATH . $f)); |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - public function fileSize($file, $format = false){
|
|
| 94 | + public function fileSize($file, $format = false) {
|
|
| 95 | 95 | $out = 0; |
| 96 | - if($this->checkFile($file)){
|
|
| 96 | + if ($this->checkFile($file)) {
|
|
| 97 | 97 | $out = filesize(MODX_BASE_PATH . $this->relativePath($file)); |
| 98 | 98 | } |
| 99 | - if($format){
|
|
| 100 | - $types = array( 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); |
|
| 99 | + if ($format) {
|
|
| 100 | + $types = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
|
|
| 101 | 101 | $size = $out > 0 ? floor(log($out, 1024)) : 0; |
| 102 | 102 | $out = number_format($out / pow(1024, $size), 2, '.', ',') . ' ' . $types[$size]; |
| 103 | 103 | } |
@@ -114,12 +114,12 @@ discard block |
||
| 114 | 114 | * @param $fname Имя файла |
| 115 | 115 | * @return string MIME тип файла |
| 116 | 116 | */ |
| 117 | - public function takeFileMIME($file){
|
|
| 117 | + public function takeFileMIME($file) {
|
|
| 118 | 118 | $out = null; |
| 119 | 119 | $path = $this->relativePath($file); |
| 120 | - if($this->checkFile($path)){
|
|
| 121 | - $fname = MODX_BASE_PATH.$path; |
|
| 122 | - switch(true){
|
|
| 120 | + if ($this->checkFile($path)) {
|
|
| 121 | + $fname = MODX_BASE_PATH . $path; |
|
| 122 | + switch (true) {
|
|
| 123 | 123 | /** need fileinfo extension */ |
| 124 | 124 | case (extension_loaded('fileinfo') && class_exists('\finfo')):
|
| 125 | 125 | $fi = new \finfo(FILEINFO_MIME_TYPE); |
@@ -134,15 +134,15 @@ discard block |
||
| 134 | 134 | /** |
| 135 | 135 | * @see: http://www.php.net/manual/ru/function.finfo-open.php#112617 |
| 136 | 136 | */ |
| 137 | - $fh=fopen($fname,'rb'); |
|
| 137 | + $fh = fopen($fname, 'rb'); |
|
| 138 | 138 | if ($fh) {
|
| 139 | - $bytes6=fread($fh,6); |
|
| 139 | + $bytes6 = fread($fh, 6); |
|
| 140 | 140 | fclose($fh); |
| 141 | - switch(true){
|
|
| 142 | - case ($bytes6===false): break; |
|
| 143 | - case (substr($bytes6,0,3)=="\xff\xd8\xff"): $out = 'image/jpeg'; break; |
|
| 144 | - case ($bytes6=="\x89PNG\x0d\x0a"): $out = 'image/png'; break; |
|
| 145 | - case ($bytes6=="GIF87a" || $bytes6=="GIF89a"): $out = 'image/gif'; break; |
|
| 141 | + switch (true) {
|
|
| 142 | + case ($bytes6 === false): break; |
|
| 143 | + case (substr($bytes6, 0, 3) == "\xff\xd8\xff"): $out = 'image/jpeg'; break; |
|
| 144 | + case ($bytes6 == "\x89PNG\x0d\x0a"): $out = 'image/png'; break; |
|
| 145 | + case ($bytes6 == "GIF87a" || $bytes6 == "GIF89a"): $out = 'image/gif'; break; |
|
| 146 | 146 | default: $out = 'application/octet-stream'; break; |
| 147 | 147 | } |
| 148 | 148 | } |
@@ -151,11 +151,11 @@ discard block |
||
| 151 | 151 | return $out; |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - public function makeDir($path, $perm = 0755){
|
|
| 155 | - if (!$this->checkDir($path)){
|
|
| 154 | + public function makeDir($path, $perm = 0755) {
|
|
| 155 | + if (!$this->checkDir($path)) {
|
|
| 156 | 156 | $path = MODX_BASE_PATH . $this->relativePath($path); |
| 157 | 157 | $flag = mkdir($path, $this->toOct($perm), true); |
| 158 | - }else{
|
|
| 158 | + } else {
|
|
| 159 | 159 | $flag = true; |
| 160 | 160 | } |
| 161 | 161 | return $flag; |
@@ -168,12 +168,12 @@ discard block |
||
| 168 | 168 | * @param $to получатель |
| 169 | 169 | * @return bool статус копирования |
| 170 | 170 | */ |
| 171 | - public function copyFile($from, $to, $chmod = 0644){
|
|
| 171 | + public function copyFile($from, $to, $chmod = 0644) {
|
|
| 172 | 172 | $flag = false; |
| 173 | 173 | $from = MODX_BASE_PATH . $this->relativePath($from); |
| 174 | 174 | $to = MODX_BASE_PATH . $this->relativePath($to); |
| 175 | 175 | $dir = $this->takeFileDir($to); |
| 176 | - if($this->checkFile($from) && $this->makeDir($dir) && copy($from, $to)){
|
|
| 176 | + if ($this->checkFile($from) && $this->makeDir($dir) && copy($from, $to)) {
|
|
| 177 | 177 | chmod($to, $this->toOct($chmod)); |
| 178 | 178 | $flag = true; |
| 179 | 179 | } |
@@ -187,12 +187,12 @@ discard block |
||
| 187 | 187 | * @param string $to получатель |
| 188 | 188 | * @return bool статус перемещения |
| 189 | 189 | */ |
| 190 | - public function moveFile($from, $to, $chmod = 0644){
|
|
| 190 | + public function moveFile($from, $to, $chmod = 0644) {
|
|
| 191 | 191 | $flag = false; |
| 192 | 192 | $from = MODX_BASE_PATH . $this->relativePath($from); |
| 193 | 193 | $to = MODX_BASE_PATH . $this->relativePath($to); |
| 194 | 194 | $dir = $this->takeFileDir($to); |
| 195 | - if($this->checkFile($from) && $this->makeDir($dir) && rename($from, $to)){
|
|
| 195 | + if ($this->checkFile($from) && $this->makeDir($dir) && rename($from, $to)) {
|
|
| 196 | 196 | chmod($to, $this->toOct($chmod)); |
| 197 | 197 | $flag = true; |
| 198 | 198 | } |
@@ -206,13 +206,13 @@ discard block |
||
| 206 | 206 | * @param string $owner начальный путь который стоит вырезать |
| 207 | 207 | * @return string относительный путь |
| 208 | 208 | */ |
| 209 | - public function relativePath($path, $owner = null){
|
|
| 210 | - if(is_null($owner)){
|
|
| 209 | + public function relativePath($path, $owner = null) {
|
|
| 210 | + if (is_null($owner)) {
|
|
| 211 | 211 | $owner = MODX_BASE_PATH; |
| 212 | 212 | } |
| 213 | - if(!(empty($path) || !is_scalar($path)) && !preg_match("/^http(s)?:\/\/\w+/",$path)){
|
|
| 214 | - $path = trim(preg_replace("#^".$owner."#", '', $path), '/');
|
|
| 215 | - }else{
|
|
| 213 | + if (!(empty($path) || !is_scalar($path)) && !preg_match("/^http(s)?:\/\/\w+/", $path)) {
|
|
| 214 | + $path = trim(preg_replace("#^" . $owner . "#", '', $path), '/');
|
|
| 215 | + } else {
|
|
| 216 | 216 | $path = ''; |
| 217 | 217 | } |
| 218 | 218 | return $path; |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | * @param mixed $chmod строка или число в восьмеричной/десятичной системе счисления |
| 231 | 231 | * @return int число в восьмеричной системе счисления |
| 232 | 232 | */ |
| 233 | - public function toOct($chmod){
|
|
| 233 | + public function toOct($chmod) {
|
|
| 234 | 234 | return is_string($chmod) ? octdec($chmod) : $chmod; |
| 235 | 235 | } |
| 236 | 236 | |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | if ($this->checkDir($path)) {
|
| 241 | 241 | $dirIterator = new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS); |
| 242 | 242 | $dirRecursiveIterator = new \RecursiveIteratorIterator($dirIterator, \RecursiveIteratorIterator::CHILD_FIRST); |
| 243 | - foreach($dirRecursiveIterator as $path) {
|
|
| 243 | + foreach ($dirRecursiveIterator as $path) {
|
|
| 244 | 244 | $path->isDir() ? rmdir($path->getPathname()) : unlink($path->getPathname()); |
| 245 | 245 | } |
| 246 | 246 | $flag = rmdir($_path); |
@@ -248,17 +248,17 @@ discard block |
||
| 248 | 248 | return $flag; |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | - public function unlink($file){
|
|
| 251 | + public function unlink($file) {
|
|
| 252 | 252 | $flag = false; |
| 253 | - if($this->checkFile($file)){
|
|
| 253 | + if ($this->checkFile($file)) {
|
|
| 254 | 254 | $flag = unlink(MODX_BASE_PATH . $this->relativePath($file)); |
| 255 | 255 | } |
| 256 | 256 | return $flag; |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - public function delete($path){
|
|
| 259 | + public function delete($path) {
|
|
| 260 | 260 | $path = MODX_BASE_PATH . $this->relativePath($path); |
| 261 | - switch(true){
|
|
| 261 | + switch (true) {
|
|
| 262 | 262 | case $this->checkDir($path): |
| 263 | 263 | $flag = $this->rmDir($path); |
| 264 | 264 | break; |
@@ -272,11 +272,11 @@ discard block |
||
| 272 | 272 | } |
| 273 | 273 | public function getInexistantFilename($file, $full = false) {
|
| 274 | 274 | $i = 1; |
| 275 | - $file = $mainFile = MODX_BASE_PATH.$this->relativePath($file); |
|
| 275 | + $file = $mainFile = MODX_BASE_PATH . $this->relativePath($file); |
|
| 276 | 276 | while ($this->checkFile($file)) {
|
| 277 | 277 | $i++; |
| 278 | - $out = $this->takeFileDir($file).'/'; |
|
| 279 | - $out .= $this->takeFileName($mainFile)."({$i}).".$this->takeFileExt($file);
|
|
| 278 | + $out = $this->takeFileDir($file) . '/'; |
|
| 279 | + $out .= $this->takeFileName($mainFile) . "({$i})." . $this->takeFileExt($file);
|
|
| 280 | 280 | $file = $out; |
| 281 | 281 | } |
| 282 | 282 | return $full ? $file : $this->takeFileBasename($file); |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | if (!$this->checkDir($path)){
|
| 156 | 156 | $path = MODX_BASE_PATH . $this->relativePath($path); |
| 157 | 157 | $flag = mkdir($path, $this->toOct($perm), true); |
| 158 | - }else{
|
|
| 158 | + } else{
|
|
| 159 | 159 | $flag = true; |
| 160 | 160 | } |
| 161 | 161 | return $flag; |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | } |
| 213 | 213 | if(!(empty($path) || !is_scalar($path)) && !preg_match("/^http(s)?:\/\/\w+/",$path)){
|
| 214 | 214 | $path = trim(preg_replace("#^".$owner."#", '', $path), '/');
|
| 215 | - }else{
|
|
| 215 | + } else{
|
|
| 216 | 216 | $path = ''; |
| 217 | 217 | } |
| 218 | 218 | return $path; |
@@ -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 | -include_once(MODX_BASE_PATH.'assets/snippets/phpthumb/phpthumb.class.php'); |
|
| 3 | +include_once(MODX_BASE_PATH . 'assets/snippets/phpthumb/phpthumb.class.php'); |
|
| 4 | 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,9 +17,9 @@ 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))); |
|
| 22 | - $options = 'f='.$ext.'&'.$options; |
|
| 20 | + $ext = explode('.', $inputFile); |
|
| 21 | + $ext = str_replace('jpeg', 'jpg', strtolower(array_pop($ext))); |
|
| 22 | + $options = 'f=' . $ext . '&' . $options; |
|
| 23 | 23 | $this->setOptions($options); |
| 24 | 24 | if ($this->thumb->GenerateThumbnail() && $this->thumb->RenderToFile($outputFile)) { |
| 25 | 25 | return true; |
@@ -34,12 +34,12 @@ discard block |
||
| 34 | 34 | case 'jpg': |
| 35 | 35 | $ext = $this->fs->takeFileExt($file); |
| 36 | 36 | if ($ext == 'jpeg' || $ext == 'jpg') { |
| 37 | - $cmd = '/usr/bin/jpegtran -optimize -progressive -copy none -outfile '.escapeshellarg($file.'_').' '.escapeshellarg($file); |
|
| 37 | + $cmd = '/usr/bin/jpegtran -optimize -progressive -copy none -outfile ' . escapeshellarg($file . '_') . ' ' . escapeshellarg($file); |
|
| 38 | 38 | exec($cmd, $result, $return_var); |
| 39 | - if ($this->fs->fileSize($file) > $this->fs->fileSize($file.'_')) { |
|
| 40 | - $this->fs->moveFile($file.'_', $file); |
|
| 39 | + if ($this->fs->fileSize($file) > $this->fs->fileSize($file . '_')) { |
|
| 40 | + $this->fs->moveFile($file . '_', $file); |
|
| 41 | 41 | } else { |
| 42 | - $this->fs->unlink($file.'_'); |
|
| 42 | + $this->fs->unlink($file . '_'); |
|
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | break; |
@@ -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 | -include_once(dirname(dirname(__FILE__)).'/APIHelpers.class.php'); |
|
| 4 | -class Helper extends \APIhelpers{ |
|
| 3 | +include_once(dirname(dirname(__FILE__)) . '/APIHelpers.class.php'); |
|
| 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] |
@@ -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 | } |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | $this->get_TV(); |
| 80 | 80 | $uTable = $this->makeTable("manager_users"); |
| 81 | 81 | $aTable = $this->makeTable("user_attributes"); |
| 82 | - $query = "SELECT `u`.`id`, `a`.`email`, `u`.`username` FROM ".$aTable." as `a` LEFT JOIN ".$uTable." as `u` ON `u`.`id`=`a`.`internalKey`"; |
|
| 82 | + $query = "SELECT `u`.`id`, `a`.`email`, `u`.`username` FROM " . $aTable . " as `a` LEFT JOIN " . $uTable . " as `u` ON `u`.`id`=`a`.`internalKey`"; |
|
| 83 | 83 | $this->managerUsers = new DLCollection($modx, $this->query($query)); |
| 84 | 84 | } |
| 85 | 85 | |
@@ -94,20 +94,20 @@ discard block |
||
| 94 | 94 | $out = array_diff_key(parent::toArray(), $this->default_field); |
| 95 | 95 | $tpl = $this->get('template'); |
| 96 | 96 | $tvTPL = APIHelpers::getkey($this->tvTpl, $tpl, array()); |
| 97 | - foreach($tvTPL as $item){ |
|
| 98 | - if(isset($this->tvid[$item]) && !array_key_exists($this->tvid[$item], $out)){ |
|
| 97 | + foreach ($tvTPL as $item) { |
|
| 98 | + if (isset($this->tvid[$item]) && !array_key_exists($this->tvid[$item], $out)) { |
|
| 99 | 99 | $out[$this->tvid[$item]] = $this->get($this->tvid[$item]); |
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | - if($render){ |
|
| 103 | - foreach($out as $key => $val){ |
|
| 102 | + if ($render) { |
|
| 103 | + foreach ($out as $key => $val) { |
|
| 104 | 104 | $out[$key] = $this->renderTV($key); |
| 105 | 105 | } |
| 106 | 106 | } |
| 107 | 107 | return $out; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - public function toArray($prefix = '', $suffix = '', $sep = '_', $render = true){ |
|
| 110 | + public function toArray($prefix = '', $suffix = '', $sep = '_', $render = true) { |
|
| 111 | 111 | $out = array_merge( |
| 112 | 112 | $this->toArrayMain(), |
| 113 | 113 | $this->toArrayTV($render), |
@@ -115,17 +115,17 @@ discard block |
||
| 115 | 115 | ); |
| 116 | 116 | return \APIhelpers::renameKeyArr($out, $prefix, $suffix, $sep); |
| 117 | 117 | } |
| 118 | - public function getUrl(){ |
|
| 118 | + public function getUrl() { |
|
| 119 | 119 | $out = null; |
| 120 | 120 | $id = (int)$this->getID(); |
| 121 | - if(!empty($id)){ |
|
| 121 | + if (!empty($id)) { |
|
| 122 | 122 | $out = $this->modx->makeUrl($id); |
| 123 | 123 | } |
| 124 | 124 | return $out; |
| 125 | 125 | } |
| 126 | - public function getTitle($main = 'menutitle', $second = 'pagetitle'){ |
|
| 126 | + public function getTitle($main = 'menutitle', $second = 'pagetitle') { |
|
| 127 | 127 | $title = $this->get($main); |
| 128 | - if(empty($title) && $title !== '0'){ |
|
| 128 | + if (empty($title) && $title !== '0') { |
|
| 129 | 129 | $title = $this->get($second); |
| 130 | 130 | } |
| 131 | 131 | return $title; |
@@ -138,14 +138,14 @@ discard block |
||
| 138 | 138 | $del = ($this->get('deleted') == 0 && ($this->get('deletedon') == 0 || $this->get('deletedon') > time())); |
| 139 | 139 | return ($pub && $unpub && $del); |
| 140 | 140 | } |
| 141 | - public function touch(){ |
|
| 141 | + public function touch() { |
|
| 142 | 142 | $this->set('editedon', time()); |
| 143 | 143 | return $this; |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - public function renderTV($tvname){ |
|
| 146 | + public function renderTV($tvname) { |
|
| 147 | 147 | $out = null; |
| 148 | - if($this->getID() > 0){ |
|
| 148 | + if ($this->getID() > 0) { |
|
| 149 | 149 | include_once MODX_MANAGER_PATH . "includes/tmplvars.format.inc.php"; |
| 150 | 150 | include_once MODX_MANAGER_PATH . "includes/tmplvars.commands.inc.php"; |
| 151 | 151 | $tvval = $this->get($tvname); |
@@ -158,13 +158,13 @@ discard block |
||
| 158 | 158 | return $out; |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - public function get($key){ |
|
| 161 | + public function get($key) { |
|
| 162 | 162 | $out = parent::get($key); |
| 163 | - if(isset($this->tv[$key])){ |
|
| 163 | + if (isset($this->tv[$key])) { |
|
| 164 | 164 | $tpl = $this->get('template'); |
| 165 | 165 | $tvTPL = APIHelpers::getkey($this->tvTpl, $tpl, array()); |
| 166 | 166 | $tvID = APIHelpers::getkey($this->tv, $key, 0); |
| 167 | - if(in_array($tvID, $tvTPL) && is_null($out)){ |
|
| 167 | + if (in_array($tvID, $tvTPL) && is_null($out)) { |
|
| 168 | 168 | $out = APIHelpers::getkey($this->tvd[$key], 'value', null); |
| 169 | 169 | } |
| 170 | 170 | } |
@@ -184,46 +184,46 @@ discard block |
||
| 184 | 184 | break; |
| 185 | 185 | case 'published': |
| 186 | 186 | $value = (int)((bool)$value); |
| 187 | - if($value){ |
|
| 187 | + if ($value) { |
|
| 188 | 188 | $this->field['publishedon'] = time() + $this->modxConfig('server_offset_time'); |
| 189 | 189 | } |
| 190 | 190 | break; |
| 191 | 191 | case 'publishedon': |
| 192 | 192 | $value = $this->getTime($value); |
| 193 | - if($value){ |
|
| 193 | + if ($value) { |
|
| 194 | 194 | $this->field['published'] = 1; |
| 195 | - }else{ |
|
| 195 | + } else { |
|
| 196 | 196 | $this->field['published'] = 0; |
| 197 | 197 | } |
| 198 | 198 | break; |
| 199 | 199 | case 'pub_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'] = 1; |
| 203 | 203 | $this->field['publishedon'] = $value; |
| 204 | 204 | } |
| 205 | 205 | break; |
| 206 | 206 | case 'unpub_date': |
| 207 | 207 | $value = $this->getTime($value); |
| 208 | - if($value > 0 && time() + $this->modxConfig('server_offset_time') > $value){ |
|
| 208 | + if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) { |
|
| 209 | 209 | $this->field['published'] = 0; |
| 210 | 210 | $this->field['publishedon'] = 0; |
| 211 | 211 | } |
| 212 | 212 | break; |
| 213 | 213 | case 'deleted': |
| 214 | 214 | $value = (int)((bool)$value); |
| 215 | - if($value){ |
|
| 215 | + if ($value) { |
|
| 216 | 216 | $this->field['deletedon'] = time() + $this->modxConfig('server_offset_time'); |
| 217 | - }else{ |
|
| 217 | + } else { |
|
| 218 | 218 | $this->field['deletedon'] = 0; |
| 219 | 219 | } |
| 220 | 220 | break; |
| 221 | 221 | case 'deletedon': |
| 222 | 222 | $value = $this->getTime($value); |
| 223 | - if($value > 0 && time() + $this->modxConfig('server_offset_time') < $value){ |
|
| 223 | + if ($value > 0 && time() + $this->modxConfig('server_offset_time') < $value) { |
|
| 224 | 224 | $value = 0; |
| 225 | 225 | } |
| 226 | - if($value){ |
|
| 226 | + if ($value) { |
|
| 227 | 227 | $this->field['deleted'] = 1; |
| 228 | 228 | } |
| 229 | 229 | break; |
@@ -243,19 +243,19 @@ discard block |
||
| 243 | 243 | return $this; |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | - protected function getUser($value, $default = 0){ |
|
| 246 | + protected function getUser($value, $default = 0) { |
|
| 247 | 247 | $currentAdmin = APIHelpers::getkey($_SESSION, 'mgrInternalKey', 0); |
| 248 | 248 | $value = (int)$value; |
| 249 | - if(!empty($value)){ |
|
| 249 | + if (!empty($value)) { |
|
| 250 | 250 | $by = $this->findUserBy($value); |
| 251 | 251 | $exists = $this->managerUsers->exists(function($key, $val) use ($by, $value){ |
| 252 | 252 | return ($val->containsKey($by) && $val->get($by) === (string)$value); |
| 253 | 253 | }); |
| 254 | - if(!$exists){ |
|
| 254 | + if (!$exists) { |
|
| 255 | 255 | $value = 0; |
| 256 | 256 | } |
| 257 | 257 | } |
| 258 | - if(empty($value)){ |
|
| 258 | + if (empty($value)) { |
|
| 259 | 259 | $value = empty($currentAdmin) ? $default : $currentAdmin; |
| 260 | 260 | } |
| 261 | 261 | return $value; |
@@ -279,13 +279,13 @@ discard block |
||
| 279 | 279 | return $find; |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | - protected function getTime($value){ |
|
| 282 | + protected function getTime($value) { |
|
| 283 | 283 | $value = trim($value); |
| 284 | - if(!empty($value)){ |
|
| 285 | - if(!is_numeric($value)){ |
|
| 284 | + if (!empty($value)) { |
|
| 285 | + if (!is_numeric($value)) { |
|
| 286 | 286 | $value = (int)strtotime($value); |
| 287 | 287 | } |
| 288 | - if(!empty($value)){ |
|
| 288 | + if (!empty($value)) { |
|
| 289 | 289 | $value += $this->modxConfig('server_offset_time'); |
| 290 | 290 | } |
| 291 | 291 | } |
@@ -344,8 +344,8 @@ discard block |
||
| 344 | 344 | |
| 345 | 345 | foreach ($this->default_field as $key => $value) { |
| 346 | 346 | $tmp = $this->get($key); |
| 347 | - if ($this->newDoc && ( !is_int($tmp) && $tmp=='')) { |
|
| 348 | - if($tmp == $value){ |
|
| 347 | + if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
| 348 | + if ($tmp == $value) { |
|
| 349 | 349 | switch ($key) { |
| 350 | 350 | case 'cacheable': |
| 351 | 351 | $value = $this->modxConfig('cache_default'); |
@@ -366,11 +366,11 @@ discard block |
||
| 366 | 366 | } |
| 367 | 367 | $this->field[$key] = $value; |
| 368 | 368 | } |
| 369 | - switch(true){ |
|
| 369 | + switch (true) { |
|
| 370 | 370 | case $key == 'parent': |
| 371 | 371 | $parent = (int)$this->get($key); |
| 372 | 372 | $q = $this->query("SELECT count(`id`) FROM {$this->makeTable('site_content')} WHERE `id`='{$parent}'"); |
| 373 | - if($this->modx->db->getValue($q)!=1){ |
|
| 373 | + if ($this->modx->db->getValue($q) != 1) { |
|
| 374 | 374 | $parent = $value; |
| 375 | 375 | } |
| 376 | 376 | $this->field[$key] = $parent; |
@@ -428,7 +428,7 @@ 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()) { |
@@ -437,11 +437,11 @@ discard block |
||
| 437 | 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()) { |
@@ -470,7 +470,7 @@ discard block |
||
| 470 | 470 | ), $fire_events); |
| 471 | 471 | |
| 472 | 472 | $id = $this->sanitarIn($_ids); |
| 473 | - if(!empty($id)){ |
|
| 473 | + if (!empty($id)) { |
|
| 474 | 474 | $this->query("DELETE from {$this->makeTable('site_content')} where `id` IN ({$id})"); |
| 475 | 475 | $this->query("DELETE from {$this->makeTable('site_tmplvar_contentvalues')} where `contentid` IN ({$id})"); |
| 476 | 476 | $this->invokeEvent('OnEmptyTrash', array( |
@@ -537,25 +537,25 @@ discard block |
||
| 537 | 537 | $this->modx->_TVnames[$row['name']] = $row['id']; |
| 538 | 538 | } |
| 539 | 539 | } |
| 540 | - foreach($this->modx->_TVnames as $name => $id){ |
|
| 540 | + foreach ($this->modx->_TVnames as $name => $id) { |
|
| 541 | 541 | $this->tvid[$id] = $name; |
| 542 | 542 | $this->tv[$name] = $id; |
| 543 | 543 | } |
| 544 | 544 | $this->loadTVTemplate()->loadTVDefault(array_values($this->tv)); |
| 545 | 545 | return $this; |
| 546 | 546 | } |
| 547 | - protected function loadTVTemplate(){ |
|
| 548 | - $q = $this->query("SELECT `tmplvarid`, `templateid` FROM ".$this->makeTable('site_tmplvar_templates')); |
|
| 547 | + protected function loadTVTemplate() { |
|
| 548 | + $q = $this->query("SELECT `tmplvarid`, `templateid` FROM " . $this->makeTable('site_tmplvar_templates')); |
|
| 549 | 549 | $q = $this->modx->db->makeArray($q); |
| 550 | 550 | $this->tvTpl = array(); |
| 551 | - foreach($q as $item){ |
|
| 551 | + foreach ($q as $item) { |
|
| 552 | 552 | $this->tvTpl[$item['templateid']][] = $item['tmplvarid']; |
| 553 | 553 | } |
| 554 | 554 | return $this; |
| 555 | 555 | } |
| 556 | 556 | protected function loadTVDefault(array $tvId = array()) |
| 557 | 557 | { |
| 558 | - if(is_array($tvId) && !empty($tvId)){ |
|
| 558 | + if (is_array($tvId) && !empty($tvId)) { |
|
| 559 | 559 | $tbl_site_tmplvars = $this->makeTable('site_tmplvars'); |
| 560 | 560 | $fields = 'id,name,default_text as value,display,display_params,type'; |
| 561 | 561 | $implodeTvId = implode(',', $tvId); |
@@ -572,7 +572,7 @@ 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)."'"; |
|
| 575 | + $sql = "SELECT `id` FROM {$this->makeTable('site_templates')} WHERE `templatename` = '" . $this->escape($tpl) . "'"; |
|
| 576 | 576 | $rs = $this->query($sql); |
| 577 | 577 | if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) throw new Exception("Template {$tpl} is not exists"); |
| 578 | 578 | $tpl = $this->modx->db->getValue($rs); |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | $value = $this->getTime($value); |
| 193 | 193 | if($value){ |
| 194 | 194 | $this->field['published'] = 1; |
| 195 | - }else{ |
|
| 195 | + } else{ |
|
| 196 | 196 | $this->field['published'] = 0; |
| 197 | 197 | } |
| 198 | 198 | break; |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | $value = (int)((bool)$value); |
| 215 | 215 | if($value){ |
| 216 | 216 | $this->field['deletedon'] = time() + $this->modxConfig('server_offset_time'); |
| 217 | - }else{ |
|
| 217 | + } else{ |
|
| 218 | 218 | $this->field['deletedon'] = 0; |
| 219 | 219 | } |
| 220 | 220 | break; |
@@ -403,7 +403,9 @@ discard block |
||
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | foreach ($fld as $key => $value) { |
| 406 | - if (empty($this->tv[$key])) continue; |
|
| 406 | + if (empty($this->tv[$key])) {
|
|
| 407 | + continue; |
|
| 408 | + } |
|
| 407 | 409 | if ($value === '') { |
| 408 | 410 | $this->query("DELETE FROM {$this->makeTable('site_tmplvar_contentvalues')} WHERE `contentid` = '{$this->id}' AND `tmplvarid` = '{$this->tv[$key]}'"); |
| 409 | 411 | } 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)); |
@@ -33,6 +33,9 @@ discard block |
||
| 33 | 33 | $this->_decodedFields = new DLCollection($this->modx); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | + /** |
|
| 37 | + * @param boolean $flag |
|
| 38 | + */ |
|
| 36 | 39 | public function setDebug($flag){
|
| 37 | 40 | $this->_debug = (bool)$flag; |
| 38 | 41 | return $this; |
@@ -43,6 +46,10 @@ discard block |
||
| 43 | 46 | public function getDefaultFields(){
|
| 44 | 47 | return $this->default_field; |
| 45 | 48 | } |
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @param string $name |
|
| 52 | + */ |
|
| 46 | 53 | final public function modxConfig($name, $default = null) |
| 47 | 54 | {
|
| 48 | 55 | return APIHelpers::getkey($this->modx->config, $name, $default); |
@@ -71,6 +78,10 @@ discard block |
||
| 71 | 78 | } |
| 72 | 79 | return $value; |
| 73 | 80 | } |
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * @param string $name |
|
| 84 | + */ |
|
| 74 | 85 | final public function invokeEvent($name, $data = array(), $flag = false) |
| 75 | 86 | {
|
| 76 | 87 | $flag = (isset($flag) && $flag != '') ? (bool)$flag : false; |
@@ -144,6 +155,10 @@ discard block |
||
| 144 | 155 | } |
| 145 | 156 | $this->invokeEvent('OnSiteRefresh', array('IDs' => $IDs), $fire_events);
|
| 146 | 157 | } |
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * @param integer $id |
|
| 161 | + */ |
|
| 147 | 162 | public function switchObject($id){
|
| 148 | 163 | switch(true){
|
| 149 | 164 | //Если загружен другой объект - не тот, с которым мы хотим временно поработать |
@@ -345,6 +360,10 @@ discard block |
||
| 345 | 360 | return $out; |
| 346 | 361 | } |
| 347 | 362 | |
| 363 | + /** |
|
| 364 | + * @param string $table |
|
| 365 | + * @param string $field |
|
| 366 | + */ |
|
| 348 | 367 | public function checkUnique($table, $field, $PK = 'id') |
| 349 | 368 | {
|
| 350 | 369 | $val = $this->get($field); |
@@ -394,6 +413,9 @@ discard block |
||
| 394 | 413 | |
| 395 | 414 | abstract public function save($fire_events = null, $clearCache = false); |
| 396 | 415 | |
| 416 | + /** |
|
| 417 | + * @param integer $ids |
|
| 418 | + */ |
|
| 397 | 419 | abstract public function delete($ids, $fire_events = null); |
| 398 | 420 | |
| 399 | 421 | final public function sanitarTag($data) |
@@ -401,6 +423,9 @@ discard block |
||
| 401 | 423 | return parent::sanitarTag($this->modx->stripTags($data)); |
| 402 | 424 | } |
| 403 | 425 | |
| 426 | + /** |
|
| 427 | + * @param string $version |
|
| 428 | + */ |
|
| 404 | 429 | final protected function checkVersion($version, $dmi3yy = true) |
| 405 | 430 | {
|
| 406 | 431 | $flag = false; |
@@ -418,6 +443,9 @@ discard block |
||
| 418 | 443 | return $flag; |
| 419 | 444 | } |
| 420 | 445 | |
| 446 | + /** |
|
| 447 | + * @param string $name |
|
| 448 | + */ |
|
| 421 | 449 | protected function eraseField($name) |
| 422 | 450 | {
|
| 423 | 451 | $flag = false; |
@@ -487,7 +515,7 @@ discard block |
||
| 487 | 515 | |
| 488 | 516 | /** |
| 489 | 517 | * Получить список не запакованных полей |
| 490 | - * @return array |
|
| 518 | + * @return DLCollection |
|
| 491 | 519 | */ |
| 492 | 520 | public function getNoEncodeFields(){
|
| 493 | 521 | return $this->_decodedFields->filter(function($value){
|
@@ -497,7 +525,7 @@ discard block |
||
| 497 | 525 | |
| 498 | 526 | /** |
| 499 | 527 | * Получить список не распакованных полей |
| 500 | - * @return array |
|
| 528 | + * @return DLCollection |
|
| 501 | 529 | */ |
| 502 | 530 | public function getNoDecodeFields(){
|
| 503 | 531 | return $this->_decodedFields->filter(function($value){
|
@@ -564,7 +592,7 @@ discard block |
||
| 564 | 592 | * Запаковывает конкретное поле в JSON |
| 565 | 593 | * @param string $field Имя поля |
| 566 | 594 | * @param bool $store обновить запакованное поле |
| 567 | - * @return array json строка |
|
| 595 | + * @return string|null json строка |
|
| 568 | 596 | */ |
| 569 | 597 | public function encodeField($field, $store = false){
|
| 570 | 598 | $out = null; |
@@ -13,23 +13,23 @@ discard block |
||
| 13 | 13 | protected $set = array(); |
| 14 | 14 | protected $newDoc = false; |
| 15 | 15 | protected $pkName = 'id'; |
| 16 | - protected $ignoreError = ''; |
|
| 16 | + protected $ignoreError = ''; |
|
| 17 | 17 | protected $_debug = false; |
| 18 | 18 | protected $_query = array(); |
| 19 | 19 | protected $jsonFields = array(); |
| 20 | - /** |
|
| 21 | - * @var DLCollection |
|
| 22 | - */ |
|
| 20 | + /** |
|
| 21 | + * @var DLCollection |
|
| 22 | + */ |
|
| 23 | 23 | private $_decodedFields; |
| 24 | - private $_table = array(); |
|
| 24 | + private $_table = array(); |
|
| 25 | 25 | |
| 26 | 26 | public function __construct(DocumentParser $modx, $debug = false) |
| 27 | 27 | {
|
| 28 | 28 | if(function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc()){
|
| 29 | - throw new Exception('Magic Quotes is a deprecated and mostly useless setting that should be disabled. Please ask your server administrator to disable it in php.ini or in your webserver config.');
|
|
| 30 | - } |
|
| 29 | + throw new Exception('Magic Quotes is a deprecated and mostly useless setting that should be disabled. Please ask your server administrator to disable it in php.ini or in your webserver config.');
|
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - $this->setDebug($debug); |
|
| 32 | + $this->setDebug($debug); |
|
| 33 | 33 | $this->_decodedFields = new DLCollection($this->modx); |
| 34 | 34 | } |
| 35 | 35 | |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | $value = $this->modx->db->escape($value); |
| 71 | 71 | } |
| 72 | 72 | return $value; |
| 73 | - } |
|
| 73 | + } |
|
| 74 | 74 | final public function invokeEvent($name, $data = array(), $flag = false) |
| 75 | 75 | {
|
| 76 | 76 | $flag = (isset($flag) && $flag != '') ? (bool)$flag : false; |
@@ -109,42 +109,42 @@ discard block |
||
| 109 | 109 | |
| 110 | 110 | final public function clearCache($fire_events = null, $custom = false) |
| 111 | 111 | {
|
| 112 | - $IDs = array(); |
|
| 113 | - if($custom === false) {
|
|
| 114 | - $this->modx->clearCache(); |
|
| 115 | - include_once(MODX_MANAGER_PATH . 'processors/cache_sync.class.processor.php'); |
|
| 116 | - $sync = new synccache(); |
|
| 117 | - $path = $this->getCachePath(true); |
|
| 118 | - $sync->setCachepath($path); |
|
| 119 | - $sync->setReport(false); |
|
| 120 | - $sync->emptyCache(); |
|
| 121 | - }else {
|
|
| 122 | - if(is_scalar($custom)){
|
|
| 123 | - $custom = array($custom); |
|
| 124 | - } |
|
| 125 | - switch ($this->modx->config['cache_type']) {
|
|
| 126 | - case 2: |
|
| 127 | - $cacheFile = "_*.pageCache.php"; |
|
| 128 | - break; |
|
| 129 | - default: |
|
| 130 | - $cacheFile = ".pageCache.php"; |
|
| 131 | - } |
|
| 132 | - if(is_array($custom)) {
|
|
| 133 | - foreach($custom as $id) {
|
|
| 134 | - $tmp = glob(MODX_BASE_PATH."assets/cache/docid_" . $id . $cacheFile); |
|
| 135 | - foreach($tmp as $file){
|
|
| 136 | - if(is_readable($file)){
|
|
| 137 | - unlink($file); |
|
| 138 | - } |
|
| 139 | - $IDs[] = $id; |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - clearstatcache(); |
|
| 144 | - } |
|
| 112 | + $IDs = array(); |
|
| 113 | + if($custom === false) {
|
|
| 114 | + $this->modx->clearCache(); |
|
| 115 | + include_once(MODX_MANAGER_PATH . 'processors/cache_sync.class.processor.php'); |
|
| 116 | + $sync = new synccache(); |
|
| 117 | + $path = $this->getCachePath(true); |
|
| 118 | + $sync->setCachepath($path); |
|
| 119 | + $sync->setReport(false); |
|
| 120 | + $sync->emptyCache(); |
|
| 121 | + }else {
|
|
| 122 | + if(is_scalar($custom)){
|
|
| 123 | + $custom = array($custom); |
|
| 124 | + } |
|
| 125 | + switch ($this->modx->config['cache_type']) {
|
|
| 126 | + case 2: |
|
| 127 | + $cacheFile = "_*.pageCache.php"; |
|
| 128 | + break; |
|
| 129 | + default: |
|
| 130 | + $cacheFile = ".pageCache.php"; |
|
| 131 | + } |
|
| 132 | + if(is_array($custom)) {
|
|
| 133 | + foreach($custom as $id) {
|
|
| 134 | + $tmp = glob(MODX_BASE_PATH."assets/cache/docid_" . $id . $cacheFile); |
|
| 135 | + foreach($tmp as $file){
|
|
| 136 | + if(is_readable($file)){
|
|
| 137 | + unlink($file); |
|
| 138 | + } |
|
| 139 | + $IDs[] = $id; |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + clearstatcache(); |
|
| 144 | + } |
|
| 145 | 145 | $this->invokeEvent('OnSiteRefresh', array('IDs' => $IDs), $fire_events);
|
| 146 | 146 | } |
| 147 | - public function switchObject($id){
|
|
| 147 | + public function switchObject($id){
|
|
| 148 | 148 | switch(true){
|
| 149 | 149 | //Если загружен другой объект - не тот, с которым мы хотим временно поработать |
| 150 | 150 | case ($this->getID() != $id && $id): |
@@ -161,13 +161,13 @@ discard block |
||
| 161 | 161 | } |
| 162 | 162 | return $obj; |
| 163 | 163 | } |
| 164 | - public function useIgnore($flag = true){
|
|
| 165 | - $this->ignoreError = $flag ? 'IGNORE' : ''; |
|
| 166 | - return $this; |
|
| 167 | - } |
|
| 168 | - public function hasIgnore(){
|
|
| 169 | - return (bool)$this->ignoreError; |
|
| 170 | - } |
|
| 164 | + public function useIgnore($flag = true){
|
|
| 165 | + $this->ignoreError = $flag ? 'IGNORE' : ''; |
|
| 166 | + return $this; |
|
| 167 | + } |
|
| 168 | + public function hasIgnore(){
|
|
| 169 | + return (bool)$this->ignoreError; |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | 172 | public function set($key, $value) |
| 173 | 173 | {
|
@@ -255,38 +255,38 @@ discard block |
||
| 255 | 255 | final public function fromJson($data, $callback = null) |
| 256 | 256 | {
|
| 257 | 257 | if (is_scalar($data) && !empty($data)) {
|
| 258 | - $json = json_decode($data); |
|
| 259 | - } else throw new Exception("json is not string with json data");
|
|
| 260 | - |
|
| 261 | - if ($this->jsonError($json)) {
|
|
| 262 | - if (isset($callback) && is_callable($callback)) {
|
|
| 263 | - call_user_func_array($callback, array($json)); |
|
| 264 | - } else {
|
|
| 265 | - if (isset($callback)) throw new Exception("Can't call callback JSON unpack <pre>" . print_r($callback, 1) . "</pre>");
|
|
| 258 | + $json = json_decode($data); |
|
| 259 | + } else throw new Exception("json is not string with json data");
|
|
| 260 | + |
|
| 261 | + if ($this->jsonError($json)) {
|
|
| 262 | + if (isset($callback) && is_callable($callback)) {
|
|
| 263 | + call_user_func_array($callback, array($json)); |
|
| 264 | + } else {
|
|
| 265 | + if (isset($callback)) throw new Exception("Can't call callback JSON unpack <pre>" . print_r($callback, 1) . "</pre>");
|
|
| 266 | 266 | foreach ($json as $key => $val) {
|
| 267 | - $this->set($key, $val); |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - } else throw new Exception('Error from JSON decode: <pre>' . print_r($data, 1) . '</pre>');
|
|
| 267 | + $this->set($key, $val); |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + } else throw new Exception('Error from JSON decode: <pre>' . print_r($data, 1) . '</pre>');
|
|
| 271 | 271 | |
| 272 | - return $this; |
|
| 272 | + return $this; |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | final public function toJson($callback = null) |
| 276 | 276 | {
|
| 277 | 277 | $data = $this->toArray(); |
| 278 | 278 | if (isset($callback) && is_callable($callback)) {
|
| 279 | - $data = call_user_func_array($callback, array($data)); |
|
| 280 | - } else {
|
|
| 281 | - if (isset($callback)) throw new Exception("Can't call callback JSON pre pack <pre>" . print_r($callback, 1) . "</pre>");
|
|
| 282 | - } |
|
| 279 | + $data = call_user_func_array($callback, array($data)); |
|
| 280 | + } else {
|
|
| 281 | + if (isset($callback)) throw new Exception("Can't call callback JSON pre pack <pre>" . print_r($callback, 1) . "</pre>");
|
|
| 282 | + } |
|
| 283 | 283 | $json = json_encode($data); |
| 284 | 284 | |
| 285 | - if ($this->jsonError($data, $json)) {
|
|
| 286 | - throw new Exception('Error from JSON decode: <pre>' . print_r($data, 1) . '</pre>');
|
|
| 287 | - } |
|
| 285 | + if ($this->jsonError($data, $json)) {
|
|
| 286 | + throw new Exception('Error from JSON decode: <pre>' . print_r($data, 1) . '</pre>');
|
|
| 287 | + } |
|
| 288 | 288 | |
| 289 | - return $json; |
|
| 289 | + return $json; |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | final protected function jsonError($data) |
@@ -500,7 +500,7 @@ discard block |
||
| 500 | 500 | * @return array |
| 501 | 501 | */ |
| 502 | 502 | public function getNoDecodeFields(){
|
| 503 | - return $this->_decodedFields->filter(function($value){
|
|
| 503 | + return $this->_decodedFields->filter(function($value){
|
|
| 504 | 504 | return ($value === true); |
| 505 | 505 | }); |
| 506 | 506 | } |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -include_once(MODX_BASE_PATH.'assets/lib/APIHelpers.class.php'); |
|
| 3 | -include_once(MODX_BASE_PATH.'assets/snippets/DocLister/lib/jsonHelper.class.php'); |
|
| 4 | -include_once(MODX_BASE_PATH.'assets/snippets/DocLister/lib/DLCollection.class.php'); |
|
| 2 | +include_once(MODX_BASE_PATH . 'assets/lib/APIHelpers.class.php'); |
|
| 3 | +include_once(MODX_BASE_PATH . 'assets/snippets/DocLister/lib/jsonHelper.class.php'); |
|
| 4 | +include_once(MODX_BASE_PATH . 'assets/snippets/DocLister/lib/DLCollection.class.php'); |
|
| 5 | 5 | |
| 6 | 6 | abstract class MODxAPI extends MODxAPIhelpers |
| 7 | 7 | {
|
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | public function __construct(DocumentParser $modx, $debug = false) |
| 27 | 27 | {
|
| 28 | - if(function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc()){
|
|
| 28 | + if (function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc()) {
|
|
| 29 | 29 | throw new Exception('Magic Quotes is a deprecated and mostly useless setting that should be disabled. Please ask your server administrator to disable it in php.ini or in your webserver config.');
|
| 30 | 30 | } |
| 31 | 31 | |
@@ -33,40 +33,40 @@ discard block |
||
| 33 | 33 | $this->_decodedFields = new DLCollection($this->modx); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - public function setDebug($flag){
|
|
| 36 | + public function setDebug($flag) {
|
|
| 37 | 37 | $this->_debug = (bool)$flag; |
| 38 | 38 | return $this; |
| 39 | 39 | } |
| 40 | - public function getDebug(){
|
|
| 40 | + public function getDebug() {
|
|
| 41 | 41 | return $this->_debug; |
| 42 | 42 | } |
| 43 | - public function getDefaultFields(){
|
|
| 43 | + public function getDefaultFields() {
|
|
| 44 | 44 | return $this->default_field; |
| 45 | 45 | } |
| 46 | 46 | final public function modxConfig($name, $default = null) |
| 47 | 47 | {
|
| 48 | 48 | return APIHelpers::getkey($this->modx->config, $name, $default); |
| 49 | 49 | } |
| 50 | - public function addQuery($q){
|
|
| 51 | - if(is_scalar($q) && !empty($q)){
|
|
| 50 | + public function addQuery($q) {
|
|
| 51 | + if (is_scalar($q) && !empty($q)) {
|
|
| 52 | 52 | $this->_query[] = $q; |
| 53 | 53 | } |
| 54 | 54 | return $this; |
| 55 | 55 | } |
| 56 | - public function getQueryList(){
|
|
| 56 | + public function getQueryList() {
|
|
| 57 | 57 | return $this->_query; |
| 58 | 58 | } |
| 59 | 59 | final public function query($SQL) |
| 60 | 60 | {
|
| 61 | - if($this->getDebug()){
|
|
| 61 | + if ($this->getDebug()) {
|
|
| 62 | 62 | $this->addQuery($SQL); |
| 63 | 63 | } |
| 64 | 64 | return empty($SQL) ? null : $this->modx->db->query($SQL); |
| 65 | 65 | } |
| 66 | - final public function escape($value){
|
|
| 67 | - if(!is_scalar($value)){
|
|
| 66 | + final public function escape($value) {
|
|
| 67 | + if (!is_scalar($value)) {
|
|
| 68 | 68 | $value = ''; |
| 69 | - }else{
|
|
| 69 | + } else {
|
|
| 70 | 70 | $value = $this->modx->db->escape($value); |
| 71 | 71 | } |
| 72 | 72 | return $value; |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | final public function clearCache($fire_events = null, $custom = false) |
| 111 | 111 | {
|
| 112 | 112 | $IDs = array(); |
| 113 | - if($custom === false) {
|
|
| 113 | + if ($custom === false) {
|
|
| 114 | 114 | $this->modx->clearCache(); |
| 115 | 115 | include_once(MODX_MANAGER_PATH . 'processors/cache_sync.class.processor.php'); |
| 116 | 116 | $sync = new synccache(); |
@@ -118,8 +118,8 @@ discard block |
||
| 118 | 118 | $sync->setCachepath($path); |
| 119 | 119 | $sync->setReport(false); |
| 120 | 120 | $sync->emptyCache(); |
| 121 | - }else {
|
|
| 122 | - if(is_scalar($custom)){
|
|
| 121 | + } else {
|
|
| 122 | + if (is_scalar($custom)) {
|
|
| 123 | 123 | $custom = array($custom); |
| 124 | 124 | } |
| 125 | 125 | switch ($this->modx->config['cache_type']) {
|
@@ -129,11 +129,11 @@ discard block |
||
| 129 | 129 | default: |
| 130 | 130 | $cacheFile = ".pageCache.php"; |
| 131 | 131 | } |
| 132 | - if(is_array($custom)) {
|
|
| 133 | - foreach($custom as $id) {
|
|
| 134 | - $tmp = glob(MODX_BASE_PATH."assets/cache/docid_" . $id . $cacheFile); |
|
| 135 | - foreach($tmp as $file){
|
|
| 136 | - if(is_readable($file)){
|
|
| 132 | + if (is_array($custom)) {
|
|
| 133 | + foreach ($custom as $id) {
|
|
| 134 | + $tmp = glob(MODX_BASE_PATH . "assets/cache/docid_" . $id . $cacheFile); |
|
| 135 | + foreach ($tmp as $file) {
|
|
| 136 | + if (is_readable($file)) {
|
|
| 137 | 137 | unlink($file); |
| 138 | 138 | } |
| 139 | 139 | $IDs[] = $id; |
@@ -144,8 +144,8 @@ discard block |
||
| 144 | 144 | } |
| 145 | 145 | $this->invokeEvent('OnSiteRefresh', array('IDs' => $IDs), $fire_events);
|
| 146 | 146 | } |
| 147 | - public function switchObject($id){
|
|
| 148 | - switch(true){
|
|
| 147 | + public function switchObject($id) {
|
|
| 148 | + switch (true) {
|
|
| 149 | 149 | //Если загружен другой объект - не тот, с которым мы хотим временно поработать |
| 150 | 150 | case ($this->getID() != $id && $id): |
| 151 | 151 | $obj = clone $this; |
@@ -161,11 +161,11 @@ discard block |
||
| 161 | 161 | } |
| 162 | 162 | return $obj; |
| 163 | 163 | } |
| 164 | - public function useIgnore($flag = true){
|
|
| 164 | + public function useIgnore($flag = true) {
|
|
| 165 | 165 | $this->ignoreError = $flag ? 'IGNORE' : ''; |
| 166 | 166 | return $this; |
| 167 | 167 | } |
| 168 | - public function hasIgnore(){
|
|
| 168 | + public function hasIgnore() {
|
|
| 169 | 169 | return (bool)$this->ignoreError; |
| 170 | 170 | } |
| 171 | 171 | |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | } |
| 322 | 322 | return $out; |
| 323 | 323 | } |
| 324 | - final public function fieldPKName(){
|
|
| 324 | + final public function fieldPKName() {
|
|
| 325 | 325 | return $this->pkName; |
| 326 | 326 | } |
| 327 | 327 | final public function makeTable($table) |
@@ -337,7 +337,7 @@ discard block |
||
| 337 | 337 | } |
| 338 | 338 | $out = array(); |
| 339 | 339 | foreach ($data as $item) {
|
| 340 | - if($item !== ''){
|
|
| 340 | + if ($item !== '') {
|
|
| 341 | 341 | $out[] = $this->escape($item); |
| 342 | 342 | } |
| 343 | 343 | } |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | * @param string $field имя поля |
| 434 | 434 | * @return boolean |
| 435 | 435 | */ |
| 436 | - public function isJsonField($field){
|
|
| 436 | + public function isJsonField($field) {
|
|
| 437 | 437 | return (is_scalar($field) && in_array($field, $this->jsonFields)); |
| 438 | 438 | } |
| 439 | 439 | |
@@ -442,8 +442,8 @@ discard block |
||
| 442 | 442 | * @param string $field имя поля |
| 443 | 443 | * @return $this |
| 444 | 444 | */ |
| 445 | - public function markAsDecode($field){
|
|
| 446 | - if(is_scalar($field)){
|
|
| 445 | + public function markAsDecode($field) {
|
|
| 446 | + if (is_scalar($field)) {
|
|
| 447 | 447 | $this->_decodedFields->set($field, false); |
| 448 | 448 | } |
| 449 | 449 | return $this; |
@@ -454,8 +454,8 @@ discard block |
||
| 454 | 454 | * @param string $field имя поля |
| 455 | 455 | * @return $this |
| 456 | 456 | */ |
| 457 | - public function markAsEncode($field){
|
|
| 458 | - if(is_scalar($field)){
|
|
| 457 | + public function markAsEncode($field) {
|
|
| 458 | + if (is_scalar($field)) {
|
|
| 459 | 459 | $this->_decodedFields->set($field, true); |
| 460 | 460 | } |
| 461 | 461 | return $this; |
@@ -465,9 +465,9 @@ discard block |
||
| 465 | 465 | * Пометить все поля как запакованные |
| 466 | 466 | * @return $this |
| 467 | 467 | */ |
| 468 | - public function markAllEncode(){
|
|
| 468 | + public function markAllEncode() {
|
|
| 469 | 469 | $this->_decodedFields->clear(); |
| 470 | - foreach($this->jsonFields as $field){
|
|
| 470 | + foreach ($this->jsonFields as $field) {
|
|
| 471 | 471 | $this->markAsEncode($field); |
| 472 | 472 | } |
| 473 | 473 | return $this; |
@@ -477,9 +477,9 @@ discard block |
||
| 477 | 477 | * Пометить все поля как распакованные |
| 478 | 478 | * @return $this |
| 479 | 479 | */ |
| 480 | - public function markAllDecode(){
|
|
| 480 | + public function markAllDecode() {
|
|
| 481 | 481 | $this->_decodedFields->clear(); |
| 482 | - foreach($this->jsonFields as $field){
|
|
| 482 | + foreach ($this->jsonFields as $field) {
|
|
| 483 | 483 | $this->markAsDecode($field); |
| 484 | 484 | } |
| 485 | 485 | return $this; |
@@ -489,8 +489,8 @@ discard block |
||
| 489 | 489 | * Получить список не запакованных полей |
| 490 | 490 | * @return array |
| 491 | 491 | */ |
| 492 | - public function getNoEncodeFields(){
|
|
| 493 | - return $this->_decodedFields->filter(function($value){
|
|
| 492 | + public function getNoEncodeFields() {
|
|
| 493 | + return $this->_decodedFields->filter(function($value) {
|
|
| 494 | 494 | return ($value === false); |
| 495 | 495 | }); |
| 496 | 496 | } |
@@ -499,8 +499,8 @@ discard block |
||
| 499 | 499 | * Получить список не распакованных полей |
| 500 | 500 | * @return array |
| 501 | 501 | */ |
| 502 | - public function getNoDecodeFields(){
|
|
| 503 | - return $this->_decodedFields->filter(function($value){
|
|
| 502 | + public function getNoDecodeFields() {
|
|
| 503 | + return $this->_decodedFields->filter(function($value) {
|
|
| 504 | 504 | return ($value === true); |
| 505 | 505 | }); |
| 506 | 506 | } |
@@ -510,12 +510,12 @@ discard block |
||
| 510 | 510 | * @param string $field имя поля |
| 511 | 511 | * @return boolean |
| 512 | 512 | */ |
| 513 | - public function isDecodableField($field){
|
|
| 513 | + public function isDecodableField($field) {
|
|
| 514 | 514 | $data = $this->get($field); |
| 515 | 515 | /** |
| 516 | 516 | * Если поле скалярного типа и оно не распаковывалось раньше |
| 517 | 517 | */ |
| 518 | - return (is_scalar($data) && is_scalar($field) && $this->_decodedFields->get($field)===true); |
|
| 518 | + return (is_scalar($data) && is_scalar($field) && $this->_decodedFields->get($field) === true); |
|
| 519 | 519 | } |
| 520 | 520 | |
| 521 | 521 | /** |
@@ -523,11 +523,11 @@ discard block |
||
| 523 | 523 | * @param string $field имя поля |
| 524 | 524 | * @return boolean |
| 525 | 525 | */ |
| 526 | - public function isEncodableField($field){
|
|
| 526 | + public function isEncodableField($field) {
|
|
| 527 | 527 | /** |
| 528 | 528 | * Если поле было распаковано ранее и еще не упаковано |
| 529 | 529 | */ |
| 530 | - return (is_scalar($field) && $this->_decodedFields->get($field)===false); |
|
| 530 | + return (is_scalar($field) && $this->_decodedFields->get($field) === false); |
|
| 531 | 531 | } |
| 532 | 532 | |
| 533 | 533 | /** |
@@ -536,13 +536,13 @@ discard block |
||
| 536 | 536 | * @param bool $store обновить распакованное поле |
| 537 | 537 | * @return array ассоциативный массив с данными из json строки |
| 538 | 538 | */ |
| 539 | - public function decodeField($field, $store = false){
|
|
| 539 | + public function decodeField($field, $store = false) {
|
|
| 540 | 540 | $out = array(); |
| 541 | - if($this->isDecodableField($field)){
|
|
| 541 | + if ($this->isDecodableField($field)) {
|
|
| 542 | 542 | $data = $this->get($field); |
| 543 | 543 | $out = jsonHelper::jsonDecode($data, array('assoc' => true), true);
|
| 544 | 544 | } |
| 545 | - if($store){
|
|
| 545 | + if ($store) {
|
|
| 546 | 546 | $this->field[$field] = $out; |
| 547 | 547 | $this->markAsDecode($field); |
| 548 | 548 | } |
@@ -553,8 +553,8 @@ discard block |
||
| 553 | 553 | * Декодирование всех json полей |
| 554 | 554 | * @return $this |
| 555 | 555 | */ |
| 556 | - protected function decodeFields(){
|
|
| 557 | - foreach($this->getNoDecodeFields() as $field => $flag){
|
|
| 556 | + protected function decodeFields() {
|
|
| 557 | + foreach ($this->getNoDecodeFields() as $field => $flag) {
|
|
| 558 | 558 | $this->decodeField($field, true); |
| 559 | 559 | } |
| 560 | 560 | return $this; |
@@ -566,13 +566,13 @@ discard block |
||
| 566 | 566 | * @param bool $store обновить запакованное поле |
| 567 | 567 | * @return array json строка |
| 568 | 568 | */ |
| 569 | - public function encodeField($field, $store = false){
|
|
| 569 | + public function encodeField($field, $store = false) {
|
|
| 570 | 570 | $out = null; |
| 571 | - if($this->isEncodableField($field)){
|
|
| 571 | + if ($this->isEncodableField($field)) {
|
|
| 572 | 572 | $data = $this->get($field); |
| 573 | 573 | $out = json_encode($data); |
| 574 | 574 | } |
| 575 | - if($store){
|
|
| 575 | + if ($store) {
|
|
| 576 | 576 | $this->field[$field] = $out; |
| 577 | 577 | $this->markAsEncode($field); |
| 578 | 578 | } |
@@ -583,8 +583,8 @@ discard block |
||
| 583 | 583 | * Запаковка всех json полей |
| 584 | 584 | * @return $this |
| 585 | 585 | */ |
| 586 | - protected function encodeFields(){
|
|
| 587 | - foreach($this->getNoEncodeFields() as $field => $flag){
|
|
| 586 | + protected function encodeFields() {
|
|
| 587 | + foreach ($this->getNoEncodeFields() as $field => $flag) {
|
|
| 588 | 588 | $this->encodeField($field, true); |
| 589 | 589 | } |
| 590 | 590 | return $this; |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | final public function escape($value){
|
| 67 | 67 | if(!is_scalar($value)){
|
| 68 | 68 | $value = ''; |
| 69 | - }else{
|
|
| 69 | + } else{
|
|
| 70 | 70 | $value = $this->modx->db->escape($value); |
| 71 | 71 | } |
| 72 | 72 | return $value; |
@@ -94,7 +94,9 @@ discard block |
||
| 94 | 94 | final public function list_log($flush = false) |
| 95 | 95 | {
|
| 96 | 96 | echo '<pre>' . print_r(APIHelpers::sanitarTag($this->log), true) . '</pre>'; |
| 97 | - if ($flush) $this->clearLog(); |
|
| 97 | + if ($flush) {
|
|
| 98 | + $this->clearLog(); |
|
| 99 | + } |
|
| 98 | 100 | return $this; |
| 99 | 101 | } |
| 100 | 102 | |
@@ -118,7 +120,7 @@ discard block |
||
| 118 | 120 | $sync->setCachepath($path); |
| 119 | 121 | $sync->setReport(false); |
| 120 | 122 | $sync->emptyCache(); |
| 121 | - }else {
|
|
| 123 | + } else {
|
|
| 122 | 124 | if(is_scalar($custom)){
|
| 123 | 125 | $custom = array($custom); |
| 124 | 126 | } |
@@ -207,7 +209,9 @@ discard block |
||
| 207 | 209 | try {
|
| 208 | 210 | if ($this->issetField($key) && is_scalar($this->field[$key])) {
|
| 209 | 211 | $tmp = "`{$key}`='{$this->escape($this->field[$key])}'";
|
| 210 | - } else throw new Exception("{$key} is invalid <pre>" . print_r($this->field[$key], true) . "</pre>");
|
|
| 212 | + } else {
|
|
| 213 | + throw new Exception("{$key} is invalid <pre>" . print_r($this->field[$key], true) . "</pre>");
|
|
| 214 | + } |
|
| 211 | 215 | } catch (Exception $e) {
|
| 212 | 216 | die($e->getMessage()); |
| 213 | 217 | } |
@@ -256,18 +260,24 @@ discard block |
||
| 256 | 260 | {
|
| 257 | 261 | if (is_scalar($data) && !empty($data)) {
|
| 258 | 262 | $json = json_decode($data); |
| 259 | - } else throw new Exception("json is not string with json data");
|
|
| 263 | + } else {
|
|
| 264 | + throw new Exception("json is not string with json data");
|
|
| 265 | + } |
|
| 260 | 266 | |
| 261 | 267 | if ($this->jsonError($json)) {
|
| 262 | 268 | if (isset($callback) && is_callable($callback)) {
|
| 263 | 269 | call_user_func_array($callback, array($json)); |
| 264 | 270 | } else {
|
| 265 | - if (isset($callback)) throw new Exception("Can't call callback JSON unpack <pre>" . print_r($callback, 1) . "</pre>");
|
|
| 271 | + if (isset($callback)) {
|
|
| 272 | + throw new Exception("Can't call callback JSON unpack <pre>" . print_r($callback, 1) . "</pre>");
|
|
| 273 | + } |
|
| 266 | 274 | foreach ($json as $key => $val) {
|
| 267 | 275 | $this->set($key, $val); |
| 268 | 276 | } |
| 269 | 277 | } |
| 270 | - } else throw new Exception('Error from JSON decode: <pre>' . print_r($data, 1) . '</pre>');
|
|
| 278 | + } else {
|
|
| 279 | + throw new Exception('Error from JSON decode: <pre>' . print_r($data, 1) . '</pre>');
|
|
| 280 | + } |
|
| 271 | 281 | |
| 272 | 282 | return $this; |
| 273 | 283 | } |
@@ -278,7 +288,9 @@ discard block |
||
| 278 | 288 | if (isset($callback) && is_callable($callback)) {
|
| 279 | 289 | $data = call_user_func_array($callback, array($data)); |
| 280 | 290 | } else {
|
| 281 | - if (isset($callback)) throw new Exception("Can't call callback JSON pre pack <pre>" . print_r($callback, 1) . "</pre>");
|
|
| 291 | + if (isset($callback)) {
|
|
| 292 | + throw new Exception("Can't call callback JSON pre pack <pre>" . print_r($callback, 1) . "</pre>");
|
|
| 293 | + } |
|
| 282 | 294 | } |
| 283 | 295 | $json = json_encode($data); |
| 284 | 296 | |