diff options
author | Bot <bot@myigel.name> | 2017-01-02 03:57:23 +0100 |
---|---|---|
committer | Igor Scheller <igor.scheller@igorshp.de> | 2017-01-02 03:57:23 +0100 |
commit | 7313e15ce8236e19331fb6639a3a5b97c8f06ecd (patch) | |
tree | 399e5eaa403d6dd5993ca8fb6f2162319d2ed2e1 /includes/sys_page.php | |
parent | b839e401062b294292fdcbd7e30b79bc149fab6f (diff) |
PSR-2 formatting
Diffstat (limited to 'includes/sys_page.php')
-rw-r--r-- | includes/sys_page.php | 147 |
1 files changed, 79 insertions, 68 deletions
diff --git a/includes/sys_page.php b/includes/sys_page.php index 82ce9896..d173d5dc 100644 --- a/includes/sys_page.php +++ b/includes/sys_page.php @@ -17,18 +17,19 @@ use Engelsystem\ValidationResult; * @param int $default_value * Default value unix timestamp */ -function check_request_datetime($date_name, $time_name, $allowed_days, $default_value) { - $time = date("H:i", $default_value); - $day = date("Y-m-d", $default_value); +function check_request_datetime($date_name, $time_name, $allowed_days, $default_value) +{ + $time = date("H:i", $default_value); + $day = date("Y-m-d", $default_value); - if (isset($_REQUEST[$time_name]) && preg_match('#^\d{1,2}:\d\d$#', trim($_REQUEST[$time_name]))) { - $time = trim($_REQUEST[$time_name]); - } - if (isset($_REQUEST[$date_name]) && in_array($_REQUEST[$date_name], $allowed_days)) { - $day = $_REQUEST[$date_name]; - } + if (isset($_REQUEST[$time_name]) && preg_match('#^\d{1,2}:\d\d$#', trim($_REQUEST[$time_name]))) { + $time = trim($_REQUEST[$time_name]); + } + if (isset($_REQUEST[$date_name]) && in_array($_REQUEST[$date_name], $allowed_days)) { + $day = $_REQUEST[$date_name]; + } - return parse_date("Y-m-d H:i", $day . " " . $time); + return parse_date("Y-m-d H:i", $day . " " . $time); } /** @@ -40,20 +41,22 @@ function check_request_datetime($date_name, $time_name, $allowed_days, $default_ * The string to parse * @return The parsed unix timestamp */ -function parse_date($pattern, $value) { - $datetime = DateTime::createFromFormat($pattern, trim($value)); - if ($datetime == null) { - return null; - } - return $datetime->getTimestamp(); +function parse_date($pattern, $value) +{ + $datetime = DateTime::createFromFormat($pattern, trim($value)); + if ($datetime == null) { + return null; + } + return $datetime->getTimestamp(); } /** * Leitet den Browser an die übergebene URL weiter und hält das Script an. */ -function redirect($url) { - header("Location: " . $url, true, 302); - raw_output(""); +function redirect($url) +{ + header("Location: " . $url, true, 302); + raw_output(""); } /** @@ -62,9 +65,10 @@ function redirect($url) { * @param String $output * String to display */ -function raw_output($output) { - echo $output; - die(); +function raw_output($output) +{ + echo $output; + die(); } /** @@ -77,12 +81,13 @@ function raw_output($output) { * @param string $value_name * name of the column to use as displayed value */ -function select_array($data, $key_name, $value_name) { - $ret = []; - foreach ($data as $value) { - $ret[$value[$key_name]] = $value[$value_name]; - } - return $ret; +function select_array($data, $key_name, $value_name) +{ + $ret = []; + foreach ($data as $value) { + $ret[$value[$key_name]] = $value[$value_name]; + } + return $ret; } /** @@ -93,11 +98,12 @@ function select_array($data, $key_name, $value_name) { * @param array<int> $default * Default return value, if param is not set */ -function check_request_int_array($name, $default = []) { - if (isset($_REQUEST[$name]) && is_array($_REQUEST[$name])) { - return array_filter($_REQUEST[$name], 'is_numeric'); - } - return $default; +function check_request_int_array($name, $default = []) +{ + if (isset($_REQUEST[$name]) && is_array($_REQUEST[$name])) { + return array_filter($_REQUEST[$name], 'is_numeric'); + } + return $default; } /** @@ -112,11 +118,12 @@ function check_request_int_array($name, $default = []) { * is a null value allowed? * @return ValidationResult containing the parsed date */ -function check_request_date($name, $error_message = null, $null_allowed = false) { - if (! isset($_REQUEST[$name])) { - return new ValidationResult($null_allowed, null); - } - return check_date($_REQUEST[$name], $error_message, $null_allowed); +function check_request_date($name, $error_message = null, $null_allowed = false) +{ + if (! isset($_REQUEST[$name])) { + return new ValidationResult($null_allowed, null); + } + return check_date($_REQUEST[$name], $error_message, $null_allowed); } /** @@ -131,61 +138,65 @@ function check_request_date($name, $error_message = null, $null_allowed = false) * is a null value allowed? * @return ValidationResult containing the parsed date */ -function check_date($input, $error_message = null, $null_allowed = false) { - if ($tmp = parse_date("Y-m-d H:i", trim($input) . " 00:00")) { - return new ValidationResult(true, $tmp); - } - if ($null_allowed) { - return new ValidationResult(true, null); - } +function check_date($input, $error_message = null, $null_allowed = false) +{ + if ($tmp = parse_date("Y-m-d H:i", trim($input) . " 00:00")) { + return new ValidationResult(true, $tmp); + } + if ($null_allowed) { + return new ValidationResult(true, null); + } - error($error_message); - return new ValidationResult(false, null); + error($error_message); + return new ValidationResult(false, null); } /** * Returns REQUEST value filtered or default value (null) if not set. */ -function strip_request_item($name, $default_value = null) { - if (isset($_REQUEST[$name])) { - return strip_item($_REQUEST[$name]); - } - return $default_value; +function strip_request_item($name, $default_value = null) +{ + if (isset($_REQUEST[$name])) { + return strip_item($_REQUEST[$name]); + } + return $default_value; } /** * Testet, ob der angegebene REQUEST Wert ein Integer ist, bzw. * eine ID sein könnte. */ -function test_request_int($name) { - if (isset($_REQUEST[$name])) { - return preg_match("/^[0-9]*$/", $_REQUEST[$name]); - } - return false; +function test_request_int($name) +{ + if (isset($_REQUEST[$name])) { + return preg_match("/^[0-9]*$/", $_REQUEST[$name]); + } + return false; } /** * Gibt den gefilterten REQUEST Wert mit Zeilenumbrüchen zurück */ -function strip_request_item_nl($name, $default_value = null) { - if (isset($_REQUEST[$name])) { - return preg_replace("/([^\p{L}\p{S}\p{P}\p{Z}\p{N}+\n]{1,})/ui", '', strip_tags($_REQUEST[$name])); - } - return $default_value; +function strip_request_item_nl($name, $default_value = null) +{ + if (isset($_REQUEST[$name])) { + return preg_replace("/([^\p{L}\p{S}\p{P}\p{Z}\p{N}+\n]{1,})/ui", '', strip_tags($_REQUEST[$name])); + } + return $default_value; } /** * Entfernt unerwünschte Zeichen */ -function strip_item($item) { - return preg_replace("/([^\p{L}\p{S}\p{P}\p{Z}\p{N}+]{1,})/ui", '', strip_tags($item)); +function strip_item($item) +{ + return preg_replace("/([^\p{L}\p{S}\p{P}\p{Z}\p{N}+]{1,})/ui", '', strip_tags($item)); } /** * Überprüft eine E-Mail-Adresse. */ -function check_email($email) { - return (bool) filter_var($email, FILTER_VALIDATE_EMAIL); +function check_email($email) +{ + return (bool) filter_var($email, FILTER_VALIDATE_EMAIL); } - -?> |