summaryrefslogtreecommitdiffstats
path: root/lib/kolab_utils.php
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2011-12-25 17:58:03 +0100
committerAleksander Machniak <alec@alec.pl>2011-12-25 17:58:03 +0100
commit92a5add47382cd41e782f45ef47e46806acdd615 (patch)
tree2a7993dc635df3746a037f78203746d2a3cbf330 /lib/kolab_utils.php
parente8ea8f9522098c104eae131b773c4fd6cb7d329c (diff)
downloadwebadmin-92a5add47382cd41e782f45ef47e46806acdd615.tar.gz
Restructured directory tree and class names (I'm not happy with it still)
Some improvements in the client
Diffstat (limited to 'lib/kolab_utils.php')
-rw-r--r--lib/kolab_utils.php141
1 files changed, 80 insertions, 61 deletions
diff --git a/lib/kolab_utils.php b/lib/kolab_utils.php
index 97b8bdf..1acd4ba 100644
--- a/lib/kolab_utils.php
+++ b/lib/kolab_utils.php
@@ -1,78 +1,97 @@
<?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);
- }
+class kolab_utils
+{
+ const REQUEST_ANY = 0;
+ const REQUEST_GET = 1;
+ const REQUEST_POST = 2;
- if (array_key_exists($key, $hdrs)) {
- return $hdrs[$key];
- } else {
- return null;
- }
+ /**
+ * Read a specific HTTP request header
+ *
+ * @param string $name Header name
+ *
+ * @return mixed Header value or null if not available
+ */
+ public static function request_header($name)
+ {
+ if (function_exists('getallheaders')) {
+ $hdrs = array_change_key_case(getallheaders(), CASE_UPPER);
+ $key = strtoupper($name);
}
-
- /**
- * Make sure the string ends with a slash
- */
- public static function slashify($str)
- {
- return self::unslashify($str).'/';
+ else {
+ $key = 'HTTP_' . strtoupper(strtr($name, '-', '_'));
+ $hdrs = array_change_key_case($_SERVER, CASE_UPPER);
}
- /**
- * Remove slash at the end of the string
- */
- public static function unslashify($str)
- {
- return preg_replace('/\/$/', '', $str);
+ return $hdrs[$key];
+ }
+
+ /**
+ * Returns input parameter value.
+ *
+ * @param string $name Parameter name
+ * @param int $type Parameter type
+ * @param bool $allow_html Enable to strip invalid/unsecure content
+ *
+ * @return mixed Input value
+ */
+ public static function get_input($name, $type = null, $allow_html = false)
+ {
+ if ($type == self::REQUEST_GET) {
+ $value = isset($_GET[$name]) ? $_GET[$name] : null;
+ }
+ else if ($type == self::REQUEST_POST) {
+ $value = isset($_POST[$name]) ? $_POST[$name] : null;
+ }
+ else {
+ $value = isset($_REQUEST[$name]) ? $_REQUEST[$name] : null;
}
- 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);
+ }
- return self::parse_input($value, $allow_html);
+ /**
+ * Input parsing.
+ *
+ * @param mixed $value Input value
+ * @param bool $allow_html Enable to strip invalid/unsecure content
+ *
+ * @return mixed Input value
+ */
+ public static function parse_input($value, $allow_html = false)
+ {
+ if (empty($value)) {
+ return $value;
}
- 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);
+ }
- 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;
+ }
- return $value;
- }
+ /**
+ * 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);
}
-?>
+}