38 $libraries = $config->get(
'libraries');
39 if ($libraries === null) {
42 $libraries[
$name] = $location;
43 $config->set(
'libraries', $libraries);
58 static $loaded_libraries = array();
60 if (in_array(
$name, $loaded_libraries)) {
66 if (!isset($libraries[
$name])) {
67 $error =
"$name is not a registered library";
68 throw new \InvalidParameterException(
$error);
71 if (!include_once($libraries[$name])) {
72 $error =
"Could not load the $name library from {$libraries[$name]}";
73 throw new \InvalidParameterException(
$error);
76 $loaded_libraries[] =
$name;
94 function forward($location =
"", $reason =
'system') {
95 if (headers_sent(
$file, $line)) {
96 throw new \SecurityException(
"Redirect could not be issued due to headers already being sent. Halting execution for security. " 97 .
"Output started in file $file at line $line. Search http://learn.elgg.org/ for more information.");
115 if (headers_sent(
$file, $line)) {
116 _elgg_services()->logger->error(
"Cannot modify header information - headers already sent by 117 (output started at $file:$line)");
122 if (!preg_match(
'~^HTTP/\\d\\.\\d~',
$header)) {
192 if (isset($config[
'deps']) || isset($config[
'exports'])) {
383 if ($handle = opendir($directory)) {
384 while ((
$file = readdir($handle)) !==
false) {
385 if (!is_file($directory .
$file) || in_array($file, $exceptions)) {
416 $path = preg_replace(
"/([^:])\/\//",
"$1/",
$path);
565 return _elgg_services()->events->unregisterHandler($event, $object_type, $callback);
756 _elgg_services()->hooks->unregisterHandler($hook, $entity_type, $callback);
877 error_log(
"Exception at time $timestamp: $exception");
883 header(
"Cache-Control: no-cache, must-revalidate",
true);
884 header(
'Expires: Fri, 05 Feb 1982 00:00:00 -0500',
true);
888 $GLOBALS[
'_ELGG']->pagesetupdone =
true;
894 if (!empty($CONFIG->exception_include) && is_file($CONFIG->exception_include)) {
898 include $CONFIG->exception_include;
900 $exception_output = ob_get_clean();
904 if (!empty($exception_output)) {
905 echo $exception_output;
912 $response = new \Symfony\Component\HttpFoundation\JsonResponse(null, 500);
915 $response = new \Symfony\Component\HttpFoundation\Response(
'', 500);
935 http_response_code(500);
936 echo "Fatal error in exception handler. Check log for Exception at time $timestamp";
937 error_log(
"Exception at time $timestamp : fatal error in exception handler : $message");
968 if (0 === strpos($errmsg,
"mysql_connect(): The mysql extension is deprecated")) {
970 if (preg_match(
'~/classes/Elgg/Database\.php$~', strtr(
$filename,
'\\',
'/'))) {
975 $error = date(
"Y-m-d H:i:s (T)") .
": \"$errmsg\" in file $filename (line $linenum)";
979 if (!
elgg_log(
"PHP: $error",
'ERROR')) {
980 error_log(
"PHP ERROR: $error");
985 throw new \Exception(
$error);
989 case E_USER_WARNING :
990 case E_RECOVERABLE_ERROR:
993 if (error_reporting() && !
elgg_log(
"PHP: $error",
'WARNING')) {
994 error_log(
"PHP WARNING: $error");
1000 if (isset($CONFIG->debug) && $CONFIG->debug ===
'NOTICE') {
1001 if (!
elgg_log(
"PHP (errno $errno): $error",
'NOTICE')) {
1002 error_log(
"PHP NOTICE: $error");
1029 static $levels = array(
1037 if ($level ==
'DEBUG') {
1041 $level = $levels[$level];
1074 if (!isset(
$version) || !isset($release)) {
1076 if (!is_file(
$path)) {
1082 return $human_readable ? $release :
$version;
1099 $backtrace_level += 1;
1100 return _elgg_services()->deprecation->sendNotice($msg, $dep_version, $backtrace_level);
1118 $scheme = isset($parts[
'scheme']) ?
"{$parts['scheme']}://" :
'';
1119 $host = isset($parts[
'host']) ?
"{$parts['host']}" :
'';
1120 $port = isset($parts[
'port']) ?
":{$parts['port']}" :
'';
1121 $path = isset($parts[
'path']) ?
"{$parts['path']}" :
'';
1122 $query = isset($parts[
'query']) ?
"?{$parts['query']}" :
'';
1123 $fragment = isset($parts[
'fragment']) ?
"#{$parts['fragment']}" :
'';
1125 $string = $scheme . $host . $port .
$path . $query . $fragment;
1155 if (isset($components[
'query'])) {
1161 if (isset($query[
'__elgg_ts']) && isset($query[
'__elgg_token'])) {
1166 $query[
'__elgg_ts'] =
time();
1168 $components[
'query'] = http_build_query($query);
1202 if (isset($url_array[
'query'])) {
1208 foreach ($elements as $k => $v) {
1219 if ($query || empty($url_array[
'path'])) {
1220 $url_array[
'query'] = http_build_query($query);
1222 unset($url_array[
'query']);
1249 if ($url1 == $url2) {
1256 if (isset($url1_info[
'path'])) {
1257 $url1_info[
'path'] = trim($url1_info[
'path'],
'/');
1259 if (isset($url2_info[
'path'])) {
1260 $url2_info[
'path'] = trim($url2_info[
'path'],
'/');
1264 $parts = array(
'scheme',
'host',
'path');
1266 foreach ($parts as $part) {
1267 if ((isset($url1_info[$part]) && isset($url2_info[$part]))
1268 && $url1_info[$part] != $url2_info[$part]) {
1270 } elseif (isset($url1_info[$part]) && !isset($url2_info[$part])) {
1272 } elseif (!isset($url1_info[$part]) && isset($url2_info[$part])) {
1278 if (isset($url1_info[
'query']) && isset($url2_info[
'query'])
1279 && $url1_info[
'query'] == $url2_info[
'query']) {
1284 $url1_params = array();
1285 $url2_params = array();
1287 if (isset($url1_info[
'query'])) {
1288 if ($url1_info[
'query'] = html_entity_decode($url1_info[
'query'])) {
1293 if (isset($url2_info[
'query'])) {
1294 if ($url2_info[
'query'] = html_entity_decode($url2_info[
'query'])) {
1300 foreach ($ignore_params as $param) {
1301 if (isset($url1_params[$param])) {
1302 unset($url1_params[$param]);
1304 if (isset($url2_params[$param])) {
1305 unset($url2_params[$param]);
1314 $diff_count = count(array_diff_assoc($url1_params, $url2_params));
1315 $diff_count += count(array_diff_assoc($url2_params, $url1_params));
1316 if ($diff_count > 0) {
1376 if (!is_array($array)) {
1383 return (isset($array[
$key]) && !empty($array[$key])) ? $array[
$key] :
$default;
1397 $existing = empty($existing) ? [] : (array) $existing;
1401 array_splice($existing, count($existing), 0, $merge);
1403 return array_values(array_unique($existing));
1427 $sort_type = SORT_LOCALE_STRING) {
1431 foreach ($array as $v) {
1432 if (isset($v[$element])) {
1433 $sort[] = strtolower($v[$element]);
1439 return array_multisort($sort, $sort_order, $sort_type, $array);
1453 $temp = strtolower(ini_get($ini_get_arg));
1455 if ($temp ==
'1' || $temp ==
'on' || $temp ==
'true') {
1474 $val = ini_get($setting);
1477 $last = strtolower($val[strlen($val) - 1]);
1478 if (in_array($last, [
'g',
'm',
'k'])) {
1479 $val = substr($val, 0, -1);
1529 foreach ($singulars as $singular) {
1530 $plural = $singular .
's';
1532 if (array_key_exists($singular,
$options)) {
1537 if (!is_array(
$options[$singular])) {
1573 $time = (float)(microtime(
true) - $GLOBALS[
'START_MICROTIME']);
1574 $uri =
_elgg_services()->request->server->get(
'REQUEST_URI',
'CLI');
1576 elgg_log(
"Page {$uri} generated in $time seconds",
'INFO');
1578 $message =
'Error: ' . get_class($e) .
' thrown within the shutdown handler. ';
1579 $message .=
"Message: '{$e->getMessage()}' in file {$e->getFile()} (line {$e->getLine()})";
1581 error_log(
"Exception trace stack: {$e->getTraceAsString()}");
1585 session_write_close();
1620 if (count($segments) < 2) {
1624 if ($segments[0] ===
'view' || $segments[0] ===
'form') {
1625 if ($segments[0] ===
'view') {
1627 $view = implode(
'/', array_slice($segments, 1));
1630 $view =
'forms/' . implode(
'/', array_slice($segments, 1));
1634 $allowed_views = $ajax_api->getViews();
1647 if (isset(
$vars[
'guid'])) {
1652 if ($segments[0] ===
'view') {
1656 switch ($segments[1]) {
1658 $content_type =
'text/javascript;charset=utf-8';
1661 $content_type =
'text/css;charset=utf-8';
1666 $content_type = (new \Elgg\Filesystem\MimeTypeDetector())->getType(
$file,
'text/html');
1671 $action = implode(
'/', array_slice($segments, 1));
1675 if ($content_type) {
1697 if (!isset($page[0])) {
1714 header(
"HTTP/1.1 404 Not Found",
true, 404);
1716 header(
'Expires: ' . gmdate(
'D, d M Y H:i:s \G\M\T', strtotime(
"+1 week")),
true);
1717 header(
"Pragma: public",
true);
1718 header(
"Cache-Control: public",
true);
1743 $content_type =
'text/javascript';
1747 $content_type =
'text/css';
1762 $page = implode(
'/', $page);
1763 $regex =
'|(.+?)\.\w+$|';
1764 if (!preg_match($regex, $page, $matches)) {
1767 $view =
"$type/{$matches[1]}";
1772 $msg =
'URLs starting with /js/ and /css/ are deprecated. Use elgg_get_simplecache_url().';
1777 header(
"Content-type: $content_type;charset=utf-8");
1803 $order_by = strtolower($order_by);
1805 if (strpos($order_by,
' asc') !==
false) {
1806 $return = str_replace(
' asc',
' desc', $order_by);
1807 } elseif (strpos($order_by,
' desc') !==
false) {
1808 $return = str_replace(
' desc',
' asc', $order_by);
1811 $return = $order_by .
' desc';
1830 return $object->enable() ?
true :
false;
1844 return $object->disable() ?
true :
false;
1858 return $object->delete() ?
true :
false;
1883 $metadata_required = array(
1884 'metadata_owner_guid',
'metadata_owner_guids',
1885 'metadata_name',
'metadata_names',
1886 'metadata_value',
'metadata_values' 1894 $annotations_required = array(
1895 'annotation_owner_guid',
'annotation_owner_guids',
1896 'annotation_name',
'annotation_names',
1897 'annotation_value',
'annotation_values' 1941 'content' =>
elgg_view(
"core/walled_garden/$view"),
1942 'class' =>
'elgg-walledgarden-single hidden',
1943 'id' => str_replace(
'_',
'-',
"elgg-walledgarden-$view"),
1974 if (isset($CONFIG->site) && $CONFIG->site instanceof \
ElggSite) {
1975 $CONFIG->site->checkWalledGarden();
1980 elgg_extend_view(
'page/layouts/walled_garden',
'page/layouts/walled_garden/cancel_button');
2000 unset($accesses[ACCESS_PUBLIC]);
2027 $resource = new \Elgg\Http\WebAppManifestResource(
$site);
2028 header(
'Content-Type: application/json;charset=utf-8');
2029 echo json_encode($resource->get());
2034 $result[
'links'][
'manifest'] = [
2035 'rel' =>
'manifest',
2066 $value[] = $CONFIG->path .
'engine/tests/ElggTravisInstallTest.php';
2067 $value[] = $CONFIG->path .
'engine/tests/ElggCoreHelpersTest.php';
2068 $value[] = $CONFIG->path .
'engine/tests/ElggCoreRegressionBugsTest.php';
2069 $value[] = $CONFIG->path .
'engine/tests/ElggBatchTest.php';
2129 define(
'ELGG_HTTP_SWITCHING_PROTOCOLS', 101);
2134 define(
'ELGG_HTTP_NON_AUTHORITATIVE_INFORMATION', 203);
2149 define(
'ELGG_HTTP_PERMANENTLY_REDIRECT', 308);
2157 define(
'ELGG_HTTP_PROXY_AUTHENTICATION_REQUIRED', 407);
2162 define(
'ELGG_HTTP_PRECONDITION_FAILED', 412);
2163 define(
'ELGG_HTTP_REQUEST_ENTITY_TOO_LARGE', 413);
2164 define(
'ELGG_HTTP_REQUEST_URI_TOO_LONG', 414);
2165 define(
'ELGG_HTTP_UNSUPPORTED_MEDIA_TYPE', 415);
2166 define(
'ELGG_HTTP_REQUESTED_RANGE_NOT_SATISFIABLE', 416);
2169 define(
'ELGG_HTTP_UNPROCESSABLE_ENTITY', 422);
2172 define(
'ELGG_HTTP_RESERVED_FOR_WEBDAV_ADVANCED_COLLECTIONS_EXPIRED_PROPOSAL', 425);
2174 define(
'ELGG_HTTP_PRECONDITION_REQUIRED', 428);
2176 define(
'ELGG_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE', 431);
2177 define(
'ELGG_HTTP_INTERNAL_SERVER_ERROR', 500);
2180 define(
'ELGG_HTTP_SERVICE_UNAVAILABLE', 503);
2182 define(
'ELGG_HTTP_VERSION_NOT_SUPPORTED', 505);
2183 define(
'ELGG_HTTP_VARIANT_ALSO_NEGOTIATES_EXPERIMENTAL', 506);
2184 define(
'ELGG_HTTP_INSUFFICIENT_STORAGE', 507);
2187 define(
'ELGG_HTTP_NETWORK_AUTHENTICATION_REQUIRED', 511);
2192 define(
'ELGG_JSON_ENCODING', JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT);
2195 $events->registerHandler(
'boot',
'system',
function () {
2198 $events->registerHandler(
'cache:flush',
'system',
function () {
2202 $events->registerHandler(
'init',
'system',
'_elgg_init');
2203 $events->registerHandler(
'init',
'system',
'_elgg_walled_garden_init', 1000);
2205 $hooks->registerHandler(
'unit_test',
'system',
'_elgg_api_test');
elgg_http_add_url_query_elements($url, array $elements)
Sets elements in a URL's query string.
const ELGG_HTTP_FORBIDDEN
elgg_parse_str($str)
Parses a string using mb_parse_str() if available.
elgg_view_exists($view, $viewtype= '', $recurse=true)
Returns whether the specified view exists.
$object
These two snippets demonstrates triggering an event and how to register for that event.
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
elgg_get_loaded_css()
Get the loaded CSS URLs.
elgg_get_site_entity($site_guid=0)
Get an entity (default is current site)
if(!$owner||!($owner instanceof ElggUser)||!$owner->canEdit()) $error
elgg_is_xhr()
Checks whether the request was requested via ajax.
elgg_unregister_plugin_hook_handler($hook, $entity_type, $callback)
Unregister a callback as a plugin hook.
if(!array_key_exists($filename, $text_files)) $file
elgg_add_action_tokens_to_url($url, $html_encode=false)
Adds action tokens to URL.
_elgg_css_page_handler($page)
Serve CSS.
_elgg_is_valid_options_for_batch_operation($options, $type)
Checks if there are some constraints on the options array for potentially dangerous operations...
elgg_set_http_header($header, $replace=true)
Set a response HTTP header.
elgg_register_external_file($type, $name, $url, $location, $priority=500)
Core registration function for external files.
elgg_unrequire_js($name)
Cancel a request to load an AMD module onto the page.
elgg_is_admin_logged_in()
Returns whether or not the viewer is currently logged in and an admin user.
if($guid==elgg_get_logged_in_user_guid()) $name
elgg_define_js($name, $config)
Defines a JS lib as an AMD module.
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
elgg_view_form($action, $form_vars=array(), $body_vars=array())
elgg_view_resource($name, array $vars=[])
Render a resource view.
elgg_sort_3d_array_by_value(&$array, $element, $sort_order=SORT_ASC, $sort_type=SORT_LOCALE_STRING)
Sorts a 3d array by specific element.
elgg_clear_plugin_hook_handlers($hook, $type)
Clears all callback registrations for a plugin hook.
elgg_get_ordered_event_handlers($event, $type)
Returns an ordered array of event handlers registered for $event and $type.
elgg_http_url_is_identical($url1, $url2, $ignore_params=array('offset', 'limit'))
Test if two URLs are functionally identical.
elgg_unregister_external_file($type, $name)
Unregister an external file.
sanitise_filepath($path, $append_slash=true)
Sanitise file paths ensuring that they begin and end with slashes etc.
elgg_get_simplecache_url($view, $subview= '')
Get the URL for the cached view.
elgg()
Get a reference to the global Application object.
elgg_register_css($name, $url, $priority=null)
Register a CSS file for inclusion in the HTML head.
elgg_load_library($name)
Load a PHP library.
elgg_signed_request_gatekeeper()
Validates if the HMAC signature of the current request is valid Issues 403 response if signature is i...
elgg_view_layout($layout_name, $vars=array())
Displays a layout with optional parameters.
_elgg_favicon_page_handler($segments)
Handle requests for /favicon.ico.
elgg parse_url
Parse a URL into its parts.
elgg_get_system_messages()
Get a copy of the current system messages.
elgg_register_plugin_hook_handler($hook, $type, $callback, $priority=500)
_elgg_sql_reverse_order_by_clause($order_by)
Reverses the ordering in an ORDER BY clause.
elgg_extract_class(array $array, $existing=[])
Extract class names from an array with key "class", optionally merging into a preexisting set...
elgg_trigger_before_event($event, $object_type, $object=null)
Trigger a "Before event" indicating a process is about to begin.
_elgg_shutdown_hook()
Emits a shutdown:system event upon PHP shutdown, but before database connections are dropped...
_elgg_php_exception_handler($exception)
Intercepts, logs, and displays uncaught exceptions.
register_error($error)
Display an error on next page load.
elgg_get_loaded_external_files($type, $location)
Get external resource descriptors.
elgg_get_viewtype()
Return the current view type.
is_not_null($string)
Returns true is string is not empty, false, or null.
elgg_batch_delete_callback($object)
Delete objects with a delete() method.
_elgg_js_page_handler($page)
Serve javascript pages.
elgg_unregister_css($name)
Unregister a CSS file.
elgg_require_js($name)
Request that Elgg load an AMD module onto the page.
elgg_get_file_list($directory, $exceptions=array(), $list=array(), $extensions=null)
Returns a list of files in $directory.
elgg_get_ini_setting_in_bytes($setting)
Returns a PHP INI setting in bytes.
_elgg_api_test($hook, $type, $value, $params)
Adds unit tests for the general API.
elgg_load_css($name)
Load a CSS file for this page.
elgg_register_js($name, $url, $location= 'head', $priority=null)
Register a JavaScript file for inclusion.
generate_action_token($timestamp)
Generate an action token.
elgg_http_remove_url_query_element($url, $element)
Removes an element from a URL's query string.
elgg_trigger_deprecated_event($event, $object_type, $object=null, $message, $version)
Trigger an event normally, but send a notice about deprecated use if any handlers are registered...
static static $_instance
Reference to the loaded Application returned by elgg()
_elgg_ajax_page_handler($segments)
Serve individual views for Ajax.
elgg_load_external_file($type, $name)
Load an external resource for use on this page.
_elgg_walled_garden_index()
Intercepts the index page when Walled Garden mode is enabled.
_elgg_cacheable_view_page_handler($page, $type)
Serves a JS or CSS view with headers for caching.
ini_get_bool($ini_get_arg)
Return the state of a php.ini setting as a bool.
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_dump($value, $to_screen=true)
Logs or displays $value.
elgg_set_viewtype($viewtype="")
Manually set the viewtype.
const ELGG_ENTITIES_ANY_VALUE
elgg echo
Translates a string.
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
elgg_register_page_handler($identifier, $function)
Registers a page handler for a particular identifier.
elgg_ajax_gatekeeper()
Require that the current request be an XHR.
_elgg_walled_garden_ajax_handler($page)
Serve walled garden sections.
elgg_view($view, $vars=array(), $ignore1=false, $ignore2=false, $viewtype= '')
Return a parsed view.
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
elgg global
Pointer to the global context.
clearfix elgg elgg elgg elgg page header
elgg_register_library($name, $location)
Register a PHP file as a library.
elgg_extend_view($view, $view_extension, $priority=501)
Extends a view with another view.
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
elgg_register_event_handler($event, $object_type, $callback, $priority=500)
elgg_log($message, $level= 'NOTICE')
Display or log a message.
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_walled_garden_remove_public_access($hook, $type, $accesses)
Remove public access for walled gardens.
forward($location="", $reason= 'system')
Forward to $location.
elgg_get_version($human_readable=false)
Get the current Elgg version information.
elgg_load_js($name)
Load a JavaScript resource on this page.
elgg_http_build_url(array $parts, $html_encode=true)
Builds a URL from the a parts array like one returned by parse_url().
elgg_set_system_messages(\Elgg\SystemMessages\RegisterSet $set)
Set the system messages.
elgg_batch_disable_callback($object)
Disable objects with a disable() method.
elgg_format_url($url)
Handles formatting of ampersands in urls.
static elggDir()
Returns a directory that points to the root of Elgg, but not necessarily the install root...
elgg_clear_event_handlers($event, $object_type)
Clears all callback registrations for a event.
elgg_trigger_after_event($event, $object_type, $object=null)
Trigger an "After event" indicating a process has finished.
_elgg_init()
Elgg's main init.
define(function(require){var $=require('jquery');$(document).on('change', '#elgg-river-selector', function(){var url=window.location.href;if(window.location.search.length){url=url.substring(0, url.indexOf('?'));}url+= '?'+$(this).val();window.location.href=url;});})
Initiates page reload when river selector value changes core/river/filter.
elgg_register_action($action, $filename="", $access= 'logged_in')
Registers an action.
elgg_get_ordered_hook_handlers($hook, $type)
Returns an ordered array of hook handlers registered for $hook and $type.
_elgg_normalize_plural_options_array($options, $singulars)
Normalise the singular keys in an options array to plural keys.
elgg_http_get_signed_url($url, $expires=false)
Signs provided URL with a SHA256 HMAC key.
elgg_trigger_event($event, $object_type, $object=null)
_elgg_walled_garden_init()
Checks the status of the Walled Garden and forwards to a login page if required.
_elgg_php_error_handler($errno, $errmsg, $filename, $linenum, $vars)
Intercepts catchable PHP errors.
system_message($message)
Display a system message on next page load.
http free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
elgg_get_loaded_js($location= 'head')
Get the JavaScript URLs that are loaded.
elgg_batch_enable_callback($object)
Enable objects with an enable() method.
elgg_unregister_event_handler($event, $object_type, $callback)
Unregisters a callback for an event.
elgg_http_validate_signed_url($url)
Validates if the HMAC signature of the URL is valid.
elgg_unregister_js($name)
Unregister a JavaScript file.
count_messages($register="")
Counts the number of messages, either globally or in a particular register.
if($composer===null) if(!isset($composer->version)) $release
get_entity($guid)
Loads and returns an entity object from a guid.
elgg_view_page($title, $body, $page_shell= 'default', $vars=array())
Assembles and outputs a full page.