From 3a367901e12df0f08a4ff7043fd15b23d06daa7f Mon Sep 17 00:00:00 2001 From: mcfly Date: Tue, 8 Sep 2009 02:00:48 +0000 Subject: [PATCH] Reverting code back, home it works. --- e107_plugins/forum/classes/forumClass.php | 1263 -------------------- e107_plugins/forum/classes/forumPost.php | 72 -- e107_plugins/forum/classes/forumThread.php | 306 ----- e107_plugins/forum/forum.php | 11 +- e107_plugins/forum/forum_class.php | 134 +-- e107_plugins/forum/forum_post.php | 8 +- e107_plugins/forum/forum_shortcodes.php | 55 +- e107_plugins/forum/forum_viewforum.php | 8 +- e107_plugins/forum/forum_viewtopic.php | 350 +++++- 9 files changed, 391 insertions(+), 1816 deletions(-) delete mode 100644 e107_plugins/forum/classes/forumClass.php delete mode 100644 e107_plugins/forum/classes/forumPost.php delete mode 100644 e107_plugins/forum/classes/forumThread.php diff --git a/e107_plugins/forum/classes/forumClass.php b/e107_plugins/forum/classes/forumClass.php deleted file mode 100644 index d3fede93f..000000000 --- a/e107_plugins/forum/classes/forumClass.php +++ /dev/null @@ -1,1263 +0,0 @@ -e107 = e107::getInstance(); - $this->loadPermList(); - $this->fieldTypes['forum_post']['post_user'] = 'int'; - $this->fieldTypes['forum_post']['post_forum'] = 'int'; - $this->fieldTypes['forum_post']['post_datestamp'] = 'int'; - $this->fieldTypes['forum_post']['post_edit_datestamp'] = 'int'; - $this->fieldTypes['forum_post']['post_edit_user'] = 'int'; - $this->fieldTypes['forum_post']['post_thread'] = 'int'; - $this->fieldTypes['forum_post']['post_options'] = 'escape'; - $this->fieldTypes['forum_post']['post_attachments'] = 'escape'; - - $this->fieldTypes['forum_thread']['thread_user'] = 'int'; - $this->fieldTypes['forum_thread']['thread_lastpost'] = 'int'; - $this->fieldTypes['forum_thread']['thread_lastuser'] = 'int'; - $this->fieldTypes['forum_thread']['thread_sticky'] = 'int'; - $this->fieldTypes['forum_thread']['thread_forum_id'] = 'int'; - $this->fieldTypes['forum_thread']['thread_active'] = 'int'; - $this->fieldTypes['forum_thread']['thread_datestamp'] = 'int'; - $this->fieldTypes['forum_thread']['thread_views'] = 'int'; - $this->fieldTypes['forum_thread']['thread_replies'] = 'int'; - $this->fieldTypes['forum_thread']['thread_options'] = 'escape'; - - $this->fieldTypes['forum']['forum_lastpost_user'] = 'int'; - } - - function loadPermList() - { -// var_dump($this->e107); - if($tmp = $this->e107->ecache->retrieve_sys('forum_perms')) - { - $this->permList = $e107->arrayStorage->ReadArray($tmp); - } - else - { - $this->getForumPermList(); - $tmp = $this->e107->arrayStorage->WriteArray($this->permList, false); - $this->e107->ecache->set_sys('forum_perms', $tmp); - - } - unset($tmp); - } - - - function getForumPermList() - { - $this->permList = array(); - $qryList = array(); - - $qryList['view'] = " - SELECT f.forum_id - FROM `#forum` AS f - LEFT JOIN `#forum` AS fp ON f.forum_parent = fp.forum_id AND fp.forum_class IN (".USERCLASS_LIST.") - WHERE f.forum_class IN (".USERCLASS_LIST.") AND f.forum_parent != 0 AND fp.forum_id IS NOT NULL - "; - - $qryList['post'] = " - SELECT f.forum_id - FROM `#forum` AS f - LEFT JOIN `#forum` AS fp ON f.forum_parent = fp.forum_id AND fp.forum_postclass IN (".USERCLASS_LIST.") - WHERE f.forum_postclass IN (".USERCLASS_LIST.") AND f.forum_parent != 0 AND fp.forum_id IS NOT NULL - "; - - $qryList['thread'] = " - SELECT f.forum_id - FROM `#forum` AS f - LEFT JOIN `#forum` AS fp ON f.forum_parent = fp.forum_id AND fp.forum_threadclass IN (".USERCLASS_LIST.") - WHERE f.forum_threadclass IN (".USERCLASS_LIST.") AND f.forum_parent != 0 AND fp.forum_id IS NOT NULL - "; - - foreach($qryList as $key => $qry) - { - if($this->e107->sql->db_Select_gen($qry)) - { - while($row = $this->e107->sql->db_Fetch()) - { - $this->permList[$key][] = $row['forum_id']; - } - } - } - } - - /** - * Test for forum permissions. - * - * 'view' - user is able to view forumId - * 'post' - user is able to create new post in forumId - * 'thread' - user is able to create new thread in forumId - * - * @param integer $forumId - * @param string $type (view, post, thread) - * @return boolean - */ - function checkPerm($forumId, $type='view') - { - return (in_array($forumId, $this->permList[$type])); - } - - public function threadNew($threadId=false) - { - $this->thread = new plugin_forum_classes_forumThread($threadId, $this); - } - - /** - * Check to see of thread has been viewed by current user - * - * - * @param integer $threadId - * @return boolean - */ - function threadViewed($threadId) - { - if(!$this->userViewed) - { - if(isset($this->e107->currentUser['user_plugin_forum_viewed'])) - { - $this->userViewed = explode(',', $this->e107->currentUser['user_plugin_forum_viewed']); - } - } - return (is_array($this->userViewed) && in_array($threadId, $this->userViewed)); - } - - function getTrackedThreadList($id, $retType = 'array') - { - $id = (int)$id; - if($this->e107->sql->db_Select('forum_track', 'track_thread', 'track_userid = '.$id)) - { - while($row = $this->e107->sql->db_Fetch()) - { - $ret[] = $row['track_thread']; - } - return ($retType == 'array' ? $ret : implode(',', $ret)); - } - return false; - } - - /* - * Add a post to the db. - * - * If threadinfo is given, then we're adding a new thread. - * We must get thread_id to provide to postInfo after insertion - */ - function postAdd($postInfo, $updateThread = true, $updateForum = true) - { - //Future option, will just set to true here - $addUserPostCount = true; - $result = false; - - $info = array(); - $info['_FIELD_TYPES'] = $this->fieldTypes['forum_post']; - $info['data'] = $postInfo; - $postId = $this->e107->sql->db_Insert('forum_post', $info); - $forumInfo = array(); - - if($postId && $updateThread) - { - $threadInfo = array(); - if(varset($postInfo['post_user'])) - { - $threadInfo['thread_lastuser'] = $postInfo['post_user']; - $threadInfo['thread_lastuser_anon'] = '_NULL_'; - $forumInfo['forum_lastpost_user'] = $postInfo['post_user']; - $forumInfo['forum_lastpost_user_anon'] = '_NULL_'; - } - else - { - $threadInfo['thread_lastuser'] = 0; - $threadInfo['thread_lastuser_anon'] = $postInfo['post_user_anon']; - $forumInfo['forum_lastpost_user'] = 0; - $forumInfo['forum_lastpost_user_anon'] = $postInfo['post_user_anon']; - } - $threadInfo['thread_lastpost'] = $postInfo['post_datestamp']; - $threadInfo['thread_total_replies'] = 'thread_total_replies + 1'; - - $info = array(); - $info['data'] = $threadInfo; - $info['WHERE'] = 'thread_id = '.$postInfo['post_thread']; - $info['_FIELD_TYPES'] = $this->fieldTypes['forum_thread']; - $info['_FIELD_TYPES']['thread_total_replies'] = 'cmd'; - - $result = $this->e107->sql->db_Update('forum_thread', $info); - - } - - if(($result || !$updateThread) && $updateForum) - { - if(varset($postInfo['post_user'])) - { - $forumInfo['forum_lastpost_user'] = $postInfo['post_user']; - $forumInfo['forum_lastpost_user_anon'] = '_NULL_'; - } - else - { - $forumInfo['forum_lastpost_user'] = 0; - $forumInfo['forum_lastpost_user_anon'] = $postInfo['post_user_anon']; - } - - $info = array(); - //If we update the thread, then we assume it was a reply, otherwise we've added a reply only. - $info['_FIELD_TYPES'] = $this->fieldTypes['forum']; - if($updateThread) - { - $forumInfo['forum_replies'] = 'forum_replies+1'; - $info['_FIELD_TYPES']['forum_replies'] = 'cmd'; - } - else - { - $forumInfo['forum_threads'] = 'forum_threads+1'; - $info['_FIELD_TYPES']['forum_threads'] = 'cmd'; - } - $info['data'] = $forumInfo; - $info['data']['forum_lastpost_info'] = $postInfo['post_datestamp'].'.'.$postInfo['post_thread']; - $info['WHERE'] = 'forum_id = '.$postInfo['post_forum']; - $result = $this->e107->sql->db_Update('forum', $info); - } - - if($result && USER && $addUserPostCount) - { - $qry = ' - INSERT INTO `#user_extended` (user_extended_id, user_plugin_forum_posts) - VALUES ('.USERID.', 1) - ON DUPLICATE KEY UPDATE user_plugin_forum_posts = user_plugin_forum_posts + 1 - '; - $result = $this->e107->sql->db_Select_gen($qry); - } - return $postId; - } - - function threadAdd($threadInfo, $postInfo) - { - $info = array(); - $info['_FIELD_TYPES'] = $this->fieldTypes['forum_thread']; - $info['data'] = $threadInfo; - if($newThreadId = $this->e107->sql->db_Insert('forum_thread', $info)) - { - $postInfo['post_thread'] = $newThreadId; - $newPostId = $this->postAdd($postInfo, false); - $this->threadMarkAsRead($newThreadId); - return array('postid' => $newPostId, 'threadid' => $newThreadId); - } - return false; - } - - function threadUpdate($threadId, $threadInfo) - { - $info = array(); - $info['data'] = $threadInfo; - $info['_FIELD_TYPES'] = $this->fieldTypes['forum_thread']; - $info['WHERE'] = 'thread_id = '.(int)$threadId; - $this->e107->sql->db_Update('forum_thread', $info); - } - - function postUpdate($postId, $postInfo) - { - $info = array(); - $info['data'] = $postInfo; - $info['_FIELD_TYPES'] = $this->fieldTypes['forum_post']; - $info['WHERE'] = 'post_id = '.(int)$postId; - $this->e107->sql->db_Update('forum_post', $info); - } - - - - - function threadGetUserPostcount($threadId) - { - $threadId = (int)$threadId; - $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($this->e107->sql->db_Select_gen($qry)) - { - $ret = array(); - while($row = $this->e107->sql->db_Fetch()) - { - $ret[$row['post_user']] = $row['post_count']; - } - } - return $ret; - } - - function threadGetUserViewed($uid = USERID) - { - if($uid == USERID) - { - $viewed = $this->e107->currentUser['user_plugin_forum_viewed']; - } - else - { - $tmp = get_user_data($uid); - $viewed = $tmp['user_plugin_forum_viewed']; - unset($tmp); - } - return explode(',', $viewed); - } - - function postDeleteAttachments($type = 'post', $id='', $f='') - { - $e107 = e107::getInstance(); - $id = (int)$id; - if(!$id) { return; } - if($type == 'thread') - { - if(!$e107->sql->db_Select('forum_post', 'post_id', 'post_attachments IS NOT NULL')) - { - return true; - } - $postList = array(); - while($row = $e107->sql->dbFetch(MYSQL_ASSOC)) - { - $postList[] = $row['post_id']; - } - foreach($postList as $postId) - { - $this->postDeleteAttachment('post', $postId); - } - } - if($type == 'post') - { - if(!$e107->sql->db_Select('forum_post', 'post_attachments', 'post_id = '.$id)) - { - return true; - } - $tmp = $e107->sql->db_Fetch(MYSQL_ASSOC); - $attachments = explode(',', $tmp['post_attachments']); - foreach($attachments as $k => $a) - { - $info = explode('*', $a); - if('' == $f || $info[1] == $f) - { - $fname = e_PLUGIN."forum/attachments/{$info[1]}"; - @unlink($fname); - - //If attachment is an image and there is a thumb, remove it - if('img' == $info[0] && $info[2]) - { - $fname = e_PLUGIN."forum/attachments/thumb/{$info[2]}"; - @unlink($fname); - } - } - unset($attachments[$k]); - } - $tmp = array(); - if(count($attachments)) - { - $tmp['post_attachments'] = implode(',', $attachments); - } - else - { - $tmp['post_attachments'] = '_NULL_'; - } - $info = array(); - $info['data'] = $tmp; - $info['_FILE_TYPES']['post_attachments'] = 'escape'; - $info['WHERE'] = 'post_id = '.$id; - $e107->sql->db_update('forum_post', $info); - } - } - - /** - * Given threadId and postId, determine which number of post in thread the postid is - * - */ - function postGetPostNum($threadId, $postId) - { - $threadId = (int)$threadId; - $postId = (int)$postId; - $e107 = e107::getInstance(); - 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; - $sql2 = new db; - if ($type == 'thread') - { - $id = (int)$id; - $lpInfo = $this->threadGetLastpost($id); - $tmp = array(); - if($lpInfo['user_name']) - { - $tmp['thread_lastuser'] = $lpInfo['post_user']; - $tmp['thread_lastuser_anon'] = '_NULL_'; - } - else - { - $tmp['thread_lastuser'] = 0; - $tmp['thread_lastuser_anon'] = ($lpInfo['post_user_anon'] ? $lpInfo['post_user_anon'] : 'Anonymous'); - } - $tmp['thread_lastpost'] = $lpInfo['post_datestamp']; - $info = array(); - $info['data'] = $tmp; - $info['_FIELD_TYPES'] = $this->fieldTypes['forum_thread']; - $info['WHERE'] = 'thread_id = '.$id; - $sql->db_Update('forum_thread', $info); - - return $lpInfo; - } - if ($type == 'forum') - { - if ($id == 'all') - { - if ($sql->db_Select('forum', 'forum_id', 'forum_parent != 0')) - { - while ($row = $sql->db_Fetch()) - { - $parentList[] = $row['forum_id']; - } - foreach($parentList as $id) - { - set_time_limit(60); - $this->forumUpdateLastpost('forum', $id, $updateThreads); - } - } - } - else - { - $id = (int)$id; - $lp_info = ''; - $lp_user = 'NULL'; - if($updateThreads == true) - { - if ($sql2->db_Select('forum_t', 'thread_id', "thread_forum_id = $id AND thread_parent = 0")) - { - while ($row = $sql2->db_Fetch(MYSQL_ASSOC)) - { - set_time_limit(60); - $this->forumUpdateLastpost('thread', $row['thread_id']); - } - } - } - 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); - $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); - } - } - } - } - - function forumMarkAsRead($forum_id) - { - $e107 = e107::getInstance(); - $extra = ''; - $newIdList = array(); - if ($forum_id !== 0) - { - $forum_id = (int)$forum_id; - $flist = array(); - $flist[] = $forum_id; - if($subList = $this->forumGetSubs($forum_id)) - { - foreach($subList as $sub) - { - $flist[] = $sub['forum_id']; - } - } - $forumList = implode(',', $flist); - $extra = " AND thread_forum_id IN($forumList)"; - } - $qry = 'thread_lastpost > '.USERLV.$extra; - - if ($e107->sql->db_Select('forum_thread', 'thread_id', $qry)) - { - while ($row = $e107->sql->db_Fetch(MYSQL_ASSOC)) - { - $newIdList[] = $row['thread_id']; - } - if(count($newIdList)) - { - $this->threadMarkAsRead($newIdList); - } - } - header('location:'.e_SELF); - exit; - } - - function threadMarkAsRead($threadId) - { - global $currentUser; - $e107 = e107::getInstance(); - $_tmp = preg_split('#\,+#', $currentUser['user_plugin_forum_viewed']); - if(!is_array($threadId)) { $threadId = array($threadId); } - foreach($threadId as $tid) - { - $_tmp[] = (int)$tid; - } - $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); - } - - 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)) { - $ret[] = $row; - } - return $ret; - } - return FALSE; - } - - function forumGetMods($uclass = e_UC_ADMIN, $force=false) - { - if(count($this->modArray) && !$force) - { - return $this->modArray; - } - 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)) - { - $this->modArray[$row['user_id']] = $row['user_name']; - } - } - else - { - $this->modArray = $this->e107->user_class->get_users_in_class($uclass, 'user_name', true); - } - return $this->modArray; - } - - function isModerator($uid) - { - return ($uid && in_array($uid, array_keys($this->modArray))); - } - - function forumGetForumList() - { - $e107 = e107::getInstance(); - $qry = ' - SELECT f.*, u.user_name FROM `#forum` AS f - LEFT JOIN `#user` AS u ON f.forum_lastpost_user IS NOT NULL AND u.user_id = f.forum_lastpost_user - ORDER BY f.forum_order ASC - '; - if ($e107->sql->db_Select_gen($qry)) - { - $ret = array(); - while ($row = $e107->sql->db_Fetch(MYSQL_ASSOC)) - { - if(!$row['forum_parent']) - { - $ret['parents'][] = $row; - } - elseif($row['forum_sub']) - { -// $ret['subs'][$row['forum_parent']][$row['forum_sub']][] = $row; - $ret['subs'][$row['forum_sub']][] = $row; - } - else - { - $ret['forums'][$row['forum_parent']][] = $row; - } - } - return $ret; - } - return false; - } - - function forum_getforums($type = 'all') - { - global $sql; - $qry = " - SELECT f.*, u.user_name FROM #forum AS f - LEFT JOIN #user AS u ON SUBSTRING_INDEX(f.forum_lastpost_user,'.',1) = u.user_id - WHERE forum_parent != 0 AND forum_sub = 0 - ORDER BY f.forum_order ASC - "; - if ($sql->db_Select_gen($qry)) - { - while ($row = $sql->db_Fetch(MYSQL_ASSOC)) - { - if($type == 'all') - { - $ret[$row['forum_parent']][] = $row; - } - else - { - $ret[] = $row; - } - } - return $ret; - } - return FALSE; - } - - function forumGetSubs($forum_id = '') - { - global $sql; - $where = ($forum_id != '' && $forum_id != 'bysub' ? 'AND forum_sub = '.(int)$forum_id : ''); - $qry = " - SELECT f.*, u.user_name FROM `#forum` AS f - LEFT JOIN `#user` AS u ON f.forum_lastpost_user = u.user_id - WHERE forum_sub != 0 {$where} - ORDER BY f.forum_order ASC - "; - if ($sql->db_Select_gen($qry)) - { - while ($row = $sql->db_Fetch(MYSQL_ASSOC)) - { - if($forum_id == '') - { - $ret[$row['forum_parent']][$row['forum_sub']][] = $row; - } - elseif($forum_id == 'bysub') - { - $ret[$row['forum_sub']][] = $row; - } - else - { - $ret[] = $row; - } - } - return $ret; - } - return false; - } - - /** - * List of forums with unread threads - * - * Get a list of forum IDs that have unread threads. - * If a forum is a subforum, also ensure the parent is in the list. - * - * @return type description - * @access public - */ - function forumGetUnreadForums() - { - if (!USER) {return false; } // Can't determine new threads for non-logged in users - $e107 = e107::getInstance(); - $viewed = ''; - - if($e107->currentUser['user_plugin_forum_viewed']) - { - $viewed = " AND thread_id NOT IN (".$e107->currentUser['user_plugin_forum_viewed'].")"; - } - - $_newqry = ' - 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)) - { - while($row = $e107->sql->db_Fetch(MYSQL_ASSOC)) - { - $ret[] = $row['thread_forum_id']; - if($row['forum_sub']) - { - $ret[] = $row['forum_sub']; - } - } - return $ret; - } - else - { - return false; - } - } - - function thread_user($post_info) - { - if($post_info['user_name']) - { - return $post_info['user_name']; - } - else - { - $tmp = explode(".", $post_info['thread_user'], 2); - return $tmp[1]; - } - } - - function track($which, $uid, $threadId, $force=false) - { - $e107 = e107::getInstance(); - global $pref; - - if (!varsettrue($pref['forum_track']) && !$force) { return false; } - - $threadId = (int)$threadId; - $uid = (int)$uid; - $result = false; - switch($which) - { - case 'add': - $tmp = array(); - $tmp['data']['track_userid'] = $uid; - $tmp['data']['track_thread'] = $threadId; - $result = $e107->sql->db_Insert('forum_track', $tmp); - unset($tmp); - break; - - case 'delete': - case 'del': - $result = $e107->sql->db_Delete('forum_track', "`track_userid` = {$uid} AND `track_thread` = {$threadId}"); - break; - - case 'check': - $result = $e107->sql->db_Count('forum_track', '(*)', "WHERE `track_userid` = {$uid} AND `track_thread` = {$threadId}"); - break; - } - return $result; - } - - function forum_get($forum_id) - { - $forum_id = (int)$forum_id; - $qry = " - SELECT f.*, fp.forum_class as parent_class, fp.forum_name as parent_name, fp.forum_id as parent_id, fp.forum_postclass as parent_postclass, sp.forum_name AS sub_parent FROM #forum AS f - LEFT JOIN #forum AS fp ON fp.forum_id = f.forum_parent - LEFT JOIN #forum AS sp ON f.forum_sub = sp.forum_id AND f.forum_sub > 0 - WHERE f.forum_id = {$forum_id} - "; - global $sql; - if ($sql->db_Select_gen($qry)) - { - return $sql->db_Fetch(MYSQL_ASSOC); - } - return FALSE; - } - - function forumGetAllowed($type='view') - { - global $sql; - $forumList = implode(',', $this->permList[$type]); - $qry = " - SELECT forum_id, forum_name FROM `#forum` - WHERE forum_id IN ({$forumList}) - "; - if ($sql->db_Select_gen($qry)) - { - while($row = $sql->db_Fetch(MYSQL_ASSOC)) - { - $ret[$row['forum_id']] = $row['forum_name']; - } - - } - return $ret; - } - - function forumGetThreads($forumId, $from, $view) - { - $forumId = (int)$forumId; - $from = (int)$from; - $view = (int)$view; - - $qry = " - SELECT t.*, u.user_name, lpu.user_name AS lastpost_username from `#forum_thread` as t - LEFT JOIN `#user` AS u ON t.thread_user = u.user_id - LEFT JOIN `#user` AS lpu ON t.thread_lastuser = lpu.user_id - WHERE t.thread_forum_id = {$forumId} - ORDER BY - t.thread_sticky DESC, - t.thread_lastpost DESC - LIMIT {$from},{$view}"; - - $this->threadList = array(); - if ($this->e107->sql->db_Select_gen($qry)) - { - while ($row = $this->e107->sql->db_Fetch()) - { - $this->threadList = $row; - } - return true; - } - return false; - } - - function threadGetLastpost($id) - { - $e107 = e107::getInstance(); - $id = (int)$id; - $qry = " - SELECT p.post_user, p.post_user_anon, p.post_datestamp, p.post_thread, u.user_name FROM `#forum_post` AS p - LEFT JOIN `#user` AS u ON u.user_id = p.post_user - WHERE p.post_thread = {$id} - ORDER BY p.post_datestamp DESC LIMIT 0,1 - "; - if ($e107->sql->db_Select_gen($qry)) - { - return $e107->sql->db_Fetch(MYSQL_ASSOC); - } - return false; - } - -// function forum_get_topic_count($forum_id) -// { -// $e107 = e107::getInstance(); -// 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
"; -// return; - $e107 = e107::getInstance(); - $threadId = (int)$threadId; - $forumId = (int)$forumId; - $lastpost = (int)$lastpost; - - if($which == 'next') - { - $dir = '<'; - $sort = 'ASC'; - } - else - { - $dir = '>'; - $sort = 'DESC'; - } - - $qry = " - SELECT thread_id from `#forum_thread` - WHERE thread_forum_id = $forumId - AND thread_lastpost {$dir} $lastpost - ORDER BY - thread_sticky DESC, - thread_lastpost {$sort} - LIMIT 1"; - if ($e107->sql->db_Select_gen($qry)) - { - $row = $e107->sql->db_Fetch(); - return $row['thread_id']; - - } - return false; - } - - - function _forum_lp_update($lp_type, $lp_user, $lp_info, $lp_forum_id, $lp_forum_sub) - { - global $sql; - $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)."' "); - 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)."' "); - } - } - - - function threadGetNew($count = 50, $unread = true, $uid = USERID) - { - $e107 = e107::getInstance(); - $viewed = ''; - if($unread) - { - $viewed = implode(',', $this->threadGetUserViewed($uid)); - if($viewed != '') - { - $viewed = ' AND p.post_forum NOT IN ('.$viewed.')'; - } - } - - $qry = " - SELECT ft.*, fp.thread_name as post_subject, fp.thread_total_replies as replies, u.user_id, u.user_name, f.forum_class - FROM #forum_t AS ft - LEFT JOIN #forum_t as fp ON fp.thread_id = ft.thread_parent - LEFT JOIN #user as u ON u.user_id = SUBSTRING_INDEX(ft.thread_user,'.',1) - LEFT JOIN #forum as f ON f.forum_id = ft.thread_forum_id - WHERE ft.thread_datestamp > ".USERLV. " - AND f.forum_class IN (".USERCLASS_LIST.") - {$viewed} - ORDER BY ft.thread_datestamp DESC LIMIT 0, ".intval($count); - - $qry = " - SELECT t.*, u.user_name FROM `#forum_thread` AS t - LEFT JOIN `#user` AS u ON u.user_id = t.thread_lastuser - WHERE t.thread_lastpost > ".USERLV. " - {$viewed} - ORDER BY t.thread_lastpost DESC LIMIT 0, ".(int)$count; - - - if($e107->sql->db_Select_gen($qry)) - { - $ret = $e107->sql->db_getList(); - } - return $ret; - } - - function forumPrune($type, $days, $forumArray) - { - $e107 = e107::getInstance(); - $prunedate = time() - (int)$days * 86400; - $forumList = implode(',', $forumArray); - - if($type == 'delete') - { - //Get list of threads to prune - if ($e107->sql->db_Select('forum_thread', 'thread_id', "thread_lastpost < {$prunedate} AND thread_sticky != 1 AND thread_forum_id IN ({$forumList})")) - { - $threadList = $e107->sql->db_getList(); - foreach($threadList as $thread) - { - $this->threadDelete($thread['thread_id'], false); - } - foreach($forumArray as $fid) - { - $this->forumUpdateLastpost('forum', $fid); - $this->forumUpdateCounts($fid); - } - return FORLAN_8." ( ".$thread_count." ".FORLAN_92.", ".$reply_count." ".FORLAN_93." )"; - } - else - { - return FORLAN_9; - } - } - if($type == 'make_inactive') - { - $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 forumUpdateCounts($forumId, $recalcThreads = false) - { - $e107 = e107::getInstance(); - if($forumId == 'all') - { - $e107->sql->db_Select('forum', 'forum_id', 'forum_parent != 0'); - $flist = $e107->sql->db_getList(); - foreach($flist as $f) - { - set_time_limit(60); - $this->forumUpdateCounts($f['forum_id'], $recalcThreads); - } - return; - } - $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($recalcThreads == true) - { - set_time_limit(60); - $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['post_thread']; - $replies = (int)$t['replies']; - $e107->sql->db_Update('forum_thread', "thread_total_replies={$replies} WHERE thread_id={$tid}"); - } - } - } - - function getUserCounts() - { - global $sql; - $qry = " - SELECT post_user, count(post_user) AS cnt FROM `#forum_post` - WHERE post_user > 0 - GROUP BY post_user - "; - - if($sql->db_Select_gen($qry)) - { - $ret = array(); - while($row = $sql->db_Fetch(MYSQL_ASSOC)) - { - $ret[$row['post_user']] = $row['cnt']; - } - return $ret; - } - return FALSE; - } - - /* - * set bread crumb - * $forum_href override ONLY applies when template is missing FORUM_CRUMB - * $thread_title is needed for post-related breadcrumbs - */ - function set_crumb($forum_href=false, $thread_title='') - { - $e107 = e107::getInstance(); - global $FORUM_CRUMB, $forumInfo, $thread; - global $BREADCRUMB,$BACKLINK; // Eventually we should deprecate BACKLINK - - if(!$forumInfo) { $forumInfo = $thread->threadInfo; } -// var_dump($forumInfo); -// var_dump($thread); - - if(is_array($FORUM_CRUMB)) - { - $search = array('{SITENAME}', '{SITENAME_HREF}'); - $replace = array(SITENAME, "href='".$e107->url->getUrl('core:core', 'main', 'action=index')."'"); - $FORUM_CRUMB['sitename']['value'] = str_replace($search, $replace, $FORUM_CRUMB['sitename']['value']); - - $search = array('{FORUMS_TITLE}', '{FORUMS_HREF}'); - $replace = array(LAN_01, "href='".$e107->url->getUrl('forum', 'forum', 'func=main')."'"); - $FORUM_CRUMB['forums']['value'] = str_replace($search, $replace, $FORUM_CRUMB['forums']['value']); - - $search = '{PARENT_TITLE}'; - $replace = $e107->tp->toHTML($forumInfo['parent_name']); - $FORUM_CRUMB['parent']['value'] = str_replace($search, $replace, $FORUM_CRUMB['parent']['value']); - - if($forum_info['forum_sub']) - { - $search = array('{SUBPARENT_TITLE}', '{SUBPARENT_HREF}'); - $replace = array(ltrim($forumInfo['sub_parent'], '*'), "href='".$e107->url->getUrl('forum', 'forum', "func=view&id={$forumInfo['forum_sub']}")."'"); - $FORUM_CRUMB['subparent']['value'] = str_replace($search, $replace, $FORUM_CRUMB['subparent']['value']); - } - else - { - $FORUM_CRUMB['subparent']['value'] = ''; - } - - $search = array('{FORUM_TITLE}', '{FORUM_HREF}'); - $replace = array(ltrim($forumInfo['forum_name'], '*'),"href='".$e107->url->getUrl('forum', 'forum', "func=view&id={$forumInfo['forum_id']}")."'"); - $FORUM_CRUMB['forum']['value'] = str_replace($search, $replace, $FORUM_CRUMB['forum']['value']); - - $search = array('{THREAD_TITLE}'); - $replace = array($thread->threadInfo['thread_name']); - $FORUM_CRUMB['thread']['value'] = str_replace($search, $replace, $FORUM_CRUMB['thread']['value']); - - $FORUM_CRUMB['fieldlist'] = 'sitename,forums,parent,subparent,forum,thread'; - $BREADCRUMB = $e107->tp->parseTemplate('{BREADCRUMB=FORUM_CRUMB}', true); - } - else - { - $dfltsep = ' :: '; - $BREADCRUMB = "".SITENAME."".$dfltsep."".LAN_01."".$dfltsep; - if($forum_info['sub_parent']) - { - $forum_sub_parent = (substr($forum_info['sub_parent'], 0, 1) == '*' ? substr($forum_info['sub_parent'], 1) : $forum_info['sub_parent']); - $BREADCRUMB .= "{$forum_sub_parent}".$dfltsep; - } - - $tmpFname = $forum_info['forum_name']; - if(substr($tmpFname, 0, 1) == "*") { $tmpFname = substr($tmpFname, 1); } - if ($forum_href) - { - $BREADCRUMB .= "".$tp->toHTML($tmpFname, TRUE, 'no_hook,emotes_off').""; - } else - { - $BREADCRUMB .= $tmpFname; - } - - if(strlen($thread_title)) - { - $BREADCRUMB .= $dfltsep.$thread_title; - } - } - $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; - if(!$e107->sql->db_Select('forum_post', 'post_user, post_forum, post_thread', 'post_id = '.$postId)) - { - echo 'NOT FOUND!'; return; - } - $row = $this->e107->sql->db_Fetch(); - - //delete attachments if they exist - if($row['post_attachments']) - { - $this->postDeleteAttachments('post', $postId); - } - - // delete post - $this->e107->sql->db_Delete('forum_post', 'post_id='.$postId); - - if($updateCounts) - { - //decrement user post counts - if ($row['post_user']) - { - $this->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 - $this->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 - $this->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']; - } - -} - - -/** -* @return string path to and filename of forum icon image -* -* @param string $filename filename of forum image -* @param string $eMLANG_folder if specified, indicates its a multilanguage image being processed and -* gives the subfolder of the image path to the eMLANG_path() function, -* default = FALSE -* @param string $eMLANG_pref if specified, indicates that $filename may be overridden by the -* $pref with $eMLANG_pref as its key if that pref is TRUE, default = FALSE -* -* @desc checks for the existence of a forum icon image in the themes forum folder and if it is found -* returns the path and filename of that file, otherwise it returns the path and filename of the -* default forum icon image in e_IMAGES. The additional $eMLANG args if specfied switch the process -* to the sister multi-language function eMLANG_path(). -* -* @access public -*/ -function img_path($filename) -{ - global $pref; - - $multilang = array('reply.png','newthread.png','moderator.png','main_admin.png','admin.png'); - $ML = (in_array($filename,$multilang)) ? TRUE : FALSE; - - if(file_exists(THEME.'forum/'.$filename) || is_readable(THEME.'forum/'.e_LANGUAGE.'_'.$filename)) - { - $image = ($ML && is_readable(THEME.'forum/'.e_LANGUAGE.'_'.$filename)) ? THEME.'forum/'.e_LANGUAGE."_".$filename : THEME.'forum/'.$filename; - } - else - { - if(defined('IMODE')) - { - if($ML) - { - $image = (is_readable(e_PLUGIN.'forum/images/'.IMODE.'/'.e_LANGUAGE.'_'.$filename)) ? e_PLUGIN.'forum/images/'.IMODE.'/'.e_LANGUAGE.'_'.$filename : e_PLUGIN.'forum/images/'.IMODE.'/English_'.$filename; - } - else - { - $image = e_PLUGIN.'forum/images/'.IMODE.'/'.$filename; - } - } - else - { - if($ML) - { - $image = (is_readable(e_PLUGIN."forum/images/lite/".e_LANGUAGE.'_'.$filename)) ? e_PLUGIN.'forum/images/lite/'.e_LANGUAGE.'_'.$filename : e_PLUGIN.'forum/images/lite/English_'.$filename; - } - else - { - $image = e_PLUGIN.'forum/images/lite/'.$filename; - } - - } - } - - return $image; -} - - - - -if (file_exists(THEME.'forum/forum_icons_template.php')) -{ - require_once(THEME.'forum/forum_icons_template.php'); -} -elseif (file_exists(THEME.'forum_icons_template.php')) -{ - require_once(THEME.'forum_icons_template.php'); -} -else -{ - require_once(e_PLUGIN.'forum/templates/forum_icons_template.php'); -} -?> diff --git a/e107_plugins/forum/classes/forumPost.php b/e107_plugins/forum/classes/forumPost.php deleted file mode 100644 index 3b94b8d43..000000000 --- a/e107_plugins/forum/classes/forumPost.php +++ /dev/null @@ -1,72 +0,0 @@ -loadPost($id, $start, $num); - } - } - - function loadPost($id, $start, $num) - { - $e107 = e107::getInstance(); - $id = (int)$id; - $ret = false; - if('post' === $start) - { - $qry = ' - SELECT u.user_name, t.thread_active, t.thread_datestamp, t.thread_name, p.* FROM `#forum_post` AS p - LEFT JOIN `#forum_thread` AS t ON t.thread_id = p.post_thread - LEFT JOIN `#user` AS u ON u.user_id = p.post_user - WHERE p.post_id = '.$id; - } - else - { - $qry = " - SELECT p.*, - u.user_name, u.user_customtitle, u.user_hideemail, u.user_email, u.user_signature, - u.user_admin, u.user_image, u.user_join, ue.user_plugin_forum_posts, - eu.user_name AS edit_name - FROM `#forum_post` AS p - LEFT JOIN `#user` AS u ON p.post_user = u.user_id - LEFT JOIN `#user` AS eu ON p.post_edit_user IS NOT NULL AND p.post_edit_user = eu.user_id - LEFT JOIN `#user_extended` AS ue ON ue.user_extended_id = p.post_user - WHERE p.post_thread = {$id} - ORDER BY p.post_datestamp ASC - LIMIT {$start}, {$num} - "; - } - if($e107->sql->db_Select_gen($qry)) - { - $this->post = array(); - while($row = $e107->sql->db_Fetch()) - { - $this->post[] = $row; - } - if('post' === $start) { $this->post = $this->post[0]; } - return true; - } - return false; - } - - -} diff --git a/e107_plugins/forum/classes/forumThread.php b/e107_plugins/forum/classes/forumThread.php deleted file mode 100644 index 7f837edeb..000000000 --- a/e107_plugins/forum/classes/forumThread.php +++ /dev/null @@ -1,306 +0,0 @@ -e107 = e107::getInstance(); - $this->forum = $forum; - $this->threadId = $threadId; - if('post' == varset($_GET['f'])) { - $this->processFunction(); - } - $this->init(); - if(isset($_POST['track_toggle'])) - { - $this->toggle_track(); - exit; - } - if($threadId) { - $this->loadPosts(); - } -// var_dump($this->forum); - } - - function init() - { -// global $pref, $forum; - global $pref; - $this->perPage = (varset($_GET['perpage']) ? (int)$_GET['perpage'] : $pref['forum_postspage']); - $this->page = (varset($_GET['p']) ? (int)$_GET['p'] : 0); - if('last' == varset($_GET['f'])) - { - $this->processFunction(); - } - - //If threadId doesn't exist, or not given, redirect to main forum page - if (!$this->threadId || !$this->threadInfo = $this->loadThread($this->threadId)) - { - header('Location:' . $this->e107->url->getUrl('forum', 'forum', array('func' => 'main'))); - exit; - } - - //If not permitted to view forum, redirect to main forum page - if (!$this->forum->checkPerm($this->threadInfo['thread_forum_id'], 'view')) - { - header('Location:' . $this->e107->url->getUrl('forum', 'forum', array('func' => 'main'))); - exit; - } - $this->pages = (int)ceil(($this->threadInfo['thread_total_replies'] + 1) / $this->perPage); - $this->noInc = false; - } - - public function loadPosts() - { - $this->postList = new plugin_forum_classes_forumPost($this->threadId, $this->page * $this->perPage, $this->perPage); - } - - function toggle_track() - { - if (!USER || !isset($_GET['id'])) { return; } - if($this->threadInfo['track_userid']) - { - $this->forum->track('del', USERID, $_GET['id']); - $img = IMAGE_untrack; - } - else - { - $this->forum->track('add', USERID, $_GET['id']); - $img = IMAGE_track; - } - if(e_AJAX_REQUEST) - { - $url = $this->e107->url->getUrl('forum', 'thread', array('func' => 'view', 'id' => $this->threadId)); - echo "{$img}"; - exit(); - } - } - - function processFunction() - { - global $pref; - if (!isset($_GET['f'])) { return; } - - $function = trim($_GET['f']); - switch ($function) - { - case 'post': - $postId = varset($_GET['id']); - $postInfo = $forum->postGet($postId,'post'); - $postNum = $forum->postGetPostNum($postInfo['post_thread'], $postId); - $postPage = ceil($postNum / $pref['forum_postspage'])-1; - $url = $this->e107->url->getUrl('forum', 'thread', "func=view&id={$postInfo['post_thread']}&page=$postPage"); - header('location: '.$url); - exit; - break; - - case 'last': - $pages = ceil(($thread->threadInfo['thread_total_replies'] + 1) / $thread->perPage); - $thread->page = ($pages - 1); - break; - - case 'next': - $next = $forum->threadGetNextPrev('next', $this->threadId, $this->threadInfo['forum_id'], $this->threadInfo['thread_lastpost']); - if ($next) - { - $url = $e107->url->getUrl('forum', 'thread', array('func' => 'view', 'id' => $next)); - header("location: {$url}"); - exit; - } - $this->message = LAN_405; - break; - - case 'prev': - $prev = $forum->threadGetNextPrev('prev', $this->threadId, $this->threadInfo['forum_id'], $this->threadInfo['thread_lastpost']); - if ($prev) - { - $url = $e107->url->getUrl('forum', 'thread', array('func' => 'view', 'id' => $prev)); - header("location: {$url}"); - exit; - } - $this->message = LAN_404; - break; - - case 'report': - $postId = (int)$_GET['id']; - $postInfo = $forum->postGet($postId, 'post'); - - if (isset($_POST['report_thread'])) - { - $report_add = $e107->tp->toDB($_POST['report_add']); - if ($pref['reported_post_email']) - { - require_once (e_HANDLER . 'mail.php'); - $report = LAN_422 . SITENAME . " : " . (substr(SITEURL, -1) == "/" ? SITEURL : SITEURL . "/") . $PLUGINS_DIRECTORY . "forum/forum_viewtopic.php?" . $thread_id . ".post\n" . LAN_425 . USERNAME . "\n" . $report_add; - $subject = LAN_421 . " " . SITENAME; - sendemail(SITEADMINEMAIL, $subject, $report); - } - $e107->sql->db_Insert('generic', "0, 'reported_post', " . time() . ", '" . USERID . "', '{$thread_info['head']['thread_name']}', " . intval($thread_id) . ", '{$report_add}'"); - define('e_PAGETITLE', LAN_01 . " / " . LAN_428); - require_once (HEADERF); - $text = LAN_424 . "

" . LAN_429 . ''; - $e107->ns->tablerender(LAN_414, $text, array('forum_viewtopic', 'report')); - } - else - { - $thread_name = $e107->tp->toHTML($postInfo['thread_name'], true, 'no_hook, emotes_off'); - define('e_PAGETITLE', LAN_01 . ' / ' . LAN_426 . ' ' . $thread_name); - require_once (HEADERF); - $url = $e107->url->getUrl('forum', 'thread', 'func=post&id='.$postId); - $actionUrl = $e107->url->getUrl('forum', 'thread', 'func=report&id='.$postId); - $text = "
- - - - - - - - - - - - -
- " . LAN_415 . ': ' . $thread_name . " " . LAN_420 . " - - -
" . LAN_417 . "
" . LAN_418 . " -
- -

- -
"; - $e107->ns->tablerender(LAN_414, $text, array('forum_viewtopic', 'report2')); - } - require_once (FOOTERF); - exit; - break; - - } - - } - - function loadThread($id, $joinForum = true, $uid = USERID) - { - $id = (int)$id; - $uid = (int)$uid; - - if($joinForum) - { - // TODO: Fix query to get only forum and parent info needed, with correct naming - $qry = ' - SELECT t.*, f.*, - fp.forum_id as parent_id, fp.forum_name as parent_name, - sp.forum_id as forum_sub, sp.forum_name as sub_parent, - tr.track_userid - FROM `#forum_thread` AS t - LEFT JOIN `#forum` AS f ON t.thread_forum_id = f.forum_id - LEFT JOIN `#forum` AS fp ON fp.forum_id = f.forum_parent - LEFT JOIN `#forum` AS sp ON sp.forum_id = f.forum_sub - LEFT JOIN `#forum_track` AS tr ON tr.track_thread = t.thread_id AND tr.track_userid = '.$uid.' - WHERE thread_id = '.$id; - } - else - { - $qry = ' - SELECT * - FROM `#forum_thread` - WHERE thread_id = '.$id; - } - if($this->e107->sql->db_Select_gen($qry)) - { - $tmp = $this->e107->sql->db_Fetch(); - if($tmp) - { - if(trim($tmp['thread_options']) != '') - { - $tmp['thread_options'] = unserialize($tmp['thread_options']); - } - return $tmp; - } - } - return false; - } - - public function render() - { - global $FORUMREPLYSTYLE, $FORUMREPLYSTYLE_ALT, $FORUMTHREADSTYLE, $FORUMDELETEDSTYLE, $FORUMDELETEDSTYLE_ALT; - global $forum_shortcodes; - $ret = ""; - - if(!$FORUMREPLYSTYLE) $FORUMREPLYSTYLE = $FORUMTHREADSTYLE; - - $alt = false; - - $i = $this->page; - //var_dump($forum->thread->postList); - foreach ($this->postList->post as $postInfo) - { - if($postInfo['post_options']) - { - $postInfo['post_options'] = unserialize($postInfo['post_options']); - } - $loop_uid = (int)$postInfo['post_user']; - $i++; - - //TODO: Look into fixing this, to limit to a single query per pageload - $e_hide_query = "SELECT post_id FROM `#forum_post` WHERE (`post_thread` = {$threadId} AND post_user= " . USERID . ' LIMIT 1'; - $e_hide_hidden = FORLAN_HIDDEN; - $e_hide_allowed = USER; - - if ($i > 1) - { - $postInfo['thread_start'] = false; - $alt = !$alt; - - if($postInfo['post_status']) - { - $_style = (isset($FORUMDELETEDSTYLE_ALT) && $alt ? $FORUMDELETEDSTYLE_ALT : $FORUMDELETEDSTYLE); - } - else - { - $_style = (isset($FORUMREPLYSTYLE_ALT) && $alt ? $FORUMREPLYSTYLE_ALT : $FORUMREPLYSTYLE); - } - setScVar('forum_shortcodes', 'postInfo', $postInfo); - $ret .= $this->e107->tp->parseTemplate($_style, true, $forum_shortcodes) . "\n"; - } - else - { - $postInfo['thread_start'] = true; - setScVar('forum_shortcodes', 'postInfo', $postInfo); - $ret .= $this->e107->tp->parseTemplate($FORUMTHREADSTYLE, true, $forum_shortcodes) . "\n"; - } - } - unset($loop_uid); - return $ret; - } - - public function IncrementViews($id=0) - { - $e107 = e107::getInstance(); - $id = ($id ? (int)$id : $this->threadId); - return $e107->sql->db_Update('forum_thread', 'thread_views=thread_views+1 WHERE thread_id='.$id); - } - - -} - diff --git a/e107_plugins/forum/forum.php b/e107_plugins/forum/forum.php index 496770710..1f998ee34 100644 --- a/e107_plugins/forum/forum.php +++ b/e107_plugins/forum/forum.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum.php,v $ -| $Revision: 1.14 $ -| $Date: 2009-09-06 04:30:46 $ +| $Revision: 1.15 $ +| $Date: 2009-09-08 02:00:38 $ | $Author: mcfly_e107 $ +----------------------------------------------------------------------------+ */ @@ -23,7 +23,8 @@ if(!defined('e107_INIT')) include_lan(e_PLUGIN.'forum/languages/'.e_LANGUAGE.'/lan_forum.php'); -$forum = new plugin_forum_forumClass; +require_once(e_PLUGIN.'forum/forum_class.php'); +$forum = new e107forum; if ($untrackId = varset($_REQUEST['untrack'])) { @@ -46,7 +47,7 @@ if(isset($_GET['f'])) header('location:'.e_SELF); exit; break; - + case 'rules': include_once(HEADERF); forum_rules('show'); @@ -332,7 +333,7 @@ function parse_forum($f, $restricted_string = '') list($lastpost_datestamp, $lastpost_thread) = explode('.', $f['forum_lastpost_info']); if ($f['user_name']) { - + $lastpost_name = "{$f['user_name']}"; } else diff --git a/e107_plugins/forum/forum_class.php b/e107_plugins/forum/forum_class.php index 17e0ce2bb..74e4d46c8 100644 --- a/e107_plugins/forum/forum_class.php +++ b/e107_plugins/forum/forum_class.php @@ -9,27 +9,24 @@ * Message Handler * * $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_class.php,v $ - * $Revision: 1.39 $ - * $Date: 2009-09-06 04:30:46 $ + * $Revision: 1.40 $ + * $Date: 2009-09-08 02:00:43 $ * $Author: mcfly_e107 $ * */ if (!defined('e107_INIT')) { exit; } -class plugin_forum_forumClass +class e107forum { var $permList = array(); var $fieldTypes = array(); var $userViewed = array(); var $modArray = array(); var $e107; - private $threadList = array(); - private $postList = array(); - function __construct() + function e107forum() { - $this->e107 = e107::getInstance(); $this->loadPermList(); $this->fieldTypes['forum_post']['post_user'] = 'int'; $this->fieldTypes['forum_post']['post_forum'] = 'int'; @@ -52,20 +49,21 @@ class plugin_forum_forumClass $this->fieldTypes['forum_thread']['thread_options'] = 'escape'; $this->fieldTypes['forum']['forum_lastpost_user'] = 'int'; + $this->e107 = e107::getInstance(); } function loadPermList() { -// var_dump($this->e107); - if($tmp = $this->e107->ecache->retrieve_sys('forum_perms')) + global $e107; + if($tmp = $e107->ecache->retrieve_sys('forum_perms')) { $this->permList = $e107->arrayStorage->ReadArray($tmp); } else { $this->getForumPermList(); - $tmp = $this->e107->arrayStorage->WriteArray($this->permList, false); - $this->e107->ecache->set_sys('forum_perms', $tmp); + $tmp = $e107->arrayStorage->WriteArray($this->permList, false); + $e107->ecache->set_sys('forum_perms', $tmp); } unset($tmp); @@ -74,24 +72,26 @@ class plugin_forum_forumClass function getForumPermList() { + global $e107; + $this->permList = array(); $qryList = array(); - $qryList['view'] = " + $qryList[view] = " SELECT f.forum_id FROM `#forum` AS f LEFT JOIN `#forum` AS fp ON f.forum_parent = fp.forum_id AND fp.forum_class IN (".USERCLASS_LIST.") WHERE f.forum_class IN (".USERCLASS_LIST.") AND f.forum_parent != 0 AND fp.forum_id IS NOT NULL "; - $qryList['post'] = " + $qryList[post] = " SELECT f.forum_id FROM `#forum` AS f LEFT JOIN `#forum` AS fp ON f.forum_parent = fp.forum_id AND fp.forum_postclass IN (".USERCLASS_LIST.") WHERE f.forum_postclass IN (".USERCLASS_LIST.") AND f.forum_parent != 0 AND fp.forum_id IS NOT NULL "; - $qryList['thread'] = " + $qryList[thread] = " SELECT f.forum_id FROM `#forum` AS f LEFT JOIN `#forum` AS fp ON f.forum_parent = fp.forum_id AND fp.forum_threadclass IN (".USERCLASS_LIST.") @@ -100,9 +100,9 @@ class plugin_forum_forumClass foreach($qryList as $key => $qry) { - if($this->e107->sql->db_Select_gen($qry)) + if($e107->sql->db_Select_gen($qry)) { - while($row = $this->e107->sql->db_Fetch()) + while($row = $e107->sql->db_Fetch(MYSQL_ASSOC)) { $this->permList[$key][] = $row['forum_id']; } @@ -110,36 +110,19 @@ class plugin_forum_forumClass } } - /** - * Test for forum permissions. - * - * 'view' - user is able to view forumId - * 'post' - user is able to create new post in forumId - * 'thread' - user is able to create new thread in forumId - * - * @param integer $forumId - * @param string $type (view, post, thread) - * @return boolean - */ function checkPerm($forumId, $type='view') { return (in_array($forumId, $this->permList[$type])); } - /** - * Check to see of thread has been viewed by current user - * - * - * @param integer $threadId - * @return boolean - */ function threadViewed($threadId) { + $e107 = e107::getInstance(); if(!$this->userViewed) { - if(isset($this->e107->currentUser['user_plugin_forum_viewed'])) + if(isset($e107->currentUser['user_plugin_forum_viewed'])) { - $this->userViewed = explode(',', $this->e107->currentUser['user_plugin_forum_viewed']); + $this->userViewed = explode(',', $e107->currentUser['user_plugin_forum_viewed']); } } return (is_array($this->userViewed) && in_array($threadId, $this->userViewed)); @@ -147,10 +130,11 @@ class plugin_forum_forumClass function getTrackedThreadList($id, $retType = 'array') { + $e107 = e107::getInstance(); $id = (int)$id; - if($this->e107->sql->db_Select('forum_track', 'track_thread', 'track_userid = '.$id)) + if($e107->sql->db_Select('forum_track', 'track_thread', 'track_userid = '.$id)) { - while($row = $this->e107->sql->db_Fetch()) + while($row = $e107->sql->db_Fetch(MYSQL_ASSOC)) { $ret[] = $row['track_thread']; } @@ -167,14 +151,16 @@ class plugin_forum_forumClass */ function postAdd($postInfo, $updateThread = true, $updateForum = true) { +// var_dump($postInfo); //Future option, will just set to true here $addUserPostCount = true; $result = false; + $e107 = e107::getInstance(); $info = array(); $info['_FIELD_TYPES'] = $this->fieldTypes['forum_post']; $info['data'] = $postInfo; - $postId = $this->e107->sql->db_Insert('forum_post', $info); + $postId = $e107->sql->db_Insert('forum_post', $info); $forumInfo = array(); if($postId && $updateThread) @@ -203,7 +189,7 @@ class plugin_forum_forumClass $info['_FIELD_TYPES'] = $this->fieldTypes['forum_thread']; $info['_FIELD_TYPES']['thread_total_replies'] = 'cmd'; - $result = $this->e107->sql->db_Update('forum_thread', $info); + $result = $e107->sql->db_Update('forum_thread', $info); } @@ -236,7 +222,7 @@ class plugin_forum_forumClass $info['data'] = $forumInfo; $info['data']['forum_lastpost_info'] = $postInfo['post_datestamp'].'.'.$postInfo['post_thread']; $info['WHERE'] = 'forum_id = '.$postInfo['post_forum']; - $result = $this->e107->sql->db_Update('forum', $info); + $result = $e107->sql->db_Update('forum', $info); } if($result && USER && $addUserPostCount) @@ -246,17 +232,18 @@ class plugin_forum_forumClass VALUES ('.USERID.', 1) ON DUPLICATE KEY UPDATE user_plugin_forum_posts = user_plugin_forum_posts + 1 '; - $result = $this->e107->sql->db_Select_gen($qry); + $result = $e107->sql->db_Select_gen($qry); } return $postId; } function threadAdd($threadInfo, $postInfo) { + $e107 = e107::getInstance(); $info = array(); $info['_FIELD_TYPES'] = $this->fieldTypes['forum_thread']; $info['data'] = $threadInfo; - if($newThreadId = $this->e107->sql->db_Insert('forum_thread', $info)) + if($newThreadId = $e107->sql->db_Insert('forum_thread', $info)) { $postInfo['post_thread'] = $newThreadId; $newPostId = $this->postAdd($postInfo, false); @@ -268,30 +255,34 @@ class plugin_forum_forumClass function threadUpdate($threadId, $threadInfo) { + $e107 = e107::getInstance(); $info = array(); $info['data'] = $threadInfo; $info['_FIELD_TYPES'] = $this->fieldTypes['forum_thread']; $info['WHERE'] = 'thread_id = '.(int)$threadId; - $this->e107->sql->db_Update('forum_thread', $info); + $e107->sql->db_Update('forum_thread', $info); } function postUpdate($postId, $postInfo) { + $e107 = e107::getInstance(); $info = array(); $info['data'] = $postInfo; $info['_FIELD_TYPES'] = $this->fieldTypes['forum_post']; $info['WHERE'] = 'post_id = '.(int)$postId; - $this->e107->sql->db_Update('forum_post', $info); + $e107->sql->db_Update('forum_post', $info); } function threadGet($id, $joinForum = true, $uid = USERID) { + global $pref; + $e107 = e107::getInstance(); $id = (int)$id; $uid = (int)$uid; if($joinForum) { - // TODO: Fix query to get only forum and parent info needed, with correct naming + //TODO: Fix query to get only forum and parent info needed, with correct naming $qry = ' SELECT t.*, f.*, fp.forum_id as parent_id, fp.forum_name as parent_name, @@ -311,9 +302,9 @@ class plugin_forum_forumClass FROM `#forum_thread` WHERE thread_id = '.$id; } - if($this->e107->sql->db_Select_gen($qry)) + if($e107->sql->db_Select_gen($qry)) { - $tmp = $this->e107->sql->db_Fetch(); + $tmp = $e107->sql->db_Fetch(MYSQL_ASSOC); if($tmp) { if(trim($tmp['thread_options']) != '') @@ -330,6 +321,7 @@ class plugin_forum_forumClass { $id = (int)$id; $ret = false; + $e107 = e107::getInstance(); if('post' === $start) { $qry = ' @@ -354,10 +346,10 @@ class plugin_forum_forumClass LIMIT {$start}, {$num} "; } - if($this->e107->sql->db_Select_gen($qry)) + if($e107->sql->db_Select_gen($qry)) { $ret = array(); - while($row = $this->e107->sql->db_Fetch()) + while($row = $e107->sql->db_Fetch(MYSQL_ASSOC)) { $ret[] = $row; } @@ -370,16 +362,17 @@ class plugin_forum_forumClass 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($this->e107->sql->db_Select_gen($qry)) + if($e107->sql->db_Select_gen($qry)) { $ret = array(); - while($row = $this->e107->sql->db_Fetch()) + while($row = $e107->sql->db_Fetch(MYSQL_ASSOC)) { $ret[$row['post_user']] = $row['post_count']; } @@ -389,9 +382,10 @@ class plugin_forum_forumClass function threadGetUserViewed($uid = USERID) { + $e107 = e107::getInstance(); if($uid == USERID) { - $viewed = $this->e107->currentUser['user_plugin_forum_viewed']; + $viewed = $e107->currentUser['user_plugin_forum_viewed']; } else { @@ -511,7 +505,7 @@ class plugin_forum_forumClass { if ($sql->db_Select('forum', 'forum_id', 'forum_parent != 0')) { - while ($row = $sql->db_Fetch()) + while ($row = $sql->db_Fetch(MYSQL_ASSOC)) { $parentList[] = $row['forum_id']; } @@ -641,7 +635,7 @@ class plugin_forum_forumClass } return $this->modArray; } - + function isModerator($uid) { return ($uid && in_array($uid, array_keys($this->modArray))); @@ -863,10 +857,8 @@ class plugin_forum_forumClass function forumGetThreads($forumId, $from, $view) { + $e107 = e107::getInstance(); $forumId = (int)$forumId; - $from = (int)$from; - $view = (int)$view; - $qry = " SELECT t.*, u.user_name, lpu.user_name AS lastpost_username from `#forum_thread` as t LEFT JOIN `#user` AS u ON t.thread_user = u.user_id @@ -875,18 +867,17 @@ class plugin_forum_forumClass ORDER BY t.thread_sticky DESC, t.thread_lastpost DESC - LIMIT {$from},{$view}"; + LIMIT ".(int)$from.','.(int)$view; - $this->threadList = array(); - if ($this->e107->sql->db_Select_gen($qry)) + $ret = array(); + if ($e107->sql->db_Select_gen($qry)) { - while ($row = $this->e107->sql->db_Fetch()) + while ($row = $e107->sql->db_Fetch(MYSQL_ASSOC)) { - $this->threadList = $row; + $ret[] = $row; } - return true; } - return false; + return $ret; } function threadGetLastpost($id) @@ -1227,11 +1218,12 @@ class plugin_forum_forumClass function postDelete($postId, $updateCounts = true) { $postId = (int)$postId; - if(!$e107->sql->db_Select('forum_post', 'post_user, post_forum, post_thread', 'post_id = '.$postId)) + $e107 = e107::getInstance(); + if(!$e107->sql->db_Select('forum_post', '*', 'post_id = '.$postId)) { echo 'NOT FOUND!'; return; } - $row = $this->e107->sql->db_Fetch(); + $row = $e107->sql->db_Fetch(MYSQL_ASSOC); //delete attachments if they exist if($row['post_attachments']) @@ -1240,21 +1232,21 @@ class plugin_forum_forumClass } // delete post - $this->e107->sql->db_Delete('forum_post', 'post_id='.$postId); + $e107->sql->db_Delete('forum_post', 'post_id='.$postId); if($updateCounts) { //decrement user post counts if ($row['post_user']) { - $this->e107->sql->db_Update('user_extended', 'user_plugin_forum_posts=GREATEST(user_plugin_forum_posts-1,0) WHERE user_id='.$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 - $this->e107->sql->db_Update('forum_thread', "thread_total_replies=GREATEST(thread_total_replies-1,0) WHERE thread_id=".$row['post_thread']); + $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 - $this->e107->sql->db_Update('forum', "forum_replies=GREATEST(forum_replies-1,0) WHERE forum_id=".$row['post_forum']); + $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']); diff --git a/e107_plugins/forum/forum_post.php b/e107_plugins/forum/forum_post.php index 9c4f45b09..1dbda5d8d 100644 --- a/e107_plugins/forum/forum_post.php +++ b/e107_plugins/forum/forum_post.php @@ -3,7 +3,7 @@ + ----------------------------------------------------------------------------+ | e107 website system | -| �Steve Dunstan 2001-2002 +| ©Steve Dunstan 2001-2002 | http://e107.org | jalist@e107.org | @@ -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.37 $ -| $Date: 2009-09-06 04:30:46 $ +| $Revision: 1.38 $ +| $Date: 2009-09-08 02:00:41 $ | $Author: mcfly_e107 $ +----------------------------------------------------------------------------+ */ @@ -22,8 +22,6 @@ require_once('../../class2.php'); $lan_file = e_PLUGIN.'forum/languages/'.e_LANGUAGE.'/lan_forum_post.php'; include(file_exists($lan_file) ? $lan_file : e_PLUGIN.'forum/languages/English/lan_forum_post.php'); -e107::getScParser(); - if (isset($_POST['fjsubmit'])) { header('location:'.$e107->url->getUrl('forum', 'thread', array('func' => 'view', 'id'=>$_POST['forumjump']))); diff --git a/e107_plugins/forum/forum_shortcodes.php b/e107_plugins/forum/forum_shortcodes.php index daa5e6232..ca642d884 100644 --- a/e107_plugins/forum/forum_shortcodes.php +++ b/e107_plugins/forum/forum_shortcodes.php @@ -11,7 +11,7 @@ class forum_shortcodes var $postInfo; var $thread; var $forum; - + function forum_shortcodes() { $this->e107 = e107::getInstance(); @@ -280,14 +280,14 @@ class forum_shortcodes $rankInfo = $this->e107->userRank->getRanks($this->postInfo['post_user']); if(!$parm) { $parm = 'name'; } - + switch($parm) { - + case 'userid' : return $this->sc_memberid(); break; - + case 'special': if(isset($rankInfo['special'])) { return $rankInfo['special']; } if($this->forum->isModerator($this->postInfo['post_user'])) @@ -296,7 +296,7 @@ class forum_shortcodes } return ''; break; - + default: return varset($rankInfo[$parm], ''); break; @@ -307,7 +307,7 @@ class forum_shortcodes { if (MODERATOR) { - return $this->showModOptions(); + return showmodoptions(); } } @@ -345,48 +345,5 @@ class forum_shortcodes // Defined in case an indicator is required return ''; } - - function showModOptions() - { - global $thread, $postInfo; - - $e107 = e107::getInstance(); - $forum_id = $thread->threadInfo['forum_id']; - - - if ($this->postInfo['thread_start']) - { - $type = 'Thread'; - $ret = " 'view', 'id' => $this->postInfo['post_thread']))."' id='frmMod_{$this->postInfo['post_forum']}_{$this->postInfo['post_thread']}'>"; - $delId = $postInfo['post_thread']; - } - else - { - $type = 'Post'; - $ret = "postInfo['post_thread']}'>"; - $delId = $this->postInfo['post_id']; - } - - $ret .= " -
- 'edit', 'id' => $postInfo['post_id']))."'>" . IMAGE_admin_edit . " - postInfo['post_forum']}, {$this->postInfo['post_thread']}, '{$this->postInfo['user_name']}')\" /> - - "; - if ($type == 'Thread') - { - $ret .= " 'move', 'id' => $this->postInfo['post_id']))."'>" . IMAGE_admin_move2 . ""; - } - else - { - $ret .= " 'split', 'id' => $this->postInfo['post_id']))."'>" . IMAGE_admin_split . ''; - - } - $ret .= " -
-
"; - return $ret; - - } } ?> \ No newline at end of file diff --git a/e107_plugins/forum/forum_viewforum.php b/e107_plugins/forum/forum_viewforum.php index f23a16363..ecd28f86a 100644 --- a/e107_plugins/forum/forum_viewforum.php +++ b/e107_plugins/forum/forum_viewforum.php @@ -9,8 +9,8 @@ * View specific forums * * $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_viewforum.php,v $ -* $Revision: 1.13 $ -* $Date: 2009-09-06 04:30:46 $ +* $Revision: 1.14 $ +* $Date: 2009-09-08 02:00:42 $ * $Author: mcfly_e107 $ * */ @@ -38,7 +38,7 @@ $page = (varset($_GET['p']) ? $_GET['p'] : 0); $threadFrom = $page * $view; require_once(e_PLUGIN.'forum/forum_class.php'); -$forum = new plugin_forum_forumClass; +$forum = new e107forum; $STARTERTITLE = LAN_54; $THREADTITLE = LAN_53; @@ -496,7 +496,7 @@ function parse_sub($subInfo) $SUB_REPLIES = $subInfo['forum_replies']; if(USER && is_array($newflag_list) && in_array($subInfo['forum_id'], $newflag_list)) { - + $NEWFLAG = "".IMAGE_new.''; } else diff --git a/e107_plugins/forum/forum_viewtopic.php b/e107_plugins/forum/forum_viewtopic.php index 7d450593c..61049ba39 100644 --- a/e107_plugins/forum/forum_viewtopic.php +++ b/e107_plugins/forum/forum_viewtopic.php @@ -6,17 +6,18 @@ * Released under the terms and conditions of the * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * - * Forum Viewtopic + * Message Handler * * $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_viewtopic.php,v $ - * $Revision: 1.21 $ - * $Date: 2009-09-06 04:30:46 $ + * $Revision: 1.22 $ + * $Date: 2009-09-08 02:00:44 $ * $Author: mcfly_e107 $ * */ require_once ('../../class2.php'); + if (isset($_POST['fjsubmit'])) { header('location:' . $e107->url->getUrl('forum', 'forum', array('func' => 'view', 'id' => $_POST['forumjump']))); @@ -30,29 +31,48 @@ if (!e_QUERY) header('Location:' . $e107->url->getUrl('forum', 'forum', array('func' => 'main'))); exit; } -e107::getScParser(); -include_lan(e_PLUGIN.'forum/languages/English/lan_forum_viewtopic.php'); -$forum = new plugin_forum_classes_forumClass; -include_lan(e_PLUGIN.'forum/languages/English/lan_forum_viewtopic.php'); -include_lan(e_PLUGIN.'forum/templates/forum_icons_template.php'); -$forum->threadNew(varset($_GET['id'])); +include_lan(e_PLUGIN . 'forum/languages/English/lan_forum_viewtopic.php'); +include_once (e_PLUGIN . 'forum/forum_class.php'); +include_lan(e_PLUGIN . 'forum/templates/forum_icons_template.php'); -require_once (e_HANDLER.'level_handler.php'); -if (!is_object($e107->userRank)) { $e107->userRank = new e107UserRank; } +$forum = new e107forum; +$thread = new e107ForumThread; -require_once (e_PLUGIN.'forum/forum_shortcodes.php'); -setScVar('forum_shortcodes', 'thread', $forum->thread); - -$pm_installed = e107::isInstalled('pm'); - -//Only increment thread views if not being viewed by thread starter -if (USER && (USERID != $forum->thread->threadInfo['thread_user'] || $forum->thread->threadInfo['thread_total_replies'] > 0) || !$forum->thread->noInc) +if(isset($_GET['f']) && $_GET['f'] == 'post') { - $forum->thread->IncrementViews(); + $thread->processFunction(); } -define('e_PAGETITLE', LAN_01 . ' / ' . $e107->tp->toHTML($forum->thread->threadInfo['forum_name'], true, 'no_hook, emotes_off') . " / " . $tp->toHTML($thread->threadInfo['thread_name'], true, 'no_hook, emotes_off')); +$thread->init(); + +if(isset($_POST['track_toggle'])) +{ + $thread->toggle_track(); + exit; +} +//print_a($_POST); + +if(isset($_GET['f'])) +{ + $thread->processFunction(); + if($_GET['f'] != 'last') { $thread->init(); } +} + +require_once (e_HANDLER . 'level_handler.php'); +if (!is_object($e107->userRank)) { $e107->userRank = new e107UserRank; } +require_once (e_PLUGIN . 'forum/forum_shortcodes.php'); +setScVar('forum_shortcodes', 'thread', $thread); + +$pm_installed = plugInstalled('pm'); + +//Only increment thread views if not being viewed by thread starter +if (USER && (USERID != $thread->threadInfo['thread_user'] || $thread->threadInfo['thread_total_replies'] > 0) || !$thread->noInc) +{ + $forum->threadIncview($threadId); +} + +define('e_PAGETITLE', LAN_01 . ' / ' . $e107->tp->toHTML($thread->threadInfo['forum_name'], true, 'no_hook, emotes_off') . " / " . $tp->toHTML($thread->threadInfo['thread_name'], true, 'no_hook, emotes_off')); $forum->modArray = $forum->forumGetMods($thread->threadInfo['forum_moderators']); define('MODERATOR', (USER && $forum->isModerator(USERID))); setScVar('forum_shortcodes', 'forum', $forum); @@ -60,24 +80,25 @@ setScVar('forum_shortcodes', 'forum', $forum); if (MODERATOR && isset($_POST['mod'])) { require_once (e_PLUGIN . 'forum/forum_mod.php'); - $forum->thread->message = forum_thread_moderate($_POST); + $thread->message = forum_thread_moderate($_POST); + $thread->threadInfo = $forum->threadGet($thread->threadId); } -$forum->thread->loadPosts(); +$postList = $forum->PostGet($thread->threadId, $thread->page * $thread->perPage, $thread->perPage); $gen = new convert; -if ($forum->thread->message) +if ($thread->message) { - $ns->tablerender('', $forum->thread->message, array('forum_viewtopic', 'msg')); + $ns->tablerender('', $thread->message, array('forum_viewtopic', 'msg')); } -if (isset($forum->thread->threadInfo['thread_options']['poll'])) +if (isset($thread->threadInfo['thread_options']['poll'])) { if (!defined('POLLCLASS')) { include (e_PLUGIN . 'poll/poll_class.php'); } - $_qry = 'SELECT * FROM `#polls` WHERE `poll_datestamp` = ' . $forum->thread->threadId; + $_qry = 'SELECT * FROM `#polls` WHERE `poll_datestamp` = ' . $thread->threadId; $poll = new poll; $pollstr = "
" . $poll->render_poll($_qry, 'forum', 'query', true) . '
'; } @@ -106,15 +127,15 @@ if (!$FORUMSTART) // get info for main thread ------------------------------------------------------------------------------------------------------------------------------------------------------------------- $forum->set_crumb(true); // Set $BREADCRUMB (and BACKLINK) -$THREADNAME = $e107->tp->toHTML($forum->thread->threadInfo['thread_name'], true, 'no_hook, emotes_off'); +$THREADNAME = $e107->tp->toHTML($thread->threadInfo['thread_name'], true, 'no_hook, emotes_off'); $NEXTPREV = "<< 'prev', 'id' => $thread->threadId)) . "'>" . LAN_389 . ""; $NEXTPREV .= ' | '; $NEXTPREV .= " 'next', 'id' => $thread->threadId)) . "'>" . LAN_390 . " >>"; if ($pref['forum_track'] && USER) { - $img = ($forum->thread->threadInfo['track_userid'] ? IMAGE_track : IMAGE_untrack); - $url = $e107->url->getUrl('forum', 'thread', array('func' => 'view', 'id' => $forum->thread->threadId)); + $img = ($thread->threadInfo['track_userid'] ? IMAGE_track : IMAGE_untrack); + $url = $e107->url->getUrl('forum', 'thread', array('func' => 'view', 'id' => $thread->threadId)); $TRACK .= " {$img} @@ -138,32 +159,75 @@ if ($pref['forum_track'] && USER) $MODERATORS = LAN_321 . implode(', ', $forum->modArray); -$THREADSTATUS = (!$forum->thread->threadInfo['thread_active'] ? LAN_66 : ''); +$THREADSTATUS = (!$thread->threadInfo['thread_active'] ? LAN_66 : ''); -if ($forum->thread->pages > 1) +if ($thread->pages > 1) { - $parms = ($forum->thread->pages).",1,{$forum->thread->page},url::forum::thread::func=view&id={$forum->thread->threadId}&page=[FROM],off"; + $parms = ($thread->pages).",1,{$thread->page},url::forum::thread::func=view&id={$thread->threadId}&page=[FROM],off"; $GOTOPAGES = $tp->parseTemplate("{NEXTPREV={$parms}}"); } $BUTTONS = ''; -if ($forum->checkPerm($forum->thread->threadInfo['thread_forum_id'], 'post') && $forum->thread->threadInfo['thread_active']) +if ($forum->checkPerm($thread->threadInfo['thread_forum_id'], 'post') && $thread->threadInfo['thread_active']) { - $BUTTONS .= " 'rp', 'id' => $forum->thread->threadId)) . "'>" . IMAGE_reply . ""; + $BUTTONS .= " 'rp', 'id' => $thread->threadId)) . "'>" . IMAGE_reply . ""; } -if ($forum->checkPerm($forum->thread->threadInfo['thread_forum_id'], 'thread')) +if ($forum->checkPerm($thread->threadInfo['thread_forum_id'], 'thread')) { - $BUTTONS .= " 'nt', 'id' => $forum->thread->threadInfo['thread_forum_id'])) . "'>" . IMAGE_newthread . ""; + $BUTTONS .= " 'nt', 'id' => $thread->threadInfo['thread_forum_id'])) . "'>" . IMAGE_newthread . ""; } $POLL = $pollstr; + $FORUMJUMP = forumjump(); $forstr = preg_replace("/\{(.*?)\}/e", '$\1', $FORUMSTART); -$forthread = $forum->thread->render(); +unset($forrep); +if (!$FORUMREPLYSTYLE) $FORUMREPLYSTYLE = $FORUMTHREADSTYLE; +$alt = false; -if ($forum->checkPerm($forum->thread->threadInfo['thread_forum_id'], 'post') && $forum->thread->threadInfo['thread_active']) +$i = $thread->page; +foreach ($postList as $postInfo) +{ + if($postInfo['post_options']) + { + $postInfo['post_options'] = unserialize($postInfo['post_options']); + } + $loop_uid = (int)$postInfo['post_user']; + $i++; + + //TODO: Look into fixing this, to limit to a single query per pageload + $e_hide_query = "SELECT post_id FROM `#forum_post` WHERE (`post_thread` = {$threadId} AND post_user= " . USERID . ' LIMIT 1'; + $e_hide_hidden = FORLAN_HIDDEN; + $e_hide_allowed = USER; + + if ($i > 1) + { + $postInfo['thread_start'] = false; + $alt = !$alt; + + if($postInfo['post_status']) + { + $_style = (isset($FORUMDELETEDSTYLE_ALT) && $alt ? $FORUMDELETEDSTYLE_ALT : $FORUMDELETEDSTYLE); + } + else + { + $_style = (isset($FORUMREPLYSTYLE_ALT) && $alt ? $FORUMREPLYSTYLE_ALT : $FORUMREPLYSTYLE); + } + setScVar('forum_shortcodes', 'postInfo', $postInfo); + $forrep .= $e107->tp->parseTemplate($_style, true, $forum_shortcodes) . "\n"; + } + else + { + $postInfo['thread_start'] = true; + setScVar('forum_shortcodes', 'postInfo', $postInfo); + $forthr = $e107->tp->parseTemplate($FORUMTHREADSTYLE, true, $forum_shortcodes) . "\n"; + } +} +unset($loop_uid); + +if ($forum->checkPerm($thread->threadInfo['thread_forum_id'], 'post') && $thread->threadInfo['thread_active']) { if (!$forum_quickreply) { @@ -185,13 +249,13 @@ if ($forum->checkPerm($forum->thread->threadInfo['thread_forum_id'], 'post') && } $forend = preg_replace("/\{(.*?)\}/e", '$\1', $FORUMEND); -$forumstring = $forstr . $forthread . $forend; +$forumstring = $forstr . $forthr . $forrep . $forend; //If last post came after USERLV and not yet marked as read, mark the thread id as read $threadsViewed = explode(',', $currentUser['user_plugin_forum_viewed']); -if ($forum->thread->threadInfo['thread_lastpost'] > USERLV && !in_array($forum->thread->threadId, $threadsViewed)) +if ($thread->threadInfo['thread_lastpost'] > USERLV && !in_array($thread->threadId, $threadsViewed)) { - $tst = $forum->threadMarkAsRead($forum->thread->threadId); + $tst = $forum->threadMarkAsRead($thread->threadId); } require_once (HEADERF); @@ -218,6 +282,46 @@ echo ""; require_once (FOOTERF); +function showmodoptions() +{ + global $thread, $postInfo; + + $e107 = e107::getInstance(); + $forum_id = $thread->threadInfo['forum_id']; + if ($postInfo['thread_start']) + { + $type = 'Thread'; + $ret = "
'view', 'id' => $postInfo['post_thread']))."' id='frmMod_{$postInfo['post_forum']}_{$postInfo['post_thread']}'>"; + $delId = $postInfo['post_thread']; + } + else + { + $type = 'Post'; + $ret = ""; + $delId = $postInfo['post_id']; + } + + $ret .= " +
+ 'edit', 'id' => $postInfo['post_id']))."'>" . IMAGE_admin_edit . " + + + "; + if ($type == 'Thread') + { + $ret .= " 'move', 'id' => $postInfo['post_id']))."'>" . IMAGE_admin_move2 . ""; + } + else + { + $ret .= " 'split', 'id' => $postInfo['post_id']))."'>" . IMAGE_admin_split . ''; + + } + $ret .= " +
+
"; + return $ret; +} + function forumjump() { global $forum; @@ -335,3 +439,167 @@ function rpg($user_join, $user_forums) $rpg_info .= ""; return $rpg_info; } + +class e107ForumThread +{ + + var $message, $threadId, $forumId, $perPage, $noInc, $pages; + + function init() + { + global $pref, $forum; + $e107 = e107::getInstance(); + $this->threadId = (int)varset($_GET['id']); + $this->perPage = (varset($_GET['perpage']) ? (int)$_GET['perpage'] : $pref['forum_postspage']); + $this->page = (varset($_GET['p']) ? (int)$_GET['p'] : 0); + + //If threadId doesn't exist, or not given, redirect to main forum page + if (!$this->threadId || !$this->threadInfo = $forum->threadGet($this->threadId)) + { + header('Location:' . $e107->url->getUrl('forum', 'forum', array('func' => 'main'))); + exit; + } + + //If not permitted to view forum, redirect to main forum page + if (!$forum->checkPerm($this->threadInfo['thread_forum_id'], 'view')) + { + header('Location:' . $e107->url->getUrl('forum', 'forum', array('func' => 'main'))); + exit; + } + $this->pages = ceil(($this->threadInfo['thread_total_replies'] + 1) / $this->perPage); + $this->noInc = false; + } + + function toggle_track() + { + global $forum, $thread; + $e107 = e107::getInstance(); + if (!USER || !isset($_GET['id'])) { return; } + if($thread->threadInfo['track_userid']) + { + $forum->track('del', USERID, $_GET['id']); + $img = IMAGE_untrack; + } + else + { + $forum->track('add', USERID, $_GET['id']); + $img = IMAGE_track; + } + if(e_AJAX_REQUEST) + { + $url = $e107->url->getUrl('forum', 'thread', array('func' => 'view', 'id' => $thread->threadId)); + echo "{$img}"; + exit(); + } + } + + function processFunction() + { + global $forum, $thread, $pref; + $e107 = e107::getInstance(); + if (!isset($_GET['f'])) + { + return; + } + + $function = trim($_GET['f']); + switch ($function) + { + case 'post': + $postId = varset($_GET['id']); + $postInfo = $forum->postGet($postId,'post'); + $postNum = $forum->postGetPostNum($postInfo['post_thread'], $postId); + $postPage = ceil($postNum / $pref['forum_postspage'])-1; + $url = $e107->url->getUrl('forum', 'thread', "func=view&id={$postInfo['post_thread']}&page=$postPage"); + header('location: '.$url); + exit; + break; + + case 'last': + $pages = ceil(($thread->threadInfo['thread_total_replies'] + 1) / $thread->perPage); + $thread->page = ($pages - 1); + break; + + case 'next': + $next = $forum->threadGetNextPrev('next', $this->threadId, $this->threadInfo['forum_id'], $this->threadInfo['thread_lastpost']); + if ($next) + { + $url = $e107->url->getUrl('forum', 'thread', array('func' => 'view', 'id' => $next)); + header("location: {$url}"); + exit; + } + $this->message = LAN_405; + break; + + case 'prev': + $prev = $forum->threadGetNextPrev('prev', $this->threadId, $this->threadInfo['forum_id'], $this->threadInfo['thread_lastpost']); + if ($prev) + { + $url = $e107->url->getUrl('forum', 'thread', array('func' => 'view', 'id' => $prev)); + header("location: {$url}"); + exit; + } + $this->message = LAN_404; + break; + + case 'report': + $postId = (int)$_GET['id']; + $postInfo = $forum->postGet($postId, 'post'); + + if (isset($_POST['report_thread'])) + { + $report_add = $e107->tp->toDB($_POST['report_add']); + if ($pref['reported_post_email']) + { + require_once (e_HANDLER . 'mail.php'); + $report = LAN_422 . SITENAME . " : " . (substr(SITEURL, -1) == "/" ? SITEURL : SITEURL . "/") . $PLUGINS_DIRECTORY . "forum/forum_viewtopic.php?" . $thread_id . ".post\n" . LAN_425 . USERNAME . "\n" . $report_add; + $subject = LAN_421 . " " . SITENAME; + sendemail(SITEADMINEMAIL, $subject, $report); + } + $e107->sql->db_Insert('generic', "0, 'reported_post', " . time() . ", '" . USERID . "', '{$thread_info['head']['thread_name']}', " . intval($thread_id) . ", '{$report_add}'"); + define('e_PAGETITLE', LAN_01 . " / " . LAN_428); + require_once (HEADERF); + $text = LAN_424 . "

" . LAN_429 . ''; + $e107->ns->tablerender(LAN_414, $text, array('forum_viewtopic', 'report')); + } + else + { + $thread_name = $e107->tp->toHTML($postInfo['thread_name'], true, 'no_hook, emotes_off'); + define('e_PAGETITLE', LAN_01 . ' / ' . LAN_426 . ' ' . $thread_name); + require_once (HEADERF); + $url = $e107->url->getUrl('forum', 'thread', 'func=post&id='.$postId); + $actionUrl = $e107->url->getUrl('forum', 'thread', 'func=report&id='.$postId); + $text = "
+ + + + + + + + + + + + +
+ " . LAN_415 . ': ' . $thread_name . " " . LAN_420 . " + + +
" . LAN_417 . "
" . LAN_418 . " +
+ +

+ +
"; + $e107->ns->tablerender(LAN_414, $text, array('forum_viewtopic', 'report2')); + } + require_once (FOOTERF); + exit; + break; + + } + } +} + +?> \ No newline at end of file