From 54a3c3e7e9e70c4770010e442e95f734200d03f9 Mon Sep 17 00:00:00 2001
From: brettp
Date: Thu, 15 Oct 2009 04:41:46 +0000
Subject: Standardized gobs of files.
git-svn-id: http://code.elgg.org/elgg/trunk@3548 36083f99-b078-4883-b0ff-0f9b5a30f544
---
engine/lib/input.php | 692 +++++++++++++++++++++++++--------------------------
1 file changed, 339 insertions(+), 353 deletions(-)
(limited to 'engine/lib/input.php')
diff --git a/engine/lib/input.php b/engine/lib/input.php
index 49eb63f13..289542547 100644
--- a/engine/lib/input.php
+++ b/engine/lib/input.php
@@ -1,376 +1,362 @@
-
- * @link http://elgg.org/
- */
-
- /**
- * Get some input from variables passed on the GET or POST line.
- *
- * @param $variable string The variable we want to return.
- * @param $default mixed A default value for the variable if it is not found.
- * @param $filter_result If true then the result is filtered for bad tags.
- */
- function get_input($variable, $default = "", $filter_result = true)
- {
-
- global $CONFIG;
-
- if (isset($CONFIG->input[$variable])) {
- $var = $CONFIG->input[$variable];
-
- if ($filter_result)
- $var = filter_tags($var);
-
- return $var;
+/**
+ * Parameter input functions.
+ * This file contains functions for getting input from get/post variables.
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @author Curverider Ltd
+ * @link http://elgg.org/
+ */
+
+/**
+ * Get some input from variables passed on the GET or POST line.
+ *
+ * @param $variable string The variable we want to return.
+ * @param $default mixed A default value for the variable if it is not found.
+ * @param $filter_result If true then the result is filtered for bad tags.
+ */
+function get_input($variable, $default = "", $filter_result = true) {
+
+ global $CONFIG;
+
+ if (isset($CONFIG->input[$variable])) {
+ $var = $CONFIG->input[$variable];
+
+ if ($filter_result) {
+ $var = filter_tags($var);
}
-
- if (isset($_REQUEST[$variable])) {
-
- if (is_array($_REQUEST[$variable])) {
- $var = $_REQUEST[$variable];
- } else {
- $var = trim($_REQUEST[$variable]);
- }
-
- if ($filter_result)
- $var = filter_tags($var);
- return $var;
-
+ return $var;
+ }
+
+ if (isset($_REQUEST[$variable])) {
+ if (is_array($_REQUEST[$variable])) {
+ $var = $_REQUEST[$variable];
+ } else {
+ $var = trim($_REQUEST[$variable]);
}
- return $default;
+ if ($filter_result) {
+ $var = filter_tags($var);
+ }
+ return $var;
}
-
- /**
- * Sets an input value that may later be retrieved by get_input
- *
- * @param string $variable The name of the variable
- * @param string $value The value of the variable
- */
- function set_input($variable, $value) {
-
- global $CONFIG;
- if (!isset($CONFIG->input))
- $CONFIG->input = array();
-
- if (is_array($value))
- {
- foreach ($value as $key => $val)
- $value[$key] = trim($val);
-
- $CONFIG->input[trim($variable)] = $value;
+
+ return $default;
+}
+
+/**
+ * Sets an input value that may later be retrieved by get_input
+ *
+ * @param string $variable The name of the variable
+ * @param string $value The value of the variable
+ */
+function set_input($variable, $value) {
+ global $CONFIG;
+ if (!isset($CONFIG->input)) {
+ $CONFIG->input = array();
+ }
+
+ if (is_array($value)) {
+ foreach ($value as $key => $val) {
+ $value[$key] = trim($val);
}
- else
- $CONFIG->input[trim($variable)] = trim($value);
-
+
+ $CONFIG->input[trim($variable)] = $value;
+ } else {
+ $CONFIG->input[trim($variable)] = trim($value);
}
-
- /**
- * Filter tags from a given string based on registered hooks.
- * @param $var
- * @return mixed The filtered result
- */
- function filter_tags($var)
- {
- return trigger_plugin_hook('validate', 'input', null, $var);
+}
+
+/**
+ * Filter tags from a given string based on registered hooks.
+ * @param $var
+ * @return mixed The filtered result
+ */
+function filter_tags($var) {
+ return trigger_plugin_hook('validate', 'input', null, $var);
+}
+
+/**
+ * Sanitise file paths for input, ensuring that they begin and end with slashes etc.
+ *
+ * @param string $path The path
+ * @return string
+ */
+function sanitise_filepath($path) {
+ // Convert to correct UNIX paths
+ $path = str_replace('\\', '/', $path);
+
+ // Sort trailing slash
+ $path = trim($path);
+ $path = rtrim($path, " /");
+ $path = $path . "/";
+
+ return $path;
+}
+
+
+/**
+ * Takes a string and turns any URLs into formatted links
+ *
+ * @param string $text The input string
+ * @return string The output stirng with formatted links
+ **/
+function parse_urls($text) {
+ return preg_replace_callback('/(?"\'\!\(\)]+)/i',
+ create_function(
+ '$matches',
+ '
+ $url = $matches[1];
+ $urltext = str_replace("/", "/", $url);
+ return "$urltext";
+ '
+ ), $text);
+}
+
+function autop($pee, $br = 1) {
+ $pee = $pee . "\n"; // just to make things a little easier, pad the end
+ $pee = preg_replace('|
\s*
|', "\n\n", $pee);
+ // Space things out a little
+ $allblocks = '(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|map|area|blockquote|address|math|style|input|p|h[1-6]|hr)';
+ $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee);
+ $pee = preg_replace('!(' . $allblocks . '>)!', "$1\n\n", $pee);
+ $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines
+ if ( strpos($pee, '
', '', $pee);
+ $pee = preg_replace('!\s*(?' . $allblocks . '[^>]*>)!', "$1", $pee);
+ $pee = preg_replace('!(?' . $allblocks . '[^>]*>)\s*
!', "$1", $pee);
+ if ($br) {
+ $pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', create_function('$matches', 'return str_replace("\n", "", $matches[0]);'), $pee);
+ $pee = preg_replace('|(?)\s*\n|', "
\n", $pee); // optionally make line breaks
+ $pee = str_replace('', "\n", $pee);
}
-
-
- /**
- * Takes a string and turns any URLs into formatted links
- *
- * @param string $text The input string
- * @return string The output stirng with formatted links
- **/
- function parse_urls($text) {
-
- return preg_replace_callback('/(?"\'\!\(\)]+)/i',
- create_function(
- '$matches',
- '
- $url = $matches[1];
- $urltext = str_replace("/", "/", $url);
- return "$urltext";
- '
- ), $text);
- }
-
- function autop($pee, $br = 1) {
- $pee = $pee . "\n"; // just to make things a little easier, pad the end
- $pee = preg_replace('|
\s*
|', "\n\n", $pee);
- // Space things out a little
- $allblocks = '(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|map|area|blockquote|address|math|style|input|p|h[1-6]|hr)';
- $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee);
- $pee = preg_replace('!(' . $allblocks . '>)!', "$1\n\n", $pee);
- $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines
- if ( strpos($pee, '