22 const GET_PATH_KEY =
'__elgg_uri';
23 const REWRITE_TEST_TOKEN =
'__testing_rewrite';
24 const REWRITE_TEST_OUTPUT =
'success';
44 private static $public_services = [
66 $this->services = $services;
73 if (!isset($GLOBALS[
'START_MICROTIME'])) {
74 $GLOBALS[
'START_MICROTIME'] = microtime(
true);
77 $services->timer->begin([]);
86 if (!isset($GLOBALS[
'_ELGG'])) {
87 $GLOBALS[
'_ELGG'] = new \stdClass();
90 $this->engine_dir = __DIR__ .
'/../..';
102 $this->services->config->loadSettingsFile();
115 if (function_exists(
'elgg')) {
119 $lib_dir = self::elggDir()->chroot(
"engine/lib");
158 'private_settings.php',
173 'deprecated-1.9.php',
174 'deprecated-1.10.php',
175 'deprecated-1.11.php',
176 'deprecated-1.12.php',
177 'deprecated-2.1.php',
181 call_user_func(
function ()
use ($lib_dir, $lib_files) {
186 foreach ($lib_files as
$file) {
187 $setup = (require_once $lib_dir->getPath($file));
189 if ($setup instanceof \Closure) {
190 $setups[
$file] = $setup;
195 self::$_instance = $this;
200 $events = $this->services->events;
201 $hooks = $this->services->hooks;
204 foreach ($setups as $func) {
205 $func($events, $hooks);
216 $app = self::create();
236 $config = $this->services->config;
238 if ($config->getVolatile(
'Elgg\Application_phpunit')) {
239 throw new \RuntimeException(
'Unit tests should not call ' . __METHOD__);
242 if ($config->getVolatile(
'boot_complete')) {
246 $this->loadSettings();
248 $config->set(
'boot_complete',
false);
251 $config->set(
'default_limit', 10);
256 $events = $this->services->events;
260 $events->trigger(
'boot',
'system');
263 $this->services->plugins->load();
265 $root = Directory\Local::root();
266 if ($root->getPath() != self::elggDir()->getPath()) {
271 $viewsFile = $root->getFile(
'views.php');
272 if ($viewsFile->exists()) {
273 $viewsSpec = $viewsFile->includeFile();
274 if (is_array($viewsSpec)) {
284 _elgg_services()->translator->registerPluginTranslations($root->getPath());
288 $root_start = $root->getPath(
"start.php");
289 if (is_file($root_start)) {
303 $this->allowPathRewrite();
306 $events->trigger(
'plugins_boot',
'system');
309 $events->trigger(
'init',
'system');
311 $config->set(
'boot_complete',
true);
314 $events->trigger(
'ready',
'system');
330 $this->loadSettings();
331 return $this->services->publicDb;
342 if (isset(self::$public_services[
$name])) {
343 return $this->services->{$name};
345 trigger_error(
"Undefined property: " . __CLASS__ .
":\${$name}");
354 private static function create() {
355 if (self::$_instance === null) {
358 register_shutdown_function(
function () {
360 if (function_exists(
'_elgg_shutdown_hook')) {
368 return self::$_instance;
377 self::create()->run();
386 $path = $this->setupPath();
389 if (isset($_GET[self::REWRITE_TEST_TOKEN])) {
390 if (
false !== strpos(
$path, self::REWRITE_TEST_TOKEN)) {
391 echo self::REWRITE_TEST_OUTPUT;
396 if (php_sapi_name() ===
'cli-server') {
397 $www_root =
"http://{$_SERVER['SERVER_NAME']}:{$_SERVER['SERVER_PORT']}/";
398 $this->services->config->set(
'wwwroot', $www_root);
401 if (0 === strpos(
$path,
'/cache/')) {
402 (
new Application\CacheHandler($this, $this->services->config, $_SERVER))->handleRequest(
$path);
406 if (0 === strpos(
$path,
'/serve-file/')) {
407 $this->services->serveFileHandler->getResponse($this->services->request)->send();
411 if (
$path ===
'/rewrite.php') {
412 require Directory\Local::root()->getPath(
"install.php");
416 if (php_sapi_name() ===
'cli-server') {
427 header(
"Content-Type: text/html;charset=utf-8");
429 if (!$this->services->router->route($this->services->request)) {
443 $app = self::create();
444 $app->services->config->loadSettingsFile();
446 if ($GLOBALS[
'_ELGG']->dataroot_in_settings) {
447 return $app->services->config->getVolatile(
'dataroot');
450 $dataroot = $app->services->datalist->get(
'dataroot');
452 throw new \InstallationException(
'The datalists table lacks a value for "dataroot".');
455 $app->services->config->set(
'dataroot',
$dataroot);
466 return Directory\Local::fromPath(realpath(__DIR__ .
'/../../..'));
475 ini_set(
'display_errors', 1);
497 ini_set(
'display_errors', 1);
499 define(
'UPGRADING',
'upgrading');
518 if (
$result[
'failure'] ==
true) {
523 $rewriteTester = new \ElggRewriteTester();
525 if (!$rewriteTester->runRewriteTest(
$url)) {
528 if (!$rewriteTester->runLocalhostAccessTest()) {
530 $msg =
elgg_echo(
"installation:htaccess:localhost:connectionfailed");
531 if ($msg ===
"installation:htaccess:localhost:connectionfailed") {
532 $msg =
"Elgg cannot connect to itself to test rewrite rules properly. Check " 533 .
"that curl is working and there are no IP restrictions preventing " 534 .
"localhost connections.";
541 $msg =
elgg_echo(
"installation:htaccess:needs_upgrade");
542 if ($msg ===
"installation:htaccess:needs_upgrade") {
543 $msg =
"You must update your .htaccess file so that the path is injected " 544 .
"into the GET parameter __elgg_uri (you can use install/config/htaccess.dist as a guide).";
569 private function setupPath() {
570 if (!isset($_GET[self::GET_PATH_KEY]) || is_array($_GET[self::GET_PATH_KEY])) {
571 if (php_sapi_name() ===
'cli-server') {
572 $_GET[self::GET_PATH_KEY] = (string)
parse_url($_SERVER[
"REQUEST_URI"], PHP_URL_PATH);
574 $_GET[self::GET_PATH_KEY] =
'/';
579 $_GET[self::GET_PATH_KEY] =
'/' . trim($_GET[self::GET_PATH_KEY],
'/');
581 return $_GET[self::GET_PATH_KEY];
589 private function allowPathRewrite() {
590 $request = $this->services->request;
591 $new = $this->services->router->allowRewrite($request);
592 if (
$new === $request) {
596 $this->services->setValue(
'request',
$new);
static index()
Elgg's front controller.
A simple directory abstraction.
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
run()
Routes the request, booting core if not yet booted.
elgg_reset_system_cache()
Reset the system cache by deleting the caches.
loadSettings()
Load settings.php.
static install()
Renders a web UI for installing Elgg.
if(!$entity->delete()) $forward_url
if(!array_key_exists($filename, $text_files)) $file
__get($name)
Get an undefined property.
if($guid==elgg_get_logged_in_user_guid()) $name
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Access to configuration values.
elgg_is_registered_viewtype($viewtype)
Checks if $viewtype is registered.
elgg parse_url
Parse a URL into its parts.
elgg forward
Meant to mimic the php forward() function by simply redirecting the user to another page...
static getDataPath()
Determine the Elgg data directory with trailing slash, save it to config, and return it...
getDb()
Get a Database wrapper for performing queries without booting Elgg.
_elgg_shutdown_hook()
Emits a shutdown:system event upon PHP shutdown, but before database connections are dropped...
elgg_get_viewtype()
Return the current view type.
static start()
Replacement for loading engine/start.php.
loadCore()
Load all Elgg procedural code and wire up boot events, but don't boot.
bootCore()
Bootstrap the Elgg engine, loads plugins, and calls initial system events.
static static $_instance
Reference to the loaded Application returned by elgg()
static upgrade()
Elgg upgrade script.
__construct(ServiceProvider $services)
Constructor.
elgg_set_viewtype($viewtype="")
Manually set the viewtype.
elgg echo
Translates a string.
elgg require
Throw an error if the required package isn't present.
elgg_get_site_url($site_guid=0)
Get the URL for the current (or specified) site.
clearfix elgg elgg elgg elgg page header
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
elgg register_error
Wrapper function for system_messages.
static elggDir()
Returns a directory that points to the root of Elgg, but not necessarily the install root...
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.
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_view_page($title, $body, $page_shell= 'default', $vars=array())
Assembles and outputs a full page.
_elgg_set_initial_context(\Elgg\Http\Request $request)
Set an initial context if using index.php front controller.