diff options
author | Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> | 2011-12-23 12:41:45 +0100 |
---|---|---|
committer | Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> | 2011-12-23 12:41:45 +0100 |
commit | 7b7b26250580f713edc9aa459ad12abfcaa24ea0 (patch) | |
tree | cd246ba8f55f00ba6046da2bb9aa242f4f84d3f1 /lib/kolab_utils.php | |
parent | 69169e37f63c2885fe0176b5c7aa7ee2079b814e (diff) | |
download | webadmin-7b7b26250580f713edc9aa459ad12abfcaa24ea0.tar.gz |
Restructure the files that do not belong in public_html to live in lib/
Use lib/Conf.php for configuration
Reuse as much of the existing utilities as possible, by sharing the common codebase (i.e. kolab_utils, etc)
Diffstat (limited to 'lib/kolab_utils.php')
-rw-r--r-- | lib/kolab_utils.php | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/lib/kolab_utils.php b/lib/kolab_utils.php new file mode 100644 index 0000000..97b8bdf --- /dev/null +++ b/lib/kolab_utils.php @@ -0,0 +1,78 @@ +<?php + + class kolab_utils { + /** + * Read a specific HTTP request header + * + * @param string $name Header name + * @return mixed Header value or null if not available + */ + public static function get_request_header($name) { + if (function_exists('getallheaders')) { + $hdrs = array_change_key_case(getallheaders(), CASE_UPPER); + $key = strtoupper($name); + } else { + $key = 'HTTP_' . strtoupper(strtr($name, '-', '_')); + $hdrs = array_change_key_case($_SERVER, CASE_UPPER); + } + + if (array_key_exists($key, $hdrs)) { + return $hdrs[$key]; + } else { + return null; + } + } + + /** + * Make sure the string ends with a slash + */ + public static function slashify($str) + { + return self::unslashify($str).'/'; + } + + /** + * Remove slash at the end of the string + */ + public static function unslashify($str) + { + return preg_replace('/\/$/', '', $str); + } + + public static function get_input($name, $type = null, $allow_html = false) + { + if ($type == 'GET') { + $value = isset($_GET[$name]) ? $_GET[$name] : null; + } + else if ($type == 'POST') { + $value = isset($_POST[$name]) ? $_POST[$name] : null; + } + else { + $value = isset($_REQUEST[$name]) ? $_REQUEST[$name] : null; + } + + return self::parse_input($value, $allow_html); + } + + public static function parse_input($value, $allow_html = false) + { + if (empty($value)) { + return $value; + } + + if (is_array($value)) { + foreach ($value as $idx => $val) { + $value[$idx] = self::parse_input($val, $allow_html); + } + } + // remove HTML tags if not allowed + else if (!$allow_html) { + $value = strip_tags($value); + } + + return $value; + } + + } + +?> |