Elgg  Version master
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 (string $header, bool $replace=true)
 Set a response HTTP header. More...
 
 elgg_register_success_message (string|array $options)
 Registers a success system message. More...
 
 elgg_register_error_message (string|array $options)
 Registers a error system message. More...
 
 elgg_log ($message, $level=\Psr\Log\LogLevel::NOTICE)
 Log a message. More...
 
 elgg_dump ($value)
 Logs $value to PHP's error_log(). More...
 
 elgg_deprecated_notice (string $msg, string $dep_version)
 Log a notice about deprecated use of a function, view, etc. More...
 
 elgg_http_build_url (array $parts, bool $html_encode=true)
 Builds a URL from the a parts array like one returned by parse_url(). More...
 
 elgg_add_action_tokens_to_url (string $url, bool $html_encode=false)
 Adds action tokens to URL. More...
 
 elgg_http_remove_url_query_element (string $url, string $element)
 Removes an element from a URL's query string. More...
 
 elgg_http_add_url_query_elements (string $url, array $elements)
 Sets elements in a URL's query string. More...
 
 elgg_http_url_is_identical (string $url1, string $url2, array $ignore_params=['offset', 'limit'])
 Test if two URLs are functionally identical. More...
 
 elgg_http_get_signed_url (string $url, string $expires=null)
 Signs provided URL with a SHA256 HMAC key. More...
 
 elgg_http_validate_signed_url (string $url)
 Validates if the HMAC signature of the URL is valid. More...
 
 elgg_get_http_client (array $options=[])
 Returns a Guzzle HTTP client. More...
 
 elgg_extract ($key, $array, $default=null, bool $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 (string $setting)
 Returns a PHP INI setting in bytes. More...
 
 _elgg_services ()
 Get the global service provider. More...
 

Function Documentation

_elgg_services ( )
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 ( string  $url,
bool  $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 154 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 301 of file elgglib.php.

elgg_deprecated_notice ( string  $msg,
string  $dep_version 
)

Log a notice about deprecated use of a function, view, etc.

Parameters
string$msgMessage to log
string$dep_versionHuman-readable release version: 1.7, 1.8, ...
Returns
true
Since
1.7.0

Definition at line 115 of file elgglib.php.

elgg_dump (   $value)

Logs $value to PHP's error_log().

A 'debug', log' event is triggered. 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 102 of file elgglib.php.

elgg_extract (   $key,
  $array,
  $default = null,
bool  $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 | int$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 256 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/classes/Elgg/FormsService.php, and /root/Elgg/engine/lib/views.php.

Definition at line 278 of file elgglib.php.

elgg_get_http_client ( array  $options = [])

Returns a Guzzle HTTP client.

Parameters
array$optionsOptions for the client
Returns

Definition at line 237 of file elgglib.php.

elgg_get_ini_setting_in_bytes ( string  $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 316 of file elgglib.php.

elgg_http_add_url_query_elements ( string  $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 183 of file elgglib.php.

elgg_http_build_url ( array  $parts,
bool  $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?
Returns
string Full URL
Since
1.7.0

Definition at line 133 of file elgglib.php.

elgg_http_get_signed_url ( string  $url,
string  $expires = null 
)

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() Null value indicate non-expiring URL
Returns
string

Definition at line 216 of file elgglib.php.

elgg_http_remove_url_query_element ( string  $url,
string  $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 169 of file elgglib.php.

elgg_http_url_is_identical ( string  $url1,
string  $url2,
array  $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 201 of file elgglib.php.

elgg_http_validate_signed_url ( string  $url)

Validates if the HMAC signature of the URL is valid.

Parameters
string$urlURL to validate
Returns
bool

Definition at line 226 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 86 of file elgglib.php.

elgg_register_error_message ( string|array  $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_success_message ( string|array  $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 ( string  $header,
bool  $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.