Elgg  Version 3.0
Namespaces | Functions
pagehandler.php File Reference

Go to the source code of this file.

Namespaces

 Elgg\Core
 Updates the advanced settings for the primary site object.
 

Functions

 elgg_register_route ($name, array $params=[])
 Register a new route. More...
 
 elgg_unregister_route ($name)
 Unregister a route by its name. More...
 
 elgg_generate_url ($name, array $parameters=[])
 Generate a URL for named route. More...
 
 elgg_generate_entity_url (ElggEntity $entity, $resource= 'view', $subresource=null, array $parameters=[])
 Generate entity URL from a named route. More...
 
 elgg_generate_action_url ($action, array $query=[], $add_csrf_tokens=true)
 Generate an action URL. More...
 
 elgg_gatekeeper ()
 Used at the top of a page to mark it as logged in users only. More...
 
 elgg_admin_gatekeeper ()
 Used at the top of a page to mark it as admin only. More...
 
 elgg_entity_gatekeeper ($guid, $type=null, $subtype=null)
 Can the viewer see this entity? More...
 
 elgg_ajax_gatekeeper ()
 Require that the current request be an XHR. More...
 
 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. More...
 
 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. More...
 
 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. More...
 

Function Documentation

elgg_admin_gatekeeper ( )

Used at the top of a page to mark it as admin only.

Returns
void
Exceptions

Definition at line 153 of file pagehandler.php.

elgg_ajax_gatekeeper ( )

Require that the current request be an XHR.

If not, execution of the current function will end and a 400 response page will be sent.

Returns
void
Exceptions

Definition at line 189 of file pagehandler.php.

elgg_entity_gatekeeper (   $guid,
  $type = null,
  $subtype = null 
)

Can the viewer see this entity?

Tests if the entity exists and whether the viewer has access to the entity if it does. If the viewer cannot view this entity, it forwards to an appropriate page.

Parameters
int$guidEntity GUID
string$typeOptional required entity type
string$subtypeOptional required entity subtype
Returns
void
Exceptions
Exception

Definition at line 176 of file pagehandler.php.

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.

Parameters
string$errorError message Can be used by handlers to display an error message For certain requests this error message will also be used as the response body
string$forward_urlURL to redirect the client to Can be used by handlers to redirect the client on non-ajax requests
int$status_codeHTTP status code Status code of the HTTP response For BC reasons and due to the logic in the client-side AJAX API, this defaults to 200. Note that the Router and AJAX API will treat these responses as error in spite of the HTTP code assigned
Returns

Definition at line 233 of file pagehandler.php.

elgg_gatekeeper ( )

Used at the top of a page to mark it as logged in users only.

Returns
void
Exceptions

Definition at line 142 of file pagehandler.php.

elgg_generate_action_url (   $action,
array  $query = [],
  $add_csrf_tokens = true 
)

Generate an action URL.

Parameters
string$actionAction name
array$queryQuery elements
bool$add_csrf_tokensAdd tokens
Returns
string
Examples:
/root/Elgg/engine/classes/Elgg/FormsService.php.

Definition at line 122 of file pagehandler.php.

elgg_generate_entity_url ( ElggEntity  $entity,
  $resource = 'view',
  $subresource = null,
array  $parameters = [] 
)

Generate entity URL from a named route.

This function is intended to generate URLs from registered named routes that depend on entity type and subtype. It will first try to detect routes that contain both type and subtype in the name, and will then fallback to route names without the subtype, e.g. 'view:object:blog:attachments' and 'view:object:attachments'

Route segments will be automatically resolved from entity attributes and metadata, so given the path /blog/view/{guid}/{title}/{status} the path will be be resolved from entity guid, URL-friendly title and status metadata.

Parameters that do not have matching segment names in the route path, will be added to the URL as query elements.

Parameters
ElggEntity$entityEntity
string$resourceResource name
string$subresourceSubresource name
array$parametersURL query elements
Returns
false|string

Definition at line 84 of file pagehandler.php.

elgg_generate_url (   $name,
array  $parameters = [] 
)

Generate a URL for named route.

Parameters
string$nameRoute name
array$parametersParameters
Returns
false|string

Definition at line 58 of file pagehandler.php.

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.

Parameters
mixed$contentResponse content In page handlers, response content should contain an HTML string In action handlers, response content can contain either a JSON string or an array of data
string$messageSystem message visible to the client Can be used by handlers to display a system message
string$forward_urlForward URL Can be used by handlers to redirect the client on non-ajax requests
int$status_codeHTTP status code Status code of the HTTP response (defaults to 200)
Returns

Definition at line 208 of file pagehandler.php.

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.

Parameters
string$forward_urlRedirection URL Relative or absolute URL to redirect the client to
int$status_codeHTTP status code Status code of the HTTP response Note that the Router and AJAX API will treat these responses as redirection in spite of the HTTP code assigned Note that non-redirection HTTP codes will throw an exception
Returns
Exceptions

Definition at line 255 of file pagehandler.php.

elgg_register_route (   $name,
array  $params = [] 
)

Register a new route.

Route paths can contain wildcard segments, i.e. /blog/owner/{username} To make a certain wildcard segment optional, add ? to its name, i.e. /blog/owner/{username?}

Wildcard requirements for common named variables such as 'guid' and 'username' will be set automatically.

Warning
If you are registering a route in the path of a route registered by deprecated elgg_register_page_handler, your registration must preceed the call to elgg_register_page_handler() in the boot sequence.
Parameters
string$nameUnique route name This name can later be used to generate route URLs
array$paramsRoute parameters
  • path : path of the route
  • resource : name of the resource view
  • defaults : default values of wildcard segments
  • requirements : regex patterns for wildcard segment requirements
  • methods : HTTP methods
Returns
Exceptions
InvalidParameterException

Definition at line 35 of file pagehandler.php.

elgg_unregister_route (   $name)

Unregister a route by its name.

Parameters
string$nameName of the route
Returns
void

Definition at line 46 of file pagehandler.php.