".getgroupname($mod_group)."" : getgroupname($mod_group);
}
}
}
return (string)$moderators;
}
/**
* Set a post id
*
* @param $value
*/
public function setPostId($value) {
$this->post_id = $value;
}
/**
* Set a thread id
*
* @param $value
*/
public function setThreadId($value) {
$this->thread_id = $value;
}
/**
* Set a forum id
*
* @param $value
*/
public function setForumID($value) {
$this->forum_id = $value;
}
public function set_modActions() {
$this->locale = fusion_get_locale('', FORUM_LOCALE);
$this->form_action = FORUM.'viewthread.php?thread_id='.$this->thread_id.(isset($_GET['rowstart']) && isnum($_GET['rowstart']) ? "&rowstart=".$_GET['rowstart'] : '');
if (!isset($_GET['rowstart'])) {
$_GET['rowstart'] = 0;
}
if (isset($_POST['step']) && $_POST['step'] != "") {
$_GET['step'] = $_POST['step'];
}
$_GET['step'] = isset($_GET['step']) && in_array($_GET['step'], $this->allowed_actions) ? $_GET['step'] : '';
$_GET['error'] = isset($_GET['error']) ? $_GET['error'] : '';
if ($this->thread_id && !$this->forum_id) {
$forum_id_data = dbarray(dbquery("SELECT forum_id FROM ".DB_FORUM_THREADS." WHERE thread_id='".$this->thread_id."'"));
$this->forum_id = $forum_id_data['forum_id'];
}
// get forum parents
$branch_data = dbarray(dbquery("SELECT forum_cat, forum_branch FROM ".DB_FORUMS." WHERE forum_id='".$this->forum_id."'"));
$this->parent_id = $branch_data['forum_cat'];
$this->branch_id = $branch_data['forum_branch'];
// at any time when cancel is clicked, redirect to forum id.
if (isset($_POST['cancelDelete'])) {
redirect(FORUM."viewthread.php?thread_id=".intval($this->thread_id));
}
/**
* Thread actions
*/
switch ($_GET['step']) {
case 'renew':
self::mod_renew_thread();
break;
case 'delete':
self::mod_delete_thread();
break;
case 'lock':
self::mod_lock_thread();
break;
case 'unlock':
self::mod_unlock_thread();
break;
case 'sticky':
self::mod_sticky_thread();
break;
case 'nonsticky':
self::mod_nonsticky_thread();
break;
case 'move':
self::mod_move_thread();
break;
}
$message = '';
switch ($_GET['error']) {
case '1':
$message = $this->locale['error-MP001'];
break;
case '2':
$message = $this->locale['error-MP002'];
break;
case '3':
$message = $this->locale['forum_0307'];
break;
}
if ($message != "") {
opentable($this->locale['error-MP000']);
echo "
\n";
if (!isset($_POST['deletethread'])) {
echo openform('delform', 'post', $this->form_action."&step=delete");
echo $this->locale['forum_0704']."
\n";
echo form_button('deletethread', $this->locale['yes'], $this->locale['yes'], ['class' => 'm-r-10 btn-danger']);
echo form_button('cancelDelete', $this->locale['no'], $this->locale['no'], ['class' => 'm-r-10 btn-default']);
echo "\n";
echo closeform();
} else {
// reset every user post count as if they never posted before
self::unset_userpost();
// then we remove thread. outputs information what have been deleted
$response = self::remove_thread();
// refresh forum information as if thread never existed
self::refresh_forum(TRUE);
if ($response == TRUE) {
echo $this->locale['forum_0701']."
\n";
echo "
".$this->locale['forum_0549']."\n";
echo "
".$this->locale['forum_0550']."\n";
} else {
echo $this->locale['forum_0705'];
}
}
echo "
\n";
echo closemodal();
add_to_footer(ob_get_clean());
}
}
/**
* Unset User Post based on Thread id
* This function assumes as if user have never posted before
*
* @return int - number of posts that user have made in this thread
*/
private function unset_userpost() {
$post_count = 0;
if (self::verify_thread($this->thread_id)) {
$result = dbquery("SELECT post_author, COUNT(post_id) as num_posts FROM ".DB_FORUM_POSTS." WHERE thread_id='".$this->thread_id."' GROUP BY post_author");
$rows = dbrows($result);
if ($rows > 0) {
while ($pdata = dbarray($result)) {
dbquery("UPDATE ".DB_USERS." SET user_posts=user_posts-".$pdata['num_posts']." WHERE user_id='".$pdata['post_author']."'");
$post_count = $pdata['num_posts'] + $post_count;
}
}
}
return (int)$post_count;
}
/**
* SQL action remove thread
* - post deleted
* - attachment deleted
* - user thread tracking deleted.
*/
private function remove_thread() {
$response = FALSE;
if (self::verify_thread($this->thread_id) && self::verify_forum($this->forum_id)) {
$param = [':thread_id' => intval($this->thread_id)];
// Delete all thread posts
dbquery("DELETE FROM ".DB_FORUM_POSTS." WHERE thread_id=:thread_id", $param);
// Delete all thread notifications
dbquery("DELETE FROM ".DB_FORUM_THREAD_NOTIFY." WHERE thread_id=:thread_id", $param);
// Delete all attachment files
$result = dbquery("SELECT attach_name FROM ".DB_FORUM_ATTACHMENTS." WHERE thread_id=:thread_id", $param);
if (dbrows($result)) {
while ($attach = dbarray($result)) {
if (file_exists(INFUSIONS."forum/attachments/".$attach['attach_name'])) {
@unlink(INFUSIONS."forum/attachments/".$attach['attach_name']);
}
}
}
// Delete all attachments
dbquery("DELETE FROM ".DB_FORUM_ATTACHMENTS." WHERE thread_id=:thread_id", $param);
// Delete all poll voters
dbquery("DELETE FROM ".DB_FORUM_POLL_VOTERS." WHERE thread_id=:thread_id", $param);
// Delete all Poll Options
dbquery("DELETE FROM ".DB_FORUM_POLL_OPTIONS." WHERE thread_id=:thread_id", $param);
// Delete Thread Poll
dbquery("DELETE FROM ".DB_FORUM_POLLS." WHERE thread_id=:thread_id", $param);
// Delete The Thread
dbquery("DELETE FROM ".DB_FORUM_THREADS." WHERE thread_id=:thread_id", $param);
$response = TRUE;
}
return (boolean)$response;
}
/**
* Refresh db_forum forum's stats
*
* @param bool $delete_thread true if thread deletion
*/
private function refresh_forum($delete_thread = FALSE) {
if (self::verify_forum($this->forum_id)) {
$remaining_threads_count = dbcount("(forum_id)", DB_FORUM_THREADS, "forum_id='$this->forum_id'");
// last post id from a given forum id.
if ($remaining_threads_count) {
$result = dbquery("SELECT p.forum_id, p.post_id, p.post_author, p.post_datestamp,
COUNT(p.post_id) AS post_count FROM ".DB_FORUM_POSTS." p
INNER JOIN ".DB_FORUMS." fo ON p.forum_id=fo.forum_id
WHERE p.forum_id='".(int)$this->forum_id."' AND p.post_hidden='0'
GROUP BY p.post_id
ORDER BY p.post_datestamp DESC LIMIT 1");
if (dbrows($result) > 0) {
$pdata = dbarray($result); // yielded LAST post
dbquery("UPDATE ".DB_FORUMS." SET
forum_lastpostid = '".$pdata['post_id']."',
forum_lastpost = '".$pdata['post_datestamp']."',
forum_postcount = '".$pdata['post_count']."',
".($delete_thread ? "forum_threadcount = '".(dbcount("(thread_id)", DB_FORUM_THREADS,
"forum_id='".$this->forum_id."'"))."'," : '')."
forum_lastuser = '".$pdata['post_author']."'
WHERE forum_id = '".$this->forum_id."'
");
}
} else {
dbquery("UPDATE ".DB_FORUMS." SET forum_lastpostid = '0', forum_lastpost='0', forum_postcount=0, forum_threadcount=0, forum_lastuser='0' WHERE forum_id='".intval($this->forum_id)."'");
}
}
}
/**
* Moderator Action - Lock Thread
* Modal pop up confirmation of thread being `locked`
*/
private function mod_lock_thread() {
if (iMOD) {
dbquery("UPDATE ".DB_FORUM_THREADS." SET thread_locked='1' WHERE thread_id='".intval($this->thread_id)."' AND thread_hidden='0'");
ob_start();
echo openmodal('lockthread', $this->locale['forum_0202'], ['class' => 'modal-center']);
echo "";
if ($pdata['num_posts'] != $post_count) {
$remove_first_post = TRUE;
echo str_replace(['[STRONG]', '[/STRONG]'], ['
', ''], $this->locale['forum_0305'])."
\n"; // trying to remove first post with other post in the thread
} else {
echo str_replace(['[STRONG]', '[/STRONG]'], ['
', ''], $this->locale['forum_0306'])."
\n"; // confirm ok to remove first post.
}
if ($remove_first_post && count($array_post) == 1) {
echo "
".$this->locale['forum_0307']."\n"; // no post to move.
echo "
".$this->locale['forum_0309']."";
$f_post_blo = TRUE;
}
echo "
\n";
}
if (!isset($_POST['new_forum_id']) && !$f_post_blo) {
$fl_result = dbquery("
SELECT f.forum_id, f.forum_name, f.forum_type, f2.forum_name 'forum_cat_name',
( SELECT COUNT(thread_id) FROM ".DB_FORUM_THREADS." th WHERE f.forum_id=th.forum_id AND th.thread_id !='".intval($this->thread_id)."'
GROUP BY th.forum_id
) AS threadcount
FROM ".DB_FORUMS." f
LEFT JOIN ".DB_FORUMS." f2 ON f.forum_cat=f2.forum_id
WHERE ".groupaccess('f.forum_access')."
ORDER BY f2.forum_order ASC, f.forum_order ASC
");
if (dbrows($fl_result)) {
$exclude_opts = [];
while ($data = dbarray($fl_result)) {
if (empty($data['threadcount']) || $data['forum_type'] == '1') {
$exclude_opts[] = $data['forum_id'];
}
}
echo openform('modopts', 'post', $this->form_action);
echo form_select_tree('new_forum_id', $this->locale['forum_0301'], '', [
'disable_opts' => $exclude_opts,
'no_root' => 1,
'inline' => FALSE,
'inner_width' => '100%'
], DB_FORUMS, 'forum_name', 'forum_id', 'forum_cat');
foreach ($array_post as $value) {
echo form_hidden("delete_item_post[]", "", $value, ["input_id" => "delete_post[$value]"]);
}
echo form_hidden('move_posts', '', 1);
echo modalfooter(
form_button($this->locale['forum_0302'], $this->locale['forum_0208'], $this->locale['forum_0208'], ['class' => 'btn-primary'])
);
echo closeform();
} else {
echo "