Elgg  Version master
input.php
Go to the documentation of this file.
1 <?php
20 function get_input(string $variable, $default = null, bool $filter_result = true) {
21  return _elgg_services()->request->getParam($variable, $default, $filter_result);
22 }
23 
34 function set_input(string $variable, $value): void {
35  _elgg_services()->request->setParam($variable, $value, true);
36 }
37 
50 function elgg_get_request_data(bool $filter_result = true): array {
51  return _elgg_services()->request->getParams($filter_result);
52 }
53 
63 function elgg_get_title_input(string $variable = 'title', string $default = ''): string {
64  $raw_input = get_input($variable, $default, false);
65  return htmlspecialchars($raw_input ?? '', ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
66 }
67 
78  return elgg_trigger_event_results('sanitize', 'input', [], $input);
79 }
80 
89 function elgg_is_valid_email(string $address): bool {
90  return _elgg_services()->accounts->isValidEmail($address);
91 }
92 
105 function elgg_make_sticky_form(string $form_name, array $ignored_field_names = []): void {
106  _elgg_services()->stickyForms->makeStickyForm($form_name, $ignored_field_names);
107 }
108 
121 function elgg_clear_sticky_form(string $form_name): void {
122  _elgg_services()->stickyForms->clearStickyForm($form_name);
123 }
124 
133 function elgg_is_sticky_form(string $form_name): bool {
134  return _elgg_services()->stickyForms->isStickyForm($form_name);
135 }
136 
148 function elgg_get_sticky_value(string $form_name, string $variable = '', $default = null, bool $filter_result = true) {
149  return _elgg_services()->stickyForms->getStickyValue($form_name, $variable, $default, $filter_result);
150 }
151 
161 function elgg_get_sticky_values(string $form_name, bool $filter_result = true): array {
162  return _elgg_services()->stickyForms->getStickyValues($form_name, $filter_result);
163 }
164 
176 function elgg_is_empty($value): bool {
178 }
179 
194 function _elgg_htmlawed_tag_post_processor(string $element, array|false $attributes = false): string {
195  if ($attributes === false) {
196  // This is a closing tag. Prevent further processing to avoid inserting a duplicate tag
197  return "</{$element}>";
198  }
199 
200  // this list should be coordinated with the WYSIWYG editor used (tinymce, ckeditor, etc.)
201  $allowed_styles = [
202  'color', 'cursor', 'text-align', 'vertical-align', 'font-size',
203  'font-weight', 'font-style', 'border', 'border-top', 'background-color',
204  'border-bottom', 'border-left', 'border-right',
205  'margin', 'margin-top', 'margin-bottom', 'margin-left',
206  'margin-right', 'padding', 'float', 'text-decoration'
207  ];
208 
209  $params = ['tag' => $element];
210  $allowed_styles = elgg_trigger_event_results('allowed_styles', 'htmlawed', $params, $allowed_styles);
211 
212  // must return something.
213  $string = '';
214 
215  foreach ($attributes as $attr => $value) {
216  if ($attr == 'style') {
217  $styles = explode(';', $value);
218 
219  $style_str = '';
220  foreach ($styles as $style) {
221  if (!trim($style) || !str_contains($style, ':')) {
222  continue;
223  }
224 
225  list($style_attr, $style_value) = explode(':', trim($style));
226  $style_attr = trim($style_attr);
227  $style_value = trim($style_value);
228 
229  if (in_array($style_attr, $allowed_styles)) {
230  $style_str .= "{$style_attr}: {$style_value}; ";
231  }
232  }
233 
234  if ($style_str) {
235  $style_str = trim($style_str);
236  $string .= " style=\"{$style_str}\"";
237  }
238  } else {
239  $string .= " {$attr}=\"{$value}\"";
240  }
241  }
242 
243  // Some WYSIWYG editors do not like tags like <p > so only add a space if needed.
244  $string = trim($string);
245  if (!elgg_is_empty($string)) {
246  $string = " {$string}";
247  }
248 
249  return "<{$element}{$string}>";
250 }
251 
260 function elgg_string_to_array(string $string): array {
261  $ar = explode(',', $string);
262  $ar = array_map('trim', $ar);
263  $ar = array_map('strip_tags', $ar);
264 
265  $ar = array_filter($ar, function($string) {
266  return !elgg_is_empty($string);
267  });
268 
269  $ar = array_unique($ar);
270 
271  // reset keys
272  return array_values($ar);
273 }
$default
Definition: checkbox.php:31
elgg_get_title_input(string $variable= 'title', string $default= '')
Get an HTML-escaped title from input.
Definition: input.php:63
$params
Saves global plugin settings.
Definition: save.php:13
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
Definition: LICENSE.txt:215
elgg_clear_sticky_form(string $form_name)
Remove form submission data from the session.
Definition: input.php:121
elgg_sanitize_input($input)
Filter input from a given string based on registered events.
Definition: input.php:77
elgg_trigger_event_results(string $event, string $type, array $params=[], $returnvalue=null)
Triggers an event where it is expected that the mixed return value could be manipulated by event call...
Definition: events.php:117
elgg_string_to_array(string $string)
Takes in a comma-separated string and returns an array of uniquely trimmed and stripped strings...
Definition: input.php:260
static isEmpty($value)
Check if a value isn&#39;t empty, but allow 0 and &#39;0&#39;.
Definition: Values.php:192
elgg_get_sticky_value(string $form_name, string $variable= '', $default=null, bool $filter_result=true)
Get a specific value from cached form submission data.
Definition: input.php:148
set_input(string $variable, $value)
Sets an input value that may later be retrieved by get_input.
Definition: input.php:34
$value
Definition: generic.php:51
get_input(string $variable, $default=null, bool $filter_result=true)
Parameter input functions.
Definition: input.php:20
elgg_is_empty($value)
Check if a value isn&#39;t empty, but allow 0 and &#39;0&#39;.
Definition: input.php:176
_elgg_htmlawed_tag_post_processor(string $element, array|false $attributes=false)
Post processor for tags in htmlawed.
Definition: input.php:194
$input
Definition: input.php:9
elgg_get_sticky_values(string $form_name, bool $filter_result=true)
Get all submission data cached for a form.
Definition: input.php:161
elgg_make_sticky_form(string $form_name, array $ignored_field_names=[])
Save form submission data (all GET and POST vars) into a session cache.
Definition: input.php:105
elgg_get_request_data(bool $filter_result=true)
Returns all values parsed from the current request, including $_GET and $_POST values, as well as any values set with set_input()
Definition: input.php:50
elgg_is_sticky_form(string $form_name)
Does form submission data exist for this form?
Definition: input.php:133
elgg_is_valid_email(string $address)
Validates an email address.
Definition: input.php:89
$style
Definition: full.php:94
_elgg_services()
Get the global service provider.
Definition: elgglib.php:346
$attributes
Elgg AJAX loader.
Definition: ajax_loader.php:10