| @@ -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 | 
| @@ -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 | } | 
| @@ -17,10 +17,10 @@ discard block | ||
| 17 | 17 |  			list(, $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; | 
| @@ -217,7 +217,7 @@ discard block | ||
| 217 | 217 | */ | 
| 218 | 218 | function get_user_ip($out = '127.0.0.1') | 
| 219 | 219 |  	{ | 
| 220 | -		$_getEnv = function ($data) { | |
| 220 | +		$_getEnv = function($data) { | |
| 221 | 221 |  			switch (true) { | 
| 222 | 222 | case (isset($_SERVER[$data])): | 
| 223 | 223 | $out = $_SERVER[$data]; | 
| @@ -357,7 +357,7 @@ discard block | ||
| 357 | 357 | $output .= fgets($conn, 128); | 
| 358 | 358 | } | 
| 359 | 359 | fclose($conn); | 
| 360 | -		} else { | |
| 360 | +		}else { | |
| 361 | 361 |  			throw new ErrorException('Could not connect to ' . $nic_server . '!'); | 
| 362 | 362 | } | 
| 363 | 363 | |
| @@ -438,7 +438,7 @@ discard block | ||
| 438 | 438 | function image_size($image, $mode = null) | 
| 439 | 439 |  	{ | 
| 440 | 440 | $width = $height = 0; | 
| 441 | -		if(is_scalar($image) && is_file($image)){ | |
| 441 | +		if (is_scalar($image) && is_file($image)) { | |
| 442 | 442 | $size = @getimagesize($image); | 
| 443 | 443 | $width = isset($size[0]) ? $size[0] : 0; | 
| 444 | 444 | $height = isset($size[1]) ? $size[1] : 0; | 
| @@ -477,7 +477,7 @@ discard block | ||
| 477 | 477 | } | 
| 478 | 478 | } | 
| 479 | 479 | |
| 480 | -if(!function_exists('validate_date')){ | |
| 480 | +if (!function_exists('validate_date')) { | |
| 481 | 481 | /** | 
| 482 | 482 | * Проверка валидности даты | 
| 483 | 483 | * | 
| @@ -493,13 +493,13 @@ discard block | ||
| 493 | 493 | * @param Closure $validator метод для дополнительной проверки даты | 
| 494 | 494 | * @return null|string | 
| 495 | 495 | */ | 
| 496 | -	function validate_date($date, $fromFormat='Y-m-d', $toFormat = 'Y-m-d', Closure $validator = null){ | |
| 496 | +	function validate_date($date, $fromFormat = 'Y-m-d', $toFormat = 'Y-m-d', Closure $validator = null) { | |
| 497 | 497 | $validTime = false; | 
| 498 | 498 | $datetime2 = null; | 
| 499 | -		if(is_scalar($date)){ | |
| 499 | +		if (is_scalar($date)) { | |
| 500 | 500 |  			$datetime1 = new \DateTime("NOW"); | 
| 501 | 501 | $datetime2 = \DateTime::createFromFormat($fromFormat, $date); | 
| 502 | -			if($datetime2 instanceof \DateTime){ | |
| 502 | +			if ($datetime2 instanceof \DateTime) { | |
| 503 | 503 | $interval = $datetime1->diff($datetime2); | 
| 504 | 504 | $validTime = is_callable($validator) ? (bool)$validator($datetime2, $interval) : true; | 
| 505 | 505 | } | 
| @@ -507,7 +507,7 @@ discard block | ||
| 507 | 507 | return $validTime ? $datetime2->format($toFormat) : null; | 
| 508 | 508 | } | 
| 509 | 509 | } | 
| 510 | -if(!function_exists('format_bytes')){ | |
| 510 | +if (!function_exists('format_bytes')) { | |
| 511 | 511 | /** | 
| 512 | 512 | * Преобразование из байт в другие порядки (кило, мега, гига) с добавлением префикса | 
| 513 | 513 | * | 
| @@ -518,23 +518,23 @@ discard block | ||
| 518 | 518 | */ | 
| 519 | 519 |  	function format_bytes($bytes, $precision = 2, $suffixes = array('Байт', 'Кбайт', 'Мбайт', 'Гбайт', 'Тбайт')) { | 
| 520 | 520 | $bytes = (float)$bytes; | 
| 521 | - if(empty($bytes)) return 0; | |
| 521 | + if (empty($bytes)) return 0; | |
| 522 | 522 | $base = log($bytes, 1024); | 
| 523 | - return trim(round(pow(1024, $base - floor($base)), $precision) . ' ' .get_key($suffixes, (int)$base, '', 'is_scalar')); | |
| 523 | + return trim(round(pow(1024, $base - floor($base)), $precision) . ' ' . get_key($suffixes, (int)$base, '', 'is_scalar')); | |
| 524 | 524 | } | 
| 525 | 525 | } | 
| 526 | 526 | |
| 527 | -if(!function_exists('format_microtime')){ | |
| 527 | +if (!function_exists('format_microtime')) { | |
| 528 | 528 | /** | 
| 529 | 529 | * Форматирование microtime времени | 
| 530 | 530 | * @param string $time microtime время | 
| 531 | 531 | * @param int $len Кол-во символов после точки | 
| 532 | 532 | */ | 
| 533 | -	function format_microtime($time, $len = 4){ | |
| 534 | -		return sprintf("%.".(int)$len."f", $time); | |
| 533 | +	function format_microtime($time, $len = 4) { | |
| 534 | +		return sprintf("%." . (int)$len . "f", $time); | |
| 535 | 535 | } | 
| 536 | 536 | } | 
| 537 | -if(!function_exists('ip_in_range')){ | |
| 537 | +if (!function_exists('ip_in_range')) { | |
| 538 | 538 | /** | 
| 539 | 539 | * Входит ли указанный IP в заданный диапазон | 
| 540 | 540 | * | 
| @@ -543,7 +543,7 @@ discard block | ||
| 543 | 543 | * @param string $upper Конечный IP диапазона | 
| 544 | 544 | * @return bool | 
| 545 | 545 | */ | 
| 546 | -	function in_ip_range($ip, $lower, $upper){ | |
| 546 | +	function in_ip_range($ip, $lower, $upper) { | |
| 547 | 547 | return (ip2long($lower) <= ip2long($ip) && ip2long($upper) >= ip2long($ip)) ? TRUE : FALSE; | 
| 548 | 548 | } | 
| 549 | 549 | } | 
| 550 | 550 | \ No newline at end of file | 
| @@ -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; | 
| @@ -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; | 
| @@ -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 | 
| @@ -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 (!empty($_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 (!empty($_para_tags) && array_key_exists($tag, $_para_tags)) return "\r\n\r\n"; | |
| 317 | +				if ($tag === 'br') {
 | |
| 318 | + return "\r\n"; | |
| 319 | + } | |
| 320 | +				if (!empty($_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 (!empty($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 (!empty($allowable_tags)) $_allowable_tags = array_flip($allowable_tags); | |
| 417 | +					if (!empty($allowable_tags)) {
 | |
| 418 | + $_allowable_tags = array_flip($allowable_tags); | |
| 419 | + } | |
| 404 | 420 | |
| 405 | 421 | #парные таги, которые будут восприниматься как параграфы | 
| 406 | - if (!empty($para_tags)) $_para_tags = array_flip($para_tags); | |
| 422 | +					if (!empty($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 |