23 const GET_PATH_KEY =
'__elgg_uri';
24 const REWRITE_TEST_TOKEN =
'__testing_rewrite';
25 const REWRITE_TEST_OUTPUT =
'success';
40 private static $testing_app;
50 private static $public_services = [
53 'table_columns' =>
true,
73 $this->services = $services;
80 if (!isset($GLOBALS[
'START_MICROTIME'])) {
81 $GLOBALS[
'START_MICROTIME'] = microtime(
true);
84 $services->timer->begin([]);
93 if (!isset($GLOBALS[
'_ELGG'])) {
94 $GLOBALS[
'_ELGG'] = new \stdClass();
97 $this->engine_dir = __DIR__ .
'/../..';
109 $this->services->config->loadSettingsFile();
122 if (function_exists(
'elgg')) {
126 $lib_dir = self::elggDir()->chroot(
"engine/lib");
165 'private_settings.php',
180 'deprecated-1.9.php',
181 'deprecated-1.10.php',
182 'deprecated-1.11.php',
183 'deprecated-1.12.php',
184 'deprecated-2.1.php',
188 call_user_func(
function () use ($lib_dir, $lib_files) {
193 foreach ($lib_files as
$file) {
194 $setup = (require_once $lib_dir->getPath(
$file));
196 if ($setup instanceof \Closure) {
197 $setups[
$file] = $setup;
202 self::$_instance = $this;
207 $events = $this->services->events;
208 $hooks = $this->services->hooks;
211 foreach ($setups as $func) {
212 $func($events, $hooks);
223 $app = self::create();
243 $config = $this->services->config;
245 if ($this->isTestingApplication()) {
246 throw new \RuntimeException(
'Unit tests should not call ' . __METHOD__);
249 if ($config->getVolatile(
'boot_complete')) {
253 $this->loadSettings();
255 $config->set(
'boot_complete',
false);
258 $config->set(
'default_limit', 10);
263 $events = $this->services->events;
267 $events->trigger(
'boot',
'system');
270 $this->services->plugins->load();
272 $root = Directory\Local::root();
273 if ($root->getPath() != self::elggDir()->getPath()) {
278 $viewsFile = $root->getFile(
'views.php');
279 if ($viewsFile->exists()) {
280 $viewsSpec = $viewsFile->includeFile();
281 if (is_array($viewsSpec)) {
291 _elgg_services()->translator->registerPluginTranslations($root->getPath());
295 $root_start = $root->getPath(
"start.php");
296 if (is_file($root_start)) {
310 $this->allowPathRewrite();
313 $events->trigger(
'plugins_boot',
'system');
316 $events->trigger(
'init',
'system');
318 $config->set(
'boot_complete',
true);
321 $events->trigger(
'ready',
'system');
337 $this->loadSettings();
338 return $this->services->publicDb;
349 if (isset(self::$public_services[
$name])) {
350 return $this->services->{
$name};
352 trigger_error(
"Undefined property: " . __CLASS__ .
":\${$name}");
361 private static function create() {
362 if (self::$_instance ===
null) {
365 register_shutdown_function(
function () {
367 if (function_exists(
'_elgg_shutdown_hook')) {
372 self::$_instance =
new self(
new Di\ServiceProvider(
new Config()));
375 return self::$_instance;
384 return self::create()->run();
393 $path = $this->setupPath();
396 if (isset($_GET[self::REWRITE_TEST_TOKEN])) {
397 if (
false !== strpos(
$path, self::REWRITE_TEST_TOKEN)) {
398 echo self::REWRITE_TEST_OUTPUT;
403 if (php_sapi_name() ===
'cli-server') {
404 $www_root =
"http://{$_SERVER['SERVER_NAME']}:{$_SERVER['SERVER_PORT']}/";
405 $this->services->config->set(
'wwwroot', $www_root);
408 if (0 === strpos(
$path,
'/cache/')) {
409 (
new Application\CacheHandler($this, $this->services->config, $_SERVER))->handleRequest(
$path);
413 if (0 === strpos(
$path,
'/serve-file/')) {
414 $this->services->serveFileHandler->getResponse($this->services->request)->send();
418 if (
$path ===
'/rewrite.php') {
419 require Directory\Local::root()->getPath(
"install.php");
423 if (php_sapi_name() ===
'cli-server') {
434 header(
"Content-Type: text/html;charset=utf-8");
436 if (!$this->services->router->route($this->services->request)) {
450 $app = self::create();
451 $app->services->config->loadSettingsFile();
453 if ($GLOBALS[
'_ELGG']->dataroot_in_settings) {
454 return $app->services->config->getVolatile(
'dataroot');
457 $dataroot = $app->services->datalist->get(
'dataroot');
459 throw new \InstallationException(
'The datalists table lacks a value for "dataroot".');
462 $app->services->config->set(
'dataroot',
$dataroot);
473 return Directory\Local::fromPath(realpath(__DIR__ .
'/../../..'));
482 ini_set(
'display_errors', 1);
504 ini_set(
'display_errors', 1);
506 define(
'UPGRADING',
'upgrading');
511 $site_host = parse_url(
$site_url, PHP_URL_HOST) .
'/';
525 if (
$result[
'failure'] ==
true) {
530 $rewriteTester = new \ElggRewriteTester();
532 if (!$rewriteTester->runRewriteTest(
$url)) {
535 if (!$rewriteTester->runLocalhostAccessTest()) {
537 $msg =
elgg_echo(
"installation:htaccess:localhost:connectionfailed");
538 if ($msg ===
"installation:htaccess:localhost:connectionfailed") {
539 $msg =
"Elgg cannot connect to itself to test rewrite rules properly. Check "
540 .
"that curl is working and there are no IP restrictions preventing "
541 .
"localhost connections.";
548 $msg =
elgg_echo(
"installation:htaccess:needs_upgrade");
549 if ($msg ===
"installation:htaccess:needs_upgrade") {
550 $msg =
"You must update your .htaccess file so that the path is injected "
551 .
"into the GET parameter __elgg_uri (you can use install/config/htaccess.dist as a guide).";
576 private function setupPath() {
577 if (!isset($_GET[self::GET_PATH_KEY]) || is_array($_GET[self::GET_PATH_KEY])) {
578 if (php_sapi_name() ===
'cli-server') {
579 $_GET[self::GET_PATH_KEY] = (string)parse_url($_SERVER[
"REQUEST_URI"], PHP_URL_PATH);
581 $_GET[self::GET_PATH_KEY] =
'/';
586 $_GET[self::GET_PATH_KEY] =
'/' . trim($_GET[self::GET_PATH_KEY],
'/');
588 return $_GET[self::GET_PATH_KEY];
596 private function allowPathRewrite() {
597 $request = $this->services->request;
598 $new = $this->services->router->allowRewrite($request);
599 if (
$new === $request) {
603 $this->services->setValue(
'request',
$new);
614 self::$testing_app = $testing;
622 return (
bool) self::$testing_app;
if($guid==elgg_get_logged_in_user_guid()) $name
clearfix elgg elgg elgg elgg page header
elgg_reset_system_cache()
Reset the system cache by deleting the caches.
static setTestingApplication($testing=true)
Flag this application as running for testing (PHPUnit)
__construct(ServiceProvider $services)
Constructor.
static elggDir()
Returns a directory that points to the root of Elgg, but not necessarily the install root.
bootCore()
Bootstrap the Elgg engine, loads plugins, and calls initial system events.
static upgrade()
Elgg upgrade script.
static index()
Elgg's front controller.
static getDataPath()
Determine the Elgg data directory with trailing slash, save it to config, and return it.
loadCore()
Load all Elgg procedural code and wire up boot events, but don't boot.
static isTestingApplication()
Checks if the application is running in PHPUnit.
run()
Routes the request, booting core if not yet booted.
static start()
Replacement for loading engine/start.php.
static $_instance
Reference to the loaded Application returned by elgg()
getDb()
Get a Database wrapper for performing queries without booting Elgg.
__get($name)
Get an undefined property.
static install()
Renders a web UI for installing Elgg.
loadSettings()
Load settings.php.
elgg_get_site_url($site_guid=0)
Get the URL for the current (or specified) site.
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
register_error($error)
Display an error on next page load.
_elgg_shutdown_hook()
Emits a shutdown:system event upon PHP shutdown, but before database connections are dropped.
forward($location="", $reason='system')
Forward to $location.
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
if(! $entity->delete()) $forward_url
A simple directory abstraction.
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
elgg_get_viewtype()
Return the current view type.
elgg_is_registered_viewtype($viewtype)
Checks if $viewtype is registered.
elgg_view_page($title, $body, $page_shell='default', $vars=array())
Assembles and outputs a full page.
elgg_set_viewtype($viewtype="")
Manually set the viewtype.
elgg_normalize_site_url($unsafe_url)
From untrusted input, get a site URL safe for forwarding.
_elgg_set_initial_context(\Elgg\Http\Request $request)
Set an initial context if using index.php front controller.
if(!array_key_exists($filename, $text_files)) $file