summaryrefslogtreecommitdiffstats
path: root/lib/kolab_utils.php
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2011-12-23 14:46:24 +0100
committerAleksander Machniak <alec@alec.pl>2011-12-23 14:46:24 +0100
commite8ea8f9522098c104eae131b773c4fd6cb7d329c (patch)
tree196bf9b39771cd6cbf9294ff9631b58d6fa3a732 /lib/kolab_utils.php
parent2e04d0e498fef6b5dad832a4f400fa865bbf853d (diff)
parentfa17922ff4fa6617851d6dc4147da0d8660ca2bc (diff)
downloadwebadmin-e8ea8f9522098c104eae131b773c4fd6cb7d329c.tar.gz
Merge branch 'master' of ssh://git.klab.cc/git/vanmeeuwen/kolab-wap
Conflicts: lib/kolab_admin_client_task.php lib/kolab_html.php public_html/include/kolab_utils.php public_html/include/tasks/main.php public_html/include/tasks/user.php public_html/lib/Smarty/Smarty.class.php public_html/lib/Smarty/plugins/block.textformat.php public_html/lib/Smarty/plugins/function.fetch.php public_html/lib/Smarty/plugins/function.html_checkboxes.php public_html/lib/Smarty/plugins/function.html_image.php public_html/lib/Smarty/plugins/function.html_radios.php public_html/lib/Smarty/plugins/function.mailto.php public_html/lib/Smarty/plugins/modifier.capitalize.php public_html/lib/Smarty/plugins/modifier.date_format.php public_html/lib/Smarty/plugins/modifier.debug_print_var.php public_html/lib/Smarty/plugins/modifier.escape.php public_html/lib/Smarty/plugins/modifier.replace.php public_html/lib/Smarty/plugins/modifier.spacify.php public_html/lib/Smarty/plugins/modifier.truncate.php public_html/lib/Smarty/plugins/modifiercompiler.count_characters.php public_html/lib/Smarty/plugins/modifiercompiler.count_sentences.php public_html/lib/Smarty/plugins/modifiercompiler.count_words.php public_html/lib/Smarty/plugins/modifiercompiler.escape.php public_html/lib/Smarty/plugins/modifiercompiler.from_charset.php public_html/lib/Smarty/plugins/modifiercompiler.lower.php public_html/lib/Smarty/plugins/modifiercompiler.strip.php public_html/lib/Smarty/plugins/modifiercompiler.to_charset.php public_html/lib/Smarty/plugins/modifiercompiler.unescape.php public_html/lib/Smarty/plugins/modifiercompiler.upper.php public_html/lib/Smarty/plugins/modifiercompiler.wordwrap.php public_html/lib/Smarty/plugins/shared.escape_special_chars.php public_html/lib/Smarty/plugins/shared.mb_wordwrap.php public_html/lib/Smarty/plugins/variablefilter.htmlspecialchars.php
Diffstat (limited to 'lib/kolab_utils.php')
-rw-r--r--lib/kolab_utils.php78
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;
+ }
+
+ }
+
+?>