Returns a directory that points to the root of Elgg, but not necessarily
the install root. See self::root() for that.
public static elggDir ( ) : Elgg\Filesystem\Directory | ||
return | Elgg\Filesystem\Directory |
/** * @access private */ function _elgg_config_test($hook, $type, $tests) { $tests[] = \Elgg\Application::elggDir()->getPath("engine/tests/ElggCoreConfigTest.php"); return $tests; }
/** * Initialize the site including site entity, plugins, and configuration * * @param array $submissionVars Submitted vars * * @return bool */ protected function saveSiteSettings($submissionVars) { // ensure that file path, data path, and www root end in / $submissionVars['dataroot'] = sanitise_filepath($submissionVars['dataroot']); $submissionVars['wwwroot'] = sanitise_filepath($submissionVars['wwwroot']); $site = new ElggSite(); $site->name = strip_tags($submissionVars['sitename']); $site->url = $submissionVars['wwwroot']; $site->access_id = ACCESS_PUBLIC; $site->email = $submissionVars['siteemail']; $guid = $site->save(); if (!$guid) { register_error(_elgg_services()->translator->translate('install:error:createsite')); return FALSE; } // bootstrap site info $this->CONFIG->site_guid = $guid; $this->CONFIG->site = $site; _elgg_services()->configTable->set('installed', time()); _elgg_services()->configTable->set('dataroot', $submissionVars['dataroot']); _elgg_services()->configTable->set('default_site', $site->getGUID()); _elgg_services()->configTable->set('version', elgg_get_version()); _elgg_services()->configTable->set('simplecache_enabled', 1); _elgg_services()->configTable->set('system_cache_enabled', 1); _elgg_services()->configTable->set('simplecache_lastupdate', time()); // new installations have run all the upgrades $upgrades = elgg_get_upgrade_files(\Elgg\Application::elggDir()->getPath("/engine/lib/upgrades/")); _elgg_services()->configTable->set('processed_upgrades', $upgrades); _elgg_services()->configTable->set('view', 'default', $site->getGUID()); _elgg_services()->configTable->set('language', 'en', $site->getGUID()); _elgg_services()->configTable->set('default_access', $submissionVars['siteaccess'], $site->getGUID()); _elgg_services()->configTable->set('allow_registration', TRUE, $site->getGUID()); _elgg_services()->configTable->set('walled_garden', FALSE, $site->getGUID()); _elgg_services()->configTable->set('allow_user_default_access', '', $site->getGUID()); _elgg_services()->configTable->set('default_limit', 10, $site->getGUID()); _elgg_services()->configTable->set('security_protect_upgrade', true, $site->getGUID()); _elgg_services()->configTable->set('security_notify_admins', true, $site->getGUID()); _elgg_services()->configTable->set('security_notify_user_password', true, $site->getGUID()); _elgg_services()->configTable->set('security_email_require_password', true, $site->getGUID()); $this->setSubtypeClasses(); $this->enablePlugins(); return TRUE; }
/** * Make it possible for composer-managed Elgg site to recognize plugins * version-controlled in Elgg core. * * @param string $plugin The name of the plugin to symlink * * @return bool Whether the symlink succeeded. */ private static function symlinkPluginFromRootToElgg($plugin) { $from = Directory\Local::root()->getPath("mod/{$plugin}"); $to = Elgg\Application::elggDir()->getPath("mod/{$plugin}"); return !file_exists($from) && symlink($to, $from); }
<?php /** * Core Elgg JavaScript file */ // this warning is due to the change in JS boot order in Elgg 1.9 echo <<<JS if (typeof elgg != 'object') { \tthrow new Error('elgg configuration object is not defined! You must include the js/initialize_elgg view in html head before JS library files!'); } JS; // We use named AMD modules and inline them here in order to save HTTP requests, // as these modules will be required on each page echo elgg_view('elgg/popup.js'); $elggDir = \Elgg\Application::elggDir(); $files = array($elggDir->getPath("js/lib/elgglib.js"), $elggDir->getPath("js/classes/ElggEntity.js"), $elggDir->getPath("js/classes/ElggUser.js"), $elggDir->getPath("js/classes/ElggPriorityList.js"), $elggDir->getPath("js/lib/prototypes.js"), $elggDir->getPath("js/lib/hooks.js"), $elggDir->getPath("js/lib/security.js"), $elggDir->getPath("js/lib/languages.js"), $elggDir->getPath("js/lib/ajax.js"), $elggDir->getPath("js/lib/session.js"), $elggDir->getPath("js/lib/pageowner.js"), $elggDir->getPath("js/lib/configuration.js"), $elggDir->getPath("js/lib/comments.js"), $elggDir->getPath("js/lib/ui.js")); foreach ($files as $file) { readfile($file); // putting a new line between the files to address https://github.com/elgg/elgg/issues/3081 echo "\n"; } foreach (_elgg_get_js_site_data() as $expression => $value) { $value = json_encode($value); echo "{$expression} = {$value};\n"; } ?> //<script> // page data overrides site data $.extend(elgg.data, elgg._data); delete elgg._data;
/** * Get the current Elgg version information * * @param bool $human_readable Whether to return a human readable version (default: false) * * @return string|false Depending on success * @since 1.9 */ function elgg_get_version($human_readable = false) { static $version, $release; if (!isset($version) || !isset($release)) { $path = \Elgg\Application::elggDir()->getPath('version.php'); if (!is_file($path)) { return false; } include $path; } return $human_readable ? $release : $version; }
/** * Create Elgg's .htaccess file or confirm that it exists * * @param string $url URL of rewrite test * * @return bool */ public function createHtaccess($url) { $root = Directory\Local::root(); $file = $root->getFile(".htaccess"); if ($file->exists()) { // check that this is the Elgg .htaccess $data = $file->getContents(); if ($data === FALSE) { // don't have permission to read the file $this->htaccessIssue = 'read_permission'; return FALSE; } if (strpos($data, 'Elgg') === FALSE) { $this->htaccessIssue = 'non_elgg_htaccess'; return FALSE; } else { // check if this is an old Elgg htaccess if (strpos($data, 'RewriteRule ^rewrite.php$ install.php') == FALSE) { $this->htaccessIssue = 'old_elgg_htaccess'; return FALSE; } return TRUE; } } if (!is_writable($root->getPath())) { $this->htaccessIssue = 'write_permission'; return FALSE; } // create the .htaccess file $result = copy(\Elgg\Application::elggDir()->getPath("install/config/htaccess.dist"), $file->getPath()); if (!$result) { $this->htaccessIssue = 'cannot_copy'; return FALSE; } // does default RewriteBase work already? if (!$this->runRewriteTest($url)) { //try to rewrite to guessed subdirectory if ($subdir = $this->guessSubdirectory($url)) { $contents = $file->getContents(); $contents = preg_replace("/#RewriteBase \\/(\r?\n)/", "RewriteBase {$subdir}\$1", $contents); if ($contents) { $file->putContents($contents); } } } return TRUE; }
/** * Get the current Elgg version information * * @param bool $human_readable Whether to return a human readable version (default: false) * * @return string|false Depending on success * @since 1.9 */ function elgg_get_version($human_readable = false) { static $version, $release; if (!isset($version) || !isset($release)) { if (!(include \Elgg\Application::elggDir()->getPath('version.php'))) { return false; } } return $human_readable ? $release : $version; }
/** * Boots the engine * * @return void */ public function boot() { // Register the error handlers set_error_handler('_elgg_php_error_handler'); set_exception_handler('_elgg_php_exception_handler'); $db = _elgg_services()->db; // we inject the logger here to allow use of DB without loading core $db->setLogger(_elgg_services()->logger); $db->setupConnections(); $db->assertInstalled(); $CONFIG = _elgg_services()->config->getStorageObject(); $local_path = Local::root()->getPath(); // setup stuff available without any DB info $CONFIG->path = $local_path; $CONFIG->plugins_path = "{$local_path}mod/"; $CONFIG->pluginspath = "{$local_path}mod/"; $CONFIG->entity_types = ['group', 'object', 'site', 'user']; $CONFIG->language = 'en'; // set cookie values for session and remember me _elgg_services()->config->getCookieConfig(); // we need this stuff before cache $rows = $db->getData("\n\t\t\tSELECT *\n\t\t\tFROM {$db->prefix}config\n\t\t\tWHERE `name` IN ('__site_secret__', 'default_site', 'dataroot')\n\t\t"); $configs = []; foreach ($rows as $row) { $configs[$row->name] = unserialize($row->value); } // booting during installation if (empty($configs['dataroot'])) { $configs['dataroot'] = ''; // don't use cache $CONFIG->boot_cache_ttl = 0; } if (!$GLOBALS['_ELGG']->dataroot_in_settings) { $CONFIG->dataroot = rtrim($configs['dataroot'], '/\\') . DIRECTORY_SEPARATOR; } $CONFIG->site_guid = (int) $configs['default_site']; if (!isset($CONFIG->boot_cache_ttl)) { $CONFIG->boot_cache_ttl = self::DEFAULT_BOOT_CACHE_TTL; } if ($this->timer) { $this->timer->begin([__CLASS__ . '::getBootData']); } // early config is done, now get the core boot data $data = $this->getBootData($CONFIG, $db); if ($this->timer) { $this->timer->begin([__CLASS__ . '::getBootData']); } $configs_cache = $data->getConfigValues(); $CONFIG->site = $data->getSite(); $CONFIG->wwwroot = $CONFIG->site->url; $CONFIG->sitename = $CONFIG->site->name; $CONFIG->sitedescription = $CONFIG->site->description; $CONFIG->url = $CONFIG->wwwroot; _elgg_services()->subtypeTable->setCachedValues($data->getSubtypeData()); foreach ($data->getConfigValues() as $key => $value) { $CONFIG->{$key} = $value; } _elgg_services()->plugins->setBootPlugins($data->getActivePlugins()); _elgg_services()->pluginSettingsCache->setCachedValues($data->getPluginSettings()); if (!$GLOBALS['_ELGG']->simplecache_enabled_in_settings) { $simplecache_enabled = $configs_cache['simplecache_enabled']; $CONFIG->simplecache_enabled = $simplecache_enabled === false ? 1 : $simplecache_enabled; } $system_cache_enabled = $configs_cache['system_cache_enabled']; $CONFIG->system_cache_enabled = $system_cache_enabled === false ? 1 : $system_cache_enabled; // needs to be set before [init, system] for links in html head $CONFIG->lastcache = (int) $configs_cache['simplecache_lastupdate']; $GLOBALS['_ELGG']->i18n_loaded_from_cache = false; if (!empty($CONFIG->debug)) { _elgg_services()->logger->setLevel($CONFIG->debug); _elgg_services()->logger->setDisplay(true); } _elgg_services()->views->view_path = \Elgg\Application::elggDir()->getPath("/views/"); // finish boot sequence _elgg_session_boot(); if ($CONFIG->system_cache_enabled) { _elgg_services()->systemCache->loadAll(); } _elgg_services()->translator->loadTranslations(); // we always need site->email and user->icontime, so load them together $user_guid = _elgg_services()->session->getLoggedInUserGuid(); if ($user_guid) { _elgg_services()->metadataCache->populateFromEntities([$user_guid]); } // gives hint to get() how to approach missing values $CONFIG->site_config_loaded = true; // invalidate on some actions just in case other invalidation triggers miss something _elgg_services()->hooks->registerHandler('action', 'all', function ($action) { if (0 === strpos($action, 'admin/' || $action === 'plugins/settings/save')) { $this->invalidateCache(); } }, 1); }