From 092f64bcf82bac17947cde426d0cc6202829817a Mon Sep 17 00:00:00 2001 From: Cameron Date: Tue, 12 Mar 2013 20:35:04 -0700 Subject: [PATCH] Forum template work. (work in progress) --- e107_plugins/forum/forum_class.php | 403 ++++++++++++++---- e107_plugins/forum/forum_conf.php | 82 ++-- e107_plugins/forum/forum_viewforum.php | 34 +- .../shortcodes/batch/post_shortcodes.php | 4 +- .../forum/templates/forum_post_template.php | 42 ++ .../templates/forum_viewforum_template.php | 4 +- .../templates/forum_viewtopic_template.php | 6 +- 7 files changed, 460 insertions(+), 115 deletions(-) diff --git a/e107_plugins/forum/forum_class.php b/e107_plugins/forum/forum_class.php index 88ec26cd1..c54d306d8 100644 --- a/e107_plugins/forum/forum_class.php +++ b/e107_plugins/forum/forum_class.php @@ -8,13 +8,70 @@ * * Forum class * -* $URL$ -* $Id$ -* */ if (!defined('e107_INIT')) { exit; } + + +/* Forum Header File */ +if (!defined('e107_INIT')) { exit; } + +$code = <<prefs->get('postspage')) { $this->setDefaults(); } + + if(e_AJAX_REQUEST && MODERATOR) // see javascript above. + { + if(!vartrue($_POST['thread'])) + { + exit; + } + + $id = intval($_POST['thread']); + + $ret = array('hide'=>false,'msg'=>'','status'=>null); + + switch ($_POST['action']) + { + case 'delete': + if($this->threadDelete($id)) + { + $ret['msg'] = 'Deleted Thread #'.$id; + $ret['hide'] = true; + $ret['status'] = 'ok'; + } + else + { + $ret['msg'] = "Couldn't Delete the Thread"; + $ret['status'] = 'error'; + } + break; + + case 'lock': + if(e107::getDB()->update('forum_thread', 'thread_active=0 WHERE thread_id='.$id)) + { + $ret['msg'] = FORLAN_CLOSE; + $ret['status'] = 'ok'; + } + else + { + $ret['msg'] = "failed to close thread"; + $ret['status'] = 'error'; + } + break; + + case 'unlock': + if(e107::getDB()->update('forum_thread', 'thread_active=1 WHERE thread_id='.$id)) + { + $ret['msg'] = FORLAN_OPEN; + $ret['status'] = 'ok'; + } + else + { + $ret['msg'] = "failed to open thread"; + $ret['status'] = 'error'; + } + break; + + case 'stick': + if(e107::getDB()->update('forum_thread', 'thread_sticky=1 WHERE thread_id='.$id)) + { + $ret['msg'] = FORLAN_STICK; + $ret['status'] = 'ok'; + } + else + { + $ret['msg'] = "failed to stick thread"; + $ret['status'] = 'error'; + } + break; + + case 'unstick': + if(e107::getDB()->update('forum_thread', 'thread_sticky=0 WHERE thread_id='.$id)) + { + $ret['msg'] = FORLAN_UNSTICK; + $ret['status'] = 'ok'; + } + else + { + $ret['msg'] = "failed to unstick thread"; + $ret['status'] = 'error'; + } + break; + + default: + $ret['status'] = 'error'; + $ret['msg'] = 'No action selected'; + break; + } + + echo json_encode($ret); + + exit; + } + + + + + // var_dump($this->prefs); /* @@ -58,6 +210,8 @@ class e107forum */ } + + private function loadPermList() { $e107 = e107::getInstance(); @@ -74,12 +228,16 @@ class e107forum unset($tmp); } + + public function getForumPermList($what = null) { if(null !== $what) return (isset($this->permList[$what]) ? $this->permList[$what] : null); return $this->permList; } + + private function setDefaults() { $this->prefs->set('show_topics', '1'); @@ -95,6 +253,8 @@ class e107forum $this->prefs->set('highlightsticky', '1'); } + + private function _getForumPermList() { $e107 = e107::getInstance(); @@ -125,10 +285,10 @@ class e107forum foreach($qryList as $key => $qry) { - if($e107->sql->db_Select_gen($qry)) + if($e107->sql->gen($qry)) { $tmp = array(); - while($row = $e107->sql->db_Fetch()) + while($row = $e107->sql->fetch()) { $tmp[$row['forum_id']] = 1; $tmp[$row['forum_parent']] = 1; @@ -140,11 +300,15 @@ class e107forum } } + + function checkPerm($forumId, $type='view') { return (in_array($forumId, $this->permList[$type])); } + + function threadViewed($threadId) { $e107 = e107::getInstance(); @@ -158,13 +322,15 @@ class e107forum return (is_array($this->userViewed) && in_array($threadId, $this->userViewed)); } + + function getTrackedThreadList($id, $retType = 'array') { $e107 = e107::getInstance(); $id = (int)$id; if($e107->sql->db_Select('forum_track', 'track_thread', 'track_userid = '.$id)) { - while($row = $e107->sql->db_Fetch(MYSQL_ASSOC)) + while($row = $e107->sql->fetch(MYSQL_ASSOC)) { $ret[] = $row['track_thread']; } @@ -219,7 +385,7 @@ class e107forum // $info['_FIELD_TYPES'] = $this->fieldTypes['forum_thread']; $info['_FIELD_TYPES']['thread_total_replies'] = 'cmd'; - $result = $e107->sql->db_Update('forum_thread', $info); + $result = $e107->sql->update('forum_thread', $info); } @@ -252,7 +418,7 @@ class e107forum $info['data'] = $forumInfo; $info['data']['forum_lastpost_info'] = $postInfo['post_datestamp'].'.'.$postInfo['post_thread']; $info['WHERE'] = 'forum_id = '.$postInfo['post_forum']; - $result = $e107->sql->db_Update('forum', $info); + $result = $e107->sql->update('forum', $info); } if($result && USER && $addUserPostCount) @@ -262,11 +428,13 @@ class e107forum VALUES ('.USERID.', 1) ON DUPLICATE KEY UPDATE user_plugin_forum_posts = user_plugin_forum_posts + 1 '; - $result = $e107->sql->db_Select_gen($qry); + $result = $e107->sql->gen($qry); } return $postId; } + + function threadAdd($threadInfo, $postInfo) { $e107 = e107::getInstance(); @@ -283,6 +451,8 @@ class e107forum return false; } + + function threadMove($threadId, $newForumId, $threadTitle= '', $titleType=0) { $sql = e107::getDb(); @@ -304,16 +474,16 @@ class e107forum $threadTitle = ", thread_name = '{$threadTitle}'"; } } - $sql->db_Update('forum_thread', "thread_forum_id={$newForumId} {$threadTitle} WHERE thread_id={$threadId}"); + $sql->update('forum_thread', "thread_forum_id={$newForumId} {$threadTitle} WHERE thread_id={$threadId}"); //Move all posts to new forum - $posts = $sql->db_Update('forum_post', "post_forum={$newForumId} WHERE post_thread={$threadId}"); + $posts = $sql->update('forum_post', "post_forum={$newForumId} WHERE post_thread={$threadId}"); $replies = $posts-1; if($replies < 0) { $replies = 0; } //change thread counts accordingly - $sql->db_Update('forum', "forum_threads=forum_threads-1, forum_replies=forum_replies-$replies WHERE forum_id={$oldForumId}"); - $sql->db_Update('forum', "forum_threads=forum_threads+1, forum_replies=forum_replies+$replies WHERE forum_id={$newForumId}"); + $sql->update('forum', "forum_threads=forum_threads-1, forum_replies=forum_replies-$replies WHERE forum_id={$oldForumId}"); + $sql->update('forum', "forum_threads=forum_threads+1, forum_replies=forum_replies+$replies WHERE forum_id={$newForumId}"); // update lastpost information for old and new forums $this->forumUpdateLastpost('forum', $oldForumId, false); @@ -321,6 +491,8 @@ class e107forum } + + function threadUpdate($threadId, $threadInfo) { $e107 = e107::getInstance(); @@ -328,9 +500,11 @@ class e107forum $info['data'] = $threadInfo; // $info['_FIELD_TYPES'] = $this->fieldTypes['forum_thread']; $info['WHERE'] = 'thread_id = '.(int)$threadId; - $e107->sql->db_Update('forum_thread', $info); + $e107->sql->update('forum_thread', $info); } + + function postUpdate($postId, $postInfo) { $e107 = e107::getInstance(); @@ -338,9 +512,11 @@ class e107forum $info['data'] = $postInfo; // $info['_FIELD_TYPES'] = $this->fieldTypes['forum_post']; $info['WHERE'] = 'post_id = '.(int)$postId; - $e107->sql->db_Update('forum_post', $info); + $e107->sql->update('forum_post', $info); } + + function threadGet($id, $joinForum = true, $uid = USERID) { $e107 = e107::getInstance(); @@ -369,9 +545,9 @@ class e107forum FROM `#forum_thread` WHERE thread_id = '.$id; } - if($e107->sql->db_Select_gen($qry)) + if($e107->sql->gen($qry)) { - $tmp = $e107->sql->db_Fetch(MYSQL_ASSOC); + $tmp = $e107->sql->fetch(MYSQL_ASSOC); if($tmp) { if(trim($tmp['thread_options']) != '') @@ -384,6 +560,8 @@ class e107forum return false; } + + function postGet($id, $start, $num = NULL) { $id = (int)$id; @@ -415,10 +593,10 @@ class e107forum LIMIT {$start}, {$num} "; } - if($e107->sql->db_Select_gen($qry)) + if($e107->sql->gen($qry)) { $ret = array(); - while($row = $e107->sql->db_Fetch(MYSQL_ASSOC)) + while($row = $e107->sql->fetch(MYSQL_ASSOC)) { $ret[] = $row; } @@ -428,6 +606,7 @@ class e107forum } + function threadGetUserPostcount($threadId) { $threadId = (int)$threadId; @@ -438,10 +617,10 @@ class e107forum WHERE post_thread = {$threadId} AND post_user IS NOT NULL GROUP BY post_user "; - if($e107->sql->db_Select_gen($qry)) + if($e107->sql->gen($qry)) { $ret = array(); - while($row = $e107->sql->db_Fetch(MYSQL_ASSOC)) + while($row = $e107->sql->fetch(MYSQL_ASSOC)) { $ret[$row['post_user']] = $row['post_count']; } @@ -449,6 +628,8 @@ class e107forum return $ret; } + + function threadGetUserViewed($uid = USERID) { $e107 = e107::getInstance(); @@ -465,6 +646,8 @@ class e107forum return explode(',', $viewed); } + + function postDeleteAttachments($type = 'post', $id='', $f='') { $e107 = e107::getInstance(); @@ -492,7 +675,7 @@ class e107forum { return true; } - $tmp = $e107->sql->db_Fetch(MYSQL_ASSOC); + $tmp = $e107->sql->fetch(MYSQL_ASSOC); $attachments = explode(',', $tmp['post_attachments']); foreach($attachments as $k => $a) { @@ -524,10 +707,12 @@ class e107forum $info['data'] = $tmp; $info['_FILE_TYPES']['post_attachments'] = 'escape'; $info['WHERE'] = 'post_id = '.$id; - $e107->sql->db_update('forum_post', $info); + $e107->sql->update('forum_post', $info); } } + + /** * Given threadId and postId, determine which number of post in thread the postid is * @@ -540,6 +725,8 @@ class e107forum return $e107->sql->db_Count('forum_post', '(*)', "WHERE post_id <= {$postId} AND post_thread = {$threadId} ORDER BY post_id ASC"); } + + function forumUpdateLastpost($type, $id, $updateThreads = false) { global $sql, $tp; @@ -564,7 +751,7 @@ class e107forum $info['data'] = $tmp; // $info['_FIELD_TYPES'] = $this->fieldTypes['forum_thread']; $info['WHERE'] = 'thread_id = '.$id; - $sql->db_Update('forum_thread', $info); + $sql->update('forum_thread', $info); return $lpInfo; } @@ -574,7 +761,7 @@ class e107forum { if ($sql->db_Select('forum', 'forum_id', 'forum_parent != 0')) { - while ($row = $sql->db_Fetch(MYSQL_ASSOC)) + while ($row = $sql->fetch(MYSQL_ASSOC)) { $parentList[] = $row['forum_id']; } @@ -594,7 +781,7 @@ class e107forum { if ($sql2->db_Select('forum_t', 'thread_id', "thread_forum_id = $id AND thread_parent = 0")) { - while ($row = $sql2->db_Fetch(MYSQL_ASSOC)) + while ($row = $sql2->fetch(MYSQL_ASSOC)) { set_time_limit(60); $this->forumUpdateLastpost('thread', $row['thread_id']); @@ -603,22 +790,24 @@ class e107forum } 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); + $row = $sql->fetch(MYSQL_ASSOC); $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); + $sql->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->update('forum', "forum_lastpost_user = {$lp_user}, forum_lastpost_user_anon = NULL, forum_lastpost_info = '{$lp_info}' WHERE forum_id=".$id); } } } } + + function forumMarkAsRead($forum_id) { $e107 = e107::getInstance(); @@ -643,7 +832,7 @@ class e107forum if ($e107->sql->db_Select('forum_thread', 'thread_id', $qry)) { - while ($row = $e107->sql->db_Fetch(MYSQL_ASSOC)) + while ($row = $e107->sql->fetch(MYSQL_ASSOC)) { $newIdList[] = $row['thread_id']; } @@ -656,6 +845,8 @@ class e107forum exit; } + + function threadMarkAsRead($threadId) { global $currentUser; @@ -668,15 +859,17 @@ class e107forum } $tmp = array_unique($tmp); $viewed = trim(implode(',', $_tmp), ','); - return $e107->sql->db_Update('user_extended', "user_plugin_forum_viewed = '{$viewed}' WHERE user_extended_id = ".USERID); + return $e107->sql->update('user_extended', "user_plugin_forum_viewed = '{$viewed}' WHERE user_extended_id = ".USERID); } + + function forum_getparents() { global $sql; if ($sql->db_Select('forum', '*', 'forum_parent=0 ORDER BY forum_order ASC')) { - while ($row = $sql->db_Fetch(MYSQL_ASSOC)) { + while ($row = $sql->fetch(MYSQL_ASSOC)) { $ret[] = $row; } return $ret; @@ -684,6 +877,8 @@ class e107forum return FALSE; } + + function forumGetMods($uclass = e_UC_ADMIN, $force=false) { if(count($this->modArray) && !$force) @@ -693,7 +888,7 @@ class e107forum if($uclass == e_UC_ADMIN || trim($uclass) == '') { $this->e107->sql->db_Select('user', 'user_id, user_name','user_admin = 1 ORDER BY user_name ASC'); - while($row = $this->e107->sql->db_Fetch(MYSQL_ASSOC)) + while($row = $this->e107->sql->fetch(MYSQL_ASSOC)) { $this->modArray[$row['user_id']] = $row['user_name']; } @@ -705,11 +900,15 @@ class e107forum return $this->modArray; } + + function isModerator($uid) { return ($uid && in_array($uid, array_keys($this->forumGetMods()))); } + + function forumGetForumList($all=false) { $e107 = e107::getInstance(); @@ -720,10 +919,10 @@ class e107forum LEFT JOIN `#user` AS u ON f.forum_lastpost_user IS NOT NULL AND u.user_id = f.forum_lastpost_user '.$where. 'ORDER BY f.forum_order ASC'; - if ($e107->sql->db_Select_gen($qry)) + if ($e107->sql->gen($qry)) { $ret = array(); - while ($row = $e107->sql->db_Fetch()) + while ($row = $e107->sql->fetch()) { if(!$row['forum_parent']) { @@ -743,6 +942,8 @@ class e107forum return false; } + + function forum_getforums($type = 'all') { global $sql; @@ -752,9 +953,9 @@ class e107forum WHERE forum_parent != 0 AND forum_sub = 0 ORDER BY f.forum_order ASC "; - if ($sql->db_Select_gen($qry)) + if ($sql->gen($qry)) { - while ($row = $sql->db_Fetch(MYSQL_ASSOC)) + while ($row = $sql->fetch(MYSQL_ASSOC)) { if($type == 'all') { @@ -770,6 +971,8 @@ class e107forum return FALSE; } + + function forumGetSubs($forum_id = '') { global $sql; @@ -780,9 +983,9 @@ class e107forum WHERE forum_sub != 0 {$where} ORDER BY f.forum_order ASC "; - if ($sql->db_Select_gen($qry)) + if ($sql->gen($qry)) { - while ($row = $sql->db_Fetch(MYSQL_ASSOC)) + while ($row = $sql->fetch(MYSQL_ASSOC)) { if($forum_id == '') { @@ -802,6 +1005,8 @@ class e107forum return false; } + + /** * List of forums with unread threads * @@ -826,9 +1031,9 @@ class e107forum SELECT DISTINCT f.forum_sub, ft.thread_forum_id FROM `#forum_thread` AS ft LEFT JOIN `#forum` AS f ON f.forum_id = ft.thread_forum_id WHERE ft.thread_lastpost > '.USERLV.' '.$viewed; - if($e107->sql->db_Select_gen($_newqry)) + if($e107->sql->gen($_newqry)) { - while($row = $e107->sql->db_Fetch(MYSQL_ASSOC)) + while($row = $e107->sql->fetch(MYSQL_ASSOC)) { $ret[] = $row['thread_forum_id']; if($row['forum_sub']) @@ -844,6 +1049,8 @@ class e107forum } } + + function thread_user($post_info) { if($post_info['user_name']) @@ -857,6 +1064,8 @@ class e107forum } } + + function track($which, $uid, $threadId, $force=false) { $e107 = e107::getInstance(); @@ -878,7 +1087,7 @@ class e107forum case 'delete': case 'del': - $result = $e107->sql->db_Delete('forum_track', "`track_userid` = {$uid} AND `track_thread` = {$threadId}"); + $result = $e107->sql->delete('forum_track', "`track_userid` = {$uid} AND `track_thread` = {$threadId}"); break; case 'check': @@ -888,6 +1097,8 @@ class e107forum return $result; } + + function forumGet($forum_id) { $sql = e107::getDb(); @@ -898,13 +1109,15 @@ class e107forum LEFT JOIN #forum AS sp ON f.forum_sub = sp.forum_id AND f.forum_sub > 0 WHERE f.forum_id = {$forum_id} "; - if ($sql->db_Select_gen($qry)) + if ($sql->gen($qry)) { - return $sql->db_Fetch(MYSQL_ASSOC); + return $sql->fetch(MYSQL_ASSOC); } return FALSE; } + + function forumGetAllowed($type='view') { global $sql; @@ -913,9 +1126,9 @@ class e107forum SELECT forum_id, forum_name FROM `#forum` WHERE forum_id IN ({$forumList}) "; - if ($sql->db_Select_gen($qry)) + if ($sql->gen($qry)) { - while($row = $sql->db_Fetch(MYSQL_ASSOC)) + while($row = $sql->fetch(MYSQL_ASSOC)) { $ret[$row['forum_id']] = $row['forum_name']; } @@ -924,6 +1137,8 @@ class e107forum return $ret; } + + function forumGetThreads($forumId, $from, $view) { $e107 = e107::getInstance(); @@ -939,9 +1154,9 @@ class e107forum LIMIT ".(int)$from.','.(int)$view; $ret = array(); - if ($e107->sql->db_Select_gen($qry)) + if ($e107->sql->gen($qry)) { - while ($row = $e107->sql->db_Fetch(MYSQL_ASSOC)) + while ($row = $e107->sql->fetch(MYSQL_ASSOC)) { $ret[] = $row; } @@ -949,6 +1164,8 @@ class e107forum return $ret; } + + function threadGetLastpost($id) { $e107 = e107::getInstance(); @@ -959,9 +1176,9 @@ class e107forum WHERE p.post_thread = {$id} ORDER BY p.post_datestamp DESC LIMIT 0,1 "; - if ($e107->sql->db_Select_gen($qry)) + if ($e107->sql->gen($qry)) { - return $e107->sql->db_Fetch(MYSQL_ASSOC); + return $e107->sql->fetch(MYSQL_ASSOC); } return false; } @@ -972,6 +1189,8 @@ class e107forum // return $e107->sql->db_Count('forum_thread', '(*)', 'WHERE thread_forum_id='.(int)$forum_id); // } + + function threadGetNextPrev($which, $threadId, $forumId, $lastpost) { // echo "threadid = $threadId
forum id = $forumId
"; @@ -1000,32 +1219,38 @@ class e107forum thread_sticky DESC, thread_lastpost {$sort} LIMIT 1"; - if ($e107->sql->db_Select_gen($qry)) + if ($e107->sql->gen($qry)) { - $row = $e107->sql->db_Fetch(); + $row = $e107->sql->fetch(); return $row['thread_id']; } return false; } + + function threadIncView($id) { $id = (int)$id; - return e107::getDb()->db_Update('forum_thread', 'thread_views=thread_views+1 WHERE thread_id='.$id); + return e107::getDb()->update('forum_thread', 'thread_views=thread_views+1 WHERE thread_id='.$id); } + + function _forum_lp_update($lp_type, $lp_user, $lp_info, $lp_forum_id, $lp_forum_sub) { $sql = e107::getDb(); - $sql->db_Update('forum', "{$lp_type}={$lp_type}+1, forum_lastpost_user='{$lp_user}', forum_lastpost_info = '{$lp_info}' WHERE forum_id='".intval($lp_forum_id)."' "); + $sql->update('forum', "{$lp_type}={$lp_type}+1, forum_lastpost_user='{$lp_user}', forum_lastpost_info = '{$lp_info}' WHERE forum_id='".intval($lp_forum_id)."' "); if($lp_forum_sub) { - $sql->db_Update('forum', "forum_lastpost_user = '{$lp_user}', forum_lastpost_info = '{$lp_info}' WHERE forum_id='".intval($lp_forum_sub)."' "); + $sql->update('forum', "forum_lastpost_user = '{$lp_user}', forum_lastpost_info = '{$lp_info}' WHERE forum_id='".intval($lp_forum_sub)."' "); } } + + function threadGetNew($count = 50, $unread = true, $uid = USERID) { $e107 = e107::getInstance(); @@ -1058,13 +1283,15 @@ class e107forum ORDER BY t.thread_lastpost DESC LIMIT 0, ".(int)$count; - if($e107->sql->db_Select_gen($qry)) + if($e107->sql->gen($qry)) { $ret = $e107->sql->db_getList(); } return $ret; } + + function forumPrune($type, $days, $forumArray) { $e107 = e107::getInstance(); @@ -1095,11 +1322,13 @@ class e107forum } if($type == 'make_inactive') { - $pruned = $e107->sql->db_Update('forum_thread', "thread_active=0 WHERE thread_lastpost < {$prunedate} thread_forum_id IN ({$forumList})"); + $pruned = $e107->sql->update('forum_thread', "thread_active=0 WHERE thread_lastpost < {$prunedate} thread_forum_id IN ({$forumList})"); return FORLAN_8.' '.$pruned.' '.FORLAN_91; } } + + function forumUpdateCounts($forumId, $recalcThreads = false) { $e107 = e107::getInstance(); @@ -1117,7 +1346,7 @@ class e107forum $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}"); + $e107->sql->update('forum', "forum_threads={$threads}, forum_replies={$replies} WHERE forum_id={$forumId}"); if($recalcThreads == true) { set_time_limit(60); @@ -1127,11 +1356,13 @@ class e107forum { $tid = $t['post_thread']; $replies = (int)$t['replies']; - $e107->sql->db_Update('forum_thread', "thread_total_replies={$replies} WHERE thread_id={$tid}"); + $e107->sql->update('forum_thread', "thread_total_replies={$replies} WHERE thread_id={$tid}"); } } } + + function getUserCounts() { global $sql; @@ -1141,10 +1372,10 @@ class e107forum GROUP BY post_user "; - if($sql->db_Select_gen($qry)) + if($sql->gen($qry)) { $ret = array(); - while($row = $sql->db_Fetch(MYSQL_ASSOC)) + while($row = $sql->fetch(MYSQL_ASSOC)) { $ret[$row['post_user']] = $row['cnt']; } @@ -1153,6 +1384,8 @@ class e107forum return FALSE; } + + /* * set bread crumb * $forum_href override ONLY applies when template is missing FORUM_CRUMB @@ -1237,29 +1470,40 @@ class e107forum } + + /** + * Delete a Thread + * @param $threadId integer + * @param $updateForumLastPost boolean + * @return true on success or false on error. + */ function threadDelete($threadId, $updateForumLastpost = true) { $e107 = e107::getInstance(); + + $sql = e107::getDb(); + $status = false; + if ($threadInfo = $this->threadGet($threadId)) { // delete poll if there is one - $e107->sql->db_Delete('poll', 'poll_datestamp='.$threadId); + $sql->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_extended_id='.$k); + $sql->update('user_extended', 'user_plugin_forum_posts=GREATEST(user_plugin_forum_posts-'.$v.',0) WHERE user_extended_id='.$k); } } // delete all posts $qry = 'SELECT post_id FROM `#forum_post` WHERE post_thread = '.$threadId; - if($e107->sql->db_Select_gen($qry)) + if($sql->gen($qry)) { $postList = array(); - while($row = $e107->sql->db_Fetch(MYSQL_ASSOC)) + while($row = $sql->fetch(MYSQL_ASSOC)) { $postList[] = $row['post_id']; } @@ -1270,23 +1514,34 @@ class e107forum } // delete the thread itself - $e107->sql->db_Delete('forum_thread', 'thread_id='.$threadId); + if($sql->delete('forum_thread', 'thread_id='.$threadId)) + { + $status = true; + } //Delete any thread tracking - $e107->sql->db_Delete('forum_track', 'track_thread='.$threadId); + $sql->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']); + $sql->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']; + return $status; // - XXX should return true/false $threadInfo['thread_total_replies']; } } + + + /** + * Delete a Post + * @param $postId integer + * @param $updateCounts boolean + * + */ function postDelete($postId, $updateCounts = true) { $postId = (int)$postId; @@ -1295,7 +1550,7 @@ class e107forum { echo 'NOT FOUND!'; return; } - $row = $e107->sql->db_Fetch(MYSQL_ASSOC); + $row = $e107->sql->fetch(MYSQL_ASSOC); //delete attachments if they exist if($row['post_attachments']) @@ -1304,21 +1559,21 @@ class e107forum } // delete post - $e107->sql->db_Delete('forum_post', 'post_id='.$postId); + $e107->sql->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_extended_id='.$row['post_user']); + $e107->sql->update('user_extended', 'user_plugin_forum_posts=GREATEST(user_plugin_forum_posts-1,0) WHERE user_extended_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']); + $e107->sql->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']); + $e107->sql->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']); diff --git a/e107_plugins/forum/forum_conf.php b/e107_plugins/forum/forum_conf.php index c0e829280..e6b451f23 100644 --- a/e107_plugins/forum/forum_conf.php +++ b/e107_plugins/forum/forum_conf.php @@ -57,7 +57,8 @@ if(!in_array(USERID, array_keys($modList))) require_once(HEADERF); -if (isset($_POST['deletepollconfirm'])) { +if (isset($_POST['deletepollconfirm'])) +{ $sql->db_Delete("poll", "poll_id='".intval($thread_parent)."' "); $sql->db_Select("forum_t", "*", "thread_id='".$thread_id."' "); $row = $sql->db_Fetch(); @@ -135,14 +136,19 @@ if ($action == "delete_poll") if ($action == 'move') { $postInfo = $forum->postGet($id, 0, 1); - $text = " -
-
- - - - ') // Inject id into table row. //XXX Find a better way to do this without placing in template. . + { + $_TEMPLATE = "".substr($_TEMPLATE,4); + } + return $tp->simpleParse($_TEMPLATE, $tVars); } @@ -607,10 +619,15 @@ function parse_sub($subInfo) $lp_name = $subInfo['forum_lastpost_user_anon']; } $tVars->SUB_LASTPOST = $lp_date.'
'.$lp_name.' '.$lp_thread; + + $tVars->SUB_LASTPOSTDATE = $gen->computeLapse($tmp[0], time(), false, false, 'short'); + $tVars->SUB_LASTPOSTUSER = $lp_name; } else { $tVars->SUB_LASTPOST = '-'; + $tVars->SUB_LASTPOSTUSER = ''; + $tVars->SUB_LASTPOSTDATE = ''; } return $tp->simpleParse($FORUM_VIEW_SUB, $tVars); } @@ -643,11 +660,18 @@ function fadminoptions($thread_info) //FIXME - not fully working. - $moveUrl = $e107->url->create('forum/thread/move', "id=".$thread_info['thread_id']); + $moveUrl = $e107->url->create('forum/thread/move', "id=".$thread_info['thread_id']); + $lockUnlock = ($thread_info['thread_active'] ) ? 'lock' : 'unlock'; + $stickUnstick = ($thread_info['thread_sticky'] == 1) ? 'unstick' : 'stick'; + $id = intval($thread_info['thread_id']); + + $lan = array('stick'=>'Stick','unstick'=>'Unstick','lock'=>"Lock", 'unlock'=>"Unlock"); - $text .= "
  • Delete
  • "; - $text .= "
  • Stick/Unstick
  • "; - $text .= "
  • Lock/Unlock
  • "; + + $text .= "
  • Delete
  • "; + $text .= "
  • ".$lan[$stickUnstick]."
  • "; + $text .= "
  • ".$lan[$lockUnlock]."
  • "; + $text .= "
  • Move
  • "; /* @@ -659,7 +683,7 @@ function fadminoptions($thread_info) $text .= "
  • ".($thread_info['thread_active'] ? " Lock" : " Unlock"). "
  • "; - $text .= "
  • ".IMAGE_admin_move.' Move
  • '; + $text .= "
  • Move
  • "; */ $text .= ""; diff --git a/e107_plugins/forum/shortcodes/batch/post_shortcodes.php b/e107_plugins/forum/shortcodes/batch/post_shortcodes.php index 0f44248ee..8ebc8bce8 100644 --- a/e107_plugins/forum/shortcodes/batch/post_shortcodes.php +++ b/e107_plugins/forum/shortcodes/batch/post_shortcodes.php @@ -91,11 +91,11 @@ class plugin_forum_post_shortcodes extends e_shortcode $ret = " "; if ($action != 'nt') { - $ret .= ($eaction ? "" : ""); + $ret .= ($eaction ? "" : ""); } else { - $ret .= ($eaction ? "" : ""); + $ret .= ($eaction ? "" : ""); } return $ret; } diff --git a/e107_plugins/forum/templates/forum_post_template.php b/e107_plugins/forum/templates/forum_post_template.php index 1db03f98a..7eb7ef423 100644 --- a/e107_plugins/forum/templates/forum_post_template.php +++ b/e107_plugins/forum/templates/forum_post_template.php @@ -224,6 +224,48 @@ $THREADTOPIC_REPLY = " "; } + + +$FORUMPOST_TEMPLATE['form'] = " +
    +
    + {FORMSTART} +
    ".FORCONF_24.": - + + + */ + + $frm = e107::getForm(); + $qry = " SELECT f.forum_id, f.forum_name, fp.forum_name AS forum_parent, sp.forum_name AS sub_parent FROM `#forum` AS f @@ -152,16 +158,28 @@ if ($action == 'move') AND f.forum_id != ".(int)$threadInfo['thread_forum_id']." ORDER BY f.forum_parent ASC, f.forum_sub, f.forum_order ASC "; - $e107->sql->db_Select_gen($qry); - $fList = $e107->sql->db_getList(); + + $sql->gen($qry); + $fList = $sql->db_getList(); + + + $text = " + +
    + + + + - - - - + +
    ".FORCONF_24.": +

    - ".FORCONF_32."
    - ".FORCONF_28."
    - ".FORCONF_29.' ['.FORCONF_27.'] '.FORCONF_30."
    - ".FORCONF_31." -

    - - -
    ".FORCONF_32."
    + ".$frm->radio('rename_thread','none',true, 'label='.FORCONF_28)." + ".$frm->radio('rename_thread', 'add', false, array('label'=> FORCONF_29.' ['.FORCONF_27.'] '.FORCONF_30)). " +
    ".$frm->radio('rename_thread','rename', false, array('label'=>FORCONF_31))." + ".$frm->text('newtitle', $tp->toForm($threadInfo['thread_name']), 250)." +
    +
    +
    + +
    -
    "; - $text = $e107->ns->tablerender($e107->tp->toHTML($threadInfo['thread_name']), $e107->tp->toHTML($postInfo[0]['post_entry']), '', true).$ns->tablerender('', $text, '', true); - $e107->ns->tablerender(FORCONF_25, $text); + +
    + "; + + $ns = e107::getRender(); + $tp = e107::getParser(); + + $threadName = $tp->toHTML($threadInfo['thread_name'], true); + $threadText = $tp->toHTML($postInfo[0]['post_entry'], true); + + $text .= "

    ".$threadName."

    ".$threadText."
    "; // $e107->ns->tablerender(, ), '', true).$ns->tablerender('', $text, '', true); + $ns->tablerender(FORCONF_25, $text); } require_once(FOOTERF); diff --git a/e107_plugins/forum/forum_viewforum.php b/e107_plugins/forum/forum_viewforum.php index d1a7c659e..5dfc7bdc8 100644 --- a/e107_plugins/forum/forum_viewforum.php +++ b/e107_plugins/forum/forum_viewforum.php @@ -22,6 +22,11 @@ if (!$e107->isInstalled('forum')) } include_lan(e_PLUGIN.'forum/languages/'.e_LANGUAGE.'/lan_forum_viewforum.php'); + + + + + if (isset($_POST['fjsubmit'])) { // TODO - load from DB and find forum_name @@ -558,6 +563,13 @@ function parse_thread($thread_info) $_TEMPLATE = $FORUM_VIEW_FORUM; break; } + + + if(substr($_TEMPLATE,0,4) == '
    + + + + {USERBOX} + {SUBJECTBOX} + + + + + {POLL} + {FILEATTACH} + + + + +
    {BACKLINK} +
    {POSTTYPE} + {POSTBOX}
    + {EMAILNOTIFY}
    + {NOEMOTES}
    + {POSTTHREADAS} +
    + {BUTTONS} +
    + {FORMEND} + +
    +"; +$FORUMPOST_TEMPLATE['reply'] = ""; + + +$FORUMPOST = $FORUMPOST_TEMPLATE['form']; + + + $FORUM_CRUMB['sitename']['value'] = "{SITENAME}"; $FORUM_CRUMB['sitename']['sep'] = " :: "; diff --git a/e107_plugins/forum/templates/forum_viewforum_template.php b/e107_plugins/forum/templates/forum_viewforum_template.php index 373148190..a6d8c70e7 100644 --- a/e107_plugins/forum/templates/forum_viewforum_template.php +++ b/e107_plugins/forum/templates/forum_viewforum_template.php @@ -295,7 +295,7 @@ $FORUMVIEW_TEMPLATE['header'] = "
    {THREADNAME}\n"; $FORUMVIEW_TEMPLATE['item-announce'] = $FORUMVIEW['item'] ; // "{THREADNAME}\n"; @@ -305,7 +305,7 @@ $FORUMVIEW_TEMPLATE['sub-item'] = "{NEWFLAG}
    {SUB_FORUMTITLE}
    {SUB_DESCRIPTION} {SUB_REPLIESX} {SUB_THREADSX} - {SUB_LASTPOST} + {SUB_LASTPOSTUSER} {SUB_LASTPOSTDATE} \n"; $FORUMVIEW_TEMPLATE['sub-footer'] = ""; diff --git a/e107_plugins/forum/templates/forum_viewtopic_template.php b/e107_plugins/forum/templates/forum_viewtopic_template.php index 532e03f96..6530b2a4b 100644 --- a/e107_plugins/forum/templates/forum_viewtopic_template.php +++ b/e107_plugins/forum/templates/forum_viewtopic_template.php @@ -376,11 +376,9 @@ $FORUMTOPIC_TEMPLATE['thread'] =" -
    - {TOP=caret} -
    +   - + {ATTACHMENTS} {LASTEDIT}{LASTEDITBY=link} {SIGNATURE}