= 1577833200); // 2020-01-01 - date of birth of this soft } public static function description($comment) { if (preg_match("/^[\p{L}0-9\p{P}\p{Zs}\p{Zl}\p{Sc}\=\+]+$/uim", $comment)) return true; return false; } public static function email($value, $domains=NULL, $checkDns=true) { $regex = '/^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$/'; if (!preg_match($regex, $value)) { return false; } $domain = explode('@', $value); $domain = $domain[1]; if ($domains && !in_array($domain, ensure_is_array($domains))) return false; if ($checkDns) { if (!function_exists('checkdnsrr')) { Log::warning( "Check::email(): PHP function checkdnsrr is missing, can't check domain against DNS. ". "Assume is OK." ); } else if (!(checkdnsrr($domain, 'MX') || checkdnsrr($domain, 'A'))) { return false; } } return true; } public static function ip_address($ip, $allow_private_ip_address=true, $allow_reserved_ip_address=true, $ipv4_only=false, $ipv6_only=false) { $flag = null; if ($ipv4_only) $flag |= FILTER_FLAG_IPV4; if ($ipv6_only) $flag |= FILTER_FLAG_IPV6; if (!isset($allow_private_ip_address) || !$allow_private_ip_address) $flag |= FILTER_FLAG_NO_PRIV_RANGE; if (!isset($allow_reserved_ip_address) || !$allow_reserved_ip_address) $flag |= FILTER_FLAG_NO_RES_RANGE; if (!is_null($flag)) return (bool)filter_var($ip, FILTER_VALIDATE_IP, $flag); else return (bool)filter_var($ip, FILTER_VALIDATE_IP); } public static function tcp_or_udp_port($value) { if (!is_int($value)) { if (!preg_match('/^[0-9]+$/', $value)) return false; $value = intval($value); } if ($value <= 0) return false; if ($value > 65635) return false; return true; } public static function is_empty($val) { switch(gettype($val)) { case "boolean": case "integer": case "double": case "object": case "resource": return False; case "array": case "string": if ($val == "0") return false; return empty($val); case "NULL": return True; } } } # vim: tabstop=2 shiftwidth=2 softtabstop=2 expandtab