Elgg  Version 1.11
input.php
Go to the documentation of this file.
1 <?php
27 function get_input($variable, $default = null, $filter_result = true) {
28  return _elgg_services()->input->get($variable, $default, $filter_result);
29 }
30 
41 function set_input($variable, $value) {
42  _elgg_services()->input->set($variable, $value);
43 }
44 
53 function filter_tags($var) {
54  return elgg_trigger_plugin_hook('validate', 'input', null, $var);
55 }
56 
65 function current_page_url() {
67 
68  $page = $url['scheme'] . "://" . $url['host'];
69 
70  if (isset($url['port']) && $url['port']) {
71  $page .= ":" . $url['port'];
72  }
73 
74  $page = trim($page, "/");
75 
76  $page .= _elgg_services()->request->getRequestUri();
77 
78  return $page;
79 }
80 
88 function is_email_address($address) {
89  return filter_var($address, FILTER_VALIDATE_EMAIL) === $address;
90 }
91 
103 function elgg_make_sticky_form($form_name) {
104  _elgg_services()->stickyForms->makeStickyForm($form_name);
105 }
106 
119 function elgg_clear_sticky_form($form_name) {
120  _elgg_services()->stickyForms->clearStickyForm($form_name);
121 }
122 
131 function elgg_is_sticky_form($form_name) {
132  return _elgg_services()->stickyForms->isStickyForm($form_name);
133 }
134 
148 function elgg_get_sticky_value($form_name, $variable = '', $default = null, $filter_result = true) {
149  return _elgg_services()->stickyForms->getStickyValue($form_name, $variable, $default, $filter_result);
150 
151 }
152 
162 function elgg_get_sticky_values($form_name, $filter_result = true) {
163  return _elgg_services()->stickyForms->getStickyValues($form_name, $filter_result);
164 }
165 
175 function elgg_clear_sticky_value($form_name, $variable) {
176  _elgg_services()->stickyForms->clearStickyValue($form_name, $variable);
177 }
178 
197  $dbprefix = elgg_get_config('dbprefix');
198 
199  // only return results to logged in users.
201  exit;
202  }
203 
204  if (!$q = get_input('term', get_input('q'))) {
205  exit;
206  }
207 
208  $input_name = get_input('name', 'members');
209 
210  $q = sanitise_string($q);
211 
212  // replace mysql vars with escaped strings
213  $q = str_replace(array('_', '%'), array('\_', '\%'), $q);
214 
215  $match_on = get_input('match_on', 'all');
216 
217  if (!is_array($match_on)) {
218  $match_on = array($match_on);
219  }
220 
221  // all = users and groups
222  if (in_array('all', $match_on)) {
223  $match_on = array('users', 'groups');
224  }
225 
227  if (get_input('match_owner', false)) {
228  $owner_guid = $user->getGUID();
229  }
230 
231  $limit = sanitise_int(get_input('limit', elgg_get_config('default_limit')));
232 
233  // grab a list of entities and send them in json.
234  $results = array();
235  foreach ($match_on as $match_type) {
236  switch ($match_type) {
237  case 'users':
238  $options = array(
239  'type' => 'user',
240  'limit' => $limit,
241  'joins' => array("JOIN {$dbprefix}users_entity ue ON e.guid = ue.guid"),
242  'wheres' => array(
243  "ue.banned = 'no'",
244  "(ue.name LIKE '$q%' OR ue.name LIKE '% $q%' OR ue.username LIKE '$q%')"
245  )
246  );
247 
248  $entities = elgg_get_entities($options);
249  if (!empty($entities)) {
250  foreach ($entities as $entity) {
251 
252  if (in_array('groups', $match_on)) {
253  $value = $entity->guid;
254  } else {
255  $value = $entity->username;
256  }
257 
258  $output = elgg_view_list_item($entity, array(
259  'use_hover' => false,
260  'use_link' => false,
261  'class' => 'elgg-autocomplete-item',
262  'title' => $entity->name, // Default title would be a link
263  ));
264 
265  $icon = elgg_view_entity_icon($entity, 'tiny', array(
266  'use_hover' => false,
267  ));
268 
269  $result = array(
270  'type' => 'user',
271  'name' => $entity->name,
272  'desc' => $entity->username,
273  'guid' => $entity->guid,
274  'label' => $output,
275  'value' => $value,
276  'icon' => $icon,
277  'url' => $entity->getURL(),
278  'html' => elgg_view('input/userpicker/item', array(
279  'entity' => $entity,
280  'input_name' => $input_name,
281  )),
282  );
283  $results[$entity->name . rand(1, 100)] = $result;
284  }
285  }
286  break;
287 
288  case 'groups':
289  // don't return results if groups aren't enabled.
290  if (!elgg_is_active_plugin('groups')) {
291  continue;
292  }
293 
294  $options = array(
295  'type' => 'group',
296  'limit' => $limit,
297  'owner_guid' => $owner_guid,
298  'joins' => array("JOIN {$dbprefix}groups_entity ge ON e.guid = ge.guid"),
299  'wheres' => array(
300  "(ge.name LIKE '$q%' OR ge.name LIKE '% $q%' OR ge.description LIKE '% $q%')"
301  )
302  );
303 
304  $entities = elgg_get_entities($options);
305  if (!empty($entities)) {
306  foreach ($entities as $entity) {
307  $output = elgg_view_list_item($entity, array(
308  'use_hover' => false,
309  'class' => 'elgg-autocomplete-item',
310  'full_view' => false,
311  'href' => false,
312  'title' => $entity->name, // Default title would be a link
313  ));
314 
315  $icon = elgg_view_entity_icon($entity, 'tiny', array(
316  'use_hover' => false,
317  ));
318 
319  $result = array(
320  'type' => 'group',
321  'name' => $entity->name,
322  'desc' => strip_tags($entity->description),
323  'guid' => $entity->guid,
324  'label' => $output,
325  'value' => $entity->guid,
326  'icon' => $icon,
327  'url' => $entity->getURL(),
328  );
329 
330  $results[$entity->name . rand(1, 100)] = $result;
331  }
332  }
333  break;
334 
335  case 'friends':
336  $options = array(
337  'type' => 'user',
338  'limit' => $limit,
339  'relationship' => 'friend',
340  'relationship_guid' => $user->getGUID(),
341  'joins' => array("JOIN {$dbprefix}users_entity ue ON e.guid = ue.guid"),
342  'wheres' => array(
343  "ue.banned = 'no'",
344  "(ue.name LIKE '$q%' OR ue.name LIKE '% $q%' OR ue.username LIKE '$q%')"
345  )
346  );
347 
349  if (!empty($entities)) {
350  foreach ($entities as $entity) {
351 
352  $output = elgg_view_list_item($entity, array(
353  'use_hover' => false,
354  'use_link' => false,
355  'class' => 'elgg-autocomplete-item',
356  'title' => $entity->name, // Default title would be a link
357  ));
358 
359  $icon = elgg_view_entity_icon($entity, 'tiny', array(
360  'use_hover' => false,
361  ));
362 
363  $result = array(
364  'type' => 'user',
365  'name' => $entity->name,
366  'desc' => $entity->username,
367  'guid' => $entity->guid,
368  'label' => $output,
369  'value' => $entity->username,
370  'icon' => $icon,
371  'url' => $entity->getURL(),
372  'html' => elgg_view('input/userpicker/item', array(
373  'entity' => $entity,
374  'input_name' => $input_name,
375  )),
376  );
377  $results[$entity->name . rand(1, 100)] = $result;
378  }
379  }
380  break;
381 
382  default:
383  header("HTTP/1.0 400 Bad Request", true);
384  echo "livesearch: unknown match_on of $match_type";
385  exit;
386  break;
387  }
388  }
389 
390  ksort($results);
391  header("Content-Type: application/json");
392  echo json_encode(array_values($results));
393  exit;
394 }
395 
405  if (is_array($array)) {
406  $array2 = array();
407  foreach ($array as $key => $data) {
408  if ($key != stripslashes($key)) {
409  $array2[stripslashes($key)] = $data;
410  } else {
411  $array2[$key] = $data;
412  }
413  }
414  return $array2;
415  } else {
416  return $array;
417  }
418 }
419 
429  if (is_array($value)) {
431  $value = array_map('_elgg_stripslashes_deep', $value);
432  } else {
433  $value = stripslashes($value);
434  }
435  return $value;
436 }
437 
444 function _elgg_input_init() {
445  // register an endpoint for live search / autocomplete.
446  elgg_register_page_handler('livesearch', 'input_livesearch_page_handler');
447 
448  // backward compatible for plugins directly accessing globals
449  if (get_magic_quotes_gpc()) {
450  $_POST = array_map('_elgg_stripslashes_deep', $_POST);
451  $_GET = array_map('_elgg_stripslashes_deep', $_GET);
452  $_COOKIE = array_map('_elgg_stripslashes_deep', $_COOKIE);
453  $_REQUEST = array_map('_elgg_stripslashes_deep', $_REQUEST);
454  if (!empty($_SERVER['REQUEST_URI'])) {
455  $_SERVER['REQUEST_URI'] = stripslashes($_SERVER['REQUEST_URI']);
456  }
457  if (!empty($_SERVER['QUERY_STRING'])) {
458  $_SERVER['QUERY_STRING'] = stripslashes($_SERVER['QUERY_STRING']);
459  }
460  if (!empty($_SERVER['HTTP_REFERER'])) {
461  $_SERVER['HTTP_REFERER'] = stripslashes($_SERVER['HTTP_REFERER']);
462  }
463  if (!empty($_SERVER['PATH_INFO'])) {
464  $_SERVER['PATH_INFO'] = stripslashes($_SERVER['PATH_INFO']);
465  }
466  if (!empty($_SERVER['PHP_SELF'])) {
467  $_SERVER['PHP_SELF'] = stripslashes($_SERVER['PHP_SELF']);
468  }
469  if (!empty($_SERVER['PATH_TRANSLATED'])) {
470  $_SERVER['PATH_TRANSLATED'] = stripslashes($_SERVER['PATH_TRANSLATED']);
471  }
472  }
473 }
474 
475 return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) {
476  $events->registerHandler('init', 'system', '_elgg_input_init');
477 };
elgg_is_sticky_form($form_name)
Has this form been made sticky?
Definition: input.php:131
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
$dbprefix
Definition: index.php:13
elgg_clear_sticky_value($form_name, $variable)
Clear a specific sticky variable.
Definition: input.php:175
get_input($variable, $default=null, $filter_result=true)
Get some input from variables passed submitted through GET or POST.
Definition: input.php:27
elgg_get_sticky_value($form_name, $variable= '', $default=null, $filter_result=true)
Get a specific sticky variable.
Definition: input.php:148
current_page_url()
Returns the current page&#39;s complete URL.
Definition: input.php:65
elgg_clear_sticky_form($form_name)
Clear the sticky form cache.
Definition: input.php:119
$input_name
Definition: item.php:14
$data
Definition: opendd.php:13
$value
Definition: longtext.php:26
set_input($variable, $value)
Sets an input value that may later be retrieved by get_input.
Definition: input.php:41
$default
Definition: checkbox.php:34
filter_tags($var)
Filter tags from a given string based on registered hooks.
Definition: input.php:53
exit
Definition: reorder.php:12
elgg parse_url
Parse a URL into its parts.
Definition: elgglib.js:432
$url
Definition: exceptions.php:24
if(!$owner) $icon
Definition: default.php:16
elgg_view_list_item($item, array $vars=array())
View an item in a list.
Definition: views.php:1378
$options
Definition: index.php:14
$owner_guid
$limit
Definition: userpicker.php:31
$key
Definition: summary.php:34
_elgg_services()
Definition: autoloader.php:14
input_livesearch_page_handler($page)
Page handler for autocomplete endpoint.
Definition: input.php:196
sanitise_string($string)
Wrapper function for alternate English spelling (.
Definition: database.php:150
$user
Definition: ban.php:13
const ELGG_ENTITIES_ANY_VALUE
Definition: elgglib.php:1967
elgg echo
Translates a string.
Definition: languages.js:43
elgg_get_entities(array $options=array())
Returns an array of entities with optional filtering.
Definition: entities.php:490
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
Definition: elgglib.php:775
elgg_register_page_handler($identifier, $function)
Registers a page handler for a particular identifier.
Definition: pagehandler.php:34
elgg_get_site_url($site_guid=0)
Get the URL for the current (or specified) site.
elgg_view($view, $vars=array(), $bypass=false, $ignored=false, $viewtype= '')
Return a parsed view.
Definition: views.php:354
_elgg_stripslashes_arraykeys($array)
Strip slashes from array keys.
Definition: input.php:404
_elgg_input_init()
Initialize the input library.
Definition: input.php:444
_elgg_stripslashes_deep($value)
Strip slashes.
Definition: input.php:428
elgg_is_active_plugin($plugin_id, $site_guid=null)
Returns if a plugin is active for a current site.
Definition: plugins.php:135
sanitise_int($int, $signed=true)
Sanitizes an integer for database use.
Definition: database.php:173
elgg_get_logged_in_user_entity()
Return the current logged in user, or null if no user is logged in.
Definition: sessions.php:32
clearfix elgg elgg elgg elgg page header
Definition: admin.php:127
elgg_get_entities_from_relationship($options)
Return entities matching a given query joining against a relationship.
$output
Definition: item.php:10
elgg_make_sticky_form($form_name)
Load all the GET and POST variables into the sticky form cache.
Definition: input.php:103
$entity
Definition: delete.php:10
is_email_address($address)
Validates an email address.
Definition: input.php:88
elgg_view_entity_icon(\ElggEntity $entity, $size= 'medium', $vars=array())
View the icon of an entity.
Definition: views.php:865
elgg_get_sticky_values($form_name, $filter_result=true)
Get all the values in a sticky form in an array.
Definition: input.php:162