diff options
Diffstat (limited to 'phpBB/includes/functions_posting.php')
| -rw-r--r-- | phpBB/includes/functions_posting.php | 578 | 
1 files changed, 131 insertions, 447 deletions
| diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index e5cbae0d71..baef7bcda5 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2,9 +2,8 @@  /**  *  * @package phpBB3 -* @version $Id$  * @copyright (c) 2005 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2  *  */ @@ -21,7 +20,7 @@ if (!defined('IN_PHPBB'))  */  function generate_smilies($mode, $forum_id)  { -	global $auth, $db, $user, $config, $template; +	global $db, $user, $config, $template, $phpbb_dispatcher;  	global $phpEx, $phpbb_root_path;  	$start = request_var('start', 0); @@ -62,10 +61,7 @@ function generate_smilies($mode, $forum_id)  			'body' => 'posting_smilies.html')  		); -		$template->assign_var('PAGINATION', -			generate_pagination(append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=smilies&f=' . $forum_id), -				$smiley_count, $config['smilies_per_page'], $start, true) -		); +		generate_pagination(append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=smilies&f=' . $forum_id), $smiley_count, $config['smilies_per_page'], $start);  	}  	$display_link = false; @@ -127,6 +123,18 @@ function generate_smilies($mode, $forum_id)  		}  	} +	/** +	* This event is called after the smilies are populated +	* +	* @event core.generate_smilies_after +	* @var	string	mode			Mode of the smilies: window|inline +	* @var	int		forum_id		The forum ID we are currently in +	* @var	bool	display_link	Shall we display the "more smilies" link? +	* @since 3.1-A1 +	*/ +	$vars = array('mode', 'forum_id', 'display_link'); +	extract($phpbb_dispatcher->trigger_event('core.generate_smilies_after', compact($vars))); +  	if ($mode == 'inline' && $display_link)  	{  		$template->assign_vars(array( @@ -340,7 +348,7 @@ function posting_gen_topic_types($forum_id, $cur_topic_type = POST_NORMAL)  			$topic_type_array[] = array(  				'VALUE'			=> $topic_value['const'], -				'S_CHECKED'		=> ($cur_topic_type == $topic_value['const'] || ($forum_id == 0 && $topic_value['const'] == POST_GLOBAL)) ? ' checked="checked"' : '', +				'S_CHECKED'		=> ($cur_topic_type == $topic_value['const']) ? ' checked="checked"' : '',  				'L_TOPIC_TYPE'	=> $user->lang[$topic_value['lang']]  			);  		} @@ -569,30 +577,30 @@ function get_supported_image_types($type = false)  		if ($type !== false)  		{  			// Type is one of the IMAGETYPE constants - it is fetched from getimagesize() -			// We do not use the constants here, because some were not available in PHP 4.3.x  			switch ($type)  			{  				// GIF -				case 1: +				case IMAGETYPE_GIF:  					$new_type = ($format & IMG_GIF) ? IMG_GIF : false;  				break;  				// JPG, JPC, JP2 -				case 2: -				case 9: -				case 10: -				case 11: -				case 12: +				case IMAGETYPE_JPEG: +				case IMAGETYPE_JPC: +				case IMAGETYPE_JPEG2000: +				case IMAGETYPE_JP2: +				case IMAGETYPE_JPX: +				case IMAGETYPE_JB2:  					$new_type = ($format & IMG_JPG) ? IMG_JPG : false;  				break;  				// PNG -				case 3: +				case IMAGETYPE_PNG:  					$new_type = ($format & IMG_PNG) ? IMG_PNG : false;  				break;  				// WBMP -				case 15: +				case IMAGETYPE_WBMP:  					$new_type = ($format & IMG_WBMP) ? IMG_WBMP : false;  				break;  			} @@ -812,7 +820,7 @@ function posting_gen_inline_attachments(&$attachment_data)  */  function posting_gen_attachment_entry($attachment_data, &$filename_data, $show_attach_box = true)  { -	global $template, $config, $phpbb_root_path, $phpEx, $user, $auth; +	global $template, $config, $phpbb_root_path, $phpEx, $user;  	// Some default template variables  	$template->assign_vars(array( @@ -1014,7 +1022,7 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id  		$mode = 'post_review';  	} -	$sql = $db->sql_build_query('SELECT', array( +	$sql_ary = array(  		'SELECT'	=> 'u.username, u.user_id, u.user_colour, p.*, z.friend, z.foe',  		'FROM'		=> array( @@ -1025,14 +1033,15 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id  		'LEFT_JOIN'	=> array(  			array(  				'FROM'	=> array(ZEBRA_TABLE => 'z'), -				'ON'	=> 'z.user_id = ' . $user->data['user_id'] . ' AND z.zebra_id = p.poster_id' -			) +				'ON'	=> 'z.user_id = ' . $user->data['user_id'] . ' AND z.zebra_id = p.poster_id', +			),  		),  		'WHERE'		=> $db->sql_in_set('p.post_id', $post_list) . ' -			AND u.user_id = p.poster_id' -	)); +			AND u.user_id = p.poster_id', +	); +	$sql = $db->sql_build_query('SELECT', $sql_ary);  	$result = $db->sql_query($sql);  	$bbcode_bitfield = ''; @@ -1087,7 +1096,7 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id  			continue;  		} -		$row =& $rowset[$post_list[$i]]; +		$row = $rowset[$post_list[$i]];  		$poster_id		= $row['user_id'];  		$post_subject	= $row['post_subject']; @@ -1166,238 +1175,6 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id  	return true;  } -/** -* User Notification -*/ -function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id, $topic_id, $post_id, $author_name = '') -{ -	global $db, $user, $config, $phpbb_root_path, $phpEx, $auth; - -	$topic_notification = ($mode == 'reply' || $mode == 'quote') ? true : false; -	$forum_notification = ($mode == 'post') ? true : false; - -	if (!$topic_notification && !$forum_notification) -	{ -		trigger_error('NO_MODE'); -	} - -	if (($topic_notification && !$config['allow_topic_notify']) || ($forum_notification && !$config['allow_forum_notify'])) -	{ -		return; -	} - -	$topic_title = ($topic_notification) ? $topic_title : $subject; -	$topic_title = censor_text($topic_title); - -	// Exclude guests, current user and banned users from notifications -	if (!function_exists('phpbb_get_banned_user_ids')) -	{ -		include($phpbb_root_path . 'includes/functions_user.' . $phpEx); -	} -	$sql_ignore_users = phpbb_get_banned_user_ids(); -	$sql_ignore_users[ANONYMOUS] = ANONYMOUS; -	$sql_ignore_users[$user->data['user_id']] = $user->data['user_id']; - -	$notify_rows = array(); - -	// -- get forum_userids	|| topic_userids -	$sql = 'SELECT u.user_id, u.username, u.user_email, u.user_lang, u.user_notify_type, u.user_jabber -		FROM ' . (($topic_notification) ? TOPICS_WATCH_TABLE : FORUMS_WATCH_TABLE) . ' w, ' . USERS_TABLE . ' u -		WHERE w.' . (($topic_notification) ? 'topic_id' : 'forum_id') . ' = ' . (($topic_notification) ? $topic_id : $forum_id) . ' -			AND ' . $db->sql_in_set('w.user_id', $sql_ignore_users, true) . ' -			AND w.notify_status = ' . NOTIFY_YES . ' -			AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ') -			AND u.user_id = w.user_id'; -	$result = $db->sql_query($sql); - -	while ($row = $db->sql_fetchrow($result)) -	{ -		$notify_user_id = (int) $row['user_id']; -		$notify_rows[$notify_user_id] = array( -			'user_id'		=> $notify_user_id, -			'username'		=> $row['username'], -			'user_email'	=> $row['user_email'], -			'user_jabber'	=> $row['user_jabber'], -			'user_lang'		=> $row['user_lang'], -			'notify_type'	=> ($topic_notification) ? 'topic' : 'forum', -			'template'		=> ($topic_notification) ? 'topic_notify' : 'newtopic_notify', -			'method'		=> $row['user_notify_type'], -			'allowed'		=> false -		); - -		// Add users who have been already notified to ignore list -		$sql_ignore_users[$notify_user_id] = $notify_user_id; -	} -	$db->sql_freeresult($result); - -	// forum notification is sent to those not already receiving topic notifications -	if ($topic_notification) -	{ -		$sql = 'SELECT u.user_id, u.username, u.user_email, u.user_lang, u.user_notify_type, u.user_jabber -			FROM ' . FORUMS_WATCH_TABLE . ' fw, ' . USERS_TABLE . " u -			WHERE fw.forum_id = $forum_id -				AND " . $db->sql_in_set('fw.user_id', $sql_ignore_users, true) . ' -				AND fw.notify_status = ' . NOTIFY_YES . ' -				AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ') -				AND u.user_id = fw.user_id'; -		$result = $db->sql_query($sql); - -		while ($row = $db->sql_fetchrow($result)) -		{ -			$notify_user_id = (int) $row['user_id']; -			$notify_rows[$notify_user_id] = array( -				'user_id'		=> $notify_user_id, -				'username'		=> $row['username'], -				'user_email'	=> $row['user_email'], -				'user_jabber'	=> $row['user_jabber'], -				'user_lang'		=> $row['user_lang'], -				'notify_type'	=> 'forum', -				'template'		=> 'forum_notify', -				'method'		=> $row['user_notify_type'], -				'allowed'		=> false -			); -		} -		$db->sql_freeresult($result); -	} - -	if (!sizeof($notify_rows)) -	{ -		return; -	} - -	// Make sure users are allowed to read the forum -	foreach ($auth->acl_get_list(array_keys($notify_rows), 'f_read', $forum_id) as $forum_id => $forum_ary) -	{ -		foreach ($forum_ary as $auth_option => $user_ary) -		{ -			foreach ($user_ary as $user_id) -			{ -				$notify_rows[$user_id]['allowed'] = true; -			} -		} -	} - -	// Now, we have to do a little step before really sending, we need to distinguish our users a little bit. ;) -	$msg_users = $delete_ids = $update_notification = array(); -	foreach ($notify_rows as $user_id => $row) -	{ -		if (!$row['allowed'] || !trim($row['user_email'])) -		{ -			$delete_ids[$row['notify_type']][] = $row['user_id']; -		} -		else -		{ -			$msg_users[] = $row; -			$update_notification[$row['notify_type']][] = $row['user_id']; - -			/* -			* We also update the forums watch table for this user when we are -			* sending out a topic notification to prevent sending out another -			* notification in case this user is also subscribed to the forum -			* this topic was posted in. -			* Since an UPDATE query is used, this has no effect on users only -			* subscribed to the topic (i.e. no row is created) and should not -			* be a performance issue. -			*/ -			if ($row['notify_type'] === 'topic') -			{ -				$update_notification['forum'][] = $row['user_id']; -			} -		} -	} -	unset($notify_rows); - -	// Now, we are able to really send out notifications -	if (sizeof($msg_users)) -	{ -		include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); -		$messenger = new messenger(); - -		$msg_list_ary = array(); -		foreach ($msg_users as $row) -		{ -			$pos = (!isset($msg_list_ary[$row['template']])) ? 0 : sizeof($msg_list_ary[$row['template']]); - -			$msg_list_ary[$row['template']][$pos]['method']	= $row['method']; -			$msg_list_ary[$row['template']][$pos]['email']	= $row['user_email']; -			$msg_list_ary[$row['template']][$pos]['jabber']	= $row['user_jabber']; -			$msg_list_ary[$row['template']][$pos]['name']	= $row['username']; -			$msg_list_ary[$row['template']][$pos]['lang']	= $row['user_lang']; -			$msg_list_ary[$row['template']][$pos]['user_id']= $row['user_id']; -		} -		unset($msg_users); - -		foreach ($msg_list_ary as $email_template => $email_list) -		{ -			foreach ($email_list as $addr) -			{ -				$messenger->template($email_template, $addr['lang']); - -				$messenger->to($addr['email'], $addr['name']); -				$messenger->im($addr['jabber'], $addr['name']); - -				$messenger->assign_vars(array( -					'USERNAME'		=> htmlspecialchars_decode($addr['name']), -					'TOPIC_TITLE'	=> htmlspecialchars_decode($topic_title), -					'FORUM_NAME'	=> htmlspecialchars_decode($forum_name), -					'AUTHOR_NAME'	=> htmlspecialchars_decode($author_name), - -					'U_FORUM'				=> generate_board_url() . "/viewforum.$phpEx?f=$forum_id", -					'U_TOPIC'				=> generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&t=$topic_id", -					'U_NEWEST_POST'			=> generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&t=$topic_id&p=$post_id&e=$post_id", -					'U_STOP_WATCHING_TOPIC'	=> generate_board_url() . "/viewtopic.$phpEx?uid={$addr['user_id']}&f=$forum_id&t=$topic_id&unwatch=topic", -					'U_STOP_WATCHING_FORUM'	=> generate_board_url() . "/viewforum.$phpEx?uid={$addr['user_id']}&f=$forum_id&unwatch=forum", -				)); - -				$messenger->send($addr['method']); -			} -		} -		unset($msg_list_ary); - -		$messenger->save_queue(); -	} - -	// Handle the DB updates -	$db->sql_transaction('begin'); - -	if (!empty($update_notification['topic'])) -	{ -		$sql = 'UPDATE ' . TOPICS_WATCH_TABLE . ' -			SET notify_status = ' . NOTIFY_NO . " -			WHERE topic_id = $topic_id -				AND " . $db->sql_in_set('user_id', $update_notification['topic']); -		$db->sql_query($sql); -	} - -	if (!empty($update_notification['forum'])) -	{ -		$sql = 'UPDATE ' . FORUMS_WATCH_TABLE . ' -			SET notify_status = ' . NOTIFY_NO . " -			WHERE forum_id = $forum_id -				AND " . $db->sql_in_set('user_id', $update_notification['forum']); -		$db->sql_query($sql); -	} - -	// Now delete the user_ids not authorised to receive notifications on this topic/forum -	if (!empty($delete_ids['topic'])) -	{ -		$sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . " -			WHERE topic_id = $topic_id -				AND " . $db->sql_in_set('user_id', $delete_ids['topic']); -		$db->sql_query($sql); -	} - -	if (!empty($delete_ids['forum'])) -	{ -		$sql = 'DELETE FROM ' . FORUMS_WATCH_TABLE . " -			WHERE forum_id = $forum_id -				AND " . $db->sql_in_set('user_id', $delete_ids['forum']); -		$db->sql_query($sql); -	} - -	$db->sql_transaction('commit'); -} -  //  // Post handling functions  // @@ -1482,11 +1259,8 @@ function delete_post($forum_id, $topic_id, $post_id, &$data)  			delete_topics('topic_id', array($topic_id), false); -			if ($data['topic_type'] != POST_GLOBAL) -			{ -				$sql_data[FORUMS_TABLE] .= 'forum_topics_real = forum_topics_real - 1'; -				$sql_data[FORUMS_TABLE] .= ($data['topic_approved']) ? ', forum_posts = forum_posts - 1, forum_topics = forum_topics - 1' : ''; -			} +			$sql_data[FORUMS_TABLE] .= 'forum_topics_real = forum_topics_real - 1'; +			$sql_data[FORUMS_TABLE] .= ($data['topic_approved']) ? ', forum_posts = forum_posts - 1, forum_topics = forum_topics - 1' : '';  			$update_sql = update_post_information('forum', $forum_id, true);  			if (sizeof($update_sql)) @@ -1506,10 +1280,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data)  			$row = $db->sql_fetchrow($result);  			$db->sql_freeresult($result); -			if ($data['topic_type'] != POST_GLOBAL) -			{ -				$sql_data[FORUMS_TABLE] = ($data['post_approved']) ? 'forum_posts = forum_posts - 1' : ''; -			} +			$sql_data[FORUMS_TABLE] = ($data['post_approved']) ? 'forum_posts = forum_posts - 1' : '';  			$sql_data[TOPICS_TABLE] = 'topic_poster = ' . intval($row['poster_id']) . ', topic_first_post_id = ' . intval($row['post_id']) . ", topic_first_poster_colour = '" . $db->sql_escape($row['user_colour']) . "', topic_first_poster_name = '" . (($row['poster_id'] == ANONYMOUS) ? $db->sql_escape($row['post_username']) : $db->sql_escape($row['username'])) . "', topic_time = " . (int) $row['post_time']; @@ -1520,10 +1291,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data)  		break;  		case 'delete_last_post': -			if ($data['topic_type'] != POST_GLOBAL) -			{ -				$sql_data[FORUMS_TABLE] = ($data['post_approved']) ? 'forum_posts = forum_posts - 1' : ''; -			} +			$sql_data[FORUMS_TABLE] = ($data['post_approved']) ? 'forum_posts = forum_posts - 1' : '';  			$update_sql = update_post_information('forum', $forum_id, true);  			if (sizeof($update_sql)) @@ -1565,10 +1333,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data)  			$row = $db->sql_fetchrow($result);  			$db->sql_freeresult($result); -			if ($data['topic_type'] != POST_GLOBAL) -			{ -				$sql_data[FORUMS_TABLE] = ($data['post_approved']) ? 'forum_posts = forum_posts - 1' : ''; -			} +			$sql_data[FORUMS_TABLE] = ($data['post_approved']) ? 'forum_posts = forum_posts - 1' : '';  			$sql_data[TOPICS_TABLE] = 'topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : '');  			$next_post_id = (int) $row['post_id']; @@ -1645,7 +1410,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data)  */  function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $update_message = true, $update_search_index = true)  { -	global $db, $auth, $user, $config, $phpEx, $template, $phpbb_root_path; +	global $db, $auth, $user, $config, $phpEx, $template, $phpbb_root_path, $phpbb_container;  	// We do not handle erasing posts here  	if ($mode == 'delete') @@ -1672,8 +1437,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u  	// First of all make sure the subject and topic title are having the correct length.  	// To achieve this without cutting off between special chars we convert to an array and then count the elements. -	$subject = truncate_string($subject); -	$data['topic_title'] = truncate_string($data['topic_title']); +	$subject = truncate_string($subject, 120); +	$data['topic_title'] = truncate_string($data['topic_title'], 120);  	// Collect some basic information about which tables and which rows to update/insert  	$sql_data = $topic_row = array(); @@ -1721,7 +1486,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u  		case 'post':  		case 'reply':  			$sql_data[POSTS_TABLE]['sql'] = array( -				'forum_id'			=> ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id'], +				'forum_id'			=> $data['forum_id'],  				'poster_id'			=> (int) $user->data['user_id'],  				'icon_id'			=> $data['icon_id'],  				'poster_ip'			=> $user->ip, @@ -1789,7 +1554,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u  			}  			$sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array( -				'forum_id'			=> ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id'], +				'forum_id'			=> $data['forum_id'],  				'poster_id'			=> $data['poster_id'],  				'icon_id'			=> $data['icon_id'],  				'post_approved'		=> (!$post_approval) ? 0 : $data['post_approved'], @@ -1825,7 +1590,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u  				'topic_poster'				=> (int) $user->data['user_id'],  				'topic_time'				=> $current_time,  				'topic_last_view_time'		=> $current_time, -				'forum_id'					=> ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id'], +				'forum_id'					=> $data['forum_id'],  				'icon_id'					=> $data['icon_id'],  				'topic_approved'			=> $post_approval,  				'topic_title'				=> $subject, @@ -1861,14 +1626,11 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u  			$sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . (($auth->acl_get('f_postcount', $data['forum_id']) && $post_approval) ? ', user_posts = user_posts + 1' : ''); -			if ($topic_type != POST_GLOBAL) +			if ($post_approval)  			{ -				if ($post_approval) -				{ -					$sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1'; -				} -				$sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real + 1' . (($post_approval) ? ', forum_topics = forum_topics + 1' : ''); +				$sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1';  			} +			$sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real + 1' . (($post_approval) ? ', forum_topics = forum_topics + 1' : '');  		break;  		case 'reply': @@ -1881,7 +1643,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u  			$sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . (($auth->acl_get('f_postcount', $data['forum_id']) && $post_approval) ? ', user_posts = user_posts + 1' : ''); -			if ($post_approval && $topic_type != POST_GLOBAL) +			if ($post_approval)  			{  				$sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1';  			} @@ -1905,7 +1667,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u  			}  			$sql_data[TOPICS_TABLE]['sql'] = array( -				'forum_id'					=> ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id'], +				'forum_id'					=> $data['forum_id'],  				'icon_id'					=> $data['icon_id'],  				'topic_approved'			=> (!$post_approval) ? 0 : $data['topic_approved'],  				'topic_title'				=> $subject, @@ -2020,61 +1782,6 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u  		unset($sql_data[POSTS_TABLE]['sql']);  	} -	$make_global = false; - -	// Are we globalising or unglobalising? -	if ($post_mode == 'edit_first_post' || $post_mode == 'edit_topic') -	{ -		if (!sizeof($topic_row)) -		{ -			$sql = 'SELECT topic_type, topic_replies, topic_replies_real, topic_approved, topic_last_post_id -				FROM ' . TOPICS_TABLE . ' -				WHERE topic_id = ' . $data['topic_id']; -			$result = $db->sql_query($sql); -			$topic_row = $db->sql_fetchrow($result); -			$db->sql_freeresult($result); -		} - -		// globalise/unglobalise? -		if (($topic_row['topic_type'] != POST_GLOBAL && $topic_type == POST_GLOBAL) || ($topic_row['topic_type'] == POST_GLOBAL && $topic_type != POST_GLOBAL)) -		{ -			if (!empty($sql_data[FORUMS_TABLE]['stat']) && implode('', $sql_data[FORUMS_TABLE]['stat'])) -			{ -				$db->sql_query('UPDATE ' . FORUMS_TABLE . ' SET ' . implode(', ', $sql_data[FORUMS_TABLE]['stat']) . ' WHERE forum_id = ' . $data['forum_id']); -			} - -			$make_global = true; -			$sql_data[FORUMS_TABLE]['stat'] = array(); -		} - -		// globalise -		if ($topic_row['topic_type'] != POST_GLOBAL && $topic_type == POST_GLOBAL) -		{ -			// Decrement topic/post count -			$sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - ' . ($topic_row['topic_replies_real'] + 1); -			$sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real - 1' . (($topic_row['topic_approved']) ? ', forum_topics = forum_topics - 1' : ''); - -			// Update forum_ids for all posts -			$sql = 'UPDATE ' . POSTS_TABLE . ' -				SET forum_id = 0 -				WHERE topic_id = ' . $data['topic_id']; -			$db->sql_query($sql); -		} -		// unglobalise -		else if ($topic_row['topic_type'] == POST_GLOBAL && $topic_type != POST_GLOBAL) -		{ -			// Increment topic/post count -			$sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + ' . ($topic_row['topic_replies_real'] + 1); -			$sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real + 1' . (($topic_row['topic_approved']) ? ', forum_topics = forum_topics + 1' : ''); - -			// Update forum_ids for all posts -			$sql = 'UPDATE ' . POSTS_TABLE . ' -				SET forum_id = ' . $data['forum_id'] . ' -				WHERE topic_id = ' . $data['topic_id']; -			$db->sql_query($sql); -		} -	} -  	// Update the topics table  	if (isset($sql_data[TOPICS_TABLE]['sql']))  	{ @@ -2237,9 +1944,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u  	}  	// we need to update the last forum information -	// only applicable if the topic is not global and it is approved -	// we also check to make sure we are not dealing with globaling the latest topic (pretty rare but still needs to be checked) -	if ($topic_type != POST_GLOBAL && !$make_global && ($post_approved || !$data['post_approved'])) +	// only applicable if the topic is approved +	if ($post_approved || !$data['post_approved'])  	{  		// the last post makes us update the forum table. This can happen if...  		// We make a new topic @@ -2329,78 +2035,6 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u  			}  		}  	} -	else if ($make_global) -	{ -		// somebody decided to be a party pooper, we must recalculate the whole shebang (maybe) -		$sql = 'SELECT forum_last_post_id -			FROM ' . FORUMS_TABLE . ' -			WHERE forum_id = ' . (int) $data['forum_id']; -		$result = $db->sql_query($sql); -		$forum_row = $db->sql_fetchrow($result); -		$db->sql_freeresult($result); - -		// we made a topic global, go get new data -		if ($topic_row['topic_type'] != POST_GLOBAL && $topic_type == POST_GLOBAL && $forum_row['forum_last_post_id'] == $topic_row['topic_last_post_id']) -		{ -			// we need a fresh change of socks, everything has become invalidated -			$sql = 'SELECT MAX(topic_last_post_id) as last_post_id -				FROM ' . TOPICS_TABLE . ' -				WHERE forum_id = ' . (int) $data['forum_id'] . ' -					AND topic_approved = 1'; -			$result = $db->sql_query($sql); -			$row = $db->sql_fetchrow($result); -			$db->sql_freeresult($result); - -			// any posts left in this forum? -			if (!empty($row['last_post_id'])) -			{ -				$sql = 'SELECT p.post_id, p.post_subject, p.post_time, p.poster_id, p.post_username, u.user_id, u.username, u.user_colour -					FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u -					WHERE p.poster_id = u.user_id -						AND p.post_id = ' . (int) $row['last_post_id']; -				$result = $db->sql_query($sql); -				$row = $db->sql_fetchrow($result); -				$db->sql_freeresult($result); - -				// salvation, a post is found! jam it into the forums table -				$sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = ' . (int) $row['post_id']; -				$sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = '" . $db->sql_escape($row['post_subject']) . "'"; -				$sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = ' . (int) $row['post_time']; -				$sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = ' . (int) $row['poster_id']; -				$sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape(($row['poster_id'] == ANONYMOUS) ? $row['post_username'] : $row['username']) . "'"; -				$sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_colour = '" . $db->sql_escape($row['user_colour']) . "'"; -			} -			else -			{ -				// just our luck, the last topic in the forum has just been globalized... -				$sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = 0'; -				$sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = ''"; -				$sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = 0'; -				$sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = 0'; -				$sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = ''"; -				$sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_colour = ''"; -			} -		} -		else if ($topic_row['topic_type'] == POST_GLOBAL && $topic_type != POST_GLOBAL && $forum_row['forum_last_post_id'] < $topic_row['topic_last_post_id']) -		{ -			// this post has a higher id, it is newer -			$sql = 'SELECT p.post_id, p.post_subject, p.post_time, p.poster_id, p.post_username, u.user_id, u.username, u.user_colour -				FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u -				WHERE p.poster_id = u.user_id -					AND p.post_id = ' . (int) $topic_row['topic_last_post_id']; -			$result = $db->sql_query($sql); -			$row = $db->sql_fetchrow($result); -			$db->sql_freeresult($result); - -			// salvation, a post is found! jam it into the forums table -			$sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = ' . (int) $row['post_id']; -			$sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = '" . $db->sql_escape($row['post_subject']) . "'"; -			$sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = ' . (int) $row['post_time']; -			$sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = ' . (int) $row['poster_id']; -			$sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape(($row['poster_id'] == ANONYMOUS) ? $row['post_username'] : $row['username']) . "'"; -			$sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_colour = '" . $db->sql_escape($row['user_colour']) . "'"; -		} -	}  	// topic sync time!  	// simply, we update if it is a reply or the last post is edited @@ -2488,7 +2122,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u  	}  	// Delete topic shadows (if any exist). We do not need a shadow topic for an global announcement -	if ($make_global) +	if ($topic_type == POST_GLOBAL)  	{  		$sql = 'DELETE FROM ' . TOPICS_TABLE . '  			WHERE topic_moved_id = ' . $data['topic_id']; @@ -2512,27 +2146,22 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u  	if ($update_search_index && $data['enable_indexing'])  	{  		// Select the search method and do some additional checks to ensure it can actually be utilised -		$search_type = basename($config['search_type']); - -		if (!file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx)) -		{ -			trigger_error('NO_SUCH_SEARCH_MODULE'); -		} +		$search_type = $config['search_type'];  		if (!class_exists($search_type))  		{ -			include("{$phpbb_root_path}includes/search/$search_type.$phpEx"); +			trigger_error('NO_SUCH_SEARCH_MODULE');  		}  		$error = false; -		$search = new $search_type($error); +		$search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user);  		if ($error)  		{  			trigger_error($error);  		} -		$search->index($mode, $data['post_id'], $data['message'], $subject, $poster_id, ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id']); +		$search->index($mode, $data['post_id'], $data['message'], $subject, $poster_id, $data['forum_id']);  	}  	// Topic Notification, do not change if moderator is changing other users posts... @@ -2561,7 +2190,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u  	// Mark this topic as read  	// We do not use post_time here, this is intended (post_time can have a date in the past if editing a message) -	markread('topic', (($topic_type == POST_GLOBAL) ? 0 : $data['forum_id']), $data['topic_id'], time()); +	markread('topic', $data['forum_id'], $data['topic_id'], time());  	//  	if ($config['load_db_lastread'] && $user->data['is_registered']) @@ -2569,7 +2198,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u  		$sql = 'SELECT mark_time  			FROM ' . FORUMS_TRACK_TABLE . '  			WHERE user_id = ' . $user->data['user_id'] . ' -				AND forum_id = ' . (($topic_type == POST_GLOBAL) ? 0 : $data['forum_id']); +				AND forum_id = ' . $data['forum_id'];  		$result = $db->sql_query($sql);  		$f_mark_time = (int) $db->sql_fetchfield('mark_time');  		$db->sql_freeresult($result); @@ -2582,30 +2211,87 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u  	if (($config['load_db_lastread'] && $user->data['is_registered']) || $config['load_anon_lastread'] || $user->data['is_registered'])  	{  		// Update forum info -		if ($topic_type == POST_GLOBAL) -		{ -			$sql = 'SELECT MAX(topic_last_post_time) as forum_last_post_time -				FROM ' . TOPICS_TABLE . ' -				WHERE forum_id = 0'; -		} -		else -		{ -			$sql = 'SELECT forum_last_post_time -				FROM ' . FORUMS_TABLE . ' -				WHERE forum_id = ' . $data['forum_id']; -		} +		$sql = 'SELECT forum_last_post_time +			FROM ' . FORUMS_TABLE . ' +			WHERE forum_id = ' . $data['forum_id'];  		$result = $db->sql_query($sql);  		$forum_last_post_time = (int) $db->sql_fetchfield('forum_last_post_time');  		$db->sql_freeresult($result); -		update_forum_tracking_info((($topic_type == POST_GLOBAL) ? 0 : $data['forum_id']), $forum_last_post_time, $f_mark_time, false); +		update_forum_tracking_info($data['forum_id'], $forum_last_post_time, $f_mark_time, false);  	}  	// Send Notifications -	if (($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $post_approval) +	$notification_data = array_merge($data, array( +		'topic_title'		=> (isset($data['topic_title'])) ? $data['topic_title'] : $subject, +		'post_username'		=> $username, +		'poster_id'			=> $poster_id, +		'post_text'			=> $data['message'], +		'post_time'			=> $current_time, +		'post_subject'		=> $subject, +	)); + +	$phpbb_notifications = $phpbb_container->get('notification_manager'); + +	if ($post_approval)  	{ -		$username = ($username) ? $username : $user->data['username']; -		user_notification($mode, $subject, $data['topic_title'], $data['forum_name'], $data['forum_id'], $data['topic_id'], $data['post_id'], $username); +		switch ($mode) +		{ +			case 'post': +				$phpbb_notifications->add_notifications(array( +					'quote', +					'topic', +				), $notification_data); +			break; + +			case 'reply': +			case 'quote': +				$phpbb_notifications->add_notifications(array( +					'quote', +					'bookmark', +					'post', +				), $notification_data); +			break; + +			case 'edit_topic': +			case 'edit_first_post': +			case 'edit': +			case 'edit_last_post': +				$phpbb_notifications->update_notifications(array( +					'quote', +					'bookmark', +					'topic', +					'post', +				), $notification_data); +			break; +		} +	} +	else +	{ +		switch ($mode) +		{ +			case 'post': +				$phpbb_notifications->add_notifications('topic_in_queue', $notification_data); +			break; + +			case 'reply': +			case 'quote': +				$phpbb_notifications->add_notifications('post_in_queue', $notification_data); +			break; + +			case 'edit_topic': +			case 'edit_first_post': +			case 'edit': +			case 'edit_last_post': +				$phpbb_notifications->delete_notifications('topic', $data['topic_id']); + +				$phpbb_notifications->delete_notifications(array( +					'quote', +					'bookmark', +					'post', +				), $data['post_id']); +			break; +		}  	}  	$params = $add_anchor = ''; @@ -2732,5 +2418,3 @@ function phpbb_bump_topic($forum_id, $topic_id, $post_data, $bump_time = false)  	return $url;  } - -?>
\ No newline at end of file | 
