Elgg  Version 4.x
Functions
elgglib.php File Reference

Go to the source code of this file.

Functions

 elgg ()
 Bootstrapping and helper procedural code available for use in Elgg core and plugins. More...
 
 elgg_set_http_header ($header, $replace=true)
 Set a response HTTP header. More...
 
 elgg_register_success_message ($options)
 Registers a success system message. More...
 
 elgg_register_error_message ($options)
 Registers a error system message. More...
 
 elgg_register_event_handler ($event, $object_type, $callback, $priority=500)
 
 elgg_unregister_event_handler ($event, $object_type, $callback)
 Unregisters a callback for an event. More...
 
 elgg_clear_event_handlers ($event, $object_type)
 Clears all callback registrations for a event. More...
 
 elgg_trigger_event ($event, $object_type, $object=null)
 
 elgg_trigger_before_event ($event, $object_type, $object=null)
 Trigger a "Before event" indicating a process is about to begin. More...
 
 elgg_trigger_after_event ($event, $object_type, $object=null)
 Trigger an "After event" indicating a process has finished. More...
 
 elgg_register_plugin_hook_handler ($hook, $type, $callback, $priority=500)
 
 elgg_unregister_plugin_hook_handler ($hook, $entity_type, $callback)
 Unregister a callback as a plugin hook. More...
 
 elgg_clear_plugin_hook_handlers ($hook, $type)
 Clears all callback registrations for a plugin hook. More...
 
 elgg_trigger_plugin_hook ($hook, $type, $params=null, $returnvalue=null)
 
 elgg_log ($message, $level=\Psr\Log\LogLevel::NOTICE)
 Log a message. More...
 
 elgg_dump ($value)
 Logs $value to PHP's error_log(). More...
 
 elgg_http_build_url (array $parts, $html_encode=true)
 Builds a URL from the a parts array like one returned by parse_url(). More...
 
 elgg_add_action_tokens_to_url ($url, $html_encode=false)
 Adds action tokens to URL. More...
 
 elgg_http_remove_url_query_element ($url, $element)
 Removes an element from a URL's query string. More...
 
 elgg_http_add_url_query_elements ($url, array $elements)
 Sets elements in a URL's query string. More...
 
 elgg_http_url_is_identical ($url1, $url2, $ignore_params=['offset', 'limit'])
 Test if two URLs are functionally identical. More...
 
 elgg_http_get_signed_url ($url, $expires=false)
 Signs provided URL with a SHA256 HMAC key. More...
 
 elgg_http_validate_signed_url ($url)
 Validates if the HMAC signature of the URL is valid. More...
 
 elgg_extract ($key, $array, $default=null, $strict=true)
 Checks for $array[$key] and returns its value if it exists, else returns $default. More...
 
 elgg_extract_class (array $array, $existing=[], $extract_key= 'class')
 Extract class names from an array, optionally merging into a preexisting set. More...
 
 elgg_call (int $flags, Closure $closure)
 Calls a callable autowiring the arguments using public DI services and applying logic based on flags. More...
 
 elgg_get_ini_setting_in_bytes ($setting)
 Returns a PHP INI setting in bytes. More...
 
 _elgg_services ()
 Get the global service provider. More...
 
 _elgg_array_diff_assoc_recursive ()
 Computes the difference of arrays with additional index check. More...
 

Function Documentation

_elgg_array_diff_assoc_recursive ( )

Computes the difference of arrays with additional index check.

Returns
array
Since
4.1

Definition at line 793 of file elgglib.php.

_elgg_services ( )

Get the global service provider.

Returns
Examples:
/root/Elgg/engine/classes/ElggBatch.php, /root/Elgg/engine/lib/output.php, and /root/Elgg/engine/lib/views.php.

Definition at line 777 of file elgglib.php.

elgg ( )

Bootstrapping and helper procedural code available for use in Elgg core and plugins.

Get a reference to the public service provider

Returns
Since
2.0.0

Definition at line 12 of file elgglib.php.

elgg_add_action_tokens_to_url (   $url,
  $html_encode = false 
)

Adds action tokens to URL.

As of 1.7.0 action tokens are required on all actions. Use this function to append action tokens to a URL's GET parameters. This will preserve any existing GET parameters.

Note
If you are using { input/form} you don't need to add tokens to the action. The form view automatically handles tokens.
Parameters
string$urlFull action URL
bool$html_encodeHTML encode the url? (default: false)
Returns
string URL with action tokens
Since
1.7.0

Definition at line 467 of file elgglib.php.

elgg_call ( int  $flags,
Closure  $closure 
)

Calls a callable autowiring the arguments using public DI services and applying logic based on flags.

Parameters
int$flagsBitwise flags ELGG_IGNORE_ACCESS ELGG_ENFORCE_ACCESS ELGG_SHOW_DISABLED_ENTITIES ELGG_HIDE_DISABLED_ENTITIES
Closure$closureCallable to call
Returns
mixed

Definition at line 731 of file elgglib.php.

elgg_clear_event_handlers (   $event,
  $object_type 
)

Clears all callback registrations for a event.

Parameters
string$eventThe name of the event
string$object_typeThe objecttype of the event
Returns
void
Since
2.3

Definition at line 153 of file elgglib.php.

elgg_clear_plugin_hook_handlers (   $hook,
  $type 
)

Clears all callback registrations for a plugin hook.

Parameters
string$hookThe name of the hook
string$typeThe type of the hook
Returns
void
Since
2.0

Definition at line 322 of file elgglib.php.

elgg_dump (   $value)

Logs $value to PHP's error_log().

A { debug log} is called. If a handler returns false, it will stop the default logging method.

Note
Use the developers plugin to display logs
Parameters
mixed$valueThe value
Returns
void
Since
1.7.0

Definition at line 415 of file elgglib.php.

elgg_extract (   $key,
  $array,
  $default = null,
  $strict = true 
)

Checks for $array[$key] and returns its value if it exists, else returns $default.

Shorthand for $value = (isset($array['key'])) ? $array['key'] : 'default';

Parameters
string$keyKey to check in the source array
array$arraySource array
mixed$defaultValue to return if key is not found
bool$strictReturn array key if it's set, even if empty. If false, return $default if the array key is unset or empty.
Returns
mixed
Since
1.8.0
Examples:
/root/Elgg/engine/classes/Elgg/FormsService.php, /root/Elgg/engine/classes/ElggBatch.php, and /root/Elgg/engine/lib/views.php.

Definition at line 686 of file elgglib.php.

elgg_extract_class ( array  $array,
  $existing = [],
  $extract_key = 'class' 
)

Extract class names from an array, optionally merging into a preexisting set.

Parameters
array$arraySource array
string|string[]$existing Existing name(s)
string$extract_keyKey to extract new classes from
Returns
string[]
Since
2.3.0
Examples:
/root/Elgg/engine/lib/views.php.

Definition at line 708 of file elgglib.php.

elgg_get_ini_setting_in_bytes (   $setting)

Returns a PHP INI setting in bytes.

Use this for arithmetic when determining if a file can be uploaded.

Parameters
string$settingThe php.ini setting
Returns
int
Since
1.7.0 http://www.php.net/manual/en/function.ini-get.php

Definition at line 746 of file elgglib.php.

elgg_http_add_url_query_elements (   $url,
array  $elements 
)

Sets elements in a URL's query string.

Parameters
string$urlThe URL
array$elementsKey/value pairs to set in the URL. If the value is null, the element is removed from the URL.
Returns
string The new URL with the query strings added
Since
1.7.0

Definition at line 515 of file elgglib.php.

elgg_http_build_url ( array  $parts,
  $html_encode = true 
)

Builds a URL from the a parts array like one returned by parse_url().

Note
If only partial information is passed, a partial URL will be returned.
Parameters
array$partsAssociative array of URL components like parse_url() returns 'user' and 'pass' parts are ignored because of security reasons
bool$html_encodeHTML Encode the url?
See also
https://github.com/Elgg/Elgg/pull/8146#issuecomment-91544585
Returns
string Full URL
Since
1.7.0

Definition at line 432 of file elgglib.php.

elgg_http_get_signed_url (   $url,
  $expires = false 
)

Signs provided URL with a SHA256 HMAC key.

Note
Signed URLs do not offer CSRF protection and should not be used instead of action tokens.
Parameters
string$urlURL to sign
string$expiresExpiration time A string suitable for strtotime() Falsey values indicate non-expiring URL
Returns
string

Definition at line 657 of file elgglib.php.

elgg_http_remove_url_query_element (   $url,
  $element 
)

Removes an element from a URL's query string.

Note
You can send a partial URL string.
Parameters
string$urlFull URL
string$elementThe element to remove
Returns
string The new URL with the query element removed.
Since
1.7.0

Definition at line 501 of file elgglib.php.

elgg_http_url_is_identical (   $url1,
  $url2,
  $ignore_params = ['offset',
'limit']   
)

Test if two URLs are functionally identical.

If $ignore_params is used, neither the name nor its value will be considered when comparing.

The order of GET params doesn't matter.

Parameters
string$url1First URL
string$url2Second URL
array$ignore_paramsGET params to ignore in the comparison
Returns
bool
Since
1.8.0

Definition at line 564 of file elgglib.php.

elgg_http_validate_signed_url (   $url)

Validates if the HMAC signature of the URL is valid.

Parameters
string$urlURL to validate
Returns
bool

Definition at line 667 of file elgglib.php.

elgg_log (   $message,
  $level = \Psr\Log\LogLevel::NOTICE 
)

Log a message.

If $level is >= to the debug setting in ->debug, the message will be sent to elgg_dump(). Messages with lower priority than ->debug are ignored.

Note
Use the developers plugin to display logs
Parameters
string$messageUser message
string$levelNOTICE | WARNING | ERROR
Returns
bool
Since
1.7.0
Examples:
/root/Elgg/engine/lib/views.php.

Definition at line 399 of file elgglib.php.

elgg_register_error_message (   $options)

Registers a error system message.

Parameters
string | array$optionsa single string or an array of system message options
See also
::factory()
Returns
void
Since
4.2

Definition at line 62 of file elgglib.php.

elgg_register_event_handler (   $event,
  $object_type,
  $callback,
  $priority = 500 
)

Definition at line 126 of file elgglib.php.

elgg_register_plugin_hook_handler (   $hook,
  $type,
  $callback,
  $priority = 500 
)

Definition at line 294 of file elgglib.php.

elgg_register_success_message (   $options)

Registers a success system message.

Parameters
string | array$optionsa single string or an array of system message options
See also
::factory()
Returns
void
Since
4.2

Definition at line 43 of file elgglib.php.

elgg_set_http_header (   $header,
  $replace = true 
)

Set a response HTTP header.

See also
header()
Parameters
string$headerHeader
bool$replaceReplace existing header
Returns
void
Since
2.3

Definition at line 26 of file elgglib.php.

elgg_trigger_after_event (   $event,
  $object_type,
  $object = null 
)

Trigger an "After event" indicating a process has finished.

Unlike regular events, all the handlers will be called, their return values ignored.

To register for an after event, append ":after" to the event name when registering.

Parameters
string$eventThe event type. The fired event type will be appended with ":after".
string$object_typeThe object type
string$objectThe object involved in the event
Returns
true
See also
elgg_trigger_before_event()

Definition at line 230 of file elgglib.php.

elgg_trigger_before_event (   $event,
  $object_type,
  $object = null 
)

Trigger a "Before event" indicating a process is about to begin.

Like regular events, a handler returning false will cancel the process and false will be returned.

To register for a before event, append ":before" to the event name when registering.

Parameters
string$eventThe event type. The fired event type will be appended with ":before".
string$object_typeThe object type
mixed$objectThe object involved in the event
Returns
bool False if any handler returned false, otherwise true
See also
elgg_trigger_event()
elgg_trigger_after_event()

Definition at line 211 of file elgglib.php.

elgg_trigger_event (   $event,
  $object_type,
  $object = null 
)

Definition at line 190 of file elgglib.php.

elgg_trigger_plugin_hook (   $hook,
  $type,
  $params = null,
  $returnvalue = null 
)
elgg_unregister_event_handler (   $event,
  $object_type,
  $callback 
)

Unregisters a callback for an event.

Parameters
string$eventThe event type
string$object_typeThe object type
callable$callbackThe callback. Since 1.11, static method callbacks will match dynamic methods
Returns
bool true if a handler was found and removed
Since
1.7

Definition at line 140 of file elgglib.php.

elgg_unregister_plugin_hook_handler (   $hook,
  $entity_type,
  $callback 
)

Unregister a callback as a plugin hook.

Parameters
string$hookThe name of the hook
string$entity_typeThe name of the type of entity (eg "user", "object" etc)
callable$callbackThe PHP callback to be removed. Since 1.11, static method callbacks will match dynamic methods
Returns
void
Since
1.8.0

Definition at line 309 of file elgglib.php.