24 $libraries = $config->get(
'libraries');
25 if ($libraries === null) {
28 $libraries[
$name] = $location;
29 $config->set(
'libraries', $libraries);
44 static $loaded_libraries = array();
46 if (in_array(
$name, $loaded_libraries)) {
52 if (!isset($libraries[
$name])) {
53 $error =
"$name is not a registered library";
54 throw new \InvalidParameterException(
$error);
57 if (!include_once($libraries[$name])) {
58 $error =
"Could not load the $name library from {$libraries[$name]}";
59 throw new \InvalidParameterException(
$error);
62 $loaded_libraries[] =
$name;
80 function forward($location =
"", $reason =
'system') {
81 if (!headers_sent($file, $line)) {
94 header(
"Location: {$location}");
98 throw new \SecurityException(
"Redirect could not be issued due to headers already being sent. Halting execution for security. " 99 .
"Output started in file $file at line $line. Search http://learn.elgg.org/ for more information.");
161 if (isset($config[
'deps']) || isset($config[
'exports'])) {
340 if ($handle = opendir($directory)) {
341 while (($file = readdir($handle)) !==
false) {
342 if (!is_file($directory . $file) || in_array($file, $exceptions)) {
348 $list[] = $directory . $file;
351 $list[] = $directory . $file;
373 $path = preg_replace(
"/([^:])\/\//",
"$1/",
$path);
419 if (!isset(
$messages[$register]) && !empty($register)) {
431 if ($register !=
"") {
432 $returnarray = array();
433 $returnarray[$register] =
$messages[$register];
443 if (!empty($register)) {
448 $count +=
sizeof($submessages);
568 return _elgg_services()->events->unregisterHandler($event, $object_type, $callback);
646 \
Elgg\EventsService::OPTION_STOPPABLE =>
false,
666 \
Elgg\EventsService::OPTION_DEPRECATION_MESSAGE =>
$message,
667 \
Elgg\EventsService::OPTION_DEPRECATION_VERSION =>
$version,
752 _elgg_services()->hooks->unregisterHandler($hook, $entity_type, $callback);
832 error_log(
"Exception #$timestamp: $exception");
838 header(
"Cache-Control: no-cache, must-revalidate",
true);
839 header(
'Expires: Fri, 05 Feb 1982 00:00:00 -0500',
true);
844 $CONFIG->pagesetupdone =
true;
850 if (!empty($CONFIG->exception_include) && is_file($CONFIG->exception_include)) {
852 include $CONFIG->exception_include;
853 $exception_output = ob_get_clean();
857 if (!empty($exception_output)) {
858 echo $exception_output;
888 echo "Fatal error in exception handler. Check log for Exception #$timestamp";
889 error_log(
"Exception #$timestamp : fatal error in exception handler : $message");
918 $error = date(
"Y-m-d H:i:s (T)") .
": \"$errmsg\" in file $filename (line $linenum)";
922 error_log(
"PHP ERROR: $error");
926 throw new \Exception(
$error);
930 case E_USER_WARNING :
931 case E_RECOVERABLE_ERROR:
934 if (error_reporting()) {
935 error_log(
"PHP WARNING: $error");
941 if (isset($CONFIG->debug) && $CONFIG->debug ===
'NOTICE') {
942 error_log(
"PHP NOTICE: $error");
968 static $levels = array(
976 if ($level ==
'DEBUG') {
980 $level = $levels[$level];
1015 if (isset($CONFIG->path)) {
1016 if (!isset(
$version) || !isset($release)) {
1017 if (!include($CONFIG->path .
"version.php")) {
1021 return $human_readable ? $release :
$version;
1061 if (!$dep_version) {
1066 $elgg_version_arr = explode(
'.', $elgg_version);
1067 $elgg_major_version = (int)$elgg_version_arr[0];
1068 $elgg_minor_version = (int)$elgg_version_arr[1];
1070 $dep_version_arr = explode(
'.', (
string)$dep_version);
1071 $dep_major_version = (int)$dep_version_arr[0];
1072 $dep_minor_version = (int)$dep_version_arr[1];
1076 if (($dep_major_version < $elgg_major_version) ||
1077 ($dep_minor_version < $elgg_minor_version)) {
1081 $msg =
"Deprecated in $dep_major_version.$dep_minor_version: $msg";
1090 $msg .=
" Called from ";
1092 $backtrace = debug_backtrace();
1094 array_shift($backtrace);
1095 $i = count($backtrace);
1097 foreach ($backtrace as $trace) {
1098 $stack[] =
"[#$i] {$trace['file']}:{$trace['line']}";
1101 if ($backtrace_level > 0) {
1102 if ($backtrace_level <= 1) {
1109 $msg .= implode(
"<br /> -> ", $stack);
1129 $scheme = isset($parts[
'scheme']) ?
"{$parts['scheme']}://" :
'';
1130 $host = isset($parts[
'host']) ?
"{$parts['host']}" :
'';
1131 $port = isset($parts[
'port']) ?
":{$parts['port']}" :
'';
1132 $path = isset($parts[
'path']) ?
"{$parts['path']}" :
'';
1133 $query = isset($parts[
'query']) ?
"?{$parts['query']}" :
'';
1134 $fragment = isset($parts[
'fragment']) ?
"#{$parts['fragment']}" :
'';
1136 $string = $scheme . $host . $port .
$path . $query . $fragment;
1166 if (isset($components[
'query'])) {
1172 if (isset($query[
'__elgg_ts']) && isset($query[
'__elgg_token'])) {
1177 $query[
'__elgg_ts'] = time();
1179 $components[
'query'] = http_build_query($query);
1213 if (isset($url_array[
'query'])) {
1219 foreach ($elements as $k => $v) {
1230 if ($query || empty($url_array[
'path'])) {
1231 $url_array[
'query'] = http_build_query($query);
1233 unset($url_array[
'query']);
1260 if ($url1 == $url2) {
1267 if (isset($url1_info[
'path'])) {
1268 $url1_info[
'path'] = trim($url1_info[
'path'],
'/');
1270 if (isset($url2_info[
'path'])) {
1271 $url2_info[
'path'] = trim($url2_info[
'path'],
'/');
1275 $parts = array(
'scheme',
'host',
'path');
1277 foreach ($parts as $part) {
1278 if ((isset($url1_info[$part]) && isset($url2_info[$part]))
1279 && $url1_info[$part] != $url2_info[$part]) {
1281 } elseif (isset($url1_info[$part]) && !isset($url2_info[$part])) {
1283 } elseif (!isset($url1_info[$part]) && isset($url2_info[$part])) {
1289 if (isset($url1_info[
'query']) && isset($url2_info[
'query'])
1290 && $url1_info[
'query'] == $url2_info[
'query']) {
1295 $url1_params = array();
1296 $url2_params = array();
1298 if (isset($url1_info[
'query'])) {
1299 if ($url1_info[
'query'] = html_entity_decode($url1_info[
'query'])) {
1304 if (isset($url2_info[
'query'])) {
1305 if ($url2_info[
'query'] = html_entity_decode($url2_info[
'query'])) {
1311 foreach ($ignore_params as $param) {
1312 if (isset($url1_params[$param])) {
1313 unset($url1_params[$param]);
1315 if (isset($url2_params[$param])) {
1316 unset($url2_params[$param]);
1325 $diff_count = count(array_diff_assoc($url1_params, $url2_params));
1326 $diff_count += count(array_diff_assoc($url2_params, $url1_params));
1327 if ($diff_count > 0) {
1350 if (!is_array($array)) {
1357 return (isset($array[
$key]) && !empty($array[$key])) ? $array[
$key] :
$default;
1382 $sort_type = SORT_LOCALE_STRING) {
1386 foreach ($array as $v) {
1387 if (isset($v[$element])) {
1388 $sort[] = strtolower($v[$element]);
1394 return array_multisort(
$sort, $sort_order, $sort_type, $array);
1408 $temp = strtolower(ini_get($ini_get_arg));
1410 if ($temp ==
'1' || $temp ==
'on' || $temp ==
'true') {
1429 $val = ini_get($setting);
1432 $last = strtolower($val[strlen($val) - 1]);
1480 foreach ($singulars as $singular) {
1481 $plural = $singular .
's';
1483 if (array_key_exists($singular,
$options)) {
1488 if (!is_array(
$options[$singular])) {
1524 $uri =
_elgg_services()->request->server->get(
'REQUEST_URI',
'CLI');
1526 elgg_log(
"Page {$uri} generated in $time seconds",
'INFO');
1528 $message =
'Error: ' . get_class($e) .
' thrown within the shutdown handler. ';
1529 $message .=
"Message: '{$e->getMessage()}' in file {$e->getFile()} (line {$e->getLine()})";
1531 error_log(
"Exception trace stack: {$e->getTraceAsString()}");
1535 session_write_close();
1567 if (is_array($page) &&
sizeof($page)) {
1570 $view = implode(
'/', $page);
1573 if (!array_key_exists(
$view, $allowed_views)) {
1574 header(
'HTTP/1.1 403 Forbidden');
1584 if (isset(
$vars[
'guid'])) {
1591 header(
"Content-Type: text/javascript");
1594 header(
"Content-Type: text/css");
1616 if (!isset($page[0])) {
1633 header(
"HTTP/1.1 404 Not Found",
true, 404);
1635 header(
'Expires: ' . gmdate(
'D, d M Y H:i:s \G\M\T', strtotime(
"+1 week")),
true);
1636 header(
"Pragma: public",
true);
1637 header(
"Cache-Control: public",
true);
1661 $content_type =
'text/javascript';
1665 $content_type =
'text/css';
1680 $page = implode(
'/', $page);
1681 $regex =
'|(.+?)\.\w+$|';
1682 if (!preg_match($regex, $page, $matches)) {
1685 $view =
"$type/{$matches[1]}";
1691 header(
"Content-type: $content_type");
1717 $order_by = strtolower($order_by);
1719 if (strpos($order_by,
' asc') !==
false) {
1720 $return = str_replace(
' asc',
' desc', $order_by);
1721 } elseif (strpos($order_by,
' desc') !==
false) {
1722 $return = str_replace(
' desc',
' asc', $order_by);
1725 $return = $order_by .
' desc';
1744 return $object->enable() ?
true :
false;
1758 return $object->disable() ?
true :
false;
1772 return $object->delete() ?
true :
false;
1797 $metadata_required = array(
1798 'metadata_owner_guid',
'metadata_owner_guids',
1799 'metadata_name',
'metadata_names',
1800 'metadata_value',
'metadata_values' 1803 $required = array_merge($required, $metadata_required);
1808 $annotations_required = array(
1809 'annotation_owner_guid',
'annotation_owner_guids',
1810 'annotation_name',
'annotation_names',
1811 'annotation_value',
'annotation_values' 1814 $required = array_merge($required, $annotations_required);
1821 foreach ($required as
$key) {
1846 'class' =>
'elgg-walledgarden-double',
1847 'id' =>
'elgg-walledgarden-login',
1866 'content' =>
elgg_view(
"core/walled_garden/$view"),
1867 'class' =>
'elgg-walledgarden-single hidden',
1868 'id' => str_replace(
'_',
'-',
"elgg-walledgarden-$view"),
1896 if (isset($CONFIG->site) && $CONFIG->site instanceof \
ElggSite) {
1897 $CONFIG->site->checkWalledGarden();
1912 unset($accesses[ACCESS_PUBLIC]);
1932 set_error_handler(
'_elgg_php_error_handler');
1933 set_exception_handler(
'_elgg_php_exception_handler');
1974 $resource = new \Elgg\Http\WebAppManifestResource(
$site);
1975 header(
'Content-Type: application/json');
1976 echo json_encode($resource->get());
1981 $result[
'links'][
'manifest'] = [
1982 'rel' =>
'manifest',
1990 elgg_register_js(
'jquery.ui.autocomplete.html',
'vendors/jquery/jquery.ui.autocomplete.html.js');
1996 elgg_register_js(
'jquery.imgareaselect',
'vendors/jquery/jquery.imgareaselect/scripts/jquery.imgareaselect.min.js');
1999 elgg_register_css(
'jquery.imgareaselect',
'vendors/jquery/jquery.imgareaselect/css/imgareaselect-deprecated.css');
2002 register_shutdown_function(
'_elgg_shutdown_hook');
2007 $CONFIG->wordblacklist = array();
2010 foreach (
$list as $l) {
2011 $CONFIG->wordblacklist[] = trim($l);
2030 $value[] = $CONFIG->path .
'engine/tests/ElggTravisInstallTest.php';
2031 $value[] = $CONFIG->path .
'engine/tests/ElggCoreHelpersTest.php';
2032 $value[] = $CONFIG->path .
'engine/tests/ElggCoreRegressionBugsTest.php';
2033 $value[] = $CONFIG->path .
'engine/tests/ElggBatchTest.php';
2045 define(
'ACCESS_DEFAULT', -1);
2046 define(
'ACCESS_PRIVATE', 0);
2047 define(
'ACCESS_LOGGED_IN', 1);
2048 define(
'ACCESS_PUBLIC', 2);
2049 define(
'ACCESS_FRIENDS', -2);
2059 define(
'ELGG_ENTITIES_ANY_VALUE', null);
2068 define(
'ELGG_ENTITIES_NO_VALUE', 0);
2077 define(
'REFERRER', -1);
2087 define(
'REFERER', -1);
_elgg_load_autoload_cache()
Load cached data into the autoload system.
elgg_http_add_url_query_elements($url, array $elements)
Sets elements in a URL's query string.
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_unregister_plugin_hook_handler($hook, $entity_type, $callback)
Unregister a callback as a plugin hook.
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_register_external_file($type, $name, $url, $location, $priority=500)
Core registration function for external files.
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_sort_3d_array_by_value(&$array, $element, $sort_order=SORT_ASC, $sort_type=SORT_LOCALE_STRING)
Sorts a 3d array by specific element.
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.
if(is_callable('mb_internal_encoding')) elgg_parse_str($str)
Parses a string using mb_parse_str() if available.
elgg_register_external_view($view, $cacheable=false)
Registers a view as being available externally (i.e.
elgg_view_exists($view, $viewtype= '', $recurse=true)
Returns whether the specified view exists.
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.
if(!$autoload_available) _elgg_services()
_elgg_favicon_page_handler($segments)
Handle requests for /favicon.ico.
elgg parse_url
Parse a URL into its parts.
elgg_extract($key, array $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
_elgg_load_site_config()
Loads configuration related to this site.
elgg_register_plugin_hook_handler($hook, $type, $callback, $priority=500)
Register a callback as a plugin hook handler.
_elgg_sql_reverse_order_by_clause($order_by)
Reverses the ordering in an ORDER BY clause.
_elgg_ajax_page_handler($page)
Serve individual views for Ajax.
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.
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_set_viewtype($viewtype="")
Manually set the viewtype.
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
elgg_get_simplecache_url($type, $view)
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...
elgg_load_external_file($type, $name)
Load an external resource for use on this page.
_elgg_engine_boot()
Boots the engine.
_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_dump($value, $to_screen=true)
Logs or displays $value.
const ELGG_ENTITIES_ANY_VALUE
elgg echo
Translates a string.
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
Trigger a Plugin Hook and run all handler callbacks registered to that hook:type. ...
elgg_register_page_handler($identifier, $function)
Registers a page handler for a particular identifier.
_elgg_walled_garden_ajax_handler($page)
Serve walled garden sections.
global $START_MICROTIME
The time with microseconds when the Elgg engine was started.
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Sends a notice about deprecated use of a function, view, etc.
elgg global
Pointer to the global context.
elgg_register_library($name, $location)
Register a PHP file as a library.
elgg_view($view, $vars=array(), $bypass=false, $ignored=false, $viewtype= '')
Return a parsed view.
system_messages($message=null, $register="success", $count=false)
Queues a message to be displayed.
elgg_view_layout($layout_name, $vars=array())
Displays a layout with optional parameters.
elgg_register_event_handler($event, $object_type, $callback, $priority=500)
Register a callback as an Elgg event handler.
elgg_log($message, $level= 'NOTICE')
Display or log a message.
_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().
$content
Set robots.txt action.
elgg_batch_disable_callback($object)
Disable objects with a disable() method.
elgg_format_url($url)
Handles formatting of ampersands in urls.
elgg_trigger_after_event($event, $object_type, $object=null)
Trigger an "After event" indicating a process has finished.
_elgg_init()
Elgg's main init.
elgg_view_page($title, $body, $page_shell= 'default', $vars=array())
Assembles and outputs a full page.
clearfix elgg elgg elgg elgg page header
elgg_register_action($action, $filename="", $access= 'logged_in')
Registers an action.
_elgg_session_boot()
Initializes the session and checks for the remember me cookie.
_elgg_normalize_plural_options_array($options, $singulars)
Normalise the singular keys in an options array to plural keys.
elgg_trigger_event($event, $object_type, $object=null)
Trigger an Elgg Event and attempt to run all handler callbacks registered to that event...
_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.
_elgg_load_application_config()
Loads configuration related to Elgg as an application.
system_message($message)
Display a system message on next page load.
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_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.
if(file_exists($welcome)) $vars