Exemple #1
0
/**
 * Load config options from config.inc.php and database and
 * setup sane defaults.
 * Return configuration in global $config array variable
 *
 * @todo    Add security check if install.php is still available
 * @param   boolean force reload of configuration data
 */
function load_config($force_reload = false)
{
    global $config, $lang, $smarty;
    // configuration cached and not outdated?
    if (!$force_reload && !$config['recompile'] && session_get('config') && session_get('config_userid') === $_COOKIE['VDBuserid'] && session_get('config_timestamp') == filemtime(CONFIG_FILE)) {
        // load from cache
        $config = session_get('config');
    } else {
        // check MySQL extension and cache directories
        verify_installation();
        // remember modification time
        session_set('config_timestamp', filemtime(CONFIG_FILE));
        // get config options from the database
        $SELECT = 'SELECT opt,value
                     FROM ' . TBL_CONFIG;
        $result = runSQL($SELECT);
        $config = array_merge($config, array_associate($result, 'opt', 'value'));
        // check if database matches the current version
        if ($config['dbversion'] < DB_REQUIRED) {
            // run installer
            redirect('install.php?action=upgrade');
        }
        // get user config options from the database
        // does not use get_current_user_id() to allow fallback to login page after loading config
        if (is_numeric($user_id = $_COOKIE['VDBuserid'])) {
            // store user id in session to identify reload point for config
            session_set('config_userid', $user_id);
            $SQL = 'SELECT opt, value
                         FROM ' . TBL_USERCONFIG . '
                        WHERE user_id = ' . $user_id;
            $result = runSQL($SQL);
            $config = array_merge($config, array_associate($result, 'opt', 'value'));
        }
        // set some defaults
        if (empty($config['language'])) {
            $config['language'] = 'en';
        }
        if (empty($config['template'])) {
            $config['template'] = 'modern::compact';
        }
        if (empty($config['filterdefault'])) {
            $config['filterdefault'] = 'unseen';
        }
        //      if ($config['IMDBage'] < 1) $config['IMDBage']          = 60*60*24*5;
        if ($config['castcolumns'] < 1) {
            $config['castcolumns'] = 4;
        }
        if ($config['listcolumns'] < 1) {
            $config['listcolumns'] = 1;
        }
        if ($config['thumbAge'] < 1) {
            $config['thumbAge'] = 60 * 60 * 24 * 7 * 3;
        }
        if ($config['shownew'] < 1) {
            $config['shownew'] = 12;
        }
        // prepare som options for later use
        $config['languages'] = explode('::', $config['languageflags']);
        // prepare template/style
        $tpl = explode('::', $config['template']);
        $config['style'] = 'templates/' . $tpl[0] . '/' . $tpl[1] . '.css';
        $config['templatedir'] = 'templates/' . $tpl[0] . '/';
        /*
                // multiple style files - use template name as base (e.g. elegant_grey.css)
                if (!file_exists($config['style']))
                {
                    // this should be an array
                    $config['style']    = array('templates/'.$tpl[0].'/'.$tpl[0].'.css',
                                                'templates/'.$tpl[0].'/'.$tpl[0].'_'.$tpl[1].'.css');
                }
        */
        // check if selected template is valid
        if (!file_exists($config['style'])) {
            $config['template'] = 'elegant::grey';
            $config['templatedir'] = 'templates/elegant/';
            $config['style'] = 'templates/elegant/grey.css';
        }
        // smarty cacheid for multiuser mode
        $config['cacheid'] = $tpl[0];
        // get installed engines meta information
        if (empty($config['engines'])) {
            require_once './engines/engines.php';
            $config['engines'] = engineMeta();
            // translate config options of type engine xyz into config[engine]
            foreach ($config['engines'] as $engine => $meta) {
                // convert the db engine options into associative array of engine enabled status
                if ($config['engine' . $engine]) {
                    $config['engine'][$engine] = $config['engine' . $engine];
                    // add meta-engine if enabled
                    engine_setup_meta($engine, $meta);
                }
            }
        }
        /*
                // added proxy support for $_ENV
                $proxy = $config['proxy_host'];
                if (empty($proxy))
                {
                    $env = array_change_key_case($_ENV);
                    $proxy = $env['http_proxy'];
                }
                if (!empty($proxy))
                {
                    $uri = parse_url($proxy);
                    $config['proxy_host'] = ($uri['scheme']) ? $uri['host'] : $uri['path'];
                    $config['proxy_port'] = ($uri['port']) ? $uri['port'] : 8080;
                }
        */
        // store loaded configuration
        session_set('config', $config);
    }
    // setup smarty
    $smarty->template_dir = array($config['templatedir'], 'templates/modern');
    $smarty->assign('template', $config['templatedir']);
    // initialize languages
    $lang = array();
    // load english language as default
    require './language/en.php';
    // override it with local language if nessesary:
    if ($config['language'] != 'en') {
        $languages = explode('_', $config['language']);
        $file = '';
        foreach ($languages as $language) {
            if ($file) {
                $file .= '_';
            }
            $file .= $language;
            @(include './language/' . $file . '.php');
            // convert languages to utf-8 encoding
            if ($lang['encoding'] != 'utf-8') {
                $lang = iconv_array($lang['encoding'], 'utf-8', $lang);
                $lang['encoding'] = 'utf-8';
            }
        }
    }
    // set connection character set and collation
    #   db_set_encoding();
}
Exemple #2
0
    }
    // make sure default engine ist active
    if (!empty($enginedefault)) {
        $opt = 'engine' . $enginedefault;
        ${$opt} = 1;
    }
    $config['engine'] = array();
    foreach ($config['engines'] as $engine => $meta) {
        $opt = 'engine' . $engine;
        $SQL = 'REPLACE INTO ' . TBL_CONFIG . " (opt,value) VALUES ('{$opt}','" . addslashes(${$opt}) . "')";
        runSQL($SQL);
        // mark engine as available
        $config['engine'][$engine] = ${$opt};
        // add meta-engine if enabled
        if (${$opt}) {
            engine_setup_meta($engine, $meta);
        }
    }
    // update session variables
    update_session();
    // remove user-specific config options
    $user_id = get_current_user_id();
    if (!empty($user_id)) {
        $SQL = "DELETE FROM " . TBL_USERCONFIG . " WHERE user_id = '" . addslashes($user_id) . "'";
        runSQL($SQL);
    }
    // make sure no artifacts
    $smarty->clearCache('list.tpl');
    // reload config
    load_config(true);
}