Elgg  Version 6.1
livesearch.php
Go to the documentation of this file.
1 <?php
10 
11 /* @var $request \Elgg\Http\Request */
12 $request = elgg_extract('request', $vars);
13 
14 // pass all input params (GET & POST) into $vars
15 $input_params = $request->getParams();
16 $ignored_inputs = ['view', '_route'];
17 foreach ($input_params as $name => $value) {
18  if (in_array($name, $ignored_inputs)) {
19  continue;
20  }
21 
22  // request can contain wrong value
24 
25  // set request param in $vars, but don't overrule already set values
26  // extract with false in order to replace empty value in $vars with request data
28 }
29 
30 // term is used in jquery autocomplete, but sometimes q is passed as the query, this will put q into term
31 $vars['term'] = trim((string) elgg_extract('term', $vars, elgg_extract('q', $vars)));
32 
33 // check if we have a query
34 if (elgg_is_empty($vars['term'])) {
35  throw new BadRequestException(elgg_echo('BadRequestException:livesearch:no_query'));
36 }
37 
38 $vars['limit'] = (int) elgg_extract('limit', $vars, elgg_get_config('default_limit'));
39 
40 $match_on = elgg_extract('match_on', $vars);
41 
42 // livesearch will result in a json response
43 elgg_set_viewtype('json');
44 
45 if (!elgg_view_exists("resources/livesearch/$match_on")) {
46  throw new PageNotFoundException();
47 }
48 
49 echo elgg_view("resources/livesearch/$match_on", $vars);
$match_on
Definition: livesearch.php:40
elgg_get_config(string $name, $default=null)
Get an Elgg configuration value.
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
$request
Definition: livesearch.php:12
foreach($input_params as $name=> $value) $vars['term']
Definition: livesearch.php:31
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
$ignored_inputs
Definition: livesearch.php:16
$input_params
Definition: livesearch.php:15
$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_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:256
elgg_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
Definition: views.php:156
Thrown when page is not accessible.
elgg_set_viewtype(string $viewtype= '')
Manually set the viewtype.
Definition: views.php:60
Thrown when request is malformatted.
elgg_view_exists(string $view, string $viewtype= '', bool $recurse=true)
Returns whether the specified view exists.
Definition: views.php:131