示例#1
0
 /**
  * Check if Elgg has been installed
  * @return bool
  */
 private function isInstalled()
 {
     $path = Local::root()->getPath('engine/settings.php');
     if (!is_file($path)) {
         $path = Local::root()->getPath('elgg-config/settings.php');
     }
     return is_file($path);
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 protected function handle()
 {
     $params = array('displayname' => 'Administrator', 'username' => $this->ask('Enter admin username: '******'admin'), 'password' => $this->ask('Enter admin password: '******'email' => $email = $this->ask('Enter admin email: '), 'dbuser' => $this->ask('Enter database username: '******'dbpassword' => $this->ask('Enter database password: '******'dbname' => $this->ask('Enter database name: '), 'dbprefix' => $this->ask('Enter database prefix [elgg_]: ', 'elgg_'), 'sitename' => $this->ask('Enter site name: '), 'siteemail' => $this->ask("Enter site email [{$email}]: ", $email), 'wwwroot' => $this->ask('Enter site URL [http://localhost/]: ', 'http://localhost/'), 'dataroot' => $this->ask('Enter data directory path: '), 'timezone' => 'UTC');
     global $CONFIG;
     $CONFIG = new \stdClass();
     $CONFIG->system_cache_enabled = false;
     foreach ($params as $key => $value) {
         $CONFIG->{$key} = $value;
     }
     $installer = new ElggInstaller();
     $htaccess = !is_file(\Elgg\Filesystem\Directory\Local::root()->getPath('.htaccess'));
     $installer->batchInstall($params, $htaccess);
     system_message('Installation is successful');
 }
示例#3
0
/**
 * Get the root directory path for this installation
 *
 * Note: This is not the same as the Elgg root! In the Elgg 1.x series, Elgg
 * was always at the install root, but as of 2.0, Elgg can be installed as a
 * composer dependency, so you cannot assume that it the install root anymore.
 *
 * @return string
 * @since 1.8.0
 */
function elgg_get_root_path()
{
    return Directory\Local::root()->getPath('/');
}
示例#4
0
 /**
  * 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);
 }
示例#5
0
文件: Config.php 项目: elgg/elgg
 /**
  * {@inheritdoc}
  */
 public function loadSettingsFile()
 {
     if ($this->settings_loaded) {
         return;
     }
     if (isset($this->config->Config_file)) {
         if ($this->config->Config_file === false) {
             $this->settings_loaded = true;
             return;
         }
         $path = $this->config->Config_file;
     } else {
         $path = Directory\Local::root()->getPath('engine/settings.php');
         if (!is_file($path)) {
             $path = Directory\Local::root()->getPath('elgg-config/settings.php');
         }
     }
     // No settings means a fresh install
     if (!is_file($path)) {
         if ($this->getVolatile('installer_running')) {
             $this->settings_loaded = true;
             return;
         }
         header("Location: install.php");
         exit;
     }
     if (!is_readable($path)) {
         echo "The Elgg settings file exists but the web server doesn't have read permission to it.";
         exit;
     }
     // we assume settings is going to write to CONFIG, but we may need to copy its values
     // into our local config
     global $CONFIG;
     $global_is_bound = isset($CONFIG) && $CONFIG === $this->config;
     require_once $path;
     // normalize commonly needed values
     if (isset($CONFIG->dataroot)) {
         $CONFIG->dataroot = rtrim($CONFIG->dataroot, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
         $GLOBALS['_ELGG']->dataroot_in_settings = true;
     } else {
         $GLOBALS['_ELGG']->dataroot_in_settings = false;
     }
     $GLOBALS['_ELGG']->simplecache_enabled_in_settings = isset($CONFIG->simplecache_enabled);
     if (!empty($CONFIG->cacheroot)) {
         $CONFIG->cacheroot = rtrim($CONFIG->cacheroot, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
     }
     if (!$global_is_bound) {
         // must manually copy settings into our storage
         foreach ($CONFIG as $key => $value) {
             $this->config->{$key} = $value;
         }
     }
     $this->settings_loaded = true;
 }
示例#6
0
 /**
  * Confirm that the rewrite rules are firing
  *
  * @param array &$report The requirements report array
  *
  * @return void
  */
 protected function checkRewriteRules(&$report)
 {
     $tester = new ElggRewriteTester();
     $url = _elgg_services()->config->getSiteUrl() . "rewrite.php";
     $report['rewrite'] = array($tester->run($url, Directory\Local::root()->getPath()));
 }
示例#7
0
<?php

use Elgg\Filesystem\Directory;
$subject = elgg_extract("subject", $vars);
$message = nl2br(elgg_extract("body", $vars));
$language = elgg_extract("language", $vars, get_current_language());
$recipient = elgg_extract("recipient", $vars);
$site = elgg_get_site_entity();
$site_url = elgg_get_site_url();
$isElggAtRoot = Elgg\Application::elggDir()->getPath() === Directory\Local::root()->getPath();
$elggSubdir = $isElggAtRoot ? '' : 'vendor/elgg/elgg/';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php 
echo $language;
?>
" lang="<?php 
echo $language;
?>
">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<base target="_blank" />
		
		<?php 
if (!empty($subject)) {
    echo elgg_format_element('title', [], $subject);
}
?>
	</head>
	<body>
示例#8
0
 /**
  * Returns a directory that points to the root of Elgg, but not necessarily
  * the install root. See `self::root()` for that.
  * 
  * @return Directory
  */
 public static function elggDir()
 {
     return Directory\Local::fromPath(realpath(__DIR__ . '/../../..'));
 }
示例#9
0
 /**
  * Merge a specification of absolute view paths
  *
  * @param array $spec Specification
  *    viewtype => [
  *        view_name => path or array of paths
  *    ]
  *
  * @access private
  */
 public function mergeViewsSpec(array $spec)
 {
     foreach ($spec as $viewtype => $list) {
         foreach ($list as $view => $paths) {
             if (!is_array($paths)) {
                 $paths = [$paths];
             }
             foreach ($paths as $path) {
                 if (preg_match('~^([/\\\\]|[a-zA-Z]\\:)~', $path)) {
                     // absolute path
                 } else {
                     // relative path
                     $path = Directory\Local::root()->getPath($path);
                 }
                 if (substr($view, -1) === '/') {
                     // prefix
                     $this->autoregisterViews($view, $path, $viewtype);
                 } else {
                     $this->setViewLocation($view, $viewtype, $path);
                 }
             }
         }
     }
 }
示例#10
0
 /**
  * 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;
 }
示例#11
0
/**
 * Loads configuration related to Elgg as an application
 *
 * This runs on the engine boot and loads from the datalists database table.
 * 
 * @see _elgg_engine_boot()
 * 
 * @access private
 */
function _elgg_load_application_config()
{
    _elgg_services()->timer->begin([__FUNCTION__]);
    global $CONFIG;
    $install_root = Directory\Local::root();
    $defaults = array('path' => $install_root->getPath("/"), 'plugins_path' => $install_root->getPath("mod") . "/", 'language' => 'en', 'pluginspath' => $install_root->getPath("mod") . "/");
    foreach ($defaults as $name => $value) {
        if (empty($CONFIG->{$name})) {
            $CONFIG->{$name} = $value;
        }
    }
    $GLOBALS['_ELGG']->view_path = \Elgg\Application::elggDir()->getPath("/views/");
    // set cookie values for session and remember me
    _elgg_configure_cookies($CONFIG);
    if (!is_memcache_available()) {
        _elgg_services()->datalist->loadAll();
    }
    // make sure dataroot gets set
    \Elgg\Application::getDataPath();
    if (!$GLOBALS['_ELGG']->simplecache_enabled_in_settings) {
        $simplecache_enabled = datalist_get('simplecache_enabled');
        $CONFIG->simplecache_enabled = $simplecache_enabled === false ? 1 : $simplecache_enabled;
    }
    $system_cache_enabled = datalist_get('system_cache_enabled');
    $CONFIG->system_cache_enabled = $system_cache_enabled === false ? 1 : $system_cache_enabled;
    // needs to be set before system, init for links in html head
    $CONFIG->lastcache = (int) datalist_get("simplecache_lastupdate");
    $GLOBALS['_ELGG']->i18n_loaded_from_cache = false;
    // this must be synced with the enum for the entities table
    $CONFIG->entity_types = array('group', 'object', 'site', 'user');
    _elgg_services()->timer->end([__FUNCTION__]);
}
示例#12
0
 public function testCanRegisterActionWithoutFilename()
 {
     $this->assertTrue($this->actions->register('login'));
     $actions = $this->actions->getAllActions();
     $this->assertArrayHasKey('login', $actions);
     $this->assertEquals(['file' => realpath(Filesystem\Directory\Local::root()->getPath() . 'actions/login.php'), 'access' => 'logged_in'], $actions['login']);
 }
示例#13
0
文件: BootService.php 项目: elgg/elgg
 /**
  * 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);
 }