Beispiel #1
0
function meiu_bootstrap()
{
    unset_globals();
    global $base_url, $base_path, $base_root, $language, $templatelangs;
    timer_start('page');
    require_once COREDIR . 'loader.php';
    require_once INCDIR . 'functions.php';
    include_once INCDIR . 'plugin.php';
    init_defines();
    if (file_exists(COREDIR . 'lang' . DIRECTORY_SEPARATOR . LANGSET . '.lang.php')) {
        require_once COREDIR . 'lang' . DIRECTORY_SEPARATOR . LANGSET . '.lang.php';
    }
    boot_init();
    $plugin =& loader::lib('plugin');
    $Config =& loader::config();
    if (!$Config['safemode']) {
        $plugin->init_plugins();
    }
    $plugin->trigger('boot_init');
    //输出对象
    $output =& loader::lib('output');
    //载入当前用户信息
    $user =& loader::model('user');
    $output->set('loggedin', $user->loggedin());
    if ($user->loggedin()) {
        $output->set('u_info', $user->get_all_field());
        $user_extrainfo = $user->get_extra($user->get_field('id'));
        $output->set('u_extrainfo', $user_extrainfo);
        $user_theme = isset($user_extrainfo['theme']) ? $user_extrainfo['theme'] : '';
    } else {
        $user_theme = null;
    }
    init_template($user_theme);
    $templatelangs = array();
    $uri =& loader::lib('uri');
    $uriinfo = $uri->parse_uri();
    $setting_mdl =& loader::model('setting');
    //如果数据库中的版本和程序版本不一致则跳转到执行自动升级脚本
    $version = $setting_mdl->get_conf('system.version');
    if ($version != MPIC_VERSION) {
        if (file_exists(ROOTDIR . 'install/upgrade.php')) {
            include ROOTDIR . 'install/upgrade.php';
            exit;
        }
    }
    $output->set('base_path', $base_path);
    $output->set('statics_path', $base_path . 'statics/');
    $output->set('site_logo', $setting_mdl->get_conf('site.logo', ''));
    $output->set('site_name', $setting_mdl->get_conf('site.title', lang('myalbum')));
    define('IN_CTL', $uriinfo['ctl']);
    define('IN_ACT', $uriinfo['act']);
    $_GET = array_merge($_GET, $uriinfo['pars']);
    $_REQUEST = array_merge($_REQUEST, $uriinfo['pars']);
    require_once INCDIR . 'pagecore.php';
    if ($plugin->has_trigger('custom_page.' . IN_CTL . '.' . IN_ACT) || $plugin->has_trigger('custom_page.' . IN_CTL)) {
        $plugin->trigger('custom_page.' . IN_CTL . '.' . IN_ACT) || $plugin->trigger('custom_page.' . IN_CTL, IN_ACT);
    } else {
        if (file_exists(CTLDIR . $uriinfo['ctl'] . '.ctl.php')) {
            require_once CTLDIR . $uriinfo['ctl'] . '.ctl.php';
            $controller_name = $uriinfo['ctl'] . '_ctl';
            $controller = new $controller_name();
            $controller->_init();
            if (method_exists($controller, $uriinfo['act'])) {
                call_user_func(array($controller, $uriinfo['act']));
            } else {
                header("HTTP/1.1 404 Not Found");
                showError(lang('404_not_found'));
            }
            $controller->_called();
        } else {
            header("HTTP/1.1 404 Not Found");
            showError(lang('404_not_found'));
        }
    }
}
Beispiel #2
0
function bootstrap()
{
    global $base_url, $base_path, $base_root;
    global $db_url, $session_name, $login_lifetime;
    if (isset($_SERVER['HTTP_HOST'])) {
        $_SERVER['HTTP_HOST'] = strtolower($_SERVER['HTTP_HOST']);
        if (!validate_host_name($_SERVER['HTTP_HOST'])) {
            header('HTTP/1.1 400 Bad Request');
            exit;
        }
    } else {
        $_SERVER['HTTP_HOST'] = '';
    }
    unset_globals();
    @(include 'settings.inc');
    @(include 'config.inc');
    @(include 'db.inc');
    if ($db_url == 'mysql://*****:*****@localhost/databasename') {
        $db_url = false;
    }
    if ($db_url) {
        require_once 'pdo.php';
        db_connect($db_url);
    }
    if ($base_url) {
        $base_url = trim($base_url, '/');
        $url = parse_url($base_url);
        if (!isset($url['path'])) {
            $url['path'] = '';
        }
        $base_path = $url['path'];
        $base_root = substr($base_url, 0, strlen($base_url) - strlen($base_path));
    } else {
        $base_root = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
        $base_url = $base_root .= '://' . $_SERVER['HTTP_HOST'];
        if ($dir = trim(dirname($_SERVER['SCRIPT_NAME']), '\\,/')) {
            $base_path = '/' . $dir;
            $base_url .= $base_path;
        } else {
            $base_path = '';
        }
    }
    if (!$session_name) {
        list(, $session_name) = explode('://', $base_url, 2);
        $session_name = 'izend@' . $session_name;
        if (ini_get('session.cookie_secure')) {
            $session_name .= 'SSL';
        }
    }
    session_open(md5($session_name));
    if (isset($_SESSION['user']['lasttime'])) {
        $now = time();
        if ($now - $_SESSION['user']['lasttime'] > $login_lifetime) {
            unset($_SESSION['user']);
        } else {
            $_SESSION['user']['lasttime'] = $now;
        }
    }
    if (!empty($_SESSION['user']['timezone'])) {
        date_default_timezone_set($_SESSION['user']['timezone']);
    }
}