diff options
Diffstat (limited to 'phpBB/includes/functions_user.php')
| -rw-r--r-- | phpBB/includes/functions_user.php | 215 | 
1 files changed, 102 insertions, 113 deletions
| diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 3f4203c554..7a79e6276f 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -485,44 +485,6 @@ function user_delete($mode, $user_id, $post_username = false)  				include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);  			} -			$sql = 'SELECT topic_id, COUNT(post_id) AS total_posts -				FROM ' . POSTS_TABLE . " -				WHERE poster_id = $user_id -				GROUP BY topic_id"; -			$result = $db->sql_query($sql); - -			$topic_id_ary = array(); -			while ($row = $db->sql_fetchrow($result)) -			{ -				$topic_id_ary[$row['topic_id']] = $row['total_posts']; -			} -			$db->sql_freeresult($result); - -			if (sizeof($topic_id_ary)) -			{ -				$sql = 'SELECT topic_id, topic_replies, topic_replies_real -					FROM ' . TOPICS_TABLE . ' -					WHERE ' . $db->sql_in_set('topic_id', array_keys($topic_id_ary)); -				$result = $db->sql_query($sql); - -				$del_topic_ary = array(); -				while ($row = $db->sql_fetchrow($result)) -				{ -					if (max($row['topic_replies'], $row['topic_replies_real']) + 1 == $topic_id_ary[$row['topic_id']]) -					{ -						$del_topic_ary[] = $row['topic_id']; -					} -				} -				$db->sql_freeresult($result); - -				if (sizeof($del_topic_ary)) -				{ -					$sql = 'DELETE FROM ' . TOPICS_TABLE . ' -						WHERE ' . $db->sql_in_set('topic_id', $del_topic_ary); -					$db->sql_query($sql); -				} -			} -  			// Delete posts, attachments, etc.  			delete_posts('poster_id', $user_id); @@ -569,62 +531,12 @@ function user_delete($mode, $user_id, $post_username = false)  		WHERE session_user_id = ' . $user_id;  	$db->sql_query($sql); -	// Remove any undelivered mails... -	$sql = 'SELECT msg_id, user_id -		FROM ' . PRIVMSGS_TO_TABLE . ' -		WHERE author_id = ' . $user_id . ' -			AND folder_id = ' . PRIVMSGS_NO_BOX; -	$result = $db->sql_query($sql); - -	$undelivered_msg = $undelivered_user = array(); -	while ($row = $db->sql_fetchrow($result)) +	// Clean the private messages tables from the user +	if (!function_exists('phpbb_delete_user_pms'))  	{ -		$undelivered_msg[] = $row['msg_id']; -		$undelivered_user[$row['user_id']][] = true; -	} -	$db->sql_freeresult($result); - -	if (sizeof($undelivered_msg)) -	{ -		$sql = 'DELETE FROM ' . PRIVMSGS_TABLE . ' -			WHERE ' . $db->sql_in_set('msg_id', $undelivered_msg); -		$db->sql_query($sql); -	} - -	$sql = 'DELETE FROM ' . PRIVMSGS_TO_TABLE . ' -		WHERE author_id = ' . $user_id . ' -			AND folder_id = ' . PRIVMSGS_NO_BOX; -	$db->sql_query($sql); - -	// Delete all to-information -	$sql = 'DELETE FROM ' . PRIVMSGS_TO_TABLE . ' -		WHERE user_id = ' . $user_id; -	$db->sql_query($sql); - -	// Set the remaining author id to anonymous - this way users are still able to read messages from users being removed -	$sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . ' -		SET author_id = ' . ANONYMOUS . ' -		WHERE author_id = ' . $user_id; -	$db->sql_query($sql); - -	$sql = 'UPDATE ' . PRIVMSGS_TABLE . ' -		SET author_id = ' . ANONYMOUS . ' -		WHERE author_id = ' . $user_id; -	$db->sql_query($sql); - -	foreach ($undelivered_user as $_user_id => $ary) -	{ -		if ($_user_id == $user_id) -		{ -			continue; -		} - -		$sql = 'UPDATE ' . USERS_TABLE . ' -			SET user_new_privmsg = user_new_privmsg - ' . sizeof($ary) . ', -				user_unread_privmsg = user_unread_privmsg - ' . sizeof($ary) . ' -			WHERE user_id = ' . $_user_id; -		$db->sql_query($sql); +		include($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);  	} +	phpbb_delete_user_pms($user_id);  	$db->sql_transaction('commit'); @@ -774,7 +686,7 @@ function user_ban($mode, $ban, $ban_len, $ban_len_other, $ban_exclude, $ban_reas  			}  			else  			{ -				trigger_error('LENGTH_BAN_INVALID'); +				trigger_error('LENGTH_BAN_INVALID', E_USER_WARNING);  			}  		}  	} @@ -834,7 +746,7 @@ function user_ban($mode, $ban, $ban_len, $ban_len_other, $ban_exclude, $ban_reas  			// Make sure we have been given someone to ban  			if (!sizeof($sql_usernames))  			{ -				trigger_error('NO_USER_SPECIFIED'); +				trigger_error('NO_USER_SPECIFIED', E_USER_WARNING);  			}  			$sql = 'SELECT user_id @@ -865,7 +777,7 @@ function user_ban($mode, $ban, $ban_len, $ban_len_other, $ban_exclude, $ban_reas  			else  			{  				$db->sql_freeresult($result); -				trigger_error('NO_USERS'); +				trigger_error('NO_USERS', E_USER_WARNING);  			}  			$db->sql_freeresult($result);  		break; @@ -967,7 +879,7 @@ function user_ban($mode, $ban, $ban_len, $ban_len_other, $ban_exclude, $ban_reas  				if (empty($banlist_ary))  				{ -					trigger_error('NO_IPS_DEFINED'); +					trigger_error('NO_IPS_DEFINED', E_USER_WARNING);  				}  			}  		break; @@ -995,12 +907,12 @@ function user_ban($mode, $ban, $ban_len, $ban_len_other, $ban_exclude, $ban_reas  			if (sizeof($ban_list) == 0)  			{ -				trigger_error('NO_EMAILS_DEFINED'); +				trigger_error('NO_EMAILS_DEFINED', E_USER_WARNING);  			}  		break;  		default: -			trigger_error('NO_MODE'); +			trigger_error('NO_MODE', E_USER_WARNING);  		break;  	} @@ -1463,6 +1375,31 @@ function validate_match($string, $optional = false, $match = '')  }  /** +* Validate Language Pack ISO Name +* +* Tests whether a language name is valid and installed +* +* @param string $lang_iso	The language string to test +* +* @return bool|string		Either false if validation succeeded or +*							a string which will be used as the error message +*							(with the variable name appended) +*/ +function validate_language_iso_name($lang_iso) +{ +	global $db; + +	$sql = 'SELECT lang_id +		FROM ' . LANG_TABLE . " +		WHERE lang_iso = '" . $db->sql_escape($lang_iso) . "'"; +	$result = $db->sql_query($sql); +	$lang_id = (int) $db->sql_fetchfield('lang_id'); +	$db->sql_freeresult($result); + +	return ($lang_id) ? false : 'WRONG_DATA'; +} + +/**  * Check to see if the username has been taken, or if it is disallowed.  * Also checks if it includes the " character, which we don't allow in usernames.  * Used for registering, changing names, and posting anonymously with a username @@ -1621,8 +1558,9 @@ function validate_password($password)  {  	global $config, $db, $user; -	if (!$password) +	if ($password === '' || $config['pass_complex'] === 'PASS_TYPE_ANY')  	{ +		// Password empty or no password complexity required.  		return false;  	} @@ -1633,7 +1571,6 @@ function validate_password($password)  	{  		$upp = '\p{Lu}';  		$low = '\p{Ll}'; -		$let = '\p{L}';  		$num = '\p{N}';  		$sym = '[^\p{Lu}\p{Ll}\p{N}]';  		$pcre = true; @@ -1643,7 +1580,6 @@ function validate_password($password)  		mb_regex_encoding('UTF-8');  		$upp = '[[:upper:]]';  		$low = '[[:lower:]]'; -		$let = '[[:lower:][:upper:]]';  		$num = '[[:digit:]]';  		$sym = '[^[:upper:][:lower:][:digit:]]';  		$mbstring = true; @@ -1652,7 +1588,6 @@ function validate_password($password)  	{  		$upp = '[A-Z]';  		$low = '[a-z]'; -		$let = '[a-zA-Z]';  		$num = '[0-9]';  		$sym = '[^A-Za-z0-9]';  		$pcre = true; @@ -1662,22 +1597,22 @@ function validate_password($password)  	switch ($config['pass_complex'])  	{ -		case 'PASS_TYPE_CASE': -			$chars[] = $low; -			$chars[] = $upp; -		break; +		// No break statements below ... +		// We require strong passwords in case pass_complex is not set or is invalid +		default: + +		// Require mixed case letters, numbers and symbols +		case 'PASS_TYPE_SYMBOL': +			$chars[] = $sym; +		// Require mixed case letters and numbers  		case 'PASS_TYPE_ALPHA': -			$chars[] = $let;  			$chars[] = $num; -		break; -		case 'PASS_TYPE_SYMBOL': +		// Require mixed case letters +		case 'PASS_TYPE_CASE':  			$chars[] = $low;  			$chars[] = $upp; -			$chars[] = $num; -			$chars[] = $sym; -		break;  	}  	if ($pcre) @@ -1967,6 +1902,27 @@ function validate_jabber($jid)  }  /** +* Verifies whether a style ID corresponds to an active style. +* +* @param int $style_id The style_id of a style which should be checked if activated or not. +* @return boolean +*/ +function phpbb_style_is_active($style_id) +{ +	global $db; + +	$sql = 'SELECT style_active +		FROM ' . STYLES_TABLE . ' +		WHERE style_id = '. (int) $style_id; +	$result = $db->sql_query($sql); + +	$style_is_active = (bool) $db->sql_fetchfield('style_active'); +	$db->sql_freeresult($result); + +	return $style_is_active; +} + +/**  * Remove avatar  */  function avatar_delete($mode, $row, $clean_db = false) @@ -2083,7 +2039,7 @@ function avatar_upload($data, &$error)  	// Init upload class  	include_once($phpbb_root_path . 'includes/functions_upload.' . $phpEx); -	$upload = new fileupload('AVATAR_', array('jpg', 'jpeg', 'gif', 'png'), $config['avatar_filesize'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height'], explode('|', $config['mime_triggers'])); +	$upload = new fileupload('AVATAR_', array('jpg', 'jpeg', 'gif', 'png'), $config['avatar_filesize'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height'], (isset($config['mime_triggers']) ? explode('|', $config['mime_triggers']) : false));  	if (!empty($_FILES['uploadfile']['name']))  	{ @@ -3605,4 +3561,37 @@ function remove_newly_registered($user_id, $user_data = false)  	return $user_data['group_id'];  } +/** +* Gets user ids of currently banned registered users. +* +* @param array $user_ids Array of users' ids to check for banning, +*						leave empty to get complete list of banned ids +* @return array	Array of banned users' ids if any, empty array otherwise +*/ +function phpbb_get_banned_user_ids($user_ids = array()) +{ +	global $db; + +	$sql_user_ids = (!empty($user_ids)) ? $db->sql_in_set('ban_userid', $user_ids) : 'ban_userid <> 0'; + +	// Get banned User ID's +	// Ignore stale bans which were not wiped yet +	$banned_ids_list = array(); +	$sql = 'SELECT ban_userid +		FROM ' . BANLIST_TABLE . " +		WHERE $sql_user_ids +			AND ban_exclude <> 1 +			AND (ban_end > " . time() . ' +				OR ban_end = 0)'; +	$result = $db->sql_query($sql); +	while ($row = $db->sql_fetchrow($result)) +	{ +		$user_id = (int) $row['ban_userid']; +		$banned_ids_list[$user_id] = $user_id; +	} +	$db->sql_freeresult($result); + +	return $banned_ids_list; +} +  ?> | 
