phpBB

Code Changes

File: includes/functions_posting.php

  Unmodified   Added   Modified   Removed
Line 24Line 24
*/
function generate_smilies($mode, $forum_id)
{

*/
function generate_smilies($mode, $forum_id)
{

	global $db, $user, $config, $template, $phpbb_dispatcher;

	global $db, $user, $config, $template, $phpbb_dispatcher, $request;

	global $phpEx, $phpbb_root_path, $phpbb_container, $phpbb_path_helper;


	global $phpEx, $phpbb_root_path, $phpbb_container, $phpbb_path_helper;


	$base_url = append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=smilies&f=' . $forum_id);

	/* @var $pagination \phpbb\pagination */

	$pagination = $phpbb_container->get('pagination');

	$pagination = $phpbb_container->get('pagination');

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


	$base_url = append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=smilies&f=' . $forum_id);
$start = $request->variable('start', 0);


if ($mode == 'window')
{


if ($mode == 'window')
{

Line 119Line 120

foreach ($smilies as $row)
{


foreach ($smilies as $row)
{

 
			/**
* Modify smiley root path before populating smiley list
*
* @event core.generate_smilies_before
* @var string root_path root_path for smilies
* @since 3.1.11-RC1
*/
$vars = array('root_path');
extract($phpbb_dispatcher->trigger_event('core.generate_smilies_before', compact($vars)));

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

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

Line 313Line 323
					'ICON_IMG'		=> $root_path . $config['icons_path'] . '/' . $data['img'],
'ICON_WIDTH' => $data['width'],
'ICON_HEIGHT' => $data['height'],

					'ICON_IMG'		=> $root_path . $config['icons_path'] . '/' . $data['img'],
'ICON_WIDTH' => $data['width'],
'ICON_HEIGHT' => $data['height'],

 
					'ICON_ALT'		=> $data['alt'],


'S_CHECKED' => ($id == $icon_id) ? true : false,
'S_ICON_CHECKED' => ($id == $icon_id) ? ' checked="checked"' : '')


'S_CHECKED' => ($id == $icon_id) ? true : false,
'S_ICON_CHECKED' => ($id == $icon_id) ? ' checked="checked"' : '')

Line 331Line 342
*/
function posting_gen_topic_types($forum_id, $cur_topic_type = POST_NORMAL)
{

*/
function posting_gen_topic_types($forum_id, $cur_topic_type = POST_NORMAL)
{

	global $auth, $user, $template, $topic_type;

	global $auth, $user, $template;


$toggle = false;

$topic_types = array(


$toggle = false;

$topic_types = array(

		'sticky'	=> array('const' => POST_STICKY, 'lang' => 'POST_STICKY'),
'announce' => array('const' => POST_ANNOUNCE, 'lang' => 'POST_ANNOUNCEMENT'),
'global' => array('const' => POST_GLOBAL, 'lang' => 'POST_GLOBAL')

		'sticky'			=> array('const' => POST_STICKY, 'lang' => 'POST_STICKY'),
'announce' => array('const' => POST_ANNOUNCE, 'lang' => 'POST_ANNOUNCEMENT'),
'announce_global' => array('const' => POST_GLOBAL, 'lang' => 'POST_GLOBAL')

	);

$topic_type_array = array();

foreach ($topic_types as $auth_key => $topic_value)
{

	);

$topic_type_array = array();

foreach ($topic_types as $auth_key => $topic_value)
{

		// We do not have a special post global announcement permission
$auth_key = ($auth_key == 'global') ? 'announce' : $auth_key;


 
		if ($auth->acl_get('f_' . $auth_key, $forum_id))
{
$toggle = true;

		if ($auth->acl_get('f_' . $auth_key, $forum_id))
{
$toggle = true;

Line 377Line 385

$template->assign_vars(array(
'S_TOPIC_TYPE_STICKY' => ($auth->acl_get('f_sticky', $forum_id)),


$template->assign_vars(array(
'S_TOPIC_TYPE_STICKY' => ($auth->acl_get('f_sticky', $forum_id)),

			'S_TOPIC_TYPE_ANNOUNCE'	=> ($auth->acl_get('f_announce', $forum_id)))
);

			'S_TOPIC_TYPE_ANNOUNCE'	=> ($auth->acl_gets('f_announce', 'f_announce_global', $forum_id)),
));

	}

return $toggle;

	}

return $toggle;

Line 391Line 399
/**
* Upload Attachment - filedata is generated here
* Uses upload class

/**
* Upload Attachment - filedata is generated here
* Uses upload class

 
*
* @deprecated 3.2.0-a1 (To be removed: 3.4.0)

*
* @param string $form_name The form name of the file upload input
* @param int $forum_id The id of the forum
* @param bool $local Whether the file is local or not
* @param string $local_storage The path to the local file
* @param bool $is_message Whether it is a PM or not

*
* @param string $form_name The form name of the file upload input
* @param int $forum_id The id of the forum
* @param bool $local Whether the file is local or not
* @param string $local_storage The path to the local file
* @param bool $is_message Whether it is a PM or not

* @param \filespec		$local_filedata	A filespec object created for the local file
* @param \phpbb\mimetype\guesser $mimetype_guesser The mimetype guesser object if used
* @param \phpbb\plupload\plupload $plupload The plupload object if one is being used

* @param array			$local_filedata	A filespec object created for the local file



*

*

* @return object filespec

* @return array File data array

*/

*/

function upload_attachment($form_name, $forum_id, $local = false, $local_storage = '', $is_message = false, $local_filedata = false, \phpbb\mimetype\guesser $mimetype_guesser = null, \phpbb\plupload\plupload $plupload = null)

function upload_attachment($form_name, $forum_id, $local = false, $local_storage = '', $is_message = false, $local_filedata = false)

{

{

	global $auth, $user, $config, $db, $cache;
global $phpbb_root_path, $phpEx, $phpbb_dispatcher;

	global $phpbb_container;






	$filedata = array(
'error' => array()
);


	/** @var \phpbb\attachment\manager $attachment_manager */
$attachment_manager = $phpbb_container->get('attachment.manager');
$file = $attachment_manager->upload($form_name, $forum_id, $local, $local_storage, $is_message, $local_filedata);
unset($attachment_manager);





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

$filedata['post_attach'] = $local || $upload->is_valid($form_name);

if (!$filedata['post_attach'])
{
$filedata['error'][] = $user->lang['NO_UPLOAD_FORM_FOUND'];
return $filedata;
}

$extensions = $cache->obtain_attach_extensions((($is_message) ? false : (int) $forum_id));
$upload->set_allowed_extensions(array_keys($extensions['_allowed_']));

$file = ($local) ? $upload->local_upload($local_storage, $local_filedata, $mimetype_guesser) : $upload->form_upload($form_name, $mimetype_guesser, $plupload);

if ($file->init_error)
{
$filedata['post_attach'] = false;
return $filedata;
}

// Whether the uploaded file is in the image category
$is_image = (isset($extensions[$file->get('extension')]['display_cat'])) ? $extensions[$file->get('extension')]['display_cat'] == ATTACHMENT_CATEGORY_IMAGE : false;

if (!$auth->acl_get('a_') && !$auth->acl_get('m_', $forum_id))
{
// Check Image Size, if it is an image
if ($is_image)
{
$file->upload->set_allowed_dimensions(0, 0, $config['img_max_width'], $config['img_max_height']);
}

// Admins and mods are allowed to exceed the allowed filesize
if (!empty($extensions[$file->get('extension')]['max_filesize']))
{
$allowed_filesize = $extensions[$file->get('extension')]['max_filesize'];
}
else
{
$allowed_filesize = ($is_message) ? $config['max_filesize_pm'] : $config['max_filesize'];
}

$file->upload->set_max_filesize($allowed_filesize);
}

$file->clean_filename('unique', $user->data['user_id'] . '_');

// Are we uploading an image *and* this image being within the image category?
// Only then perform additional image checks.
$file->move_file($config['upload_path'], false, !$is_image);

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

if (sizeof($file->error))
{
$file->remove();
$filedata['error'] = array_merge($filedata['error'], $file->error);
$filedata['post_attach'] = false;

return $filedata;
}

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

if ($plupload && $plupload->is_active())
{
$plupload->emit_error(104, 'ATTACHED_IMAGE_NOT_IMAGE');
}

// 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['mimetype'] = $file->get('mimetype');
$filedata['extension'] = $file->get('extension');
$filedata['physical_filename'] = $file->get('realname');
$filedata['real_filename'] = $file->get('uploadname');
$filedata['filetime'] = time();

/**
* Event to modify uploaded file before submit to the post
*
* @event core.modify_uploaded_file
* @var array filedata Array containing uploaded file data
* @var bool is_image Flag indicating if the file is an image
* @since 3.1.0-RC3
*/
$vars = array(
'filedata',
'is_image',
);
extract($phpbb_dispatcher->trigger_event('core.modify_uploaded_file', compact($vars)));

// Check our complete quota
if ($config['attachment_quota'])
{
if ($config['upload_dir_size'] + $file->get('filesize') > $config['attachment_quota'])
{
$filedata['error'][] = $user->lang['ATTACH_QUOTA_REACHED'];
$filedata['post_attach'] = false;

$file->remove();

return $filedata;
}
}

// Check free disk space
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['post_attach'] = false;

$file->remove();

return $filedata;
}
}

// Create Thumbnail
if ($filedata['thumbnail'])
{
$source = $file->get('destination_file');
$destination = $file->get('destination_path') . '/thumb_' . $file->get('realname');

if (!create_thumbnail($source, $destination, $file->get('mimetype')))
{
$filedata['thumbnail'] = 0;
}
}

return $filedata;

	return $file;





























































































































































}

/**

}

/**

Line 667Line 519
*/
function create_thumbnail($source, $destination, $mimetype)
{

*/
function create_thumbnail($source, $destination, $mimetype)
{

	global $config;

	global $config, $phpbb_filesystem;


$min_filesize = (int) $config['img_min_thumb_filesize'];
$img_filesize = (file_exists($source)) ? @filesize($source) : false;


$min_filesize = (int) $config['img_min_thumb_filesize'];
$img_filesize = (file_exists($source)) ? @filesize($source) : false;

Line 701Line 553

$used_imagick = false;



$used_imagick = false;


	// Only use imagemagick if defined and the passthru function not disabled

	// Only use ImageMagick if defined and the passthru function not disabled

	if ($config['img_imagick'] && function_exists('passthru'))
{
if (substr($config['img_imagick'], -1) !== '/')

	if ($config['img_imagick'] && function_exists('passthru'))
{
if (substr($config['img_imagick'], -1) !== '/')

Line 819Line 671
		return false;
}


		return false;
}


	phpbb_chmod($destination, CHMOD_READ | CHMOD_WRITE);








	try
{
$phpbb_filesystem->phpbb_chmod($destination, CHMOD_READ | CHMOD_WRITE);
}
catch (\phpbb\filesystem\exception\filesystem_exception $e)
{
// Do nothing
}


return true;
}


return true;
}

Line 983Line 842
	foreach ($draft_rows as $draft)
{
$link_topic = $link_forum = $link_pm = false;

	foreach ($draft_rows as $draft)
{
$link_topic = $link_forum = $link_pm = false;

		$insert_url = $view_url = $title = '';

		$view_url = $title = '';


if (isset($topic_rows[$draft['topic_id']])
&& (


if (isset($topic_rows[$draft['topic_id']])
&& (

Line 1036Line 895
*/
function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id = 0, $show_quote_button = true)
{

*/
function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id = 0, $show_quote_button = true)
{

	global $user, $auth, $db, $template, $bbcode, $cache;
global $config, $phpbb_root_path, $phpEx, $phpbb_container;

	global $user, $auth, $db, $template;
global $config, $phpbb_root_path, $phpEx, $phpbb_container, $phpbb_dispatcher;





 
	/* @var $phpbb_content_visibility \phpbb\content_visibility */

	$phpbb_content_visibility = $phpbb_container->get('content.visibility');
$sql_sort = ($mode == 'post_review') ? 'ASC' : 'DESC';


	$phpbb_content_visibility = $phpbb_container->get('content.visibility');
$sql_sort = ($mode == 'post_review') ? 'ASC' : 'DESC';


Line 1073Line 933
	}

$sql_ary = array(

	}

$sql_ary = array(

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

		'SELECT'	=> 'u.username, u.user_id, u.user_colour, p.*, z.friend, z.foe, uu.username as post_delete_username, uu.user_colour as post_delete_user_colour',


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


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

Line 1084Line 944
			array(
'FROM' => array(ZEBRA_TABLE => 'z'),
'ON' => 'z.user_id = ' . $user->data['user_id'] . ' AND z.zebra_id = p.poster_id',

			array(
'FROM' => array(ZEBRA_TABLE => 'z'),
'ON' => 'z.user_id = ' . $user->data['user_id'] . ' AND z.zebra_id = p.poster_id',

 
			),
array(
'FROM' => array(USERS_TABLE => 'uu'),
'ON' => 'uu.user_id = p.post_delete_user',

			),
),


			),
),


Line 1094Line 958
	$sql = $db->sql_build_query('SELECT', $sql_ary);
$result = $db->sql_query($sql);


	$sql = $db->sql_build_query('SELECT', $sql_ary);
$result = $db->sql_query($sql);


	$bbcode_bitfield = '';

 
	$rowset = array();
$has_attachments = false;
while ($row = $db->sql_fetchrow($result))
{
$rowset[$row['post_id']] = $row;

	$rowset = array();
$has_attachments = false;
while ($row = $db->sql_fetchrow($result))
{
$rowset[$row['post_id']] = $row;

		$bbcode_bitfield = $bbcode_bitfield | base64_decode($row['bbcode_bitfield']);

 

if ($row['post_attachment'])
{


if ($row['post_attachment'])
{

Line 1108Line 970
		}
}
$db->sql_freeresult($result);

		}
}
$db->sql_freeresult($result);


// Instantiate BBCode class
if (!isset($bbcode) && $bbcode_bitfield !== '')
{
include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
$bbcode = new bbcode(base64_encode($bbcode_bitfield));
}

 

// Grab extensions


// Grab extensions

	$extensions = $attachments = array();

	$attachments = array();

	if ($has_attachments && $auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id))
{

	if ($has_attachments && $auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id))
{

		$extensions = $cache->obtain_attach_extensions($forum_id);


 
		// Get attachments...
$sql = 'SELECT *
FROM ' . ATTACHMENTS_TABLE . '

		// Get attachments...
$sql = 'SELECT *
FROM ' . ATTACHMENTS_TABLE . '

Line 1136Line 989
		}
$db->sql_freeresult($result);
}

		}
$db->sql_freeresult($result);
}

 

/**
* Event to modify the posts list for topic reviews
*
* @event core.topic_review_modify_post_list
* @var array attachments Array with the post attachments data
* @var int cur_post_id Post offset ID
* @var int forum_id The topic's forum ID
* @var string mode The topic review mode
* @var array post_list Array with the post IDs
* @var array rowset Array with the posts data
* @var bool show_quote_button Flag indicating if the quote button should be displayed
* @var int topic_id The topic ID that is being reviewed
* @since 3.1.9-RC1
*/
$vars = array(
'attachments',
'cur_post_id',
'forum_id',
'mode',
'post_list',
'rowset',
'show_quote_button',
'topic_id',
);
extract($phpbb_dispatcher->trigger_event('core.topic_review_modify_post_list', compact($vars)));


for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i)
{


for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i)
{

Line 1176Line 1055
		$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']}");


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


























		$l_deleted_message = '';
if ($row['post_visibility'] == ITEM_DELETED)
{
$display_postername = get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']);

// User having deleted the post also being the post author?
if (!$row['post_delete_user'] || $row['post_delete_user'] == $poster_id)
{
$display_username = $display_postername;
}
else
{
$display_username = get_username_string('full', $row['post_delete_user'], $row['post_delete_username'], $row['post_delete_user_colour']);
}

if ($row['post_delete_reason'])
{
$l_deleted_message = $user->lang('POST_DELETED_BY_REASON', $display_postername, $display_username, $user->format_date($row['post_delete_time'], false, true), $row['post_delete_reason']);
}
else
{
$l_deleted_message = $user->lang('POST_DELETED_BY', $display_postername, $display_username, $user->format_date($row['post_delete_time'], false, true));
}
}

$post_row = array(

			'POST_AUTHOR_FULL'		=> get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
'POST_AUTHOR_COLOUR' => get_username_string('colour', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
'POST_AUTHOR' => get_username_string('username', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),

			'POST_AUTHOR_FULL'		=> get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
'POST_AUTHOR_COLOUR' => get_username_string('colour', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
'POST_AUTHOR' => get_username_string('username', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),

Line 1186Line 1090
			'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=\"phpbb.toggleDisplay('{$post_anchor}', 1); return false;\">", '</a>') : '',

			'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=\"phpbb.toggleDisplay('{$post_anchor}', 1); return false;\">", '</a>') : '',

 
			'S_POST_DELETED'	=> ($row['post_visibility'] == ITEM_DELETED) ? true : false,
'L_DELETE_POST' => $l_deleted_message,


'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 1193Line 1099
			'MESSAGE'			=> $message,
'DECODED_MESSAGE' => $decoded_message,
'POST_ID' => $row['post_id'],

			'MESSAGE'			=> $message,
'DECODED_MESSAGE' => $decoded_message,
'POST_ID' => $row['post_id'],

 
			'POST_TIME'			=> $row['post_time'],
'USER_ID' => $row['user_id'],

			'U_MINI_POST'		=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'p=' . $row['post_id']) . '#p' . $row['post_id'],
'U_MCP_DETAILS' => ($auth->acl_get('m_info', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&amp;mode=post_details&amp;f=' . $forum_id . '&amp;p=' . $row['post_id'], true, $user->session_id) : '',

			'U_MINI_POST'		=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'p=' . $row['post_id']) . '#p' . $row['post_id'],
'U_MCP_DETAILS' => ($auth->acl_get('m_info', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&amp;mode=post_details&amp;f=' . $forum_id . '&amp;p=' . $row['post_id'], true, $user->session_id) : '',

			'POSTER_QUOTE'		=> ($show_quote_button && $auth->acl_get('f_reply', $forum_id)) ? addslashes(get_username_string('username', $poster_id, $row['username'], $row['user_colour'], $row['post_username'])) : '')

			'POSTER_QUOTE'		=> ($show_quote_button && $auth->acl_get('f_reply', $forum_id)) ? addslashes(get_username_string('username', $poster_id, $row['username'], $row['user_colour'], $row['post_username'])) : '',

		);

		);

 

$current_row_number = $i;

/**
* Event to modify the template data block for topic reviews
*
* @event core.topic_review_modify_row
* @var string mode The review mode
* @var int topic_id The topic that is being reviewed
* @var int forum_id The topic's forum
* @var int cur_post_id Post offset id
* @var int current_row_number Number of the current row being iterated
* @var array post_row Template block array of the current post
* @var array row Array with original post and user data
* @since 3.1.4-RC1
*/
$vars = array(
'mode',
'topic_id',
'forum_id',
'cur_post_id',
'current_row_number',
'post_row',
'row',
);
extract($phpbb_dispatcher->trigger_event('core.topic_review_modify_row', compact($vars)));

$template->assign_block_vars($mode . '_row', $post_row);


// Display not already displayed Attachments for this post, we already parsed them. ;)
if (!empty($attachments[$row['post_id']]))


// Display not already displayed Attachments for this post, we already parsed them. ;)
if (!empty($attachments[$row['post_id']]))

Line 1229Line 1165
*/
function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $softdelete_reason = '')
{

*/
function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $softdelete_reason = '')
{

	global $db, $user, $auth, $phpbb_container;

	global $db, $user, $phpbb_container;

	global $config, $phpEx, $phpbb_root_path;

// Specify our post mode

	global $config, $phpEx, $phpbb_root_path;

// Specify our post mode

Line 1276Line 1212
		$db->sql_freeresult($result);
}


		$db->sql_freeresult($result);
}


 
	/* @var $phpbb_content_visibility \phpbb\content_visibility */

	$phpbb_content_visibility = $phpbb_container->get('content.visibility');

// (Soft) delete the post

	$phpbb_content_visibility = $phpbb_container->get('content.visibility');

// (Soft) delete the post

Line 1317Line 1254

if ($is_soft)
{


if ($is_soft)
{

				$topic_row = array();

 
				$phpbb_content_visibility->set_topic_visibility(ITEM_DELETED, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason);
}
else

				$phpbb_content_visibility->set_topic_visibility(ITEM_DELETED, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason);
}
else

Line 1487Line 1423
* Submit Post
* @todo Split up and create lightweight, simple API for this.
*/

* 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, $update_search_index = true)

function submit_post($mode, $subject, $username, $topic_type, &$poll_ary, &$data_ary, $update_message = true, $update_search_index = true)

{

{

	global $db, $auth, $user, $config, $phpEx, $template, $phpbb_root_path, $phpbb_container, $phpbb_dispatcher;

	global $db, $auth, $user, $config, $phpEx, $phpbb_root_path, $phpbb_container, $phpbb_dispatcher, $phpbb_log, $request;





 
	$poll = $poll_ary;
$data = $data_ary;

	/**
* Modify the data for post submitting
*

	/**
* Modify the data for post submitting
*

Line 1516Line 1454
		'update_search_index',
);
extract($phpbb_dispatcher->trigger_event('core.modify_submit_post_data', compact($vars)));

		'update_search_index',
);
extract($phpbb_dispatcher->trigger_event('core.modify_submit_post_data', compact($vars)));

 
	$poll_ary = $poll;
$data_ary = $data;
unset($poll);
unset($data);


// We do not handle erasing posts here
if ($mode == 'delete')


// We do not handle erasing posts here
if ($mode == 'delete')

Line 1523Line 1465
		return false;
}


		return false;
}


 
	if (!empty($data_ary['post_time']))
{
$current_time = $data_ary['post_time'];
}
else
{

	$current_time = time();

	$current_time = time();

 
	}


if ($mode == 'post')
{


if ($mode == 'post')
{

Line 1537Line 1486
	}
else if ($mode == 'edit')
{

	}
else if ($mode == 'edit')
{

		$post_mode = ($data['topic_posts_approved'] + $data['topic_posts_unapproved'] + $data['topic_posts_softdeleted'] == 1) ? 'edit_topic' : (($data['topic_first_post_id'] == $data['post_id']) ? 'edit_first_post' : (($data['topic_last_post_id'] == $data['post_id']) ? 'edit_last_post' : 'edit'));

		$post_mode = ($data_ary['topic_posts_approved'] + $data_ary['topic_posts_unapproved'] + $data_ary['topic_posts_softdeleted'] == 1) ? 'edit_topic' : (($data_ary['topic_first_post_id'] == $data_ary['post_id']) ? 'edit_first_post' : (($data_ary['topic_last_post_id'] == $data_ary['post_id']) ? 'edit_last_post' : 'edit'));

	}

// 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, 120);

	}

// 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, 120);

	$data['topic_title'] = truncate_string($data['topic_title'], 120);

	$data_ary['topic_title'] = truncate_string($data_ary['topic_title'], 120);


// Collect some basic information about which tables and which rows to update/insert
$sql_data = $topic_row = array();


// Collect some basic information about which tables and which rows to update/insert
$sql_data = $topic_row = array();

	$poster_id = ($mode == 'edit') ? $data['poster_id'] : (int) $user->data['user_id'];

	$poster_id = ($mode == 'edit') ? $data_ary['poster_id'] : (int) $user->data['user_id'];


// Retrieve some additional information if not present


// Retrieve some additional information if not present

	if ($mode == 'edit' && (!isset($data['post_visibility']) || !isset($data['topic_visibility']) || $data['post_visibility'] === false || $data['topic_visibility'] === false))

	if ($mode == 'edit' && (!isset($data_ary['post_visibility']) || !isset($data_ary['topic_visibility']) || $data_ary['post_visibility'] === false || $data_ary['topic_visibility'] === false))

	{
$sql = 'SELECT p.post_visibility, t.topic_type, t.topic_posts_approved, t.topic_posts_unapproved, t.topic_posts_softdeleted, t.topic_visibility
FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p
WHERE t.topic_id = p.topic_id

	{
$sql = 'SELECT p.post_visibility, t.topic_type, t.topic_posts_approved, t.topic_posts_unapproved, t.topic_posts_softdeleted, t.topic_visibility
FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p
WHERE t.topic_id = p.topic_id

				AND p.post_id = ' . $data['post_id'];

				AND p.post_id = ' . $data_ary['post_id'];

		$result = $db->sql_query($sql);
$topic_row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);


		$result = $db->sql_query($sql);
$topic_row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);


		$data['topic_visibility'] = $topic_row['topic_visibility'];
$data['post_visibility'] = $topic_row['post_visibility'];

		$data_ary['topic_visibility'] = $topic_row['topic_visibility'];
$data_ary['post_visibility'] = $topic_row['post_visibility'];

	}

// This variable indicates if the user is able to post or put into the queue

	}

// This variable indicates if the user is able to post or put into the queue

Line 1569Line 1518

// Check the permissions for post approval.
// Moderators must go through post approval like ordinary users.


// Check the permissions for post approval.
// Moderators must go through post approval like ordinary users.

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

	if (!$auth->acl_get('f_noapprove', $data_ary['forum_id']))

	{
// Post not approved, but in queue
$post_visibility = ITEM_UNAPPROVED;

	{
// Post not approved, but in queue
$post_visibility = ITEM_UNAPPROVED;

Line 1582Line 1531
				$post_visibility = ITEM_REAPPROVE;
break;
}

				$post_visibility = ITEM_REAPPROVE;
break;
}

 
	}
else if (isset($data_ary['post_visibility']) && $data_ary['post_visibility'] !== false)
{
$post_visibility = $data_ary['post_visibility'];

	}

// MODs/Extensions are able to force any visibility on posts

	}

// MODs/Extensions are able to force any visibility on posts

	if (isset($data['force_approved_state']))

	if (isset($data_ary['force_approved_state']))

	{

	{

		$post_visibility = (in_array((int) $data['force_approved_state'], array(ITEM_APPROVED, ITEM_UNAPPROVED, ITEM_DELETED, ITEM_REAPPROVE))) ? (int) $data['force_approved_state'] : $post_visibility;

		$post_visibility = (in_array((int) $data_ary['force_approved_state'], array(ITEM_APPROVED, ITEM_UNAPPROVED, ITEM_DELETED, ITEM_REAPPROVE))) ? (int) $data_ary['force_approved_state'] : $post_visibility;

	}

	}

	if (isset($data['force_visibility']))

	if (isset($data_ary['force_visibility']))

	{

	{

		$post_visibility = (in_array((int) $data['force_visibility'], array(ITEM_APPROVED, ITEM_UNAPPROVED, ITEM_DELETED, ITEM_REAPPROVE))) ? (int) $data['force_visibility'] : $post_visibility;

		$post_visibility = (in_array((int) $data_ary['force_visibility'], array(ITEM_APPROVED, ITEM_UNAPPROVED, ITEM_DELETED, ITEM_REAPPROVE))) ? (int) $data_ary['force_visibility'] : $post_visibility;

	}

// Start the transaction here

	}

// Start the transaction here

Line 1603Line 1556
		case 'post':
case 'reply':
$sql_data[POSTS_TABLE]['sql'] = array(

		case 'post':
case 'reply':
$sql_data[POSTS_TABLE]['sql'] = array(

				'forum_id'			=> $data['forum_id'],

				'forum_id'			=> $data_ary['forum_id'],

				'poster_id'			=> (int) $user->data['user_id'],

				'poster_id'			=> (int) $user->data['user_id'],

				'icon_id'			=> $data['icon_id'],

				'icon_id'			=> $data_ary['icon_id'],

				'poster_ip'			=> $user->ip,
'post_time' => $current_time,
'post_visibility' => $post_visibility,

				'poster_ip'			=> $user->ip,
'post_time' => $current_time,
'post_visibility' => $post_visibility,

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

				'enable_bbcode'		=> $data_ary['enable_bbcode'],
'enable_smilies' => $data_ary['enable_smilies'],
'enable_magic_url' => $data_ary['enable_urls'],
'enable_sig' => $data_ary['enable_sig'],

				'post_username'		=> (!$user->data['is_registered']) ? $username : '',
'post_subject' => $subject,

				'post_username'		=> (!$user->data['is_registered']) ? $username : '',
'post_subject' => $subject,

				'post_text'			=> $data['message'],
'post_checksum' => $data['message_md5'],
'post_attachment' => (!empty($data['attachment_data'])) ? 1 : 0,
'bbcode_bitfield' => $data['bbcode_bitfield'],
'bbcode_uid' => $data['bbcode_uid'],
'post_postcount' => ($auth->acl_get('f_postcount', $data['forum_id'])) ? 1 : 0,
'post_edit_locked' => $data['post_edit_locked']

				'post_text'			=> $data_ary['message'],
'post_checksum' => $data_ary['message_md5'],
'post_attachment' => (!empty($data_ary['attachment_data'])) ? 1 : 0,
'bbcode_bitfield' => $data_ary['bbcode_bitfield'],
'bbcode_uid' => $data_ary['bbcode_uid'],
'post_postcount' => ($auth->acl_get('f_postcount', $data_ary['forum_id'])) ? 1 : 0,
'post_edit_locked' => $data_ary['post_edit_locked']

			);
break;


			);
break;


Line 1638Line 1591
			// If normal edit display edit info

// Display edit info if edit reason given or user is editing his post, which is not the last within the topic.

			// If normal edit display edit info

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

			if ($data_ary['post_edit_reason'] || (!$auth->acl_get('m_edit', $data_ary['forum_id']) && ($post_mode == 'edit' || $post_mode == 'edit_first_post')))

			{

			{

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

				$data_ary['post_edit_reason']		= truncate_string($data_ary['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,

					'post_edit_reason'	=> $data['post_edit_reason'],
'post_edit_user' => (int) $data['post_edit_user'],

					'post_edit_reason'	=> $data_ary['post_edit_reason'],
'post_edit_user' => (int) $data_ary['post_edit_user'],

				);

$sql_data[POSTS_TABLE]['stat'][] = 'post_edit_count = post_edit_count + 1';
}

				);

$sql_data[POSTS_TABLE]['stat'][] = 'post_edit_count = post_edit_count + 1';
}

			else if (!$data['post_edit_reason'] && $mode == 'edit' && $auth->acl_get('m_edit', $data['forum_id']))

			else if (!$data_ary['post_edit_reason'] && $mode == 'edit' && $auth->acl_get('m_edit', $data_ary['forum_id']))

			{
$sql_data[POSTS_TABLE]['sql'] = array(
'post_edit_reason' => '',

			{
$sql_data[POSTS_TABLE]['sql'] = array(
'post_edit_reason' => '',

Line 1661Line 1614
			// Could be simplified by only adding to the log if the edit is not tracked - but this may confuse admins/mods
if ($user->data['user_id'] != $poster_id)
{

			// Could be simplified by only adding to the log if the edit is not tracked - but this may confuse admins/mods
if ($user->data['user_id'] != $poster_id)
{

				$log_subject = ($subject) ? $subject : $data['topic_title'];
add_log('mod', $data['forum_id'], $data['topic_id'], 'LOG_POST_EDITED', $log_subject, (!empty($username)) ? $username : $user->lang['GUEST'], $data['post_edit_reason']);








				$log_subject = ($subject) ? $subject : $data_ary['topic_title'];
$phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_POST_EDITED', false, array(
'forum_id' => $data_ary['forum_id'],
'topic_id' => $data_ary['topic_id'],
'post_id' => $data_ary['post_id'],
$log_subject,
(!empty($username)) ? $username : $user->lang['GUEST'],
$data_ary['post_edit_reason']
));

			}

if (!isset($sql_data[POSTS_TABLE]['sql']))

			}

if (!isset($sql_data[POSTS_TABLE]['sql']))

Line 1671Line 1631
			}

$sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array(

			}

$sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array(

				'forum_id'			=> $data['forum_id'],
'poster_id' => $data['poster_id'],
'icon_id' => $data['icon_id'],

				'forum_id'			=> $data_ary['forum_id'],
'poster_id' => $data_ary['poster_id'],
'icon_id' => $data_ary['icon_id'],

				// We will change the visibility later
//'post_visibility' => $post_visibility,

				// We will change the visibility later
//'post_visibility' => $post_visibility,

				'enable_bbcode'		=> $data['enable_bbcode'],
'enable_smilies' => $data['enable_smilies'],
'enable_magic_url' => $data['enable_urls'],
'enable_sig' => $data['enable_sig'],
'post_username' => ($username && $data['poster_id'] == ANONYMOUS) ? $username : '',

				'enable_bbcode'		=> $data_ary['enable_bbcode'],
'enable_smilies' => $data_ary['enable_smilies'],
'enable_magic_url' => $data_ary['enable_urls'],
'enable_sig' => $data_ary['enable_sig'],
'post_username' => ($username && $data_ary['poster_id'] == ANONYMOUS) ? $username : '',

				'post_subject'		=> $subject,

				'post_subject'		=> $subject,

				'post_checksum'		=> $data['message_md5'],
'post_attachment' => (!empty($data['attachment_data'])) ? 1 : 0,
'bbcode_bitfield' => $data['bbcode_bitfield'],
'bbcode_uid' => $data['bbcode_uid'],
'post_edit_locked' => $data['post_edit_locked'])

				'post_checksum'		=> $data_ary['message_md5'],
'post_attachment' => (!empty($data_ary['attachment_data'])) ? 1 : 0,
'bbcode_bitfield' => $data_ary['bbcode_bitfield'],
'bbcode_uid' => $data_ary['bbcode_uid'],
'post_edit_locked' => $data_ary['post_edit_locked'])

			);

if ($update_message)
{

			);

if ($update_message)
{

				$sql_data[POSTS_TABLE]['sql']['post_text'] = $data['message'];

				$sql_data[POSTS_TABLE]['sql']['post_text'] = $data_ary['message'];

			}

break;
}

			}

break;
}

	$topic_row = array();

 

// And the topic ladies and gentlemen
switch ($post_mode)


// And the topic ladies and gentlemen
switch ($post_mode)

Line 1706Line 1665
				'topic_poster'				=> (int) $user->data['user_id'],
'topic_time' => $current_time,
'topic_last_view_time' => $current_time,

				'topic_poster'				=> (int) $user->data['user_id'],
'topic_time' => $current_time,
'topic_last_view_time' => $current_time,

				'forum_id'					=> $data['forum_id'],
'icon_id' => $data['icon_id'],

				'forum_id'					=> $data_ary['forum_id'],
'icon_id' => $data_ary['icon_id'],

				'topic_posts_approved'		=> ($post_visibility == ITEM_APPROVED) ? 1 : 0,
'topic_posts_softdeleted' => ($post_visibility == ITEM_DELETED) ? 1 : 0,
'topic_posts_unapproved' => ($post_visibility == ITEM_UNAPPROVED) ? 1 : 0,

				'topic_posts_approved'		=> ($post_visibility == ITEM_APPROVED) ? 1 : 0,
'topic_posts_softdeleted' => ($post_visibility == ITEM_DELETED) ? 1 : 0,
'topic_posts_unapproved' => ($post_visibility == ITEM_UNAPPROVED) ? 1 : 0,

Line 1717Line 1676
				'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_type' => $topic_type,

				'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_type' => $topic_type,

				'topic_time_limit'			=> ($topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE) ? ($data['topic_time_limit'] * 86400) : 0,
'topic_attachment' => (!empty($data['attachment_data'])) ? 1 : 0,


				'topic_time_limit'			=> ($topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE) ? ($data_ary['topic_time_limit'] * 86400) : 0,
'topic_attachment' => (!empty($data_ary['attachment_data'])) ? 1 : 0,
'topic_status' => (isset($data_ary['topic_status'])) ? $data_ary['topic_status'] : ITEM_UNLOCKED,

			);


			);


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

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

			{

			{

				$poll_start = ($poll['poll_start']) ? $poll['poll_start'] : $current_time;
$poll_length = $poll['poll_length'] * 86400;

				$poll_start = ($poll_ary['poll_start']) ? $poll_ary['poll_start'] : $current_time;
$poll_length = $poll_ary['poll_length'] * 86400;

				if ($poll_length < 0)
{
$poll_start = $poll_start + $poll_length;

				if ($poll_length < 0)
{
$poll_start = $poll_start + $poll_length;

Line 1736Line 1696
				}

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

				}

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

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

					'poll_title'		=> $poll_ary['poll_title'],

					'poll_start'		=> $poll_start,

					'poll_start'		=> $poll_start,

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

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

					'poll_length'		=> $poll_length,

					'poll_length'		=> $poll_length,

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

					'poll_vote_change'	=> $poll_ary['poll_vote_change'])

				);
}


				);
}


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

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


if ($post_visibility == ITEM_APPROVED)
{


if ($post_visibility == ITEM_APPROVED)
{

Line 1770Line 1730
				(($post_visibility == ITEM_APPROVED) ? ', topic_posts_approved = topic_posts_approved + 1' : '') .
(($post_visibility == ITEM_UNAPPROVED) ? ', topic_posts_unapproved = topic_posts_unapproved + 1' : '') .
(($post_visibility == ITEM_DELETED) ? ', topic_posts_softdeleted = topic_posts_softdeleted + 1' : '') .

				(($post_visibility == ITEM_APPROVED) ? ', topic_posts_approved = topic_posts_approved + 1' : '') .
(($post_visibility == ITEM_UNAPPROVED) ? ', topic_posts_unapproved = topic_posts_unapproved + 1' : '') .
(($post_visibility == ITEM_DELETED) ? ', topic_posts_softdeleted = topic_posts_softdeleted + 1' : '') .

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

				((!empty($data_ary['attachment_data']) || (isset($data_ary['topic_attachment']) && $data_ary['topic_attachment'])) ? ', topic_attachment = 1' : '');





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

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


if ($post_visibility == ITEM_APPROVED)
{


if ($post_visibility == ITEM_APPROVED)
{

Line 1790Line 1750

case 'edit_topic':
case 'edit_first_post':


case 'edit_topic':
case 'edit_first_post':

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

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

			{

			{

				$poll_start = ($poll['poll_start'] || empty($poll['poll_options'])) ? $poll['poll_start'] : $current_time;
$poll_length = $poll['poll_length'] * 86400;

				$poll_start = ($poll_ary['poll_start'] || empty($poll_ary['poll_options'])) ? $poll_ary['poll_start'] : $current_time;
$poll_length = $poll_ary['poll_length'] * 86400;

				if ($poll_length < 0)
{
$poll_start = $poll_start + $poll_length;

				if ($poll_length < 0)
{
$poll_start = $poll_start + $poll_length;

Line 1806Line 1766
			}

$sql_data[TOPICS_TABLE]['sql'] = array(

			}

$sql_data[TOPICS_TABLE]['sql'] = array(

				'forum_id'					=> $data['forum_id'],
'icon_id' => $data['icon_id'],

				'forum_id'					=> $data_ary['forum_id'],
'icon_id' => $data_ary['icon_id'],

				'topic_title'				=> $subject,
'topic_first_poster_name' => $username,
'topic_type' => $topic_type,

				'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_start : 0,
'poll_max_options' => (isset($poll['poll_options'])) ? $poll['poll_max_options'] : 1,
'poll_length' => (isset($poll['poll_options'])) ? $poll_length : 0,
'poll_vote_change' => (isset($poll['poll_vote_change'])) ? $poll['poll_vote_change'] : 0,

				'topic_time_limit'			=> ($topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE) ? ($data_ary['topic_time_limit'] * 86400) : 0,
'poll_title' => (isset($poll_ary['poll_options'])) ? $poll_ary['poll_title'] : '',
'poll_start' => (isset($poll_ary['poll_options'])) ? $poll_start : 0,
'poll_max_options' => (isset($poll_ary['poll_options'])) ? $poll_ary['poll_max_options'] : 1,
'poll_length' => (isset($poll_ary['poll_options'])) ? $poll_length : 0,
'poll_vote_change' => (isset($poll_ary['poll_vote_change'])) ? $poll_ary['poll_vote_change'] : 0,

				'topic_last_view_time'		=> $current_time,


				'topic_last_view_time'		=> $current_time,


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

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

			);

break;
}

			);

break;
}

 

$poll = $poll_ary;
$data = $data_ary;
/**
* Modify sql query data for post submitting
*
* @event core.submit_post_modify_sql_data
* @var array data Array with the data for the post
* @var array poll Array with the poll data for the post
* @var string post_mode Variable containing posting mode value
* @var bool sql_data Array with the data for the posting SQL query
* @var string subject Variable containing post subject value
* @var int topic_type Variable containing topic type value
* @var string username Variable containing post author name
* @since 3.1.3-RC1
*/
$vars = array(
'data',
'poll',
'post_mode',
'sql_data',
'subject',
'topic_type',
'username',
);
extract($phpbb_dispatcher->trigger_event('core.submit_post_modify_sql_data', compact($vars)));
$poll_ary = $poll;
$data_ary = $data;
unset($poll);
unset($data);


// Submit new topic
if ($post_mode == 'post')


// Submit new topic
if ($post_mode == 'post')

Line 1832Line 1822
			$db->sql_build_array('INSERT', $sql_data[TOPICS_TABLE]['sql']);
$db->sql_query($sql);


			$db->sql_build_array('INSERT', $sql_data[TOPICS_TABLE]['sql']);
$db->sql_query($sql);


		$data['topic_id'] = $db->sql_nextid();

		$data_ary['topic_id'] = $db->sql_nextid();


$sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array(


$sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array(

			'topic_id' => $data['topic_id'])

			'topic_id' => $data_ary['topic_id'])

		);
unset($sql_data[TOPICS_TABLE]['sql']);
}

		);
unset($sql_data[TOPICS_TABLE]['sql']);
}

Line 1846Line 1836
		if ($post_mode == 'reply')
{
$sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array(

		if ($post_mode == 'reply')
{
$sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array(

				'topic_id' => $data['topic_id'],

				'topic_id' => $data_ary['topic_id'],

			));
}

$sql = 'INSERT INTO ' . POSTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_data[POSTS_TABLE]['sql']);
$db->sql_query($sql);

			));
}

$sql = 'INSERT INTO ' . POSTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_data[POSTS_TABLE]['sql']);
$db->sql_query($sql);

		$data['post_id'] = $db->sql_nextid();

		$data_ary['post_id'] = $db->sql_nextid();


if ($post_mode == 'post' || $post_visibility == ITEM_APPROVED)
{
$sql_data[TOPICS_TABLE]['sql'] = array(


if ($post_mode == 'post' || $post_visibility == ITEM_APPROVED)
{
$sql_data[TOPICS_TABLE]['sql'] = array(

				'topic_last_post_id'		=> $data['post_id'],

				'topic_last_post_id'		=> $data_ary['post_id'],

				'topic_last_post_time'		=> $current_time,
'topic_last_poster_id' => $sql_data[POSTS_TABLE]['sql']['poster_id'],
'topic_last_poster_name' => ($user->data['user_id'] == ANONYMOUS) ? $sql_data[POSTS_TABLE]['sql']['post_username'] : $user->data['username'],

				'topic_last_post_time'		=> $current_time,
'topic_last_poster_id' => $sql_data[POSTS_TABLE]['sql']['poster_id'],
'topic_last_poster_name' => ($user->data['user_id'] == ANONYMOUS) ? $sql_data[POSTS_TABLE]['sql']['post_username'] : $user->data['username'],

Line 1868Line 1858

if ($post_mode == 'post')
{


if ($post_mode == 'post')
{

			$sql_data[TOPICS_TABLE]['sql']['topic_first_post_id'] = $data['post_id'];

			$sql_data[TOPICS_TABLE]['sql']['topic_first_post_id'] = $data_ary['post_id'];

		}

// Update total post count and forum information

		}

// Update total post count and forum information

Line 1876Line 1866
		{
if ($post_mode == 'post')
{

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

				set_config_count('num_topics', 1, true);

				$config->increment('num_topics', 1, false);

			}

			}

			set_config_count('num_posts', 1, true);

			$config->increment('num_posts', 1, false);





			$sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = ' . $data['post_id'];

			$sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = ' . $data_ary['post_id'];

			$sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = '" . $db->sql_escape($subject) . "'";
$sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = ' . $current_time;
$sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = ' . (int) $user->data['user_id'];

			$sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = '" . $db->sql_escape($subject) . "'";
$sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = ' . $current_time;
$sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = ' . (int) $user->data['user_id'];

Line 1896Line 1886
	{
$sql = 'UPDATE ' . TOPICS_TABLE . '
SET ' . $db->sql_build_array('UPDATE', $sql_data[TOPICS_TABLE]['sql']) . '

	{
$sql = 'UPDATE ' . TOPICS_TABLE . '
SET ' . $db->sql_build_array('UPDATE', $sql_data[TOPICS_TABLE]['sql']) . '

			WHERE topic_id = ' . $data['topic_id'];

			WHERE topic_id = ' . $data_ary['topic_id'];

		$db->sql_query($sql);

unset($sql_data[TOPICS_TABLE]['sql']);

		$db->sql_query($sql);

unset($sql_data[TOPICS_TABLE]['sql']);

Line 1907Line 1897
	{
$sql = 'UPDATE ' . POSTS_TABLE . '
SET ' . $db->sql_build_array('UPDATE', $sql_data[POSTS_TABLE]['sql']) . '

	{
$sql = 'UPDATE ' . POSTS_TABLE . '
SET ' . $db->sql_build_array('UPDATE', $sql_data[POSTS_TABLE]['sql']) . '

			WHERE post_id = ' . $data['post_id'];

			WHERE post_id = ' . $data_ary['post_id'];

		$db->sql_query($sql);

unset($sql_data[POSTS_TABLE]['sql']);
}

// Update Poll Tables

		$db->sql_query($sql);

unset($sql_data[POSTS_TABLE]['sql']);
}

// Update Poll Tables

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

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

	{
$cur_poll_options = array();


	{
$cur_poll_options = array();


Line 1922Line 1912
		{
$sql = 'SELECT *
FROM ' . POLL_OPTIONS_TABLE . '

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

				WHERE topic_id = ' . $data['topic_id'] . '

				WHERE topic_id = ' . $data_ary['topic_id'] . '

				ORDER BY poll_option_id';
$result = $db->sql_query($sql);


				ORDER BY poll_option_id';
$result = $db->sql_query($sql);


Line 1936Line 1926

$sql_insert_ary = array();



$sql_insert_ary = array();


		for ($i = 0, $size = sizeof($poll['poll_options']); $i < $size; $i++)

		for ($i = 0, $size = sizeof($poll_ary['poll_options']); $i < $size; $i++)

		{

		{

			if (strlen(trim($poll['poll_options'][$i])))

			if (strlen(trim($poll_ary['poll_options'][$i])))

			{
if (empty($cur_poll_options[$i]))
{
// If we add options we need to put them to the end to be able to preserve votes...
$sql_insert_ary[] = array(
'poll_option_id' => (int) sizeof($cur_poll_options) + 1 + sizeof($sql_insert_ary),

			{
if (empty($cur_poll_options[$i]))
{
// If we add options we need to put them to the end to be able to preserve votes...
$sql_insert_ary[] = array(
'poll_option_id' => (int) sizeof($cur_poll_options) + 1 + sizeof($sql_insert_ary),

						'topic_id'			=> (int) $data['topic_id'],
'poll_option_text' => (string) $poll['poll_options'][$i]

						'topic_id'			=> (int) $data_ary['topic_id'],
'poll_option_text' => (string) $poll_ary['poll_options'][$i]

					);
}

					);
}

				else if ($poll['poll_options'][$i] != $cur_poll_options[$i])

				else if ($poll_ary['poll_options'][$i] != $cur_poll_options[$i])

				{
$sql = 'UPDATE ' . POLL_OPTIONS_TABLE . "

				{
$sql = 'UPDATE ' . POLL_OPTIONS_TABLE . "

						SET poll_option_text = '" . $db->sql_escape($poll['poll_options'][$i]) . "'

						SET poll_option_text = '" . $db->sql_escape($poll_ary['poll_options'][$i]) . "'

						WHERE poll_option_id = " . $cur_poll_options[$i]['poll_option_id'] . '

						WHERE poll_option_id = " . $cur_poll_options[$i]['poll_option_id'] . '

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

							AND topic_id = ' . $data_ary['topic_id'];

					$db->sql_query($sql);
}
}

					$db->sql_query($sql);
}
}

Line 1962Line 1952

$db->sql_multi_insert(POLL_OPTIONS_TABLE, $sql_insert_ary);



$db->sql_multi_insert(POLL_OPTIONS_TABLE, $sql_insert_ary);


		if (sizeof($poll['poll_options']) < sizeof($cur_poll_options))

		if (sizeof($poll_ary['poll_options']) < sizeof($cur_poll_options))

		{
$sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . '

		{
$sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . '

				WHERE poll_option_id > ' . sizeof($poll['poll_options']) . '
AND topic_id = ' . $data['topic_id'];

				WHERE poll_option_id > ' . sizeof($poll_ary['poll_options']) . '
AND topic_id = ' . $data_ary['topic_id'];

			$db->sql_query($sql);
}

// If edited, we would need to reset votes (since options can be re-ordered above, you can't be sure if the change is for changing the text or adding an option

			$db->sql_query($sql);
}

// If edited, we would need to reset votes (since options can be re-ordered above, you can't be sure if the change is for changing the text or adding an option

		if ($mode == 'edit' && sizeof($poll['poll_options']) != sizeof($cur_poll_options))

		if ($mode == 'edit' && sizeof($poll_ary['poll_options']) != sizeof($cur_poll_options))

		{

		{

			$db->sql_query('DELETE FROM ' . POLL_VOTES_TABLE . ' WHERE topic_id = ' . $data['topic_id']);
$db->sql_query('UPDATE ' . POLL_OPTIONS_TABLE . ' SET poll_option_total = 0 WHERE topic_id = ' . $data['topic_id']);

			$db->sql_query('DELETE FROM ' . POLL_VOTES_TABLE . ' WHERE topic_id = ' . $data_ary['topic_id']);
$db->sql_query('UPDATE ' . POLL_OPTIONS_TABLE . ' SET poll_option_total = 0 WHERE topic_id = ' . $data_ary['topic_id']);

		}
}

// Submit Attachments

		}
}

// Submit Attachments

	if (!empty($data['attachment_data']) && $data['post_id'] && in_array($mode, array('post', 'reply', 'quote', 'edit')))

	if (!empty($data_ary['attachment_data']) && $data_ary['post_id'] && in_array($mode, array('post', 'reply', 'quote', 'edit')))

	{
$space_taken = $files_added = 0;
$orphan_rows = array();


	{
$space_taken = $files_added = 0;
$orphan_rows = array();


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

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

		{
$orphan_rows[(int) $attach_row['attach_id']] = array();
}

		{
$orphan_rows[(int) $attach_row['attach_id']] = array();
}

Line 2006Line 1996
			$db->sql_freeresult($result);
}


			$db->sql_freeresult($result);
}


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

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

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

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

Line 2034Line 2024
				$files_added++;

$attach_sql = array(

				$files_added++;

$attach_sql = array(

					'post_msg_id'		=> $data['post_id'],
'topic_id' => $data['topic_id'],

					'post_msg_id'		=> $data_ary['post_id'],
'topic_id' => $data_ary['topic_id'],

					'is_orphan'			=> 0,
'poster_id' => $poster_id,
'attach_comment' => $attach_row['attach_comment'],

					'is_orphan'			=> 0,
'poster_id' => $poster_id,
'attach_comment' => $attach_row['attach_comment'],

Line 2051Line 2041

if ($space_taken && $files_added)
{


if ($space_taken && $files_added)
{

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

			$config->increment('upload_dir_size', $space_taken, false);
$config->increment('num_files', $files_added, false);

		}
}

$first_post_has_topic_info = ($post_mode == 'edit_first_post' &&

		}
}

$first_post_has_topic_info = ($post_mode == 'edit_first_post' &&

			(($post_visibility == ITEM_DELETED && $data['topic_posts_softdeleted'] == 1) ||
($post_visibility == ITEM_UNAPPROVED && $data['topic_posts_unapproved'] == 1) ||
($post_visibility == ITEM_REAPPROVE && $data['topic_posts_unapproved'] == 1) ||
($post_visibility == ITEM_APPROVED && $data['topic_posts_approved'] == 1)));

			(($post_visibility == ITEM_DELETED && $data_ary['topic_posts_softdeleted'] == 1) ||
($post_visibility == ITEM_UNAPPROVED && $data_ary['topic_posts_unapproved'] == 1) ||
($post_visibility == ITEM_REAPPROVE && $data_ary['topic_posts_unapproved'] == 1) ||
($post_visibility == ITEM_APPROVED && $data_ary['topic_posts_approved'] == 1)));

	// Fix the post's and topic's visibility and first/last post information, when the post is edited

	// Fix the post's and topic's visibility and first/last post information, when the post is edited

	if (($post_mode != 'post' && $post_mode != 'reply') && $data['post_visibility'] != $post_visibility)

	if (($post_mode != 'post' && $post_mode != 'reply') && $data_ary['post_visibility'] != $post_visibility)

	{
// If the post was not approved, it could also be the starter,
// so we sync the starter after approving/restoring, to ensure that the stats are correct
// Same applies for the last post

	{
// If the post was not approved, it could also be the starter,
// so we sync the starter after approving/restoring, to ensure that the stats are correct
// Same applies for the last post

		$is_starter = ($post_mode == 'edit_first_post' || $post_mode == 'edit_topic' || $data['post_visibility'] != ITEM_APPROVED);
$is_latest = ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || $data['post_visibility'] != ITEM_APPROVED);

		$is_starter = ($post_mode == 'edit_first_post' || $post_mode == 'edit_topic' || $data_ary['post_visibility'] != ITEM_APPROVED);
$is_latest = ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || $data_ary['post_visibility'] != ITEM_APPROVED);





 
		/* @var $phpbb_content_visibility \phpbb\content_visibility */

		$phpbb_content_visibility = $phpbb_container->get('content.visibility');

		$phpbb_content_visibility = $phpbb_container->get('content.visibility');

		$phpbb_content_visibility->set_post_visibility($post_visibility, $data['post_id'], $data['topic_id'], $data['forum_id'], $user->data['user_id'], time(), '', $is_starter, $is_latest);

		$phpbb_content_visibility->set_post_visibility($post_visibility, $data_ary['post_id'], $data_ary['topic_id'], $data_ary['forum_id'], $user->data['user_id'], time(), '', $is_starter, $is_latest);

	}
else if ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || $first_post_has_topic_info)
{

	}
else if ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || $first_post_has_topic_info)
{

		if ($post_visibility == ITEM_APPROVED || $data['topic_visibility'] == $post_visibility)

		if ($post_visibility == ITEM_APPROVED || $data_ary['topic_visibility'] == $post_visibility)

		{
// 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. ;)

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

			if ($data_ary['poster_id'] == ANONYMOUS)

			{
$sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_name = '" . $db->sql_escape($username) . "'";
}

			{
$sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_name = '" . $db->sql_escape($username) . "'";
}

Line 2092Line 2083
				// it just means that we might have to
$sql = 'SELECT forum_last_post_id, forum_last_post_subject
FROM ' . FORUMS_TABLE . '

				// it just means that we might have to
$sql = 'SELECT forum_last_post_id, forum_last_post_subject
FROM ' . FORUMS_TABLE . '

					WHERE forum_id = ' . (int) $data['forum_id'];

					WHERE forum_id = ' . (int) $data_ary['forum_id'];

				$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);

// this post is the latest post in the forum, better update

				$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);

// this post is the latest post in the forum, better update

				if ($row['forum_last_post_id'] == $data['post_id'] && ($row['forum_last_post_subject'] !== $subject || $data['poster_id'] == ANONYMOUS))

				if ($row['forum_last_post_id'] == $data_ary['post_id'] && ($row['forum_last_post_subject'] !== $subject || $data_ary['poster_id'] == ANONYMOUS))

				{
// the post's subject changed
if ($row['forum_last_post_subject'] !== $subject)

				{
// the post's subject changed
if ($row['forum_last_post_subject'] !== $subject)

Line 2107Line 2098
					}

// Update the user name if poster is anonymous... just in case a moderator changed it

					}

// Update the user name if poster is anonymous... just in case a moderator changed it

					if ($data['poster_id'] == ANONYMOUS)

					if ($data_ary['poster_id'] == ANONYMOUS)

					{
$sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape($username) . "'";
}

					{
$sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape($username) . "'";
}

Line 2118Line 2109

// Update forum stats
$where_sql = array(


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

		POSTS_TABLE		=> 'post_id = ' . $data_ary['post_id'],
TOPICS_TABLE => 'topic_id = ' . $data_ary['topic_id'],
FORUMS_TABLE => 'forum_id = ' . $data_ary['forum_id'],

		USERS_TABLE		=> 'user_id = ' . $poster_id
);


		USERS_TABLE		=> 'user_id = ' . $poster_id
);


Line 2137Line 2128
	if ($topic_type == POST_GLOBAL)
{
$sql = 'DELETE FROM ' . TOPICS_TABLE . '

	if ($topic_type == POST_GLOBAL)
{
$sql = 'DELETE FROM ' . TOPICS_TABLE . '

			WHERE topic_moved_id = ' . $data['topic_id'];

			WHERE topic_moved_id = ' . $data_ary['topic_id'];

		$db->sql_query($sql);
}


		$db->sql_query($sql);
}


Line 2145Line 2136
	$db->sql_transaction('commit');

// Delete draft if post was loaded...

	$db->sql_transaction('commit');

// Delete draft if post was loaded...

	$draft_id = request_var('draft_loaded', 0);

	$draft_id = $request->variable('draft_loaded', 0);

	if ($draft_id)
{
$sql = 'DELETE FROM ' . DRAFTS_TABLE . "

	if ($draft_id)
{
$sql = 'DELETE FROM ' . DRAFTS_TABLE . "

Line 2155Line 2146
	}

// Index message contents

	}

// Index message contents

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

	if ($update_search_index && $data_ary['enable_indexing'])

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

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

Line 2166Line 2157
		}

$error = false;

		}

$error = false;

		$search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user);

		$search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher);


if ($error)
{
trigger_error($error);
}



if ($error)
{
trigger_error($error);
}


		$search->index($mode, $data['post_id'], $data['message'], $subject, $poster_id, $data['forum_id']);

		$search->index($mode, $data_ary['post_id'], $data_ary['message'], $subject, $poster_id, $data_ary['forum_id']);

	}

// Topic Notification, do not change if moderator is changing other users posts...
if ($user->data['user_id'] == $poster_id)
{

	}

// Topic Notification, do not change if moderator is changing other users posts...
if ($user->data['user_id'] == $poster_id)
{

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

		if (!$data_ary['notify_set'] && $data_ary['notify'])

		{
$sql = 'INSERT INTO ' . TOPICS_WATCH_TABLE . ' (user_id, topic_id)

		{
$sql = 'INSERT INTO ' . TOPICS_WATCH_TABLE . ' (user_id, topic_id)

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

				VALUES (' . $user->data['user_id'] . ', ' . $data_ary['topic_id'] . ')';

			$db->sql_query($sql);
}

			$db->sql_query($sql);
}

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

		else if (($config['email_enable'] || $config['jab_enable']) && $data_ary['notify_set'] && !$data_ary['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'] . '

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

					AND topic_id = ' . $data_ary['topic_id'];

			$db->sql_query($sql);
}
}

			$db->sql_query($sql);
}
}

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

		markread('post', $data_ary['forum_id'], $data_ary['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', $data_ary['forum_id'], $data_ary['topic_id'], time());


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


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

Line 2210Line 2201
		$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 = ' . $data_ary['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 2225Line 2216
		// Update forum info
$sql = 'SELECT forum_last_post_time
FROM ' . FORUMS_TABLE . '

		// Update forum info
$sql = 'SELECT forum_last_post_time
FROM ' . FORUMS_TABLE . '

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

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

	}

// If a username was supplied or the poster is a guest, we will use the supplied username.

	}

// If a username was supplied or the poster is a guest, we will use the supplied username.

Line 2239Line 2230
	$username = ($username !== '' || !$user->data['is_registered']) ? $username : $user->data['username'];

// Send Notifications

	$username = ($username !== '' || !$user->data['is_registered']) ? $username : $user->data['username'];

// Send Notifications

	$notification_data = array_merge($data, array(
'topic_title' => (isset($data['topic_title'])) ? $data['topic_title'] : $subject,

	$notification_data = array_merge($data_ary, array(
'topic_title' => (isset($data_ary['topic_title'])) ? $data_ary['topic_title'] : $subject,

		'post_username'		=> $username,
'poster_id' => $poster_id,

		'post_username'		=> $username,
'poster_id' => $poster_id,

		'post_text'			=> $data['message'],

		'post_text'			=> $data_ary['message'],

		'post_time'			=> $current_time,
'post_subject' => $subject,
));


		'post_time'			=> $current_time,
'post_subject' => $subject,
));


 
	/* @var $phpbb_notifications \phpbb\notification\manager */

	$phpbb_notifications = $phpbb_container->get('notification_manager');

if ($post_visibility == ITEM_APPROVED)

	$phpbb_notifications = $phpbb_container->get('notification_manager');

if ($post_visibility == ITEM_APPROVED)

Line 2351Line 2343

$params = $add_anchor = '';



$params = $add_anchor = '';


	if ($post_visibility == ITEM_APPROVED)



	if ($post_visibility == ITEM_APPROVED ||
($auth->acl_get('m_softdelete', $data_ary['forum_id']) && $post_visibility == ITEM_DELETED) ||
($auth->acl_get('m_approve', $data_ary['forum_id']) && in_array($post_visibility, array(ITEM_UNAPPROVED, ITEM_REAPPROVE))))

	{

	{

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

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


if ($mode != 'post')
{


if ($mode != 'post')
{

			$params .= '&amp;p=' . $data['post_id'];
$add_anchor = '#p' . $data['post_id'];

			$params .= '&amp;p=' . $data_ary['post_id'];
$add_anchor = '#p' . $data_ary['post_id'];

		}
}
else if ($mode != 'post' && $post_mode != 'edit_first_post' && $post_mode != 'edit_topic')
{

		}
}
else if ($mode != 'post' && $post_mode != 'edit_first_post' && $post_mode != 'edit_topic')
{

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

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

	}

$url = (!$params) ? "{$phpbb_root_path}viewforum.$phpEx" : "{$phpbb_root_path}viewtopic.$phpEx";

	}

$url = (!$params) ? "{$phpbb_root_path}viewforum.$phpEx" : "{$phpbb_root_path}viewtopic.$phpEx";

	$url = append_sid($url, 'f=' . $data['forum_id'] . $params) . $add_anchor;

	$url = append_sid($url, 'f=' . $data_ary['forum_id'] . $params) . $add_anchor;





 
	$poll = $poll_ary;
$data = $data_ary;

	/**
* This event is used for performing actions directly after a post or topic
* has been submitted. When a new topic is posted, the topic ID is

	/**
* This event is used for performing actions directly after a post or topic
* has been submitted. When a new topic is posted, the topic ID is

Line 2406Line 2402
		'url',
);
extract($phpbb_dispatcher->trigger_event('core.submit_post_end', compact($vars)));

		'url',
);
extract($phpbb_dispatcher->trigger_event('core.submit_post_end', compact($vars)));

 
	$data_ary = $data;
$poll_ary = $poll;
unset($data);
unset($poll);


return $url;
}


return $url;
}

Line 2426Line 2426
*/
function phpbb_bump_topic($forum_id, $topic_id, $post_data, $bump_time = false)
{

*/
function phpbb_bump_topic($forum_id, $topic_id, $post_data, $bump_time = false)
{

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

	global $config, $db, $user, $phpEx, $phpbb_root_path, $phpbb_log;


if ($bump_time === false)
{


if ($bump_time === false)
{

Line 2505Line 2505
		update_forum_tracking_info($forum_id, $forum_last_post_time, $f_mark_time, false);
}


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





	$phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_BUMP_TOPIC', false, array(
'forum_id' => $forum_id,
'topic_id' => $topic_id,
$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']}";



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


Line 2543Line 2547
function phpbb_handle_post_delete($forum_id, $topic_id, $post_id, &$post_data, $is_soft = false, $delete_reason = '')
{
global $user, $auth, $config, $request;

function phpbb_handle_post_delete($forum_id, $topic_id, $post_id, &$post_data, $is_soft = false, $delete_reason = '')
{
global $user, $auth, $config, $request;

	global $phpbb_root_path, $phpEx;

	global $phpbb_root_path, $phpEx, $phpbb_log;


$perm_check = ($is_soft) ? 'softdelete' : 'delete';



$perm_check = ($is_soft) ? 'softdelete' : 'delete';


Line 2578Line 2582

if ($next_post_id === false)
{


if ($next_post_id === false)
{

				add_log('mod', $forum_id, $topic_id, (($is_soft) ? 'LOG_SOFTDELETE_TOPIC' : 'LOG_DELETE_TOPIC'), $post_data['topic_title'], $post_username, $delete_reason);







				$phpbb_log->add('mod', $user->data['user_id'], $user->ip, (($is_soft) ? 'LOG_SOFTDELETE_TOPIC' : 'LOG_DELETE_TOPIC'), false, array(
'forum_id' => $forum_id,
'topic_id' => $topic_id,
$post_data['topic_title'],
$post_username,
$delete_reason
));


$meta_info = append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id");
$message = $user->lang['POST_DELETED'];
}
else
{


$meta_info = append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id");
$message = $user->lang['POST_DELETED'];
}
else
{

				add_log('mod', $forum_id, $topic_id, (($is_soft) ? 'LOG_SOFTDELETE_POST' : 'LOG_DELETE_POST'), $post_data['post_subject'], $post_username, $delete_reason);








				$phpbb_log->add('mod', $user->data['user_id'], $user->ip, (($is_soft) ? 'LOG_SOFTDELETE_POST' : 'LOG_DELETE_POST'), false, array(
'forum_id' => $forum_id,
'topic_id' => $topic_id,
'post_id' => $post_id,
$post_data['post_subject'],
$post_username,
$delete_reason
));


$meta_info = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;p=$next_post_id") . "#p$next_post_id";
$message = $user->lang['POST_DELETED'];


$meta_info = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;p=$next_post_id") . "#p$next_post_id";
$message = $user->lang['POST_DELETED'];