diff --git a/e107_plugins/forum/e_url/forum.php b/e107_plugins/forum/e_url/forum.php index b39788933..877890a99 100644 --- a/e107_plugins/forum/e_url/forum.php +++ b/e107_plugins/forum/e_url/forum.php @@ -1,11 +1,11 @@ toHTML($f['forum_name'], TRUE, "no_hook"); - $f['forum_description'] = $tp -> toHTML($f['forum_description'], TRUE, "no_hook"); + $f['forum_name'] = $tp -> toHTML($f['forum_name'], TRUE, 'no_hook'); + $f['forum_description'] = $tp -> toHTML($f['forum_description'], TRUE, 'no_hook'); - $FORUMNAME = "{$f['forum_name']}"; +// $e107->url->getUrl('forum', 'thread', array('func' => 'track'))) + + $FORUMNAME = "{$f['forum_name']}"; $FORUMDESCRIPTION = $f['forum_description'].($restricted_string ? "
$restricted_string" : ""); $THREADS = $f['forum_threads']; $REPLIES = $f['forum_replies']; @@ -365,7 +367,7 @@ function parse_subs($subList, $lastpost_datestamp) foreach($subList as $sub) { $ret['text'] .= ($ret['text'] ? ", " : ""); - $suburl = $e107->url->getUrl('forum', 'forum', array('func' => 'view', 'id' => $sub['forum_id'])); + $suburl = $e107->url->getUrl('forum', 'forum', array('func' => 'view', 'id' => $sub['forum_id'])); $ret['text'] .= "".$e107->tp->toHTML($sub['forum_name']).''; $ret['threads'] += $sub['forum_threads']; $ret['replies'] += $sub['forum_replies']; @@ -389,7 +391,12 @@ if (e_QUERY == 'track') // $sql2 = new db; // $tmp = explode("-", USERREALM); - $qry = "SELECT * from `#forum_thread` WHERE thread_id IN({$trackedThreadList}) ORDER BY thread_lastpost DESC"; + $qry = " + SELECT t.*, p.* from `#forum_thread` AS t + LEFT JOIN `#forum_post` AS p ON p.post_thread = t.thread_id AND p.post_datestamp = t.thread_datestamp + WHERE thread_id IN({$trackedThreadList}) + ORDER BY thread_lastpost DESC + "; if($e107->sql->db_Select_gen($qry)) { while($row = $e107->sql->db_Fetch(MYSQL_ASSOC)) diff --git a/e107_plugins/forum/forum_class.php b/e107_plugins/forum/forum_class.php index 2cc40fe33..5a81bf6c6 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.20 $ -| $Date: 2008-12-07 04:16:38 $ +| $Revision: 1.21 $ +| $Date: 2008-12-09 21:46:14 $ | $Author: mcfly_e107 $ +----------------------------------------------------------------------------+ */ @@ -186,13 +186,13 @@ class e107forum $threadInfo['_FIELD_TYPES'] = $this->fieldTypes['forum_thread']; $threadInfo['_FIELD_TYPES']['thread_total_replies'] = 'cmd'; -// print_a($threadInfo); +// var_dump($threadInfo); // exit; $result = $e107->sql->db_Update('forum_thread', $threadInfo); } - if($result && $updateForum) + if(($result || !$updateThread) && $updateForum) { if(varset($postInfo['post_user'])) { @@ -232,7 +232,6 @@ class e107forum $result = $e107->sql->db_Select_gen($qry); } return $postId; - } function threadAdd($threadInfo, $postInfo) @@ -322,6 +321,29 @@ class e107forum return $ret; } + + function threadGetUserPostcount($threadId) + { + $threadId = (int)$threadId; + $e107 = e107::getInstance(); + $ret = false; + $qry = " + SELECT post_user, count(post_user) AS post_count FROM `#forum_post` + WHERE post_thread = {$threadId} AND post_user IS NOT NULL + GROUP BY post_user + "; + if($e107->sql->db_Select_gen($qry)) + { + $ret = array(); + while($row = $e107->sql->db_Fetch(MYSQL_ASSOC)) + { + $ret[$row['post_user']] = $row['post_count']; + } + } + return $ret; + } + + function thread_postnum($thread_id) { global $sql; @@ -343,7 +365,7 @@ class e107forum return $ret; } - function update_lastpost($type, $id, $update_threads = FALSE) + function forumUpdateLastpost($type, $id, $update_threads = FALSE) { global $sql, $tp; $sql2 = new db; @@ -385,10 +407,10 @@ class e107forum } else { - $id = intval($id); - $forum_lp_user = ''; - $forum_lp_info = ''; - if($update_threads == TRUE) + $id = (int)$id; + $lp_info = ''; + $lp_user = 'NULL'; + if($update_threads == true) { if ($sql2->db_Select('forum_t', 'thread_id', "thread_forum_id = $id AND thread_parent = 0")) { @@ -398,15 +420,20 @@ class e107forum } } } - if ($sql->db_Select("forum_t", "*", "thread_forum_id={$id} ORDER BY thread_datestamp DESC LIMIT 0,1")) + if ($sql->db_Select('forum_thread', 'thread_id, thread_lastuser, thread_lastuser_anon, thread_datestamp', 'thread_forum_id='.$id.' ORDER BY thread_datestamp DESC LIMIT 1')) { $row = $sql->db_Fetch(MYSQL_ASSOC); - $tmp = explode(chr(1), $row['thread_user']); - $forum_lp_user = $tmp[0]; - $last_id = $row['thread_parent'] ? $row['thread_parent'] : $row['thread_id']; - $forum_lp_info = $row['thread_datestamp'].".".$last_id; + $lp_info = $row['thread_datestamp'].'.'.$row['thread_id']; + $lp_user = $row['thread_lastuser']; + } + if($row['thread_lastuser_anon']) + { + $sql->db_Update('forum', "forum_lastpost_user = 0, forum_lastpost_anon = '{$row['thread_lastuser_anon']}', forum_lastpost_info = '{$lp_info}' WHERE forum_id=".$id); + } + else + { + $sql->db_Update('forum', "forum_lastpost_user = {$lp_user}, forum_lastpost_user_anon = NULL, forum_lastpost_info = '{$lp_info}' WHERE forum_id=".$id); } - $sql->db_Update('forum', "forum_lastpost_user = '{$forum_lp_user}', forum_lastpost_info = '{$forum_lp_info}' WHERE forum_id={$id}"); } } } diff --git a/e107_plugins/forum/forum_mod.php b/e107_plugins/forum/forum_mod.php index acc0d639f..e6d3370c4 100644 --- a/e107_plugins/forum/forum_mod.php +++ b/e107_plugins/forum/forum_mod.php @@ -11,132 +11,96 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_mod.php,v $ -| $Revision: 1.2 $ -| $Date: 2007-08-14 21:11:29 $ -| $Author: e107steved $ +| $Revision: 1.3 $ +| $Date: 2008-12-09 21:46:14 $ +| $Author: mcfly_e107 $ +----------------------------------------------------------------------------+ */ -if (!defined('e107_INIT')) { exit; } +if (!defined('e107_INIT')) +{ + exit; +} +include_lan(e_PLUGIN.'forum/languages/English/lan_forum_admin.php'); -@include_once e_PLUGIN.'forum/languages/'.e_LANGUAGE.'/lan_forum_admin.php'; -@include_once e_PLUGIN.'forum/languages/English/lan_forum_admin.php'; - function forum_thread_moderate($p) { + // var_dump($_POST); + // return; + $e107 = e107::getInstance(); global $sql; - foreach($p as $key => $val) { + foreach ($p as $key => $val) + { if (preg_match("#(.*?)_(\d+)_x#", $key, $matches)) { $act = $matches[1]; - $id = intval($matches[2]); - - switch($act) + $id = (int)$matches[2]; + + switch ($act) { - case 'lock' : - $sql->db_Update("forum_t", "thread_active='0' WHERE thread_id='$id' "); - return FORLAN_CLOSE; - break; - - case 'unlock' : - $sql->db_Update("forum_t", "thread_active='1' WHERE thread_id='$id' "); - return FORLAN_OPEN; - break; - - case 'stick' : - $sql->db_Update("forum_t", "thread_s='1' WHERE thread_id='$id' "); - return FORLAN_STICK; - break; - - case 'unstick' : - $sql->db_Update("forum_t", "thread_s='0' WHERE thread_id='$id' "); - return FORLAN_UNSTICK; - break; - - case 'delete' : - return forum_delete_thread($id); - break; - + case 'lock': + $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; + + case 'stick': + $e107->sql->db_Update('forum_thread', 'thread_s=1 WHERE thread_id='.$id); + return FORLAN_STICK; + break; + + case 'unstick': + $e107->sql->db_Update('forum_thread', 'thread_s=0 WHERE thread_id='.$id); + return FORLAN_UNSTICK; + break; + + case 'deleteThread': + return forumDeleteThread($id); + break; + } } } } - -function forum_delete_thread($thread_id) + +function forumDeleteThread($threadId) { - global $sql; - @require_once(e_PLUGIN.'forum/forum_class.php'); - $f =& new e107forum; - $sql->db_Select("forum_t", "*", "thread_id='".intval($thread_id)."' "); - $row = $sql->db_Fetch(); - - if ($row['thread_parent']) + require_once (e_PLUGIN.'forum/forum_class.php'); + $e107 = e107::getInstance(); + $f = &new e107forum; + if ($threadInfo = $f->threadGet($threadId)) { - // post is a reply? - $sql->db_Delete("forum_t", "thread_id='".intval($thread_id)."' "); - // dec forum reply count by 1 - $sql->db_Update("forum", "forum_replies=forum_replies-1 WHERE forum_id='".$row['thread_forum_id']."' AND forum_replies>0"); - // dec thread reply count by 1 - $sql->db_Update("forum_t", "thread_total_replies=thread_total_replies-1 WHERE thread_id='".$row['thread_parent']."' AND thread_total_replies>0"); - // dec user forum post count by 1 - $tmp = explode(".", $row['thread_user']); - $uid = intval($tmp[0]); - if($uid > 0) - { - $sql->db_Update("user", "user_forums=user_forums-1 WHERE user_id='".$uid."' AND user_forums>0"); - } - // update lastpost info - $f->update_lastpost('thread', $row['thread_parent']); - $f->update_lastpost('forum', $row['thread_forum_id']); - return FORLAN_154; - } - else - { - // post is thread // delete poll if there is one - $sql->db_Delete("poll", "poll_datestamp='".intval($thread_id)."'"); + $e107->sql->db_Delete('poll', 'poll_datestamp='.$threadId); + //decrement user post counts - forum_userpost_count("WHERE thread_id = '".intval($thread_id)."' OR thread_parent = '".intval($thread_id)."'", "dec"); - // delete replies and grab how many there were - $count = $sql->db_Delete("forum_t", "thread_parent='".intval($thread_id)."'"); - // delete the post itself - $sql->db_Delete("forum_t", "thread_id='".intval($thread_id)."'"); - // update thread/reply counts - $sql->db_Update("forum", "forum_threads=LEAST(forum_threads-1,0), forum_replies=LEAST(forum_replies-{$count},0) WHERE forum_id='".$row['thread_forum_id']."'"); - // update lastpost info - $f->update_lastpost('forum', $row['thread_forum_id']); - return FORLAN_6.($count ? ", ".$count." ".FORLAN_7."." : "."); - } -} - -function forum_userpost_count($where = "", $type = "dec") -{ - global $sql; - - $qry = " - SELECT thread_user, count(thread_user) AS cnt FROM #forum_t - {$where} - GROUP BY thread_user - "; - - if($sql->db_Select_gen($qry)) - { - $uList = $sql->db_getList(); - foreach($uList as $u) + if ($postCount = $f->threadGetUserPostcount($threadId)) { - $tmp = explode(".", $u['thread_user']); - $uid = intval($tmp[0]); - if($uid > 0) + foreach ($postCount as $k => $v) { - if("set" == $type) - { - $sql->db_Update("user", "user_forums={$u['cnt']} WHERE user_id='".$uid."'"); - } - else - { // user_forums is unsigned, so underflow will give a very big number - $sql->db_Update("user", "user_forums=LEAST(user_forums-{$u['cnt']},0) WHERE user_id='".$uid."'"); - } + $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.'.'; } } + ?> \ No newline at end of file diff --git a/e107_plugins/forum/forum_post.php b/e107_plugins/forum/forum_post.php index 70c46bf44..43f138e36 100644 --- a/e107_plugins/forum/forum_post.php +++ b/e107_plugins/forum/forum_post.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_post.php,v $ -| $Revision: 1.26 $ -| $Date: 2008-12-08 02:33:34 $ +| $Revision: 1.27 $ +| $Date: 2008-12-09 21:46:14 $ | $Author: mcfly_e107 $ +----------------------------------------------------------------------------+ */ @@ -113,9 +113,9 @@ if($pref['forum_attach']) $a_filetypes = get_filetypes(); $max_upload_size = calc_max_upload_size(-1); // Find overriding maximum upload size $max_upload_size = set_max_size($a_filetypes, $max_upload_size); - $max_upload_size = $e107->parseMemorySize($max_upload_size, 0); + $max_upload_size = $e107->parseMemorySize($max_upload_size, 0); $a_filetypes = array_keys($a_filetypes); - $allowed_filetypes = implode(' | ', $a_filetypes); + $allowed_filetypes = implode(' | ', $a_filetypes); } if (isset($_POST['submitpoll'])) @@ -212,7 +212,7 @@ if (isset($_POST['newthread']) || isset($_POST['reply'])) $threadInfo = array(); $postOptions = array(); $threadOptions = array(); - + if ((isset($_POST['newthread']) && trim($_POST['subject']) == '') || trim($_POST['post']) == '') { message_handler('ALERT', 5); @@ -272,7 +272,7 @@ if (isset($_POST['newthread']) || isset($_POST['reply'])) // New thread started. Add the thread info (with lastest post info), add the post. // Update forum with latest post info case 'nt': - $threadInfo['thread_s'] = (MODERATOR ? $_POST['threadtype'] : 0); + $threadInfo['thread_s'] = (MODERATOR ? (int)$_POST['threadtype'] : 0); $threadInfo['thread_name'] = $_POST['subject']; $threadInfo['thread_forum_id'] = $forumId; $threadInfo['thread_active'] = 1; @@ -281,21 +281,26 @@ if (isset($_POST['newthread']) || isset($_POST['reply'])) { $threadOptions['poll'] = '1'; } - $threadInfo['thread_options'] = serialize($threadOptions); + if(is_array($threadOptions) && count($threadOptions)) + { + $threadInfo['thread_options'] = serialize($threadOptions); + } + else + { + $threadInfo['thread_options'] = ''; + } if($postResult = $forum->threadAdd($threadInfo, $postInfo)) { - $newPostId = $postResult['postid']; - $newThreadId = $postResult['threadid']; + $newPostId = $postResult['postid']; + $newThreadId = $postResult['threadid']; + if($_POST['email_notify']) + { + $forum->track('add', USERID, $newThreadId); + } } + break; } - -// $email_notify = ($_POST['email_notify'] ? 99 : 1); - -// if ($_POST['poll_title'] != "" && $_POST['poll_option'][0] != "" && $_POST['poll_option'][1] != "") -// { -// $subject = "[".LAN_402."] ".$subject; -// } // print_a($threadInfo); // print_a($postInfo); // exit; @@ -541,9 +546,9 @@ function forumjump() function process_upload() { global $pref, $forum_info, $thread_info, $admin_log; - + $postId = (int)$postId; - $ret = array(); + $ret = array(); // var_dump($_FILES); if (isset($_FILES['file_userfile']['error'])) diff --git a/e107_plugins/forum/forum_viewtopic.php b/e107_plugins/forum/forum_viewtopic.php index 65b878e1f..9851203ab 100644 --- a/e107_plugins/forum/forum_viewtopic.php +++ b/e107_plugins/forum/forum_viewtopic.php @@ -12,8 +12,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_viewtopic.php,v $ -| $Revision: 1.10 $ -| $Date: 2008-12-08 02:33:34 $ +| $Revision: 1.11 $ +| $Date: 2008-12-09 21:46:14 $ | $Author: mcfly_e107 $ +----------------------------------------------------------------------------+ */ @@ -149,7 +149,7 @@ $NEXTPREV .= " if ($pref['forum_track'] && USER) { $img = ($thread->threadInfo['track_userid'] ? IMAGE_track : IMAGE_untrack); - $url = $e107->url->getUrl('forum', 'thread', array('func' => 'view', 'id' => $thread->threadId)); + $url = $e107->url->getUrl('forum', 'thread', array('func' => 'view', 'id' => $thread->threadId)); $TRACK .= " {$img} @@ -157,8 +157,8 @@ if ($pref['forum_track'] && USER)