Exemple #1
0
    /**
     * Setup basic user-specific items (style, language, ...)
     */
    function setup($lang_set = false, $style_id = false)
    {
        global $db, $request, $template, $config, $auth, $phpEx, $phpbb_root_path, $cache;
        global $phpbb_dispatcher;
        if ($this->data['user_id'] != ANONYMOUS) {
            $user_lang_name = file_exists($this->lang_path . $this->data['user_lang'] . "/common.{$phpEx}") ? $this->data['user_lang'] : basename($config['default_lang']);
            $user_date_format = $this->data['user_dateformat'];
            $user_timezone = $this->data['user_timezone'];
        } else {
            $lang_override = $request->variable('language', '');
            if ($lang_override) {
                $this->set_cookie('lang', $lang_override, 0, false);
            } else {
                $lang_override = $request->variable($config['cookie_name'] . '_lang', '', true, \phpbb\request\request_interface::COOKIE);
            }
            if ($lang_override) {
                $use_lang = basename($lang_override);
                $user_lang_name = file_exists($this->lang_path . $use_lang . "/common.{$phpEx}") ? $use_lang : basename($config['default_lang']);
                $this->data['user_lang'] = $user_lang_name;
            } else {
                $user_lang_name = basename($config['default_lang']);
            }
            $user_date_format = $config['default_dateformat'];
            $user_timezone = $config['board_timezone'];
            /**
            * If a guest user is surfing, we try to guess his/her language first by obtaining the browser language
            * If re-enabled we need to make sure only those languages installed are checked
            * Commented out so we do not loose the code.
            
            if ($request->header('Accept-Language'))
            {
            	$accept_lang_ary = explode(',', $request->header('Accept-Language'));
            
            	foreach ($accept_lang_ary as $accept_lang)
            	{
            		// Set correct format ... guess full xx_YY form
            		$accept_lang = substr($accept_lang, 0, 2) . '_' . strtoupper(substr($accept_lang, 3, 2));
            		$accept_lang = basename($accept_lang);
            
            		if (file_exists($this->lang_path . $accept_lang . "/common.$phpEx"))
            		{
            			$user_lang_name = $config['default_lang'] = $accept_lang;
            			break;
            		}
            		else
            		{
            			// No match on xx_YY so try xx
            			$accept_lang = substr($accept_lang, 0, 2);
            			$accept_lang = basename($accept_lang);
            
            			if (file_exists($this->lang_path . $accept_lang . "/common.$phpEx"))
            			{
            				$user_lang_name = $config['default_lang'] = $accept_lang;
            				break;
            			}
            		}
            	}
            }
            */
        }
        $user_data = $this->data;
        $lang_set_ext = array();
        /**
         * Event to load language files and modify user data on every page
         *
         * @event core.user_setup
         * @var	array	user_data			Array with user's data row
         * @var	string	user_lang_name		Basename of the user's langauge
         * @var	string	user_date_format	User's date/time format
         * @var	string	user_timezone		User's timezone, should be one of
         *							http://www.php.net/manual/en/timezones.php
         * @var	mixed	lang_set			String or array of language files
         * @var	array	lang_set_ext		Array containing entries of format
         * 					array(
         * 						'ext_name' => (string) [extension name],
         * 						'lang_set' => (string|array) [language files],
         * 					)
         * 					For performance reasons, only load translations
         * 					that are absolutely needed globally using this
         * 					event. Use local events otherwise.
         * @var	mixed	style_id			Style we are going to display
         * @since 3.1.0-a1
         */
        $vars = array('user_data', 'user_lang_name', 'user_date_format', 'user_timezone', 'lang_set', 'lang_set_ext', 'style_id');
        extract($phpbb_dispatcher->trigger_event('core.user_setup', compact($vars)));
        $this->data = $user_data;
        $this->lang_name = $user_lang_name;
        $this->date_format = $user_date_format;
        try {
            $this->timezone = new \DateTimeZone($user_timezone);
        } catch (\Exception $e) {
            // If the timezone the user has selected is invalid, we fall back to UTC.
            $this->timezone = new \DateTimeZone('UTC');
        }
        // We include common language file here to not load it every time a custom language file is included
        $lang =& $this->lang;
        // Do not suppress error if in DEBUG mode
        $include_result = defined('DEBUG') ? include $this->lang_path . $this->lang_name . "/common.{$phpEx}" : @(include $this->lang_path . $this->lang_name . "/common.{$phpEx}");
        if ($include_result === false) {
            die('Language file ' . $this->lang_path . $this->lang_name . "/common.{$phpEx}" . " couldn't be opened.");
        }
        $this->add_lang($lang_set);
        unset($lang_set);
        foreach ($lang_set_ext as $ext_lang_pair) {
            $this->add_lang_ext($ext_lang_pair['ext_name'], $ext_lang_pair['lang_set']);
        }
        unset($lang_set_ext);
        $style_request = $request->variable('style', 0);
        if ($style_request && (!$config['override_user_style'] || $auth->acl_get('a_styles')) && !defined('ADMIN_START')) {
            global $SID, $_EXTRA_URL;
            $style_id = $style_request;
            $SID .= '&style=' . $style_id;
            $_EXTRA_URL = array('style=' . $style_id);
        } else {
            // Set up style
            $style_id = $style_id ? $style_id : (!$config['override_user_style'] ? $this->data['user_style'] : $config['default_style']);
        }
        $sql = 'SELECT *
			FROM ' . STYLES_TABLE . " s\n\t\t\tWHERE s.style_id = {$style_id}";
        $result = $db->sql_query($sql, 3600);
        $this->style = $db->sql_fetchrow($result);
        $db->sql_freeresult($result);
        // Fallback to user's standard style
        if (!$this->style && $style_id != $this->data['user_style']) {
            $style_id = $this->data['user_style'];
            $sql = 'SELECT *
				FROM ' . STYLES_TABLE . " s\n\t\t\t\tWHERE s.style_id = {$style_id}";
            $result = $db->sql_query($sql, 3600);
            $this->style = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
        }
        // User has wrong style
        if (!$this->style && $style_id == $this->data['user_style']) {
            $style_id = $this->data['user_style'] = $config['default_style'];
            $sql = 'UPDATE ' . USERS_TABLE . "\n\t\t\t\tSET user_style = {$style_id}\n\t\t\t\tWHERE user_id = {$this->data['user_id']}";
            $db->sql_query($sql);
            $sql = 'SELECT *
				FROM ' . STYLES_TABLE . " s\n\t\t\t\tWHERE s.style_id = {$style_id}";
            $result = $db->sql_query($sql, 3600);
            $this->style = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
        }
        if (!$this->style) {
            trigger_error('NO_STYLE_DATA', E_USER_ERROR);
        }
        // Now parse the cfg file and cache it
        $parsed_items = $cache->obtain_cfg_items($this->style);
        $check_for = array('pagination_sep' => (string) ', ');
        foreach ($check_for as $key => $default_value) {
            $this->style[$key] = isset($parsed_items[$key]) ? $parsed_items[$key] : $default_value;
            settype($this->style[$key], gettype($default_value));
            if (is_string($default_value)) {
                $this->style[$key] = htmlspecialchars($this->style[$key]);
            }
        }
        $template->set_style();
        $this->img_lang = $this->lang_name;
        // Call phpbb_user_session_handler() in case external application want to "bend" some variables or replace classes...
        // After calling it we continue script execution...
        phpbb_user_session_handler();
        /**
         * Execute code at the end of user setup
         *
         * @event core.user_setup_after
         * @since 3.1.6-RC1
         */
        $phpbb_dispatcher->dispatch('core.user_setup_after');
        // If this function got called from the error handler we are finished here.
        if (defined('IN_ERROR_HANDLER')) {
            return;
        }
        // Disable board if the install/ directory is still present
        // For the brave development army we do not care about this, else we need to comment out this everytime we develop locally
        if (!defined('DEBUG') && !defined('ADMIN_START') && !defined('IN_INSTALL') && !defined('IN_LOGIN') && file_exists($phpbb_root_path . 'install') && !is_file($phpbb_root_path . 'install')) {
            // Adjust the message slightly according to the permissions
            if ($auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_')) {
                $message = 'REMOVE_INSTALL';
            } else {
                $message = !empty($config['board_disable_msg']) ? $config['board_disable_msg'] : 'BOARD_DISABLE';
            }
            trigger_error($message);
        }
        // Is board disabled and user not an admin or moderator?
        if ($config['board_disable'] && !defined('IN_LOGIN') && !defined('SKIP_CHECK_DISABLED') && !$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_')) {
            if ($this->data['is_bot']) {
                send_status_line(503, 'Service Unavailable');
            }
            $message = !empty($config['board_disable_msg']) ? $config['board_disable_msg'] : 'BOARD_DISABLE';
            trigger_error($message);
        }
        // Is load exceeded?
        if ($config['limit_load'] && $this->load !== false) {
            if ($this->load > floatval($config['limit_load']) && !defined('IN_LOGIN') && !defined('IN_ADMIN')) {
                // Set board disabled to true to let the admins/mods get the proper notification
                $config['board_disable'] = '1';
                if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_')) {
                    if ($this->data['is_bot']) {
                        send_status_line(503, 'Service Unavailable');
                    }
                    trigger_error('BOARD_UNAVAILABLE');
                }
            }
        }
        if (isset($this->data['session_viewonline'])) {
            // Make sure the user is able to hide his session
            if (!$this->data['session_viewonline']) {
                // Reset online status if not allowed to hide the session...
                if (!$auth->acl_get('u_hideonline')) {
                    $sql = 'UPDATE ' . SESSIONS_TABLE . '
						SET session_viewonline = 1
						WHERE session_user_id = ' . $this->data['user_id'];
                    $db->sql_query($sql);
                    $this->data['session_viewonline'] = 1;
                }
            } else {
                if (!$this->data['user_allow_viewonline']) {
                    // the user wants to hide and is allowed to  -> cloaking device on.
                    if ($auth->acl_get('u_hideonline')) {
                        $sql = 'UPDATE ' . SESSIONS_TABLE . '
						SET session_viewonline = 0
						WHERE session_user_id = ' . $this->data['user_id'];
                        $db->sql_query($sql);
                        $this->data['session_viewonline'] = 0;
                    }
                }
            }
        }
        // Does the user need to change their password? If so, redirect to the
        // ucp profile reg_details page ... of course do not redirect if we're already in the ucp
        if (!defined('IN_ADMIN') && !defined('ADMIN_START') && $config['chg_passforce'] && !empty($this->data['is_registered']) && $auth->acl_get('u_chgpasswd') && $this->data['user_passchg'] < time() - $config['chg_passforce'] * 86400) {
            if (strpos($this->page['query_string'], 'mode=reg_details') === false && $this->page['page_name'] != "ucp.{$phpEx}") {
                redirect(append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'i=profile&amp;mode=reg_details'));
            }
        }
        return;
    }
    /**
     * Setup basic user-specific items (style, language, ...)
     */
    function setup($lang_set = false, $style = false)
    {
        global $db, $template, $config, $auth, $phpEx, $phpbb_root_path, $cache;
        if ($this->data['user_id'] != ANONYMOUS) {
            $this->lang_name = file_exists($this->lang_path . $this->data['user_lang'] . "/common.{$phpEx}") ? $this->data['user_lang'] : basename($config['default_lang']);
            $this->date_format = $this->data['user_dateformat'];
            $this->timezone = $this->data['user_timezone'] * 3600;
            $this->dst = $this->data['user_dst'] * 3600;
        } else {
            $this->lang_name = basename($config['default_lang']);
            $this->date_format = $config['default_dateformat'];
            $this->timezone = $config['board_timezone'] * 3600;
            $this->dst = $config['board_dst'] * 3600;
            /**
            * If a guest user is surfing, we try to guess his/her language first by obtaining the browser language
            * If re-enabled we need to make sure only those languages installed are checked
            * Commented out so we do not loose the code.
            
            if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
            {
            	$accept_lang_ary = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
            
            	foreach ($accept_lang_ary as $accept_lang)
            	{
            		// Set correct format ... guess full xx_YY form
            		$accept_lang = substr($accept_lang, 0, 2) . '_' . strtoupper(substr($accept_lang, 3, 2));
            		$accept_lang = basename($accept_lang);
            
            		if (file_exists($this->lang_path . $accept_lang . "/common.$phpEx"))
            		{
            			$this->lang_name = $config['default_lang'] = $accept_lang;
            			break;
            		}
            		else
            		{
            			// No match on xx_YY so try xx
            			$accept_lang = substr($accept_lang, 0, 2);
            			$accept_lang = basename($accept_lang);
            
            			if (file_exists($this->lang_path . $accept_lang . "/common.$phpEx"))
            			{
            				$this->lang_name = $config['default_lang'] = $accept_lang;
            				break;
            			}
            		}
            	}
            }
            */
        }
        // We include common language file here to not load it every time a custom language file is included
        $lang =& $this->lang;
        // Do not suppress error if in DEBUG_EXTRA mode
        $include_result = defined('DEBUG_EXTRA') ? include $this->lang_path . $this->lang_name . "/common.{$phpEx}" : @(include $this->lang_path . $this->lang_name . "/common.{$phpEx}");
        if ($include_result === false) {
            die('Language file ' . $this->lang_path . $this->lang_name . "/common.{$phpEx}" . " couldn't be opened.");
        }
        $this->add_lang($lang_set);
        unset($lang_set);
        if (!empty($_GET['style']) && $auth->acl_get('a_styles') && !defined('ADMIN_START')) {
            global $SID, $_EXTRA_URL;
            $style = request_var('style', 0);
            $SID .= '&amp;style=' . $style;
            $_EXTRA_URL = array('style=' . $style);
        } else {
            // Set up style
            $style = $style ? $style : (!$config['override_user_style'] ? $this->data['user_style'] : $config['default_style']);
        }
        $sql = 'SELECT s.style_id, t.template_storedb, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_name, c.theme_storedb, c.theme_id, i.imageset_path, i.imageset_id, i.imageset_name
			FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . ' c, ' . STYLES_IMAGESET_TABLE . " i\n\t\t\tWHERE s.style_id = {$style}\n\t\t\t\tAND t.template_id = s.template_id\n\t\t\t\tAND c.theme_id = s.theme_id\n\t\t\t\tAND i.imageset_id = s.imageset_id";
        $result = $db->sql_query($sql, 3600);
        $this->theme = $db->sql_fetchrow($result);
        $db->sql_freeresult($result);
        // User has wrong style
        if (!$this->theme && $style == $this->data['user_style']) {
            $style = $this->data['user_style'] = $config['default_style'];
            $sql = 'UPDATE ' . USERS_TABLE . "\n\t\t\t\tSET user_style = {$style}\n\t\t\t\tWHERE user_id = {$this->data['user_id']}";
            $db->sql_query($sql);
            $sql = 'SELECT s.style_id, t.template_storedb, t.template_path, t.template_id, t.bbcode_bitfield, c.theme_path, c.theme_name, c.theme_storedb, c.theme_id, i.imageset_path, i.imageset_id, i.imageset_name
				FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . ' c, ' . STYLES_IMAGESET_TABLE . " i\n\t\t\t\tWHERE s.style_id = {$style}\n\t\t\t\t\tAND t.template_id = s.template_id\n\t\t\t\t\tAND c.theme_id = s.theme_id\n\t\t\t\t\tAND i.imageset_id = s.imageset_id";
            $result = $db->sql_query($sql, 3600);
            $this->theme = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
        }
        if (!$this->theme) {
            trigger_error('Could not get style data', E_USER_ERROR);
        }
        // Now parse the cfg file and cache it
        $parsed_items = $cache->obtain_cfg_items($this->theme);
        // We are only interested in the theme configuration for now
        $parsed_items = $parsed_items['theme'];
        $check_for = array('parse_css_file' => (int) 0, 'pagination_sep' => (string) ', ');
        foreach ($check_for as $key => $default_value) {
            $this->theme[$key] = isset($parsed_items[$key]) ? $parsed_items[$key] : $default_value;
            settype($this->theme[$key], gettype($default_value));
            if (is_string($default_value)) {
                $this->theme[$key] = htmlspecialchars($this->theme[$key]);
            }
        }
        // If the style author specified the theme needs to be cached
        // (because of the used paths and variables) than make sure it is the case.
        // For example, if the theme uses language-specific images it needs to be stored in db.
        if (!$this->theme['theme_storedb'] && $this->theme['parse_css_file']) {
            $this->theme['theme_storedb'] = 1;
            $stylesheet = file_get_contents("{$phpbb_root_path}styles/{$this->theme['theme_path']}/theme/stylesheet.css");
            // Match CSS imports
            $matches = array();
            preg_match_all('/@import url\\(["\'](.*)["\']\\);/i', $stylesheet, $matches);
            if (sizeof($matches)) {
                $content = '';
                foreach ($matches[0] as $idx => $match) {
                    if ($content = @file_get_contents("{$phpbb_root_path}styles/{$this->theme['theme_path']}/theme/" . $matches[1][$idx])) {
                        $content = trim($content);
                    } else {
                        $content = '';
                    }
                    $stylesheet = str_replace($match, $content, $stylesheet);
                }
                unset($content);
            }
            $stylesheet = str_replace('./', 'styles/' . $this->theme['theme_path'] . '/theme/', $stylesheet);
            $sql_ary = array('theme_data' => $stylesheet, 'theme_mtime' => time(), 'theme_storedb' => 1);
            $sql = 'UPDATE ' . STYLES_THEME_TABLE . '
				SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
				WHERE theme_id = ' . $this->theme['theme_id'];
            $db->sql_query($sql);
            unset($sql_ary);
        }
        $template->set_template();
        $this->img_lang = file_exists($phpbb_root_path . 'styles/' . $this->theme['imageset_path'] . '/imageset/' . $this->lang_name) ? $this->lang_name : $config['default_lang'];
        // Same query in style.php
        $sql = 'SELECT *
			FROM ' . STYLES_IMAGESET_DATA_TABLE . '
			WHERE imageset_id = ' . $this->theme['imageset_id'] . "\n\t\t\tAND image_filename <> ''\n\t\t\tAND image_lang IN ('" . $db->sql_escape($this->img_lang) . "', '')";
        $result = $db->sql_query($sql, 3600);
        $localised_images = false;
        while ($row = $db->sql_fetchrow($result)) {
            if ($row['image_lang']) {
                $localised_images = true;
            }
            $row['image_filename'] = rawurlencode($row['image_filename']);
            $this->img_array[$row['image_name']] = $row;
        }
        $db->sql_freeresult($result);
        // there were no localised images, try to refresh the localised imageset for the user's language
        if (!$localised_images) {
            // Attention: this code ignores the image definition list from acp_styles and just takes everything
            // that the config file contains
            $sql_ary = array();
            $db->sql_transaction('begin');
            $sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . '
				WHERE imageset_id = ' . $this->theme['imageset_id'] . '
					AND image_lang = \'' . $db->sql_escape($this->img_lang) . '\'';
            $result = $db->sql_query($sql);
            if (@file_exists("{$phpbb_root_path}styles/{$this->theme['imageset_path']}/imageset/{$this->img_lang}/imageset.cfg")) {
                $cfg_data_imageset_data = parse_cfg_file("{$phpbb_root_path}styles/{$this->theme['imageset_path']}/imageset/{$this->img_lang}/imageset.cfg");
                foreach ($cfg_data_imageset_data as $image_name => $value) {
                    if (strpos($value, '*') !== false) {
                        if (substr($value, -1, 1) === '*') {
                            list($image_filename, $image_height) = explode('*', $value);
                            $image_width = 0;
                        } else {
                            list($image_filename, $image_height, $image_width) = explode('*', $value);
                        }
                    } else {
                        $image_filename = $value;
                        $image_height = $image_width = 0;
                    }
                    if (strpos($image_name, 'img_') === 0 && $image_filename) {
                        $image_name = substr($image_name, 4);
                        $sql_ary[] = array('image_name' => (string) $image_name, 'image_filename' => (string) $image_filename, 'image_height' => (int) $image_height, 'image_width' => (int) $image_width, 'imageset_id' => (int) $this->theme['imageset_id'], 'image_lang' => (string) $this->img_lang);
                    }
                }
            }
            if (sizeof($sql_ary)) {
                $db->sql_multi_insert(STYLES_IMAGESET_DATA_TABLE, $sql_ary);
                $db->sql_transaction('commit');
                $cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE);
                add_log('admin', 'LOG_IMAGESET_LANG_REFRESHED', $this->theme['imageset_name'], $this->img_lang);
            } else {
                $db->sql_transaction('commit');
                add_log('admin', 'LOG_IMAGESET_LANG_MISSING', $this->theme['imageset_name'], $this->img_lang);
            }
        }
        // Call phpbb_user_session_handler() in case external application want to "bend" some variables or replace classes...
        // After calling it we continue script execution...
        phpbb_user_session_handler();
        // If this function got called from the error handler we are finished here.
        if (defined('IN_ERROR_HANDLER')) {
            return;
        }
        // Disable board if the install/ directory is still present
        // For the brave development army we do not care about this, else we need to comment out this everytime we develop locally
        if (!defined('DEBUG_EXTRA') && !defined('ADMIN_START') && !defined('IN_INSTALL') && !defined('IN_LOGIN') && file_exists($phpbb_root_path . 'install') && !is_file($phpbb_root_path . 'install')) {
            // Adjust the message slightly according to the permissions
            if ($auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_')) {
                $message = 'REMOVE_INSTALL';
            } else {
                $message = !empty($config['board_disable_msg']) ? $config['board_disable_msg'] : 'BOARD_DISABLE';
            }
            trigger_error($message);
        }
        // Is board disabled and user not an admin or moderator?
        if ($config['board_disable'] && !defined('IN_LOGIN') && !$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_')) {
            if ($this->data['is_bot']) {
                send_status_line(503, 'Service Unavailable');
            }
            $message = !empty($config['board_disable_msg']) ? $config['board_disable_msg'] : 'BOARD_DISABLE';
            trigger_error($message);
        }
        // Is load exceeded?
        if ($config['limit_load'] && $this->load !== false) {
            if ($this->load > floatval($config['limit_load']) && !defined('IN_LOGIN') && !defined('IN_ADMIN')) {
                // Set board disabled to true to let the admins/mods get the proper notification
                $config['board_disable'] = '1';
                if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_')) {
                    if ($this->data['is_bot']) {
                        send_status_line(503, 'Service Unavailable');
                    }
                    trigger_error('BOARD_UNAVAILABLE');
                }
            }
        }
        if (isset($this->data['session_viewonline'])) {
            // Make sure the user is able to hide his session
            if (!$this->data['session_viewonline']) {
                // Reset online status if not allowed to hide the session...
                if (!$auth->acl_get('u_hideonline')) {
                    $sql = 'UPDATE ' . SESSIONS_TABLE . '
						SET session_viewonline = 1
						WHERE session_user_id = ' . $this->data['user_id'];
                    $db->sql_query($sql);
                    $this->data['session_viewonline'] = 1;
                }
            } else {
                if (!$this->data['user_allow_viewonline']) {
                    // the user wants to hide and is allowed to  -> cloaking device on.
                    if ($auth->acl_get('u_hideonline')) {
                        $sql = 'UPDATE ' . SESSIONS_TABLE . '
						SET session_viewonline = 0
						WHERE session_user_id = ' . $this->data['user_id'];
                        $db->sql_query($sql);
                        $this->data['session_viewonline'] = 0;
                    }
                }
            }
        }
        // Does the user need to change their password? If so, redirect to the
        // ucp profile reg_details page ... of course do not redirect if we're already in the ucp
        if (!defined('IN_ADMIN') && !defined('ADMIN_START') && $config['chg_passforce'] && !empty($this->data['is_registered']) && $auth->acl_get('u_chgpasswd') && $this->data['user_passchg'] < time() - $config['chg_passforce'] * 86400) {
            if (strpos($this->page['query_string'], 'mode=reg_details') === false && $this->page['page_name'] != "ucp.{$phpEx}") {
                redirect(append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'i=profile&amp;mode=reg_details'));
            }
        }
        // [+] Karma MOD
        if (!class_exists('karmamod')) {
            require $phpbb_root_path . 'includes/functions_karma.' . $phpEx;
        }
        global $karmamod;
        $karmamod = new karmamod();
        // [-] Karma MOD
        return;
    }
Exemple #3
0
 /**
  * Setup basic user-specific items (style, language, ...)
  */
 function setup($lang_set = false, $style = false)
 {
     global $db, $cache, $config, $auth, $template;
     // We need $lang declared as global to make sure we do not miss extra $lang vars added using this function
     global $theme, $images, $lang, $nav_separator;
     global $class_settings, $tree;
     // Get all settings
     $class_settings->setup_settings();
     // Mighty Gorgon - Change Lang - BEGIN
     $test_language = request_var(LANG_URL, '');
     if (!empty($test_language)) {
         $test_language = str_replace(array('.', '/'), '', urldecode($test_language));
         $config['default_lang'] = file_exists(@phpbb_realpath($this->lang_path . 'lang_' . basename($test_language) . '/lang_main.' . PHP_EXT)) ? $test_language : $config['default_lang'];
         $this->set_cookie('lang', $config['default_lang'], $user->cookie_expire);
     } else {
         if (isset($_COOKIE[$config['cookie_name'] . '_lang']) && file_exists(@phpbb_realpath($this->lang_path . 'lang_' . basename($_COOKIE[$config['cookie_name'] . '_lang']) . '/lang_main.' . PHP_EXT))) {
             $config['default_lang'] = $_COOKIE[$config['cookie_name'] . '_lang'];
         }
     }
     // Mighty Gorgon - Change Lang - END
     if ($this->data['user_id'] != ANONYMOUS) {
         $this->lang_name = file_exists($this->lang_path . 'lang_' . basename($this->data['user_lang']) . '/lang_main.' . PHP_EXT) ? basename($this->data['user_lang']) : basename($config['default_lang']);
         $this->date_format = $this->data['user_dateformat'];
         $this->timezone = $this->data['user_timezone'] * 3600;
         $this->dst = $this->data['user_dst'] * 3600;
         $config['board_timezone'] = !empty($this->data['user_timezone']) ? $this->data['user_timezone'] : $config['board_timezone'];
         $config['default_dateformat'] = !empty($this->data['user_dateformat']) ? $this->data['user_dateformat'] : $config['default_dateformat'];
         $config['topics_per_page'] = !empty($this->data['user_topics_per_page']) ? $this->data['user_topics_per_page'] : $config['topics_per_page'];
         $config['posts_per_page'] = !empty($this->data['user_posts_per_page']) ? $this->data['user_posts_per_page'] : $config['posts_per_page'];
         $config['hot_threshold'] = !empty($this->data['user_hot_threshold']) ? $this->data['user_hot_threshold'] : $config['hot_threshold'];
         // Store CMS AUTH - BEGIN
         if (empty($this->data['user_cms_auth'])) {
             $auth_array = array();
             $auth_to_get_array = array('cmsl_admin', 'cmss_admin', 'cmsb_admin');
             foreach ($auth_to_get_array as $auth_to_get) {
                 $auth_getf = $auth->acl_getf($auth_to_get, true);
                 foreach ($auth_getf as $auth_id => $auth_value) {
                     $auth_array[$auth_to_get][$auth_id] = $auth_value[$auth_to_get];
                 }
             }
             $this->data['user_cms_auth'] = $auth_array;
             $sql = "UPDATE " . USERS_TABLE . "\n\t\t\t\t\tSET user_cms_auth = '" . $db->sql_escape(serialize($this->data['user_cms_auth'])) . "'\n\t\t\t\t\tWHERE user_id = " . $this->data['user_id'];
             $db->sql_query($sql);
         } else {
             $this->data['user_cms_auth'] = unserialize($this->data['user_cms_auth']);
         }
         // Store CMS AUTH - END
     } else {
         $this->lang_name = basename($config['default_lang']);
         $this->date_format = $config['default_dateformat'];
         $this->timezone = $config['board_timezone'] * 3600;
         $this->dst = $config['board_dst'] * 3600;
     }
     // If we've had to change the value in any way then let's write it back to the database before we go any further since it means there is something wrong with it
     if ($this->data['user_id'] != ANONYMOUS && $this->data['user_lang'] !== $this->lang_name && file_exists($this->lang_path . 'lang_' . basename($this->lang_name) . '/lang_main.' . PHP_EXT)) {
         $sql = 'UPDATE ' . USERS_TABLE . "\n\t\t\t\tSET user_lang = '" . $db->sql_escape($this->lang_name) . "'\n\t\t\t\tWHERE user_lang = '" . $this->data['user_lang'] . "'";
         $result = $db->sql_query($sql);
         $this->data['user_lang'] = $this->lang_name;
     } elseif ($this->data['user_id'] === ANONYMOUS && $config['default_lang'] !== $this->lang_name && file_exists($this->lang_path . 'lang_' . basename($this->lang_name) . '/lang_main.' . PHP_EXT)) {
         $sql = 'UPDATE ' . CONFIG_TABLE . "\n\t\t\t\tSET config_value = '" . $db->sql_escape($this->lang_name) . "'\n\t\t\t\tWHERE config_name = 'default_lang'";
         $result = $db->sql_query($sql);
     }
     $config['default_lang'] = $this->lang_name;
     // We include common language file here to not load it every time a custom language file is included
     $lang =& $this->lang;
     setup_basic_lang();
     $this->add_lang($lang_set);
     unset($lang_set);
     $nav_separator = empty($nav_separator) ? empty($lang['Nav_Separator']) ? '&nbsp;&raquo;&nbsp;' : $lang['Nav_Separator'] : $nav_separator;
     if (empty($tree['auth'])) {
         get_user_tree($this->data);
     }
     // MG Logs - BEGIN
     if ($config['mg_log_actions'] || $config['db_log_actions']) {
         include IP_ROOT_PATH . 'includes/log_http_cmd.' . PHP_EXT;
     }
     // MG Logs - END
     // UPI2DB - BEGIN
     if (!defined('IN_CMS') && $this->data['upi2db_access']) {
         if (!defined('UPI2DB_UNREAD')) {
             $this->data['upi2db_unread'] = upi2db_unread();
         }
     } else {
         $this->data['upi2db_unread'] = array();
     }
     // UPI2DB - END
     // Mighty Gorgon Edit
     // DISABLED BY MG
     /*
     //if (!empty($_GET['style']) && $auth->acl_get('a_styles') && !defined('IN_ADMIN') && !defined('IN_CMS'))
     if (!empty($_GET['style']) && !defined('IN_ADMIN') && !defined('IN_CMS'))
     {
     	global $SID, $_EXTRA_URL;
     
     	$style = request_var(STYLE_URL, 0);
     	$SID .= '&amp;' . STYLE_URL . '=' . $style;
     	$_EXTRA_URL = array(STYLE_URL . '=' . $style);
     }
     else
     {
     	// Set up style
     	$style = ($style) ? $style : ((!$config['override_user_style']) ? $this->data['user_style'] : $config['default_style']);
     }
     */
     // Call phpbb_user_session_handler() in case external application want to "bend" some variables or replace classes...
     // After calling it we continue script execution...
     phpbb_user_session_handler();
     // If this function got called from the error handler we are finished here.
     if (defined('IN_ERROR_HANDLER')) {
         return;
     }
     // Disable board if the install/ directory is still present
     // For the brave development army we do not care about this, else we need to comment out this everytime we develop locally
     // DISABLED BY MG
     /*
     if (!defined('DEBUG_EXTRA') && !defined('IN_ADMIN') && !defined('IN_CMS') && !defined('IN_INSTALL') && !defined('IN_LOGIN') && file_exists(IP_ROOT_PATH . 'install') && !is_file(IP_ROOT_PATH . 'install'))
     {
     	// Adjust the message slightly according to the permissions
     	if ($auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_'))
     	{
     		$message = 'REMOVE_INSTALL';
     	}
     	else
     	{
     		$message = (!empty($config['board_disable_msg'])) ? $config['board_disable_msg'] : 'BOARD_DISABLE';
     	}
     	trigger_error($message);
     }
     */
     // Is board disabled and user not an admin or moderator?
     // DISABLED BY MG
     /*
     if ($config['board_disable'] && !defined('IN_LOGIN') && !$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
     {
     	if ($this->data['is_bot'])
     	{
     		send_status_line(503, 'Service Unavailable');
     	}
     
     	$message = (!empty($config['board_disable_msg'])) ? $config['board_disable_msg'] : 'BOARD_DISABLE';
     	trigger_error($message);
     }
     */
     // Is load exceeded?
     // DISABLED BY MG
     /*
     if ($config['limit_load'] && $this->load !== false)
     {
     	if ($this->load > floatval($config['limit_load']) && !defined('IN_LOGIN') && !defined('IN_ADMIN'))
     	{
     		// Set board disabled to true to let the admins/mods get the proper notification
     		$config['board_disable'] = '1';
     
     		if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
     		{
     			if ($this->data['is_bot'])
     			{
     				send_status_line(503, 'Service Unavailable');
     			}
     			trigger_error('BOARD_UNAVAILABLE');
     		}
     	}
     }
     */
     // DISABLED BY MG
     /*
     if (isset($this->data['session_viewonline']))
     {
     	// Make sure the user is able to hide his session
     	if (!$this->data['session_viewonline'])
     	{
     		// Reset online status if not allowed to hide the session...
     		if (!$auth->acl_get('u_hideonline'))
     		{
     			$sql = 'UPDATE ' . SESSIONS_TABLE . '
     				SET session_viewonline = 1
     				WHERE session_user_id = ' . $this->data['user_id'];
     			$db->sql_query($sql);
     			$this->data['session_viewonline'] = 1;
     		}
     	}
     	elseif (!$this->data['user_allow_viewonline'])
     	{
     		// the user wants to hide and is allowed to -> cloaking device on.
     		if ($auth->acl_get('u_hideonline'))
     		{
     			$sql = 'UPDATE ' . SESSIONS_TABLE . '
     				SET session_viewonline = 0
     				WHERE session_user_id = ' . $this->data['user_id'];
     			$db->sql_query($sql);
     			$this->data['session_viewonline'] = 0;
     		}
     	}
     }
     */
     // Set up style
     $current_default_style = $config['default_style'];
     $change_style = false;
     $is_mobile = is_mobile();
     // For debugging purpose you can force this to true
     //$this->data['is_mobile'] = true;
     // We need to store somewhere if the user has the mobile style enabled... so we can output a link to switch between mobile style and norma style
     $this->data['mobile_style'] = false;
     $disable_mobile_style = false;
     // MOBILE STYLE DISABLING - BEGIN
     // Let's check if the user wants to disable the mobile style
     if (isset($_GET['mob'])) {
         $mob_get = isset($_GET['mob']) && intval($_GET['mob']) == 0 ? 0 : 1;
         $_GET['mob'] = $mob_get;
         $_COOKIE[$config['cookie_name'] . '_mob'] = $mob_get;
         $this->set_cookie('mob', $mob_get, $user->cookie_expire);
         if (empty($mob_get)) {
             $disable_mobile_style = true;
         }
     }
     $mob_cok = isset($_COOKIE[$config['cookie_name'] . '_mob']) && intval($_COOKIE[$config['cookie_name'] . '_mob']) == 0 ? false : true;
     if (empty($mob_cok)) {
         $disable_mobile_style = true;
     }
     // MOBILE STYLE DISABLING - END
     if (empty($disable_mobile_style) && !empty($this->data['is_mobile']) && !defined('IN_CMS') && !defined('IN_ADMIN')) {
         $this->data['mobile_style'] = true;
         $_COOKIE[$config['cookie_name'] . '_mob'] = 1;
         $this->set_cookie('mob', 1, $user->cookie_expire);
         $theme = setup_mobile_style();
     } else {
         if (empty($config['override_user_style'])) {
             // Mighty Gorgon - Change Style - BEGIN
             // Check cookie as well!!!
             $test_style = request_var(STYLE_URL, 0);
             if ($test_style > 0) {
                 $config['default_style'] = urldecode($test_style);
                 $config['default_style'] = check_style_exists($config['default_style']) == false ? $current_default_style : $config['default_style'];
                 $this->set_cookie('style', $config['default_style'], $user->cookie_expire);
                 $change_style = true;
             } else {
                 if (isset($_COOKIE[$config['cookie_name'] . '_style']) && check_style_exists($_COOKIE[$config['cookie_name'] . '_style']) != false) {
                     $config['default_style'] = $_COOKIE[$config['cookie_name'] . '_style'];
                 }
             }
             // Mighty Gorgon - Change Style - END
             $style = $this->data['user_id'] != ANONYMOUS && $this->data['user_style'] > 0 && empty($change_style) ? $this->data['user_style'] : $config['default_style'];
             if ($theme = setup_style($style, $current_default_style)) {
                 if ($this->data['user_id'] != ANONYMOUS && !empty($change_style)) {
                     // user logged in --> save new style ID in user profile
                     $sql = "UPDATE " . USERS_TABLE . "\n\t\t\t\t\t\t\tSET user_style = " . $theme['themes_id'] . "\n\t\t\t\t\t\t\tWHERE user_id = " . $this->data['user_id'];
                     $db->sql_query($sql);
                     $this->data['user_style'] = $theme['themes_id'];
                 }
                 return;
             }
         }
         $theme = setup_style($config['default_style'], $current_default_style);
     }
     return;
 }