Vergleich inc/class_moderation.php - 1.2.6 - 1.2.10

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 3Zeile 3
 * MyBB 1.2
* Copyright � 2006 MyBB Group, All Rights Reserved
*

 * MyBB 1.2
* Copyright � 2006 MyBB Group, All Rights Reserved
*

 * Website: http://www.mybboard.com
* License: http://www.mybboard.com/eula.html

 * Website: http://www.mybboard.net
* License: http://www.mybboard.net/eula.html

 *

 *

 * $Id: class_moderation.php 2734 2007-02-08 22:21:16Z CraKteR $

 * $Id: class_moderation.php 3532 2007-12-02 01:30:41Z Tikitiki $

 */

class Moderation

 */

class Moderation

Zeile 19Zeile 19
	 */
function close_threads($tids)
{

	 */
function close_threads($tids)
{

		global $db;


		global $db, $plugins;


		if(!is_array($tids))
{
$tids = array($tids);
}
$tid_list = implode(",", $tids);

		if(!is_array($tids))
{
$tids = array($tids);
}
$tid_list = implode(",", $tids);






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


		$openthread = array(
"closed" => "yes",
);
$db->update_query(TABLE_PREFIX."threads", $openthread, "tid IN ($tid_list)");

		$openthread = array(
"closed" => "yes",
);
$db->update_query(TABLE_PREFIX."threads", $openthread, "tid IN ($tid_list)");


return true;
}


return true;
}


/**
* Open one or more threads


/**
* Open one or more threads

Zeile 41Zeile 43
	 * @param int Thread IDs
* @return boolean true
*/

	 * @param int Thread IDs
* @return boolean true
*/





	function open_threads($tids)

	function open_threads($tids)

	{
global $db;







	{
global $db, $plugins;

if(!is_array($tids))
{
$tids = array($tids);
}
$tid_list = implode(",", $tids);





		if(!is_array($tids))
{
$tids = array($tids);
}
$tid_list = implode(",", $tids);

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






$closethread = array(
"closed" => "no",
);
$db->update_query(TABLE_PREFIX."threads", $closethread, "tid IN ($tid_list)");


$closethread = array(
"closed" => "no",
);
$db->update_query(TABLE_PREFIX."threads", $closethread, "tid IN ($tid_list)");





		return true;
}

/**
* Stick one or more threads

		return true;
}

/**
* Stick one or more threads

	 *
* @param int Thread IDs

	 *
* @param int Thread IDs

	 * @return boolean true
*/
function stick_threads($tids)
{

	 * @return boolean true
*/
function stick_threads($tids)
{

		global $db;


		global $db, $plugins;


		if(!is_array($tids))
{
$tids = array($tids);
}
$tid_list = implode(",", $tids);

		if(!is_array($tids))
{
$tids = array($tids);
}
$tid_list = implode(",", $tids);

 

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


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


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

		);

		);

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

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





		return true;
}


		return true;
}


Zeile 92Zeile 98
	 */
function unstick_threads($tids)
{

	 */
function unstick_threads($tids)
{

		global $db;

		global $db, $plugins;


if(!is_array($tids))
{
$tids = array($tids);
}
$tid_list = implode(",", $tids);


if(!is_array($tids))
{
$tids = array($tids);
}
$tid_list = implode(",", $tids);

 

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


$unstickthread = array(
"sticky" => 0,
);
$db->update_query(TABLE_PREFIX."threads", $unstickthread, "tid IN ($tid_list)");


$unstickthread = array(
"sticky" => 0,
);
$db->update_query(TABLE_PREFIX."threads", $unstickthread, "tid IN ($tid_list)");


return true;
}

/**


return true;
}

/**

	 * Remove redirects that redirect to the specified thread
*
* @param int Thread ID of the thread

	 * Remove redirects that redirect to the specified thread
*
* @param int Thread ID of the thread

Zeile 116Zeile 124
	 */
function remove_redirects($tid)
{

	 */
function remove_redirects($tid)
{

		global $db;



		global $db, $plugins;

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





		// Find the fids that have these redirects
$query = $db->simple_select(TABLE_PREFIX."threads", "fid", "closed='moved|$tid'");
while($forum = $db->fetch_array($query))
{
$fids[] = $forum['fid'];
}

 
		// Delete the redirects
$db->delete_query(TABLE_PREFIX."threads", "closed='moved|$tid'");

		// Delete the redirects
$db->delete_query(TABLE_PREFIX."threads", "closed='moved|$tid'");

		// Update the forum stats of the fids found above
if(is_array($fids))
{
foreach($fids as $fid)
{
update_forum_count($fid);
}
}


 
		return true;
}


		return true;
}


Zeile 147Zeile 142
	function delete_thread($tid)
{
global $db, $cache, $plugins;

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

 
		
$thread = get_thread($tid);

$userposts = array();


// Find the pid, uid, visibility, and forum post count status
$query = $db->query("
SELECT p.pid, p.uid, p.visible, f.usepostcounts


// Find the pid, uid, visibility, and forum post count status
$query = $db->query("
SELECT p.pid, p.uid, p.visible, f.usepostcounts

			FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=p.fid)

			FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=p.fid)

			WHERE p.tid='$tid'
");

			WHERE p.tid='$tid'
");

		$num_unapproved_posts = 0;


		$pids = array();
$num_unapproved_posts = $num_approved_posts = 0;

		while($post = $db->fetch_array($query))
{

		while($post = $db->fetch_array($query))
{

			$pids .= $post['pid'].",";

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

			$usepostcounts = $post['usepostcounts'];

			$usepostcounts = $post['usepostcounts'];

			

			

			// Remove attachments
remove_attachments($post['pid']);


			// Remove attachments
remove_attachments($post['pid']);


Zeile 168Zeile 168
			if($post['visible'] == 0)
{
$num_unapproved_posts++;

			if($post['visible'] == 0)
{
$num_unapproved_posts++;

				continue;
}

// Count the post counts for each user to be subtracted
if($userposts[$post['uid']])
{
$userposts[$post['uid']]--;
}

				continue;
}







			else

			else

			{
$userposts[$post['uid']] = -1;










			{
$num_approved_posts++;
// Count the post counts for each user to be subtracted
if($userposts[$post['uid']])
{
$userposts[$post['uid']]--;
}
else
{
$userposts[$post['uid']] = -1;
}

			}
}
// Remove post count from users

			}
}
// Remove post count from users

Zeile 189Zeile 192
				foreach($userposts as $uid => $subtract)
{
$db->query("UPDATE ".TABLE_PREFIX."users SET postnum=postnum$subtract WHERE uid='$uid'");

				foreach($userposts as $uid => $subtract)
{
$db->query("UPDATE ".TABLE_PREFIX."users SET postnum=postnum$subtract WHERE uid='$uid'");

				}
}

				}
}

		}
// Delete posts and their attachments
if($pids)

		}
// Delete posts and their attachments
if($pids)

		{
$pids .= "0";

		{
$pids = implode(",", $pids);

			$db->delete_query(TABLE_PREFIX."posts", "pid IN ($pids)");
$db->delete_query(TABLE_PREFIX."attachments", "pid IN ($pids)");

			$db->delete_query(TABLE_PREFIX."posts", "pid IN ($pids)");
$db->delete_query(TABLE_PREFIX."attachments", "pid IN ($pids)");

		}

		}

		// Get thread info
$query = $db->simple_select(TABLE_PREFIX."threads", "*", "tid='$tid'");
$thread = $db->fetch_array($query);

		// Get thread info
$query = $db->simple_select(TABLE_PREFIX."threads", "*", "tid='$tid'");
$thread = $db->fetch_array($query);

 

// Implied counters for unapproved thread
if($thread['visible'] == 0)
{
$num_unapproved_posts += $thread['replies'];
}


// Delete threads, redirects, favorites, polls, and poll votes
$db->delete_query(TABLE_PREFIX."threads", "tid='$tid'");


// Delete threads, redirects, favorites, polls, and poll votes
$db->delete_query(TABLE_PREFIX."threads", "tid='$tid'");

Zeile 209Zeile 218
		$db->delete_query(TABLE_PREFIX."favorites", "tid='$tid'");
$db->delete_query(TABLE_PREFIX."polls", "tid='$tid'");
$db->delete_query(TABLE_PREFIX."pollvotes", "pid='".$thread['poll']."'");

		$db->delete_query(TABLE_PREFIX."favorites", "tid='$tid'");
$db->delete_query(TABLE_PREFIX."polls", "tid='$tid'");
$db->delete_query(TABLE_PREFIX."pollvotes", "pid='".$thread['poll']."'");

		$cache->updatestats();
update_forum_count($thread['fid']);
$plugins->run_hooks("delete_thread", $tid);



















		$updated_counters = array(
"posts" => "-{$num_approved_posts}",
"unapprovedposts" => "-{$num_unapproved_posts}"
);

if($thread['visible'] == 1)
{
$updated_counters['threads'] = -1;
}
else
{
$updated_counters['unapprovedthreads'] = -1;
}

if(substr($thread['closed'], 0, 5) != "moved")
{
// Update forum count
update_forum_counters($thread['fid'], $updated_counters);
}

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


return true;
}


return true;
}

Zeile 223Zeile 250
	 * @return boolean true
*/
function delete_poll($pid)

	 * @return boolean true
*/
function delete_poll($pid)

	{
global $db;




	{
global $db, $plugins;

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


		$db->delete_query(TABLE_PREFIX."polls", "pid='$pid'");
$db->delete_query(TABLE_PREFIX."pollvotes", "pid='$pid'");
$pollarray = array(

		$db->delete_query(TABLE_PREFIX."polls", "pid='$pid'");
$db->delete_query(TABLE_PREFIX."pollvotes", "pid='$pid'");
$pollarray = array(

Zeile 238Zeile 267

/**
* Approve one or more threads


/**
* Approve one or more threads

	 *
* @param array Thread IDs
* @param int Forum ID
* @return boolean true

	 *
* @param array Thread IDs
* @param int Forum ID
* @return boolean true

	 */
function approve_threads($tids, $fid)
{

	 */
function approve_threads($tids, $fid)
{

		global $db, $cache;

		global $db, $cache, $plugins;


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


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

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

 
		

		

 
		$num_threads = $num_posts = 0;

		foreach($tids as $tid)

		foreach($tids as $tid)

		{
$query = $db->query("
SELECT p.tid, f.usepostcounts, p.uid
FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=p.fid)
WHERE p.tid='$tid' AND p.visible = '0'
");
while($post = $db->fetch_array($query))

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






			{

			{

				// If post counts enabled in this forum and the post hasn't already been approved, remove 1
if($post['usepostcounts'] != "no")













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

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

$num_threads++;
$num_posts += $thread['replies']+1; // Remove implied visible from count

if($forum['usepostcounts'] != "no")
{
// On approving thread restore user post counts
$query = $db->simple_select(TABLE_PREFIX."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))

				{

				{

					$db->query("UPDATE ".TABLE_PREFIX."users SET postnum=postnum+1 WHERE uid='".$post['uid']."'");

					$db->query("UPDATE ".TABLE_PREFIX."users SET postnum=postnum+{$counter['posts']} WHERE uid='".$counter['uid']."'");

				}
}

				}
}

			update_thread_count($tid);
}

$approve = array(
"visible" => 1,
);
$db->update_query(TABLE_PREFIX."threads", $approve, "tid IN ($tid_list)");
$db->update_query(TABLE_PREFIX."posts", $approve, "tid IN ($tid_list)", 1);

// Update stats
$cache->updatestats();
update_forum_count($fid);

			$posts_to_approve[] = $thread['firstpost'];
















 
		}

if(is_array($tid_list))
{
$tid_list = implode(",", $tid_list);

$approve = array(
"visible" => 1,
);
$db->update_query(TABLE_PREFIX."threads", $approve, "tid IN ($tid_list)");
$db->update_query(TABLE_PREFIX."posts", $approve, "pid IN (".implode(",", $posts_to_approve).")");

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

// Update stats
$update_array = array(
"threads" => "+{$num_threads}",
"unapprovedthreads" => "-{$num_threads}",
"posts" => "+{$num_posts}",
"unapprovedposts" => "-{$num_posts}"
);
update_forum_counters($fid, $update_array);
}

		return true;
}


		return true;
}


Zeile 293Zeile 341
	 * @return boolean true
*/
function unapprove_threads($tids, $fid)

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

	{
global $db, $cache;


	{
global $db, $cache, $plugins;


		if(!is_array($tids))

		if(!is_array($tids))

		{

		{

			$tids = array($tids);
}
$tid_list = implode(",", $tids);


			$tids = array($tids);
}
$tid_list = implode(",", $tids);


 
		$num_threads = $num_posts = 0;

		foreach($tids as $tid)
{

		foreach($tids as $tid)
{

 
			$thread = get_thread($tid); 

if($thread['visible'] == 1)
{
$num_threads++;
$num_posts += $thread['replies']+1; // Add implied invisible to count
}

			$query = $db->query("

			$query = $db->query("

				SELECT p.tid, f.usepostcounts, p.uid

				SELECT p.tid, f.usepostcounts, p.uid, p.visible

				FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=p.fid)
WHERE p.tid='$tid' AND p.visible = '1'

				FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=p.fid)
WHERE p.tid='$tid' AND p.visible = '1'

Zeile 318Zeile 374
					$db->query("UPDATE ".TABLE_PREFIX."users SET postnum=postnum-1 WHERE uid='".$post['uid']."'");
}
}

					$db->query("UPDATE ".TABLE_PREFIX."users SET postnum=postnum-1 WHERE uid='".$post['uid']."'");
}
}

			update_thread_count($tid);

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

		}

$approve = array(
"visible" => 0,
);
$db->update_query(TABLE_PREFIX."threads", $approve, "tid IN ($tid_list)");

		}

$approve = array(
"visible" => 0,
);
$db->update_query(TABLE_PREFIX."threads", $approve, "tid IN ($tid_list)");

		$db->update_query(TABLE_PREFIX."posts", $approve, "tid IN ($tid_list) AND replyto='0'", 1);




		$db->update_query(TABLE_PREFIX."posts", $approve, "pid IN (".implode(",", $posts_to_unapprove).")");

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


		// Update stats

		// Update stats

		$cache->updatestats();
update_forum_count($fid);






		$update_array = array( 
"threads" => "-{$num_threads}",
"unapprovedthreads" => "+{$num_threads}",
"posts" => "-{$num_posts}",
"unapprovedposts" => "+{$num_posts}"
);
update_forum_counters($fid, $update_array);


return true;
}


return true;
}

Zeile 362Zeile 425
		// Remove attachments
remove_attachments($pid);


		// Remove attachments
remove_attachments($pid);


 
		$num_unapproved_posts = $num_approved_posts = 0;

		// Update unapproved post count
if($post['visible'] == 0)
{
$db->query("UPDATE ".TABLE_PREFIX."forums SET unapprovedposts=unapprovedposts-1 WHERE fid='{$post['fid']}'");
$db->query("UPDATE ".TABLE_PREFIX."threads SET unapprovedposts=unapprovedposts-1 WHERE tid='{$post['tid']}'");

		// Update unapproved post count
if($post['visible'] == 0)
{
$db->query("UPDATE ".TABLE_PREFIX."forums SET unapprovedposts=unapprovedposts-1 WHERE fid='{$post['fid']}'");
$db->query("UPDATE ".TABLE_PREFIX."threads SET unapprovedposts=unapprovedposts-1 WHERE tid='{$post['tid']}'");

 
			$num_unaproved_posts--;

		}

		}

		$plugins->run_hooks("delete_post", $post['tid']);
$cache->updatestats();
update_thread_count($post['tid']);
update_forum_count($post['fid']);


















		else
{
$num_approved_posts++;
}
$plugins->run_hooks("class_moderation_delete_post", $post['pid']);

// Update stats
$update_array = array(
"replies" => "-{$num_approved_posts}",
"unapprovedposts" => "-{$num_unapproved_posts}"
);
update_thread_counters($post['tid'], $update_array);


// Update stats
$update_array = array(
"posts" => "-{$num_approved_posts}",
"unapprovedposts" => "-{$num_unapproved_posts}"
);

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


return true;
}


return true;
}

Zeile 385Zeile 467
	 */
function merge_posts($pids, $tid, $sep="new_line")
{

	 */
function merge_posts($pids, $tid, $sep="new_line")
{

		global $db;

		global $db, $plugins;


$pidin = implode(",", $pids);
$first = 1;


$pidin = implode(",", $pids);
$first = 1;

Zeile 397Zeile 479
			WHERE p.tid='$tid' AND p.pid IN($pidin)
ORDER BY dateline ASC
");

			WHERE p.tid='$tid' AND p.pid IN($pidin)
ORDER BY dateline ASC
");

		$num_unapproved_posts = 0;

		$num_unapproved_posts = $num_approved_posts = 0;

		$message = '';
while($post = $db->fetch_array($query))
{

		$message = '';
while($post = $db->fetch_array($query))
{

Zeile 405Zeile 487
			{ // all posts will be merged into this one
$masterpid = $post['pid'];
$message = $post['message'];

			{ // all posts will be merged into this one
$masterpid = $post['pid'];
$message = $post['message'];

 
				$fid = $post['fid'];

				$first = 0;
}
else

				$first = 0;
}
else

Zeile 422Zeile 505
				{
// Update post count of the user of the merged posts
$db->query("UPDATE ".TABLE_PREFIX."users SET postnum=postnum-1 WHERE uid='{$post['uid']}'");

				{
// Update post count of the user of the merged posts
$db->query("UPDATE ".TABLE_PREFIX."users SET postnum=postnum-1 WHERE uid='{$post['uid']}'");

 
				}
if($post['visible'] == 1)
{
$num_approved_posts++;
}
elseif($post['visible'] == 0)
{
$num_unapproved_posts++;

				}
}
}


				}
}
}


		$fid = $post['fid'];



		// Get lastpost pid to check if we're merging a post that is on the lastpost info
$query = $db->simple_select(TABLE_PREFIX."posts", "pid", "tid = '{$post['tid']}'", array('order_by' => 'dateline', 'order_dir' => 'desc', 'limit' => '1'));
$lastpostpid = $db->fetch_field($query, 'pid');


// Update the message
$mergepost = array(
"message" => $db->escape_string($message),
);


// Update the message
$mergepost = array(
"message" => $db->escape_string($message),
);

		$db->update_query(TABLE_PREFIX."posts", $mergepost, "pid='$masterpid'");

		$db->update_query(TABLE_PREFIX."posts", $mergepost, "pid = '$masterpid'");

		$db->delete_query(TABLE_PREFIX."posts", "pid IN($pidin) AND pid != '$masterpid'");
// Update pid for attachments
$mergepost2 = array(

		$db->delete_query(TABLE_PREFIX."posts", "pid IN($pidin) AND pid != '$masterpid'");
// Update pid for attachments
$mergepost2 = array(

Zeile 440Zeile 533
		);
$db->update_query(TABLE_PREFIX."posts", $mergepost2, "pid IN($pidin)");
$db->update_query(TABLE_PREFIX."attachments", $mergepost2, "pid IN($pidin)");

		);
$db->update_query(TABLE_PREFIX."posts", $mergepost2, "pid IN($pidin)");
$db->update_query(TABLE_PREFIX."attachments", $mergepost2, "pid IN($pidin)");

 

$plugins->run_hooks("class_moderation_merge_posts", array("pids" => $pids, "tid" => $tid));


// Update stats


// Update stats

		update_thread_count($tid);
update_forum_count($fid);











		$update_array = array( 
"replies" => "-{$num_approved_posts}",
"unapprovedposts" => "-{$num_unapproved_posts}"
);
update_thread_counters($tid, $update_array);

// Update stats
$update_array = array(
"posts" => "-{$num_approved_posts}",
"unapprovedposts" => "-{$num_unapproved_posts}"
);
update_forum_counters($fid, $update_array);


return true;
}


return true;
}

Zeile 466Zeile 571
		$newforum = get_forum($new_fid);
$fid = $thread['fid'];
$forum = get_forum($fid);

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

 
		$num_threads = $num_unapproved_threads = $num_posts = $num_unapproved_threads = 0;

		switch($method)
{
case "redirect": // move (and leave redirect) thread

		switch($method)
{
case "redirect": // move (and leave redirect) thread

				$plugins->run_hooks("moderation_do_move_redirect");















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

if($thread['visible'] == 1)
{
$num_threads++;
}
else
{
$num_unapproved_threads++;
// Implied forum unapproved count for unapproved threads
$num_unapproved_posts = $thread['replies']+1;
}

$num_posts = $thread['replies']+1;
$num_unapproved_posts += $thread['unapprovedposts'];

	

	

				$db->delete_query(TABLE_PREFIX."threads", "closed='moved|$tid' AND fid='$moveto'");

				$db->delete_query(TABLE_PREFIX."threads", "closed='moved|$tid' AND fid='{$new_fid}'");

				$changefid = array(
"fid" => $new_fid,
);

				$changefid = array(
"fid" => $new_fid,
);

Zeile 479Zeile 599
				$db->update_query(TABLE_PREFIX."posts", $changefid, "tid='$tid'");
$threadarray = array(
"fid" => $thread['fid'],

				$db->update_query(TABLE_PREFIX."posts", $changefid, "tid='$tid'");
$threadarray = array(
"fid" => $thread['fid'],

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

					"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']),

					"lastpost" => $thread['lastpost'],
"lastposteruid" => $thread['lastposteruid'],
"lastposter" => $db->escape_string($thread['lastposter']),

Zeile 496Zeile 616
				);
$db->insert_query(TABLE_PREFIX."threads", $threadarray);
if($redirect_expire)

				);
$db->insert_query(TABLE_PREFIX."threads", $threadarray);
if($redirect_expire)

				{

				{

					$redirect_tid = $db->insert_id();
$this->expire_thread($redirect_tid, $redirect_expire);
}

					$redirect_tid = $db->insert_id();
$this->expire_thread($redirect_tid, $redirect_expire);
}

Zeile 519Zeile 639
					"sticky" => $thread['sticky'],
"visible" => $thread['visible'],
"unapprovedposts" => $thread['unapprovedposts'],

					"sticky" => $thread['sticky'],
"visible" => $thread['visible'],
"unapprovedposts" => $thread['unapprovedposts'],

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

					"notes" => ''
);

					"notes" => ''
);

 


if($thread['visible'] == 1)
{
++$num_threads;
$num_posts = $thread['replies']+1;

// Fetch count of unapproved posts in this thread
$query = $db->simple_select(TABLE_PREFIX."posts", "COUNT(pid) AS unapproved", "tid='{$thread['tid']}' AND visible=0");
$num_unapproved_posts = $db->fetch_field($query, "unapproved");

}
else
{
$num_unapproved_threads++;
$num_unapproved_posts = $thread['replies']+1;
}

				

				

				$plugins->run_hooks("moderation_do_move_copy");

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

				$db->insert_query(TABLE_PREFIX."threads", $threadarray);
$newtid = $db->insert_id();


				$db->insert_query(TABLE_PREFIX."threads", $threadarray);
$newtid = $db->insert_id();


Zeile 530Zeile 668
				{
$query = $db->simple_select(TABLE_PREFIX."polls", "*", "tid = '{$thread['tid']}'");
$poll = $db->fetch_array($query);

				{
$query = $db->simple_select(TABLE_PREFIX."polls", "*", "tid = '{$thread['tid']}'");
$poll = $db->fetch_array($query);

					



					$poll_array = array(
'tid' => $newtid,
'question' => $db->escape_string($poll['question']),

					$poll_array = array(
'tid' => $newtid,
'question' => $db->escape_string($poll['question']),

Zeile 546Zeile 684
					);
$db->insert_query(TABLE_PREFIX."polls", $poll_array);
$new_pid = $db->insert_id();

					);
$db->insert_query(TABLE_PREFIX."polls", $poll_array);
$new_pid = $db->insert_id();

				}

$query = $db->simple_select(TABLE_PREFIX."pollvotes", "*", "tid = '{$thread['tid']}'");
while($pollvote = $db->fetch_array($query))
{
$pollvote_array = array(
'pid' => $new_pid,
'uid' => $pollvote['uid'],
'voteoption' => $pollvote['voteoption'],
'dateline' => $pollvote['dateline'],
);
$db->insert_query(TABLE_PREFIX."pollvotes", $pollvote_array);




$query = $db->simple_select(TABLE_PREFIX."pollvotes", "*", "pid = '{$poll['pid']}'");
while($pollvote = $db->fetch_array($query))
{
$pollvote_array = array(
'pid' => $new_pid,
'uid' => $pollvote['uid'],
'voteoption' => $pollvote['voteoption'],
'dateline' => $pollvote['dateline'],
);
$db->insert_query(TABLE_PREFIX."pollvotes", $pollvote_array);
}

$db->update_query(TABLE_PREFIX."threads", array('poll' => $new_pid), "tid='{$newtid}'");

				}

$query = $db->simple_select(TABLE_PREFIX."posts", "*", "tid = '{$thread['tid']}'");

				}

$query = $db->simple_select(TABLE_PREFIX."posts", "*", "tid = '{$thread['tid']}'");

Zeile 581Zeile 721
					);
$db->insert_query(TABLE_PREFIX."posts", $post_array);
$pid = $db->insert_id();

					);
$db->insert_query(TABLE_PREFIX."posts", $post_array);
$pid = $db->insert_id();

					

				

					// Insert attachments for this post
$query2 = $db->simple_select(TABLE_PREFIX."attachments", "*", "pid = '{$post['pid']}'");
while($attachment = $db->fetch_array($query2))

					// Insert attachments for this post
$query2 = $db->simple_select(TABLE_PREFIX."attachments", "*", "pid = '{$post['pid']}'");
while($attachment = $db->fetch_array($query2))

Zeile 601Zeile 741
						$db->insert_query(TABLE_PREFIX."attachments", $attachment_array);
}
}

						$db->insert_query(TABLE_PREFIX."attachments", $attachment_array);
}
}

				
update_first_post($newtid);
update_thread_count($newtid);



update_thread_data($newtid);



				$the_thread = $newtid;
break;
default:
case "move": // plain move thread

				$the_thread = $newtid;
break;
default:
case "move": // plain move thread

				$plugins->run_hooks("moderation_do_move_simple");















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

if($thread['visible'] == 1)
{
$num_threads++;
}
else
{
$num_unapproved_threads++;
// Implied forum unapproved count for unapproved threads
$num_unapproved_posts = $thread['replies']+1;
}

$num_posts = $thread['replies']+1;
$num_unapproved_posts = $thread['unapprovedposts'];

	
$sqlarray = array(
"fid" => $new_fid,

	
$sqlarray = array(
"fid" => $new_fid,

Zeile 629Zeile 782
			ORDER BY posts DESC
");
while($posters = $db->fetch_array($query))

			ORDER BY posts DESC
");
while($posters = $db->fetch_array($query))

		{
if($method == "copy" && $newforum['usepostcounts'] != "no")
{
$pcount = "+{$posters['posts']}";
}
elseif($method != "copy" && ($newforum['usepostcounts'] != "no" && $forum['usepostcounts'] == "no"))
{

		{
if($method == "copy" && $newforum['usepostcounts'] != "no" && $posters['visible'] != "no")
{





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

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

			}
elseif($method != "copy" && ($newforum['usepostcounts'] == "no" && $forum['usepostcounts'] != "no"))





			}
elseif($method != "copy" && ($newforum['usepostcounts'] != "no" && $forum['usepostcounts'] == "no" && $posters['visible'] != "no"))
{
$pcount = "+{$posters['posts']}";
}
elseif($method != "copy" && ($newforum['usepostcounts'] == "no" && $forum['usepostcounts'] != "no" && $posters['visible'] != "no"))

			{
$pcount = "-{$posters['posts']}";

			{
$pcount = "-{$posters['posts']}";

			}

			}

			if(!empty($pcount))
{
$db->query("UPDATE ".TABLE_PREFIX."users SET postnum=postnum$pcount WHERE uid='{$posters['uid']}'");
}

			if(!empty($pcount))
{
$db->query("UPDATE ".TABLE_PREFIX."users SET postnum=postnum$pcount WHERE uid='{$posters['uid']}'");
}

		}

		}


// Update forum counts


// Update forum counts

		if($fid != $new_fid)
{
update_forum_count($new_fid);
}
update_forum_count($fid);














		$update_array = array( 
"threads" => "+{$num_threads}",
"unapprovedthreads" => "+{$num_unapproved_threads}",
"posts" => "+{$num_posts}",
"unapprovedposts" => "+{$num_unapproved_posts}"
);
update_forum_counters($new_fid, $update_array);

if($method != "copy")
{
$update_array = array(
"threads" => "-{$num_threads}",
"unapprovedthreads" => "-{$num_unapproved_threads}",
"posts" => "-{$num_posts}",
"unapprovedposts" => "-{$num_unapproved_posts}"
);
update_forum_counters($fid, $update_array);
}


if(isset($newtid))
{


if(isset($newtid))
{

Zeile 661Zeile 827
		}
else
{

		}
else
{

 
			// Remove thread subscriptions for the users who no longer have permission to view the thread
$this->remove_thread_subscriptions($tid, false, $new_fid);


			return $tid;
}
}

			return $tid;
}
}





	/**
* Merge one thread into another
*

	/**
* Merge one thread into another
*

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

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

		global $db, $mybb, $mergethread, $thread;




		global $db, $mybb, $mergethread, $thread, $plugins;

$mergetid = intval($mergetid);
$tid = intval($tid);


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


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

		{
$mergetid = intval($mergetid);
$query = $db->simple_select(TABLE_PREFIX."threads", "*", "tid='".intval($mergetid)."'");
$mergethread = $db->fetch_array($query);

		{	
$mergethread = get_thread($mergetid);



		}
if(!isset($thread['tid']) || $thread['tid'] != $tid)
{

		}
if(!isset($thread['tid']) || $thread['tid'] != $tid)
{

			$tid = intval($tid);
$query = $db->simple_select(TABLE_PREFIX."threads", "*", "tid='".intval($tid)."'");
$thread = $db->fetch_array($query);

			$thread = get_thread($tid);



		}
$pollsql = '';
if($mergethread['poll'])
{

		}
$pollsql = '';
if($mergethread['poll'])
{

			$pollsql = ", poll='{$mergethread['poll']}'";

			$pollsql['poll'] = $mergethread['poll'];

			$sqlarray = array(
"tid" => $tid,
);

			$sqlarray = array(
"tid" => $tid,
);

Zeile 700Zeile 868
		}
else
{

		}
else
{

			$query = $db->simple_select(TABLE_PREFIX."threads", "*", "poll='{$mergethread['poll']}' AND tid != '".intval($mergetid)."'");

			$query = $db->simple_select(TABLE_PREFIX."threads", "*", "poll='{$mergethread['poll']}' AND tid != '{$mergetid}'");

			$pollcheck = $db->fetch_array($query);
if(!$pollcheck['poll'])
{

			$pollcheck = $db->fetch_array($query);
if(!$pollcheck['poll'])
{

Zeile 714Zeile 882
		$sqlarray = array(
"tid" => $tid,
"fid" => $thread['fid'],

		$sqlarray = array(
"tid" => $tid,
"fid" => $thread['fid'],

			"replyto" => 0

			"replyto" => 0

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

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

		
$db->query("UPDATE ".TABLE_PREFIX."threads SET subject='$subject' $pollsql WHERE tid='$tid'");
$sqlarray = array(



$pollsql['subject'] = $subject;
$db->update_query(TABLE_PREFIX."threads", $pollsql, "tid='$tid'");
$sqlarray = array(

			"closed" => "moved|$tid",

			"closed" => "moved|$tid",

		);

		);

		$db->update_query(TABLE_PREFIX."threads", $sqlarray, "closed='moved|$mergetid'");
$sqlarray = array(
"tid" => $tid,
);
$db->update_query(TABLE_PREFIX."favorites", $sqlarray, "tid='$mergetid'");
update_first_post($tid);

		$db->update_query(TABLE_PREFIX."threads", $sqlarray, "closed='moved|$mergetid'");
$sqlarray = array(
"tid" => $tid,
);
$db->update_query(TABLE_PREFIX."favorites", $sqlarray, "tid='$mergetid'");
update_first_post($tid);

 

$plugins->run_hooks("class_moderation_merge_threads", array("mergetid" => $tid, "tid" => $tid, "subject" => $subject));


$this->delete_thread($mergetid);


$this->delete_thread($mergetid);

		update_thread_count($tid);
if($thread['fid'] != $mergethread['fid'])
{
update_forum_count($mergethread['fid']);
}
update_forum_count($fid);

 




 
		$updated_stats = array(
"replies" => '+'.($mergethread['replies']+1),
"unapprovedposts" => "+{$mergethread['unapprovedposts']}"
);
update_thread_counters($tid, $updated_stats);

// Thread is not in current forum
if($mergethread['fid'] != $thread['fid'])
{
// If new thread is unapproved, implied counter comes in to effect
if($thread['visible'] == 0)
{
$updated_stats = array(
"unapprovedposts" => '+'.($mergethread['replies']+$mergethread['unapprovedposts'])
);
}
else
{
$updated_stats = array(
"posts" => '+'.($mergethread['replies']+1),
"unapprovedposts" => "+{$mergethread['unapprovedposts']}"
);
}
update_forum_counters($thread['fid'], $updated_stats);
}

		return true;
}


		return true;
}


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

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

		global $db, $thread;

		global $db, $thread, $plugins;


if(!isset($thread['tid']) || $thread['tid'] != $tid)
{


if(!isset($thread['tid']) || $thread['tid'] != $tid)
{

Zeile 764Zeile 954
		// Create the new thread
$newsubject = $db->escape_string($newsubject);
$query = array(

		// Create the new thread
$newsubject = $db->escape_string($newsubject);
$query = array(

			"fid" => $moveto,

			"fid" => intval($moveto),

			"subject" => $newsubject,

			"subject" => $newsubject,

			"icon" => $thread['icon'],
"uid" => $thread['uid'],
"username" => $thread['username'],
"dateline" => $thread['dateline'],
"lastpost" => $thread['lastpost'],
"lastposter" => $thread['lastposter'],

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

			"replies" => count($pids)-1,

			"replies" => count($pids)-1,

			"visible" => "1",

			"visible" => 1,

			"notes" => ''
);
$db->insert_query(TABLE_PREFIX."threads", $query);

			"notes" => ''
);
$db->insert_query(TABLE_PREFIX."threads", $query);

Zeile 806Zeile 996
			if($oldusepcounts == "yes" && $newusepcounts == "no")
{
$pcount = "-{$posters['posts']}";

			if($oldusepcounts == "yes" && $newusepcounts == "no")
{
$pcount = "-{$posters['posts']}";

			}

			}

			elseif($oldusepcounts == "no" && $newusepcounts == "yes")

			elseif($oldusepcounts == "no" && $newusepcounts == "yes")

			{

			{

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

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

			}

			}


if(!empty($pcount))
{
$db->query("UPDATE ".TABLE_PREFIX."users SET postnum=postnum$pcount WHERE uid='{$posters['uid']}'");


if(!empty($pcount))
{
$db->query("UPDATE ".TABLE_PREFIX."users SET postnum=postnum$pcount WHERE uid='{$posters['uid']}'");

 
			}
}

$num_visible = $num_unnaproved = $num_attachments = 0;
$query = $db->query("
SELECT p.visible, a.aid
FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."attachments a ON (a.pid=p.pid AND a.visible=1)
WHERE p.tid='{$newtid}'
");
while($post = $db->fetch_array($query))
{
if($post['visible'] == 1)
{
$num_visible++;
if($post['aid'])
{
$num_attachments++;
}
}
else if($post['visible'] == 0)
{
$num_unapproved++;

			}
}

// Update the subject of the first post in the new thread
$query = $db->simple_select(TABLE_PREFIX."posts", "pid", "tid='$newtid'", array('order_by' => 'dateline', 'limit' => 1));
$newthread = $db->fetch_array($query);

			}
}

// Update the subject of the first post in the new thread
$query = $db->simple_select(TABLE_PREFIX."posts", "pid", "tid='$newtid'", array('order_by' => 'dateline', 'limit' => 1));
$newthread = $db->fetch_array($query);

		$sqlarray = array(

		$sqlarray = array(

			"subject" => $newsubject,

			"subject" => $newsubject,

			"replyto" => 0

			"replyto" => 0

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

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





		// Update the subject of the first post in the old thread
$query = $db->simple_select(TABLE_PREFIX."posts", "pid", "tid='$tid'", array('order_by' => 'dateline', 'limit' => 1));
$oldthread = $db->fetch_array($query);

		// Update the subject of the first post in the old thread
$query = $db->simple_select(TABLE_PREFIX."posts", "pid", "tid='$tid'", array('order_by' => 'dateline', 'limit' => 1));
$oldthread = $db->fetch_array($query);

Zeile 836Zeile 1049
		);
$db->update_query(TABLE_PREFIX."posts", $sqlarray, "pid='{$oldthread['pid']}'");


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


 
		$plugins->run_hooks("class_moderation_split_posts", array("pids" => $pids, "tid" => $tid, "moveto" => $moveto, "newsubject" => $newsubject, "destination_tid" => $destination_tid));

// Update old thread stats
$update_array = array(
"replies" => "-{$num_visible}",
"unapprovedposts" => "-{$num_unapproved}",
"attachmentcount" => "-{$num_attachments}"
);
update_thread_counters($thread['tid'], $update_array);

// Update new thread stats
$update_array = array(
"replies" => $num_visible-1,
"unapprovedposts" => $num_unapproved,
"attachmentcount" => $num_attachments
);
update_thread_counters($newtid, $update_array);

if($thread['fid'] != $moveto)
{
// Update old forum stats
$update_array = array(
"posts" => "-{$num_visible}",
"unapprovedposts" => "-{$num_unapproved}"
);
update_forum_counters($thread['fid'], $update_array);

// Update new forum stats
$update_array = array(
"posts" => "+{$num_visible}",
"unapprovedposts" => "+{$num_unapproved}"
);
}
else
{
$update_array = array();
}

if($thread['visible'] == 1)
{
$update_array['threads'] = "+1";
}
else if($thread['visible'] == 0)
{
$update_array['unapprovedthreads'] = "+1";
}
update_forum_counters($moveto, $update_array);

// Update first post columns

		update_first_post($tid);
update_first_post($newtid);

		update_first_post($tid);
update_first_post($newtid);

		update_thread_count($tid);
update_thread_count($newtid);
if($moveto != $thread['fid'])
{
update_forum_count($moveto);
}
update_forum_count($thread['fid']);

 

// Merge new thread with destination thread if specified
if($destination_tid)


// Merge new thread with destination thread if specified
if($destination_tid)

Zeile 857Zeile 1112

/**
* Move multiple threads to new forum


/**
* Move multiple threads to new forum

	 *

	 *

	 * @param array Thread IDs
* @param int Destination forum
* @return boolean true
*/
function move_threads($tids, $moveto)
{

	 * @param array Thread IDs
* @param int Destination forum
* @return boolean true
*/
function move_threads($tids, $moveto)
{

		global $db;

		global $db, $plugins;


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


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

 
			
$newforum = get_forum($moveto);

		

		

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


		$total_posts = $total_unapproved_posts = $total_threads = $total_unapproved_threads = 0; 
$query = $db->simple_select(TABLE_PREFIX."threads", "fid, visible, replies, unapprovedposts", "tid IN ($tid_list)");

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

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

			$update_forums[$thread['fid']] = $thread['fid'];
















































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

$total_posts += $thread['replies']+1;
$total_unapproved_posts += $thread['unapprovedposts'];

$forum_counters[$thread['fid']]['posts'] += $thread['replies']+1;
$forum_counters[$thread['fid']]['unapprovedposts'] += $thread['unapprovedposts'];

if($thread['visible'] == 1)
{
$forum_counters[$thread['fid']]['threads']++;
++$total_threads;
}
else
{
$forum_counters[$thread['fid']]['unapprovedthreads']++;
$forum_counters[$thread['fid']]['unapprovedposts'] += $thread['replies']; // Implied unapproved posts counter for unapproved threads
++$total_unapproved_threads;
}

$query1 = $db->query("
SELECT COUNT(p.pid) AS posts, u.uid
FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
WHERE tid='{$thread['tid']}'
GROUP BY u.uid
ORDER BY posts DESC
");
while($posters = $db->fetch_array($query1))
{
if($method == "copy" && $newforum['usepostcounts'] != "no" && $posters['visible'] != "no")
{
$pcount = "+{$posters['posts']}";
}
elseif($method != "copy" && ($newforum['usepostcounts'] != "no" && $forum['usepostcounts'] == "no" && $posters['visible'] != "no"))
{
$pcount = "+{$posters['posts']}";
}
elseif($method != "copy" && ($newforum['usepostcounts'] == "no" && $forum['usepostcounts'] != "no" && $posters['visible'] != "no"))
{
$pcount = "-{$posters['posts']}";
}

if(!empty($pcount))
{
$db->query("UPDATE ".TABLE_PREFIX."users SET postnum=postnum$pcount WHERE uid='{$posters['uid']}'");
}
}

		}

		}



		

		$sqlarray = array(
"fid" => $moveto,
);
$db->update_query(TABLE_PREFIX."threads", $sqlarray, "tid IN ($tid_list)");
$db->update_query(TABLE_PREFIX."posts", $sqlarray, "tid IN ($tid_list)");


		$sqlarray = array(
"fid" => $moveto,
);
$db->update_query(TABLE_PREFIX."threads", $sqlarray, "tid IN ($tid_list)");
$db->update_query(TABLE_PREFIX."posts", $sqlarray, "tid IN ($tid_list)");


		update_forum_count($moveto);
foreach($update_forums as $fid)
{
update_forum_count($fid);
}




























		$plugins->run_hooks("class_moderation_move_threads", array("tids" => $tids, "moveto" => $moveto));

foreach($forum_counters as $fid => $counter)
{
$updated_count = array(
"posts" => "-{$counter['posts']}",
"unapprovedposts" => "-{$counter['unapprovedposts']}"
);
if($counter['threads'])
{
$updated_count['threads'] = "-{$counter['threads']}";
}
if($counter['unapprovedthreads'])
{
$updated_count['unapprovedthreads'] = "-{$counter['unapprovedthreads']}";
}
update_forum_counters($fid, $updated_count);

// Do post count changes if changing between countable and non-countable forums
}

$updated_count = array(
"threads" => "+{$total_threads}",
"unapprovedthreads" => "+{$total_unapproved_threads}",
"posts" => "+{$total_posts}",
"unapprovedposts" => "+{$total_unapproved_posts}"
);

update_forum_counters($moveto, $updated_count);

// Remove thread subscriptions for the users who no longer have permission to view the thread
$this->remove_thread_subscriptions($tid_list, false, $moveto);

		return true;
}

/**
* Approve multiple posts

		return true;
}

/**
* Approve multiple posts

	 *
* @param array PIDs
* @param int Thread ID
* @param int Forum ID
* @return boolean true
*/
function approve_posts($pids, $tid, $fid)
{
global $db, $cache;

$thread = get_thread($tid);

foreach($pids as $pid)
{
$query = $db->query("
SELECT p.tid, f.usepostcounts, p.uid
FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=p.fid)
WHERE p.pid='{$pid}' AND p.visible = '0'
");
while($post = $db->fetch_array($query))
{
// If post counts enabled in this forum and the post hasn't already been approved, add 1
if($post['usepostcounts'] != "no")
{
$db->query("UPDATE ".TABLE_PREFIX."users SET postnum=postnum+1 WHERE uid='".$post['uid']."'");
}
}
}

$where = "pid IN (".implode(",", $pids).")";

	 *
* @param array PIDs
* @return boolean true
*/
function approve_posts($pids)
{
global $db, $cache;

$num_posts = 0;
$pid_list = implode(",", $pids);
$pids = array();






















// Make visible
$approve = array(
"visible" => 1,


// Make visible
$approve = array(
"visible" => 1,

		);
$db->update_query(TABLE_PREFIX."posts", $approve, $where);





















































		);

$query = $db->query("
SELECT p.pid, p.tid, f.fid, f.usepostcounts, p.uid, p.visible, t.visible AS threadvisible, t.replies AS threadreplies, t.firstpost AS threadfirstpost, t.unapprovedposts AS threadunapprovedposts
FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=p.fid)
WHERE p.pid IN ($pid_list) AND p.visible = '0'
");
while($post = $db->fetch_array($query))
{
// If post counts enabled in this forum and the post hasn't already been approved, add 1
if($post['usepostcounts'] != "no" && $thread['visible'] == 1)
{
$db->query("UPDATE ".TABLE_PREFIX."users SET postnum=postnum+1 WHERE uid='".$post['uid']."'");
}

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

if(!$thread_counters[$post['tid']]['unapprovedposts'])
{
$thread_counters[$post['tid']]['unapprovedposts'] = $post['threadunapprovedposts'];
}
--$thread_counters[$post['tid']]['unapprovedposts'];

if($post['threadfirstpost'] != $post['pid'])
{
if(!$thread_counters[$post['tid']]['replies'])
{
$thread_counters[$post['tid']]['replies'] = $post['threadreplies'];
}
++$thread_counters[$post['tid']]['replies'];
}

// Only add to the forum count if the thread is invisible
if($post['threadvisible'] == 0)
{
++$forum_counters[$post['fid']]['num_posts'];
}

// If the first post here matches and thread is invisible, we approve the thread too
if($post['threadfirstpost'] == $post['pid'] && $post['threadvisible'] == 0)
{
$thread_counters[$post['tid']]['visible'] = 1;
$thread_counters[$post['tid']]['unapprovedposts'] += 1;
$forum_counters[$post['fid']]['num_posts'] += $post['threadreplies'];
$forum_counters[$post['fid']]['num_threads']++;
}
}

if(!count($pids)) return false;

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





		// If this is the first post of the thread, also approve the thread
$query = $db->simple_select(TABLE_PREFIX."posts", "tid", "pid='{$thread['firstpost']}' AND visible='1'");
$first_post = $db->fetch_array($query);
if($first_post['tid'])






		if(is_array($thread_counters))
{
foreach($thread_counters as $tid => $counters)
{
$db->update_query(TABLE_PREFIX."threads", $counters, "tid='{$tid}'");
}
}

if(is_array($forum_counters))

		{

		{

			$db->update_query(TABLE_PREFIX."threads", $approve, "tid='{$first_post['tid']}'");











			foreach($forum_counters as $fid => $counters)
{
$updated_forum_stats = array(
"posts" => "+{$counters['num_posts']}",
"unapprovedposts" => "-{$counters['num_posts']}",
"threads" => "+{$counters['num_threads']}",
"unapprovedthreads" => "-{$counters['num_threads']}"
);

update_forum_counters($fid, $updated_forum_stats);
}

		}

		}

		update_thread_count($tid);
update_forum_count($fid);
$cache->updatestats();


 
		return true;
}


		return true;
}


Zeile 946Zeile 1321
	 * Unapprove multiple posts
*
* @param array PIDs

	 * Unapprove multiple posts
*
* @param array PIDs

	 * @param int Thread ID
* @param int Forum ID
* @return boolean true

	 * @return boolean true



	 */

	 */

	function unapprove_posts($pids, $tid, $fid)

	function unapprove_posts($pids)

	{
global $db, $cache;

	{
global $db, $cache;

 

$pid_list = implode(",", $pids);
$pids = array();

// Make invisible
$approve = array(
"visible" => 0,
);

		

		

		$thread = get_thread($tid);

foreach($pids as $pid)
{
$query = $db->query("
SELECT p.tid, f.usepostcounts, p.uid
FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=p.fid)
WHERE p.pid='{$pid}' AND p.visible = '1'
");
while($post = $db->fetch_array($query))
{
// If post counts enabled in this forum and the post hasn't already been unapproved, remove 1
if($post['usepostcounts'] != "no")












		$query = $db->query("
SELECT p.pid, p.tid, f.fid, f.usepostcounts, p.uid, p.visible, t.visible AS threadvisible, t.replies AS threadreplies, t.firstpost AS threadfirstpost, t.unapprovedposts AS threadunapprovedposts
FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=p.fid)
WHERE p.pid IN ($pid_list) AND p.visible = '1'
");
while($post = $db->fetch_array($query))
{
// If post counts enabled in this forum and the post hasn't already been unapproved, subtract 1
if($post['usepostcounts'] != "no" && $thread['visible'] == 1)
{
$db->query("UPDATE ".TABLE_PREFIX."users SET postnum=postnum-1 WHERE uid='".$post['uid']."'");
}

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

if(!$thread_counters[$post['tid']]['unapprovedposts'])
{
$thread_counters[$post['tid']]['unapprovedposts'] = $post['threadunapprovedposts'];
}
++$thread_counters[$post['tid']]['unapprovedposts'];
if($post['threadfirstpost'] != $post['pid'])
{
if(!$thread_counters[$post['tid']]['replies'])

				{

				{

					$db->query("UPDATE ".TABLE_PREFIX."users SET postnum=postnum-1 WHERE uid='".$post['uid']."'");

					$thread_counters[$post['tid']]['replies'] = $post['threadreplies'];

				}

				}

			}
}

$where = "pid IN (".implode(",", $pids).")";
















				$thread_counters[$post['tid']]['replies'] = $thread_counters[$post['tid']]['replies']-1;
}

if($post['threadvisible'] == 1)
{
++$forum_counters[$post['fid']]['num_posts'];
}

// If the first post here matches and thread is visible, we unapprove the thread too
if($post['threadfirstpost'] == $post['pid'] && $post['threadvisible'] == 1)
{
$thread_counters[$post['tid']]['visible'] = 0;
$thread_counters[$post['tid']]['unapprovedposts'] -= 1;
$forum_counters[$post['fid']]['num_posts'] += $post['threadreplies'];
$forum_counters[$post['fid']]['num_threads']++;
}
}

if(!count($pids)) return false;





		// Make visible
$unapprove = array(
"visible" => 0,
);
$db->update_query(TABLE_PREFIX."posts", $unapprove, $where);

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








		// If this is the first post of the thread, also approve the thread
$query = $db->simple_select(TABLE_PREFIX."posts", "tid", "pid='{$thread['firstpost']}' AND visible='0'");
$first_post = $db->fetch_array($query);
if($first_post['tid'])

		if(is_array($thread_counters))




		{

		{

			$db->update_query(TABLE_PREFIX."threads", $unapprove, "tid='{$first_post['tid']}'");



















			foreach($thread_counters as $tid => $counters)
{
$db->update_query(TABLE_PREFIX."threads", $counters, "tid='{$tid}'");
}
}

if(is_array($forum_counters))
{
foreach($forum_counters as $fid => $counters)
{
$updated_forum_stats = array(
"posts" => "-{$counters['num_posts']}",
"unapprovedposts" => "+{$counters['num_posts']}",
"threads" => "-{$counters['num_threads']}",
"unapprovedthreads" => "+{$counters['num_threads']}"
);

update_forum_counters($fid, $updated_forum_stats);
}

		}

		}

		update_thread_count($tid);
update_forum_count($fid);
$cache->updatestats();


 
		return true;
}


		return true;
}


Zeile 1005Zeile 1420
	 */
function change_thread_subject($tids, $format)
{

	 */
function change_thread_subject($tids, $format)
{

		global $db;

		global $db, $plugins;


// Get tids into list
if(!is_array($tids))


// Get tids into list
if(!is_array($tids))

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

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

 

$lastpost_subject = array(
"lastpostsubject" => $new_subject['subject']
);

$db->update_query(TABLE_PREFIX."forums", $lastpost_subject, "lastposttid='{$thread['tid']}'");

		}

		}

	




$plugins->run_hooks("class_moderation_change_thread_subject", array("tids" => $tids, "format" => $format));


		return true;
}


		return true;
}


Zeile 1037Zeile 1460
	 * @return boolean true
*/
function expire_thread($tid, $deletetime)

	 * @return boolean true
*/
function expire_thread($tid, $deletetime)

	{
global $db;

	{
global $db, $plugins;


$update_thread = array(
"deletetime" => intval($deletetime)
);
$db->update_query(TABLE_PREFIX."threads", $update_thread, "tid='{$tid}'");


$update_thread = array(
"deletetime" => intval($deletetime)
);
$db->update_query(TABLE_PREFIX."threads", $update_thread, "tid='{$tid}'");






$plugins->run_hooks("class_moderation_expire_thread", array("tid" => $tid, "deletetime" => $deletetime));


		return true;
}


		return true;
}


Zeile 1052Zeile 1477
	 * Toggle post visibility (approved/unapproved)
*
* @param array Post IDs

	 * Toggle post visibility (approved/unapproved)
*
* @param array Post IDs

	 * @param int Thread ID
* @param int Forum ID

 
	 * @return boolean true
*/

	 * @return boolean true
*/

	function toggle_post_visibility($pids, $tid, $fid)

	function toggle_post_visibility($pids)

	{
global $db;
$pid_list = implode(',', $pids);

	{
global $db;
$pid_list = implode(',', $pids);

Zeile 1074Zeile 1497
		}
if(is_array($unapprove))
{

		}
if(is_array($unapprove))
{

			$this->unapprove_posts($unapprove, $tid, $fid);

			$this->unapprove_posts($unapprove);

		}
if(is_array($approve))
{

		}
if(is_array($approve))
{

			$this->approve_posts($approve, $tid, $fid);

			$this->approve_posts($approve);

		}
return true;
}

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

		}
return true;
}

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

	 *
* @param array Thread IDs

	 *
* @param array Thread IDs

	 * @param int Forum ID
* @return boolean true
*/

	 * @param int Forum ID
* @return boolean true
*/

Zeile 1100Zeile 1523
			if($thread['visible'] == 1)
{
$unapprove[] = $thread['tid'];

			if($thread['visible'] == 1)
{
$unapprove[] = $thread['tid'];

			}
else

			}
else

			{
$approve[] = $thread['tid'];
}

			{
$approve[] = $thread['tid'];
}

		}

		}

		if(is_array($unapprove))

		if(is_array($unapprove))

		{

		{

			$this->unapprove_threads($unapprove, $fid);

			$this->unapprove_threads($unapprove, $fid);

		}
if(is_array($approve))
{
$this->approve_threads($approve, $fid);
}
return true;
}


		}
if(is_array($approve))
{
$this->approve_threads($approve, $fid);
}
return true;
}


	/**
* Toggle threads open/closed
*

	/**
* Toggle threads open/closed
*

Zeile 1131Zeile 1554
		while($thread = $db->fetch_array($query))
{
if($thread['closed'] == "yes")

		while($thread = $db->fetch_array($query))
{
if($thread['closed'] == "yes")

			{

			{

				$open[] = $thread['tid'];

				$open[] = $thread['tid'];

			}

			}

			elseif($thread['closed'] == '')

			elseif($thread['closed'] == '')

			{

			{

				$close[] = $thread['tid'];

				$close[] = $thread['tid'];

			}

			}

		}
if(is_array($open))
{

		}
if(is_array($open))
{

Zeile 1147Zeile 1570
		{
$this->close_threads($close);
}

		{
$this->close_threads($close);
}

 
		return true;
}
/**
* 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 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 (if 0, will query database)
* @return boolean true
*/
function remove_thread_subscriptions($tids, $all = true, $fid = 0)
{
global $db, $plugins;

// Format thread IDs
if(!is_array($tids))
{
$tids = array($tids);
}
$tids_csv = implode(',', $tids);

// Delete only subscriptions from users who no longer have permission to read the thread.
if(!$all)
{
// Get forum ID
if(!$fid)
{
$query = $db->simple_select(TABLE_PREFIX."threads", "fid", "tid='{$tid[0]}'");
}

// Get groups that cannot view the forum or its threads
$forum_parentlist = get_parent_list($fid);
$query = $db->simple_select(TABLE_PREFIX."forumpermissions", "gid", "fid IN ({$forum_parentlist}) AND (canview='no' OR canviewthreads='no')");
$groups = array();
while($group = $db->fetch_array($query))
{
$groups[] = $group['gid'];
$additional_groups .= " OR CONCAT(',',u.additionalgroups,',') LIKE ',{$group['gid']},'";
}
// If there are groups found, delete subscriptions from users in these groups
if(count($groups) > 0)
{
$groups_csv = implode(',', $groups);
$query = $db->query("
SELECT s.tid, u.uid
FROM ".TABLE_PREFIX."favorites s
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=s.uid)
WHERE s.type='s' AND s.tid IN ({$tids_csv})
AND (u.usergroup IN ({$groups_csv}){$additional_groups})
");
while($favorites = $db->fetch_array($query))
{
$db->query("DELETE FROM ".TABLE_PREFIX."favorites WHERE uid='{$favorites['uid']}' AND tid='{$favorites['tid']}'");
}
}
}
// Delete all subscriptions of this thread
else
{
$db->delete_query(TABLE_PREFIX."favorites", "tid IN ({$tids_csv}) AND type='s'");
}

$plugins->run_hooks("class_moderation_remove_thread_subscriptions", array("tids" => $tids, "all" => $all, "fid" => $fid));


		return true;
}
}

		return true;
}
}