* @license GNU General Public License, version 2 (GPL-2.0) * * For full copyright and license information, please see * the docs/CREDITS.txt file. * */ namespace phpbb; /** * Base user class * * This is the overarching class which contains (through session extend) * all methods utilised for user functionality during a session. */ class user extends \phpbb\session { var $lang = array(); var $help = array(); var $style = array(); var $date_format; /** * DateTimeZone object holding the timezone of the user */ public $timezone; var $lang_name = false; var $lang_id = false; var $lang_path; var $img_lang; var $img_array = array(); // Able to add new options (up to id 31) var $keyoptions = array('viewimg' => 0, 'viewflash' => 1, 'viewsmilies' => 2, 'viewsigs' => 3, 'viewavatars' => 4, 'viewcensors' => 5, 'attachsig' => 6, 'bbcode' => 8, 'smilies' => 9, 'sig_bbcode' => 15, 'sig_smilies' => 16, 'sig_links' => 17); /** * Constructor to set the lang path */ function __construct() { global $phpbb_root_path; $this->lang_path = $phpbb_root_path . 'language/'; } /** * Function to set custom language path (able to use directory outside of phpBB) * * @param string $lang_path New language path used. * @access public */ function set_custom_lang_path($lang_path) { $this->lang_path = $lang_path; if (substr($this->lang_path, -1) != '/') { $this->lang_path .= '/'; } } /** * 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) ? $sty Adding or refreshing mcc in pl