diff options
Diffstat (limited to 'phpBB/includes')
| -rw-r--r-- | phpBB/includes/acp/acp_main.php | 2 | ||||
| -rw-r--r-- | phpBB/includes/auth/auth_ldap.php | 6 | ||||
| -rw-r--r-- | phpBB/includes/db/dbal.php | 43 | ||||
| -rw-r--r-- | phpBB/includes/db/firebird.php | 43 | ||||
| -rw-r--r-- | phpBB/includes/db/mssql_odbc.php | 43 | ||||
| -rw-r--r-- | phpBB/includes/db/mssqlnative.php | 18 | ||||
| -rw-r--r-- | phpBB/includes/functions.php | 11 | ||||
| -rw-r--r-- | phpBB/includes/functions_install.php | 2 | ||||
| -rw-r--r-- | phpBB/includes/functions_privmsgs.php | 160 | ||||
| -rw-r--r-- | phpBB/includes/functions_user.php | 58 | 
10 files changed, 220 insertions, 166 deletions
diff --git a/phpBB/includes/acp/acp_main.php b/phpBB/includes/acp/acp_main.php index e529ae0e5a..cffe296651 100644 --- a/phpBB/includes/acp/acp_main.php +++ b/phpBB/includes/acp/acp_main.php @@ -201,7 +201,7 @@ class acp_main  						// No maximum post id? :o  						if (!$max_post_id)  						{ -							$sql = 'SELECT MAX(post_id) +							$sql = 'SELECT MAX(post_id) as max_post_id  								FROM ' . POSTS_TABLE;  							$result = $db->sql_query($sql);  							$max_post_id = (int) $db->sql_fetchfield('max_post_id'); diff --git a/phpBB/includes/auth/auth_ldap.php b/phpBB/includes/auth/auth_ldap.php index 5dfa74ddab..eebf147d48 100644 --- a/phpBB/includes/auth/auth_ldap.php +++ b/phpBB/includes/auth/auth_ldap.php @@ -156,7 +156,11 @@ function login_ldap(&$username, &$password)  	{  		if (!@ldap_bind($ldap, htmlspecialchars_decode($config['ldap_user']), htmlspecialchars_decode($config['ldap_password'])))  		{ -			return $user->lang['LDAP_NO_SERVER_CONNECTION']; +			return array( +				'status'		=> LOGIN_ERROR_EXTERNAL_AUTH, +				'error_msg'		=> 'LDAP_NO_SERVER_CONNECTION', +				'user_row'		=> array('user_id' => ANONYMOUS), +			);  		}  	} diff --git a/phpBB/includes/db/dbal.php b/phpBB/includes/db/dbal.php index 5d456c2ff0..358df50402 100644 --- a/phpBB/includes/db/dbal.php +++ b/phpBB/includes/db/dbal.php @@ -195,6 +195,49 @@ class dbal  	}  	/** +	* Seek to given row number +	* rownum is zero-based +	*/ +	function sql_rowseek($rownum, &$query_id) +	{ +		global $cache; + +		if ($query_id === false) +		{ +			$query_id = $this->query_result; +		} + +		if (isset($cache->sql_rowset[$query_id])) +		{ +			return $cache->sql_rowseek($rownum, $query_id); +		} + +		if ($query_id === false) +		{ +			return false; +		} + +		$this->sql_freeresult($query_id); +		$query_id = $this->sql_query($this->last_query_text); + +		if ($query_id === false) +		{ +			return false; +		} + +		// We do not fetch the row for rownum == 0 because then the next resultset would be the second row +		for ($i = 0; $i < $rownum; $i++) +		{ +			if (!$this->sql_fetchrow($query_id)) +			{ +				return false; +			} +		} + +		return true; +	} + +	/**  	* Fetch field  	* if rownum is false, the current row is used, else it is pointing to the row (zero-based)  	*/ diff --git a/phpBB/includes/db/firebird.php b/phpBB/includes/db/firebird.php index 7e3f15ed1d..7072c58ac0 100644 --- a/phpBB/includes/db/firebird.php +++ b/phpBB/includes/db/firebird.php @@ -360,49 +360,6 @@ class dbal_firebird extends dbal  	}  	/** -	* Seek to given row number -	* rownum is zero-based -	*/ -	function sql_rowseek($rownum, &$query_id) -	{ -		global $cache; - -		if ($query_id === false) -		{ -			$query_id = $this->query_result; -		} - -		if (isset($cache->sql_rowset[$query_id])) -		{ -			return $cache->sql_rowseek($rownum, $query_id); -		} - -		if ($query_id === false) -		{ -			return; -		} - -		$this->sql_freeresult($query_id); -		$query_id = $this->sql_query($this->last_query_text); - -		if ($query_id === false) -		{ -			return false; -		} - -		// We do not fetch the row for rownum == 0 because then the next resultset would be the second row -		for ($i = 0; $i < $rownum; $i++) -		{ -			if (!$this->sql_fetchrow($query_id)) -			{ -				return false; -			} -		} - -		return true; -	} - -	/**  	* Get last inserted id after insert statement  	*/  	function sql_nextid() diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php index 75a080b1b7..34f7a87337 100644 --- a/phpBB/includes/db/mssql_odbc.php +++ b/phpBB/includes/db/mssql_odbc.php @@ -256,49 +256,6 @@ class dbal_mssql_odbc extends dbal  	}  	/** -	* Seek to given row number -	* rownum is zero-based -	*/ -	function sql_rowseek($rownum, &$query_id) -	{ -		global $cache; - -		if ($query_id === false) -		{ -			$query_id = $this->query_result; -		} - -		if (isset($cache->sql_rowset[$query_id])) -		{ -			return $cache->sql_rowseek($rownum, $query_id); -		} - -		if ($query_id === false) -		{ -			return false; -		} - -		$this->sql_freeresult($query_id); -		$query_id = $this->sql_query($this->last_query_text); - -		if ($query_id === false) -		{ -			return false; -		} - -		// We do not fetch the row for rownum == 0 because then the next resultset would be the second row -		for ($i = 0; $i < $rownum; $i++) -		{ -			if (!$this->sql_fetchrow($query_id)) -			{ -				return false; -			} -		} - -		return true; -	} - -	/**  	* Get last inserted id after insert statement  	*/  	function sql_nextid() diff --git a/phpBB/includes/db/mssqlnative.php b/phpBB/includes/db/mssqlnative.php index 7fbc374e77..92ac9b1fb9 100644 --- a/phpBB/includes/db/mssqlnative.php +++ b/phpBB/includes/db/mssqlnative.php @@ -440,24 +440,6 @@ class dbal_mssqlnative extends dbal  	}  	/** -	* Seek to given row number -	* rownum is zero-based -	*/ -	function sql_rowseek($rownum, &$query_id) -	{ -		global $cache; - -		if (isset($cache->sql_rowset[$query_id])) -		{ -			return $cache->sql_rowseek($rownum, $query_id); -		} - -		$seek = new result_mssqlnative($query_id); -		$row = $seek->seek($rownum); -		return ($row = $seek->fetch()) ? $row : false; -	} - -	/**  	* Get last inserted id after insert statement  	*/  	function sql_nextid() diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index ce80dc4a66..bc811cc75b 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1918,14 +1918,17 @@ function update_forum_tracking_info($forum_id, $forum_last_post_time, $f_mark_ti  		}  		else  		{ -			$sql = 'SELECT t.forum_id FROM ' . TOPICS_TABLE . ' t -				LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id'] . ') +			$sql = 'SELECT t.forum_id +				FROM ' . TOPICS_TABLE . ' t +				LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt +					ON (tt.topic_id = t.topic_id +						AND tt.user_id = ' . $user->data['user_id'] . ')  				WHERE t.forum_id = ' . $forum_id . '  					AND t.topic_last_post_time > ' . $mark_time_forum . '  					AND t.topic_moved_id = 0 ' .  					$sql_update_unapproved . ' -					AND (tt.topic_id IS NULL OR tt.mark_time < t.topic_last_post_time) -				GROUP BY t.forum_id'; +					AND (tt.topic_id IS NULL +						OR tt.mark_time < t.topic_last_post_time)';  			$result = $db->sql_query_limit($sql, 1);  			$row = $db->sql_fetchrow($result);  			$db->sql_freeresult($result); diff --git a/phpBB/includes/functions_install.php b/phpBB/includes/functions_install.php index 633b2755f0..9e9c48ff58 100644 --- a/phpBB/includes/functions_install.php +++ b/phpBB/includes/functions_install.php @@ -559,8 +559,6 @@ function phpbb_create_config_file_data($data, $dbms, $load_extensions, $debug =  		$config_data .= "// @define('DEBUG_EXTRA', true);\n";  	} -	$config_data .= '?' . '>'; // Done this to prevent highlighting editors getting confused! -  	return $config_data;  } diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index 447920cfd5..d2fce000aa 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -1084,6 +1084,166 @@ function delete_pm($user_id, $msg_ids, $folder_id)  }  /** +* Delete all PM(s) for a given user and delete the ones without references +* +* @param	int		$user_id	ID of the user whose private messages we want to delete +* +* @return	boolean		False if there were no pms found, true otherwise. +*/ +function phpbb_delete_user_pms($user_id) +{ +	global $db, $user, $phpbb_root_path, $phpEx; + +	$user_id = (int) $user_id; + +	if (!$user_id) +	{ +		return false; +	} + +	// Get PM Information for later deleting +	// The two queries where split, so we can use our indexes +	// Part 1: get PMs the user received +	$sql = 'SELECT msg_id, author_id, folder_id, pm_unread, pm_new +		FROM ' . PRIVMSGS_TO_TABLE . ' +		WHERE user_id = ' . $user_id; +	$result = $db->sql_query($sql); + +	$undelivered_msg = $undelivered_user = $delete_ids = array(); +	while ($row = $db->sql_fetchrow($result)) +	{ +		if ($row['author_id'] == $user_id && $row['folder_id'] == PRIVMSGS_NO_BOX) +		{ +			// Undelivered messages +			$undelivered_msg[] = $row['msg_id']; + +			if (isset($undelivered_user[$row['user_id']])) +			{ +				++$undelivered_user[$row['user_id']]; +			} +			else +			{ +				$undelivered_user[$row['user_id']] = 1; +			} +		} + +		$delete_ids[(int) $row['msg_id']] = (int) $row['msg_id']; +	} +	$db->sql_freeresult($result); + +	// Part 2: get PMs the user sent +	$sql = 'SELECT msg_id, author_id, folder_id, pm_unread, pm_new +		FROM ' . PRIVMSGS_TO_TABLE . ' +		WHERE author_id = ' . $user_id . ' +				AND folder_id = ' . PRIVMSGS_NO_BOX; +	$result = $db->sql_query($sql); + +	while ($row = $db->sql_fetchrow($result)) +	{ +		if ($row['author_id'] == $user_id && $row['folder_id'] == PRIVMSGS_NO_BOX) +		{ +			// Undelivered messages +			$undelivered_msg[] = $row['msg_id']; + +			if (isset($undelivered_user[$row['user_id']])) +			{ +				++$undelivered_user[$row['user_id']]; +			} +			else +			{ +				$undelivered_user[$row['user_id']] = 1; +			} +		} + +		$delete_ids[(int) $row['msg_id']] = (int) $row['msg_id']; +	} +	$db->sql_freeresult($result); + +	if (empty($delete_ids)) +	{ +		return false; +	} + +	$db->sql_transaction('begin'); + +	if (sizeof($undelivered_msg)) +	{ +		$sql = 'DELETE FROM ' . PRIVMSGS_TABLE . ' +			WHERE ' . $db->sql_in_set('msg_id', $undelivered_msg); +		$db->sql_query($sql); +	} + +	// Reset the userīs pm count to 0 +	if (isset($undelivered_user[$user_id])) +	{ +		$sql = 'UPDATE ' . USERS_TABLE . ' +			SET user_new_privmsg = 0, +				user_unread_privmsg = 0 +			WHERE user_id = ' . $user_id; +		$db->sql_query($sql); +		unset($undelivered_user[$user_id]); +	} + +	foreach ($undelivered_user as $_user_id => $count) +	{ +		$sql = 'UPDATE ' . USERS_TABLE . ' +			SET user_new_privmsg = user_new_privmsg - ' . $count . ', +				user_unread_privmsg = user_unread_privmsg - ' . $count . ' +			WHERE user_id = ' . $_user_id; +		$db->sql_query($sql); +	} + +	// Delete private message data +	$sql = 'DELETE FROM ' . PRIVMSGS_TO_TABLE . " +		WHERE user_id = $user_id +			AND " . $db->sql_in_set('msg_id', $delete_ids); +	$db->sql_query($sql); + +	// Now we have to check which messages we can delete completely +	$sql = 'SELECT msg_id +		FROM ' . PRIVMSGS_TO_TABLE . ' +		WHERE ' . $db->sql_in_set('msg_id', $delete_ids); +	$result = $db->sql_query($sql); + +	while ($row = $db->sql_fetchrow($result)) +	{ +		unset($delete_ids[$row['msg_id']]); +	} +	$db->sql_freeresult($result); + +	if (!empty($delete_ids)) +	{ +		// Check if there are any attachments we need to remove +		if (!function_exists('delete_attachments')) +		{ +			include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); +		} + +		delete_attachments('message', $delete_ids, false); + +		$sql = 'DELETE FROM ' . PRIVMSGS_TABLE . ' +			WHERE ' . $db->sql_in_set('msg_id', $delete_ids); +		$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); + +	$db->sql_transaction('commit'); + +	return true; +} + +/**  * Rebuild message header  */  function rebuild_header($check_ary) diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 83316be2a3..5a6a0b4a05 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -528,62 +528,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)) -	{ -		$undelivered_msg[] = $row['msg_id']; -		$undelivered_user[$row['user_id']][] = true; -	} -	$db->sql_freeresult($result); - -	if (sizeof($undelivered_msg)) +	// Clean the private messages tables from the user +	if (!function_exists('phpbb_delete_user_pms'))  	{ -		$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');  | 
