aboutsummaryrefslogtreecommitdiff
path: root/engine/lib
diff options
context:
space:
mode:
Diffstat (limited to 'engine/lib')
-rw-r--r--engine/lib/elgglib.php74
1 files changed, 74 insertions, 0 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php
index fd270bc1d..ac46df078 100644
--- a/engine/lib/elgglib.php
+++ b/engine/lib/elgglib.php
@@ -2710,6 +2710,80 @@ function elgg_get_breadcrumbs() {
/**
+ * Sticky forms
+ */
+
+/**
+ * Load all the REQUEST variables into the sticky form cache
+ *
+ * Call this from an action when you want all your submitted variables
+ * available if the submission fails validation and is sent back to the form
+ */
+function elgg_make_sticky_form() {
+ elgg_clear_sticky_form();
+
+ $_SESSION['sticky_form'] = array();
+
+ foreach($_REQUEST as $key => $var) {
+ // will go through XSS filtering on the get function
+ $_SESSION['sticky_form'][$key] = $var;
+ }
+}
+
+
+/**
+ * Clear the sticky form cache
+ *
+ * Call this if validation is successful in the action handler or
+ * when they sticky values have been used to repopulate the form
+ * after a validation error.
+ */
+function elgg_clear_sticky_form() {
+ unset($_SESSION['sticky_form']);
+}
+
+/**
+ * Has this form been made sticky
+ *
+ * @return boolean
+ */
+function elgg_is_sticky_form() {
+ return isset($_SESSION['sticky_form']);
+}
+
+/**
+ * Get a specific stick variable
+ *
+ * @param string $variable The name of the variable
+ * @param mixed $default Default value if the variable does not exist in sticky cache
+ * @param boolean $filter_result Filter for bad input if true
+ * @return mixed
+ *
+ * @todo should this filter the default value?
+ */
+function elgg_get_sticky_value($variable, $default = "", $filter_result = true) {
+ if (isset($_SESSION['sticky_form'][$variable])) {
+ $value = $_SESSION['sticky_form'][$variable];
+ if ($filter_result) {
+ // XSS filter result
+ $value = filter_tags($value);
+ }
+ return $value;
+ }
+ return $default;
+}
+
+/**
+ * Clear a specific sticky variable
+ *
+ * @param string $variable The name of the variable to clear
+ */
+function elgg_clear_sticky_value($variable) {
+ unset($_SESSION['sticky_form'][$variable]);
+}
+
+
+/**
* Returns the PHP INI setting in bytes
*
* @param str $setting