Vergleich inc/class_moderation.php - 1.8.0 - 1.8.6

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


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

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

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





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

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

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


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


		return true;
}

/**
* Stick one or more threads
*

		return true;
}

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

	{
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_stick_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_stick_threads", $tids);


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



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


Zeile 114Zeile 114
	/**
* 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 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)

	{
global $db, $plugins;


	{
global $db, $plugins;


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

// Delete the redirects
$tid = (int)$tid;
if(empty($tid))

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

// Delete the redirects
$tid = (int)$tid;
if(empty($tid))

		{

		{

			return false;

			return false;

		}

		}


$query = $db->simple_select('threads', 'tid', "closed='moved|$tid'");
while($redirect_tid = $db->fetch_field($query, 'tid'))


$query = $db->simple_select('threads', 'tid', "closed='moved|$tid'");
while($redirect_tid = $db->fetch_field($query, '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)
{

	 */
function delete_thread($tid)
{

Zeile 238Zeile 238
			}
}


			}
}


		if($forum['usethreadcounts'] != 0)

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

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

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

Zeile 315Zeile 315
				$updated_counters['deletedposts'] = -1;
}
else

				$updated_counters['deletedposts'] = -1;
}
else

			{

			{

				$updated_counters['unapprovedposts'] = -1;
}
}

				$updated_counters['unapprovedposts'] = -1;
}
}

Zeile 325Zeile 325
		update_forum_lastpost($thread['fid']);

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

		update_forum_lastpost($thread['fid']);

$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 357Zeile 357

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 371
		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 405Zeile 405
			}

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





			++$forum_counters[$forum['fid']]['num_threads'];
$forum_counters[$forum['fid']]['num_posts'] += $thread['replies']+1; // Remove implied visible from count
$forum_counters[$forum['fid']]['num_deleted_posts'] += $thread['deletedposts'];

			++$forum_counters[$forum['fid']]['num_threads'];
$forum_counters[$forum['fid']]['num_posts'] += $thread['replies']+1; // Remove implied visible from count
$forum_counters[$forum['fid']]['num_deleted_posts'] += $thread['deletedposts'];

Zeile 424Zeile 424
				while($counter = $db->fetch_array($query))
{
$user_counters[$counter['uid']]['num_posts'] += $counter['posts'];

				while($counter = $db->fetch_array($query))
{
$user_counters[$counter['uid']]['num_posts'] += $counter['posts'];

				}

				}

			}


			}


			if($forum['usethreadcounts'] != 0)

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

			{
++$user_counters[$thread['uid']]['num_threads'];
}

			{
++$user_counters[$thread['uid']]['num_threads'];
}

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

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

			}


			}


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

if(!empty($forum_counters))

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

if(!empty($forum_counters))

Zeile 478Zeile 478
						"posts" => "+{$counters['num_posts']}",
"unapprovedposts" => "-{$counters['num_unapproved_posts']}",
"deletedposts" => "+{$counters['num_deleted_posts']}"

						"posts" => "+{$counters['num_posts']}",
"unapprovedposts" => "-{$counters['num_unapproved_posts']}",
"deletedposts" => "+{$counters['num_deleted_posts']}"

					);
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 502Zeile 502
	/**
* 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)
{

	 */
function unapprove_threads($tids)
{

Zeile 586Zeile 586
					}
}


					}
}


				if($thread['visible'] == 1 && $forum['usethreadcounts'] != 0)

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

				{
++$user_counters[$thread['uid']]['num_threads'];
}

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

				{
++$user_counters[$thread['uid']]['num_threads'];
}

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

		}

		}


$approve = array(
"visible" => 0


$approve = array(
"visible" => 0

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

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

		}

		}

		if(!empty($redirect_tids))
{
$this->unapprove_threads($redirect_tids);

		if(!empty($redirect_tids))
{
$this->unapprove_threads($redirect_tids);

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

if(!empty($forum_counters))

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

if(!empty($forum_counters))

		{

		{

			foreach($forum_counters as $fid => $counters)
{
// Update stats

			foreach($forum_counters as $fid => $counters)
{
// Update stats

Zeile 644Zeile 644
					"threadnum" => "-{$counters['num_threads']}",
);
update_user_counters($uid, $update_array);

					"threadnum" => "-{$counters['num_threads']}",
);
update_user_counters($uid, $update_array);

			}
}

return true;

			}
}

return true;

	}

/**
* 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 671
		");
$post = $db->fetch_array($query);
if(!$post)

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

		{

		{

			return false;
}

$forum = get_forum($post['fid']);
// If post counts enabled in this forum and it hasn't already been unapproved, remove 1
if($forum['usepostcounts'] != 0 && $post['visible'] != -1 && $post['visible'] != 0 && $post['threadvisible'] != 0 && $post['threadvisible'] != -1)

			return false;
}

$forum = get_forum($post['fid']);
// If post counts enabled in this forum and it hasn't already been unapproved, remove 1
if($forum['usepostcounts'] != 0 && $post['visible'] != -1 && $post['visible'] != 0 && $post['threadvisible'] != 0 && $post['threadvisible'] != -1)

		{

		{

			update_user_counters($post['uid'], array('postnum' => "-1"));
}


			update_user_counters($post['uid'], array('postnum' => "-1"));
}


Zeile 698Zeile 698

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


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

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

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

		elseif($post['visible'] == -1)
{
$update_array = array(

		elseif($post['visible'] == -1)
{
$update_array = array(

Zeile 728Zeile 728
				"unapprovedposts" => "-1"
);
}

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

		elseif($post['visible'] == -1 || $post['threadvisible'] == 0)

		elseif($post['visible'] == -1 || $post['threadvisible'] == -1)

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

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

Zeile 750Zeile 750
	/**
* 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
*/
function merge_posts($pids, $tid=0, $sep="new_line")

	 * @return int ID of the post into which all other posts are merged
*/
function merge_posts($pids, $tid=0, $sep="new_line")

Zeile 813Zeile 812
				else
{
$message .= "[hr]{$post['message']}";

				else
{
$message .= "[hr]{$post['message']}";

				}


				}


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

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

Zeile 828Zeile 827
				{
--$thread_counters[$post['tid']]['replies'];
$forum = get_forum($post['fid']);

				{
--$thread_counters[$post['tid']]['replies'];
$forum = get_forum($post['fid']);

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

					// Subtract 1 from user's post count
if($forum['usepostcounts'] != 0 && $post['threadvisible'] == 1)
{

					// Subtract 1 from user's post count
if($forum['usepostcounts'] != 0 && $post['threadvisible'] == 1)
{

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

 
						// Update post count of the user of the merged posts

						// Update post count of the user of the merged posts

						--$user_counters[$post['uid']];

						--$user_counters[$post['uid']]['num_posts'];

					}

					}

				}





					if($post['threadfirstpost'] == $post['pid'] && $forum['usethreadcounts'] != 0 && $post['threadvisible'] == 1)
{
--$user_counters[$post['uid']]['num_threads'];
}
}

				elseif($post['visible'] == 0)
{
// Subtract 1 unapproved post from post's thread

				elseif($post['visible'] == 0)
{
// Subtract 1 unapproved post from post's thread

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

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

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

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


// Delete the extra posts
$db->delete_query("posts", "pid IN({$pidin}) AND pid != '{$masterpid}'");


// Delete the extra posts
$db->delete_query("posts", "pid IN({$pidin}) AND pid != '{$masterpid}'");

Zeile 883Zeile 889
		$db->update_query("attachments", $mergepost2, "pid IN({$pidin})");

// If the first post of a thread is merged out, the first should be updated

		$db->update_query("attachments", $mergepost2, "pid IN({$pidin})");

// If the first post of a thread is merged out, the first should be updated

		$query = $db->simple_select("threads", "tid, fid, visible", "firstpost IN({$pidin}) AND firstpost != '{$masterpid}'");

		$query = $db->simple_select("threads", "tid, uid, fid, visible", "firstpost IN({$pidin}) AND firstpost != '{$masterpid}'");

		while($thread = $db->fetch_array($query))
{
// 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

		while($thread = $db->fetch_array($query))
{
// 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", "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', 'order_dir' => 'asc', '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 907Zeile 913
					--$thread_counters[$thread['tid']]['unapprovedposts'];
}
if($thread['visible'] == 1)

					--$thread_counters[$thread['tid']]['unapprovedposts'];
}
if($thread['visible'] == 1)

				{

				{

					++$thread_counters[$thread['tid']]['replies'];
}
elseif($thread['visible'] == -1)
{
++$thread_counters[$thread['tid']]['deletedposts'];

					++$thread_counters[$thread['tid']]['replies'];
}
elseif($thread['visible'] == -1)
{
++$thread_counters[$thread['tid']]['deletedposts'];

				}

				}

				else

				else

				{

				{

					++$thread_counters[$thread['tid']]['unapprovedposts'];
}

					++$thread_counters[$thread['tid']]['unapprovedposts'];
}

 
			}

if($new_firstpost['uid'] != $thread['uid'] && $forum['usethreadcounts'] != 0 && $thread['visible'] == 1)
{
if(!isset($user_counters[$new_firstpost['uid']]))
{
$user_counters[$new_firstpost['uid']] = array(
'num_posts' => 0,
'num_threads' => 0
);
}
++$user_counters[$new_firstpost['uid']]['num_threads'];

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

$arguments = array("pids" => $pids, "tid" => $tid);

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

$arguments = array("pids" => $pids, "tid" => $tid);

		$plugins->run_hooks("class_moderation_merge_posts", $arguments);

if(!empty($thread_counters))
{

		$plugins->run_hooks("class_moderation_merge_posts", $arguments);

if(!empty($thread_counters))
{

			foreach($thread_counters as $tid => $counters)
{
$counters = array(

			foreach($thread_counters as $tid => $counters)
{
$counters = array(

Zeile 951Zeile 969
				);
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))
{

		if(!empty($user_counters))
{

			foreach($user_counters as $uid => $counter)

			foreach($user_counters as $uid => $counters)

			{

			{

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





				$update_array = array(
"postnum" => "+{$counters['num_posts']}",
"threadnum" => "+{$counters['num_threads']}"
);
update_user_counters($uid, $update_array);

			}
}


			}
}


Zeile 968Zeile 990
	/**
* 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 984Zeile 1006
		$redirect_expire = (int)$redirect_expire;

$thread = get_thread($tid, true);

		$redirect_expire = (int)$redirect_expire;

$thread = get_thread($tid, true);





		$newforum = get_forum($new_fid);
if(!$thread || !$newforum)
{
return false;

		$newforum = get_forum($new_fid);
if(!$thread || !$newforum)
{
return false;

		}

		}

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


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


Zeile 1001Zeile 1023
			$num_posts = $thread['replies']+1;
$num_unapproved_posts = $thread['unapprovedposts'];
$num_deleted_posts = $thread['deletedposts'];

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

		}

		}

		elseif($thread['visible'] == -1)
{
$num_deleted_threads++;
// Implied forum deleted count for deleted threads
$num_deleted_posts = $thread['replies']+$thread['deletedposts']+$thread['unapprovedposts']+1;

		elseif($thread['visible'] == -1)
{
$num_deleted_threads++;
// Implied forum deleted count for deleted threads
$num_deleted_posts = $thread['replies']+$thread['deletedposts']+$thread['unapprovedposts']+1;

		}

		}

		else
{
$num_unapproved_threads++;

		else
{
$num_unapproved_threads++;

Zeile 1031Zeile 1053
				);
$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":


// 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", "(','||forums||',' LIKE '%,$new_fid,%' OR forums='-1') AND pid='".$thread['prefix']."'");
break;
default:

Zeile 1266Zeile 1288

// Do post and thread count changes if changing between countable and non-countable forums
$query = $db->query("


// Do post and thread count changes if changing between countable and non-countable forums
$query = $db->query("

			SELECT COUNT(p.pid) AS posts, u.uid, p.visible

			SELECT COUNT(p.pid) AS posts, u.uid

			FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)

			FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)

			WHERE tid='$tid'
GROUP BY u.uid, p.visible

			WHERE p.tid='$tid' AND p.visible=1
GROUP BY u.uid

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

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

			if($forum['usepostcounts'] == 1 && $newforum['usepostcounts'] == 0 && $posters['visible'] == 1 && $thread['visible'] == 1)

			if($forum['usepostcounts'] == 1 && $method != 'copy' && $newforum['usepostcounts'] == 0 && $thread['visible'] == 1)

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

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

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

			if(($forum['usepostcounts'] == 0 || $method == 'copy') && $newforum['usepostcounts'] == 1 && $thread['visible'] == 1)

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

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

Zeile 1295Zeile 1317
			}
}


			}
}


		if($forum['usethreadcounts'] == 1 && $newforum['usethreadcounts'] == 0 && $thread['visible'] == 1)

		if($forum['usethreadcounts'] == 1 && $method != 'copy' && $newforum['usethreadcounts'] == 0 && $thread['visible'] == 1)

		{
update_user_counters($thread['uid'], array('threadnum' => "-1"));
}

		{
update_user_counters($thread['uid'], array('threadnum' => "-1"));
}

Zeile 1365Zeile 1387
	/**
* 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)
{

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

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


$mergetid = (int)$mergetid;
$tid = (int)$tid;


$mergetid = (int)$mergetid;
$tid = (int)$tid;

Zeile 1385Zeile 1407
		{
$thread = get_thread($tid);
}

		{
$thread = get_thread($tid);
}

		



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

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

		}



		}

$forum_cache = $cache->read('forums');


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


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

		{

		{

			$threadarray['poll'] = $mergethread['poll'];
$sqlarray = array(
"tid" => $tid,

			$threadarray['poll'] = $mergethread['poll'];
$sqlarray = array(
"tid" => $tid,

Zeile 1406Zeile 1430
			$db->delete_query("polls", "pid='{$mergethread['poll']}'");
$db->delete_query("pollvotes", "pid='{$mergethread['poll']}'");
}

			$db->delete_query("polls", "pid='{$mergethread['poll']}'");
$db->delete_query("pollvotes", "pid='{$mergethread['poll']}'");
}





		$subject = $db->escape_string($subject);
$threadarray['subject'] = $subject;

$user_posts = array();

		$subject = $db->escape_string($subject);
$threadarray['subject'] = $subject;

$user_posts = array();

		$query = $db->query("



		if($thread['visible'] != $mergethread['visible'] || $forum_cache[$thread['fid']]['usepostcounts'] != $forum_cache[$mergethread['fid']]['usepostcounts'])
{
$query = $db->query("

				SELECT uid, COUNT(pid) AS postnum
FROM ".TABLE_PREFIX."posts
WHERE tid='{$mergetid}' AND visible=1
GROUP BY uid

				SELECT uid, COUNT(pid) AS postnum
FROM ".TABLE_PREFIX."posts
WHERE tid='{$mergetid}' AND visible=1
GROUP BY uid

		");
while($post = $db->fetch_array($query))
{
$user_posts[$post['uid']]['postnum'] = $post['postnum'];










			");
while($post = $db->fetch_array($query))
{
// Update user counters
if($mergethread['visible'] == 1 && $forum_cache[$mergethread['fid']]['usepostcounts'] == 1)
{
$user_posts[$post['uid']]['postnum'] -= $post['postnum'];
}
elseif($thread['visible'] == 1 && $forum_cache[$thread['fid']]['usepostcounts'] == 1)
{
$user_posts[$post['uid']]['postnum'] += $post['postnum'];
}
}

		}

$sqlarray = array(

		}

$sqlarray = array(

Zeile 1464Zeile 1499
			$update_users = array();
foreach($subscriptions[$mergetid] as $user)
{

			$update_users = array();
foreach($subscriptions[$mergetid] as $user)
{

				if(!in_array($user, $subscriptions[$tid]))

				if(!isset($subscriptions[$tid]) || !in_array($user, $subscriptions[$tid]))

				{
// User doesn't have a $tid subscription
$update_users[] = $user;

				{
// User doesn't have a $tid subscription
$update_users[] = $user;

Zeile 1511Zeile 1546
		if($thread['visible'] != $new_firstpost['visible'])
{
$db->update_query("posts", array('visible' => $thread['visible']), "pid='{$new_firstpost['pid']}'");

		if($thread['visible'] != $new_firstpost['visible'])
{
$db->update_query("posts", array('visible' => $thread['visible']), "pid='{$new_firstpost['pid']}'");

			if($new_firstpost['visible'] == 1)
{

			if($new_firstpost['visible'] == 1 && $forum_cache[$thread['fid']]['usepostcounts'] == 1)
{

				--$user_posts[$post['uid']]['postnum'];

				--$user_posts[$post['uid']]['postnum'];

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

			}
elseif($thread['visible'] == 1 && $forum_cache[$thread['fid']]['usepostcounts'] == 1)
{

				++$user_posts[$post['uid']]['postnum'];

				++$user_posts[$post['uid']]['postnum'];

			}
}

















			}
}
// Update first post if needed
if($new_firstpost['pid'] != $thread['firstpost'])
{
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'];
}


		// Update thread count if thread has a new firstpost and is visible

		// Update thread count if thread has a new firstpost and is visible

		++$user_posts[$mergethread['uid']]['threadnum'];
if($thread['uid'] != $new_firstpost['uid'] && $new_firstpost['visible'] == 1)

		if($thread['uid'] != $new_firstpost['uid'] && $thread['visible'] == 1 && $forum_cache[$thread['fid']]['usethreadcounts'] == 1)


		{

		{

 
			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[$new_firstpost['uid']]['threadnum'];
}


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


Zeile 1533Zeile 1591
		{
// 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 = array(

			{
$updated_stats = array(

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

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

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

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

				);
}
else
{
$updated_stats = array(

				);
}
else
{
$updated_stats = array(

					"posts" => "+{$mergethread['replies']}",
"unapprovedposts" => "+{$mergethread['unapprovedposts']}",
"deletedposts" => "+{$mergethread['deletedposts']}"
);
}
update_forum_counters($thread['fid'], $updated_stats);

					"posts" => "+{$mergethread['replies']}",
"unapprovedposts" => "+{$mergethread['unapprovedposts']}",
"deletedposts" => "+{$mergethread['deletedposts']}"
);
}
update_forum_counters($thread['fid'], $updated_stats);

			update_forum_lastpost($thread['fid']);

 

// 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 1648Zeile 1705
			{
update_forum_counters($mergethread['fid'], $new_stats);
update_forum_lastpost($mergethread['fid']);

			{
update_forum_counters($mergethread['fid'], $new_stats);
update_forum_lastpost($mergethread['fid']);

			}
}
// If we're in the same forum we need to at least update the last post information
else
{
update_forum_lastpost($thread['fid']);

			}






		}

if($thread['visible'] != $new_firstpost['visible'])

		}

if($thread['visible'] != $new_firstpost['visible'])

		{

		{

			// Correct counters
if($new_firstpost['visible'] == 1)
{

			// Correct counters
if($new_firstpost['visible'] == 1)
{

Zeile 1666Zeile 1718
			elseif($new_firstpost['visible'] == -1)
{
--$mergethread['deletedposts'];

			elseif($new_firstpost['visible'] == -1)
{
--$mergethread['deletedposts'];

			}

			}

			else
{
--$mergethread['unapprovedposts'];

			else
{
--$mergethread['unapprovedposts'];

			}

			}

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

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

			}

			}

			elseif($thread['visible'] == -1)
{
++$mergethread['deletedposts'];

			elseif($thread['visible'] == -1)
{
++$mergethread['deletedposts'];

Zeile 1685Zeile 1737
			}
}


			}
}


		if($thread['visible'] != $mergethread['visible'])
{
// Update user counters
if($thread['visible'] == 1)
{
foreach($user_posts as $uid => $user_counter)
{
update_user_counters($uid, array('postnum' => "+{$user_counter['postnum']}"));
}
}
elseif($mergethread['visible'] == 1)
{
foreach($user_posts as $uid => $user_counter)
{
update_user_counters($uid, array('postnum' => "-{$user_counter['postnum']}"));
}
}
}

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

		// Update user counters
foreach($user_posts as $uid => $counters)



















		{

		{

			foreach($user_posts as $uid => $user_counter)
{
update_user_counters($uid, array('threadnum' => "-{$user_counter['threadnum']}"));
}


			$update_array = array(
"postnum" => "+{$counters['postnum']}",
"threadnum" => "+{$counters['threadnum']}",
);
update_user_counters($uid, $update_array);

		}

$updated_stats = array(

		}

$updated_stats = array(

Zeile 1721Zeile 1756
		);
update_thread_counters($tid, $updated_stats);
update_last_post($tid);

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

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

		return true;
}

/**
* 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 1746Zeile 1784

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


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





		$pids_list = implode(',', $pids);

// Get forum infos

		$pids_list = implode(',', $pids);

// Get forum infos

Zeile 1758Zeile 1796
		}

// Get the first split post

		}

// Get the first split post

		$post_info = get_post($pids[0]);




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

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


		$visible = $post_info['visible'];

$forum_counters[$moveto] = array(

		$visible = $post_info['visible'];

$forum_counters[$moveto] = array(

Zeile 1782Zeile 1823
				"uid" => (int)$post_info['uid'],
"username" => $db->escape_string($post_info['username']),
"dateline" => (int)$post_info['dateline'],

				"uid" => (int)$post_info['uid'],
"username" => $db->escape_string($post_info['username']),
"dateline" => (int)$post_info['dateline'],

 
				"firstpost" => $post_info['pid'],

				"lastpost" => 0,
"lastposter" => '',
"visible" => (int)$visible,

				"lastpost" => 0,
"lastposter" => '',
"visible" => (int)$visible,

Zeile 1792Zeile 1834
			if($visible == 1)
{
++$forum_counters[$moveto]['threads'];

			if($visible == 1)
{
++$forum_counters[$moveto]['threads'];

 
				if(!isset($user_counters[$newthread['uid']]))
{
$user_counters[$newthread['uid']] = array(
'postnum' => 0,
'threadnum' => 0
);
}
// Subtract thread from old thread opener
--$user_counters[$newthread['uid']]['threadnum'];

			}
elseif($visible == -1)
{
++$forum_counters[$moveto]['deletedthreads'];

			}
elseif($visible == -1)
{
++$forum_counters[$moveto]['deletedthreads'];

			}

			}

			else
{
// Unapproved thread?

			else
{
// Unapproved thread?

Zeile 1815Zeile 1866

// Get selected posts before moving forums to keep old fid
$original_posts_query = $db->query("


// Get selected posts before moving forums to keep old fid
$original_posts_query = $db->query("

			SELECT p.pid, p.tid, p.fid, p.visible, p.uid, t.visible as threadvisible, t.firstpost, COUNT(a.aid) as postattachmentcount

			SELECT p.pid, p.tid, p.fid, p.visible, p.uid, p.dateline, t.visible as threadvisible, t.firstpost, COUNT(a.aid) as postattachmentcount

			FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."threads t ON (p.tid=t.tid)
LEFT JOIN ".TABLE_PREFIX."attachments a ON (a.pid=p.pid AND a.visible=1)

			FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."threads t ON (p.tid=t.tid)
LEFT JOIN ".TABLE_PREFIX."attachments a ON (a.pid=p.pid AND a.visible=1)

Zeile 1826Zeile 1877
		// Move the selected posts over
$sqlarray = array(
"tid" => $newtid,

		// Move the selected posts over
$sqlarray = array(
"tid" => $newtid,

			"fid" => $moveto,

			"fid" => $moveto,

			"replyto" => 0
);
$db->update_query("posts", $sqlarray, "pid IN ($pids_list)");

			"replyto" => 0
);
$db->update_query("posts", $sqlarray, "pid IN ($pids_list)");

Zeile 1851Zeile 1902
				);
}
if(!isset($forum_counters[$post['fid']]))

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

			{

			{

				$forum_counters[$post['fid']] = array(
'posts' => 0,
'unapprovedposts' => 0,
'deletedposts' => 0

				$forum_counters[$post['fid']] = array(
'posts' => 0,
'unapprovedposts' => 0,
'deletedposts' => 0

 
				);
}
if(!isset($user_counters[$post['uid']]))
{
$user_counters[$post['uid']] = array(
'postnum' => 0,
'threadnum' => 0

				);
}
if($post['visible'] == 1)
{

				);
}
if($post['visible'] == 1)
{

				if(!isset($user_counters[$post['uid']]))
{
$user_counters[$post['uid']] = array(
'postnum' => 0,
'threadnum' => 0
);
}

 
				// Modify users' post counts
if($post['threadvisible'] == 1 && $forum_cache[$post['fid']]['usepostcounts'] == 1 && ($forum_cache[$moveto]['usepostcounts'] == 0 || $newthread['visible'] != 1))

				// Modify users' post counts
if($post['threadvisible'] == 1 && $forum_cache[$post['fid']]['usepostcounts'] == 1 && ($forum_cache[$moveto]['usepostcounts'] == 0 || $newthread['visible'] != 1))

				{

				{

					// Moving into a forum that doesn't count post counts

					// Moving into a forum that doesn't count post counts

					--$user_counters[$post['uid']]['postnum'];
}
elseif($newthread['visible'] == 1 && ($forum_cache[$post['fid']]['usepostcounts'] == 0 || $post['threadvisible'] != 1) && $forum_cache[$moveto]['usepostcounts'] == 1)
{
// Moving into a forum that does count post counts
++$user_counters[$post['uid']]['postnum'];
}

// Modify users' thread counts
if($post_info['uid'] == $post['uid'] && $forum_cache[$moveto]['usethreadcounts'] == 1 && $newthread['visible'] == 1)
{
// Moving into a forum that does count thread counts
++$user_counters[$post['uid']]['threadnum'];
}

					--$user_counters[$post['uid']]['postnum'];
}














// Subtract 1 from the old thread's replies
--$thread_counters[$post['tid']]['replies'];


// Subtract 1 from the old thread's replies
--$thread_counters[$post['tid']]['replies'];


// Add 1 to the new thread's replies
++$thread_counters[$newtid]['replies'];


 
			}
elseif($post['visible'] == 0)
{
// Unapproved post
// Subtract 1 from the old thread's unapproved posts
--$thread_counters[$post['tid']]['unapprovedposts'];

			}
elseif($post['visible'] == 0)
{
// Unapproved post
// Subtract 1 from the old thread's unapproved posts
--$thread_counters[$post['tid']]['unapprovedposts'];


// Add 1 to the new thread's unapproved posts
++$thread_counters[$newtid]['unapprovedposts'];

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

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

			{

			{

				// Soft deleted post
// Subtract 1 from the old thread's deleted posts
--$thread_counters[$post['tid']]['deletedposts'];

				// Soft deleted post
// Subtract 1 from the old thread's deleted posts
--$thread_counters[$post['tid']]['deletedposts'];

 
			}





				// Add 1 to the new thread's deleted posts
++$thread_counters[$newtid]['deletedposts'];
}


 
			// Subtract 1 from the old forum's posts
if($post['threadvisible'] == 1 && $post['visible'] == 1)
{
--$forum_counters[$post['fid']]['posts'];

			// Subtract 1 from the old forum's posts
if($post['threadvisible'] == 1 && $post['visible'] == 1)
{
--$forum_counters[$post['fid']]['posts'];

			}

			}

			elseif($post['threadvisible'] == 0 || ($post['visible'] == 0 && $post['threadvisible'] == 1))

			elseif($post['threadvisible'] == 0 || ($post['visible'] == 0 && $post['threadvisible'] == 1))

			{

			{

				--$forum_counters[$post['fid']]['unapprovedposts'];
}

				--$forum_counters[$post['fid']]['unapprovedposts'];
}

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

// Add 1 to the new forum's posts
if($newthread['visible'] == 1 && $post['visible'] == 1)
{
++$forum_counters[$moveto]['posts'];
}
elseif($newthread['visible'] == 0 || ($post['visible'] == 0 && $newthread['visible'] == 1))
{
++$forum_counters[$moveto]['unapprovedposts'];
}
else
{
++$forum_counters[$moveto]['deletedposts'];
}


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
















			// Subtract attachment counts from old thread and add to new thread (which are counted regardless of post or attachment unapproval at time of coding)
$thread_counters[$post['tid']]['attachmentcount'] -= $post['postattachmentcount'];
$thread_counters[$newtid]['attachmentcount'] += $post['postattachmentcount'];

if($post['firstpost'] == $post['pid'])

			// Subtract attachment counts from old thread and add to new thread (which are counted regardless of post or attachment unapproval at time of coding)
$thread_counters[$post['tid']]['attachmentcount'] -= $post['postattachmentcount'];
$thread_counters[$newtid]['attachmentcount'] += $post['postattachmentcount'];

if($post['firstpost'] == $post['pid'])

			{

			{

				// 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", "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', 'order_dir' => 'asc', 'limit' => 1));

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

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

 

if(!isset($user_counters[$new_firstpost['uid']]))
{
$user_counters[$new_firstpost['uid']] = array(
'postnum' => 0,
'threadnum' => 0
);
}

// Update post counters if visibility changes

				if($post['threadvisible'] != $new_firstpost['visible'])
{
$db->update_query("posts", array('visible' => $post['threadvisible']), "pid='{$new_firstpost['pid']}'");

				if($post['threadvisible'] != $new_firstpost['visible'])
{
$db->update_query("posts", array('visible' => $post['threadvisible']), "pid='{$new_firstpost['pid']}'");

					// Correct counters

					// Subtract new first post

					if($new_firstpost['visible'] == 1)
{
--$thread_counters[$post['tid']]['replies'];

					if($new_firstpost['visible'] == 1)
{
--$thread_counters[$post['tid']]['replies'];

 
						if($post['threadvisible'] == 1 && $forum_cache[$post['fid']]['usepostcounts'] == 1)
{
--$user_counters[$new_firstpost['uid']]['postnum'];
}

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

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

Zeile 1966Zeile 1995
					{
--$thread_counters[$post['tid']]['unapprovedposts'];
}

					{
--$thread_counters[$post['tid']]['unapprovedposts'];
}

 
					if($post['threadvisible'] == 0 || ($new_firstpost['visible'] == 0 && $post['threadvisible'] == 1))
{
--$forum_counters[$post['fid']]['unapprovedposts'];
}
else
{
--$forum_counters[$post['fid']]['deletedposts'];
}

// Add old first post

					if($post['threadvisible'] == 1)
{
++$thread_counters[$post['tid']]['replies'];

					if($post['threadvisible'] == 1)
{
++$thread_counters[$post['tid']]['replies'];

 
						++$forum_counters[$post['fid']]['posts'];
if($forum_cache[$post['fid']]['usepostcounts'] == 1)
{
++$user_counters[$new_firstpost['uid']]['postnum'];
}

					}
elseif($post['threadvisible'] == -1)
{
++$thread_counters[$post['tid']]['deletedposts'];

					}
elseif($post['threadvisible'] == -1)
{
++$thread_counters[$post['tid']]['deletedposts'];

 
						++$forum_counters[$post['fid']]['deletedposts'];

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

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

 
						++$forum_counters[$post['fid']]['unapprovedposts'];

					}

					}

 
				}

// Update user thread counter if thread opener changes
if($post['threadvisible'] == 1 && $forum_cache[$post['fid']]['usethreadcounts'] == 1 && $post['uid'] != $new_firstpost['uid'])
{
// Subtract thread from old thread opener
--$user_counters[$post['uid']]['threadnum'];
// Add thread to new thread opener
++$user_counters[$new_firstpost['uid']]['threadnum'];

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

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

 
			}

// This is the new first post of an existing thread?
if($post['pid'] == $post_info['pid'] && $post['dateline'] < $newthread['dateline'])
{
// Update post counters if visibility changes
if($post['visible'] != $newthread['visible'])
{
$db->update_query("posts", array('visible' => $newthread['visible']), "pid='{$post['pid']}'");

// This is needed to update the forum counters correctly
$post['visible'] = $newthread['visible'];
}

// Update user thread counter if thread opener changes
if($newthread['visible'] == 1 && $forum_cache[$newthread['fid']]['usethreadcounts'] == 1 && $post['uid'] != $newthread['uid'])
{
// Add thread to new thread opener
++$user_counters[$post['uid']]['threadnum'];
if(!isset($user_counters[$newthread['uid']]))
{
$user_counters[$newthread['uid']] = array(
'postnum' => 0,
'threadnum' => 0
);
}
// Subtract thread from old thread opener
--$user_counters[$newthread['uid']]['threadnum'];
}
update_first_post($newtid);
}

if($post['visible'] == 1)
{
// Modify users' post counts
if($newthread['visible'] == 1 && ($forum_cache[$post['fid']]['usepostcounts'] == 0 || $post['threadvisible'] != 1) && $forum_cache[$moveto]['usepostcounts'] == 1)
{
// Moving into a forum that does count post counts
++$user_counters[$post['uid']]['postnum'];
}

// Add 1 to the new thread's replies
++$thread_counters[$newtid]['replies'];
}
elseif($post['visible'] == 0)
{
// Unapproved post
// Add 1 to the new thread's unapproved posts
++$thread_counters[$newtid]['unapprovedposts'];
}
elseif($post['visible'] == -1)
{
// Soft deleted post
// Add 1 to the new thread's deleted posts
++$thread_counters[$newtid]['deletedposts'];
}

// Add 1 to the new forum's posts
if($newthread['visible'] == 1 && $post['visible'] == 1)
{
++$forum_counters[$moveto]['posts'];
}
elseif($newthread['visible'] == 0 || ($post['visible'] == 0 && $newthread['visible'] == 1))
{
++$forum_counters[$moveto]['unapprovedposts'];
}
else
{
++$forum_counters[$moveto]['deletedposts'];

			}
}

			}
}

 


		if($destination_tid == 0 && $newthread['visible'] == 1)
{
// If splitting into a new thread, subtract one from the thread's reply count to compensate for the original post

		if($destination_tid == 0 && $newthread['visible'] == 1)
{
// If splitting into a new thread, subtract one from the thread's reply count to compensate for the original post

Zeile 1991Zeile 2116
		{
// If splitting into a new thread, subtract one from the thread's reply count to compensate for the original post
--$thread_counters[$newtid]['unapprovedposts'];

		{
// If splitting into a new thread, subtract one from the thread's reply count to compensate for the original post
--$thread_counters[$newtid]['unapprovedposts'];

		}

		}

		elseif($destination_tid == 0 && $newthread['visible'] == -1)
{
// If splitting into a new thread, subtract one from the thread's reply count to compensate for the original post

		elseif($destination_tid == 0 && $newthread['visible'] == -1)
{
// If splitting into a new thread, subtract one from the thread's reply count to compensate for the original post

Zeile 2087Zeile 2212
	/**
* Move multiple threads to new forum
*

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

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

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

Zeile 2103Zeile 2228
		$moveto = (int)$moveto;

$newforum = get_forum($moveto);

		$moveto = (int)$moveto;

$newforum = get_forum($moveto);

		



		if(empty($tids) || !$newforum)
{
return false;
}

		if(empty($tids) || !$newforum)
{
return false;
}





		$total_posts = $total_unapproved_posts = $total_deleted_posts = $total_threads = $total_unapproved_threads = $total_deleted_threads = 0;
$forum_counters = $user_counters = array();
$query = $db->simple_select("threads", "fid, visible, replies, unapprovedposts, deletedposts, tid, uid", "tid IN ($tid_list)");

		$total_posts = $total_unapproved_posts = $total_deleted_posts = $total_threads = $total_unapproved_threads = $total_deleted_threads = 0;
$forum_counters = $user_counters = array();
$query = $db->simple_select("threads", "fid, visible, replies, unapprovedposts, deletedposts, tid, uid", "tid IN ($tid_list)");

Zeile 2126Zeile 2251
					'deletedthreads' => 0,
'deletedposts' => 0
);

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

			}


			}


			if(!isset($user_counters[$thread['uid']]['num_threads']))
{
$user_counters[$thread['uid']]['num_threads'] = 0;
}

			if(!isset($user_counters[$thread['uid']]['num_threads']))
{
$user_counters[$thread['uid']]['num_threads'] = 0;
}





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

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

Zeile 2150Zeile 2275
					++$user_counters[$thread['uid']]['num_threads'];
}
else if($newforum['usethreadcounts'] == 0 && $forum['usethreadcounts'] == 1)

					++$user_counters[$thread['uid']]['num_threads'];
}
else if($newforum['usethreadcounts'] == 0 && $forum['usethreadcounts'] == 1)

				{

				{

					--$user_counters[$thread['uid']]['num_threads'];
}

$query1 = $db->query("

					--$user_counters[$thread['uid']]['num_threads'];
}

$query1 = $db->query("

					SELECT COUNT(p.pid) AS posts, p.visible, u.uid

					SELECT COUNT(p.pid) AS posts, u.uid

					FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)

					FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)

					WHERE p.tid = '{$thread['tid']}'
GROUP BY p.visible, u.uid

					WHERE p.tid = '{$thread['tid']}' AND p.visible=1
GROUP BY u.uid

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

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

Zeile 2169Zeile 2294
						$user_counters[$posters['uid']]['num_posts'] = 0;
}


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


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

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

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

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

					else if($newforum['usepostcounts'] == 0 && $forum['usepostcounts'] != 0 && $posters['visible'] == 1)

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

					{
$user_counters[$posters['uid']]['num_posts'] -= $posters['posts'];
}

					{
$user_counters[$posters['uid']]['num_posts'] -= $posters['posts'];
}

Zeile 2236Zeile 2361

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


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

		



		if(!empty($user_counters))

		if(!empty($user_counters))

		{

		{

			foreach($user_counters as $uid => $counters)
{
$update_array = array(

			foreach($user_counters as $uid => $counters)
{
$update_array = array(

Zeile 2260Zeile 2385
					'unapprovedthreads' => "-{$counter['unapprovedthreads']}",
'deletedposts' => "-{$counter['deletedposts']}",
'deletedthreads' => "-{$counter['deletedthreads']}"

					'unapprovedthreads' => "-{$counter['unapprovedthreads']}",
'deletedposts' => "-{$counter['deletedposts']}",
'deletedthreads' => "-{$counter['deletedthreads']}"

					



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

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

Zeile 2288Zeile 2413
	/**
* Approve multiple posts
*

	/**
* Approve multiple posts
*

	 * @param array PIDs
* @return boolean true

	 * @param array $pids PIDs
* @return boolean

	 */
function approve_posts($pids)
{

	 */
function approve_posts($pids)
{

Zeile 2300Zeile 2425
		if(empty($pids))
{
return false;

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

		}


		}


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


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


Zeile 2340Zeile 2465

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


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

			FROM ".TABLE_PREFIX."posts p

			FROM ".TABLE_PREFIX."posts p

			LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
WHERE p.pid IN ($pid_list) AND p.visible = '0' AND t.firstpost != p.pid
");

			LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
WHERE p.pid IN ($pid_list) AND p.visible = '0' AND t.firstpost != p.pid
");

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

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

			++$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($post['threadvisible'] != 0)

			if($post['threadvisible'] == 1)

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

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

Zeile 2368Zeile 2493
					);
}
++$forum_counters[$post['fid']]['num_posts'];

					);
}
++$forum_counters[$post['fid']]['num_posts'];

			}


			}


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

// If post counts enabled in this forum and the thread is approved, add 1

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

// If post counts enabled in this forum and the thread is approved, add 1

Zeile 2380Zeile 2505
					$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))
{
$where = "pid IN (".implode(',', $pids).")";

			}
}

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

if(!empty($pids))
{
$where = "pid IN (".implode(',', $pids).")";

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

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





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

if(!empty($thread_counters))

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

if(!empty($thread_counters))

		{

		{

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

			foreach($thread_counters as $tid => $counters)
{
$counters_update = array(
"unapprovedposts" => "-".$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 2436Zeile 2561
	/**
* Unapprove multiple posts
*

	/**
* Unapprove multiple posts
*

	 * @param array PIDs
* @return boolean true

	 * @param array $pids PIDs
* @return boolean

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

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





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

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

		}


		}


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

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

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

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





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

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

Zeile 2471Zeile 2596
			FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
WHERE p.pid IN ($pid_list) AND p.visible IN (-1,1) AND t.firstpost = p.pid AND t.visible IN (-1,1)

			FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
WHERE p.pid IN ($pid_list) AND p.visible IN (-1,1) AND t.firstpost = p.pid AND t.visible IN (-1,1)

		");

		");

		while($post = $db->fetch_array($query))
{
// This is the first post in the thread so we're unapproving the whole thread.
$threads_to_update[] = $post['tid'];

		while($post = $db->fetch_array($query))
{
// This is the first post in the thread so we're unapproving the whole thread.
$threads_to_update[] = $post['tid'];

		}


		}


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

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

Zeile 2490Zeile 2615
			FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
WHERE p.pid IN ($pid_list) AND p.visible IN (-1,1) AND t.firstpost != p.pid

			FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
WHERE p.pid IN ($pid_list) AND p.visible IN (-1,1) AND t.firstpost != p.pid

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

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

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

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

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

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

Zeile 2542Zeile 2667

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


// If post counts enabled in this forum and the thread is approved, subtract 1
if($forum['usepostcounts'] != 0 && $post['visible'] == 1 && $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;

Zeile 2565Zeile 2690
		$plugins->run_hooks("class_moderation_unapprove_posts", $pids);

if(!empty($thread_counters))

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

if(!empty($thread_counters))

		{

		{

			foreach($thread_counters as $tid => $counters)
{
$counters_update = array(

			foreach($thread_counters as $tid => $counters)
{
$counters_update = array(

Zeile 2576Zeile 2701

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


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

			}
}

			}
}


if(!empty($forum_counters))
{


if(!empty($forum_counters))
{

Zeile 2590Zeile 2715
				);
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 2607Zeile 2732
	/**
* 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)
{

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

Zeile 2654Zeile 2779
	/**
* 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 2667Zeile 2792
		if(empty($tid))
{
return false;

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

		}

		}


$update_thread = array(
"deletetime" => (int)$deletetime


$update_thread = array(
"deletetime" => (int)$deletetime

Zeile 2683Zeile 2808
	/**
* 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)
{
global $db;

	 * @return boolean true
*/
function toggle_post_visibility($pids)
{
global $db;





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


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


Zeile 2700Zeile 2825
			if($post['visible'] != 0)
{
$unapprove[] = $post['pid'];

			if($post['visible'] != 0)
{
$unapprove[] = $post['pid'];

			}
else
{
$approve[] = $post['pid'];
}
}
if(is_array($unapprove))
{
$this->unapprove_posts($unapprove);
}
if(is_array($approve))
{
$this->approve_posts($approve);

			}
else
{
$approve[] = $post['pid'];
}
}
if(is_array($unapprove))
{
$this->unapprove_posts($unapprove);





		}

		}

		return true;
}






		if(is_array($approve))
{
$this->approve_posts($approve);
}
return true;
}


	/**
* 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)
{
global $db;

	 * @return boolean true
*/
function toggle_post_softdelete($pids)
{
global $db;





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


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


Zeile 2750Zeile 2875
		if(is_array($restore))
{
$this->restore_posts($restore);

		if(is_array($restore))
{
$this->restore_posts($restore);

		}
return true;
}


		}
return true;
}


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

	{
global $db;

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


	{
global $db;

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


		$tid_list = implode(',', $tids);
$query = $db->simple_select("threads", 'tid, visible', "tid IN ($tid_list)");
while($thread = $db->fetch_array($query))

		$tid_list = implode(',', $tids);
$query = $db->simple_select("threads", 'tid, visible', "tid IN ($tid_list)");
while($thread = $db->fetch_array($query))

Zeile 2781Zeile 2906
			{
$approve[] = $thread['tid'];
}

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

		}

		}

		if(is_array($unapprove))
{
$this->unapprove_threads($unapprove, $fid);

		if(is_array($unapprove))
{
$this->unapprove_threads($unapprove, $fid);

Zeile 2796Zeile 2921
	/**
* Toggle thread visibility (deleted/restored)
*

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

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

	 * @param array $tids Thread IDs


	 * @return boolean true
*/

	 * @return boolean true
*/

	function toggle_thread_softdelete($tids, $fid)

	function toggle_thread_softdelete($tids)

	{
global $db;

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

	{
global $db;

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

		$fid = (int)$fid;

 

$tid_list = implode(',', $tids);
$query = $db->simple_select("threads", 'tid, visible', "tid IN ($tid_list)");


$tid_list = implode(',', $tids);
$query = $db->simple_select("threads", 'tid, visible', "tid IN ($tid_list)");

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

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

			if($thread['visible'] != -1)
{
$delete[] = $thread['tid'];

			if($thread['visible'] != -1)
{
$delete[] = $thread['tid'];

Zeile 2823Zeile 2946
		}
if(is_array($delete))
{

		}
if(is_array($delete))
{

			$this->soft_delete_threads($delete, $fid);
}
if(is_array($restore))
{
$this->restore_threads($restore, $fid);

			$this->soft_delete_threads($delete);





		}

		}

		return true;
}






		if(is_array($restore))
{
$this->restore_threads($restore);
}
return true;
}


	/**
* 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 2865Zeile 2988
		if(is_array($close))
{
$this->close_threads($close);

		if(is_array($close))
{
$this->close_threads($close);

		}
return true;
}

		}
return true;
}


/**
* 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)
{
global $db;

	 * @return boolean true
*/
function toggle_thread_importance($tids)
{
global $db;





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


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


Zeile 2897Zeile 3020
			{
$unstick[] = $thread['tid'];
}

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

		}

		}

		if(!empty($stick))
{
$this->stick_threads($stick);

		if(!empty($stick))
{
$this->stick_threads($stick);

Zeile 2912Zeile 3035
	/**
* 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)

	{
global $db, $plugins;

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

	{
global $db, $plugins;

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

		{
$tids = array($tids);
}

		{
$tids = array($tids);
}

Zeile 2945Zeile 3068
			$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 2990Zeile 3114
	/**
* 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)
{

	 */
function apply_thread_prefix($tids, $prefix = 0)
{

Zeile 3025Zeile 3150
	/**
* 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 3136Zeile 3261
					$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))
{
$where = "pid IN (".implode(',', $pids).")";
$db->update_query("posts", $update, $where);
}

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

if(is_array($thread_counters))
{
foreach($thread_counters as $tid => $counters)
{


			}
}

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

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

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

if(is_array($thread_counters))
{
foreach($thread_counters as $tid => $counters)
{

				$counters_update = array(
"unapprovedposts" => "-".$counters['unapprovedposts'],
"replies" => "-".$counters['replies'],

				$counters_update = array(
"unapprovedposts" => "-".$counters['unapprovedposts'],
"replies" => "-".$counters['replies'],

Zeile 3195Zeile 3321
	/**
* 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 3205Zeile 3331
		$num_posts = 0;

if(empty($pids))

		$num_posts = 0;

if(empty($pids))

		{
return false;
}

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

		{
return false;
}

// 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 3231Zeile 3357
			FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
WHERE p.pid IN ($pid_list) AND p.visible = '-1' AND t.firstpost = p.pid AND t.visible = -1

			FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
WHERE p.pid IN ($pid_list) AND p.visible = '-1' AND t.firstpost = p.pid AND t.visible = -1

		");

		");

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

		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->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 3260Zeile 3386
			{
$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 3343Zeile 3469
	/**
* 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)

Zeile 3413Zeile 3539
				}
}


				}
}


			if($forum['usethreadcounts'] != 0)

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

			{
++$user_counters[$thread['uid']]['num_threads'];
}

			{
++$user_counters[$thread['uid']]['num_threads'];
}

Zeile 3479Zeile 3605
						"threadnum" => "+{$counters['num_threads']}",
);
update_user_counters($uid, $update_array);

						"threadnum" => "+{$counters['num_threads']}",
);
update_user_counters($uid, $update_array);

				}
}
}

				}
}
}

		return true;
}

/**
* Soft delete one or more threads
*

		return true;
}

/**
* 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)
{
global $db, $cache, $plugins;

if(!is_array($tids))

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

if(!is_array($tids))

		{

		{

			$tids = array($tids);
}

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

			$tids = array($tids);
}

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

		}

		}


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


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

Zeile 3516Zeile 3642
			$tid_moved_list .= "{$comma}'moved|{$tid}'";
$comma = ",";
}

			$tid_moved_list .= "{$comma}'moved|{$tid}'";
$comma = ",";
}





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

foreach($tids as $tid)

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

foreach($tids as $tid)

Zeile 3535Zeile 3661
						'num_deleted_posts' => 0,
'unapproved_threads' => 0,
'unapproved_posts' => 0

						'num_deleted_posts' => 0,
'unapproved_threads' => 0,
'unapproved_posts' => 0

					);
}

					);
}


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


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

Zeile 3550Zeile 3676
				$forum_counters[$forum['fid']]['num_deleted_posts'] += $thread['replies']+$thread['unapprovedposts']+1;

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

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

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

				{

				{

					++$forum_counters[$forum['fid']]['num_threads'];
$forum_counters[$forum['fid']]['num_posts'] += $thread['replies']+1; // Add implied invisible to count
$forum_counters[$forum['fid']]['unapproved_posts'] += $thread['unapprovedposts'];
}
else

					++$forum_counters[$forum['fid']]['num_threads'];
$forum_counters[$forum['fid']]['num_posts'] += $thread['replies']+1; // Add implied invisible to count
$forum_counters[$forum['fid']]['unapproved_posts'] += $thread['unapprovedposts'];
}
else

				{

				{

					++$forum_counters[$forum['fid']]['unapproved_threads'];
$forum_counters[$forum['fid']]['unapproved_posts'] += $thread['replies']+$thread['deletedposts']+$thread['unapprovedposts']+1; // Add implied invisible to count
$forum_counters[$forum['fid']]['num_deleted_posts'] += $thread['deletedposts'];

					++$forum_counters[$forum['fid']]['unapproved_threads'];
$forum_counters[$forum['fid']]['unapproved_posts'] += $thread['replies']+$thread['deletedposts']+$thread['unapprovedposts']+1; // Add implied invisible to count
$forum_counters[$forum['fid']]['num_deleted_posts'] += $thread['deletedposts'];

Zeile 3576Zeile 3702
					}
}


					}
}


				if($thread['visible'] == 1 && $forum['usethreadcounts'] != 0)

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

				{
++$user_counters[$thread['uid']]['num_threads'];
}

				{
++$user_counters[$thread['uid']]['num_threads'];
}

Zeile 3591Zeile 3717
		// 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;