phpBB

Code Changes

File: includes/functions_posting.php

  Unmodified   Added   Modified   Removed
Line 23Line 23
{
global $auth, $db, $user, $config, $template;
global $phpEx, $phpbb_root_path;

{
global $auth, $db, $user, $config, $template;
global $phpEx, $phpbb_root_path;

 

$start = request_var('start', 0);


if ($mode == 'window')
{


if ($mode == 'window')
{

Line 43Line 45
		}

page_header($user->lang['SMILIES']);

		}

page_header($user->lang['SMILIES']);

 

$sql = 'SELECT COUNT(smiley_id) AS item_count
FROM ' . SMILIES_TABLE . '
GROUP BY smiley_url';
$result = $db->sql_query($sql, 3600);

$smiley_count = 0;
while ($row = $db->sql_fetchrow($result))
{
++$smiley_count;
}
$db->sql_freeresult($result);


$template->set_filenames(array(
'body' => 'posting_smilies.html')


$template->set_filenames(array(
'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)

		);
}


		);
}


Line 64Line 83
		$db->sql_freeresult($result);
}


		$db->sql_freeresult($result);
}


	$last_url = '';










	if ($mode == 'window')
{
$sql = 'SELECT smiley_url, MIN(emotion) as emotion, MIN(code) AS code, smiley_width, smiley_height, MIN(smiley_order) AS min_smiley_order
FROM ' . SMILIES_TABLE . '
GROUP BY smiley_url, smiley_width, smiley_height
ORDER BY min_smiley_order';
$result = $db->sql_query_limit($sql, $config['smilies_per_page'], $start, 3600);
}
else
{

	$sql = 'SELECT *

	$sql = 'SELECT *

		FROM ' . SMILIES_TABLE .
(($mode == 'inline') ? ' WHERE display_on_posting = 1 ' : '') . '

			FROM ' . SMILIES_TABLE . '
WHERE display_on_posting = 1

		ORDER BY smiley_order';
$result = $db->sql_query($sql, 3600);

		ORDER BY smiley_order';
$result = $db->sql_query($sql, 3600);

 
	}


$smilies = array();
while ($row = $db->sql_fetchrow($result))


$smilies = array();
while ($row = $db->sql_fetchrow($result))

Line 84Line 112

if (sizeof($smilies))
{


if (sizeof($smilies))
{

 
		$root_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? generate_board_url() . '/' : $phpbb_root_path;


		foreach ($smilies as $row)
{
$template->assign_block_vars('smiley', array(
'SMILEY_CODE' => $row['code'],
'A_SMILEY_CODE' => addslashes($row['code']),

		foreach ($smilies as $row)
{
$template->assign_block_vars('smiley', array(
'SMILEY_CODE' => $row['code'],
'A_SMILEY_CODE' => addslashes($row['code']),

				'SMILEY_IMG'	=> $phpbb_root_path . $config['smilies_path'] . '/' . $row['smiley_url'],

				'SMILEY_IMG'	=> $root_path . $config['smilies_path'] . '/' . $row['smiley_url'],

				'SMILEY_WIDTH'	=> $row['smiley_width'],
'SMILEY_HEIGHT' => $row['smiley_height'],
'SMILEY_DESC' => $row['emotion'])

				'SMILEY_WIDTH'	=> $row['smiley_width'],
'SMILEY_HEIGHT' => $row['smiley_height'],
'SMILEY_DESC' => $row['emotion'])

Line 258Line 288

if (sizeof($icons))
{


if (sizeof($icons))
{

 
		$root_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? generate_board_url() . '/' : $phpbb_root_path;


		foreach ($icons as $id => $data)
{
if ($data['display'])
{
$template->assign_block_vars('topic_icon', array(
'ICON_ID' => $id,

		foreach ($icons as $id => $data)
{
if ($data['display'])
{
$template->assign_block_vars('topic_icon', array(
'ICON_ID' => $id,

					'ICON_IMG'		=> $phpbb_root_path . $config['icons_path'] . '/' . $data['img'],

					'ICON_IMG'		=> $root_path . $config['icons_path'] . '/' . $data['img'],

					'ICON_WIDTH'	=> $data['width'],
'ICON_HEIGHT' => $data['height'],


					'ICON_WIDTH'	=> $data['width'],
'ICON_HEIGHT' => $data['height'],


Line 318Line 350
	{
$topic_type_array = array_merge(array(0 => array(
'VALUE' => POST_NORMAL,

	{
$topic_type_array = array_merge(array(0 => array(
'VALUE' => POST_NORMAL,

			'S_CHECKED'		=> ($topic_type == POST_NORMAL) ? ' checked="checked"' : '',

			'S_CHECKED'		=> ($cur_topic_type == POST_NORMAL) ? ' checked="checked"' : '',

			'L_TOPIC_TYPE'	=> $user->lang['POST_NORMAL'])),

$topic_type_array

			'L_TOPIC_TYPE'	=> $user->lang['POST_NORMAL'])),

$topic_type_array

Line 357Line 389

include_once($phpbb_root_path . 'includes/functions_upload.' . $phpEx);
$upload = new fileupload();


include_once($phpbb_root_path . 'includes/functions_upload.' . $phpEx);
$upload = new fileupload();

 

if ($config['check_attachment_content'] && isset($config['mime_triggers']))
{
$upload->set_disallowed_content(explode('|', $config['mime_triggers']));
}
else if (!$config['check_attachment_content'])
{
$upload->set_disallowed_content(array());
}


if (!$local)
{


if (!$local)
{

Line 385Line 426
	}

$cat_id = (isset($extensions[$file->get('extension')]['display_cat'])) ? $extensions[$file->get('extension')]['display_cat'] : ATTACHMENT_CATEGORY_NONE;

	}

$cat_id = (isset($extensions[$file->get('extension')]['display_cat'])) ? $extensions[$file->get('extension')]['display_cat'] : ATTACHMENT_CATEGORY_NONE;


// Make sure the image category only holds valid images...
if ($cat_id == ATTACHMENT_CATEGORY_IMAGE && !$file->is_image())
{
$file->remove();

// If this error occurs a user tried to exploit an IE Bug by renaming extensions
// Since the image category is displaying content inline we need to catch this.
trigger_error($user->lang['ATTACHED_IMAGE_NOT_IMAGE']);
}

 

// Do we have to create a thumbnail?
$filedata['thumbnail'] = ($cat_id == ATTACHMENT_CATEGORY_IMAGE && $config['img_create_thumbnail']) ? 1 : 0;


// Do we have to create a thumbnail?
$filedata['thumbnail'] = ($cat_id == ATTACHMENT_CATEGORY_IMAGE && $config['img_create_thumbnail']) ? 1 : 0;

Line 434Line 465
		$filedata['post_attach'] = false;

return $filedata;

		$filedata['post_attach'] = false;

return $filedata;

 
	}

// Make sure the image category only holds valid images...
if ($cat_id == ATTACHMENT_CATEGORY_IMAGE && !$file->is_image())
{
$file->remove();

// If this error occurs a user tried to exploit an IE Bug by renaming extensions
// Since the image category is displaying content inline we need to catch this.
trigger_error($user->lang['ATTACHED_IMAGE_NOT_IMAGE']);

	}

$filedata['filesize'] = $file->get('filesize');

	}

$filedata['filesize'] = $file->get('filesize');

Line 461Line 502
	if ($free_space = @disk_free_space($phpbb_root_path . $config['upload_path']))
{
if ($free_space <= $file->get('filesize'))

	if ($free_space = @disk_free_space($phpbb_root_path . $config['upload_path']))
{
if ($free_space <= $file->get('filesize'))

 
		{
if ($auth->acl_get('a_'))
{
$filedata['error'][] = $user->lang['ATTACH_DISK_FULL'];
}
else

		{
$filedata['error'][] = $user->lang['ATTACH_QUOTA_REACHED'];

		{
$filedata['error'][] = $user->lang['ATTACH_QUOTA_REACHED'];

 
			}

			$filedata['post_attach'] = false;

$file->remove();

			$filedata['post_attach'] = false;

$file->remove();

Line 524Line 572

if ($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

			switch ($type)
{
// GIF

Line 545Line 595
					$new_type = ($format & IMG_PNG) ? IMG_PNG : false;
break;


					$new_type = ($format & IMG_PNG) ? IMG_PNG : false;
break;


				// BMP, WBMP
case 6:

				// WBMP


				case 15:
$new_type = ($format & IMG_WBMP) ? IMG_WBMP : false;
break;

				case 15:
$new_type = ($format & IMG_WBMP) ? IMG_WBMP : false;
break;

Line 608Line 657
	list($new_width, $new_height) = get_img_size_format($width, $height);

// Do not create a thumbnail if the resulting width/height is bigger than the original one

	list($new_width, $new_height) = get_img_size_format($width, $height);

// Do not create a thumbnail if the resulting width/height is bigger than the original one

	if ($new_width > $width && $new_height > $height)

	if ($new_width >= $width && $new_height >= $height)

	{
return false;
}

	{
return false;
}

Line 618Line 667
	// Only use imagemagick if defined and the passthru function not disabled
if ($config['img_imagick'] && function_exists('passthru'))
{

	// Only use imagemagick if defined and the passthru function not disabled
if ($config['img_imagick'] && function_exists('passthru'))
{

		@passthru(escapeshellcmd($config['img_imagick']) . 'convert' . ((defined('PHP_OS') && preg_match('#^win#i', PHP_OS)) ? '.exe' : '') . ' -quality 85 -antialias -sample ' . $new_width . 'x' . $new_height . ' "' . str_replace('\\', '/', $source) . '" +profile "*" "' . str_replace('\\', '/', $destination) . '"');






		if (substr($config['img_imagick'], -1) !== '/')
{
$config['img_imagick'] .= '/';
}

@passthru(escapeshellcmd($config['img_imagick']) . 'convert' . ((defined('PHP_OS') && preg_match('#^win#i', PHP_OS)) ? '.exe' : '') . ' -quality 85 -geometry ' . $new_width . 'x' . $new_height . ' "' . str_replace('\\', '/', $source) . '" "' . str_replace('\\', '/', $destination) . '"');


if (file_exists($destination))
{


if (file_exists($destination))
{

Line 645Line 699
				break;

case IMG_JPG:

				break;

case IMG_JPG:

 
					@ini_set('gd.jpeg_ignore_warning', 1);

					$image = @imagecreatefromjpeg($source);
break;


					$image = @imagecreatefromjpeg($source);
break;


Line 655Line 710
				case IMG_WBMP:
$image = @imagecreatefromwbmp($source);
break;

				case IMG_WBMP:
$image = @imagecreatefromwbmp($source);
break;

 
			}

if (empty($image))
{
return false;

			}

if ($type['version'] == 1)

			}

if ($type['version'] == 1)

Line 676Line 736
				{
return false;
}

				{
return false;
}

 

// Preserve alpha transparency (png for example)
@imagealphablending($new_image, false);
@imagesavealpha($new_image, true);


imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
}


imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
}

Line 718Line 782
		return false;
}


		return false;
}


	@chmod($destination, 0666);

	phpbb_chmod($destination, CHMOD_READ | CHMOD_WRITE);


return true;
}


return true;
}

Line 736Line 800

foreach ($attachment_data as $i => $attachment)
{


foreach ($attachment_data as $i => $attachment)
{

			$s_inline_attachment_options .= '<option value="' . $i . '">' . basename($attachment['real_filename']) . '</option>';

			$s_inline_attachment_options .= '<option value="' . $i . '">' . utf8_basename($attachment['real_filename']) . '</option>';

		}

$template->assign_var('S_INLINE_ATTACHMENT_OPTIONS', $s_inline_attachment_options);

		}

$template->assign_var('S_INLINE_ATTACHMENT_OPTIONS', $s_inline_attachment_options);

Line 750Line 814
/**
* Generate inline attachment entry
*/

/**
* Generate inline attachment entry
*/

function posting_gen_attachment_entry($attachment_data, &$filename_data)

function posting_gen_attachment_entry($attachment_data, &$filename_data, $show_attach_box = true)

{

{

	global $template, $config, $phpbb_root_path, $phpEx, $user;

	global $template, $config, $phpbb_root_path, $phpEx, $user, $auth;





 
	// Some default template variables

	$template->assign_vars(array(

	$template->assign_vars(array(

		'S_SHOW_ATTACH_BOX'	=> true)
);




		'S_SHOW_ATTACH_BOX'	=> $show_attach_box,
'S_HAS_ATTACHMENTS' => sizeof($attachment_data),
'FILESIZE' => $config['max_filesize'],
'FILE_COMMENT' => (isset($filename_data['filecomment'])) ? $filename_data['filecomment'] : '',
));


if (sizeof($attachment_data))
{


if (sizeof($attachment_data))
{

		$template->assign_vars(array(
'S_HAS_ATTACHMENTS' => true)
);


 
		// We display the posted attachments within the desired order.
($config['display_order']) ? krsort($attachment_data) : ksort($attachment_data);

foreach ($attachment_data as $count => $attach_row)
{
$hidden = '';

		// We display the posted attachments within the desired order.
($config['display_order']) ? krsort($attachment_data) : ksort($attachment_data);

foreach ($attachment_data as $count => $attach_row)
{
$hidden = '';

			$attach_row['real_filename'] = basename($attach_row['real_filename']);

			$attach_row['real_filename'] = utf8_basename($attach_row['real_filename']);


foreach ($attach_row as $key => $value)
{


foreach ($attach_row as $key => $value)
{

Line 780Line 844
			$download_link = append_sid("{$phpbb_root_path}download/file.$phpEx", 'mode=view&amp;id=' . (int) $attach_row['attach_id'], true, ($attach_row['is_orphan']) ? $user->session_id : false);

$template->assign_block_vars('attach_row', array(

			$download_link = append_sid("{$phpbb_root_path}download/file.$phpEx", 'mode=view&amp;id=' . (int) $attach_row['attach_id'], true, ($attach_row['is_orphan']) ? $user->session_id : false);

$template->assign_block_vars('attach_row', array(

				'FILENAME'			=> basename($attach_row['real_filename']),
'A_FILENAME' => addslashes(basename($attach_row['real_filename'])),

				'FILENAME'			=> utf8_basename($attach_row['real_filename']),
'A_FILENAME' => addslashes(utf8_basename($attach_row['real_filename'])),

				'FILE_COMMENT'		=> $attach_row['attach_comment'],
'ATTACH_ID' => $attach_row['attach_id'],
'S_IS_ORPHAN' => $attach_row['is_orphan'],

				'FILE_COMMENT'		=> $attach_row['attach_comment'],
'ATTACH_ID' => $attach_row['attach_id'],
'S_IS_ORPHAN' => $attach_row['is_orphan'],

Line 792Line 856
			);
}
}

			);
}
}


$template->assign_vars(array(
'FILE_COMMENT' => $filename_data['filecomment'],
'FILESIZE' => $config['max_filesize'])
);

 

return sizeof($attachment_data);
}


return sizeof($attachment_data);
}

Line 808Line 867
/**
* Load Drafts
*/

/**
* Load Drafts
*/

function load_drafts($topic_id = 0, $forum_id = 0, $id = 0)

function load_drafts($topic_id = 0, $forum_id = 0, $id = 0, $pm_action = '', $msg_id = 0)

{
global $user, $db, $template, $auth;
global $phpbb_root_path, $phpEx;

{
global $user, $db, $template, $auth;
global $phpbb_root_path, $phpEx;

Line 901Line 960
		{
// Either display as PM draft if forum_id and topic_id are empty or if access to the forums has been denied afterwards...
$link_pm = true;

		{
// Either display as PM draft if forum_id and topic_id are empty or if access to the forums has been denied afterwards...
$link_pm = true;

			$insert_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&amp;mode=compose&amp;d={$draft['draft_id']}");

			$insert_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&amp;mode=compose&amp;d={$draft['draft_id']}" . (($pm_action) ? "&amp;action=$pm_action" : '') . (($msg_id) ? "&amp;p=$msg_id" : ''));

		}

$template->assign_block_vars('draftrow', array(

		}

$template->assign_block_vars('draftrow', array(

Line 934Line 993
		WHERE p.topic_id = $topic_id
" . ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND p.post_approved = 1' : '') . '
' . (($mode == 'post_review') ? " AND p.post_id > $cur_post_id" : '') . '

		WHERE p.topic_id = $topic_id
" . ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND p.post_approved = 1' : '') . '
' . (($mode == 'post_review') ? " AND p.post_id > $cur_post_id" : '') . '

		ORDER BY p.post_time DESC';



			' . (($mode == 'post_review_edit') ? " AND p.post_id = $cur_post_id" : '') . '
ORDER BY p.post_time ';
$sql .= ($mode == 'post_review') ? 'ASC' : 'DESC';

	$result = $db->sql_query_limit($sql, $config['posts_per_page']);

$post_list = array();

	$result = $db->sql_query_limit($sql, $config['posts_per_page']);

$post_list = array();

Line 949Line 1010
	if (!sizeof($post_list))
{
return false;

	if (!sizeof($post_list))
{
return false;

 
	}

// Handle 'post_review_edit' like 'post_review' from now on
if ($mode == 'post_review_edit')
{
$mode = 'post_review';

	}

$sql = $db->sql_build_query('SELECT', array(

	}

$sql = $db->sql_build_query('SELECT', array(

		'SELECT'	=> 'u.username, u.user_id, u.user_colour, p.*',

		'SELECT'	=> 'u.username, u.user_id, u.user_colour, p.*, z.friend, z.foe',


'FROM' => array(
USERS_TABLE => 'u',
POSTS_TABLE => 'p',


'FROM' => array(
USERS_TABLE => 'u',
POSTS_TABLE => 'p',

 
		),

'LEFT_JOIN' => array(
array(
'FROM' => array(ZEBRA_TABLE => 'z'),
'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) . '

		),

'WHERE' => $db->sql_in_set('p.post_id', $post_list) . '

Line 1048Line 1122
		}

$post_subject = censor_text($post_subject);

		}

$post_subject = censor_text($post_subject);

 

$post_anchor = ($mode == 'post_review') ? 'ppr' . $row['post_id'] : 'pr' . $row['post_id'];
$u_show_post = append_sid($phpbb_root_path . 'viewtopic.' . $phpEx, "f=$forum_id&amp;t=$topic_id&amp;p={$row['post_id']}&amp;view=show#p{$row['post_id']}");


$template->assign_block_vars($mode . '_row', array(
'POST_AUTHOR_FULL' => get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),


$template->assign_block_vars($mode . '_row', array(
'POST_AUTHOR_FULL' => get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),

Line 1056Line 1133
			'U_POST_AUTHOR'			=> get_username_string('profile', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),

'S_HAS_ATTACHMENTS' => (!empty($attachments[$row['post_id']])) ? true : false,

			'U_POST_AUTHOR'			=> get_username_string('profile', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),

'S_HAS_ATTACHMENTS' => (!empty($attachments[$row['post_id']])) ? true : false,

 
			'S_FRIEND'			=> ($row['friend']) ? true : false,
'S_IGNORE_POST' => ($row['foe']) ? true : false,
'L_IGNORE_POST' => ($row['foe']) ? sprintf($user->lang['POST_BY_FOE'], get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']), "<a href=\"{$u_show_post}\" onclick=\"dE('{$post_anchor}', 1); return false;\">", '</a>') : '',


'POST_SUBJECT' => $post_subject,
'MINI_POST_IMG' => $user->img('icon_post_target', $user->lang['POST']),


'POST_SUBJECT' => $post_subject,
'MINI_POST_IMG' => $user->img('icon_post_target', $user->lang['POST']),

Line 1079Line 1159
			}
}


			}
}


		unset($rowset[$i]);

		unset($rowset[$post_list[$i]]);

	}

if ($mode == 'topic_review')

	}

if ($mode == 'topic_review')

Line 1093Line 1173
/**
* User Notification
*/

/**
* User Notification
*/

function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id, $topic_id, $post_id)

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;


{
global $db, $user, $config, $phpbb_root_path, $phpEx, $auth;


Line 1102Line 1182

if (!$topic_notification && !$forum_notification)
{


if (!$topic_notification && !$forum_notification)
{

		trigger_error('WRONG_NOTIFICATION_MODE');

		trigger_error('NO_MODE');

	}


	}


	if (!$config['allow_topic_notify'])

	if (($topic_notification && !$config['allow_topic_notify']) || ($forum_notification && !$config['allow_forum_notify']))

	{
return;
}

	{
return;
}

Line 1113Line 1193
	$topic_title = ($topic_notification) ? $topic_title : $subject;
$topic_title = censor_text($topic_title);


	$topic_title = ($topic_notification) ? $topic_title : $subject;
$topic_title = censor_text($topic_title);


	// Get banned User ID's
$sql = 'SELECT ban_userid
FROM ' . BANLIST_TABLE;
$result = $db->sql_query($sql);

$sql_ignore_users = ANONYMOUS . ', ' . $user->data['user_id'];
while ($row = $db->sql_fetchrow($result))

	// Exclude guests, current user and banned users from notifications
if (!function_exists('phpbb_get_banned_user_ids'))






	{

	{

		if (isset($row['ban_userid']))
{
$sql_ignore_users .= ', ' . $row['ban_userid'];

		include($phpbb_root_path . 'includes/functions_user.' . $phpEx);



		}

		}

	}
$db->sql_freeresult($result);


	$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


$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 w.user_id NOT IN ($sql_ignore_users)
AND w.notify_status = 0
AND u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')

		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))
{

			AND u.user_id = w.user_id';
$result = $db->sql_query($sql);

while ($row = $db->sql_fetchrow($result))
{

		$notify_rows[$row['user_id']] = array(
'user_id' => $row['user_id'],


		$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'],

			'username'		=> $row['username'],
'user_email' => $row['user_email'],
'user_jabber' => $row['user_jabber'],

Line 1153Line 1228
			'method'		=> $row['user_notify_type'],
'allowed' => false
);

			'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)
{

	}
$db->sql_freeresult($result);

// forum notification is sent to those not already receiving topic notifications
if ($topic_notification)
{

		if (sizeof($notify_rows))
{
$sql_ignore_users .= ', ' . implode(', ', array_keys($notify_rows));
}


 
		$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

		$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 fw.user_id NOT IN ($sql_ignore_users)
AND fw.notify_status = 0
AND u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')

				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))
{

				AND u.user_id = fw.user_id';
$result = $db->sql_query($sql);

while ($row = $db->sql_fetchrow($result))
{

			$notify_rows[$row['user_id']] = array(
'user_id' => $row['user_id'],


			$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'],

				'username'		=> $row['username'],
'user_email' => $row['user_email'],
'user_jabber' => $row['user_jabber'],

Line 1206Line 1280
			}
}
}

			}
}
}



 

// 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();


// 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();

Line 1220Line 1293
		{
$msg_users[] = $row;
$update_notification[$row['notify_type']][] = $row['user_id'];

		{
$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);

		}
}
unset($notify_rows);

Line 1240Line 1327
			$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]['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);


		}
unset($msg_users);


Line 1256Line 1344
					'USERNAME'		=> htmlspecialchars_decode($addr['name']),
'TOPIC_TITLE' => htmlspecialchars_decode($topic_title),
'FORUM_NAME' => htmlspecialchars_decode($forum_name),

					'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_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?f=$forum_id&t=$topic_id&unwatch=topic",
'U_STOP_WATCHING_FORUM' => generate_board_url() . "/viewforum.$phpEx?f=$forum_id&unwatch=forum",

					'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']);

				));

$messenger->send($addr['method']);

Line 1277Line 1366

if (!empty($update_notification['topic']))
{


if (!empty($update_notification['topic']))
{

		$sql = 'UPDATE ' . TOPICS_WATCH_TABLE . "
SET notify_status = 1

		$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);

			WHERE topic_id = $topic_id
AND " . $db->sql_in_set('user_id', $update_notification['topic']);
$db->sql_query($sql);

Line 1286Line 1375

if (!empty($update_notification['forum']))
{


if (!empty($update_notification['forum']))
{

		$sql = 'UPDATE ' . FORUMS_WATCH_TABLE . "
SET notify_status = 1

		$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);

			WHERE forum_id = $forum_id
AND " . $db->sql_in_set('user_id', $update_notification['forum']);
$db->sql_query($sql);

Line 1326Line 1415
	global $config, $phpEx, $phpbb_root_path;

// Specify our post mode

	global $config, $phpEx, $phpbb_root_path;

// Specify our post mode

	$post_mode = ($data['topic_first_post_id'] == $data['topic_last_post_id']) ? 'delete_topic' : (($data['topic_first_post_id'] == $post_id) ? 'delete_first_post' : (($data['topic_last_post_id'] == $post_id) ? 'delete_last_post' : 'delete'));













	$post_mode = 'delete';
if (($data['topic_first_post_id'] === $data['topic_last_post_id']) && $data['topic_replies_real'] == 0)
{
$post_mode = 'delete_topic';
}
else if ($data['topic_first_post_id'] == $post_id)
{
$post_mode = 'delete_first_post';
}
else if ($data['topic_last_post_id'] == $post_id)
{
$post_mode = 'delete_last_post';
}

	$sql_data = array();

	$sql_data = array();

	$next_post_id = 0;

	$next_post_id = false;


include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);



include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);


Line 1400Line 1501
		break;

case 'delete_first_post':

		break;

case 'delete_first_post':

			$sql = 'SELECT p.post_id, p.poster_id, p.post_username, u.username, u.user_colour

			$sql = 'SELECT p.post_id, p.poster_id, p.post_time, p.post_username, u.username, u.user_colour

				FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u
WHERE p.topic_id = $topic_id
AND p.poster_id = u.user_id

				FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u
WHERE p.topic_id = $topic_id
AND p.poster_id = u.user_id

Line 1414Line 1515
				$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_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'])) . "'";

			$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'];


// Decrementing topic_replies here is fine because this case only happens if there is more than one post within the topic - basically removing one "reply"
$sql_data[TOPICS_TABLE] .= ', topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : '');


// Decrementing topic_replies here is fine because this case only happens if there is more than one post within the topic - basically removing one "reply"
$sql_data[TOPICS_TABLE] .= ', topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : '');

Line 1476Line 1577
			$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'];
break;

			$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'];
break;

 
	}

if (($post_mode == 'delete') || ($post_mode == 'delete_last_post') || ($post_mode == 'delete_first_post'))
{
$sql = 'SELECT 1 AS has_attachments
FROM ' . ATTACHMENTS_TABLE . '
WHERE topic_id = ' . $topic_id;
$result = $db->sql_query_limit($sql, 1);
$has_attachments = (int) $db->sql_fetchfield('has_attachments');
$db->sql_freeresult($result);

if (!$has_attachments)
{
$sql_data[TOPICS_TABLE] .= ', topic_attachment = 0';
}

	}

// $sql_data[USERS_TABLE] = ($data['post_postcount']) ? 'user_posts = user_posts - 1' : '';

	}

// $sql_data[USERS_TABLE] = ($data['post_postcount']) ? 'user_posts = user_posts - 1' : '';

Line 1529Line 1645

/**
* Submit Post


/**
* Submit Post

 
* @todo Split up and create lightweight, simple API for this.

*/

*/

function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $update_message = true)

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;


Line 1579Line 1696

$data['topic_approved'] = $topic_row['topic_approved'];
$data['post_approved'] = $topic_row['post_approved'];


$data['topic_approved'] = $topic_row['topic_approved'];
$data['post_approved'] = $topic_row['post_approved'];

 
	}

// This variable indicates if the user is able to post or put into the queue - it is used later for all code decisions regarding approval
// The variable name should be $post_approved, because it indicates if the post is approved or not
$post_approval = 1;

// Check the permissions for post approval.
// Moderators must go through post approval like ordinary users.
if (!$auth->acl_get('f_noapprove', $data['forum_id']))
{
// Post not approved, but in queue
$post_approval = 0;
}

// Mods are able to force approved/unapproved posts. True means the post is approved, false the post is unapproved
if (isset($data['force_approved_state']))
{
$post_approval = ($data['force_approved_state']) ? 1 : 0;

	}

// Start the transaction here
$db->sql_transaction('begin');

	}

// Start the transaction here
$db->sql_transaction('begin');



 

// Collect Information
switch ($post_mode)


// Collect Information
switch ($post_mode)

Line 1596Line 1730
				'icon_id'			=> $data['icon_id'],
'poster_ip' => $user->ip,
'post_time' => $current_time,

				'icon_id'			=> $data['icon_id'],
'poster_ip' => $user->ip,
'post_time' => $current_time,

				'post_approved'		=> (!$auth->acl_get('f_noapprove', $data['forum_id']) && !$auth->acl_get('m_approve', $data['forum_id'])) ? 0 : 1,

				'post_approved'		=> $post_approval,

				'enable_bbcode'		=> $data['enable_bbcode'],
'enable_smilies' => $data['enable_smilies'],
'enable_magic_url' => $data['enable_urls'],

				'enable_bbcode'		=> $data['enable_bbcode'],
'enable_smilies' => $data['enable_smilies'],
'enable_magic_url' => $data['enable_urls'],

Line 1628Line 1762
			// Display edit info if edit reason given or user is editing his post, which is not the last within the topic.
if ($data['post_edit_reason'] || (!$auth->acl_get('m_edit', $data['forum_id']) && ($post_mode == 'edit' || $post_mode == 'edit_first_post')))
{

			// Display edit info if edit reason given or user is editing his post, which is not the last within the topic.
if ($data['post_edit_reason'] || (!$auth->acl_get('m_edit', $data['forum_id']) && ($post_mode == 'edit' || $post_mode == 'edit_first_post')))
{

				$data['post_edit_reason']		= truncate_string($data['post_edit_reason'], 255, false);

				$data['post_edit_reason']		= truncate_string($data['post_edit_reason'], 255, 255, false);


$sql_data[POSTS_TABLE]['sql'] = array(
'post_edit_time' => $current_time,


$sql_data[POSTS_TABLE]['sql'] = array(
'post_edit_time' => $current_time,

Line 1662Line 1796
				'forum_id'			=> ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id'],
'poster_id' => $data['poster_id'],
'icon_id' => $data['icon_id'],

				'forum_id'			=> ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id'],
'poster_id' => $data['poster_id'],
'icon_id' => $data['icon_id'],

				'post_approved'		=> (!$auth->acl_get('f_noapprove', $data['forum_id']) && !$auth->acl_get('m_approve', $data['forum_id'])) ? 0 : $data['post_approved'],

				'post_approved'		=> (!$post_approval) ? 0 : $data['post_approved'],

				'enable_bbcode'		=> $data['enable_bbcode'],
'enable_smilies' => $data['enable_smilies'],
'enable_magic_url' => $data['enable_urls'],

				'enable_bbcode'		=> $data['enable_bbcode'],
'enable_smilies' => $data['enable_smilies'],
'enable_magic_url' => $data['enable_urls'],

Line 1694Line 1828
			$sql_data[TOPICS_TABLE]['sql'] = array(
'topic_poster' => (int) $user->data['user_id'],
'topic_time' => $current_time,

			$sql_data[TOPICS_TABLE]['sql'] = array(
'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'],
'icon_id' => $data['icon_id'],

				'forum_id'					=> ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id'],
'icon_id' => $data['icon_id'],

				'topic_approved'			=> (!$auth->acl_get('f_noapprove', $data['forum_id']) && !$auth->acl_get('m_approve', $data['forum_id'])) ? 0 : 1,

				'topic_approved'			=> $post_approval,

				'topic_title'				=> $subject,
'topic_first_poster_name' => (!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : ''),
'topic_first_poster_colour' => $user->data['user_colour'],

				'topic_title'				=> $subject,
'topic_first_poster_name' => (!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : ''),
'topic_first_poster_colour' => $user->data['user_colour'],

Line 1707Line 1842

if (isset($poll['poll_options']) && !empty($poll['poll_options']))
{


if (isset($poll['poll_options']) && !empty($poll['poll_options']))
{

 
				$poll_start = ($poll['poll_start']) ? $poll['poll_start'] : $current_time;
$poll_length = $poll['poll_length'] * 86400;
if ($poll_length < 0)
{
$poll_start = $poll_start + $poll_length;
if ($poll_start < 0)
{
$poll_start = 0;
}
$poll_length = 1;
}


				$sql_data[TOPICS_TABLE]['sql'] = array_merge($sql_data[TOPICS_TABLE]['sql'], array(
'poll_title' => $poll['poll_title'],

				$sql_data[TOPICS_TABLE]['sql'] = array_merge($sql_data[TOPICS_TABLE]['sql'], array(
'poll_title' => $poll['poll_title'],

					'poll_start'		=> ($poll['poll_start']) ? $poll['poll_start'] : $current_time,

					'poll_start'		=> $poll_start,

					'poll_max_options'	=> $poll['poll_max_options'],

					'poll_max_options'	=> $poll['poll_max_options'],

					'poll_length'		=> ($poll['poll_length'] * 86400),

					'poll_length'		=> $poll_length,

					'poll_vote_change'	=> $poll['poll_vote_change'])
);
}


					'poll_vote_change'	=> $poll['poll_vote_change'])
);
}


			$sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . (($auth->acl_get('f_postcount', $data['forum_id'])) ? ', user_posts = user_posts + 1' : '');

			$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 ($topic_type != POST_GLOBAL)
{

				if ($auth->acl_get('f_noapprove', $data['forum_id']) || $auth->acl_get('m_approve', $data['forum_id']))

				if ($post_approval)

				{
$sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1';
}

				{
$sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1';
}

				$sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real + 1' . (($auth->acl_get('f_noapprove', $data['forum_id']) || $auth->acl_get('m_approve', $data['forum_id'])) ? ', forum_topics = forum_topics + 1' : '');

				$sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real + 1' . (($post_approval) ? ', forum_topics = forum_topics + 1' : '');

			}
break;

case 'reply':

			}
break;

case 'reply':

			$sql_data[TOPICS_TABLE]['stat'][] = 'topic_replies_real = topic_replies_real + 1, topic_bumped = 0, topic_bumper = 0' . (($auth->acl_get('f_noapprove', $data['forum_id']) || $auth->acl_get('m_approve', $data['forum_id'])) ? ', topic_replies = topic_replies + 1' : '') . ((!empty($data['attachment_data']) || (isset($data['topic_attachment']) && $data['topic_attachment'])) ? ', topic_attachment = 1' : '');






			$sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_view_time = ' . $current_time . ',
topic_replies_real = topic_replies_real + 1,
topic_bumped = 0,
topic_bumper = 0' .
(($post_approval) ? ', topic_replies = topic_replies + 1' : '') .
((!empty($data['attachment_data']) || (isset($data['topic_attachment']) && $data['topic_attachment'])) ? ', topic_attachment = 1' : '');





			$sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . (($auth->acl_get('f_postcount', $data['forum_id'])) ? ', user_posts = user_posts + 1' : '');

			$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 (($auth->acl_get('f_noapprove', $data['forum_id']) || $auth->acl_get('m_approve', $data['forum_id'])) && $topic_type != POST_GLOBAL)

			if ($post_approval && $topic_type != POST_GLOBAL)

			{
$sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1';
}

			{
$sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1';
}

Line 1741Line 1893

case 'edit_topic':
case 'edit_first_post':


case 'edit_topic':
case 'edit_first_post':

 
			if (isset($poll['poll_options']))
{
$poll_start = ($poll['poll_start'] || empty($poll['poll_options'])) ? $poll['poll_start'] : $current_time;
$poll_length = $poll['poll_length'] * 86400;
if ($poll_length < 0)
{
$poll_start = $poll_start + $poll_length;
if ($poll_start < 0)
{
$poll_start = 0;
}
$poll_length = 1;
}
}


$sql_data[TOPICS_TABLE]['sql'] = array(
'forum_id' => ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id'],
'icon_id' => $data['icon_id'],


$sql_data[TOPICS_TABLE]['sql'] = array(
'forum_id' => ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id'],
'icon_id' => $data['icon_id'],

				'topic_approved'			=> (!$auth->acl_get('f_noapprove', $data['forum_id']) && !$auth->acl_get('m_approve', $data['forum_id'])) ? 0 : $data['topic_approved'],

				'topic_approved'			=> (!$post_approval) ? 0 : $data['topic_approved'],

				'topic_title'				=> $subject,
'topic_first_poster_name' => $username,
'topic_type' => $topic_type,
'topic_time_limit' => ($topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE) ? ($data['topic_time_limit'] * 86400) : 0,
'poll_title' => (isset($poll['poll_options'])) ? $poll['poll_title'] : '',

				'topic_title'				=> $subject,
'topic_first_poster_name' => $username,
'topic_type' => $topic_type,
'topic_time_limit' => ($topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE) ? ($data['topic_time_limit'] * 86400) : 0,
'poll_title' => (isset($poll['poll_options'])) ? $poll['poll_title'] : '',

				'poll_start'				=> (isset($poll['poll_options'])) ? (($poll['poll_start']) ? $poll['poll_start'] : $current_time) : 0,

				'poll_start'				=> (isset($poll['poll_options'])) ? $poll_start : 0,

				'poll_max_options'			=> (isset($poll['poll_options'])) ? $poll['poll_max_options'] : 1,

				'poll_max_options'			=> (isset($poll['poll_options'])) ? $poll['poll_max_options'] : 1,

				'poll_length'				=> (isset($poll['poll_options'])) ? ($poll['poll_length'] * 86400) : 0,

				'poll_length'				=> (isset($poll['poll_options'])) ? $poll_length : 0,

				'poll_vote_change'			=> (isset($poll['poll_vote_change'])) ? $poll['poll_vote_change'] : 0,

				'poll_vote_change'			=> (isset($poll['poll_vote_change'])) ? $poll['poll_vote_change'] : 0,

 
				'topic_last_view_time'		=> $current_time,


'topic_attachment' => (!empty($data['attachment_data'])) ? 1 : (isset($data['topic_attachment']) ? $data['topic_attachment'] : 0),
);

// Correctly set back the topic replies and forum posts... only if the topic was approved before and now gets disapproved


'topic_attachment' => (!empty($data['attachment_data'])) ? 1 : (isset($data['topic_attachment']) ? $data['topic_attachment'] : 0),
);

// Correctly set back the topic replies and forum posts... only if the topic was approved before and now gets disapproved

			if (!$auth->acl_get('f_noapprove', $data['forum_id']) && !$auth->acl_get('m_approve', $data['forum_id']) && $data['topic_approved'])

			if (!$post_approval && $data['topic_approved'])

			{
// Do we need to grab some topic informations?
if (!sizeof($topic_row))

			{
// Do we need to grab some topic informations?
if (!sizeof($topic_row))

Line 1780Line 1947
				$sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics = forum_topics - 1';
$sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - ' . ($topic_row['topic_replies'] + 1);


				$sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics = forum_topics - 1';
$sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - ' . ($topic_row['topic_replies'] + 1);


				set_config('num_topics', $config['num_topics'] - 1, true);
set_config('num_posts', $config['num_posts'] - ($topic_row['topic_replies'] + 1), true);







				set_config_count('num_topics', -1, true);
set_config_count('num_posts', ($topic_row['topic_replies'] + 1) * (-1), true);

// Only decrement this post, since this is the one non-approved now
if ($auth->acl_get('f_postcount', $data['forum_id']))
{
$sql_data[USERS_TABLE]['stat'][] = 'user_posts = user_posts - 1';
}

			}

break;

			}

break;

Line 1790Line 1963
		case 'edit_last_post':

// Correctly set back the topic replies and forum posts... but only if the post was approved before.

		case 'edit_last_post':

// Correctly set back the topic replies and forum posts... but only if the post was approved before.

			if (!$auth->acl_get('f_noapprove', $data['forum_id']) && !$auth->acl_get('m_approve', $data['forum_id']) && $data['post_approved'])

			if (!$post_approval && $data['post_approved'])

			{

			{

				$sql_data[TOPICS_TABLE]['stat'][] = 'topic_replies = topic_replies - 1';

				$sql_data[TOPICS_TABLE]['stat'][] = 'topic_replies = topic_replies - 1, topic_last_view_time = ' . $current_time;

				$sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - 1';


				$sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - 1';


				set_config('num_posts', $config['num_posts'] - 1, true);






				set_config_count('num_posts', -1, true);

if ($auth->acl_get('f_postcount', $data['forum_id']))
{
$sql_data[USERS_TABLE]['stat'][] = 'user_posts = user_posts - 1';
}

			}

break;

			}

break;

Line 1839Line 2017
				'topic_last_poster_id'		=> (int) $user->data['user_id'],
'topic_last_poster_name' => (!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : ''),
'topic_last_poster_colour' => $user->data['user_colour'],

				'topic_last_poster_id'		=> (int) $user->data['user_id'],
'topic_last_poster_name' => (!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : ''),
'topic_last_poster_colour' => $user->data['user_colour'],

 
				'topic_last_post_subject'	=> (string) $subject,

			);
}


			);
}


Line 1919Line 2098
	}

// Update Poll Tables

	}

// Update Poll Tables

	if (isset($poll['poll_options']) && !empty($poll['poll_options']))

	if (isset($poll['poll_options']))

	{
$cur_poll_options = array();


	{
$cur_poll_options = array();


		if ($poll['poll_start'] && $mode == 'edit')

		if ($mode == 'edit')

		{
$sql = 'SELECT *
FROM ' . POLL_OPTIONS_TABLE . '

		{
$sql = 'SELECT *
FROM ' . POLL_OPTIONS_TABLE . '

Line 2013Line 2192

foreach ($data['attachment_data'] as $pos => $attach_row)
{


foreach ($data['attachment_data'] as $pos => $attach_row)
{

			if ($attach_row['is_orphan'] && !in_array($attach_row['attach_id'], array_keys($orphan_rows)))

			if ($attach_row['is_orphan'] && !isset($orphan_rows[$attach_row['attach_id']]))

			{
continue;
}

			{
continue;
}

Line 2030Line 2209
			else
{
// insert attachment into db

			else
{
// insert attachment into db

				if (!@file_exists($phpbb_root_path . $config['upload_path'] . '/' . basename($orphan_rows[$attach_row['attach_id']]['physical_filename'])))

				if (!@file_exists($phpbb_root_path . $config['upload_path'] . '/' . utf8_basename($orphan_rows[$attach_row['attach_id']]['physical_filename'])))

				{
continue;
}

				{
continue;
}

Line 2056Line 2235

if ($space_taken && $files_added)
{


if ($space_taken && $files_added)
{

			set_config('upload_dir_size', $config['upload_dir_size'] + $space_taken, true);
set_config('num_files', $config['num_files'] + $files_added, true);

			set_config_count('upload_dir_size', $space_taken, true);
set_config_count('num_files', $files_added, true);

		}
}


		}
}


Line 2095Line 2274
			// this post is the latest post in the forum, better update
if ($row['forum_last_post_id'] == $data['post_id'])
{

			// this post is the latest post in the forum, better update
if ($row['forum_last_post_id'] == $data['post_id'])
{

				if ($post_approved && $row['forum_last_post_subject'] !== $subject)





				// If post approved and subject changed, or poster is anonymous, we need to update the forum_last* rows
if ($post_approved && ($row['forum_last_post_subject'] !== $subject || $data['poster_id'] == ANONYMOUS))
{
// the post's subject changed
if ($row['forum_last_post_subject'] !== $subject)

				{

				{

					// the only data that can really be changed is the post's subject

 
					$sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_subject = \'' . $db->sql_escape($subject) . '\'';

					$sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_subject = \'' . $db->sql_escape($subject) . '\'';

 
					}

// Update the user name if poster is anonymous... just in case an admin changed it
if ($data['poster_id'] == ANONYMOUS)
{
$sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape($username) . "'";
}

				}
else if ($data['post_approved'] !== $post_approved)
{

				}
else if ($data['post_approved'] !== $post_approved)
{

Line 2235Line 2424
		{
// only the subject can be changed from edit
$sql_data[TOPICS_TABLE]['stat'][] = "topic_last_post_subject = '" . $db->sql_escape($subject) . "'";

		{
// only the subject can be changed from edit
$sql_data[TOPICS_TABLE]['stat'][] = "topic_last_post_subject = '" . $db->sql_escape($subject) . "'";

 

// Maybe not only the subject, but also changing anonymous usernames. ;)
if ($data['poster_id'] == ANONYMOUS)
{
$sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_name = '" . $db->sql_escape($username) . "'";
}

		}
}
else if (!$data['post_approved'] && ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies'])))

		}
}
else if (!$data['post_approved'] && ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies'])))

Line 2270Line 2465
	}

// Update total post count, do not consider moderated posts/topics

	}

// Update total post count, do not consider moderated posts/topics

	if ($auth->acl_get('f_noapprove', $data['forum_id']) || $auth->acl_get('m_approve', $data['forum_id']))

	if ($post_approval)

	{
if ($post_mode == 'post')
{

	{
if ($post_mode == 'post')
{

			set_config('num_topics', $config['num_topics'] + 1, true);
set_config('num_posts', $config['num_posts'] + 1, true);

			set_config_count('num_topics', 1, true);
set_config_count('num_posts', 1, true);

		}

if ($post_mode == 'reply')
{

		}

if ($post_mode == 'reply')
{

			set_config('num_posts', $config['num_posts'] + 1, true);

			set_config_count('num_posts', 1, true);

		}
}

// Update forum stats

		}
}

// Update forum stats

	$where_sql = array(POSTS_TABLE => 'post_id = ' . $data['post_id'], TOPICS_TABLE => 'topic_id = ' . $data['topic_id'], FORUMS_TABLE => 'forum_id = ' . $data['forum_id'], USERS_TABLE => 'user_id = ' . $user->data['user_id']);

	$where_sql = array(POSTS_TABLE => 'post_id = ' . $data['post_id'], TOPICS_TABLE => 'topic_id = ' . $data['topic_id'], FORUMS_TABLE => 'forum_id = ' . $data['forum_id'], USERS_TABLE => 'user_id = ' . $poster_id);


foreach ($sql_data as $table => $update_ary)
{


foreach ($sql_data as $table => $update_ary)
{

Line 2318Line 2513
	}

// Index message contents

	}

// Index message contents

	if ($update_message && $data['enable_indexing'])

	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']);

	{
// Select the search method and do some additional checks to ensure it can actually be utilised
$search_type = basename($config['search_type']);

Line 2353Line 2548
				VALUES (' . $user->data['user_id'] . ', ' . $data['topic_id'] . ')';
$db->sql_query($sql);
}

				VALUES (' . $user->data['user_id'] . ', ' . $data['topic_id'] . ')';
$db->sql_query($sql);
}

		else if ($data['notify_set'] && !$data['notify'])

		else if (($config['email_enable'] || $config['jab_enable']) && $data['notify_set'] && !$data['notify'])

		{
$sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . '
WHERE user_id = ' . $user->data['user_id'] . '

		{
$sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . '
WHERE user_id = ' . $user->data['user_id'] . '

Line 2365Line 2560
	if ($mode == 'post' || $mode == 'reply' || $mode == 'quote')
{
// Mark this topic as posted to

	if ($mode == 'post' || $mode == 'reply' || $mode == 'quote')
{
// Mark this topic as posted to

		markread('post', $data['forum_id'], $data['topic_id'], $data['post_time']);

		markread('post', $data['forum_id'], $data['topic_id']);

	}

// 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)

	}

// 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', $data['forum_id'], $data['topic_id'], time());

	markread('topic', (($topic_type == POST_GLOBAL) ? 0 : $data['forum_id']), $data['topic_id'], time());


//
if ($config['load_db_lastread'] && $user->data['is_registered'])


//
if ($config['load_db_lastread'] && $user->data['is_registered'])

Line 2378Line 2573
		$sql = 'SELECT mark_time
FROM ' . FORUMS_TRACK_TABLE . '
WHERE user_id = ' . $user->data['user_id'] . '

		$sql = 'SELECT mark_time
FROM ' . FORUMS_TRACK_TABLE . '
WHERE user_id = ' . $user->data['user_id'] . '

				AND forum_id = ' . $data['forum_id'];

				AND forum_id = ' . (($topic_type == POST_GLOBAL) ? 0 : $data['forum_id']);

		$result = $db->sql_query($sql);
$f_mark_time = (int) $db->sql_fetchfield('mark_time');
$db->sql_freeresult($result);

		$result = $db->sql_query($sql);
$f_mark_time = (int) $db->sql_fetchfield('mark_time');
$db->sql_freeresult($result);

Line 2391Line 2586
	if (($config['load_db_lastread'] && $user->data['is_registered']) || $config['load_anon_lastread'] || $user->data['is_registered'])
{
// Update forum info

	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);


		$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($data['forum_id'], $forum_last_post_time, $f_mark_time, false);

		update_forum_tracking_info((($topic_type == POST_GLOBAL) ? 0 : $data['forum_id']), $forum_last_post_time, $f_mark_time, false);

	}

// Send Notifications

	}

// Send Notifications

	if ($mode != 'edit' && $mode != 'delete' && ($auth->acl_get('f_noapprove', $data['forum_id']) || $auth->acl_get('m_approve', $data['forum_id'])))

	if (($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $post_approval)

	{

	{

		user_notification($mode, $subject, $data['topic_title'], $data['forum_name'], $data['forum_id'], $data['topic_id'], $data['post_id']);





		// If a username was supplied or the poster is a guest, we will use the supplied username.
// Doing it this way we can use "...post by guest-username..." in notifications when
// "guest-username" is supplied or ommit the username if it is not.
$username = ($username !== '' || !$user->data['is_registered']) ? $username : $user->data['username'];
user_notification($mode, $subject, $data['topic_title'], $data['forum_name'], $data['forum_id'], $data['topic_id'], $data['post_id'], $username);

	}

$params = $add_anchor = '';


	}

$params = $add_anchor = '';


	if ($auth->acl_get('f_noapprove', $data['forum_id']) || $auth->acl_get('m_approve', $data['forum_id']))

	if ($post_approval)

	{
$params .= '&amp;t=' . $data['topic_id'];


	{
$params .= '&amp;t=' . $data['topic_id'];


Line 2426Line 2634

$url = (!$params) ? "{$phpbb_root_path}viewforum.$phpEx" : "{$phpbb_root_path}viewtopic.$phpEx";
$url = append_sid($url, 'f=' . $data['forum_id'] . $params) . $add_anchor;


$url = (!$params) ? "{$phpbb_root_path}viewforum.$phpEx" : "{$phpbb_root_path}viewtopic.$phpEx";
$url = append_sid($url, 'f=' . $data['forum_id'] . $params) . $add_anchor;

 

return $url;
}

/**
* Handle topic bumping
* @param int $forum_id The ID of the forum the topic is being bumped belongs to
* @param int $topic_id The ID of the topic is being bumping
* @param array $post_data Passes some topic parameters:
* - 'topic_title'
* - 'topic_last_post_id'
* - 'topic_last_poster_id'
* - 'topic_last_post_subject'
* - 'topic_last_poster_name'
* - 'topic_last_poster_colour'
* @param int $bump_time The time at which topic was bumped, usually it is a current time as obtained via time().
* @return string An URL to the bumped topic, example: ./viewtopic.php?forum_id=1&amptopic_id=2&ampp=3#p3
*/
function phpbb_bump_topic($forum_id, $topic_id, $post_data, $bump_time = false)
{
global $config, $db, $user, $phpEx, $phpbb_root_path;

if ($bump_time === false)
{
$bump_time = time();
}

// Begin bumping
$db->sql_transaction('begin');

// Update the topic's last post post_time
$sql = 'UPDATE ' . POSTS_TABLE . "
SET post_time = $bump_time
WHERE post_id = {$post_data['topic_last_post_id']}
AND topic_id = $topic_id";
$db->sql_query($sql);

// Sync the topic's last post time, the rest of the topic's last post data isn't changed
$sql = 'UPDATE ' . TOPICS_TABLE . "
SET topic_last_post_time = $bump_time,
topic_bumped = 1,
topic_bumper = " . $user->data['user_id'] . "
WHERE topic_id = $topic_id";
$db->sql_query($sql);

// Update the forum's last post info
$sql = 'UPDATE ' . FORUMS_TABLE . "
SET forum_last_post_id = " . $post_data['topic_last_post_id'] . ",
forum_last_poster_id = " . $post_data['topic_last_poster_id'] . ",
forum_last_post_subject = '" . $db->sql_escape($post_data['topic_last_post_subject']) . "',
forum_last_post_time = $bump_time,
forum_last_poster_name = '" . $db->sql_escape($post_data['topic_last_poster_name']) . "',
forum_last_poster_colour = '" . $db->sql_escape($post_data['topic_last_poster_colour']) . "'
WHERE forum_id = $forum_id";
$db->sql_query($sql);

// Update bumper's time of the last posting to prevent flood
$sql = 'UPDATE ' . USERS_TABLE . "
SET user_lastpost_time = $bump_time
WHERE user_id = " . $user->data['user_id'];
$db->sql_query($sql);

$db->sql_transaction('commit');

// Mark this topic as posted to
markread('post', $forum_id, $topic_id, $bump_time);

// Mark this topic as read
markread('topic', $forum_id, $topic_id, $bump_time);

// Update forum tracking info
if ($config['load_db_lastread'] && $user->data['is_registered'])
{
$sql = 'SELECT mark_time
FROM ' . FORUMS_TRACK_TABLE . '
WHERE user_id = ' . $user->data['user_id'] . '
AND forum_id = ' . $forum_id;
$result = $db->sql_query($sql);
$f_mark_time = (int) $db->sql_fetchfield('mark_time');
$db->sql_freeresult($result);
}
else if ($config['load_anon_lastread'] || $user->data['is_registered'])
{
$f_mark_time = false;
}

if (($config['load_db_lastread'] && $user->data['is_registered']) || $config['load_anon_lastread'] || $user->data['is_registered'])
{
// Update forum info
$sql = 'SELECT forum_last_post_time
FROM ' . FORUMS_TABLE . '
WHERE forum_id = ' . $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($forum_id, $forum_last_post_time, $f_mark_time, false);
}

add_log('mod', $forum_id, $topic_id, 'LOG_BUMP_TOPIC', $post_data['topic_title']);

$url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;p={$post_data['topic_last_post_id']}") . "#p{$post_data['topic_last_post_id']}";


return $url;
}


return $url;
}