@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * @param string $key ключ массива |
| 38 | 38 | * @param mixed $default null значение по умолчанию |
| 39 | 39 | * @param Closure $validate null функция дополнительной валидации значения (должна возвращать true или false) |
| 40 | - * @return mixed |
|
| 40 | + * @return string |
|
| 41 | 41 | */ |
| 42 | 42 | function get_key($data, $key, $default = null, $validate = null) |
| 43 | 43 | { |
@@ -324,7 +324,6 @@ discard block |
||
| 324 | 324 | /** |
| 325 | 325 | * Определить ключи массива равыне значениям |
| 326 | 326 | * |
| 327 | - * @param array $array исходный массив со значениями |
|
| 328 | 327 | * @return array |
| 329 | 328 | */ |
| 330 | 329 | function array_copy_key(array $data = array()){ |
@@ -341,7 +340,7 @@ discard block |
||
| 341 | 340 | * @see http://gostash.it/ru/users/3191 |
| 342 | 341 | * |
| 343 | 342 | * @param array $tree flat data, implementing a id/parent id (adjacency list) structure |
| 344 | - * @param mixed $pid root id, node to return |
|
| 343 | + * @param integer $pid root id, node to return |
|
| 345 | 344 | * @param string $parent parent id index |
| 346 | 345 | * @param string $key id index |
| 347 | 346 | * @param string $children children index |
@@ -327,12 +327,12 @@ |
||
| 327 | 327 | * @param array $array исходный массив со значениями |
| 328 | 328 | * @return array |
| 329 | 329 | */ |
| 330 | - function array_copy_key(array $data = array()){ |
|
| 330 | + function array_copy_key(array $data = array()){ |
|
| 331 | 331 | $data = array_filter($data, function($val){ |
| 332 | 332 | return is_scalar($val); |
| 333 | 333 | }); |
| 334 | - return array_combine($data, $data); |
|
| 335 | - } |
|
| 334 | + return array_combine($data, $data); |
|
| 335 | + } |
|
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | if(!function_exists('make_tree')){ |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | $workArray = &$workArray[$subKey]; |
| 118 | 118 | } |
| 119 | 119 | } |
| 120 | - } else { |
|
| 120 | + }else { |
|
| 121 | 121 | $out = $data; |
| 122 | 122 | } |
| 123 | 123 | } |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | { |
| 185 | 185 | $out = array(); |
| 186 | 186 | foreach ($data as $k => $v) { |
| 187 | - if (is_callable($filter) && $filter($v, $k)){ |
|
| 187 | + if (is_callable($filter) && $filter($v, $k)) { |
|
| 188 | 188 | $out[$k] = $v; |
| 189 | 189 | } |
| 190 | 190 | } |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | { |
| 207 | 207 | $path = explode($separator, $path); |
| 208 | 208 | while ($key = array_shift($path)) { |
| 209 | - if (!isset($array[$key])){ |
|
| 209 | + if (!isset($array[$key])) { |
|
| 210 | 210 | return $default; |
| 211 | 211 | } |
| 212 | 212 | $array = $array[$key]; |
@@ -274,14 +274,14 @@ discard block |
||
| 274 | 274 | } |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | -if( !function_exists('array_shuffle')){ |
|
| 277 | +if (!function_exists('array_shuffle')) { |
|
| 278 | 278 | /** |
| 279 | 279 | * Перемешать массив в случайном порядке с сохранением ключей |
| 280 | 280 | * |
| 281 | 281 | * @param array $data массив с данными |
| 282 | 282 | * @return bool результат сортировки массива |
| 283 | 283 | */ |
| 284 | - function array_shuffle(array &$data = array()){ |
|
| 284 | + function array_shuffle(array &$data = array()) { |
|
| 285 | 285 | return uksort($data, function() { return rand() > rand(); }); |
| 286 | 286 | } |
| 287 | 287 | } |
@@ -301,14 +301,14 @@ discard block |
||
| 301 | 301 | if ((int)$count > 0) { |
| 302 | 302 | $data = current(array_chunk($data, (int)$count, true)); |
| 303 | 303 | } |
| 304 | - } else { |
|
| 304 | + }else { |
|
| 305 | 305 | $data = array(); |
| 306 | 306 | } |
| 307 | 307 | return $data; |
| 308 | 308 | } |
| 309 | 309 | } |
| 310 | 310 | |
| 311 | -if(!function_exists('is_assoc')){ |
|
| 311 | +if (!function_exists('is_assoc')) { |
|
| 312 | 312 | /** |
| 313 | 313 | * Является ли массив ассоциативным |
| 314 | 314 | * |
@@ -320,22 +320,22 @@ discard block |
||
| 320 | 320 | } |
| 321 | 321 | } |
| 322 | 322 | |
| 323 | -if(!function_exists('array_copy_key')){ |
|
| 323 | +if (!function_exists('array_copy_key')) { |
|
| 324 | 324 | /** |
| 325 | 325 | * Определить ключи массива равыне значениям |
| 326 | 326 | * |
| 327 | 327 | * @param array $array исходный массив со значениями |
| 328 | 328 | * @return array |
| 329 | 329 | */ |
| 330 | - function array_copy_key(array $data = array()){ |
|
| 331 | - $data = array_filter($data, function($val){ |
|
| 330 | + function array_copy_key(array $data = array()) { |
|
| 331 | + $data = array_filter($data, function($val) { |
|
| 332 | 332 | return is_scalar($val); |
| 333 | 333 | }); |
| 334 | 334 | return array_combine($data, $data); |
| 335 | 335 | } |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | -if(!function_exists('make_tree')){ |
|
| 338 | +if (!function_exists('make_tree')) { |
|
| 339 | 339 | /** |
| 340 | 340 | * Helper function |
| 341 | 341 | * @see http://gostash.it/ru/users/3191 |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | } |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | -if(!function_exists('array_chunk_vcolumn')){ |
|
| 373 | +if (!function_exists('array_chunk_vcolumn')) { |
|
| 374 | 374 | /** |
| 375 | 375 | * Разбиение массива на несколько частей с сохранением ключей, чтобы в каждой из этих частей было равное кол-во элементов |
| 376 | 376 | * Массив наполняется последовательно. Т.е. сначала наполняется данными первая часть, потом вторая и так, пока не закончатся данные. |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | * @param array $input исходный массив |
| 380 | 380 | * @param int $size кол-во частей |
| 381 | 381 | */ |
| 382 | - function array_chunk_vcolumn(array $input, $size){ |
|
| 382 | + function array_chunk_vcolumn(array $input, $size) { |
|
| 383 | 383 | $data = array_fill(0, $size, array()); |
| 384 | 384 | $size = ceil(count($input) / $size); |
| 385 | 385 | $i = 0; |
@@ -397,7 +397,7 @@ discard block |
||
| 397 | 397 | } |
| 398 | 398 | } |
| 399 | 399 | |
| 400 | -if(!function_exists('array_chunk_hcolumn')){ |
|
| 400 | +if (!function_exists('array_chunk_hcolumn')) { |
|
| 401 | 401 | /** |
| 402 | 402 | * Разбиение массива на несколько частей с сохранением ключей, чтобы в каждой из этих частей было равное кол-во элементов |
| 403 | 403 | * Массив наполняется равномерно. Т.е. в первую строку каждой части складывается по одному элементу из массива. Затем аналогичным образом во вторую и так, пока не закончатся данные. |
@@ -405,12 +405,12 @@ discard block |
||
| 405 | 405 | * @param array $input исходный массив |
| 406 | 406 | * @param int $size кол-во частей |
| 407 | 407 | */ |
| 408 | - function array_chunk_hcolumn(array $input, $size){ |
|
| 408 | + function array_chunk_hcolumn(array $input, $size) { |
|
| 409 | 409 | $data = array_fill(0, $size, array()); |
| 410 | 410 | $j = -1; |
| 411 | 411 | foreach ($input as $k => $v) |
| 412 | 412 | { |
| 413 | - if (++$j >= $size){ |
|
| 413 | + if (++$j >= $size) { |
|
| 414 | 414 | $j = 0; |
| 415 | 415 | } |
| 416 | 416 | $data[$j][$k] = $v; |
@@ -419,21 +419,21 @@ discard block |
||
| 419 | 419 | } |
| 420 | 420 | } |
| 421 | 421 | |
| 422 | -if(!function_exists('array_filter_keys')){ |
|
| 422 | +if (!function_exists('array_filter_keys')) { |
|
| 423 | 423 | /** |
| 424 | 424 | * Фильтрация массива по ключу |
| 425 | 425 | * |
| 426 | 426 | * @param array $array исходный массив |
| 427 | 427 | * @param string $needle регулярное выражение для фильтрации ключей |
| 428 | 428 | */ |
| 429 | - function array_filter_keys($array, $needle){ |
|
| 429 | + function array_filter_keys($array, $needle) { |
|
| 430 | 430 | $matchedKeys = array_filter(array_keys($array), function($key) use ($needle){ |
| 431 | 431 | return preg_match($needle, $key); |
| 432 | 432 | }); |
| 433 | 433 | return array_intersect_key($array, array_flip($matchedKeys)); |
| 434 | 434 | } |
| 435 | 435 | } |
| 436 | -if(!function_exists('choose_chance')){ |
|
| 436 | +if (!function_exists('choose_chance')) { |
|
| 437 | 437 | /*** |
| 438 | 438 | * Выбор ключа массива со определенной вероятность |
| 439 | 439 | * choose_chance(array("a" => 10, "b" => 25, "c" => 25, "d" => 40)); |
@@ -441,7 +441,7 @@ discard block |
||
| 441 | 441 | * @see: http://gostash.it/ru/stashes/381 |
| 442 | 442 | * @param array $arr исходный массив |
| 443 | 443 | */ |
| 444 | - function choose_chance(array $arr){ |
|
| 444 | + function choose_chance(array $arr) { |
|
| 445 | 445 | $rnd = mt_rand(1, array_sum($arr)); |
| 446 | 446 | $i = 0; |
| 447 | 447 | foreach ($arr as $value => $chance) { |
@@ -230,7 +230,9 @@ discard block |
||
| 230 | 230 | $path = explode($separator, $path); |
| 231 | 231 | while (count($path) > 1) { |
| 232 | 232 | $key = array_shift($path); |
| 233 | - if (!isset($tmp[$key])) return; |
|
| 233 | + if (!isset($tmp[$key])) {
|
|
| 234 | + return; |
|
| 235 | + } |
|
| 234 | 236 | $tmp = &$tmp[$key]; |
| 235 | 237 | } |
| 236 | 238 | unset($tmp[array_shift($path)]); |
@@ -253,7 +255,9 @@ discard block |
||
| 253 | 255 | $path = explode($separator, $path); |
| 254 | 256 | while (count($path) > 1) { |
| 255 | 257 | $key = array_shift($path); |
| 256 | - if (!isset($tmp[$key])) $tmp[$key] = array(); |
|
| 258 | + if (!isset($tmp[$key])) {
|
|
| 259 | + $tmp[$key] = array(); |
|
| 260 | + } |
|
| 257 | 261 | $tmp = &$tmp[$key]; |
| 258 | 262 | } |
| 259 | 263 | $tmp[array_shift($path)] = $value; |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * Заменить множественную последовательность пробелов и табуляций на 1 пробел |
| 39 | 39 | * |
| 40 | 40 | * @param mixed $data строка или массив |
| 41 | - * @return mixed |
|
| 41 | + * @return string|null |
|
| 42 | 42 | */ |
| 43 | 43 | function one_space($data) |
| 44 | 44 | { |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | * |
| 101 | 101 | * @param mixed $data |
| 102 | 102 | * @param string $charset кодировка |
| 103 | - * @return mixed |
|
| 103 | + * @return string |
|
| 104 | 104 | */ |
| 105 | 105 | function e($data, $charset = 'UTF-8') |
| 106 | 106 | { |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | */ |
| 10 | 10 | function mb_lcfirst($data, $charset = 'UTF-8') |
| 11 | 11 | { |
| 12 | - return for_all($data, function ($el) use ($charset) { |
|
| 12 | + return for_all($data, function($el) use ($charset) { |
|
| 13 | 13 | $str = one_space($el); |
| 14 | 14 | return mb_strtolower(mb_substr($str, 0, 1, $charset), $charset) . mb_substr($str, 1, mb_strlen($str), $charset); |
| 15 | 15 | }); |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | function mb_ucfirst($data, $charset = 'UTF-8') |
| 28 | 28 | { |
| 29 | - return for_all($data, function ($el) use ($charset) { |
|
| 29 | + return for_all($data, function($el) use ($charset) { |
|
| 30 | 30 | $str = one_space($el); |
| 31 | 31 | return mb_strtoupper(mb_substr($str, 0, 1, $charset), $charset) . mb_substr($str, 1, mb_strlen($str), $charset); |
| 32 | 32 | }); |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | function one_space($data) |
| 44 | 44 | { |
| 45 | - return for_all($data, function ($el) { |
|
| 45 | + return for_all($data, function($el) { |
|
| 46 | 46 | return preg_replace('/[ \t]+/', ' ', $el); |
| 47 | 47 | }); |
| 48 | 48 | } |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | function one_new_line($data) |
| 59 | 59 | { |
| 60 | - return for_all($data, function ($el) { |
|
| 60 | + return for_all($data, function($el) { |
|
| 61 | 61 | return preg_replace('/(\R)+/', '$1', $el); |
| 62 | 62 | }); |
| 63 | 63 | } |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | function full_one_space($data) |
| 74 | 74 | { |
| 75 | - return for_all($data, function ($el) { |
|
| 75 | + return for_all($data, function($el) { |
|
| 76 | 76 | return preg_replace('/\s+/', ' ', $el); |
| 77 | 77 | }); |
| 78 | 78 | } |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | function e_decode($data, $charset = 'UTF-8') |
| 90 | 90 | { |
| 91 | - return for_all($data, function ($el) use ($charset) { |
|
| 91 | + return for_all($data, function($el) use ($charset) { |
|
| 92 | 92 | return one_space(str_replace("\xC2\xA0", ' ', html_entity_decode($el, ENT_COMPAT, $charset))); |
| 93 | 93 | }); |
| 94 | 94 | } |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | function e($data, $charset = 'UTF-8') |
| 106 | 106 | { |
| 107 | - return for_all($data, function ($el) use ($charset) { |
|
| 107 | + return for_all($data, function($el) use ($charset) { |
|
| 108 | 108 | return one_space(htmlentities($el, ENT_COMPAT | ENT_SUBSTITUTE, $charset, false)); |
| 109 | 109 | }); |
| 110 | 110 | } |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | $count += count($parts) - 1; |
| 206 | 206 | $subject = implode($replacements[$key], $parts); |
| 207 | 207 | } |
| 208 | - } else { |
|
| 208 | + }else { |
|
| 209 | 209 | // Call mb_str_replace for each subject in array, recursively |
| 210 | 210 | foreach ($subject as $key => $value) { |
| 211 | 211 | $subject[$key] = mb_str_replace($search, $replace, $value, $count); |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | $text = mb_substr($text, 0, $len + 1, $encoding); |
| 232 | 232 | if (mb_substr($text, -1, null, $encoding) == ' ') { |
| 233 | 233 | $out = trim($text); |
| 234 | - } else { |
|
| 234 | + }else { |
|
| 235 | 235 | $out = mb_substr($text, 0, mb_strripos($text, ' ', null, $encoding), $encoding); |
| 236 | 236 | } |
| 237 | 237 | return preg_replace("/(([\.,\-:!?;\s])|(&\w+;))+$/ui", "", $out); |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | ~sxSX'; |
| 335 | 335 | |
| 336 | 336 | $patterns = array( |
| 337 | - '/<([\?\%]) .*? \\1>/sxSX', #встроенный PHP, Perl, ASP код |
|
| 337 | + '/<([\?\%]) .*? \\1>/sxSX', #встроенный PHP, Perl, ASP код |
|
| 338 | 338 | '/<\!\[CDATA\[ .*? \]\]>/sxSX', #блоки CDATA |
| 339 | 339 | #'/<\!\[ [\x20\r\n\t]* [a-zA-Z] .*? \]>/sxSX', #:DEPRECATED: MS Word таги типа <![if! vml]>...<![endif]> |
| 340 | 340 | |
@@ -299,26 +299,38 @@ discard block |
||
| 299 | 299 | $tag = strtolower($s[1]); |
| 300 | 300 | if ($_allowable_tags) { |
| 301 | 301 | #tag with attributes |
| 302 | - if (array_key_exists($tag, $_allowable_tags)) return $s[0]; |
|
| 302 | + if (array_key_exists($tag, $_allowable_tags)) {
|
|
| 303 | + return $s[0]; |
|
| 304 | + } |
|
| 303 | 305 | |
| 304 | 306 | #tag without attributes |
| 305 | 307 | if (array_key_exists('<' . $tag . '>', $_allowable_tags)) { |
| 306 | - if (substr($s[0], 0, 2) === '</') return '</' . $tag . '>'; |
|
| 307 | - if (substr($s[0], -2) === '/>') return '<' . $tag . ' />'; |
|
| 308 | + if (substr($s[0], 0, 2) === '</') {
|
|
| 309 | + return '</' . $tag . '>'; |
|
| 310 | + } |
|
| 311 | + if (substr($s[0], -2) === '/>') {
|
|
| 312 | + return '<' . $tag . ' />'; |
|
| 313 | + } |
|
| 308 | 314 | return '<' . $tag . '>'; |
| 309 | 315 | } |
| 310 | 316 | } |
| 311 | - if ($tag === 'br') return "\r\n"; |
|
| 312 | - if ($_para_tags && array_key_exists($tag, $_para_tags)) return "\r\n\r\n"; |
|
| 317 | + if ($tag === 'br') {
|
|
| 318 | + return "\r\n"; |
|
| 319 | + } |
|
| 320 | + if ($_para_tags && array_key_exists($tag, $_para_tags)) {
|
|
| 321 | + return "\r\n\r\n"; |
|
| 322 | + } |
|
| 313 | 323 | return ''; |
| 314 | 324 | } |
| 315 | 325 | trigger_error('Unknown callback type "' . $_callback_type . '"!', E_USER_ERROR); |
| 316 | 326 | } |
| 317 | 327 | |
| 318 | - if (($pos = strpos($s, '<')) === false || strpos($s, '>', $pos) === false) #speed improve |
|
| 328 | + if (($pos = strpos($s, '<')) === false || strpos($s, '>', $pos) === false) {
|
|
| 329 | + #speed improve |
|
| 319 | 330 | { |
| 320 | 331 | #tags are not found |
| 321 | - return $s; |
|
| 332 | + return $s; |
|
| 333 | + } |
|
| 322 | 334 | } |
| 323 | 335 | |
| 324 | 336 | $length = strlen($s); |
@@ -354,7 +366,9 @@ discard block |
||
| 354 | 366 | ); |
| 355 | 367 | if ($pair_tags) { |
| 356 | 368 | #парные таги вместе с содержимым: |
| 357 | - foreach ($pair_tags as $k => $v) $pair_tags[$k] = preg_quote($v, '/'); |
|
| 369 | + foreach ($pair_tags as $k => $v) {
|
|
| 370 | + $pair_tags[$k] = preg_quote($v, '/'); |
|
| 371 | + } |
|
| 358 | 372 | $patterns[] = '/ <((?i:' . implode('|', $pair_tags) . '))' . $re_attrs_fast_safe . '(?<!\/)> |
| 359 | 373 | .*? |
| 360 | 374 | <\/(?i:\\1)' . $re_attrs_fast_safe . '> |
@@ -400,10 +414,14 @@ discard block |
||
| 400 | 414 | } |
| 401 | 415 | |
| 402 | 416 | #массив тагов, которые не будут вырезаны |
| 403 | - if ($allowable_tags) $_allowable_tags = array_flip($allowable_tags); |
|
| 417 | + if ($allowable_tags) {
|
|
| 418 | + $_allowable_tags = array_flip($allowable_tags); |
|
| 419 | + } |
|
| 404 | 420 | |
| 405 | 421 | #парные таги, которые будут восприниматься как параграфы |
| 406 | - if ($para_tags) $_para_tags = array_flip($para_tags); |
|
| 422 | + if ($para_tags) {
|
|
| 423 | + $_para_tags = array_flip($para_tags); |
|
| 424 | + } |
|
| 407 | 425 | } |
| 408 | 426 | }#if |
| 409 | 427 | |
@@ -418,11 +436,16 @@ discard block |
||
| 418 | 436 | } |
| 419 | 437 | } |
| 420 | 438 | |
| 421 | - if ($s === $s2) break; |
|
| 439 | + if ($s === $s2) {
|
|
| 440 | + break; |
|
| 441 | + } |
|
| 422 | 442 | $s = $s2; |
| 423 | 443 | $i++; |
| 424 | 444 | }#while |
| 425 | - if ($i >= $max) $s = strip_tags($s); #too many cycles for replace... |
|
| 445 | + if ($i >= $max) {
|
|
| 446 | + $s = strip_tags($s); |
|
| 447 | + } |
|
| 448 | + #too many cycles for replace... |
|
| 426 | 449 | |
| 427 | 450 | if ($is_format_spaces && strlen($s) !== $length) { |
| 428 | 451 | #remove a duplicate spaces |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | * |
| 10 | 10 | * @param string $email проверяемый email |
| 11 | 11 | * @param bool $dns проверять ли DNS записи |
| 12 | - * @return bool|string Результат проверки почтового ящика |
|
| 12 | + * @return false|string Результат проверки почтового ящика |
|
| 13 | 13 | */ |
| 14 | 14 | function check_email($email, $dns = true) |
| 15 | 15 | { |
@@ -529,7 +529,7 @@ discard block |
||
| 529 | 529 | * Преобразование из байт в другие порядки (кило, мега, гига) с добавлением префикса |
| 530 | 530 | * |
| 531 | 531 | * @param string $bytes Обрабатываемое число |
| 532 | - * @param string $precision До какого числа после запятой округлять |
|
| 532 | + * @param integer $precision До какого числа после запятой округлять |
|
| 533 | 533 | * @param array $suffixes Массив суффиксов |
| 534 | 534 | * @return string |
| 535 | 535 | */ |
@@ -561,6 +561,6 @@ |
||
| 561 | 561 | * @return bool |
| 562 | 562 | */ |
| 563 | 563 | function in_ip_range($ip, $lower, $upper){ |
| 564 | - return (ip2long($lower) <= ip2long($ip) && ip2long($upper) >= ip2long($ip)) ? TRUE : FALSE; |
|
| 565 | - } |
|
| 564 | + return (ip2long($lower) <= ip2long($ip) && ip2long($upper) >= ip2long($ip)) ? TRUE : FALSE; |
|
| 565 | + } |
|
| 566 | 566 | } |
| 567 | 567 | \ No newline at end of file |
@@ -17,10 +17,10 @@ discard block |
||
| 17 | 17 | list($user, $domain) = explode("@", $email, 2); |
| 18 | 18 | if (!$dns || ($dns && checkdnsrr($domain, "MX") && checkdnsrr($domain, "A"))) { |
| 19 | 19 | $error = false; |
| 20 | - } else { |
|
| 20 | + }else { |
|
| 21 | 21 | $error = 'dns'; |
| 22 | 22 | } |
| 23 | - } else { |
|
| 23 | + }else { |
|
| 24 | 24 | $error = 'format'; |
| 25 | 25 | } |
| 26 | 26 | return $error; |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | */ |
| 222 | 222 | function get_user_ip($out = '127.0.0.1') |
| 223 | 223 | { |
| 224 | - $_getEnv = function ($data) { |
|
| 224 | + $_getEnv = function($data) { |
|
| 225 | 225 | $out = false; |
| 226 | 226 | switch (true) { |
| 227 | 227 | case (isset($_SERVER[$data])): |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | $output .= fgets($conn, 128); |
| 363 | 363 | } |
| 364 | 364 | fclose($conn); |
| 365 | - } else { |
|
| 365 | + }else { |
|
| 366 | 366 | die('Error: Could not connect to ' . $nic_server . '!'); |
| 367 | 367 | } |
| 368 | 368 | |
@@ -384,7 +384,7 @@ discard block |
||
| 384 | 384 | $y = date('Y'); |
| 385 | 385 | if ($y != $year) { |
| 386 | 386 | $out = $year . $sep . $y; |
| 387 | - } else { |
|
| 387 | + }else { |
|
| 388 | 388 | $out = $year; |
| 389 | 389 | } |
| 390 | 390 | return $out; |
@@ -494,7 +494,7 @@ discard block |
||
| 494 | 494 | } |
| 495 | 495 | } |
| 496 | 496 | |
| 497 | -if(!function_exists('validate_date')){ |
|
| 497 | +if (!function_exists('validate_date')) { |
|
| 498 | 498 | /** |
| 499 | 499 | * Проверка валидности даты |
| 500 | 500 | * |
@@ -510,13 +510,13 @@ discard block |
||
| 510 | 510 | * @param Closure $validator метод для дополнительной проверки даты |
| 511 | 511 | * @return null|string |
| 512 | 512 | */ |
| 513 | - function validate_date($date, $fromFormat='Y-m-d', $toFormat = 'Y-m-d', Closure $validator = null){ |
|
| 513 | + function validate_date($date, $fromFormat = 'Y-m-d', $toFormat = 'Y-m-d', Closure $validator = null) { |
|
| 514 | 514 | $validTime = false; |
| 515 | 515 | $datetime1 = $datetime2 = $interval = null; |
| 516 | - if(is_scalar($date)){ |
|
| 516 | + if (is_scalar($date)) { |
|
| 517 | 517 | $datetime1 = new \DateTime("NOW"); |
| 518 | 518 | $datetime2 = \DateTime::createFromFormat($fromFormat, $date); |
| 519 | - if($datetime2 instanceof \DateTime){ |
|
| 519 | + if ($datetime2 instanceof \DateTime) { |
|
| 520 | 520 | $interval = $datetime1->diff($datetime2); |
| 521 | 521 | $validTime = is_callable($validator) ? (bool)$validator($datetime2, $interval) : true; |
| 522 | 522 | } |
@@ -524,7 +524,7 @@ discard block |
||
| 524 | 524 | return $date = $validTime ? $datetime2->format($toFormat) : null; |
| 525 | 525 | } |
| 526 | 526 | } |
| 527 | -if(!function_exists('format_bytes')){ |
|
| 527 | +if (!function_exists('format_bytes')) { |
|
| 528 | 528 | /** |
| 529 | 529 | * Преобразование из байт в другие порядки (кило, мега, гига) с добавлением префикса |
| 530 | 530 | * |
@@ -535,23 +535,23 @@ discard block |
||
| 535 | 535 | */ |
| 536 | 536 | function format_bytes($bytes, $precision = 2, $suffixes = array('Байт', 'Кбайт', 'Мбайт', 'Гбайт', 'Тбайт')) { |
| 537 | 537 | $bytes = (float)$bytes; |
| 538 | - if(empty($bytes)) return 0; |
|
| 538 | + if (empty($bytes)) return 0; |
|
| 539 | 539 | $base = log($bytes, 1024); |
| 540 | - return trim(round(pow(1024, $base - floor($base)), $precision) . ' ' .get_key($suffixes, (int)$base, '', 'is_scalar')); |
|
| 540 | + return trim(round(pow(1024, $base - floor($base)), $precision) . ' ' . get_key($suffixes, (int)$base, '', 'is_scalar')); |
|
| 541 | 541 | } |
| 542 | 542 | } |
| 543 | 543 | |
| 544 | -if(!function_exists('format_microtime')){ |
|
| 544 | +if (!function_exists('format_microtime')) { |
|
| 545 | 545 | /** |
| 546 | 546 | * Форматирование microtime времени |
| 547 | 547 | * @param string $time microtime время |
| 548 | 548 | * @param int $len Кол-во символов после точки |
| 549 | 549 | */ |
| 550 | - function format_microtime($time, $len = 4){ |
|
| 551 | - return sprintf("%.".(int)$len."f", $time); |
|
| 550 | + function format_microtime($time, $len = 4) { |
|
| 551 | + return sprintf("%." . (int)$len . "f", $time); |
|
| 552 | 552 | } |
| 553 | 553 | } |
| 554 | -if(!function_exists('ip_in_range')){ |
|
| 554 | +if (!function_exists('ip_in_range')) { |
|
| 555 | 555 | /** |
| 556 | 556 | * Входит ли указанный IP в заданный диапазон |
| 557 | 557 | * |
@@ -560,7 +560,7 @@ discard block |
||
| 560 | 560 | * @param string $upper Конечный IP диапазона |
| 561 | 561 | * @return bool |
| 562 | 562 | */ |
| 563 | - function in_ip_range($ip, $lower, $upper){ |
|
| 563 | + function in_ip_range($ip, $lower, $upper) { |
|
| 564 | 564 | return (ip2long($lower) <= ip2long($ip) && ip2long($upper) >= ip2long($ip)) ? TRUE : FALSE; |
| 565 | 565 | } |
| 566 | 566 | } |
| 567 | 567 | \ No newline at end of file |
@@ -535,7 +535,9 @@ |
||
| 535 | 535 | */ |
| 536 | 536 | function format_bytes($bytes, $precision = 2, $suffixes = array('Байт', 'Кбайт', 'Мбайт', 'Гбайт', 'Тбайт')) { |
| 537 | 537 | $bytes = (float)$bytes; |
| 538 | - if(empty($bytes)) return 0; |
|
| 538 | + if(empty($bytes)) {
|
|
| 539 | + return 0; |
|
| 540 | + } |
|
| 539 | 541 | $base = log($bytes, 1024); |
| 540 | 542 | return trim(round(pow(1024, $base - floor($base)), $precision) . ' ' .get_key($suffixes, (int)$base, '', 'is_scalar')); |
| 541 | 543 | } |
@@ -54,12 +54,12 @@ |
||
| 54 | 54 | |
| 55 | 55 | if (!function_exists('sanitize_path')) { |
| 56 | 56 | /** |
| 57 | - * Удаление из строки символов, определяющих перемещение вверх по дереву каталогов |
|
| 58 | - * @see https://github.com/modxcms/revolution/commit/10248d06ebb7c933d33129272623d0a64d528a82#diff-9ec30f895e27297f4307c80efb483bb8 |
|
| 59 | - * |
|
| 60 | - * @param string $path путь к папке |
|
| 61 | - * @return string |
|
| 62 | - */ |
|
| 57 | + * Удаление из строки символов, определяющих перемещение вверх по дереву каталогов |
|
| 58 | + * @see https://github.com/modxcms/revolution/commit/10248d06ebb7c933d33129272623d0a64d528a82#diff-9ec30f895e27297f4307c80efb483bb8 |
|
| 59 | + * |
|
| 60 | + * @param string $path путь к папке |
|
| 61 | + * @return string |
|
| 62 | + */ |
|
| 63 | 63 | function sanitize_path($path ){ |
| 64 | 64 | return preg_replace(array("/\.*[\/|\\\]/i", "/[\/|\\\]+/i"), array('/', '/'), $path); |
| 65 | 65 | } |
@@ -60,7 +60,7 @@ |
||
| 60 | 60 | * @param string $path путь к папке |
| 61 | 61 | * @return string |
| 62 | 62 | */ |
| 63 | - function sanitize_path($path ){ |
|
| 63 | + function sanitize_path($path) { |
|
| 64 | 64 | return preg_replace(array("/\.*[\/|\\\]/i", "/[\/|\\\]+/i"), array('/', '/'), $path); |
| 65 | 65 | } |
| 66 | 66 | } |
| 67 | 67 | \ No newline at end of file |
@@ -23,14 +23,14 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | function plus_minus($num, $plus = '+', $minus = '-') |
| 25 | 25 | {
|
| 26 | - if(!is_scalar($num)){
|
|
| 26 | + if (!is_scalar($num)) {
|
|
| 27 | 27 | $num = 0; |
| 28 | 28 | } |
| 29 | - if($num < 0){
|
|
| 29 | + if ($num < 0) {
|
|
| 30 | 30 | $out = $minus . abs($num); |
| 31 | - }else if ($num > 0){
|
|
| 31 | + }else if ($num > 0) {
|
|
| 32 | 32 | $out = $plus . abs($num); |
| 33 | - }else{
|
|
| 33 | + }else {
|
|
| 34 | 34 | $out = 0; |
| 35 | 35 | } |
| 36 | 36 | return $out; |
@@ -62,12 +62,12 @@ discard block |
||
| 62 | 62 | function clean_ids($IDs, $sep = ',', $ignore = array()) |
| 63 | 63 | {
|
| 64 | 64 | $out = array(); |
| 65 | - if ( ! is_array($IDs)) {
|
|
| 65 | + if (!is_array($IDs)) {
|
|
| 66 | 66 | $IDs = is_scalar($IDs) ? explode($sep, $IDs) : array(); |
| 67 | 67 | } |
| 68 | 68 | foreach ($IDs as $item) {
|
| 69 | 69 | $item = trim($item); |
| 70 | - if ((is_scalar($item) && (int)$item >= 0) && (empty($ignore) || !in_array((int)$item, $ignore, true))){
|
|
| 70 | + if ((is_scalar($item) && (int)$item >= 0) && (empty($ignore) || !in_array((int)$item, $ignore, true))) {
|
|
| 71 | 71 | $out[] = (int)$item; |
| 72 | 72 | } |
| 73 | 73 | } |
@@ -28,9 +28,9 @@ |
||
| 28 | 28 | } |
| 29 | 29 | if($num < 0){
|
| 30 | 30 | $out = $minus . abs($num); |
| 31 | - }else if ($num > 0){
|
|
| 31 | + } else if ($num > 0){
|
|
| 32 | 32 | $out = $plus . abs($num); |
| 33 | - }else{
|
|
| 33 | + } else{
|
|
| 34 | 34 | $out = 0; |
| 35 | 35 | } |
| 36 | 36 | return $out; |
@@ -293,11 +293,11 @@ |
||
| 293 | 293 | */ |
| 294 | 294 | function clear_html($html){
|
| 295 | 295 | $filters = array( |
| 296 | - '/<!--([^\[|(<!)].*)-->/i' => '', // Remove HTML Comments (breaks with HTML5 Boilerplate) |
|
| 297 | - '/(?<!\S)\/\/\s*[^\r\n]*/' => '', // Remove comments in the form /* */ |
|
| 298 | - '/\s{2,}/' => ' ', // Shorten multiple white spaces
|
|
| 299 | - '/(\r?\n)/' => '', // Collapse new lines |
|
| 300 | - ); |
|
| 296 | + '/<!--([^\[|(<!)].*)-->/i' => '', // Remove HTML Comments (breaks with HTML5 Boilerplate) |
|
| 297 | + '/(?<!\S)\/\/\s*[^\r\n]*/' => '', // Remove comments in the form /* */ |
|
| 298 | + '/\s{2,}/' => ' ', // Shorten multiple white spaces
|
|
| 299 | + '/(\r?\n)/' => '', // Collapse new lines |
|
| 300 | + ); |
|
| 301 | 301 | return is_scalar($html) ? preg_replace(array_keys($filters), array_values($filters), $html) : ''; |
| 302 | 302 | } |
| 303 | 303 | } |
| 304 | 304 | \ No newline at end of file |
@@ -28,13 +28,13 @@ discard block |
||
| 28 | 28 | $thead = $table['head']; |
| 29 | 29 | } elseif (is_array($table)) {
|
| 30 | 30 | $thead = html_implode($table, 'th'); |
| 31 | - } else {
|
|
| 31 | + }else {
|
|
| 32 | 32 | $thead = $table; |
| 33 | 33 | } |
| 34 | - if(!empty($thead)){
|
|
| 34 | + if (!empty($thead)) {
|
|
| 35 | 35 | $thead = html_wrap('thead', html_wrap('tr', $thead));
|
| 36 | 36 | } |
| 37 | - return html_wrap('table', $thead.html_wrap('tbody', (is_array($rows) ? html_implode($rows, 'tr') : $rows)), $attr);
|
|
| 37 | + return html_wrap('table', $thead . html_wrap('tbody', (is_array($rows) ? html_implode($rows, 'tr') : $rows)), $attr);
|
|
| 38 | 38 | } |
| 39 | 39 | } |
| 40 | 40 | |
@@ -77,17 +77,17 @@ discard block |
||
| 77 | 77 | * @param array $noEscape имена аттрибутов, значения которых не следует экранировать |
| 78 | 78 | * @return string |
| 79 | 79 | */ |
| 80 | - function html_attrs($attr, $noEscape = array('href', 'src')){
|
|
| 80 | + function html_attrs($attr, $noEscape = array('href', 'src')) {
|
|
| 81 | 81 | $html = ''; |
| 82 | 82 | if (is_array($attr)) {
|
| 83 | 83 | foreach ($attr as $key => $val) {
|
| 84 | - switch(true){
|
|
| 84 | + switch (true) {
|
|
| 85 | 85 | case (is_scalar($val) && is_scalar($key)):{
|
| 86 | 86 | $html .= ' ' . $key . '="' . (in_array($key, $noEscape) ? $val : e($val)) . '"'; |
| 87 | 87 | break; |
| 88 | 88 | } |
| 89 | 89 | case (is_bool($val) && $val == true && is_scalar($key)):{
|
| 90 | - $html .= ' '.$key; |
|
| 90 | + $html .= ' ' . $key; |
|
| 91 | 91 | break; |
| 92 | 92 | } |
| 93 | 93 | } |
@@ -120,20 +120,20 @@ discard block |
||
| 120 | 120 | ); |
| 121 | 121 | } |
| 122 | 122 | $val = get_key($value, 'value', ''); |
| 123 | - if(is_int($title)){
|
|
| 123 | + if (is_int($title)) {
|
|
| 124 | 124 | $title = get_key($value, 'value', $title); |
| 125 | 125 | } |
| 126 | 126 | if ((string)$val === (string)$current) {
|
| 127 | 127 | $value['selected'] = true; |
| 128 | 128 | $selected = true; |
| 129 | - }else{
|
|
| 129 | + }else {
|
|
| 130 | 130 | unset($value['selected']); |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | $options[$title] = $value; |
| 134 | 134 | } |
| 135 | - foreach($options as $title => $attr){
|
|
| 136 | - if(!$selected && get_key($attr, 'value', '') == $default){
|
|
| 135 | + foreach ($options as $title => $attr) {
|
|
| 136 | + if (!$selected && get_key($attr, 'value', '') == $default) {
|
|
| 137 | 137 | $attr['selected'] = true; |
| 138 | 138 | } |
| 139 | 139 | $out .= html_wrap('option', $title, $attr);
|
@@ -271,12 +271,12 @@ discard block |
||
| 271 | 271 | $subText = substr($m[2], 0, $subTmp[1]) . $closeTag; |
| 272 | 272 | $html = substr($m[2], $subTmp[1] + strlen($closeTag)); |
| 273 | 273 | $replace[] = array($m[1], $subText, $closeTag); |
| 274 | - } else {
|
|
| 274 | + }else {
|
|
| 275 | 275 | $replace[] = array($m[1], $m[2], ''); |
| 276 | 276 | $html = ''; |
| 277 | 277 | } |
| 278 | 278 | } |
| 279 | - } else {
|
|
| 279 | + }else {
|
|
| 280 | 280 | $html = ''; |
| 281 | 281 | } |
| 282 | 282 | } while (!empty($html)); |
@@ -284,14 +284,14 @@ discard block |
||
| 284 | 284 | } |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | -if (!function_exists('clear_html')){
|
|
| 287 | +if (!function_exists('clear_html')) {
|
|
| 288 | 288 | /** |
| 289 | 289 | * Удаление комментариев, переносов и лишних пробелов из html строки |
| 290 | 290 | * |
| 291 | 291 | * @param string $html HTML текст |
| 292 | 292 | * @return string |
| 293 | 293 | */ |
| 294 | - function clear_html($html){
|
|
| 294 | + function clear_html($html) {
|
|
| 295 | 295 | $filters = array( |
| 296 | 296 | '/<!--([^\[|(<!)].*)-->/i' => '', // Remove HTML Comments (breaks with HTML5 Boilerplate) |
| 297 | 297 | '/(?<!\S)\/\/\s*[^\r\n]*/' => '', // Remove comments in the form /* */ |
@@ -126,7 +126,7 @@ |
||
| 126 | 126 | if ((string)$val === (string)$current) {
|
| 127 | 127 | $value['selected'] = true; |
| 128 | 128 | $selected = true; |
| 129 | - }else{
|
|
| 129 | + } else{
|
|
| 130 | 130 | unset($value['selected']); |
| 131 | 131 | } |
| 132 | 132 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | function dd() |
| 36 | 36 | { |
| 37 | 37 | ob_clean(); |
| 38 | - array_map(function ($x) { |
|
| 38 | + array_map(function($x) { |
|
| 39 | 39 | var_dump($x); |
| 40 | 40 | }, func_get_args()); |
| 41 | 41 | die; |
@@ -82,24 +82,24 @@ discard block |
||
| 82 | 82 | return html_wrap('pre', e(print_r($html, 1))); |
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | -if (!function_exists('point_info')){ |
|
| 85 | +if (!function_exists('point_info')) { |
|
| 86 | 86 | /** |
| 87 | 87 | * Информация о ресурсах потребляемых на каком-то участке кода |
| 88 | 88 | * @param string $key Имя метки |
| 89 | 89 | * @param bool $store Необходимо ли сохранить информацию о метке в памяти |
| 90 | 90 | * @param bool $clear Нужно ли выполнить сброс меток |
| 91 | 91 | */ |
| 92 | - function point_info($key, $store = false, $clear = false){ |
|
| 92 | + function point_info($key, $store = false, $clear = false) { |
|
| 93 | 93 | static $marks = array(); |
| 94 | - if(is_scalar($key) && !empty($key)){ |
|
| 95 | - if($store){ |
|
| 94 | + if (is_scalar($key) && !empty($key)) { |
|
| 95 | + if ($store) { |
|
| 96 | 96 | $marks[$key] = array( |
| 97 | 97 | 'time' => microtime(true), |
| 98 | 98 | 'memory' => memory_get_usage() |
| 99 | 99 | ); |
| 100 | 100 | $out['time'] = format_microtime($marks[$key]['time']); |
| 101 | 101 | $out = format_bytes($marks[$key]['memory']); |
| 102 | - }else{ |
|
| 102 | + }else { |
|
| 103 | 103 | $out = get_key($marks, $key, array( |
| 104 | 104 | 'time' => get_key($_SERVER, 'REQUEST_TIME_FLOAT', 0), |
| 105 | 105 | 'memory'=> 0 |
@@ -109,14 +109,14 @@ discard block |
||
| 109 | 109 | } |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - if($clear){ |
|
| 112 | + if ($clear) { |
|
| 113 | 113 | $marks = array(); |
| 114 | 114 | } |
| 115 | 115 | return $out; |
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | -if(!function_exists('call_private_method')){ |
|
| 119 | +if (!function_exists('call_private_method')) { |
|
| 120 | 120 | /** |
| 121 | 121 | * Возможность вызвать любой метод (даже приватный) |
| 122 | 122 | * call_private_method($myObject, 'myMethod', array('myValue1', 'myValue2')); |
@@ -99,7 +99,7 @@ |
||
| 99 | 99 | ); |
| 100 | 100 | $out['time'] = format_microtime($marks[$key]['time']); |
| 101 | 101 | $out = format_bytes($marks[$key]['memory']); |
| 102 | - }else{ |
|
| 102 | + } else{ |
|
| 103 | 103 | $out = get_key($marks, $key, array( |
| 104 | 104 | 'time' => get_key($_SERVER, 'REQUEST_TIME_FLOAT', 0), |
| 105 | 105 | 'memory'=> 0 |