|
From: Jon O. <jon...@us...> - 2008-07-10 20:46:41
|
Update of /cvsroot/mxbb/core/includes/sessions/internal In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv22493/sessions/internal Modified Files: login.php session.php Log Message: Updated more generic initialization of styles and languages for backends. Index: login.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/sessions/internal/login.php,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** login.php 9 Feb 2008 12:41:11 -0000 1.4 --- login.php 10 Jul 2008 20:46:36 -0000 1.5 *************** *** 58,62 **** $admin = $mx_request_vars->is_post('admin'); ! $session_id = $mx_user->mx_session_create($row['user_id'], $user_ip, PAGE_INDEX, FALSE, $autologin, $admin); // Reset login tries --- 58,62 ---- $admin = $mx_request_vars->is_post('admin'); ! $session_id = $mx_user->session_begin($row['user_id'], $user_ip, PAGE_INDEX, FALSE, $autologin, $admin); // Reset login tries *************** *** 140,144 **** if( $userdata['session_logged_in'] ) { ! $mx_user->mx_session_kill($userdata['session_id'], $userdata['user_id']); } --- 140,144 ---- if( $userdata['session_logged_in'] ) { ! $mx_user->session_end($userdata['session_id'], $userdata['user_id']); } Index: session.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/sessions/internal/session.php,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** session.php 10 Jul 2008 14:09:48 -0000 1.9 --- session.php 10 Jul 2008 20:46:36 -0000 1.10 *************** *** 36,39 **** --- 36,64 ---- // + // phpBB3 duplicates + // + var $lang = array(); + var $help = array(); + var $theme = array(); + var $date_format; + var $timezone; + var $dst; + + var $lang_name; + var $lang_path; + var $img_lang; + var $img_array = array(); + + /** + * Load sessions + * @access public + * + */ + function load() + { + $this->data = $this->session_pagestart($this->user_ip, - ( MX_PORTAL_PAGES_OFFSET + $this->page_id )); + } + + // // Adds/updates a new session to the database for the given userid. // Returns the new session ID on success. *************** *** 574,944 **** } /** ! * Setup basic user-specific items (style, language, ...) */ function setup($lang_set = false, $style = false) { global $db, $template, $board_config, $userdata, $phpbb_auth, $phpEx, $phpbb_root_path, $mx_root_path, $mx_cache; - global $mx_request_vars, $portal_config; //added for mxp - - //$template = new mx_Template($mx_root_path . 'templates/' . $this->template_name); - - switch (PORTAL_BACKEND) - { - case 'internal': - case 'phpbb3': - $phpbb_lang_path = $mx_root_path . 'includes/shared/phpbb2/language/'; - break; - case 'phpbb2': - $phpbb_lang_path = $phpbb_root_path . 'language/'; - break; - default: - $phpbb_lang_path = $phpbb_root_path . 'language/'; - } - - $board_config['default_lang'] = $this->get_phpbb_lang($board_config['default_lang']); // This will expand the lang name ! if ($userdata['user_id'] != ANONYMOUS) ! { ! $this->lang_name = (file_exists($phpbb_lang_path . "lang_" . $this->get_phpbb_lang($userdata['user_lang']) . "/lang_main.$phpEx")) ? $this->get_phpbb_lang($userdata['user_lang']) : $board_config['default_lang']; ! $this->lang_path = $phpbb_lang_path . "lang_" . $this->lang_name . '/'; ! $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 = $board_config['default_lang']; ! $this->lang_path = $phpbb_lang_path . "lang_" . $this->lang_name . '/'; ! $this->date_format = $board_config['default_dateformat']; ! $this->timezone = $board_config['board_timezone'] * 3600; ! $this->dst = $board_config['board_dst'] * 3600; ! } ! ! // We include common language file here to not load it every time a custom language file is included ! //$this->lang = &$lang; ! $this->add_lang($lang_set); ! // We include common language file here to not load it every time a custom language file is included ! //$lang = &$this->lang; ! ! unset($lang_set); ! ! /* ! if (!empty($_GET['style']) && $phpbb_auth->acl_get('a_styles')) ! { ! global $SID, $_EXTRA_URL; ! ! $style = phpBB3::request_var('style', 0); ! $SID .= '&style=' . $style; ! $_EXTRA_URL = array('style=' . $style); ! } ! else ! { ! //Workaround by OryNider in this "else" ! $sql = "SELECT bbt.* ! FROM " . MX_THEMES_TABLE . " mxt, " . STYLES_TABLE . " bbt ! WHERE mxt.style_name = bbt.style_name ! AND mxt.portal_backend = '" . PORTAL_BACKEND . "' ! AND mxt.themes_id = " . (int) $this->style; ! if ( !($result = $db->sql_query($sql, 120)) ) ! { ! mx_message_die(CRITICAL_ERROR, 'Could not query database for theme info'); ! } ! $this->phpbb_style = $db->sql_fetchrow($result); ! $db->sql_freeresult($result); ! ! // Set up style ! $style = ($style) ? $style : ((!$board_config['override_user_style'] && $this->data['user_id'] != ANONYMOUS) ? $this->data['user_style'] : $this->phpbb_style['style_id']); ! } ! ! $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 ! WHERE s.style_id = $style ! AND t.template_id = s.template_id ! AND c.theme_id = s.theme_id ! AND i.imageset_id = s.imageset_id"; ! if ( !($result = $db->sql_query($sql, 3600)) ) ! { ! mx_message_die(CRITICAL_ERROR, "Could not query database for imageset_id info style_id [$style]", "", __LINE__, __FILE__, $sql); ! } ! ! $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'] = $board_config['default_style']; ! ! $sql = 'UPDATE ' . USERS_TABLE . " ! SET user_style = $style ! WHERE 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 ! WHERE s.style_id = $style ! AND t.template_id = s.template_id ! AND c.theme_id = s.theme_id ! AND 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 = $mx_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 : $board_config['default_lang']; ! ! $sql = 'SELECT image_name, image_filename, image_lang, image_height, image_width ! FROM ' . STYLES_IMAGESET_DATA_TABLE . ' ! WHERE imageset_id = ' . $this->theme['imageset_id'] . " ! AND 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; ! } ! ! $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 = phpBB3::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'); ! $mx_cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE); ! ! mx_add_log('admin', 'LOG_IMAGESET_LANG_REFRESHED', $this->theme['imageset_name'], $this->img_lang); ! } ! else ! { ! $db->sql_transaction('commit'); ! mx_add_log('admin', 'LOG_IMAGESET_LANG_MISSING', $this->theme['imageset_name'], $this->img_lang); ! } ! } ! ! // 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')) { ! // Adjust the message slightly according to the permissions ! if ($phpbb_auth->acl_gets('a_', 'm_') || $phpbb_auth->acl_getf_global('m_')) ! { ! $message = 'REMOVE_INSTALL'; ! } ! else { ! $message = (!empty($board_config['board_disable_msg'])) ? $board_config['board_disable_msg'] : 'BOARD_DISABLE'; } - trigger_error($message); } ! // Is board disabled and user not an admin or moderator? ! if ($board_config['board_disable'] && !defined('IN_LOGIN') && !$phpbb_auth->acl_gets('a_', 'm_') && !$phpbb_auth->acl_getf_global('m_')) ! { ! header('HTTP/1.1 503 Service Unavailable'); ! ! $message = (!empty($board_config['board_disable_msg'])) ? $board_config['board_disable_msg'] : 'BOARD_DISABLE'; ! trigger_error($message); ! } ! ! // Is load exceeded? ! if ($board_config['limit_load'] && $this->load !== false) ! { ! if ($this->load > floatval($board_config['limit_load']) && !defined('IN_LOGIN')) ! { ! // Set board disabled to true to let the admins/mods get the proper notification ! $board_config['board_disable'] = '1'; ! ! if (!$phpbb_auth->acl_gets('a_', 'm_') && !$phpbb_auth->acl_getf_global('m_')) ! { ! header('HTTP/1.1 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 (!$phpbb_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 ($phpbb_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') && $board_config['chg_passforce'] && $this->data['is_registered'] && $phpbb_auth->acl_get('u_chgpasswd') && $this->data['user_passchg'] < time() - ($board_config['chg_passforce'] * 86400)) ! { ! if (strpos($this->page['query_string'], 'mode=reg_details') === false && $this->page['page_name'] != "ucp.$phpEx") ! { ! mx_redirect(mx_append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=profile&mode=reg_details')); ! } ! } ! */ return; } --- 599,658 ---- } + /** ******************************************************************************************************* + * Include the User class + ******************************************************************************************************* */ + /** ! * Define backend specific lang defs */ function setup($lang_set = false, $style = false) { global $db, $template, $board_config, $userdata, $phpbb_auth, $phpEx, $phpbb_root_path, $mx_root_path, $mx_cache; global $mx_request_vars, $portal_config; //added for mxp ! $lang_set = !$lang_set ? (defined('IN_ADMIN') ? 'lang_admin' : 'lang_main') : $lang_set; ! $this->lang_name = $this->lang['default_lang']; ! $this->lang_path = $shared_lang_path; ! $this->date_format = $board_config['default_dateformat']; ! $this->timezone = $board_config['user_timezone'] * 3600; ! $this->dst = $this->data['user_dst'] * 3600; ! // // We include common language file here to not load it every time a custom language file is included ! // ! $lang = &$this->lang; ! /* Sort of pointless here, since we have already included all main lang files ! if ((@include $this->lang_path . "common.$phpEx") === false) { ! //this will fix the path for anonymouse users ! if ((@include $phpbb_root_path . $this->lang_path . "common.$phpEx") === false) { ! die('Language file ' . $this->lang_path . "common.$phpEx" . ' couldn\'t be opened.'); } } + */ ! // We include common language file here to not load it every time a custom language file is included ! //$this->lang = &$lang; ! $this->add_lang($lang_set); ! // We include common language file here to not load it every time a custom language file is included ! //$lang = &$this->lang; ! unset($lang_set); + return; + } ! /** ! * Setup style ! * ! * Define backend specific style defs ! * ! */ ! function setup_style() ! { return; } *************** *** 993,997 **** elseif ($lang_set) { ! $this->set_lang($this->lang, $this->help, $lang_set, $use_db, $use_help); } } --- 707,711 ---- elseif ($lang_set) { ! $this->set_lang($this->lang, $this->help, $lang_set, $use_db, $use_help); } } *************** *** 1003,1040 **** function set_lang(&$lang, &$help, $lang_file, $use_db = false, $use_help = false) { ! global $phpbb_root_path, $phpEx; ! ! ! // Make sure the language path is set (if the user setup did not happen it is not set) ! if (!$this->lang_path) ! { ! global $mx_root_path, $board_config; ! ! switch (PORTAL_BACKEND) ! { ! case 'internal': ! case 'phpbb3': ! $phpbb_lang_path = $mx_root_path . 'includes/shared/phpbb2/language/'; ! break; ! case 'phpbb2': ! $phpbb_lang_path = $phpbb_root_path . 'language/'; ! break; ! default: ! $phpbb_lang_path = $phpbb_root_path . 'language/'; ! } ! ! $board_config['default_lang'] = $this->get_phpbb_lang($board_config['default_lang']); // This will expand the lang name ! ! if ($this->data['user_id'] != ANONYMOUS) ! { ! $this->lang_name = (file_exists($phpbb_lang_path . "lang_" . $this->get_phpbb_lang($this->data['user_lang']) . "/lang_main.$phpEx")) ? $this->get_phpbb_lang($this->data['user_lang']) : $board_config['default_lang']; ! $this->lang_path = $phpbb_lang_path . "lang_" . $this->lang_name . '/'; ! } ! else ! { ! $this->lang_name = ($this->lang['default_lang']) ? $this->get_phpbb_lang($this->lang['default_lang']) : $board_config['default_lang']; ! $this->lang_path = $phpbb_lang_path . "lang_" . $this->lang_name . '/'; ! } ! } // $lang == $this->lang --- 717,721 ---- function set_lang(&$lang, &$help, $lang_file, $use_db = false, $use_help = false) { ! global $phpbb_root_path, $phpEx; // $lang == $this->lang *************** *** 1051,1055 **** $language_filename = $this->lang_path . (($use_help) ? 'help_' : '') . $lang_file . '.' . $phpEx; } ! //fix for mxp if ((@include $language_filename) === false) --- 732,736 ---- $language_filename = $this->lang_path . (($use_help) ? 'help_' : '') . $lang_file . '.' . $phpEx; } ! //fix for mxp if ((@include $language_filename) === false) *************** *** 1069,1077 **** die("You should not use db with MX-Publisher!"); } ! // We include common language file here to not load it every time a custom language file is included ! $this->lang = &$lang; } } --- 750,783 ---- die("You should not use db with MX-Publisher!"); } ! // We include common language file here to not load it every time a custom language file is included ! $this->lang = &$lang; } + /** + * encode_lang + * + * $default_lang = $mx_user->encode_lang($board_config['default_lang']); + * + * @param unknown_type $lang + * @return unknown + */ + function encode_lang($lang) + { + return $lang; + } + + /** + * decode_lang + * + * $default_lang = $mx_user->decode_lang($board_config['default_lang']); + * + * @param unknown_type $lang + * @return unknown + */ + function decode_lang($lang) + { + return $lang; + } } |