Vergleich inc/class_moderation.php - 1.8.5 - 1.8.38

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 13Zeile 13
	/**
* Close one or more threads
*

	/**
* Close one or more threads
*

	 * @param array Thread IDs

	 * @param array|int $tids Thread ID(s)

	 * @return boolean true
*/
function close_threads($tids)

	 * @return boolean true
*/
function close_threads($tids)

Zeile 43Zeile 43
	/**
* Open one or more threads
*

	/**
* Open one or more threads
*

	 * @param int Thread IDs
* @return boolean true

	 * @param array|int $tids Thread ID(s)
* @return boolean

	 */

	 */





	function open_threads($tids)

	function open_threads($tids)

	{
global $db, $plugins;

if(!is_array($tids))
{
$tids = array($tids);
}

if(empty($tids))
{
return false;
}

// Make sure we only have valid values
$tids = array_map('intval', $tids);

$plugins->run_hooks("class_moderation_open_threads", $tids);


	{
global $db, $plugins;

if(!is_array($tids))
{
$tids = array($tids);
}

if(empty($tids))
{
return false;
}

// Make sure we only have valid values
$tids = array_map('intval', $tids);

$plugins->run_hooks("class_moderation_open_threads", $tids);


		$tid_list = implode(',', $tids);

$closethread = array(
"closed" => 0,
);

		$tid_list = implode(',', $tids);

$closethread = array(
"closed" => 0,
);

		$db->update_query("threads", $closethread, "tid IN ($tid_list)");

		$db->update_query("threads", $closethread, "tid IN ($tid_list)");


return true;
}


return true;
}

Zeile 79Zeile 79
	/**
* Stick one or more threads
*

	/**
* Stick one or more threads
*

	 * @param int Thread IDs
* @return boolean true

	 * @param array|int $tids Thread ID(s)
* @return boolean

	 */
function stick_threads($tids)
{

	 */
function stick_threads($tids)
{

Zeile 100Zeile 100
		$tids = array_map('intval', $tids);

$plugins->run_hooks("class_moderation_stick_threads", $tids);

		$tids = array_map('intval', $tids);

$plugins->run_hooks("class_moderation_stick_threads", $tids);





		$tid_list = implode(',', $tids);

$stickthread = array(
"sticky" => 1,

		$tid_list = implode(',', $tids);

$stickthread = array(
"sticky" => 1,

		);

		);

		$db->update_query("threads", $stickthread, "tid IN ($tid_list)");

		$db->update_query("threads", $stickthread, "tid IN ($tid_list)");


return true;
}

/**


return true;
}

/**

	 * Unstick one or more thread
*

	 * Unstick one or more thread
*

	 * @param int Thread IDs
* @return boolean true

	 * @param array|int $tids Thread ID(s)
* @return boolean

	 */
function unstick_threads($tids)
{

	 */
function unstick_threads($tids)
{

Zeile 124Zeile 124
		if(!is_array($tids))
{
$tids = array($tids);

		if(!is_array($tids))
{
$tids = array($tids);

		}


		}


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

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

Zeile 137Zeile 137
		$plugins->run_hooks("class_moderation_unstick_threads", $tids);

$tid_list = implode(',', $tids);

		$plugins->run_hooks("class_moderation_unstick_threads", $tids);

$tid_list = implode(',', $tids);





		$unstickthread = array(
"sticky" => 0,
);

		$unstickthread = array(
"sticky" => 0,
);

Zeile 149Zeile 149
	/**
* Remove redirects that redirect to the specified thread
*

	/**
* Remove redirects that redirect to the specified thread
*

	 * @param int Thread ID of the thread
* @return boolean true

	 * @param int $tid Thread ID of the thread
* @return boolean

	 */
function remove_redirects($tid)
{

	 */
function remove_redirects($tid)
{

Zeile 177Zeile 177
	/**
* Delete a thread
*

	/**
* Delete a thread
*

	 * @param int Thread ID of the thread
* @return boolean true

	 * @param int $tid Thread ID of the thread
* @return boolean

	 */
function delete_thread($tid)
{
global $db, $cache, $plugins;

	 */
function delete_thread($tid)
{
global $db, $cache, $plugins;





		$tid = (int)$tid;

		$tid = (int)$tid;





		$plugins->run_hooks("class_moderation_delete_thread_start", $tid);

		$plugins->run_hooks("class_moderation_delete_thread_start", $tid);





		$thread = get_thread($tid);
if(!$thread)
{

		$thread = get_thread($tid);
if(!$thread)
{

Zeile 196Zeile 196
		$forum = get_forum($thread['fid']);

$userposts = array();

		$forum = get_forum($thread['fid']);

$userposts = array();





		// Find the pid, uid, visibility, and forum post count status
$query = $db->simple_select('posts', 'pid, uid, visible', "tid='{$tid}'");
$pids = array();

		// Find the pid, uid, visibility, and forum post count status
$query = $db->simple_select('posts', 'pid, uid, visible', "tid='{$tid}'");
$pids = array();

Zeile 215Zeile 215

// If the post is unapproved, count it!
if(($post['visible'] == 0 && $thread['visible'] != -1) || $thread['visible'] == 0)


// If the post is unapproved, count it!
if(($post['visible'] == 0 && $thread['visible'] != -1) || $thread['visible'] == 0)

			{

			{

				$num_unapproved_posts++;
}
elseif($post['visible'] == -1 || $thread['visible'] == -1)

				$num_unapproved_posts++;
}
elseif($post['visible'] == -1 || $thread['visible'] == -1)

Zeile 225Zeile 225
			else
{
$num_approved_posts++;

			else
{
$num_approved_posts++;





				// Count the post counts for each user to be subtracted
if($forum['usepostcounts'] != 0)
{
if(!isset($userposts[$post['uid']]['num_posts']))

				// Count the post counts for each user to be subtracted
if($forum['usepostcounts'] != 0)
{
if(!isset($userposts[$post['uid']]['num_posts']))

					{

					{

						$userposts[$post['uid']]['num_posts'] = 0;
}
++$userposts[$post['uid']]['num_posts'];
}

						$userposts[$post['uid']]['num_posts'] = 0;
}
++$userposts[$post['uid']]['num_posts'];
}

			}

			}

		}

if($forum['usethreadcounts'] != 0 && substr($thread['closed'], 0, 6) != 'moved|')

		}

if($forum['usethreadcounts'] != 0 && substr($thread['closed'], 0, 6) != 'moved|')

Zeile 254Zeile 254
			{
foreach($userposts as $uid => $subtract)
{

			{
foreach($userposts as $uid => $subtract)
{

					$update_array = array(
"postnum" => "-{$subtract['num_posts']}",
"threadnum" => "-{$subtract['num_threads']}",
);









					$update_array = array();

if(isset($subtract['num_posts']))
{
$update_array['postnum'] = "-{$subtract['num_posts']}";
}

if(isset($subtract['num_threads']))
{
$update_array['threadnum'] = "-{$subtract['num_threads']}";
}


					update_user_counters($uid, $update_array);
}
}

					update_user_counters($uid, $update_array);
}
}

Zeile 323Zeile 331
		// Update forum count
update_forum_counters($thread['fid'], $updated_counters);
update_forum_lastpost($thread['fid']);

		// Update forum count
update_forum_counters($thread['fid'], $updated_counters);
update_forum_lastpost($thread['fid']);

 
		mark_reports($tid, 'thread');


$plugins->run_hooks("class_moderation_delete_thread", $tid);


$plugins->run_hooks("class_moderation_delete_thread", $tid);


return true;
}

/**


return true;
}

/**

	 * Delete a poll
*

	 * Delete a poll
*

	 * @param int Poll id
* @return boolean true

	 * @param int $pid Poll id
* @return boolean

	 */
function delete_poll($pid)
{

	 */
function delete_poll($pid)
{

Zeile 342Zeile 351
		$pid = (int)$pid;

if(empty($pid))

		$pid = (int)$pid;

if(empty($pid))

		{
return false;
}

		{
return false;
}


$plugins->run_hooks("class_moderation_delete_poll", $pid);



$plugins->run_hooks("class_moderation_delete_poll", $pid);


Zeile 357Zeile 366

return true;
}


return true;
}





	/**
* Approve one or more threads
*

	/**
* Approve one or more threads
*

	 * @param array Thread IDs
* @return boolean true

	 * @param array|int $tids Thread ID(s)
* @return boolean

	 */
function approve_threads($tids)
{

	 */
function approve_threads($tids)
{

Zeile 371Zeile 380
		if(!is_array($tids))
{
$tids = array($tids);

		if(!is_array($tids))
{
$tids = array($tids);

		}


		}


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

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

Zeile 383Zeile 392

$tid_list = $forum_counters = $user_counters = $posts_to_approve = array();



$tid_list = $forum_counters = $user_counters = $posts_to_approve = array();


		foreach($tids as $tid)




		$tids_list = implode(",", $tids);
$query = $db->simple_select("threads", "*", "tid IN ($tids_list)");

while($thread = $db->fetch_array($query))

		{

		{

			$thread = get_thread($tid);
if(!$thread || $thread['visible'] == 1 || $thread['visible'] == -1)

			if($thread['visible'] == 1 || $thread['visible'] == -1)


			{
continue;
}

			{
continue;
}

Zeile 420Zeile 431
			if($forum['usepostcounts'] != 0)
{
// On approving thread restore user post counts

			if($forum['usepostcounts'] != 0)
{
// On approving thread restore user post counts

				$query = $db->simple_select("posts", "COUNT(pid) as posts, uid", "tid='{$tid}' AND (visible='1' OR pid='{$thread['firstpost']}') AND uid > 0 GROUP BY uid");
while($counter = $db->fetch_array($query))

				$query2 = $db->simple_select("posts", "COUNT(pid) as posts, uid", "tid='{$thread['tid']}' AND (visible='1' OR pid='{$thread['firstpost']}') AND uid > 0 GROUP BY uid");
while($counter = $db->fetch_array($query2))

				{

				{

 
					if(!isset($user_counters[$counter['uid']]))
{
$user_counters[$counter['uid']] = array(
'num_posts' => 0,
'num_threads' => 0
);
}

					$user_counters[$counter['uid']]['num_posts'] += $counter['posts'];
}
}

					$user_counters[$counter['uid']]['num_posts'] += $counter['posts'];
}
}

Zeile 501Zeile 519

/**
* Unapprove one or more threads


/**
* Unapprove one or more threads

	 *
* @param array Thread IDs
* @return boolean true

	 *
* @param array|int $tids Thread ID(s)
* @return boolean

	 */
function unapprove_threads($tids)
{
global $db, $cache, $plugins;

if(!is_array($tids))

	 */
function unapprove_threads($tids)
{
global $db, $cache, $plugins;

if(!is_array($tids))

		{

		{

			$tids = array($tids);
}


			$tids = array($tids);
}


Zeile 533Zeile 551

$forum_counters = $user_counters = $posts_to_unapprove = array();



$forum_counters = $user_counters = $posts_to_unapprove = array();


		foreach($tids as $tid)




		$tids_list = implode(",", $tids);
$query = $db->simple_select("threads", "*", "tid IN ($tids_list)");

while($thread = $db->fetch_array($query))

		{

		{

			$thread = get_thread($tid);

 
			$forum = get_forum($thread['fid']);

if($thread['visible'] == 1 || $thread['visible'] == -1)

			$forum = get_forum($thread['fid']);

if($thread['visible'] == 1 || $thread['visible'] == -1)

Zeile 555Zeile 575
				if(!isset($user_counters[$thread['uid']]))
{
$user_counters[$thread['uid']] = array(

				if(!isset($user_counters[$thread['uid']]))
{
$user_counters[$thread['uid']] = array(

						'num_posts' => 0,
'num_threads' => 0
);
}

						'num_posts' => 0,
'num_threads' => 0
);
}


++$forum_counters[$forum['fid']]['num_unapprovedthreads'];
$forum_counters[$forum['fid']]['num_unapprovedposts'] += $thread['replies']+$thread['deletedposts']+1;


++$forum_counters[$forum['fid']]['num_unapprovedthreads'];
$forum_counters[$forum['fid']]['num_unapprovedposts'] += $thread['replies']+$thread['deletedposts']+1;

Zeile 579Zeile 599
				// On unapproving thread update user post counts
if($thread['visible'] == 1 && $forum['usepostcounts'] != 0)
{

				// On unapproving thread update user post counts
if($thread['visible'] == 1 && $forum['usepostcounts'] != 0)
{

					$query = $db->simple_select("posts", "COUNT(pid) AS posts, uid", "tid='{$tid}' AND (visible='1' OR pid='{$thread['firstpost']}') AND uid > 0 GROUP BY uid");
while($counter = $db->fetch_array($query))

					$query2 = $db->simple_select("posts", "COUNT(pid) AS posts, uid", "tid='{$thread['tid']}' AND (visible='1' OR pid='{$thread['firstpost']}') AND uid > 0 GROUP BY uid");
while($counter = $db->fetch_array($query2))

					{

					{

 
						if(!isset($user_counters[$counter['uid']]))
{
$user_counters[$counter['uid']] = array(
'num_posts' => 0,
'num_threads' => 0
);
}

						$user_counters[$counter['uid']]['num_posts'] += $counter['posts'];
}
}

						$user_counters[$counter['uid']]['num_posts'] += $counter['posts'];
}
}

Zeile 593Zeile 620

}
$posts_to_unapprove[] = $thread['firstpost'];


}
$posts_to_unapprove[] = $thread['firstpost'];

		}

		}


$approve = array(
"visible" => 0


$approve = array(
"visible" => 0

Zeile 607Zeile 634
			$redirect_tids[] = $redirect_tid;
}
if(!empty($redirect_tids))

			$redirect_tids[] = $redirect_tid;
}
if(!empty($redirect_tids))

		{

		{

			$this->unapprove_threads($redirect_tids);

			$this->unapprove_threads($redirect_tids);

		}

		}

		if(!empty($posts_to_unapprove))
{
$db->update_query("posts", $approve, "pid IN (".implode(',', $posts_to_unapprove).")");

		if(!empty($posts_to_unapprove))
{
$db->update_query("posts", $approve, "pid IN (".implode(',', $posts_to_unapprove).")");

		}


		}


		$plugins->run_hooks("class_moderation_unapprove_threads", $tids);

if(!empty($forum_counters))
{
foreach($forum_counters as $fid => $counters)

		$plugins->run_hooks("class_moderation_unapprove_threads", $tids);

if(!empty($forum_counters))
{
foreach($forum_counters as $fid => $counters)

			{

			{

				// Update stats
$update_array = array(
"threads" => "-{$counters['num_threads']}",

				// Update stats
$update_array = array(
"threads" => "-{$counters['num_threads']}",

Zeile 632Zeile 659
				);
update_forum_counters($fid, $update_array);
update_forum_lastpost($fid);

				);
update_forum_counters($fid, $update_array);
update_forum_lastpost($fid);

			}
}


			}
}


		if(!empty($user_counters))
{
foreach($user_counters as $uid => $counters)

		if(!empty($user_counters))
{
foreach($user_counters as $uid => $counters)

Zeile 653Zeile 680
	/**
* Delete a specific post
*

	/**
* Delete a specific post
*

	 * @param int Post ID
* @return boolean true

	 * @param int $pid Post ID
* @return boolean

	 */
function delete_post($pid)
{

	 */
function delete_post($pid)
{

Zeile 671Zeile 698
		");
$post = $db->fetch_array($query);
if(!$post)

		");
$post = $db->fetch_array($query);
if(!$post)

		{

		{

			return false;
}


			return false;
}


Zeile 698Zeile 725

// Update unapproved post count
if($post['visible'] == 0)


// Update unapproved post count
if($post['visible'] == 0)

		{
$update_array = array(
"unapprovedposts" => "-1"
);
}
elseif($post['visible'] == -1)
{
$update_array = array(

		{
$update_array = array(
"unapprovedposts" => "-1"
);
}
elseif($post['visible'] == -1)
{
$update_array = array(

				"deletedposts" => "-1"
);
}

				"deletedposts" => "-1"
);
}

Zeile 726Zeile 753
		{
$update_array = array(
"unapprovedposts" => "-1"

		{
$update_array = array(
"unapprovedposts" => "-1"

			);

			);

		}
elseif($post['visible'] == -1 || $post['threadvisible'] == -1)
{
$update_array = array(
"deletedposts" => "-1"

		}
elseif($post['visible'] == -1 || $post['threadvisible'] == -1)
{
$update_array = array(
"deletedposts" => "-1"

			);

			);

		}
else
{
$update_array = array(
"posts" => "-1"
);

		}
else
{
$update_array = array(
"posts" => "-1"
);

		}


		}


		update_forum_counters($post['fid'], $update_array);
update_forum_lastpost($post['fid']);

return true;
}

		update_forum_counters($post['fid'], $update_array);
update_forum_lastpost($post['fid']);

return true;
}





	/**
* Merge posts within thread
*

	/**
* Merge posts within thread
*

	 * @param array Post IDs to be merged
* @param int Thread ID (Set to 0 if posts from multiple threads are
* selected)

	 * @param array $pids Post IDs to be merged
* @param int $tid Thread ID (Set to 0 if posts from multiple threads are selected)


	 * @return int ID of the post into which all other posts are merged
*/

	 * @return int ID of the post into which all other posts are merged
*/

	function merge_posts($pids, $tid=0, $sep="new_line")

	function merge_posts($pids=array(), $tid=0, $sep="new_line")

	{
global $db, $plugins;


	{
global $db, $plugins;


Zeile 779Zeile 805
			LEFT JOIN ".TABLE_PREFIX."attachments a ON (a.pid=p.pid AND a.visible=1)
WHERE p.pid IN($pidin)
GROUP BY p.pid

			LEFT JOIN ".TABLE_PREFIX."attachments a ON (a.pid=p.pid AND a.visible=1)
WHERE p.pid IN($pidin)
GROUP BY p.pid

			ORDER BY p.dateline ASC

			ORDER BY p.dateline ASC, p.pid ASC

		");
$message = '';
$threads = $forum_counters = $thread_counters = $user_counters = array();

		");
$message = '';
$threads = $forum_counters = $thread_counters = $user_counters = array();

Zeile 787Zeile 813
		{
$threads[$post['tid']] = $post['tid'];
if(!isset($thread_counters[$post['tid']]))

		{
$threads[$post['tid']] = $post['tid'];
if(!isset($thread_counters[$post['tid']]))

			{

			{

				$thread_counters[$post['tid']] = array(
'replies' => 0,
'unapprovedposts' => 0,

				$thread_counters[$post['tid']] = array(
'replies' => 0,
'unapprovedposts' => 0,

Zeile 802Zeile 828
				$fid = $post['fid'];
$mastertid = $post['tid'];
$first = 0;

				$fid = $post['fid'];
$mastertid = $post['tid'];
$first = 0;

 
				$visible = $post['visible'];

			}
else
{

			}
else
{

Zeile 845Zeile 872
					{
--$user_counters[$post['uid']]['num_threads'];
}

					{
--$user_counters[$post['uid']]['num_threads'];
}

 
					$thread_counters[$post['tid']]['attachmentcount'] -= $post['attachmentcount'];

				}
elseif($post['visible'] == 0)
{

				}
elseif($post['visible'] == 0)
{

Zeile 856Zeile 884
					// Subtract 1 deleted post from post's thread
--$thread_counters[$post['tid']]['deletedposts'];
}

					// Subtract 1 deleted post from post's thread
--$thread_counters[$post['tid']]['deletedposts'];
}

				$thread_counters[$post['tid']]['attachmentcount'] -= $post['attachmentcount'];

 

// Subtract 1 post from post's forum
if($post['threadvisible'] == 1 && $post['visible'] == 1)


// Subtract 1 post from post's forum
if($post['threadvisible'] == 1 && $post['visible'] == 1)

Zeile 870Zeile 897
				else
{
--$forum_counters[$post['fid']]['deletedposts'];

				else
{
--$forum_counters[$post['fid']]['deletedposts'];

 
				}

// Add attachment count to thread
if($visible == 1)
{
$thread_counters[$mastertid]['attachmentcount'] += $post['attachmentcount'];

				}
}
}

				}
}
}

Zeile 895Zeile 928
		{
// In some cases the first post of a thread changes
// Therefore resync the visible field to make sure they're the same if they're not

		{
// In some cases the first post of a thread changes
// Therefore resync the visible field to make sure they're the same if they're not

			$query = $db->simple_select("posts", "pid, uid, visible", "tid='{$thread['tid']}'", array('order_by' => 'dateline', 'order_dir' => 'asc', 'limit' => 1));

			$query = $db->simple_select("posts", "pid, uid, visible", "tid='{$thread['tid']}'", array('order_by' => 'dateline, pid', 'limit' => 1));

			$new_firstpost = $db->fetch_array($query);
if($thread['visible'] != $new_firstpost['visible'])
{

			$new_firstpost = $db->fetch_array($query);
if($thread['visible'] != $new_firstpost['visible'])
{

Zeile 953Zeile 986
					'unapprovedposts' => signed($counters['unapprovedposts']),
'deletedposts' => signed($counters['deletedposts']),
'attachmentcount' => signed($counters['attachmentcount'])

					'unapprovedposts' => signed($counters['unapprovedposts']),
'deletedposts' => signed($counters['deletedposts']),
'attachmentcount' => signed($counters['attachmentcount'])

				);
update_thread_counters($tid, $counters);
update_last_post($tid);
}
}

if(!empty($forum_counters))
{

				);
update_thread_counters($tid, $counters);
update_last_post($tid);
}
}

if(!empty($forum_counters))
{

			foreach($forum_counters as $fid => $counters)
{
$updated_forum_stats = array(

			foreach($forum_counters as $fid => $counters)
{
$updated_forum_stats = array(

Zeile 991Zeile 1024
	/**
* Move/copy thread
*

	/**
* Move/copy thread
*

	 * @param int Thread to be moved
* @param int Destination forum
* @param string Method of movement (redirect, copy, move)
* @param int Expiry timestamp for redirect

	 * @param int $tid Thread to be moved
* @param int $new_fid Destination forum
* @param string $method Method of movement (redirect, copy, move)
* @param int $redirect_expire Expiry timestamp for redirect

	 * @return int Thread ID
*/
function move_thread($tid, $new_fid, $method="redirect", $redirect_expire=0)

	 * @return int Thread ID
*/
function move_thread($tid, $new_fid, $method="redirect", $redirect_expire=0)

Zeile 1054Zeile 1087
				);
$db->update_query("threads", $changefid, "tid='$tid'");
$db->update_query("posts", $changefid, "tid='$tid'");

				);
$db->update_query("threads", $changefid, "tid='$tid'");
$db->update_query("posts", $changefid, "tid='$tid'");


// If the thread has a prefix and the destination forum doesn't accept that prefix, remove the prefix
if($thread['prefix'] != 0)
{
switch($db->type)
{
case "pgsql":
case "sqlite":
$query = $db->simple_select("threadprefixes", "COUNT(*) as num_prefixes", "(','||forums||',' LIKE '%,$new_fid,%' OR forums='-1') AND pid='".$thread['prefix']."'");
break;
default:
$query = $db->simple_select("threadprefixes", "COUNT(*) as num_prefixes", "(CONCAT(',',forums,',') LIKE '%,$new_fid,%' OR forums='-1') AND pid='".$thread['prefix']."'");
}
if($db->fetch_field($query, "num_prefixes") == 0)
{
$sqlarray = array(
"prefix" => 0,
);
$db->update_query("threads", $sqlarray, "tid='$tid'");
}
}

$threadarray = array(


// If the thread has a prefix and the destination forum doesn't accept that prefix, remove the prefix
if($thread['prefix'] != 0)
{
switch($db->type)
{
case "pgsql":
case "sqlite":
$query = $db->simple_select("threadprefixes", "COUNT(*) as num_prefixes", "(','||forums||',' LIKE '%,$new_fid,%' OR forums='-1') AND pid='".$thread['prefix']."'");
break;
default:
$query = $db->simple_select("threadprefixes", "COUNT(*) as num_prefixes", "(CONCAT(',',forums,',') LIKE '%,$new_fid,%' OR forums='-1') AND pid='".$thread['prefix']."'");
}
if($db->fetch_field($query, "num_prefixes") == 0)
{
$sqlarray = array(
"prefix" => 0,
);
$db->update_query("threads", $sqlarray, "tid='$tid'");
}
}

$threadarray = array(

					"fid" => $thread['fid'],

					"fid" => $thread['fid'],

					"subject" => $db->escape_string($thread['subject']),
"icon" => $thread['icon'],
"uid" => $thread['uid'],
"username" => $db->escape_string($thread['username']),
"dateline" => $thread['dateline'],
"lastpost" => $thread['lastpost'],

					"subject" => $db->escape_string($thread['subject']),
"icon" => $thread['icon'],
"uid" => $thread['uid'],
"username" => $db->escape_string($thread['username']),
"dateline" => $thread['dateline'],
"lastpost" => $thread['lastpost'],

					"lastposteruid" => $thread['lastposteruid'],
"lastposter" => $db->escape_string($thread['lastposter']),
"views" => 0,
"replies" => 0,
"closed" => "moved|$tid",

					"lastposteruid" => $thread['lastposteruid'],
"lastposter" => $db->escape_string($thread['lastposter']),
"views" => 0,
"replies" => 0,
"closed" => "moved|$tid",

					"sticky" => $thread['sticky'],
"visible" => (int)$thread['visible'],

					"sticky" => $thread['sticky'],
"visible" => (int)$thread['visible'],

					"notes" => ''
);
$redirect_tid = $db->insert_query("threads", $threadarray);
if($redirect_expire)
{
$this->expire_thread($redirect_tid, $redirect_expire);

					"notes" => ''
);
$redirect_tid = $db->insert_query("threads", $threadarray);
if($redirect_expire)
{
$this->expire_thread($redirect_tid, $redirect_expire);

				}

				}


// If we're moving back to a forum where we left a redirect, delete the rediect
$query = $db->simple_select("threads", "tid", "closed LIKE 'moved|".(int)$tid."' AND fid='".(int)$new_fid."'");


// If we're moving back to a forum where we left a redirect, delete the rediect
$query = $db->simple_select("threads", "tid", "closed LIKE 'moved|".(int)$tid."' AND fid='".(int)$new_fid."'");

Zeile 1129Zeile 1162
					"attachmentcount" => $thread['attachmentcount'],
"prefix" => $thread['prefix'],
"notes" => ''

					"attachmentcount" => $thread['attachmentcount'],
"prefix" => $thread['prefix'],
"notes" => ''

				);

$arguments = array("tid" => $tid, "new_fid" => $new_fid);
$plugins->run_hooks("class_moderation_copy_thread", $arguments);

				);

$arguments = array("tid" => $tid, "new_fid" => $new_fid);
$plugins->run_hooks("class_moderation_copy_thread", $arguments);


// If the thread has a prefix and the destination forum doesn't accept that prefix, don't copy the prefix
if($threadarray['prefix'] != 0)


// If the thread has a prefix and the destination forum doesn't accept that prefix, don't copy the prefix
if($threadarray['prefix'] != 0)

Zeile 1164Zeile 1197
						'question' => $db->escape_string($poll['question']),
'dateline' => $poll['dateline'],
'options' => $db->escape_string($poll['options']),

						'question' => $db->escape_string($poll['question']),
'dateline' => $poll['dateline'],
'options' => $db->escape_string($poll['options']),

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

						'votes' => $db->escape_string($poll['votes']),

						'numoptions' => $poll['numoptions'],
'numvotes' => $poll['numvotes'],
'timeout' => $poll['timeout'],

						'numoptions' => $poll['numoptions'],
'numvotes' => $poll['numvotes'],
'timeout' => $poll['timeout'],

Zeile 1224Zeile 1257
							'pid' => $pid,
'uid' => $attachment['uid'],
'filename' => $db->escape_string($attachment['filename']),

							'pid' => $pid,
'uid' => $attachment['uid'],
'filename' => $db->escape_string($attachment['filename']),

							'filetype' => $attachment['filetype'],

							'filetype' => $db->escape_string($attachment['filetype']),

							'filesize' => $attachment['filesize'],

							'filesize' => $attachment['filesize'],

							'attachname' => $attachment['attachname'],

							'attachname' => $db->escape_string($attachment['attachname']),

							'downloads' => $attachment['downloads'],
'visible' => $attachment['visible'],

							'downloads' => $attachment['downloads'],
'visible' => $attachment['visible'],

							'thumbnail' => $attachment['thumbnail']

							'thumbnail' => $db->escape_string($attachment['thumbnail'])

						);
$new_aid = $db->insert_query("attachments", $attachment_array);


						);
$new_aid = $db->insert_query("attachments", $attachment_array);


Zeile 1304Zeile 1337
				$pcount -= $posters['posts'];
}
if(($forum['usepostcounts'] == 0 || $method == 'copy') && $newforum['usepostcounts'] == 1 && $thread['visible'] == 1)

				$pcount -= $posters['posts'];
}
if(($forum['usepostcounts'] == 0 || $method == 'copy') && $newforum['usepostcounts'] == 1 && $thread['visible'] == 1)

			{

			{

				$pcount += $posters['posts'];
}


				$pcount += $posters['posts'];
}


Zeile 1388Zeile 1421
	/**
* Merge one thread into another
*

	/**
* Merge one thread into another
*

	 * @param int Thread that will be merged into destination
* @param int Destination thread
* @param string New thread subject
* @return boolean true

	 * @param int $mergetid Thread that will be merged into destination
* @param int $tid Destination thread
* @param string $subject New thread subject
* @return boolean

	 */
function merge_threads($mergetid, $tid, $subject)
{

	 */
function merge_threads($mergetid, $tid, $subject)
{

Zeile 1401Zeile 1434
		$tid = (int)$tid;

if(!isset($mergethread['tid']) || $mergethread['tid'] != $mergetid)

		$tid = (int)$tid;

if(!isset($mergethread['tid']) || $mergethread['tid'] != $mergetid)

		{

		{

			$mergethread = get_thread($mergetid);
}
if(!isset($thread['tid']) || $thread['tid'] != $tid)
{
$thread = get_thread($tid);

			$mergethread = get_thread($mergetid);
}
if(!isset($thread['tid']) || $thread['tid'] != $tid)
{
$thread = get_thread($tid);

		}


		}


		if(!$mergethread || !$thread)
{
return false;

		if(!$mergethread || !$thread)
{
return false;

Zeile 1418Zeile 1451

$threadarray = array();
if(!$thread['poll'] && $mergethread['poll'])


$threadarray = array();
if(!$thread['poll'] && $mergethread['poll'])

		{

		{

			$threadarray['poll'] = $mergethread['poll'];
$sqlarray = array(
"tid" => $tid,
);
$db->update_query("polls", $sqlarray, "tid='".(int)$mergethread['tid']."'");

			$threadarray['poll'] = $mergethread['poll'];
$sqlarray = array(
"tid" => $tid,
);
$db->update_query("polls", $sqlarray, "tid='".(int)$mergethread['tid']."'");

		}

		}

		// Both the old and the new thread have polls? Remove one
elseif($mergethread['poll'])
{

		// Both the old and the new thread have polls? Remove one
elseif($mergethread['poll'])
{

Zeile 1462Zeile 1495
			"tid" => $tid,
"fid" => $thread['fid'],
"replyto" => 0,

			"tid" => $tid,
"fid" => $thread['fid'],
"replyto" => 0,

		);
$db->update_query("posts", $sqlarray, "tid='{$mergetid}'");


		);
$db->update_query("posts", $sqlarray, "tid='{$mergetid}'");


		$sqlarray = array(
"closed" => "moved|{$tid}",
);

		$sqlarray = array(
"closed" => "moved|{$tid}",
);

Zeile 1476Zeile 1509
		// Update the thread ratings
$new_numrating = $thread['numratings'] + $mergethread['numratings'];
$new_threadrating = $thread['totalratings'] + $mergethread['totalratings'];

		// Update the thread ratings
$new_numrating = $thread['numratings'] + $mergethread['numratings'];
$new_threadrating = $thread['totalratings'] + $mergethread['totalratings'];





		$threadarray["numratings"] = $new_numrating;
$threadarray["totalratings"] = $new_threadrating;
$db->update_query("threads", $threadarray, "tid = '{$tid}'");

		$threadarray["numratings"] = $new_numrating;
$threadarray["totalratings"] = $new_threadrating;
$db->update_query("threads", $threadarray, "tid = '{$tid}'");

Zeile 1488Zeile 1521
		while($subscription = $db->fetch_array($query))
{
if(!isset($subscriptions[$subscription['tid']]))

		while($subscription = $db->fetch_array($query))
{
if(!isset($subscriptions[$subscription['tid']]))

			{

			{

				$subscriptions[$subscription['tid']] = array();
}
$subscriptions[$subscription['tid']][] = $subscription['uid'];

				$subscriptions[$subscription['tid']] = array();
}
$subscriptions[$subscription['tid']][] = $subscription['uid'];

Zeile 1511Zeile 1544
			{
$update_array = array(
"tid" => $tid

			{
$update_array = array(
"tid" => $tid

				);

				);


$update_users = implode(",", $update_users);
$db->update_query("threadsubscriptions", $update_array, "tid = '{$mergetid}' AND uid IN ({$update_users})");


$update_users = implode(",", $update_users);
$db->update_query("threadsubscriptions", $update_array, "tid = '{$mergetid}' AND uid IN ({$update_users})");

Zeile 1542Zeile 1575

// In some cases the thread we may be merging with may cause us to have a new firstpost if it is an older thread
// Therefore resync the visible field to make sure they're the same if they're not


// In some cases the thread we may be merging with may cause us to have a new firstpost if it is an older thread
// Therefore resync the visible field to make sure they're the same if they're not

		$query = $db->simple_select("posts", "pid, uid, visible", "tid='{$tid}'", array('order_by' => 'dateline', 'order_dir' => 'asc', 'limit' => 1));

		$query = $db->simple_select("posts", "pid, uid, visible", "tid='{$tid}'", array('order_by' => 'dateline, pid', 'limit' => 1));

		$new_firstpost = $db->fetch_array($query);
if($thread['visible'] != $new_firstpost['visible'])
{

		$new_firstpost = $db->fetch_array($query);
if($thread['visible'] != $new_firstpost['visible'])
{

Zeile 1562Zeile 1595
			update_first_post($thread['tid']);
}


			update_first_post($thread['tid']);
}


		// Subtract merged thread from user counter
if($mergethread['visible'] == 1 && $forum_cache[$mergethread['fid']]['usethreadcounts'] == 1)
{
if(!isset($user_posts[$mergethread['uid']]['threadnum']))
{
$user_posts[$mergethread['uid']]['threadnum'] = 0;
}
--$user_posts[$mergethread['uid']]['threadnum'];
}

		// Attach moved posts to the first post
$db->update_query("posts", array('replyto' => $new_firstpost['pid']), "tid='{$tid}' AND replyto = 0 AND pid != '{$new_firstpost['pid']}'");









// Update thread count if thread has a new firstpost and is visible
if($thread['uid'] != $new_firstpost['uid'] && $thread['visible'] == 1 && $forum_cache[$thread['fid']]['usethreadcounts'] == 1)


// Update thread count if thread has a new firstpost and is visible
if($thread['uid'] != $new_firstpost['uid'] && $thread['visible'] == 1 && $forum_cache[$thread['fid']]['usethreadcounts'] == 1)

Zeile 1578Zeile 1604
			if(!isset($user_posts[$thread['uid']]['threadnum']))
{
$user_posts[$thread['uid']]['threadnum'] = 0;

			if(!isset($user_posts[$thread['uid']]['threadnum']))
{
$user_posts[$thread['uid']]['threadnum'] = 0;

			}

			}

			--$user_posts[$thread['uid']]['threadnum'];
if(!isset($user_posts[$new_firstpost['uid']]['threadnum']))
{
$user_posts[$new_firstpost['uid']]['threadnum'] = 0;

			--$user_posts[$thread['uid']]['threadnum'];
if(!isset($user_posts[$new_firstpost['uid']]['threadnum']))
{
$user_posts[$new_firstpost['uid']]['threadnum'] = 0;

			}

			}

			++$user_posts[$new_firstpost['uid']]['threadnum'];
}


			++$user_posts[$new_firstpost['uid']]['threadnum'];
}


Zeile 1595Zeile 1621
			{
$updated_stats = array(
"unapprovedposts" => '+'.($mergethread['replies']+$mergethread['unapprovedposts']+$mergethread['deletedposts'])

			{
$updated_stats = array(
"unapprovedposts" => '+'.($mergethread['replies']+$mergethread['unapprovedposts']+$mergethread['deletedposts'])

				);

				);

			}
elseif($thread['visible'] == -1)
{

			}
elseif($thread['visible'] == -1)
{

Zeile 1612Zeile 1638
				);
}
update_forum_counters($thread['fid'], $updated_stats);

				);
}
update_forum_counters($thread['fid'], $updated_stats);


// If old thread is unapproved, implied counter comes in to effect
if($mergethread['visible'] == 0)
{


// If old thread is unapproved, implied counter comes in to effect
if($mergethread['visible'] == 0)
{

				$updated_stats = array(
"unapprovedposts" => '-'.($mergethread['replies']+$mergethread['unapprovedposts']+$mergethread['deletedposts'])
);
}

				$updated_stats = array(
"unapprovedposts" => '-'.($mergethread['replies']+$mergethread['unapprovedposts']+$mergethread['deletedposts'])
);
}

			elseif($mergethread['visible'] == -1)
{
$updated_stats = array(
"deletedposts" => '-'.($mergethread['replies']+$mergethread['deletedposts']+$mergethread['unapprovedposts'])
);
}
else

			elseif($mergethread['visible'] == -1)
{
$updated_stats = array(
"deletedposts" => '-'.($mergethread['replies']+$mergethread['deletedposts']+$mergethread['unapprovedposts'])
);
}
else

			{
$updated_stats = array(
"posts" => "-{$mergethread['replies']}",
"unapprovedposts" => "-{$mergethread['unapprovedposts']}",
"deletedposts" => "-{$mergethread['deletedposts']}"
);

			{
$updated_stats = array(
"posts" => "-{$mergethread['replies']}",
"unapprovedposts" => "-{$mergethread['unapprovedposts']}",
"deletedposts" => "-{$mergethread['deletedposts']}"
);

			}

			}

			update_forum_counters($mergethread['fid'], $updated_stats);
update_forum_lastpost($mergethread['fid']);
}

			update_forum_counters($mergethread['fid'], $updated_stats);
update_forum_lastpost($mergethread['fid']);
}

Zeile 1645Zeile 1671
				'unapprovedposts' => 0,
'deletedposts' => 0
);

				'unapprovedposts' => 0,
'deletedposts' => 0
);





			// If old thread is unapproved, implied counter comes in to effect
if($mergethread['visible'] == 0)
{

			// If old thread is unapproved, implied counter comes in to effect
if($mergethread['visible'] == 0)
{

Zeile 1662Zeile 1688

// If new thread is unapproved, implied counter comes in to effect
if($thread['visible'] == 0)


// If new thread is unapproved, implied counter comes in to effect
if($thread['visible'] == 0)

			{

			{

				$updated_stats['unapprovedposts'] += $mergethread['replies']+$mergethread['deletedposts'];
$updated_stats['posts'] -= $mergethread['replies'];
$updated_stats['deletedposts'] -= $mergethread['deletedposts'];

				$updated_stats['unapprovedposts'] += $mergethread['replies']+$mergethread['deletedposts'];
$updated_stats['posts'] -= $mergethread['replies'];
$updated_stats['deletedposts'] -= $mergethread['deletedposts'];

Zeile 1752Zeile 1778
			"replies" => "+{$mergethread['replies']}",
"attachmentcount" => "+{$mergethread['attachmentcount']}",
"unapprovedposts" => "+{$mergethread['unapprovedposts']}",

			"replies" => "+{$mergethread['replies']}",
"attachmentcount" => "+{$mergethread['attachmentcount']}",
"unapprovedposts" => "+{$mergethread['unapprovedposts']}",

			"deletedposts" => "+{$mergethread['unapprovedposts']}",

 
			"deletedposts" => "+{$mergethread['deletedposts']}"
);
update_thread_counters($tid, $updated_stats);
update_last_post($tid);

			"deletedposts" => "+{$mergethread['deletedposts']}"
);
update_thread_counters($tid, $updated_stats);
update_last_post($tid);





		// Forum last post has to be updated after thread
update_forum_lastpost($thread['fid']);
return true;
}

		// Forum last post has to be updated after thread
update_forum_lastpost($thread['fid']);
return true;
}





	/**
* Split posts into a new/existing thread
*

	/**
* Split posts into a new/existing thread
*

	 * @param array PIDs of posts to split
* @param int Original thread ID (this is only used as a base for the new

	 * @param array $pids PIDs of posts to split
* @param int $tid Original thread ID (this is only used as a base for the new

	 * thread; it can be set to 0 when the posts specified are coming from more
* than 1 thread)

	 * thread; it can be set to 0 when the posts specified are coming from more
* than 1 thread)

	 * @param int Destination forum
* @param string New thread subject
* @param int TID if moving into existing thread
* @return int New thread ID

	 * @param int $moveto Destination forum
* @param string $newsubject New thread subject
* @param int $destination_tid TID if moving into existing thread
* @return int|bool New thread ID or false on failure

	 */
function split_posts($pids, $tid, $moveto, $newsubject, $destination_tid=0)
{

	 */
function split_posts($pids, $tid, $moveto, $newsubject, $destination_tid=0)
{

Zeile 1797Zeile 1822
		}

// Get the first split post

		}

// Get the first split post

		$query = $db->simple_select('posts', 'pid,uid,visible,icon,username,dateline', 'pid IN ('.$pids_list.')', array('order_by' => 'dateline', 'order_dir' => 'asc', 'limit' => 1));

		$query = $db->simple_select('posts', 'pid,uid,visible,icon,username,dateline', 'pid IN ('.$pids_list.')', array('order_by' => 'dateline, pid', 'limit' => 1));


$post_info = $db->fetch_array($query);



$post_info = $db->fetch_array($query);


Zeile 1811Zeile 1836
			'unapprovedposts' => 0,
'deletedposts' => 0
);

			'unapprovedposts' => 0,
'deletedposts' => 0
);

 

$user_counters = array();


if($destination_tid == 0)
{


if($destination_tid == 0)
{

Zeile 1842Zeile 1869
						'threadnum' => 0
);
}

						'threadnum' => 0
);
}

				// Subtract thread from old thread opener
--$user_counters[$newthread['uid']]['threadnum'];

				++$user_counters[$newthread['uid']]['threadnum'];


			}
elseif($visible == -1)
{

			}
elseif($visible == -1)
{

Zeile 1964Zeile 1990
			{
// In some cases the first post of a thread changes
// Therefore resync the visible field to make sure they're the same if they're not

			{
// In some cases the first post of a thread changes
// Therefore resync the visible field to make sure they're the same if they're not

				$query = $db->simple_select("posts", "pid, visible, uid", "tid='{$post['tid']}'", array('order_by' => 'dateline', 'order_dir' => 'asc', 'limit' => 1));

				$query = $db->simple_select("posts", "pid, visible, uid", "tid='{$post['tid']}'", array('order_by' => 'dateline, pid', 'limit' => 1));

				$new_firstpost = $db->fetch_array($query);

if(!isset($user_counters[$new_firstpost['uid']]))

				$new_firstpost = $db->fetch_array($query);

if(!isset($user_counters[$new_firstpost['uid']]))

Zeile 2107Zeile 2133
				++$forum_counters[$moveto]['deletedposts'];
}
}

				++$forum_counters[$moveto]['deletedposts'];
}
}

 

// Attach moved posts to the first post
$db->update_query("posts", array('replyto' => $post_info['pid']), "tid='{$newtid}' AND replyto = 0 AND pid != '{$post_info['pid']}'");


if($destination_tid == 0 && $newthread['visible'] == 1)
{


if($destination_tid == 0 && $newthread['visible'] == 1)
{

Zeile 2151Zeile 2180
				if($tid == $newtid)
{
// Update the subject of the first post in the new thread

				if($tid == $newtid)
{
// Update the subject of the first post in the new thread

					$query = $db->simple_select("posts", "pid", "tid='$newtid'", array('order_by' => 'dateline', 'limit' => 1));

					$query = $db->simple_select("posts", "pid", "tid='$newtid'", array('order_by' => 'dateline, pid', 'limit' => 1));

					$newthread = $db->fetch_array($query);

					$newthread = $db->fetch_array($query);

					$sqlarray = array(

					$sqlarray = array(

						"subject" => $newsubject,

						"subject" => $newsubject,

						"replyto" => 0
);

						"replyto" => 0
);

					$db->update_query("posts", $sqlarray, "pid='{$newthread['pid']}'");
}
else

					$db->update_query("posts", $sqlarray, "pid='{$newthread['pid']}'");
}
else

Zeile 2167Zeile 2196
						FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."threads t ON (p.tid=t.tid)
WHERE p.tid='{$tid}'

						FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."threads t ON (p.tid=t.tid)
WHERE p.tid='{$tid}'

						ORDER BY p.dateline ASC

						ORDER BY p.dateline ASC, p.pid ASC

						LIMIT 1
");
$oldthread = $db->fetch_array($query);

						LIMIT 1
");
$oldthread = $db->fetch_array($query);

Zeile 2176Zeile 2205
						"replyto" => 0
);
$db->update_query("posts", $sqlarray, "pid='{$oldthread['pid']}'");

						"replyto" => 0
);
$db->update_query("posts", $sqlarray, "pid='{$oldthread['pid']}'");

				}

foreach($counters as $key => $counter)
{

				}

foreach($counters as $key => $counter)
{

					if($counter >= 0)
{
$counters[$key] = "+{$counter}";

					if($counter >= 0)
{
$counters[$key] = "+{$counter}";

Zeile 2198Zeile 2227
				foreach($counters as $key => $counter)
{
if($counter >= 0)

				foreach($counters as $key => $counter)
{
if($counter >= 0)

					{

					{

						$counters[$key] = "+{$counter}";
}
}

						$counters[$key] = "+{$counter}";
}
}

Zeile 2206Zeile 2235
				update_forum_lastpost($fid);
}
}

				update_forum_lastpost($fid);
}
}





		return $newtid;
}

/**
* Move multiple threads to new forum
*

		return $newtid;
}

/**
* Move multiple threads to new forum
*

	 * @param array Thread IDs
* @param int Destination forum
* @return boolean true



	 * @param array $tids Thread IDs
* @param int $moveto Destination forum
* @return boolean
*
* @deprecated Iterate over move_thread instead

	 */
function move_threads($tids, $moveto)
{

	 */
function move_threads($tids, $moveto)
{

Zeile 2254Zeile 2285
				);
}


				);
}


			if(!isset($user_counters[$thread['uid']]['num_threads']))

			if(!isset($user_counters[$thread['uid']]))

			{

			{

				$user_counters[$thread['uid']]['num_threads'] = 0;




				$user_counters[$thread['uid']] = array(
'num_posts' => 0,
'num_threads' => 0
);

			}

if($thread['visible'] == 1)

			}

if($thread['visible'] == 1)

Zeile 2290Zeile 2324
				");
while($posters = $db->fetch_array($query1))
{

				");
while($posters = $db->fetch_array($query1))
{

					if(!isset($user_counters[$posters['uid']]['num_posts']))

					if(!isset($user_counters[$posters['uid']]))

					{

					{

						$user_counters[$posters['uid']]['num_posts'] = 0;




						$user_counters[$posters['uid']] = array(
'num_posts' => 0,
'num_threads' => 0
);

					}

if($newforum['usepostcounts'] != 0 && $forum['usepostcounts'] == 0)

					}

if($newforum['usepostcounts'] != 0 && $forum['usepostcounts'] == 0)

Zeile 2414Zeile 2451
	/**
* Approve multiple posts
*

	/**
* Approve multiple posts
*

	 * @param array PIDs
* @return boolean true

	 * @param array $pids PIDs
* @return boolean

	 */
function approve_posts($pids)
{
global $db, $cache, $plugins;

	 */
function approve_posts($pids)
{
global $db, $cache, $plugins;





		$num_posts = 0;

if(empty($pids))

		$num_posts = 0;

if(empty($pids))

Zeile 2430Zeile 2467

// Make sure we only have valid values
$pids = array_map('intval', $pids);


// Make sure we only have valid values
$pids = array_map('intval', $pids);





		$pid_list = implode(',', $pids);
$pids = $threads_to_update = array();


		$pid_list = implode(',', $pids);
$pids = $threads_to_update = array();


Zeile 2454Zeile 2491
		while($post = $db->fetch_array($query))
{
// This is the first post in the thread so we're approving the whole thread.

		while($post = $db->fetch_array($query))
{
// This is the first post in the thread so we're approving the whole thread.

			$threads_to_update[] = $post['tid'];
}

if(!empty($threads_to_update))
{
$this->approve_threads($threads_to_update);

			$threads_to_update[] = $post['tid'];
}

if(!empty($threads_to_update))
{
$this->approve_threads($threads_to_update);

		}

$thread_counters = $forum_counters = $user_counters = array();

		}

$thread_counters = $forum_counters = $user_counters = array();

Zeile 2479Zeile 2516
				$thread_counters[$post['tid']] = array(
'replies' => 0
);

				$thread_counters[$post['tid']] = array(
'replies' => 0
);

			}

++$thread_counters[$post['tid']]['replies'];

			}

++$thread_counters[$post['tid']]['replies'];


// If the thread of this post is unapproved then we've already taken into account this counter as implied.
// Updating it again would cause it to double count


// If the thread of this post is unapproved then we've already taken into account this counter as implied.
// Updating it again would cause it to double count

Zeile 2500Zeile 2537

// If post counts enabled in this forum and the thread is approved, add 1
if($forum['usepostcounts'] != 0 && $post['threadvisible'] == 1)


// If post counts enabled in this forum and the thread is approved, add 1
if($forum['usepostcounts'] != 0 && $post['threadvisible'] == 1)

			{
if(!isset($user_counters[$post['uid']]))
{
$user_counters[$post['uid']] = 0;

			{
if(!isset($user_counters[$post['uid']]))
{
$user_counters[$post['uid']] = 0;

				}
++$user_counters[$post['uid']];
}
}

if(empty($pids) && empty($threads_to_update))

				}
++$user_counters[$post['uid']];
}
}

if(empty($pids) && empty($threads_to_update))

		{

		{

			return false;
}

if(!empty($pids))

			return false;
}

if(!empty($pids))

		{

		{

			$where = "pid IN (".implode(',', $pids).")";
$db->update_query("posts", $approve, $where);

			$where = "pid IN (".implode(',', $pids).")";
$db->update_query("posts", $approve, $where);

		}

$plugins->run_hooks("class_moderation_approve_posts", $pids);

		}

$plugins->run_hooks("class_moderation_approve_posts", $pids);


if(!empty($thread_counters))
{


if(!empty($thread_counters))
{

Zeile 2542Zeile 2579
				$updated_forum_stats = array(
'posts' => "+{$counters['num_posts']}",
'unapprovedposts' => "-{$counters['num_posts']}",

				$updated_forum_stats = array(
'posts' => "+{$counters['num_posts']}",
'unapprovedposts' => "-{$counters['num_posts']}",

				);
update_forum_counters($fid, $updated_forum_stats);
update_forum_lastpost($fid);
}
}

if(!empty($user_counters))

				);
update_forum_counters($fid, $updated_forum_stats);
update_forum_lastpost($fid);
}
}

if(!empty($user_counters))

		{
foreach($user_counters as $uid => $counter)
{
update_user_counters($uid, array('postnum' => "+{$counter}"));
}
}

		{
foreach($user_counters as $uid => $counter)
{
update_user_counters($uid, array('postnum' => "+{$counter}"));
}
}





		return true;
}

/**
* Unapprove multiple posts
*

		return true;
}

/**
* Unapprove multiple posts
*

	 * @param array PIDs
* @return boolean true

	 * @param array $pids PIDs
* @return boolean

	 */
function unapprove_posts($pids)
{

	 */
function unapprove_posts($pids)
{

Zeile 2638Zeile 2675
			else
{
++$thread_counters[$post['tid']]['deletedposts'];

			else
{
++$thread_counters[$post['tid']]['deletedposts'];

			}

			}


if(!isset($forum_counters[$post['fid']]))
{


if(!isset($forum_counters[$post['fid']]))
{

Zeile 2725Zeile 2762
			{
update_user_counters($uid, array('postnum' => "{$counter}"));
}

			{
update_user_counters($uid, array('postnum' => "{$counter}"));
}

		}

return true;

		}

return true;

	}

/**
* Change thread subject

	}

/**
* Change thread subject

	 *
* @param mixed Thread ID(s)
* @param string Format of new subject (with {subject})
* @return boolean true

	 *
* @param int|array $tids Thread ID(s)
* @param string $format Format of new subject (with {subject})
* @return boolean

	 */
function change_thread_subject($tids, $format)
{
global $db, $mybb, $plugins;

	 */
function change_thread_subject($tids, $format)
{
global $db, $mybb, $plugins;





		// Get tids into list
if(!is_array($tids))
{
$tids = array($tids);

		// Get tids into list
if(!is_array($tids))
{
$tids = array($tids);

		}


		}


		// Make sure we only have valid values
$tids = array_map('intval', $tids);

if(empty($tids))

		// Make sure we only have valid values
$tids = array_map('intval', $tids);

if(empty($tids))

		{

		{

			return false;
}

$tid_list = implode(',', $tids);

// Get original subject

			return false;
}

$tid_list = implode(',', $tids);

// Get original subject

		$query = $db->simple_select("threads", "subject, tid", "tid IN ($tid_list)");





		$query = $db->query("
SELECT u.uid, u.username, t.tid, t.subject FROM ".TABLE_PREFIX."threads t
LEFT JOIN ".TABLE_PREFIX."users u ON t.uid=u.uid
WHERE tid IN ($tid_list)
");

		while($thread = $db->fetch_array($query))
{
// Update threads and first posts with new subject

		while($thread = $db->fetch_array($query))
{
// Update threads and first posts with new subject

			$subject = str_replace('{username}', $mybb->user['username'], $format);
$subject = str_replace('{subject}', $thread['subject'], $subject);
$new_subject = array(
"subject" => $db->escape_string($subject)











			$find = array('{username}', 'author', '{subject}');
$replace = array($mybb->user['username'], $thread['username'], $thread['subject']);

$new_subject = str_ireplace($find, $replace, $format);

$args = array(
'thread' => &$thread,
'new_subject' => &$new_subject,
);

$plugins->run_hooks("class_moderation_change_thread_subject_newsubject", $args);

$update_subject = array(
"subject" => $db->escape_string($new_subject)

			);

			);

			$db->update_query("threads", $new_subject, "tid='{$thread['tid']}'");
$db->update_query("posts", $new_subject, "tid='{$thread['tid']}' AND replyto='0'");

			$db->update_query("threads", $update_subject, "tid='{$thread['tid']}'");
$db->update_query("posts", $update_subject, "tid='{$thread['tid']}' AND replyto='0'");

		}

$arguments = array("tids" => $tids, "format" => $format);

		}

$arguments = array("tids" => $tids, "format" => $format);

Zeile 2780Zeile 2831
	/**
* Add thread expiry
*

	/**
* Add thread expiry
*

	 * @param int Thread ID
* @param int Timestamp when the thread is deleted
* @return boolean true

	 * @param int $tid Thread ID
* @param int $deletetime Timestamp when the thread is deleted
* @return boolean

	 */
function expire_thread($tid, $deletetime)
{

	 */
function expire_thread($tid, $deletetime)
{

Zeile 2809Zeile 2860
	/**
* Toggle post visibility (approved/unapproved)
*

	/**
* Toggle post visibility (approved/unapproved)
*

	 * @param array Post IDs

	 * @param array $pids Post IDs

	 * @return boolean true
*/
function toggle_post_visibility($pids)

	 * @return boolean true
*/
function toggle_post_visibility($pids)

Zeile 2846Zeile 2897
	/**
* Toggle post visibility (deleted/restored)
*

	/**
* Toggle post visibility (deleted/restored)
*

	 * @param array Post IDs

	 * @param array $pids Post IDs

	 * @return boolean true
*/
function toggle_post_softdelete($pids)

	 * @return boolean true
*/
function toggle_post_softdelete($pids)

Zeile 2883Zeile 2934
	/**
* Toggle thread visibility (approved/unapproved)
*

	/**
* Toggle thread visibility (approved/unapproved)
*

	 * @param array Thread IDs
* @param int Forum ID

	 * @param array $tids Thread IDs
* @param int $fid Forum ID

	 * @return boolean true
*/
function toggle_thread_visibility($tids, $fid)

	 * @return boolean true
*/
function toggle_thread_visibility($tids, $fid)

Zeile 2922Zeile 2973
	/**
* Toggle thread visibility (deleted/restored)
*

	/**
* Toggle thread visibility (deleted/restored)
*

	 * @param array Thread IDs

	 * @param array $tids Thread IDs

	 * @return boolean true
*/
function toggle_thread_softdelete($tids)

	 * @return boolean true
*/
function toggle_thread_softdelete($tids)

Zeile 2959Zeile 3010
	/**
* Toggle threads open/closed
*

	/**
* Toggle threads open/closed
*

	 * @param array Thread IDs

	 * @param array $tids Thread IDs

	 * @return boolean true
*/
function toggle_thread_status($tids)

	 * @return boolean true
*/
function toggle_thread_status($tids)

Zeile 2996Zeile 3047
	/**
* Toggle threads stick/unstick
*

	/**
* Toggle threads stick/unstick
*

	 * @param array Thread IDs

	 * @param array $tids Thread IDs

	 * @return boolean true
*/
function toggle_thread_importance($tids)

	 * @return boolean true
*/
function toggle_thread_importance($tids)

Zeile 3036Zeile 3087
	/**
* Remove thread subscriptions (from one or multiple threads in the same forum)
*

	/**
* Remove thread subscriptions (from one or multiple threads in the same forum)
*

	 * @param int $tids Thread ID, or an array of thread IDs from the same forum.

	 * @param int|array $tids Thread ID, or an array of thread IDs from the same forum.

	 * @param boolean $all True (default) to delete all subscriptions, false to only delete subscriptions from users with no permission to read the thread
* @param int $fid (Only applies if $all is false) The forum ID of the thread

	 * @param boolean $all True (default) to delete all subscriptions, false to only delete subscriptions from users with no permission to read the thread
* @param int $fid (Only applies if $all is false) The forum ID of the thread

	 * @return boolean true

	 * @return boolean

	 */
function remove_thread_subscriptions($tids, $all = true, $fid = 0)
{

	 */
function remove_thread_subscriptions($tids, $all = true, $fid = 0)
{

Zeile 3069Zeile 3120
			$forum_parentlist = get_parent_list($fid);
$query = $db->simple_select("forumpermissions", "gid", "fid IN ({$forum_parentlist}) AND (canview=0 OR canviewthreads=0)");
$groups = array();

			$forum_parentlist = get_parent_list($fid);
$query = $db->simple_select("forumpermissions", "gid", "fid IN ({$forum_parentlist}) AND (canview=0 OR canviewthreads=0)");
$groups = array();

 
			$additional_groups = '';

			while($group = $db->fetch_array($query))
{
$groups[] = $group['gid'];

			while($group = $db->fetch_array($query))
{
$groups[] = $group['gid'];

Zeile 3114Zeile 3166
	/**
* Apply a thread prefix (to one or multiple threads in the same forum)
*

	/**
* Apply a thread prefix (to one or multiple threads in the same forum)
*

	 * @param int $tids Thread ID, or an array of thread IDs from the same forum.

	 * @param int|array $tids Thread ID, or an array of thread IDs from the same forum.

	 * @param int $prefix Prefix ID to apply to the threads

	 * @param int $prefix Prefix ID to apply to the threads

 
	 * @return bool

	 */
function apply_thread_prefix($tids, $prefix = 0)
{
global $db, $plugins;

	 */
function apply_thread_prefix($tids, $prefix = 0)
{
global $db, $plugins;





		// Format thread IDs
if(!is_array($tids))
{

		// Format thread IDs
if(!is_array($tids))
{

Zeile 3149Zeile 3202
	/**
* Soft delete multiple posts
*

	/**
* Soft delete multiple posts
*

	 * @param array PIDs
* @return boolean true

	 * @param array $pids PIDs
* @return boolean

	 */
function soft_delete_posts($pids)
{

	 */
function soft_delete_posts($pids)
{

Zeile 3226Zeile 3279
			else
{
++$thread_counters[$post['tid']]['unapprovedposts'];

			else
{
++$thread_counters[$post['tid']]['unapprovedposts'];

			}


			}


			if(!isset($forum_counters[$post['fid']]))
{
$forum_counters[$post['fid']] = array(

			if(!isset($forum_counters[$post['fid']]))
{
$forum_counters[$post['fid']] = array(

Zeile 3240Zeile 3293
			// If the thread of this post is deleted then we've already taken into account this counter as implied.
// Updating it again would cause it to double count
if($post['threadvisible'] == 1)

			// If the thread of this post is deleted then we've already taken into account this counter as implied.
// Updating it again would cause it to double count
if($post['threadvisible'] == 1)

			{

			{

				++$forum_counters[$post['fid']]['num_deleted_posts'];
if($post['visible'] == 1)
{

				++$forum_counters[$post['fid']]['num_deleted_posts'];
if($post['visible'] == 1)
{

Zeile 3254Zeile 3307

// If post counts enabled in this forum and the thread is approved, subtract 1
if($post['usepostcounts'] != 0 && $post['threadvisible'] == 1 && $post['visible'] == 1)


// If post counts enabled in this forum and the thread is approved, subtract 1
if($post['usepostcounts'] != 0 && $post['threadvisible'] == 1 && $post['visible'] == 1)

			{
if(!isset($user_counters[$post['uid']]))

			{
if(!isset($user_counters[$post['uid']]))

				{
$user_counters[$post['uid']] = 0;
}
--$user_counters[$post['uid']];

				{
$user_counters[$post['uid']] = 0;
}
--$user_counters[$post['uid']];

			}
}


			}
}


		if(empty($pids) && empty($threads_to_update))
{
return false;
}

if(!empty($pids))

		if(empty($pids) && empty($threads_to_update))
{
return false;
}

if(!empty($pids))

		{

		{

			$where = "pid IN (".implode(',', $pids).")";
$db->update_query("posts", $update, $where);

			$where = "pid IN (".implode(',', $pids).")";
$db->update_query("posts", $update, $where);

 
			mark_reports($pids, "posts");

		}

$plugins->run_hooks("class_moderation_soft_delete_posts", $pids);

		}

$plugins->run_hooks("class_moderation_soft_delete_posts", $pids);

Zeile 3288Zeile 3342

update_thread_counters($tid, $counters_update);
update_last_post($tid);


update_thread_counters($tid, $counters_update);
update_last_post($tid);

			}
}


			}
}


		if(is_array($forum_counters))
{
foreach($forum_counters as $fid => $counters)

		if(is_array($forum_counters))
{
foreach($forum_counters as $fid => $counters)

Zeile 3310Zeile 3364
			foreach($user_counters as $uid => $counter)
{
update_user_counters($uid, array('postnum' => "{$counter}"));

			foreach($user_counters as $uid => $counter)
{
update_user_counters($uid, array('postnum' => "{$counter}"));

			}
}

			}
}


return true;
}


return true;
}

Zeile 3319Zeile 3373
	/**
* Restore multiple posts
*

	/**
* Restore multiple posts
*

	 * @param array PIDs
* @return boolean true

	 * @param array $pids PIDs
* @return boolean

	 */
function restore_posts($pids)
{

	 */
function restore_posts($pids)
{

Zeile 3360Zeile 3414
		{
// This is the first post in the thread so we're approving the whole thread.
$threads_to_update[] = $post['tid'];

		{
// This is the first post in the thread so we're approving the whole thread.
$threads_to_update[] = $post['tid'];

		}


		}


		if(!empty($threads_to_update))
{
$this->restore_threads($threads_to_update);
}

$thread_counters = $forum_counters = $user_counters = array();

		if(!empty($threads_to_update))
{
$this->restore_threads($threads_to_update);
}

$thread_counters = $forum_counters = $user_counters = array();





		$query = $db->query("
SELECT p.pid, p.tid, f.fid, f.usepostcounts, p.uid, t.visible AS threadvisible
FROM ".TABLE_PREFIX."posts p

		$query = $db->query("
SELECT p.pid, p.tid, f.fid, f.usepostcounts, p.uid, t.visible AS threadvisible
FROM ".TABLE_PREFIX."posts p

Zeile 3381Zeile 3435
			$pids[] = $post['pid'];

if(!isset($thread_counters[$post['tid']]))

			$pids[] = $post['pid'];

if(!isset($thread_counters[$post['tid']]))

			{

			{

				$thread_counters[$post['tid']] = array(
'replies' => 0
);

				$thread_counters[$post['tid']] = array(
'replies' => 0
);

			}

++$thread_counters[$post['tid']]['replies'];


			}

++$thread_counters[$post['tid']]['replies'];


			// If the thread of this post is deleted then we've already taken into account this counter as implied.
// Updating it again would cause it to double count
if($post['threadvisible'] == 1)

			// If the thread of this post is deleted then we've already taken into account this counter as implied.
// Updating it again would cause it to double count
if($post['threadvisible'] == 1)

Zeile 3423Zeile 3477
		{
$where = "pid IN (".implode(',', $pids).")";
$db->update_query("posts", $update, $where);

		{
$where = "pid IN (".implode(',', $pids).")";
$db->update_query("posts", $update, $where);

		}


		}


		$plugins->run_hooks("class_moderation_restore_posts", $pids);

if(is_array($thread_counters))

		$plugins->run_hooks("class_moderation_restore_posts", $pids);

if(is_array($thread_counters))

		{

		{

			foreach($thread_counters as $tid => $counters)
{
$counters_update = array(
"deletedposts" => "-".$counters['replies'],
"replies" => "+".$counters['replies']

			foreach($thread_counters as $tid => $counters)
{
$counters_update = array(
"deletedposts" => "-".$counters['replies'],
"replies" => "+".$counters['replies']

				);

				);

				update_thread_counters($tid, $counters_update);
update_last_post($tid);
}

				update_thread_counters($tid, $counters_update);
update_last_post($tid);
}

Zeile 3450Zeile 3504
				);
update_forum_counters($fid, $updated_forum_stats);
update_forum_lastpost($fid);

				);
update_forum_counters($fid, $updated_forum_stats);
update_forum_lastpost($fid);

			}
}


			}
}


		if(!empty($user_counters))
{
foreach($user_counters as $uid => $counter)

		if(!empty($user_counters))
{
foreach($user_counters as $uid => $counter)

Zeile 3467Zeile 3521
	/**
* Restore one or more threads
*

	/**
* Restore one or more threads
*

	 * @param array Thread IDs

	 * @param array|int $tids Thread ID(s)

	 * @return boolean true
*/
function restore_threads($tids)

	 * @return boolean true
*/
function restore_threads($tids)

	{
global $db, $cache, $plugins;

if(!is_array($tids))
{
$tids = array($tids);
}

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

	{
global $db, $cache, $plugins;

if(!is_array($tids))
{
$tids = array($tids);
}

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

		}

// Make sure we only have valid values

		}

// Make sure we only have valid values

Zeile 3489Zeile 3543

$tid_list = $forum_counters = $user_counters = $posts_to_restore = array();



$tid_list = $forum_counters = $user_counters = $posts_to_restore = array();


		foreach($tids as $tid)




		$tids_list = implode(",", $tids);
$query = $db->simple_select("threads", "*", "tid IN ($tids_list)");

while($thread = $db->fetch_array($query))

		{

		{

			$thread = get_thread($tid);
if(!$thread || $thread['visible'] != -1)

			if($thread['visible'] != -1)


			{
continue;
}
$tid_list[] = $thread['tid'];

$forum = get_forum($thread['fid']);

			{
continue;
}
$tid_list[] = $thread['tid'];

$forum = get_forum($thread['fid']);





			if(!isset($forum_counters[$forum['fid']]))
{
$forum_counters[$forum['fid']] = array(

			if(!isset($forum_counters[$forum['fid']]))
{
$forum_counters[$forum['fid']] = array(

Zeile 3511Zeile 3567
			}

if(!isset($user_counters[$thread['uid']]))

			}

if(!isset($user_counters[$thread['uid']]))

			{

			{

				$user_counters[$thread['uid']] = array(
'num_posts' => 0,
'num_threads' => 0

				$user_counters[$thread['uid']] = array(
'num_posts' => 0,
'num_threads' => 0

Zeile 3526Zeile 3582
			if($forum['usepostcounts'] != 0)
{
// On approving thread restore user post counts

			if($forum['usepostcounts'] != 0)
{
// On approving thread restore user post counts

				$query = $db->simple_select("posts", "COUNT(pid) as posts, uid", "tid='{$tid}' AND (visible='1' OR pid='{$thread['firstpost']}') AND uid > 0 GROUP BY uid");
while($counter = $db->fetch_array($query))

				$query2 = $db->simple_select("posts", "COUNT(pid) as posts, uid", "tid='{$thread['tid']}' AND (visible='1' OR pid='{$thread['firstpost']}') AND uid > 0 GROUP BY uid");
while($counter = $db->fetch_array($query2))

				{

				{

					if(!isset($user_counters[$counter['uid']]['num_posts']))

					if(!isset($user_counters[$counter['uid']]))

					{

					{

						$user_counters[$counter['uid']]['num_posts'] = 0;




						$user_counters[$counter['uid']] = array(
'num_posts' => 0,
'num_threads' => 0
);

					}
$user_counters[$counter['uid']]['num_posts'] += $counter['posts'];
}

					}
$user_counters[$counter['uid']]['num_posts'] += $counter['posts'];
}

Zeile 3612Zeile 3671
	/**
* Soft delete one or more threads
*

	/**
* Soft delete one or more threads
*

	 * @param array Thread IDs
* @return boolean true

	 * @param array|int Thread ID(s)
* @return boolean

	 */
function soft_delete_threads($tids)
{

	 */
function soft_delete_threads($tids)
{

Zeile 3625Zeile 3684
		}

if(empty($tids))

		}

if(empty($tids))

		{

		{

			return false;
}


			return false;
}


Zeile 3643Zeile 3702

$forum_counters = $user_counters = $posts_to_delete = array();



$forum_counters = $user_counters = $posts_to_delete = array();


		foreach($tids as $tid)




		$tids_list = implode(",", $tids);
$query = $db->simple_select("threads", "*", "tid IN ($tids_list)");

while($thread = $db->fetch_array($query))

		{

		{

			$thread = get_thread($tid);

 
			$forum = get_forum($thread['fid']);

if($thread['visible'] == 1 || $thread['visible'] == 0)

			$forum = get_forum($thread['fid']);

if($thread['visible'] == 1 || $thread['visible'] == 0)

Zeile 3689Zeile 3750
				// On unapproving thread update user post counts
if($thread['visible'] == 1 && $forum['usepostcounts'] != 0)
{

				// On unapproving thread update user post counts
if($thread['visible'] == 1 && $forum['usepostcounts'] != 0)
{

					$query = $db->simple_select("posts", "COUNT(pid) AS posts, uid", "tid='{$tid}' AND (visible='1' OR pid='{$thread['firstpost']}') AND uid > 0 GROUP BY uid");
while($counter = $db->fetch_array($query))

					$query2 = $db->simple_select("posts", "COUNT(pid) AS posts, uid", "tid='{$thread['tid']}' AND (visible='1' OR pid='{$thread['firstpost']}') AND uid > 0 GROUP BY uid");
while($counter = $db->fetch_array($query2))

					{

					{

						if(!isset($user_counters[$counter['uid']]['num_posts']))

						if(!isset($user_counters[$counter['uid']]))

						{

						{

							$user_counters[$counter['uid']]['num_posts'] = 0;




							$user_counters[$counter['uid']] = array(
'num_posts' => 0,
'num_threads' => 0
);

						}
$user_counters[$counter['uid']]['num_posts'] += $counter['posts'];
}

						}
$user_counters[$counter['uid']]['num_posts'] += $counter['posts'];
}

Zeile 3715Zeile 3779
		// Soft delete redirects, too
$redirect_tids = array();
$query = $db->simple_select('threads', 'tid', "closed IN ({$tid_moved_list})");

		// Soft delete redirects, too
$redirect_tids = array();
$query = $db->simple_select('threads', 'tid', "closed IN ({$tid_moved_list})");

 

mark_reports($tids, "threads");


		while($redirect_tid = $db->fetch_field($query, 'tid'))
{
$redirect_tids[] = $redirect_tid;

		while($redirect_tid = $db->fetch_field($query, 'tid'))
{
$redirect_tids[] = $redirect_tid;