Completed
Push — master ( 7b69e0...e6649e )
by Agel_Nash
02:21
created
src/utils.functions.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -17,10 +17,10 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
438 438
 	function image_size($image, $mode = null)
439 439
 	{
440 440
 		$width = $height = 0;
441
-		if(is_scalar($input) && is_file($input)){
441
+		if (is_scalar($input) && is_file($input)) {
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
Please login to merge, or discard this patch.
src/string.functions.php 1 patch
Braces   +35 added lines, -12 removed lines patch added patch discarded remove patch
@@ -299,26 +299,38 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
Please login to merge, or discard this patch.