Elgg  Version 1.11
StickyForms.php
Go to the documentation of this file.
1 <?php
2 namespace Elgg\Forms;
3 
13 class StickyForms {
14 
25  public function makeStickyForm($form_name) {
26 
27  elgg_clear_sticky_form($form_name);
28 
29  $session = _elgg_services()->session;
30  $data = $session->get('sticky_forms', array());
31  $req = _elgg_services()->request;
32 
33  // will go through XSS filtering in elgg_get_sticky_value()
34  $vars = array_merge($req->query->all(), $req->request->all());
35  $data[$form_name] = $vars;
36 
37  $session->set('sticky_forms', $data);
38  }
39 
51  function clearStickyForm($form_name) {
52  $session = _elgg_services()->session;
53  $data = $session->get('sticky_forms', array());
54  unset($data[$form_name]);
55  $session->set('sticky_forms', $data);
56  }
57 
65  function isStickyForm($form_name) {
66  $session = _elgg_services()->session;
67  $data = $session->get('sticky_forms', array());
68  return isset($data[$form_name]);
69  }
70 
83  function getStickyValue($form_name, $variable = '', $default = null, $filter_result = true) {
84  $session = _elgg_services()->session;
85  $data = $session->get('sticky_forms', array());
86  if (isset($data[$form_name][$variable])) {
87  $value = $data[$form_name][$variable];
88  if ($filter_result) {
89  // XSS filter result
91  }
92  return $value;
93  }
94  return $default;
95  }
96 
105  function getStickyValues($form_name, $filter_result = true) {
106  $session = _elgg_services()->session;
107  $data = $session->get('sticky_forms', array());
108  if (!isset($data[$form_name])) {
109  return array();
110  }
111 
112  $values = $data[$form_name];
113  if ($filter_result) {
114  foreach ($values as $key => $value) {
115  // XSS filter result
116  $values[$key] = filter_tags($value);
117  }
118  }
119  return $values;
120  }
121 
130  function clearStickyValue($form_name, $variable) {
131  $session = _elgg_services()->session;
132  $data = $session->get('sticky_forms', array());
133  unset($data[$form_name][$variable]);
134  $session->set('sticky_forms', $data);
135  }
136 
137 }
getStickyValues($form_name, $filter_result=true)
Get all the values in a sticky form in an array.
elgg_clear_sticky_form($form_name)
Clear the sticky form cache.
Definition: input.php:119
$data
Definition: opendd.php:13
$value
Definition: longtext.php:26
getStickyValue($form_name, $variable= '', $default=null, $filter_result=true)
Get a specific sticky variable.
Definition: StickyForms.php:83
$default
Definition: checkbox.php:34
filter_tags($var)
Filter tags from a given string based on registered hooks.
Definition: input.php:53
isStickyForm($form_name)
Has this form been made sticky?
Definition: StickyForms.php:65
clearStickyValue($form_name, $variable)
Clear a specific sticky variable.
$key
Definition: summary.php:34
_elgg_services()
Definition: autoloader.php:14
makeStickyForm($form_name)
Load all the GET and POST variables into the sticky form cache.
Definition: StickyForms.php:25
$session
Definition: login.php:9
clearStickyForm($form_name)
Clear the sticky form cache.
Definition: StickyForms.php:51
if(file_exists($welcome)) $vars
Definition: upgrade.php:93