|
From: Florin C B. <ory...@us...> - 2014-05-16 18:02:26
|
Update of /cvsroot/mxbb/core/includes/sessions/phpbb3 In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv14874/phpbb3 Modified Files: core.php session.php Log Message: Some fixes for internal Backend Index: core.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/sessions/phpbb3/core.php,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** core.php 9 May 2014 07:52:03 -0000 1.27 --- core.php 16 May 2014 18:02:23 -0000 1.28 *************** *** 193,225 **** global $db, $portal_config, $phpbb_root_path, $mx_root_path; global $table_prefix, $phpEx, $tplEx; ! $table_prefix = false; ! ! // // Define relative path to phpBB, and validate - // $phpbb_root_path = $mx_root_path . $portal_config['portal_backend_path']; str_replace("//", "/", $phpbb_root_path); $portal_backend_valid_file = @file_exists($phpbb_root_path . "mcp.$phpEx"); ! ! // // Load phpbb config.php (to get table prefix) - // if ((include $phpbb_root_path . "config.$phpEx") === false) { ! die('Configuration file (config) ' . $phpbb_root_path . "/config.$phpEx" . ' couldn\'t be opened.'); } - // // Define backend template extension ! // ! $tplEx = 'html'; ! ! // // Validate db connection for backend - // $_result = $db->sql_query("SELECT config_value from " . $table_prefix . "config WHERE config_name = 'cookie_domain'"); $portal_backend_valid_db = $db->sql_numrows($_result) != 0; ! return $portal_backend_valid_file && !empty($table_prefix) && $portal_backend_valid_db; } --- 193,217 ---- global $db, $portal_config, $phpbb_root_path, $mx_root_path; global $table_prefix, $phpEx, $tplEx; ! $table_prefix = false; ! // Define relative path to phpBB, and validate $phpbb_root_path = $mx_root_path . $portal_config['portal_backend_path']; str_replace("//", "/", $phpbb_root_path); $portal_backend_valid_file = @file_exists($phpbb_root_path . "mcp.$phpEx"); ! // Load phpbb config.php (to get table prefix) if ((include $phpbb_root_path . "config.$phpEx") === false) { ! die('Configuration file (config) ' . $phpbb_root_path . "config.$phpEx" . ' couldn\'t be opened.'); } // Define backend template extension ! $tplEx = 'html'; ! // Validate db connection for backend $_result = $db->sql_query("SELECT config_value from " . $table_prefix . "config WHERE config_name = 'cookie_domain'"); $portal_backend_valid_db = $db->sql_numrows($_result) != 0; ! return $portal_backend_valid_file && !empty($table_prefix) && $portal_backend_valid_db; } *************** *** 359,363 **** // Rename config keys and get internal sitename/sitedesc - // case 'portal_name': --- 351,354 ---- *************** *** 424,432 **** { global $db, $portal_config, $board_config, $dss_seeded; ! $val = $board_config['rand_seed'] . microtime(); $val = md5($val); $board_config['rand_seed'] = md5($board_config['rand_seed'] . $val . 'a'); ! if($dss_seeded !== true) { --- 415,423 ---- { global $db, $portal_config, $board_config, $dss_seeded; ! $val = $board_config['rand_seed'] . microtime(); $val = md5($val); $board_config['rand_seed'] = md5($board_config['rand_seed'] . $val . 'a'); ! if($dss_seeded !== true) { *************** *** 434,446 **** config_value = '" . $board_config['rand_seed'] . "' WHERE config_name = 'rand_seed'"; ! ! if( !$db->sql_query($sql) ) { mx_message_die(GENERAL_ERROR, "Unable to reseed PRNG", "", __LINE__, __FILE__, $sql); } ! $dss_seeded = true; } - return substr($val, 4, 16); } --- 425,439 ---- config_value = '" . $board_config['rand_seed'] . "' WHERE config_name = 'rand_seed'"; ! //display an error debuging message only if the portal is installed/upgraded ! if(!@$db->sql_query($sql) && @!file_exists('install')) { mx_message_die(GENERAL_ERROR, "Unable to reseed PRNG", "", __LINE__, __FILE__, $sql); } ! elseif(!@$db->sql_query($sql) && @file_exists('install')) ! { ! mx_message_die(GENERAL_ERROR, "Unable to reseed PRNG"."<br />Please finish upgrading and <br />". t(isset($lang['Please_remove_install_contrib'])), "", __LINE__, __FILE__, $sql); ! } $dss_seeded = true; } return substr($val, 4, 16); } Index: session.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/sessions/phpbb3/session.php,v retrieving revision 1.60 retrieving revision 1.61 diff -C2 -d -r1.60 -r1.61 *** session.php 2 Jul 2013 02:24:03 -0000 1.60 --- session.php 16 May 2014 18:02:23 -0000 1.61 *************** *** 2215,2229 **** { global $board_config, $db; ! if (!empty($this->lang_id)) { return $this->lang_id; } ! if (!$this->lang_name) { $this->lang_name = $board_config['default_lang']; } ! $sql = 'SELECT lang_id FROM ' . LANG_TABLE . " --- 2215,2229 ---- { global $board_config, $db; ! if (!empty($this->lang_id)) { return $this->lang_id; } ! if (!$this->lang_name) { $this->lang_name = $board_config['default_lang']; } ! $sql = 'SELECT lang_id FROM ' . LANG_TABLE . " *************** *** 2232,2236 **** $this->lang_id = (int) $db->sql_fetchfield('lang_id'); $db->sql_freeresult($result); ! return $this->lang_id; } --- 2232,2236 ---- $this->lang_id = (int) $db->sql_fetchfield('lang_id'); $db->sql_freeresult($result); ! return $this->lang_id; } *************** *** 2255,2259 **** --- 2255,2463 ---- $db->sql_freeresult($result); } + + /** + * Gets the user's info + * + * Will take the users email, username or member id and return their data + * + * @param int || string $username the user's email address username or member id + * @return array $results containing the user info || bool false + * @since 0.1.2 + */ + function load_user($user, $force_str = false) + { + if (!is_numeric($user) || $force_str) + { + $user = phpBB2::phpbb_clean_username($user); + } + else + { + $user = intval($user); + } + + //$this->data = array(); + + // we'll try id || email, then username + if (is_numeric($user)) + { + // number is most likely a member id + $this->data = get_user_by_id($user); + } + else + { + // the email can't be purely numeric + $this->data = get_user_by_email($user); + } + + if (empty($this->data)) + { + $this->data = get_user_by_username($user); + } + /* + if (empty($this->data)) + { + return false; + } + else + { + return $this->data; + } + */ + } + + /** + * Load user helper + * + * @param array $user_ids + */ + function load_users(array $user_ids) + { + $user_ids[] = ANONYMOUS; + + // Make user_ids unique and convert to integer. + $user_ids = array_map('intval', array_unique($user_ids)); + + // Do not load users we already have in $this->users + $user_ids = array_diff($user_ids, array_keys($this->users)); + + if (sizeof($user_ids)) + { + $sql = 'SELECT * + FROM ' . USERS_TABLE . ' + WHERE ' . $db->sql_in_set('user_id', $user_ids); + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $this->users[$row['user_id']] = $row; + } + $db->sql_freeresult($result); + } + } + + /** + * Gets the user's info from their email address + * + * Will take the users email address and return an array containing all the + * user's information in the db. Will return false on failure + * + * @param string $email the user's email address + * @return array $results containing the user info || bool false + * @since 0.1.0 + */ + function get_user_by_email($email_address = '') + { + global $db; + if ('' == $email_address || !is_string($email_address) || 2 > count(explode('@', $email_address))) + { + return false; + } + $sql = $db->sql_build_query('SELECT', ' + SELECT * FROM ' . USERS_TABLE . ' + WHERE email_address = {string:email_address}', + array('email_address' => $email_address, )); + $result = $db->sql_query_limit($sql, 1); + $return = $db->sql_fetchrow($result); + if (!$return) + { + $db->sql_freeresult($result); + //trigger_error($mx_user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING); + } + if (empty($return)) + { + return false; + } + else + { + // return all the results. + return $return; + } + } + /** + * Gets the user's info from their member id + * + * Will take the users member id and return an array containing all the + * user's information in the db. Will return false on failure + * + * @param int $id the user's member id + * @return array $results containing the user info || bool false + * @since 0.1.2 + */ + function get_user_by_id($user_id = '') + { + global $db; + if ('' == $user_id || !is_numeric($user_id)) + { + return false; + } + else + { + $id = intval($user_id); + if (0 == $user_id) + { + return false; + } + } + $sql = $db->sql_build_query('SELECT', ' + SELECT * FROM ' . USERS_TABLE . ' + WHERE user_id = {int:user_id}', + array('user_id' => $user_id, )); + $result = $db->sql_query_limit($sql, 1); + $return = $db->sql_fetchrow($result); + if (!$return) + { + $db->sql_freeresult($result); + //trigger_error($mx_user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING); + } + if (empty($return)) + { + return false; + } + else + { + // return all the results. + return $return; + } + } + + /** + * Gets the user's info from their member name (username) + * + * Will take the users member name and return an array containing all the + * user's information in the db. Will return false on failure + * + * @param string $username the user's member name + * @return array $results containing the user info || bool false + * @since 0.1.0 + */ + function get_user_by_name($user_name = '') + { + global $db; + if ('' == $user_name || !is_string($user_name)) + { + return false; + } + $sql = $db->sql_build_query('SELECT', ' + SELECT * FROM ' . USERS_TABLE . ' + WHERE user_name = {string:user_name}', + array('user_name' => $user_name, )); + $result = $db->sql_query_limit($sql, 1); + $return = $db->sql_fetchrow($result); + if (!$return) + { + $db->sql_freeresult($result); + //trigger_error($mx_user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING); + } + if (empty($return)) + { + return false; + } + else + { + // return all the results. + return $return; + } + } /** |