Example #1
0
function cs_checkdirs($dir, $show = 0)
{
    global $account;
    static $modules = array();
    if (!isset($modules[$dir])) {
        $modules[$dir] = cs_cache_dirs($dir, $account['users_lang']);
    }
    if (empty($show)) {
        $clean = $modules[$dir];
    } else {
        $clean = array();
        foreach ($modules[$dir] as $target) {
            if (isset($target['show'][$show])) {
                $create = $target['name'];
                $clean[$create] = $target;
            }
        }
    }
    return $clean;
}
Example #2
0
function cs_init($predefined)
{
    @error_reporting(E_ALL | E_STRICT);
    @set_error_handler("php_error");
    @ini_set('short_open_tag', 'off');
    @ini_set('arg_separator.output', '&');
    @ini_set('session.use_trans_sid', '0');
    @ini_set('session.use_cookies', '1');
    @ini_set('session.use_only_cookies', '1');
    @ini_set('display_errors', 'on');
    $phpversion = phpversion();
    if (version_compare($phpversion, '5.1', '>=')) {
        @date_default_timezone_set('Europe/Berlin');
    }
    global $account, $com_lang, $cs_db, $cs_logs, $cs_main, $cs_micro, $cs_template;
    $cs_micro = explode(' ', microtime());
    # starting parsetime
    $cs_logs = array('php_errors' => '', 'errors' => '', 'sql' => '', 'queries' => 0, 'warnings' => 1, 'dir' => 'uploads/logs');
    $cs_main['cellspacing'] = 1;
    $cs_main['def_lang'] = empty($cs_main['def_lang']) ? 'English' : $cs_main['def_lang'];
    $cs_main['def_theme'] = empty($cs_main['def_theme']) ? 'base' : $cs_main['def_theme'];
    $cs_main['xsrf_protection'] = true;
    $cs_main['zlib'] = true;
    require_once 'system/core/servervars.php';
    $cs_main['ajaxrequest'] = isset($_REQUEST['xhr']) ? true : false;
    require_once 'system/core/tools.php';
    require_once 'system/core/abcode.php';
    require_once 'system/core/templates.php';
    require_once 'system/core/gd.php';
    require_once 'system/core/cachegen.php';
    $cs_main['cache_mode'] = 'file';
    if (version_compare($phpversion, '5.0', '<')) {
        require_once 'mods/clansphere/fallback.php';
    }
    if ($cs_main['php_self']['basename'] == 'install.php') {
        $account = array('users_id' => 0, 'access_clansphere' => 0, 'access_errors' => 2, 'access_install' => 5);
    } else {
        file_exists('setup.php') ? require_once 'setup.php' : die(cs_error_internal('setup', '<a href="' . $cs_main['php_self']['dirname'] . 'install.php">Installation</a>'));
    }
    if (!in_array($cs_main['cache_mode'], array('file', 'none')) and !extension_loaded($cs_main['cache_mode'])) {
        $cs_main['cache_mode'] = 'file';
    }
    require_once 'system/cache/' . $cs_main['cache_mode'] . '.php';
    if (empty($cs_main['charset'])) {
        $cs_main['charset'] = 'UTF-8';
        die(cs_error_internal(0, 'No charset information found in setup.php'));
    }
    # backfall if json extension is not available
    if (!extension_loaded('json')) {
        require_once 'system/output/json.php';
    }
    require_once 'system/output/xhtml_10.php';
    # add old xhtml functions if needed
    if (!empty($cs_main['xhtml_old'])) {
        require_once 'system/output/xhtml_10_old.php';
    }
    if (!empty($predefined['init_sql'])) {
        require_once 'system/database/' . $cs_db['type'] . '.php';
        $cs_db['con'] = cs_sql_connect($cs_db);
        unset($cs_db['pwd'], $cs_db['user']);
        $cs_options = cs_sql_option(__FILE__, 'clansphere');
        $cs_options['unicode'] = extension_loaded('unicode') ? 1 : 0;
        if (!isset($cs_options['cache_unicode']) or $cs_options['cache_unicode'] != $cs_options['unicode']) {
            cs_cache_clear();
        }
    } else {
        $cs_options = array();
    }
    $cs_main = array_merge($cs_main, $cs_options, $predefined);
    if (empty($cs_main['def_path'])) {
        $cs_main['def_path'] = getcwd();
    }
    # process mod and action data
    $cs_main = cs_content_prepare($cs_main);
    if (!empty($predefined['init_sql'])) {
        require_once 'system/core/account.php';
        $cs_main['def_theme'] = empty($account['users_theme']) ? $cs_main['def_theme'] : $account['users_theme'];
    }
    # determine users language
    $account['users_lang'] = cs_content_lang();
    if (!empty($predefined['init_sql'])) {
        # check for deprecated runstartup behavior
        if (!empty($cs_main['runstartup'])) {
            cs_tasks('system/runstartup');
        }
        # fetch startup files
        $startup = cs_cache_load('startup');
        # fallback to create startup files overview
        if ($startup == false) {
            $startup = cs_cache_dirs('mods', $account['users_lang'], 1);
        }
        # execute startup files
        if (is_array($startup)) {
            foreach ($startup as $mod) {
                $file = $cs_main['def_path'] . '/mods/' . $mod . '/startup.php';
                file_exists($file) ? include_once $file : cs_error($file, 'cs_init - Startup file not found');
            }
        }
    }
    # search for possible mod and action errors
    $cs_main = cs_content_check($cs_main);
    $cs_main['template'] = empty($cs_main['def_tpl']) ? 'clansphere' : $cs_main['def_tpl'];
    $cs_template = cs_template_info($cs_main['template']);
    if (!empty($_GET['template']) and preg_match("=^[_a-z0-9-]+\$=i", $_GET['template'])) {
        $cs_main['template'] = $_GET['template'];
    }
    if (!empty($predefined['init_tpl'])) {
        if ($cs_main['ajaxrequest'] === true) {
            echo cs_ajaxwrap();
        } else {
            echo cs_template($cs_micro, $cs_main['tpl_file']);
        }
    }
}