@@ -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; |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | */ |
89 | 89 | function get_gravatar($email, $size = 32) |
90 | 90 | { |
91 | - $url = '//www.gravatar.com/avatar/' . md5(is_scalar($email) ? $email : '') . '?s=' . (int)abs($size); |
|
91 | + $url = '//www.gravatar.com/avatar/'.md5(is_scalar($email) ? $email : '').'?s='.(int)abs($size); |
|
92 | 92 | return $url; |
93 | 93 | } |
94 | 94 | } |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | */ |
104 | 104 | function share_vk($url, $title = '') |
105 | 105 | { |
106 | - return 'http://vkontakte.ru/share.php?url=' . urlencode($url) . '&title=' . urlencode($title); |
|
106 | + return 'http://vkontakte.ru/share.php?url='.urlencode($url).'&title='.urlencode($title); |
|
107 | 107 | } |
108 | 108 | } |
109 | 109 | |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | */ |
118 | 118 | function share_ok($url, $title = '') |
119 | 119 | { |
120 | - return 'http://www.odnoklassniki.ru/dk?st.cmd=addShare&st._surl=' . urlencode($url) . '&st.comments=' . urlencode($title); |
|
120 | + return 'http://www.odnoklassniki.ru/dk?st.cmd=addShare&st._surl='.urlencode($url).'&st.comments='.urlencode($title); |
|
121 | 121 | } |
122 | 122 | } |
123 | 123 | |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | */ |
131 | 131 | function share_google($url) |
132 | 132 | { |
133 | - return 'https://plus.google.com/share?url=' . urlencode($url); |
|
133 | + return 'https://plus.google.com/share?url='.urlencode($url); |
|
134 | 134 | } |
135 | 135 | } |
136 | 136 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | */ |
145 | 145 | function share_facebook($url, $title = '') |
146 | 146 | { |
147 | - return 'http://www.facebook.com/sharer/sharer.php?s=100&p[url]=' . urlencode($url) . '&p[title]=' . urlencode($title); |
|
147 | + return 'http://www.facebook.com/sharer/sharer.php?s=100&p[url]='.urlencode($url).'&p[title]='.urlencode($title); |
|
148 | 148 | } |
149 | 149 | } |
150 | 150 | |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | */ |
159 | 159 | function share_twitter($url, $title = '') |
160 | 160 | { |
161 | - return 'https://twitter.com/intent/tweet?url=' . urlencode($url) . '&text=' . urlencode($title); |
|
161 | + return 'https://twitter.com/intent/tweet?url='.urlencode($url).'&text='.urlencode($title); |
|
162 | 162 | } |
163 | 163 | } |
164 | 164 | |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | */ |
173 | 173 | function share_mail($url, $title = '') |
174 | 174 | { |
175 | - return 'http://connect.mail.ru/share?share_url=' . urlencode($url) . '&title=' . urlencode($title); |
|
175 | + return 'http://connect.mail.ru/share?share_url='.urlencode($url).'&title='.urlencode($title); |
|
176 | 176 | } |
177 | 177 | } |
178 | 178 | |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | */ |
187 | 187 | function share_linkedin($url, $title = '') |
188 | 188 | { |
189 | - return 'http://www.linkedin.com/shareArticle?mini=true&url=' . urlencode($url) . '&title=' . urlencode($title); |
|
189 | + return 'http://www.linkedin.com/shareArticle?mini=true&url='.urlencode($url).'&title='.urlencode($title); |
|
190 | 190 | } |
191 | 191 | } |
192 | 192 | |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | { |
203 | 203 | $size = (int)$size; |
204 | 204 | $size = implode("x", array($size, $size)); |
205 | - return '//chart.apis.google.com/chart?cht=qr&chs=' . $size . '&chl=' . (is_scalar($str) ? urlencode($str) : ''); |
|
205 | + return '//chart.apis.google.com/chart?cht=qr&chs='.$size.'&chl='.(is_scalar($str) ? urlencode($str) : ''); |
|
206 | 206 | } |
207 | 207 | } |
208 | 208 | |
@@ -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]; |
@@ -350,13 +350,13 @@ discard block |
||
350 | 350 | |
351 | 351 | // connect to whois server: |
352 | 352 | if ($conn = fsockopen($nic_server, 43)) { |
353 | - fputs($conn, $domain . "\r\n"); |
|
353 | + fputs($conn, $domain."\r\n"); |
|
354 | 354 | while (!feof($conn)) { |
355 | 355 | $output .= fgets($conn, 128); |
356 | 356 | } |
357 | 357 | fclose($conn); |
358 | - } else { |
|
359 | - throw new ErrorException('Could not connect to ' . $nic_server . '!'); |
|
358 | + }else { |
|
359 | + throw new ErrorException('Could not connect to '.$nic_server.'!'); |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | return $output; |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | function copyright($year, $sep = ' - ') |
375 | 375 | { |
376 | 376 | $y = date('Y'); |
377 | - return ($y != $year) ? ($year . $sep . $y) : $year; |
|
377 | + return ($y != $year) ? ($year.$sep.$y) : $year; |
|
378 | 378 | } |
379 | 379 | } |
380 | 380 | |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | function image_size($image, $mode = null) |
437 | 437 | { |
438 | 438 | $width = $height = 0; |
439 | - if(is_scalar($image) && is_file($image)){ |
|
439 | + if (is_scalar($image) && is_file($image)) { |
|
440 | 440 | $size = @getimagesize($image); |
441 | 441 | $width = isset($size[0]) ? $size[0] : 0; |
442 | 442 | $height = isset($size[1]) ? $size[1] : 0; |
@@ -475,7 +475,7 @@ discard block |
||
475 | 475 | } |
476 | 476 | } |
477 | 477 | |
478 | -if(!function_exists('validate_date')){ |
|
478 | +if (!function_exists('validate_date')) { |
|
479 | 479 | /** |
480 | 480 | * Проверка валидности даты |
481 | 481 | * |
@@ -491,13 +491,13 @@ discard block |
||
491 | 491 | * @param Closure $validator метод для дополнительной проверки даты |
492 | 492 | * @return null|string |
493 | 493 | */ |
494 | - function validate_date($date, $fromFormat='Y-m-d', $toFormat = 'Y-m-d', Closure $validator = null){ |
|
494 | + function validate_date($date, $fromFormat = 'Y-m-d', $toFormat = 'Y-m-d', Closure $validator = null) { |
|
495 | 495 | $validTime = false; |
496 | 496 | $datetime2 = null; |
497 | - if(is_scalar($date)){ |
|
497 | + if (is_scalar($date)) { |
|
498 | 498 | $datetime1 = new \DateTime("NOW"); |
499 | 499 | $datetime2 = \DateTime::createFromFormat($fromFormat, $date); |
500 | - if($datetime2 instanceof \DateTime){ |
|
500 | + if ($datetime2 instanceof \DateTime) { |
|
501 | 501 | $interval = $datetime1->diff($datetime2); |
502 | 502 | $validTime = is_callable($validator) ? (bool)$validator($datetime2, $interval) : true; |
503 | 503 | } |
@@ -505,7 +505,7 @@ discard block |
||
505 | 505 | return $validTime ? $datetime2->format($toFormat) : null; |
506 | 506 | } |
507 | 507 | } |
508 | -if(!function_exists('format_bytes')){ |
|
508 | +if (!function_exists('format_bytes')) { |
|
509 | 509 | /** |
510 | 510 | * Преобразование из байт в другие порядки (кило, мега, гига) с добавлением префикса |
511 | 511 | * |
@@ -516,23 +516,23 @@ discard block |
||
516 | 516 | */ |
517 | 517 | function format_bytes($bytes, $precision = 2, $suffixes = array('Байт', 'Кбайт', 'Мбайт', 'Гбайт', 'Тбайт')) { |
518 | 518 | $bytes = (float)$bytes; |
519 | - if(empty($bytes)) return 0; |
|
519 | + if (empty($bytes)) return 0; |
|
520 | 520 | $base = log($bytes, 1024); |
521 | - return trim(round(pow(1024, $base - floor($base)), $precision) . ' ' .get_key($suffixes, (int)$base, '', 'is_scalar')); |
|
521 | + return trim(round(pow(1024, $base - floor($base)), $precision).' '.get_key($suffixes, (int)$base, '', 'is_scalar')); |
|
522 | 522 | } |
523 | 523 | } |
524 | 524 | |
525 | -if(!function_exists('format_microtime')){ |
|
525 | +if (!function_exists('format_microtime')) { |
|
526 | 526 | /** |
527 | 527 | * Форматирование microtime времени |
528 | 528 | * @param string $time microtime время |
529 | 529 | * @param int $len Кол-во символов после точки |
530 | 530 | */ |
531 | - function format_microtime($time, $len = 4){ |
|
531 | + function format_microtime($time, $len = 4) { |
|
532 | 532 | return sprintf("%.".(int)$len."f", $time); |
533 | 533 | } |
534 | 534 | } |
535 | -if(!function_exists('ip_in_range')){ |
|
535 | +if (!function_exists('ip_in_range')) { |
|
536 | 536 | /** |
537 | 537 | * Входит ли указанный IP в заданный диапазон |
538 | 538 | * |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | * @param string $upper Конечный IP диапазона |
542 | 542 | * @return bool |
543 | 543 | */ |
544 | - function in_ip_range($ip, $lower, $upper){ |
|
544 | + function in_ip_range($ip, $lower, $upper) { |
|
545 | 545 | return (ip2long($lower) <= ip2long($ip) && ip2long($upper) >= ip2long($ip)) ? TRUE : FALSE; |
546 | 546 | } |
547 | 547 | } |
548 | 548 | \ 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 |
@@ -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; |
@@ -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){ |
|
30 | - $out = $minus . abs($num); |
|
31 | - }else if ($num > 0){ |
|
32 | - $out = $plus . abs($num); |
|
33 | - }else{ |
|
29 | + if ($num < 0) { |
|
30 | + $out = $minus.abs($num); |
|
31 | + }else if ($num > 0) { |
|
32 | + $out = $plus.abs($num); |
|
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 | } |
@@ -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')){ |
@@ -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; |
@@ -67,22 +67,22 @@ discard block |
||
67 | 67 | if (!is_scalar($addPS)) { |
68 | 68 | $addPS = ''; |
69 | 69 | } |
70 | - $InsertPrefix = (is_scalar($prefix) && $prefix !== '') ? ($prefix . $addPS) : ''; |
|
71 | - $InsertSuffix = (is_scalar($suffix) && $suffix !== '') ? ($addPS . $suffix) : ''; |
|
70 | + $InsertPrefix = (is_scalar($prefix) && $prefix !== '') ? ($prefix.$addPS) : ''; |
|
71 | + $InsertSuffix = (is_scalar($suffix) && $suffix !== '') ? ($addPS.$suffix) : ''; |
|
72 | 72 | foreach ($data as $key => $item) { |
73 | - $key = $InsertPrefix . $key; |
|
73 | + $key = $InsertPrefix.$key; |
|
74 | 74 | $val = null; |
75 | 75 | switch (true) { |
76 | 76 | case is_scalar($item): |
77 | 77 | $val = $item; |
78 | 78 | break; |
79 | 79 | case is_array($item): |
80 | - $val = (is_scalar($sep) && $sep !== '') ? rename_key_array($item, $key . $sep, $InsertSuffix, '', $sep) : array(); |
|
80 | + $val = (is_scalar($sep) && $sep !== '') ? rename_key_array($item, $key.$sep, $InsertSuffix, '', $sep) : array(); |
|
81 | 81 | $out = array_merge($out, $val); |
82 | 82 | $val = ''; |
83 | 83 | break; |
84 | 84 | } |
85 | - $out[$key . $InsertSuffix] = $val; |
|
85 | + $out[$key.$InsertSuffix] = $val; |
|
86 | 86 | } |
87 | 87 | } |
88 | 88 | return $out; |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | $workArray = &$workArray[$subKey]; |
113 | 113 | } |
114 | 114 | } |
115 | - } else { |
|
115 | + }else { |
|
116 | 116 | $out = $data; |
117 | 117 | } |
118 | 118 | } |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | { |
181 | 181 | $out = array(); |
182 | 182 | foreach ($data as $k => $v) { |
183 | - if (is_callable($filter) && $filter($v, $k)){ |
|
183 | + if (is_callable($filter) && $filter($v, $k)) { |
|
184 | 184 | $out[$k] = $v; |
185 | 185 | } |
186 | 186 | } |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | { |
203 | 203 | $path = explode($separator, $path); |
204 | 204 | while ($key = array_shift($path)) { |
205 | - if (!isset($array[$key])){ |
|
205 | + if (!isset($array[$key])) { |
|
206 | 206 | return $default; |
207 | 207 | } |
208 | 208 | $array = $array[$key]; |
@@ -270,14 +270,14 @@ discard block |
||
270 | 270 | } |
271 | 271 | } |
272 | 272 | |
273 | -if( !function_exists('array_shuffle')){ |
|
273 | +if (!function_exists('array_shuffle')) { |
|
274 | 274 | /** |
275 | 275 | * Перемешать массив в случайном порядке с сохранением ключей |
276 | 276 | * |
277 | 277 | * @param array $data массив с данными |
278 | 278 | * @return bool результат сортировки массива |
279 | 279 | */ |
280 | - function array_shuffle(array &$data = array()){ |
|
280 | + function array_shuffle(array &$data = array()) { |
|
281 | 281 | return uksort($data, function() { return rand() > rand(); }); |
282 | 282 | } |
283 | 283 | } |
@@ -297,14 +297,14 @@ discard block |
||
297 | 297 | if ((int)$count > 0) { |
298 | 298 | $data = current(array_chunk($data, (int)$count, true)); |
299 | 299 | } |
300 | - } else { |
|
300 | + }else { |
|
301 | 301 | $data = array(); |
302 | 302 | } |
303 | 303 | return $data; |
304 | 304 | } |
305 | 305 | } |
306 | 306 | |
307 | -if(!function_exists('is_assoc')){ |
|
307 | +if (!function_exists('is_assoc')) { |
|
308 | 308 | /** |
309 | 309 | * Является ли массив ассоциативным |
310 | 310 | * |
@@ -316,22 +316,22 @@ discard block |
||
316 | 316 | } |
317 | 317 | } |
318 | 318 | |
319 | -if(!function_exists('array_copy_key')){ |
|
319 | +if (!function_exists('array_copy_key')) { |
|
320 | 320 | /** |
321 | 321 | * Определить ключи массива равыне значениям |
322 | 322 | * |
323 | 323 | * @param array $data исходный массив со значениями |
324 | 324 | * @return array |
325 | 325 | */ |
326 | - function array_copy_key(array $data = array()){ |
|
327 | - $data = array_filter($data, function($val){ |
|
326 | + function array_copy_key(array $data = array()) { |
|
327 | + $data = array_filter($data, function($val) { |
|
328 | 328 | return is_scalar($val); |
329 | 329 | }); |
330 | 330 | return array_combine($data, $data); |
331 | 331 | } |
332 | 332 | } |
333 | 333 | |
334 | -if(!function_exists('make_tree')){ |
|
334 | +if (!function_exists('make_tree')) { |
|
335 | 335 | /** |
336 | 336 | * Helper function |
337 | 337 | * @see http://gostash.it/ru/users/3191 |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | } |
367 | 367 | } |
368 | 368 | |
369 | -if(!function_exists('array_chunk_vcolumn')){ |
|
369 | +if (!function_exists('array_chunk_vcolumn')) { |
|
370 | 370 | /** |
371 | 371 | * Разбиение массива на несколько частей с сохранением ключей, чтобы в каждой из этих частей было равное кол-во элементов |
372 | 372 | * Массив наполняется последовательно. Т.е. сначала наполняется данными первая часть, потом вторая и так, пока не закончатся данные. |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | * @param array $input исходный массив |
376 | 376 | * @param int $size кол-во частей |
377 | 377 | */ |
378 | - function array_chunk_vcolumn(array $input, $size){ |
|
378 | + function array_chunk_vcolumn(array $input, $size) { |
|
379 | 379 | $data = array_fill(0, $size, array()); |
380 | 380 | $size = ceil(count($input) / $size); |
381 | 381 | $i = 0; |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | } |
394 | 394 | } |
395 | 395 | |
396 | -if(!function_exists('array_chunk_hcolumn')){ |
|
396 | +if (!function_exists('array_chunk_hcolumn')) { |
|
397 | 397 | /** |
398 | 398 | * Разбиение массива на несколько частей с сохранением ключей, чтобы в каждой из этих частей было равное кол-во элементов |
399 | 399 | * Массив наполняется равномерно. Т.е. в первую строку каждой части складывается по одному элементу из массива. Затем аналогичным образом во вторую и так, пока не закончатся данные. |
@@ -401,12 +401,12 @@ discard block |
||
401 | 401 | * @param array $input исходный массив |
402 | 402 | * @param int $size кол-во частей |
403 | 403 | */ |
404 | - function array_chunk_hcolumn(array $input, $size){ |
|
404 | + function array_chunk_hcolumn(array $input, $size) { |
|
405 | 405 | $data = array_fill(0, $size, array()); |
406 | 406 | $j = -1; |
407 | 407 | foreach ($input as $k => $v) |
408 | 408 | { |
409 | - if (++$j >= $size){ |
|
409 | + if (++$j >= $size) { |
|
410 | 410 | $j = 0; |
411 | 411 | } |
412 | 412 | $data[$j][$k] = $v; |
@@ -415,21 +415,21 @@ discard block |
||
415 | 415 | } |
416 | 416 | } |
417 | 417 | |
418 | -if(!function_exists('array_filter_keys')){ |
|
418 | +if (!function_exists('array_filter_keys')) { |
|
419 | 419 | /** |
420 | 420 | * Фильтрация массива по ключу |
421 | 421 | * |
422 | 422 | * @param array $array исходный массив |
423 | 423 | * @param string $needle регулярное выражение для фильтрации ключей |
424 | 424 | */ |
425 | - function array_filter_keys($array, $needle){ |
|
425 | + function array_filter_keys($array, $needle) { |
|
426 | 426 | $matchedKeys = array_filter(array_keys($array), function($key) use ($needle){ |
427 | 427 | return preg_match($needle, $key); |
428 | 428 | }); |
429 | 429 | return array_intersect_key($array, array_flip($matchedKeys)); |
430 | 430 | } |
431 | 431 | } |
432 | -if(!function_exists('choose_chance')){ |
|
432 | +if (!function_exists('choose_chance')) { |
|
433 | 433 | /*** |
434 | 434 | * Выбор ключа массива со определенной вероятность |
435 | 435 | * choose_chance(array("a" => 10, "b" => 25, "c" => 25, "d" => 40)); |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | * @see: http://gostash.it/ru/stashes/381 |
438 | 438 | * @param array $arr исходный массив |
439 | 439 | */ |
440 | - function choose_chance(array $arr){ |
|
440 | + function choose_chance(array $arr) { |
|
441 | 441 | $rnd = mt_rand(1, array_sum($arr)); |
442 | 442 | $i = 0; |
443 | 443 | foreach ($arr as $value => $chance) { |
@@ -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 |
@@ -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 |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | */ |
10 | 10 | function html_implode(array $arr, $el) |
11 | 11 | { |
12 | - return "<$el>" . implode("</$el><$el>", $arr) . "</$el>"; |
|
12 | + return "<$el>".implode("</$el><$el>", $arr)."</$el>"; |
|
13 | 13 | } |
14 | 14 | } |
15 | 15 | |
@@ -28,10 +28,10 @@ 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 | 37 | return html_wrap('table', $thead.html_wrap('tbody', (is_array($rows) ? html_implode($rows, 'tr') : $rows)), $attr); |
@@ -77,13 +77,13 @@ 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 | - $html .= ' ' . $key . '="' . (in_array($key, $noEscape) ? $val : e($val)) . '"'; |
|
86 | + $html .= ' '.$key.'="'.(in_array($key, $noEscape) ? $val : e($val)).'"'; |
|
87 | 87 | break; |
88 | 88 | case ($val === true && is_scalar($key)): |
89 | 89 | $html .= ' '.$key; |
@@ -118,20 +118,20 @@ discard block |
||
118 | 118 | ); |
119 | 119 | } |
120 | 120 | $val = get_key($value, 'value', ''); |
121 | - if(is_int($title)){ |
|
121 | + if (is_int($title)) { |
|
122 | 122 | $title = get_key($value, 'value', $title); |
123 | 123 | } |
124 | 124 | if ((string)$val === (string)$current) { |
125 | 125 | $value['selected'] = true; |
126 | 126 | $selected = true; |
127 | - }else{ |
|
127 | + }else { |
|
128 | 128 | unset($value['selected']); |
129 | 129 | } |
130 | 130 | |
131 | 131 | $options[$title] = $value; |
132 | 132 | } |
133 | - foreach($options as $title => $attr){ |
|
134 | - if(!$selected && get_key($attr, 'value', '') == $default){ |
|
133 | + foreach ($options as $title => $attr) { |
|
134 | + if (!$selected && get_key($attr, 'value', '') == $default) { |
|
135 | 135 | $attr['selected'] = true; |
136 | 136 | } |
137 | 137 | $out .= html_wrap('option', $title, $attr); |
@@ -241,18 +241,18 @@ discard block |
||
241 | 241 | do { |
242 | 242 | $new = false; |
243 | 243 | //Поиск открывающего тэга (одного!) |
244 | - preg_match('%(<' . $tag . '[^>]*>)(.*)%s', $html, $m); |
|
244 | + preg_match('%(<'.$tag.'[^>]*>)(.*)%s', $html, $m); |
|
245 | 245 | |
246 | 246 | if (isset($m[1], $m[2])) { |
247 | 247 | //Начинаем поиски закрывающих тегов (всех до конца документа) |
248 | - preg_match_all('%</' . $tag . '[^>]*>%is', $m[2], $tmp, PREG_OFFSET_CAPTURE); |
|
248 | + preg_match_all('%</'.$tag.'[^>]*>%is', $m[2], $tmp, PREG_OFFSET_CAPTURE); |
|
249 | 249 | if (!empty($tmp[0])) { |
250 | 250 | foreach ($tmp[0] as $j => $subTmp) { |
251 | 251 | $closeTag = $subTmp[0]; //закрывающий тэг |
252 | 252 | $subText = substr($m[2], 0, $subTmp[1]); //Тексту внутри тэгов |
253 | 253 | |
254 | 254 | //подсчет открывающих тэгов внутри полученного текста |
255 | - preg_match_all('%(<' . $tag . '[^>]*>)%s', $subText, $count); |
|
255 | + preg_match_all('%(<'.$tag.'[^>]*>)%s', $subText, $count); |
|
256 | 256 | if (count($count[0]) == $j) { |
257 | 257 | $replace[] = array($m[1], $subText, $closeTag); |
258 | 258 | $new = true; |
@@ -266,15 +266,15 @@ discard block |
||
266 | 266 | $subTmp = $tmp[0][$j]; |
267 | 267 | $closeTag = $subTmp[0]; |
268 | 268 | |
269 | - $subText = substr($m[2], 0, $subTmp[1]) . $closeTag; |
|
269 | + $subText = substr($m[2], 0, $subTmp[1]).$closeTag; |
|
270 | 270 | $html = substr($m[2], $subTmp[1] + strlen($closeTag)); |
271 | 271 | $replace[] = array($m[1], $subText, $closeTag); |
272 | - } else { |
|
272 | + }else { |
|
273 | 273 | $replace[] = array($m[1], $m[2], ''); |
274 | 274 | $html = ''; |
275 | 275 | } |
276 | 276 | } |
277 | - } else { |
|
277 | + }else { |
|
278 | 278 | $html = ''; |
279 | 279 | } |
280 | 280 | } while (!empty($html)); |
@@ -282,14 +282,14 @@ discard block |
||
282 | 282 | } |
283 | 283 | } |
284 | 284 | |
285 | -if (!function_exists('clear_html')){ |
|
285 | +if (!function_exists('clear_html')) { |
|
286 | 286 | /** |
287 | 287 | * Удаление комментариев, переносов и лишних пробелов из html строки |
288 | 288 | * |
289 | 289 | * @param string $html HTML текст |
290 | 290 | * @return string |
291 | 291 | */ |
292 | - function clear_html($html){ |
|
292 | + function clear_html($html) { |
|
293 | 293 | $filters = array( |
294 | 294 | '/<!--([^\[|(<!)].*)-->/i' => '', // Remove HTML Comments (breaks with HTML5 Boilerplate) |
295 | 295 | '/(?<!\S)\/\/\s*[^\r\n]*/' => '', // Remove comments in the form /* */ |
@@ -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 |
@@ -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; |
@@ -62,9 +62,9 @@ discard block |
||
62 | 62 | } |
63 | 63 | $vals = array(); |
64 | 64 | foreach ($arr as $key => $val) { |
65 | - $vals[] = is_array($val) ? "'" . $key . "'=>" . array_code($val, $level + 1) : "'" . $key . "'=>'" . $val . "'"; |
|
65 | + $vals[] = is_array($val) ? "'".$key."'=>".array_code($val, $level + 1) : "'".$key."'=>'".$val."'"; |
|
66 | 66 | } |
67 | - $php = "array(\r" . $tabs . implode(",\r" . $tabs, $vals) . "\r" . $breaks . ")"; |
|
67 | + $php = "array(\r".$tabs.implode(",\r".$tabs, $vals)."\r".$breaks.")"; |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | return $php; |
@@ -82,19 +82,19 @@ 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 | 94 | $out = array(); |
95 | 95 | |
96 | - if(is_scalar($key) && !empty($key)){ |
|
97 | - if($store){ |
|
96 | + if (is_scalar($key) && !empty($key)) { |
|
97 | + if ($store) { |
|
98 | 98 | $marks[$key] = array( |
99 | 99 | 'time' => microtime(true), |
100 | 100 | 'memory' => memory_get_usage() |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | 'memory' => format_bytes($marks[$key]['memory']), |
104 | 104 | 'time' => format_microtime($marks[$key]['time']) |
105 | 105 | ); |
106 | - }else{ |
|
106 | + }else { |
|
107 | 107 | $out = get_key($marks, $key, array( |
108 | 108 | 'time' => get_key($_SERVER, 'REQUEST_TIME_FLOAT', 0), |
109 | 109 | 'memory'=> 0 |
@@ -113,14 +113,14 @@ discard block |
||
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
116 | - if($clear){ |
|
116 | + if ($clear) { |
|
117 | 117 | $marks = array(); |
118 | 118 | } |
119 | 119 | return $out; |
120 | 120 | } |
121 | 121 | } |
122 | 122 | |
123 | -if(!function_exists('call_private_method')){ |
|
123 | +if (!function_exists('call_private_method')) { |
|
124 | 124 | /** |
125 | 125 | * Возможность вызвать любой метод (даже приватный) |
126 | 126 | * call_private_method($myObject, 'myMethod', array('myValue1', 'myValue2')); |
@@ -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 |
@@ -9,9 +9,9 @@ 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 | - return mb_strtolower(mb_substr($str, 0, 1, $charset), $charset) . mb_substr($str, 1, mb_strlen($str), $charset); |
|
14 | + return mb_strtolower(mb_substr($str, 0, 1, $charset), $charset).mb_substr($str, 1, mb_strlen($str), $charset); |
|
15 | 15 | }); |
16 | 16 | } |
17 | 17 | } |
@@ -26,9 +26,9 @@ 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 | - return mb_strtoupper(mb_substr($str, 0, 1, $charset), $charset) . mb_substr($str, 1, mb_strlen($str), $charset); |
|
31 | + return mb_strtoupper(mb_substr($str, 0, 1, $charset), $charset).mb_substr($str, 1, mb_strlen($str), $charset); |
|
32 | 32 | }); |
33 | 33 | } |
34 | 34 | } |
@@ -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); |
@@ -302,17 +302,17 @@ discard block |
||
302 | 302 | if (array_key_exists($tag, $_allowable_tags)) return $s[0]; |
303 | 303 | |
304 | 304 | #tag without attributes |
305 | - 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 | - return '<' . $tag . '>'; |
|
305 | + 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 | + return '<'.$tag.'>'; |
|
309 | 309 | } |
310 | 310 | } |
311 | 311 | if ($tag === 'br') return "\r\n"; |
312 | 312 | if (!empty($_para_tags) && array_key_exists($tag, $_para_tags)) return "\r\n\r\n"; |
313 | 313 | return ''; |
314 | 314 | } |
315 | - trigger_error('Unknown callback type "' . $_callback_type . '"!', E_USER_ERROR); |
|
315 | + trigger_error('Unknown callback type "'.$_callback_type.'"!', E_USER_ERROR); |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | if (($pos = strpos($s, '<')) === false || strpos($s, '>', $pos) === false) #speed improve |
@@ -329,12 +329,12 @@ discard block |
||
329 | 329 | [a-zA-Z][a-zA-Z\d]*+ |
330 | 330 | (?>:[a-zA-Z][a-zA-Z\d]*+)? |
331 | 331 | ) #1 |
332 | - ' . $re_attrs_fast_safe . ' |
|
332 | + ' . $re_attrs_fast_safe.' |
|
333 | 333 | > |
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 | |
@@ -355,9 +355,9 @@ discard block |
||
355 | 355 | if (!empty($pair_tags)) { |
356 | 356 | #парные таги вместе с содержимым: |
357 | 357 | foreach ($pair_tags as $k => $v) $pair_tags[$k] = preg_quote($v, '/'); |
358 | - $patterns[] = '/ <((?i:' . implode('|', $pair_tags) . '))' . $re_attrs_fast_safe . '(?<!\/)> |
|
358 | + $patterns[] = '/ <((?i:'.implode('|', $pair_tags).'))'.$re_attrs_fast_safe.'(?<!\/)> |
|
359 | 359 | .*? |
360 | - <\/(?i:\\1)' . $re_attrs_fast_safe . '> |
|
360 | + <\/(?i:\\1)' . $re_attrs_fast_safe.'> |
|
361 | 361 | /sxSX'; |
362 | 362 | } |
363 | 363 | #d($patterns); |
@@ -388,9 +388,9 @@ discard block |
||
388 | 388 | $s2 = strtr($s2, "\x09\x0a\x0c\x0d", ' '); |
389 | 389 | */ |
390 | 390 | $s2 = preg_replace('/ [\x09\x0a\x0c\x0d]++ |
391 | - | <((?i:pre|textarea))' . $re_attrs_fast_safe . '(?<!\/)> |
|
391 | + | <((?i:pre|textarea))' . $re_attrs_fast_safe.'(?<!\/)> |
|
392 | 392 | .+? |
393 | - <\/(?i:\\1)' . $re_attrs_fast_safe . '> |
|
393 | + <\/(?i:\\1)' . $re_attrs_fast_safe.'> |
|
394 | 394 | \K |
395 | 395 | /sxSX', ' ', $s2); |
396 | 396 | if (preg_last_error() !== PREG_NO_ERROR) { |
@@ -452,7 +452,7 @@ discard block |
||
452 | 452 | if (is_nop($last)) { |
453 | 453 | $last = $sep; |
454 | 454 | } |
455 | - return empty($out) ? $end : $out . $last . $end; |
|
455 | + return empty($out) ? $end : $out.$last.$end; |
|
456 | 456 | } |
457 | 457 | } |
458 | 458 |