Elgg  Version 3.0
pagehandler.php
Go to the documentation of this file.
1 <?php
35 function elgg_register_route($name, array $params = []) {
36  return _elgg_services()->routes->register($name, $params);
37 }
38 
47  _elgg_services()->routes->unregister($name);
48 }
49 
58 function elgg_generate_url($name, array $parameters = []) {
59  return _elgg_services()->routes->generateUrl($name, $parameters);
60 }
61 
84 function elgg_generate_entity_url(ElggEntity $entity, $resource = 'view', $subresource = null, array $parameters = []) {
85 
86  $make_route_name = function ($type, $subtype) use ($resource, $subresource) {
87  $route_parts = [
88  $resource,
89  $type,
90  $subtype,
91  $subresource,
92  ];
93 
94  return implode(':', array_filter($route_parts));
95  };
96 
97  $pairs = [
98  [$entity->type, $entity->subtype],
99  [$entity->type, null],
100  ];
101 
102  foreach ($pairs as $pair) {
103  $route_name = $make_route_name($pair[0], $pair[1]);
104  $params = _elgg_services()->routes->resolveRouteParameters($route_name, $entity, $parameters);
105  if ($params !== false) {
106  return elgg_generate_url($route_name, $params);
107  }
108  }
109 
110  return false;
111 }
112 
122 function elgg_generate_action_url($action, array $query = [], $add_csrf_tokens = true) {
123 
124  $url = "action/$action";
127 
128  if ($add_csrf_tokens) {
130  }
131 
132  return $url;
133 }
134 
142 function elgg_gatekeeper() {
143  _elgg_services()->gatekeeper->assertAuthenticatedUser();
144 }
145 
154  _elgg_services()->gatekeeper->assertAuthenticatedAdmin();
155 }
156 
176 function elgg_entity_gatekeeper($guid, $type = null, $subtype = null) {
177  $entity = _elgg_services()->gatekeeper->assertExists($guid, $type, $subtype);
178  _elgg_services()->gatekeeper->assertAccessibleEntity($entity);
179 }
180 
190  _elgg_services()->gatekeeper->assertXmlHttpRequest();
191 }
192 
208 function elgg_ok_response($content = '', $message = '', $forward_url = null, $status_code = ELGG_HTTP_OK) {
209  if ($message) {
211  }
212 
213  return new \Elgg\Http\OkResponse($content, $status_code, $forward_url);
214 
215 }
216 
233 function elgg_error_response($error = '', $forward_url = REFERRER, $status_code = ELGG_HTTP_OK) {
234  if ($error) {
236  }
237 
238  return new \Elgg\Http\ErrorResponse($error, $status_code, $forward_url);
239 }
240 
256  return new Elgg\Http\RedirectResponse($forward_url, $status_code);
257 }
elgg_http_add_url_query_elements($url, array $elements)
Sets elements in a URL&#39;s query string.
Definition: elgglib.php:942
$query
Definition: groups.php:8
$action
Definition: full.php:111
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
if(!$entity->delete()) $forward_url
Definition: delete.php:30
elgg_add_action_tokens_to_url($url, $html_encode=false)
Adds action tokens to URL.
Definition: elgglib.php:894
$params
Saves global plugin settings.
Definition: save.php:13
elgg_normalize_url($url)
Definition: output.php:186
elgg_generate_action_url($action, array $query=[], $add_csrf_tokens=true)
Generate an action URL.
elgg_redirect_response($forward_url=REFERRER, $status_code=ELGG_HTTP_FOUND)
Prepare a silent redirect response to be returned by a page or an action handler. ...
const ELGG_HTTP_OK
Definition: constants.php:60
elgg_unregister_route($name)
Unregister a route by its name.
Definition: pagehandler.php:46
$subtype
Definition: delete.php:22
$guid
Removes an admin notice.
$type
Definition: delete.php:21
elgg_entity_gatekeeper($guid, $type=null, $subtype=null)
Can the viewer see this entity?
$resource
elgg_gatekeeper()
Used at the top of a page to mark it as logged in users only.
$error
Bad request error.
Definition: 400.php:6
const REFERRER
Definition: constants.php:42
$entity
Definition: reset.php:8
elgg_error_response($error= '', $forward_url=REFERRER, $status_code=ELGG_HTTP_OK)
Prepare an error response to be returned by a page or an action handler.
elgg_generate_url($name, array $parameters=[])
Generate a URL for named route.
Definition: pagehandler.php:58
$url
Definition: default.php:33
elgg_ajax_gatekeeper()
Require that the current request be an XHR.
const ELGG_HTTP_FOUND
Definition: constants.php:72
elgg_register_route($name, array $params=[])
Register a new route.
Definition: pagehandler.php:35
elgg system_message
Wrapper function for system_messages.
Definition: elgglib.js:382
elgg_ok_response($content= '', $message= '', $forward_url=null, $status_code=ELGG_HTTP_OK)
Prepares a successful response to be returned by a page or an action handler.
elgg_admin_gatekeeper()
Used at the top of a page to mark it as admin only.
elgg register_error
Wrapper function for system_messages.
Definition: elgglib.js:391
$content
Set robots.txt action.
Definition: set_robots.php:6
_elgg_services()
Get the global service provider.
Definition: elgglib.php:1292
elgg_generate_entity_url(ElggEntity $entity, $resource= 'view', $subresource=null, array $parameters=[])
Generate entity URL from a named route.
Definition: pagehandler.php:84