diff --git a/e107_plugins/forum/forum_admin.php b/e107_plugins/forum/forum_admin.php index 573b743fa..e472abb5c 100644 --- a/e107_plugins/forum/forum_admin.php +++ b/e107_plugins/forum/forum_admin.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_admin.php,v $ -| $Revision: 1.7 $ -| $Date: 2008-12-18 15:28:59 $ +| $Revision: 1.8 $ +| $Date: 2008-12-18 18:32:54 $ | $Author: mcfly_e107 $ +----------------------------------------------------------------------------+ */ @@ -84,13 +84,13 @@ if(isset($_POST['tools'])) { if(isset($_POST['counts'])) { - $for->forum_update_counts($fid, $_POST['counts_threads']); + $for->forumUpdateCounts($fid, $_POST['counts_threads']); $msg .= FORLAN_167.": $fid
"; } if(isset($_POST['lastpost'])) { $with_threads = (isset($_POST['lastpost_nothread'])) ? FALSE : TRUE; - $for->update_lastpost('forum', $fid, $with_threads); + $for->forumUpdateLastpost('forum', $fid, $with_threads); $msg .= FORLAN_168.": $fid
"; } } @@ -285,7 +285,7 @@ if (isset($_POST['updateoptions'])) if (isset($_POST['do_prune'])) { - $msg = $for->forum_prune($_POST['prune_type'], $_POST['prune_days'], $_POST['pruneForum']); + $msg = $for->forumPrune($_POST['prune_type'], $_POST['prune_days'], $_POST['pruneForum']); $forum->show_message($msg); $action = 'main'; } diff --git a/e107_plugins/forum/forum_admin_class.php b/e107_plugins/forum/forum_admin_class.php index fa20532e7..5c4fe1481 100755 --- a/e107_plugins/forum/forum_admin_class.php +++ b/e107_plugins/forum/forum_admin_class.php @@ -9,8 +9,8 @@ * Forum admin functions * * $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_admin_class.php,v $ -* $Revision: 1.11 $ -* $Date: 2008-12-18 15:28:59 $ +* $Revision: 1.12 $ +* $Date: 2008-12-18 18:32:54 $ * $Author: mcfly_e107 $ * */ @@ -20,36 +20,33 @@ class forumAdmin function show_options($action) { global $sql; - if ($action == "") - { - $action = "main"; - } + if ($action == '') { $action = 'main'; } // ##### Display options --------------------------------------------------------------------------------------------------------- $var['main']['text'] = FORLAN_76; $var['main']['link'] = e_SELF; $var['cat']['text'] = FORLAN_83; - $var['cat']['link'] = e_SELF."?cat"; + $var['cat']['link'] = e_SELF.'?cat'; if ($sql->db_Select('forum', 'forum_id', "forum_parent='0' LIMIT 1")) { $var['create']['text'] = FORLAN_77; - $var['create']['link'] = e_SELF."?create"; + $var['create']['link'] = e_SELF.'?create'; } $var['order']['text'] = FORLAN_78; - $var['order']['link'] = e_SELF."?order"; + $var['order']['link'] = e_SELF.'?order'; $var['opt']['text'] = FORLAN_79; - $var['opt']['link'] = e_SELF."?opt"; + $var['opt']['link'] = e_SELF.'?opt'; $var['prune']['text'] = FORLAN_59; - $var['prune']['link'] = e_SELF."?prune"; + $var['prune']['link'] = e_SELF.'?prune'; $var['rank']['text'] = FORLAN_63; - $var['rank']['link'] = e_SELF."?rank"; + $var['rank']['link'] = e_SELF.'?rank'; $var['rules']['text'] = FORLAN_123; - $var['rules']['link'] = e_SELF."?rules"; + $var['rules']['link'] = e_SELF.'?rules'; $var['sr']['text'] = FORLAN_116; - $var['sr']['link'] = e_SELF."?sr"; + $var['sr']['link'] = e_SELF.'?sr'; $var['mods']['text'] = FORLAN_33; - $var['mods']['link'] = e_SELF."?mods"; + $var['mods']['link'] = e_SELF.'?mods'; $var['tools']['text'] = FORLAN_153; - $var['tools']['link'] = e_SELF."?tools"; + $var['tools']['link'] = e_SELF.'?tools'; show_admin_menu(FORLAN_7, $action, $var); } @@ -90,7 +87,7 @@ class forumAdmin function delete_parent($id, $confirm = false) { global $sql; - $ret = ""; + $ret = ''; if($sql->db_Select('forum', 'forum_id', "forum_parent = {$id} AND forum_sub = 0")) { $fList = $sql->db_getList(); @@ -115,11 +112,38 @@ class forumAdmin } + function deleteForum($forumId) + { + $e107 = e107::getInstance(); + $forumId = (int)$forumId; +// echo "id = $forumId
"; + // Check for any sub forums + if($e107->sql->db_Select('forum', 'forum_id', "forum_sub = {$forumId}")) + { + $list = $e107->sql->db_getList(); + foreach($list as $f) + { + $ret .= $this->deleteForum($f['forum_id']); + } + } + require_once(e_PLUGIN.'forum/forum_class.php'); + $f = new e107Forum; + if($e107->sql->db_Select('forum_thread', 'thread_id','thread_forum_id='.$forumId)) + { + $list = $e107->sql->db_getList(); + foreach($list as $t) + { + $f->threadDelete($t['thread_id'], false); + } + } + return $e107->sql->db_Delete('forum', 'forum_id = '.$forumId); + } + function delete_forum($id, $confirm = false) { - global $sql, $tp; + $e107 = e107::getInstance(); $ret = ''; - if($sql->db_Select('forum', 'forum_id', "forum_sub = {$id}")) + if($e107->sql->db_Select('forum', 'forum_id', 'forum_sub = '.$id)) { $fList = $sql->db_getList(); foreach($fList as $f) @@ -129,9 +153,7 @@ class forumAdmin } if($confirm) { - $cnt = $sql->db_Delete('forum_t',"thread_forum_id = {$id}"); - $ret .= $cnt." forum {$id} thread(s) deleted
"; - if($sql->db_Delete("forum", "forum_id = {$id}")) + if($this->deleteForum($id)) { $ret .= "Forum {$id} successfully deleted"; } @@ -142,19 +164,17 @@ class forumAdmin return $ret; } - $sql->db_Select('forum', 'forum_name, forum_threads, forum_replies', "forum_id = {$id}"); - $row = $sql->db_Fetch(); - return "Forum {$id} [".$tp->toHTML($row['forum_name'])."] has {$row['forum_threads']} threads, {$row['forum_replies']} replies.
".$ret; + $e107->sql->db_Select('forum', 'forum_name, forum_threads, forum_replies', 'forum_id = '.$id); + $row = $e107->sql->db_Fetch(); + return "Forum {$id} [".$e107->tp->toHTML($row['forum_name'])."] has {$row['forum_threads']} threads, {$row['forum_replies']} replies.
".$ret; } function delete_sub($id, $confirm = FALSE) { - global $sql, $tp; + $e107 = e107::getInstance(); if($confirm) { - $cnt = $sql->db_Delete("forum_t","thread_forum_id = {$id}"); - $ret .= $cnt." Sub-forum {$id} thread(s) deleted
"; - if($sql->db_Delete("forum", "forum_id = {$id}")) + if($this->deleteForum($id)) { $ret .= "Sub-forum {$id} successfully deleted"; } @@ -165,9 +185,9 @@ class forumAdmin return $ret; } - $sql->db_Select("forum", "*", "forum_id = {$id}"); - $row = $sql->db_Fetch(); - return "Sub-forum {$id} [".$tp->toHTML($row['forum_name'])."] has {$row['forum_threads']} threads, {$row['forum_replies']} replies.
".$ret; + $e107->sql->db_Select('forum', '*', 'forum_id = '.$id); + $row = $e107->sql->db_Fetch(); + return "Sub-forum {$id} [".$e107->tp->toHTML($row['forum_name'])."] has {$row['forum_threads']} threads, {$row['forum_replies']} replies.
".$ret; } function delete_show_confirm($txt) @@ -175,7 +195,7 @@ class forumAdmin global $ns; $this->show_message($txt); $txt = " -
+
".FORLAN_180."

@@ -188,7 +208,7 @@ class forumAdmin { global $sql, $tp, $ns; $txt = " - + diff --git a/e107_plugins/forum/forum_class.php b/e107_plugins/forum/forum_class.php index 005f3ecdf..318d0aa2b 100644 --- a/e107_plugins/forum/forum_class.php +++ b/e107_plugins/forum/forum_class.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_class.php,v $ -| $Revision: 1.31 $ -| $Date: 2008-12-18 17:10:48 $ +| $Revision: 1.32 $ +| $Date: 2008-12-18 18:32:54 $ | $Author: mcfly_e107 $ +----------------------------------------------------------------------------+ */ @@ -492,7 +492,7 @@ class e107forum } foreach($parentList as $id) { - $this->update_lastpost('forum', $id, $update_threads); + $this->forumUpdateLastpost('forum', $id, $update_threads); } } } @@ -968,31 +968,26 @@ class e107forum return $ret; } - function forum_prune($type, $days, $forumArray) + function forumPrune($type, $days, $forumArray) { - global $sql; - $prunedate = time() - (intval($days) * 86400); - $forumList = implode(",", $forumArray); + $e107 = e107::getInstance(); + $prunedate = time() - (int)$days * 86400; + $forumList = implode(',', $forumArray); if($type == 'delete') { //Get list of threads to prune - if ($sql->db_Select("forum_t", "thread_id", "thread_lastpost < $prunedate AND thread_parent=0 AND thread_sticky != 1 AND thread_forum_id IN ({$forumList})")) + if ($e107->sql->db_Select('forum_thread', 'thread_id', "thread_lastpost < {$prunedate} AND thread_sticky != 1 AND thread_forum_id IN ({$forumList})")) { - $threadList = $sql->db_getList(); + $threadList = $e107->sql->db_getList(); foreach($threadList as $thread) { - //Delete all replies - $reply_count += $sql->db_Delete("forum_t", "thread_parent='".intval($thread['thread_id'])."'"); - //Delete thread - $thread_count += $sql->db_Delete("forum_t", "thread_id = '".intval($thread['thread_id'])."'"); - //Delete poll if there is one - $sql->db_Delete("poll", "poll_datestamp='".intval($thread['thread_id']).""); + $this->threadDelete($thread['thread_id'], false); } foreach($forumArray as $fid) { - $this->update_lastpost('forum', $fid); - $this->forum_update_counts($fid); + $this->forumUpdateLastpost('forum', $fid); + $this->forumUpdateCounts($fid); } return FORLAN_8." ( ".$thread_count." ".FORLAN_92.", ".$reply_count." ".FORLAN_93." )"; } @@ -1003,41 +998,40 @@ class e107forum } if($type == 'make_inactive') { - $pruned = $sql->db_Update("forum_t", "thread_active=0 WHERE thread_lastpost < $prunedate AND thread_parent=0 AND thread_forum_id IN ({$forumList})"); - return FORLAN_8." ".$pruned." ".FORLAN_91; + $pruned = $e107->sql->db_Update('forum_thread', "thread_active=0 WHERE thread_lastpost < {$prunedate} thread_forum_id IN ({$forumList})"); + return FORLAN_8.' '.$pruned.' '.FORLAN_91; } } - function forum_update_counts($forumID, $recalc_threads = false) + function forumUpdateCounts($forumId, $recalcThreads = false) { - global $sql; - if($forumID == 'all') + $e107 = e107::getInstance(); + if($forumId == 'all') { - $sql->db_Select('forum', 'forum_id', 'forum_parent != 0'); - $flist = $sql->db_getList(); + $e107->sql->db_Select('forum', 'forum_id', 'forum_parent != 0'); + $flist = $e107->sql->db_getList(); foreach($flist as $f) { - $this->forum_update_counts($f['forum_id']); + $this->forumUpdateCounts($f['forum_id']); } return; } - $forumID = intval($forumID); - $threads = $sql->db_Count("forum_t", "(*)", "WHERE thread_forum_id=$forumID AND thread_parent = 0"); - $replies = $sql->db_Count("forum_t", "(*)", "WHERE thread_forum_id=$forumID AND thread_parent != 0"); - $sql->db_Update("forum", "forum_threads='$threads', forum_replies='$replies' WHERE forum_id='$forumID'"); + $forumId = (int)$forumId; + $threads = $e107->sql->db_Count('forum_thread', '(*)', 'WHERE thread_forum_id='.$forumId); + $replies = $e107->sql->db_Count('forum_post', '(*)', 'WHERE post_forum='.$forumId); + $e107->sql->db_Update('forum', "forum_threads={$threads}, forum_replies={$replies} WHERE forum_id={$forumId}"); if($recalc_threads == true) { - $sql->db_Select("forum_t", "thread_parent, count(*) as replies", "thread_forum_id = $forumID GROUP BY thread_parent"); - $tlist = $sql->db_getList(); + $e107->sql->db_Select('forum_post', 'post_thread, count(post_thread) AS replies', "post_forum={$forumId} GROUP BY post_thread"); + $tlist = $e107->sql->db_getList(); foreach($tlist as $t) { - $tid = $t['thread_parent']; - $replies = intval($t['replies']); - $sql->db_Update("forum_t", "thread_total_replies='$replies' WHERE thread_id='$tid'"); + $tid = $t['post_thread']; + $replies = (int)$t['replies']; + $e107->sql->db_Update('forum_thread', "thread_total_replies={$replies} WHERE thread_id={$tid}"); } } } - function getUserCounts() { @@ -1138,6 +1132,100 @@ class e107forum } $BACKLINK = $BREADCRUMB; } + + + function threadDelete($threadId, $updateForumLastpost = true) + { + $e107 = e107::getInstance(); + if ($threadInfo = $this->threadGet($threadId)) + { + // delete poll if there is one + $e107->sql->db_Delete('poll', 'poll_datestamp='.$threadId); + + //decrement user post counts + if ($postCount = $this->threadGetUserPostcount($threadId)) + { + foreach ($postCount as $k => $v) + { + $e107->sql->db_Update('user_extended', 'user_plugin_forum_posts=GREATEST(user_plugin_forum_posts-'.$v.',0) WHERE user_id='.$k); + } + } + + // delete all posts + $qry = 'SELECT post_id FROM `#forum_post` WHERE post_thread = '.$threadId; + if($e107->sql->db_Select_gen($qry)) + { + $postList = array(); + while($row = $e107->sql->db_Fetch(MYSQL_ASSOC)) + { + $postList[] = $row['post_id']; + } + foreach($postList as $postId) + { + $this->postDelete($postId, false); + } + } + + // delete the thread itself + $e107->sql->db_Delete('forum_thread', 'thread_id='.$threadId); + + //Delete any thread tracking + $e107->sql->db_Delete('forum_track', 'track_thread='.$threadId); + + // update forum with correct thread/reply counts + $e107->sql->db_Update('forum', "forum_threads=GREATEST(forum_threads-1,0), forum_replies=GREATEST(forum_replies-{$threadInfo['thread_total_replies']},0) WHERE forum_id=".$threadInfo['thread_forum_id']); + + if($updateForumLastpost) + { + // update lastpost info + $this->forumUpdateLastpost('forum', $threadInfo['thread_forum_id']); + } + return $threadInfo['thread_total_replies']; + } + } + + function postDelete($postId, $updateCounts = true) + { + $postId = (int)$postId; + $e107 = e107::getInstance(); + if(!$e107->sql->db_Select('forum_post', '*', 'post_id = '.$postId)) + { + echo 'NOT FOUND!'; return; + } + $row = $e107->sql->db_Fetch(MYSQL_ASSOC); + + //delete attachments if they exist + if($row['post_attachments']) + { + $this->postDeleteAttachments('post', $postId); + } + + // delete post + $e107->sql->db_Delete('forum_post', 'post_id='.$postId); + + if($updateCounts) + { + //decrement user post counts + if ($row['post_user']) + { + $e107->sql->db_Update('user_extended', 'user_plugin_forum_posts=GREATEST(user_plugin_forum_posts-1,0) WHERE user_id='.$row['post_user']); + } + + // update thread with correct reply counts + $e107->sql->db_Update('forum_thread', "thread_total_replies=GREATEST(thread_total_replies-1,0) WHERE thread_id=".$row['post_thread']); + + // update forum with correct thread/reply counts + $e107->sql->db_Update('forum', "forum_replies=GREATEST(forum_replies-1,0) WHERE forum_id=".$row['post_forum']); + + // update thread lastpost info + $this->forumUpdateLastpost('thread', $row['post_thread']); + + // update forum lastpost info + $this->forumUpdateLastpost('forum', $row['post_forum']); + } + return $threadInfo['thread_total_replies']; + } + } diff --git a/e107_plugins/forum/forum_mod.php b/e107_plugins/forum/forum_mod.php index d15a25ea7..73eb65a3c 100644 --- a/e107_plugins/forum/forum_mod.php +++ b/e107_plugins/forum/forum_mod.php @@ -11,15 +11,12 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_mod.php,v $ -| $Revision: 1.5 $ -| $Date: 2008-12-15 00:29:20 $ +| $Revision: 1.6 $ +| $Date: 2008-12-18 18:32:54 $ | $Author: mcfly_e107 $ +----------------------------------------------------------------------------+ */ -if (!defined('e107_INIT')) -{ - exit; -} +if (!defined('e107_INIT')) { exit; } include_lan(e_PLUGIN.'forum/languages/English/lan_forum_admin.php'); function forum_thread_moderate($p) @@ -33,38 +30,38 @@ function forum_thread_moderate($p) if (preg_match("#(.*?)_(\d+)_x#", $key, $matches)) { $act = $matches[1]; -// print_a($matches); return; + // print_a($matches); return; $id = (int)$matches[2]; switch ($act) { case 'lock': - $e107->sql->db_Update('forum_thread', 'thread_active=0 WHERE thread_id='.$id); - return FORLAN_CLOSE; - break; + $e107->sql->db_Update('forum_thread', 'thread_active=0 WHERE thread_id='.$id); + return FORLAN_CLOSE; + break; case 'unlock': - $e107->sql->db_Update('forum_thread', 'thread_active=1 WHERE thread_id='.$id); - return FORLAN_OPEN; - break; + $e107->sql->db_Update('forum_thread', 'thread_active=1 WHERE thread_id='.$id); + return FORLAN_OPEN; + break; case 'stick': - $e107->sql->db_Update('forum_thread', 'thread_sticky=1 WHERE thread_id='.$id); - return FORLAN_STICK; - break; + $e107->sql->db_Update('forum_thread', 'thread_sticky=1 WHERE thread_id='.$id); + return FORLAN_STICK; + break; case 'unstick': - $e107->sql->db_Update('forum_thread', 'thread_sticky=0 WHERE thread_id='.$id); - return FORLAN_UNSTICK; - break; + $e107->sql->db_Update('forum_thread', 'thread_sticky=0 WHERE thread_id='.$id); + return FORLAN_UNSTICK; + break; case 'deleteThread': - return forumDeleteThread($id); - break; + return forumDeleteThread($id); + break; case 'deletePost': - return forumDeletePost($id); - break; + return forumDeletePost($id); + break; } } @@ -74,81 +71,17 @@ function forum_thread_moderate($p) function forumDeleteThread($threadId) { require_once (e_PLUGIN.'forum/forum_class.php'); - $e107 = e107::getInstance(); $f = &new e107forum; - if ($threadInfo = $f->threadGet($threadId)) - { - // delete poll if there is one - $e107->sql->db_Delete('poll', 'poll_datestamp='.$threadId); - - //decrement user post counts - if ($postCount = $f->threadGetUserPostcount($threadId)) - { - foreach ($postCount as $k => $v) - { - $e107->sql->db_Update('user_extended', 'user_plugin_forum_posts=GREATEST(user_plugin_forum_posts-'.$v.',0) WHERE user_id='.$k); - } - } - - // delete all posts - $e107->sql->db_Delete('forum_post', 'post_thread='.$threadId); - - // delete the thread itself - $e107->sql->db_Delete('forum_thread', 'thread_id='.$threadId); - - //Delete any thread tracking - $e107->sql->db_Delete('forum_track', 'track_thread='.$threadId); - - // update forum with correct thread/reply counts - $e107->sql->db_Update('forum', "forum_threads=GREATEST(forum_threads-1,0), forum_replies=GREATEST(forum_replies-{$threadInfo['thread_total_replies']},0) WHERE forum_id=".$threadInfo['thread_forum_id']); - - // update lastpost info - $f->forumUpdateLastpost('forum', $threadInfo['thread_forum_id']); - return FORLAN_6.' and '.$threadInfo['thread_total_replies'].' '.FORLAN_7.'.'; - } + $ret = $f->threadDelete($threadId); + return FORLAN_6.' and '.$ret.' '.FORLAN_7.'.'; } function forumDeletePost($postId) { - $postId = (int)$postId; require_once (e_PLUGIN.'forum/forum_class.php'); - $e107 = e107::getInstance(); $f = &new e107forum; - if(!$e107->sql->db_Select('forum_post', '*', 'post_id = '.$postId)) - { - echo 'NOT FOUND!'; return; - } - $row = $e107->sql->db_Fetch(MYSQL_ASSOC); - - //decrement user post counts - if ($row['post_user']) - { - $e107->sql->db_Update('user_extended', 'user_plugin_forum_posts=GREATEST(user_plugin_forum_posts-1,0) WHERE user_id='.$row['post_user']); - } - - //delete attachments if they exist - if($row['post_attachments']) - { - $f->postDeleteAttachments('post', $postId); - } - - // delete post - $e107->sql->db_Delete('forum_post', 'post_id='.$postId); - - // update thread with correct reply counts - $e107->sql->db_Update('forum_thread', "thread_total_replies=GREATEST(thread_total_replies-1,0) WHERE thread_id=".$row['post_thread']); - - // update forum with correct thread/reply counts - $e107->sql->db_Update('forum', "forum_replies=GREATEST(forum_replies-1,0) WHERE forum_id=".$row['post_forum']); - - // update thread lastpost info - $f->forumUpdateLastpost('thread', $row['post_thread']); - - // update forum lastpost info - $f->forumUpdateLastpost('forum', $row['post_forum']); - return FORLAN_6.' and '.$threadInfo['thread_total_replies'].' '.FORLAN_7.'.'; - + $ret = $f->postDelete($postId); + return FORLAN_6.' and '.$ret.' '.FORLAN_7.'.'; } - ?> \ No newline at end of file
".FORLAN_151."