function init() { trace('Enter'); // Select a supported language. if ($_SERVER['HTTP_ACCEPT_LANGUAGE']) { $langs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']); foreach ($langs as $current) { if (strstr($current, '-')) { $both = explode('-', $current); $current = $both[0] . '_' . strtoupper($both[1]); } $best = $this->_get_language($current); if ($best) { $lang = $best; break; } } } // Fallback to the default language. if (!$lang || !preg_match('/^[a-z_]*$/i', $lang)) { $lang = cfg('default_language'); } // Init gettext. if (!function_exists('gettext')) { die('This webserver does not have gettext installed.<br/>' . 'Please contact your webspace provider.'); } $locale_dir = './language/'; $domain = 'freech'; putenv("LANG={$lang}.UTF-8"); @setlocale(LC_ALL, ''); bindtextdomain($domain, $locale_dir); textdomain($domain); bind_textdomain_codeset($domain, 'UTF-8'); trace('Gettext initialized'); // Start the PHP session. session_set_cookie_params(time() + cfg('login_time')); if ($_COOKIE['permanent_session']) { session_id($_COOKIE['permanent_session']); session_start(); } else { session_start(); if (strtoupper($_POST['permanent']) === 'ON') { setcookie('permanent_session', session_id(), time() + cfg('login_time')); } } trace('Session started'); // Only now start the timer, as cookie handling may scew the result. $this->start_time = microtime(TRUE); // (Ab)use a Trackable as an eventbus. $this->eventbus = new Trackable(); $this->actions = array(); $this->views = array(); $this->current_user = NULL; $this->current_forum = NULL; $this->links = array('forum' => new Menu(), 'page' => new Menu(), 'search' => new Menu(), 'view' => new Menu(), 'footer' => new Menu(), 'account' => new Menu(), 'breadcrumbs' => new Menu()); trace('Eventbus created'); // Connect to the DB. $dbn = cfg('db_dbn'); if (cfg('persistent_db_connection')) { $dbn .= '?persist'; } $this->db = ADONewConnection($dbn) or die('FreechForum::FreechForum(): Error: Can\'t connect.' . ' Please check username, password and hostname.'); if (cfg('db_debug', FALSE)) { // enable AdoDB debug mode $this->db->debug = true; } global $ADODB_FETCH_MODE; $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; trace('DB connection opened'); $this->forumdb = new ForumDB($this->api); trace('ForumDB set up'); $registry = new PluginRegistry(); trace('Plugin registry initialized'); foreach (cfg('plugins') as $plugin => $active) { if ($active) { $registry->activate_plugin_from_dirname('plugins/' . $plugin, $this->api); } } trace('Plugins activated'); $this->_handle_cookies(); trace('Cookies initialized'); // Initialize the visitordb after cookie handling to prevent useless // updates. if (!cfg('disable_visitor_counter')) { require 'services/visitordb.class.php'; $this->visitordb = new VisitorDB($this->db); trace('VisitorDB initialized'); $this->visitordb->count(); } trace('Visitor counted'); /* Plugin hook: on_construct * Called from within the FreechForum() constructor before any * other output is produced. * The return value of the callback is ignored. * Args: None. */ $this->eventbus->emit('on_construct', $this->api); trace('on_construct calls completed.'); // Attempt to login, if requested. $this->login_error = 0; if ($this->get_current_action() == 'login' && $_POST['username']) { $this->login_error = $this->_try_login(); } if ($this->get_current_action() == 'logout') { session_unset(); $url = new FreechURL(); $this->_refer_to($url->get_string()); } trace('Login processed'); // Add the modlog URL to the forum links. $url = new FreechURL('', _('Moderation Log')); $url->set_var('action', 'moderation_log'); $this->links['forum']->add_link($url); // Add login/logout links. $refer_to = $this->_get_login_refer_url(); $url = new FreechURL('', _('Log in')); $url->set_var('action', 'login'); $url->set_var('refer_to', $refer_to); $this->register_url('login', $url); $url = new FreechURL('', _('Log out')); $url->set_var('action', 'logout'); $this->register_url('logout', $url); // Add user-specific links. //FIXME: this probably should not be here. $user = $this->get_current_user(); if (!$user->is_active()) { return $this->_refer_to($this->get_url('logout')->get_string()); } elseif ($user->is_anonymous()) { $this->links['account']->add_link($this->get_url('login')); } else { $url = $user->get_postings_url(); $url->set_label(_('My Postings')); $this->links['account']->add_link($url); $url = $user->get_profile_url(); $url->set_label(_('My Profile')); $this->links['account']->add_link($url); $this->links['account']->add_link($this->get_url('logout')); } trace('Leave'); }