Elgg  Version 4.3
elgglib.php
Go to the documentation of this file.
1 <?php
12 function elgg() {
13  return \Elgg\Application::$_instance->public_services;
14 }
15 
26 function elgg_set_http_header($header, $replace = true) {
27  if (!preg_match('~^HTTP/\\d\\.\\d~', $header)) {
28  list($name, $value) = explode(':', $header, 2);
29  _elgg_services()->responseFactory->setHeader($name, ltrim($value), $replace);
30  }
31 }
32 
44  if (!is_array($options)) {
45  $options = ['message' => $options];
46  }
47 
48  $options['type'] = 'success';
49  _elgg_services()->system_messages->addMessage($options);
50 }
51 
63  if (!is_array($options)) {
64  $options = ['message' => $options];
65  }
66 
67  $options['type'] = 'error';
68  _elgg_services()->system_messages->addMessage($options);
69 }
70 
126 function elgg_register_event_handler($event, $object_type, $callback, $priority = 500) {
127  return _elgg_services()->events->registerHandler($event, $object_type, $callback, $priority);
128 }
129 
140 function elgg_unregister_event_handler($event, $object_type, $callback) {
141  return _elgg_services()->events->unregisterHandler($event, $object_type, $callback);
142 }
143 
153 function elgg_clear_event_handlers($event, $object_type) {
154  _elgg_services()->events->clearHandlers($event, $object_type);
155 }
156 
190 function elgg_trigger_event($event, $object_type, $object = null) {
191  return _elgg_services()->events->trigger($event, $object_type, $object);
192 }
193 
211 function elgg_trigger_before_event($event, $object_type, $object = null) {
212  return _elgg_services()->events->triggerBefore($event, $object_type, $object);
213 }
214 
230 function elgg_trigger_after_event($event, $object_type, $object = null) {
231  return _elgg_services()->events->triggerAfter($event, $object_type, $object);
232 }
233 
294 function elgg_register_plugin_hook_handler($hook, $type, $callback, $priority = 500) {
295  return _elgg_services()->hooks->registerHandler($hook, $type, $callback, $priority);
296 }
297 
309 function elgg_unregister_plugin_hook_handler($hook, $entity_type, $callback) {
310  _elgg_services()->hooks->unregisterHandler($hook, $entity_type, $callback);
311 }
312 
323  _elgg_services()->hooks->clearHandlers($hook, $type);
324 }
325 
380 function elgg_trigger_plugin_hook($hook, $type, $params = null, $returnvalue = null) {
381  return _elgg_services()->hooks->trigger($hook, $type, $params, $returnvalue);
382 }
383 
399 function elgg_log($message, $level = \Psr\Log\LogLevel::NOTICE) {
400  return _elgg_services()->logger->log($level, $message);
401 }
402 
415 function elgg_dump($value) {
416  _elgg_services()->logger->dump($value);
417 }
418 
431 function elgg_http_build_url(array $parts, $html_encode = true): string {
432  return _elgg_services()->urls->buildUrl($parts, (bool) $html_encode);
433 }
434 
452 function elgg_add_action_tokens_to_url($url, $html_encode = false): string {
453  return _elgg_services()->urls->addActionTokensToUrl((string) $url, (bool) $html_encode);
454 }
455 
467 function elgg_http_remove_url_query_element($url, $element): string {
468  return _elgg_services()->urls->addQueryElementsToUrl((string) $url, [(string) $element => null]);
469 }
470 
481 function elgg_http_add_url_query_elements($url, array $elements): string {
482  return _elgg_services()->urls->addQueryElementsToUrl((string) $url, $elements);
483 }
484 
499 function elgg_http_url_is_identical($url1, $url2, $ignore_params = ['offset', 'limit']): bool {
500  if (!is_string($url1) || !is_string($url2)) {
501  return false;
502  }
503 
504  return _elgg_services()->urls->isUrlIdentical($url1, $url2, (array) $ignore_params);
505 }
506 
518 function elgg_http_get_signed_url($url, $expires = false) {
519  return _elgg_services()->urlSigner->sign($url, $expires);
520 }
521 
529  return _elgg_services()->urlSigner->isValid($url);
530 }
531 
547 function elgg_extract($key, $array, $default = null, $strict = true) {
548  if (!is_array($array) && !$array instanceof ArrayAccess) {
549  return $default;
550  }
551 
552  if ($strict) {
553  return (isset($array[$key])) ? $array[$key] : $default;
554  } else {
555  return (isset($array[$key]) && !empty($array[$key])) ? $array[$key] : $default;
556  }
557 }
558 
569 function elgg_extract_class(array $array, $existing = [], $extract_key = 'class') {
570  $existing = empty($existing) ? [] : (array) $existing;
571 
572  $merge = (array) elgg_extract($extract_key, $array, []);
573 
574  array_splice($existing, count($existing), 0, $merge);
575 
576  return array_values(array_unique($existing));
577 }
578 
592 function elgg_call(int $flags, Closure $closure) {
593  return _elgg_services()->invoker->call($flags, $closure);
594 }
595 
607 function elgg_get_ini_setting_in_bytes($setting) {
608  // retrieve INI setting
609  $val = ini_get($setting);
610 
611  // convert INI setting when shorthand notation is used
612  $last = strtolower($val[strlen($val) - 1]);
613  if (in_array($last, ['g', 'm', 'k'])) {
614  $val = substr($val, 0, -1);
615  }
616  $val = (int) $val;
617  switch ($last) {
618  case 'g':
619  $val *= 1024;
620  // fallthrough intentional
621  case 'm':
622  $val *= 1024;
623  // fallthrough intentional
624  case 'k':
625  $val *= 1024;
626  }
627 
628  // return byte value
629  return $val;
630 }
631 
638 function _elgg_services() {
639  // This yields a more shallow stack depth in recursive APIs like views. This aids in debugging and
640  // reduces false positives in xdebug's infinite recursion protection.
641  return \Elgg\Application::$_instance->internal_services;
642 }
$default
Definition: checkbox.php:31
elgg_call(int $flags, Closure $closure)
Calls a callable autowiring the arguments using public DI services and applying logic based on flags...
Definition: elgglib.php:592
elgg_http_add_url_query_elements($url, array $elements)
Sets elements in a URL&#39;s query string.
Definition: elgglib.php:481
elgg_unregister_plugin_hook_handler($hook, $entity_type, $callback)
Unregister a callback as a plugin hook.
Definition: elgglib.php:309
elgg_add_action_tokens_to_url($url, $html_encode=false)
Adds action tokens to URL.
Definition: elgglib.php:452
$params
Saves global plugin settings.
Definition: save.php:13
elgg_set_http_header($header, $replace=true)
Set a response HTTP header.
Definition: elgglib.php:26
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
elgg_clear_plugin_hook_handlers($hook, $type)
Clears all callback registrations for a plugin hook.
Definition: elgglib.php:322
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
Definition: LICENSE.txt:215
elgg()
Bootstrapping and helper procedural code available for use in Elgg core and plugins.
Definition: elgglib.php:12
$type
Definition: delete.php:21
elgg_register_plugin_hook_handler($hook, $type, $callback, $priority=500)
Definition: elgglib.php:294
elgg_extract_class(array $array, $existing=[], $extract_key= 'class')
Extract class names from an array, optionally merging into a preexisting set.
Definition: elgglib.php:569
elgg_trigger_before_event($event, $object_type, $object=null)
Trigger a "Before event" indicating a process is about to begin.
Definition: elgglib.php:211
$options
Elgg admin footer.
Definition: footer.php:6
$value
Definition: generic.php:51
$header
Definition: database.php:26
elgg_get_ini_setting_in_bytes($setting)
Returns a PHP INI setting in bytes.
Definition: elgglib.php:607
elgg_http_url_is_identical($url1, $url2, $ignore_params=['offset', 'limit'])
Test if two URLs are functionally identical.
Definition: elgglib.php:499
elgg_http_remove_url_query_element($url, $element)
Removes an element from a URL&#39;s query string.
Definition: elgglib.php:467
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
Definition: elgglib.php:399
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
Definition: elgglib.php:380
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:547
elgg_dump($value)
Logs $value to PHP&#39;s error_log().
Definition: elgglib.php:415
elgg_register_event_handler($event, $object_type, $callback, $priority=500)
Definition: elgglib.php:126
elgg_register_error_message($options)
Registers a error system message.
Definition: elgglib.php:62
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:44
if($email instanceof\Elgg\Email) $object
Definition: body.php:24
elgg_http_build_url(array $parts, $html_encode=true)
Builds a URL from the a parts array like one returned by parse_url().
Definition: elgglib.php:431
foreach($plugin_guids as $guid) if(empty($deactivated_plugins)) $url
Definition: deactivate.php:39
elgg_clear_event_handlers($event, $object_type)
Clears all callback registrations for a event.
Definition: elgglib.php:153
_elgg_services()
Get the global service provider.
Definition: elgglib.php:638
elgg_trigger_after_event($event, $object_type, $object=null)
Trigger an "After event" indicating a process has finished.
Definition: elgglib.php:230
elgg_http_get_signed_url($url, $expires=false)
Signs provided URL with a SHA256 HMAC key.
Definition: elgglib.php:518
elgg_register_success_message($options)
Registers a success system message.
Definition: elgglib.php:43
elgg_trigger_event($event, $object_type, $object=null)
Definition: elgglib.php:190
elgg_unregister_event_handler($event, $object_type, $callback)
Unregisters a callback for an event.
Definition: elgglib.php:140
elgg_http_validate_signed_url($url)
Validates if the HMAC signature of the URL is valid.
Definition: elgglib.php:528
$priority