/**
 * Run any php upgrade scripts which are required
 *
 * @param int $version Version upgrading from.
 * @param bool $quiet Suppress errors.  Don't use this.
 */
function upgrade_code($version, $quiet = FALSE)
{
    global $CONFIG;
    // Elgg and its database must be installed to upgrade it!
    if (!is_db_installed() || !is_installed()) {
        return FALSE;
    }
    $version = (int) $version;
    if ($handle = opendir($CONFIG->path . 'engine/lib/upgrades/')) {
        $upgrades = array();
        while ($updatefile = readdir($handle)) {
            // Look for upgrades and add to upgrades list
            if (!is_dir($CONFIG->path . 'engine/lib/upgrades/' . $updatefile)) {
                if (preg_match('/^([0-9]{10})\\.(php)$/', $updatefile, $matches)) {
                    $core_version = (int) $matches[1];
                    if ($core_version > $version) {
                        $upgrades[] = $updatefile;
                    }
                }
            }
        }
        // Sort and execute
        asort($upgrades);
        if (sizeof($upgrades) > 0) {
            foreach ($upgrades as $upgrade) {
                // hide all errors.
                if ($quiet) {
                    // hide include errors as well as any exceptions that might happen
                    try {
                        if (!@(include $CONFIG->path . 'engine/lib/upgrades/' . $upgrade)) {
                            error_log($e->getmessage());
                        }
                    } catch (Exception $e) {
                        error_log($e->getmessage());
                    }
                } else {
                    include $CONFIG->path . 'engine/lib/upgrades/' . $upgrade;
                }
            }
        }
        return TRUE;
    }
    return FALSE;
}
コード例 #2
0
ファイル: version.php プロジェクト: eokyere/elgg
/**
 * Run any php upgrade scripts which are required
 *
 * @param unknown_type $version
 */
function upgrade_code($version)
{
    global $CONFIG;
    // Elgg and its database must be installed to upgrade it!
    if (!is_db_installed() || !is_installed()) {
        return false;
    }
    $version = (int) $version;
    if ($handle = opendir($CONFIG->path . 'engine/lib/upgrades/')) {
        $upgrades = array();
        while ($updatefile = readdir($handle)) {
            // Look for upgrades and add to upgrades list
            if (!is_dir($CONFIG->path . 'engine/lib/upgrades/' . $updatefile)) {
                if (preg_match('/([0-9]*)\\.php/', $updatefile, $matches)) {
                    $core_version = (int) $matches[1];
                    if ($core_version > $version) {
                        $upgrades[] = $updatefile;
                    }
                }
            }
        }
        // Sort and execute
        asort($upgrades);
        if (sizeof($upgrades) > 0) {
            foreach ($upgrades as $upgrade) {
                try {
                    @(include $CONFIG->path . 'engine/lib/upgrades/' . $upgrade);
                } catch (Exception $e) {
                    error_log($e->getmessage());
                }
            }
        }
        return true;
    }
    return false;
}
コード例 #3
0
ファイル: sessions.php プロジェクト: jricher/Elgg
/**
 * Initialises the system session and potentially logs the user in
 * 
 * This function looks for:
 * 
 * 1. $_SESSION['id'] - if not present, we're logged out, and this is set to 0
 * 2. The cookie 'elggperm' - if present, checks it for an authentication token, validates it, and potentially logs the user in 
 *
 * @uses $_SESSION
 * @param unknown_type $event
 * @param unknown_type $object_type
 * @param unknown_type $object
 */
function session_init($event, $object_type, $object)
{
    global $DB_PREFIX, $CONFIG;
    if (!is_db_installed()) {
        return false;
    }
    // Use database for sessions
    $DB_PREFIX = $CONFIG->dbprefix;
    // HACK to allow access to prefix after object distruction
    if (!isset($CONFIG->use_file_sessions)) {
        session_set_save_handler("__elgg_session_open", "__elgg_session_close", "__elgg_session_read", "__elgg_session_write", "__elgg_session_destroy", "__elgg_session_gc");
    }
    session_name('Elgg');
    session_start();
    // Do some sanity checking by generating a fingerprint (makes some XSS attacks harder)
    if (isset($_SESSION['__elgg_fingerprint'])) {
        if ($_SESSION['__elgg_fingerprint'] != get_session_fingerprint()) {
            session_destroy();
            return false;
        }
    } else {
        $_SESSION['__elgg_fingerprint'] = get_session_fingerprint();
    }
    // Generate a simple token (private from potentially public session id)
    if (!isset($_SESSION['__elgg_session'])) {
        $_SESSION['__elgg_session'] = md5(microtime() . rand());
    }
    if (empty($_SESSION['guid'])) {
        if (isset($_COOKIE['elggperm'])) {
            $code = $_COOKIE['elggperm'];
            $code = md5($code);
            unset($_SESSION['guid']);
            //$_SESSION['guid'] = 0;
            unset($_SESSION['id']);
            //$_SESSION['id'] = 0;
            if ($user = get_user_by_code($code)) {
                $_SESSION['user'] = $user;
                $_SESSION['id'] = $user->getGUID();
                $_SESSION['guid'] = $_SESSION['id'];
                $_SESSION['code'] = $_COOKIE['elggperm'];
            }
        } else {
            unset($_SESSION['id']);
            //$_SESSION['id'] = 0;
            unset($_SESSION['guid']);
            //$_SESSION['guid'] = 0;
            unset($_SESSION['code']);
            //$_SESSION['code'] = "";
        }
    } else {
        if (!empty($_SESSION['code'])) {
            $code = md5($_SESSION['code']);
            if ($user = get_user_by_code($code)) {
                $_SESSION['user'] = $user;
                $_SESSION['id'] = $user->getGUID();
                $_SESSION['guid'] = $_SESSION['id'];
            } else {
                unset($_SESSION['user']);
                unset($_SESSION['id']);
                //$_SESSION['id'] = 0;
                unset($_SESSION['guid']);
                //$_SESSION['guid'] = 0;
                unset($_SESSION['code']);
                //$_SESSION['code'] = "";
            }
        } else {
            //$_SESSION['user'] = new ElggDummy();
            unset($_SESSION['id']);
            //$_SESSION['id'] = 0;
            unset($_SESSION['guid']);
            //$_SESSION['guid'] = 0;
            unset($_SESSION['code']);
            //$_SESSION['code'] = "";
        }
    }
    if ($_SESSION['id'] > 0) {
        set_last_action($_SESSION['id']);
    }
    register_action("login", true);
    register_action("logout");
    // Register a default PAM handler
    register_pam_handler('pam_auth_userpass');
    // Initialise the magic session
    global $SESSION;
    $SESSION = new ElggSession();
    // Finally we ensure that a user who has been banned with an open session is kicked.
    if (isset($_SESSION['user']) && $_SESSION['user']->isBanned()) {
        session_destroy();
        return false;
    }
    // Since we have loaded a new user, this user may have different language preferences
    register_translations(dirname(dirname(dirname(__FILE__))) . "/languages/");
    return true;
}
コード例 #4
0
ファイル: start.php プロジェクト: eokyere/elgg
        }
        if (!(include_once $file)) {
            throw new InstallationException("Could not load {$file}");
        }
    }
} else {
    // End portion for sanitised installs only
    throw new InstallationException(elgg_echo('installation:error:configuration'));
}
// Autodetect some default configuration settings
set_default_config();
// Trigger events
trigger_elgg_event('boot', 'system');
// Load plugins
$installed = is_installed();
$db_installed = is_db_installed();
// Determine light mode
$lm = strtolower(get_input('lightmode'));
if ($lm == 'true') {
    $lightmode = true;
}
// Load plugins, if we're not in light mode
if ($installed && $db_installed && $sanitised && !$lightmode) {
    load_plugins();
    trigger_elgg_event('plugins_boot', 'system');
}
// Forward if we haven't been installed
if ((!$installed || !$db_installed) && !substr_count($_SERVER["PHP_SELF"], "install.php") && !substr_count($_SERVER["PHP_SELF"], "css.php") && !substr_count($_SERVER["PHP_SELF"], "action_handler.php")) {
    header("Location: install.php");
    exit;
}
コード例 #5
0
/**
 * Upgrade the database schema in an ordered sequence.
 * 
 * Makes use of schema upgrade files
 * 
 * This is a about as core as it comes, so don't start running this from your plugins!
 *
 * @param int $version The version you are upgrading from (usually given in the Elgg version format of YYYYMMDDXX - see version.php for example)
 * @param string $fromdir Optional directory to load upgrades from (default: engine/schema/upgrades/)
 * @return bool
 */
function db_upgrade($version, $fromdir = "")
{
    global $CONFIG;
    // Elgg and its database must be installed to upgrade it!
    if (!is_db_installed() || !is_installed()) {
        return false;
    }
    $version = (int) $version;
    if (!$fromdir) {
        $fromdir = $CONFIG->path . 'engine/schema/upgrades/';
    }
    if ($handle = opendir($fromdir)) {
        $sqlupgrades = array();
        while ($sqlfile = readdir($handle)) {
            if (!is_dir($fromdir . $sqlfile)) {
                if (preg_match('/([0-9]*)\\.sql/', $sqlfile, $matches)) {
                    $sql_version = (int) $matches[1];
                    if ($sql_version > $version) {
                        $sqlupgrades[] = $sqlfile;
                    }
                }
            }
        }
        asort($sqlupgrades);
        if (sizeof($sqlupgrades) > 0) {
            foreach ($sqlupgrades as $sqlfile) {
                try {
                    run_sql_script($fromdir . $sqlfile);
                } catch (DatabaseException $e) {
                    error_log($e->getmessage());
                }
            }
        }
    }
    return true;
}
コード例 #6
0
ファイル: install.php プロジェクト: eokyere/elgg
 * @subpackage Core
 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
 * @author Curverider Ltd
 * @copyright Curverider Ltd 2008-2009
 * @link http://elgg.org/
 */
/**
 * Start the Elgg engine
 */
require_once dirname(__FILE__) . "/engine/start.php";
global $CONFIG;
elgg_set_viewtype('failsafe');
/**
 * If we're installed, go back to the homepage
 */
if (is_installed() && is_db_installed() && datalist_get('installed')) {
    forward("index.php");
}
/**
 * Install the database
 */
if (!is_db_installed()) {
    validate_platform();
    run_sql_script(dirname(__FILE__) . "/engine/schema/mysql.sql");
    init_site_secret();
    system_message(elgg_echo("installation:success"));
}
/**
 * Load the front page
 */
page_draw(elgg_echo("installation:settings"), elgg_view_layout("one_column", elgg_view("settings/install")));
コード例 #7
0
ファイル: elgglib.php プロジェクト: eokyere/elgg
/**
 * Get the value of a particular piece of data in the datalist
 *
 * @param string $name The name of the datalist
 * @return string|false Depending on success
 */
function datalist_get($name)
{
    global $CONFIG, $DATALIST_CACHE;
    // We need this, because sometimes datalists are received before the database is created
    if (!is_db_installed()) {
        return false;
    }
    $name = sanitise_string($name);
    if (isset($DATALIST_CACHE[$name])) {
        return $DATALIST_CACHE[$name];
    }
    // If memcache enabled then cache value in memcache
    $value = null;
    static $datalist_memcache;
    if (!$datalist_memcache && is_memcache_available()) {
        $datalist_memcache = new ElggMemcache('datalist_memcache');
    }
    if ($datalist_memcache) {
        $value = $datalist_memcache->load($name);
    }
    if ($value) {
        return $value;
    }
    // [Marcus Povey 20090217 : Now retrieving all datalist values on first load as this saves about 9 queries per page]
    $result = get_data("SELECT * from {$CONFIG->dbprefix}datalists");
    if ($result) {
        foreach ($result as $row) {
            $DATALIST_CACHE[$row->name] = $row->value;
            // Cache it if memcache is available
            if ($datalist_memcache) {
                $datalist_memcache->save($name, $row->value);
            }
        }
        if (isset($DATALIST_CACHE[$name])) {
            return $DATALIST_CACHE[$name];
        }
    }
    /*if ($row = get_data_row("SELECT value from {$CONFIG->dbprefix}datalists where name = '{$name}' limit 1")) {
    			$DATALIST_CACHE[$name] = $row->value;
    			
    			// Cache it if memcache is available
    			if ($datalist_memcache) $datalist_memcache->save($name, $row->value);
    			
    			return $row->value;
    		}*/
    return false;
}
コード例 #8
0
/**
 * Function that provides some config initialisation on system init
 *
 */
function configuration_init()
{
    global $CONFIG;
    if (is_installed() || is_db_installed()) {
        $path = datalist_get('path');
        if (!empty($path)) {
            $CONFIG->path = $path;
        }
        $dataroot = datalist_get('dataroot');
        if (!empty($dataroot)) {
            $CONFIG->dataroot = $dataroot;
        }
        $simplecache_enabled = datalist_get('simplecache_enabled');
        if ($simplecache_enabled !== false) {
            $CONFIG->simplecache_enabled = $simplecache_enabled;
        } else {
            $CONFIG->simplecache_enabled = 1;
        }
        $viewpath_cache_enabled = datalist_get('viewpath_cache_enabled');
        if ($viewpath_cache_enabled !== false) {
            $CONFIG->viewpath_cache_enabled = $viewpath_cache_enabled;
        } else {
            $CONFIG->viewpath_cache_enabled = 1;
        }
        if (isset($CONFIG->site) && $CONFIG->site instanceof ElggSite) {
            $CONFIG->wwwroot = $CONFIG->site->url;
            $CONFIG->sitename = $CONFIG->site->name;
            $CONFIG->sitedescription = $CONFIG->site->description;
            $CONFIG->siteemail = $CONFIG->site->email;
        }
        $CONFIG->url = $CONFIG->wwwroot;
        // Load default settings from database
        get_all_config();
        return true;
    }
}
コード例 #9
0
ファイル: sites.php プロジェクト: eokyere/elgg
/**
 * Initialise site handling
 *
 * Called at the beginning of system running, to set the ID of the current site.
 * This is 0 by default, but plugins may alter this behaviour by attaching functions
 * to the sites init event and changing $CONFIG->site_id.
 * 
 * @uses $CONFIG
 * @param string $event Event API required parameter
 * @param string $object_type Event API required parameter
 * @param null $object Event API required parameter
 * @return true
 */
function sites_init($event, $object_type, $object)
{
    global $CONFIG;
    if (is_installed() && is_db_installed()) {
        $site = trigger_plugin_hook("siteid", "system");
        if ($site === null || $site === false) {
            $CONFIG->site_id = (int) datalist_get('default_site');
        } else {
            $CONFIG->site_id = $site;
        }
        $CONFIG->site_guid = $CONFIG->site_id;
        $CONFIG->site = get_entity($CONFIG->site_guid);
        return true;
    }
    return true;
}