From 1b678992771cd2ac0216e89362a2a70733005de8 Mon Sep 17 00:00:00 2001 From: mcfly Date: Wed, 17 Dec 2008 04:22:37 +0000 Subject: [PATCH] More forum work, neearly all display functionality working. Beginning work on moderator functionality --- e107_plugins/forum/e_url/forum.php | 10 +- e107_plugins/forum/e_url/thread.php | 4 +- e107_plugins/forum/forum.php | 148 ++++---- e107_plugins/forum/forum_class.php | 475 +++++------------------- e107_plugins/forum/forum_conf.php | 83 +++-- e107_plugins/forum/forum_shortcodes.php | 7 +- e107_plugins/forum/forum_viewforum.php | 24 +- e107_plugins/forum/forum_viewtopic.php | 61 ++- 8 files changed, 251 insertions(+), 561 deletions(-) diff --git a/e107_plugins/forum/e_url/forum.php b/e107_plugins/forum/e_url/forum.php index be379aa7a..cae5c2ba6 100644 --- a/e107_plugins/forum/e_url/forum.php +++ b/e107_plugins/forum/e_url/forum.php @@ -1,5 +1,5 @@ forum_markasread('all'); - header('location:'.e_SELF); - exit; -} + if(isset($_GET['id'])) + { + $id = (int)$_GET['id']; + } -//Mark all threads in specific forum as read -if (varset($_REQUEST['mfar'])) -{ - $forum->forum_markasread((int)$_REQUEST['mfar']); - header('location:'.e_SELF); - exit; -} - -if (e_QUERY == 'rules') -{ - include_once(HEADERF); - forum_rules('show'); - include_once(FOOTERF); - exit; + switch($_GET['f']) + { + case 'mfar': + $forum->forumMarkAsRead($id); + header('location:'.e_SELF); + exit; + break; + + case 'rules': + include_once(HEADERF); + forum_rules('show'); + include_once(FOOTERF); + exit; + break; + } } $gen = new convert; @@ -74,7 +74,7 @@ $rules_text = forum_rules('check'); $USERINFO = "".LAN_429." | ".LAN_430.""; if(USER) { - $USERINFO .= " | ".LAN_431." | ".LAN_432." | ".LAN_435.""; + $USERINFO .= " | ".LAN_431." | ".LAN_432." | ".LAN_435.""; if($pref['forum_attach'] && (check_class($pref['upload_class']) || getperms('0'))) { $USERINFO .= " | ".FORLAN_442.""; @@ -82,7 +82,7 @@ if(USER) } if($rules_text != '') { - $USERINFO .= " | ".LAN_433.""; + $USERINFO .= " | ".LAN_433.''; } $total_topics = $sql->db_Count("forum_t", "(*)", " WHERE thread_parent='0' "); $total_replies = $sql->db_Count("forum_t", "(*)", " WHERE thread_parent!='0' "); @@ -198,7 +198,7 @@ if (USER && varsettrue($pref['forum_track']) && e_QUERY != 'track') $INFO .= "
".LAN_393.''; } -$FORUMINFO = LAN_192.($total_topics+$total_replies)." ".LAN_404." ($total_topics ".($total_topics == 1 ? LAN_411 : LAN_413).", $total_replies ".($total_replies == 1 ? LAN_412 : LAN_414).").".(!defined("e_TRACKING_DISABLED") ? "" : "
".$users." ".($users == 1 ? LAN_415 : LAN_416)." (".$member_users." ".($member_users == 1 ? LAN_417 : LAN_419).", ".$guest_users." ".($guest_users == 1 ? LAN_418 : LAN_420).")
".LAN_42.$total_members."
".LAN_41."".$nuser_name.".\n"); +$FORUMINFO = LAN_192.($total_topics+$total_replies).' '.LAN_404." ($total_topics ".($total_topics == 1 ? LAN_411 : LAN_413).", $total_replies ".($total_replies == 1 ? LAN_412 : LAN_414).").".(!defined("e_TRACKING_DISABLED") ? "" : "
".$users." ".($users == 1 ? LAN_415 : LAN_416)." (".$member_users." ".($member_users == 1 ? LAN_417 : LAN_419).", ".$guest_users." ".($guest_users == 1 ? LAN_418 : LAN_420).")
".LAN_42.$total_members."
".LAN_41."".$nuser_name.".\n"); if (!isset($FORUM_MAIN_START)) { @@ -210,12 +210,10 @@ if (!isset($FORUM_MAIN_START)) include(e_PLUGIN.'forum/templates/forum_template.php'); require_once(HEADERF); -$parent_list = $forum->forum_getparents(); -$forum_list = $forum->forum_getforums(); -$sub_list = $forum->forumGetSubs(); -$newflag_list = $forum->forum_newflag_list(); +$forumList = $forum->forumGetForumList(); +$newflag_list = $forum->forumGetUnreadForums(); -if (!$parent_list) +if (!$forumList) { $ns->tablerender(PAGE_NAME, "
".LAN_51.'
', array('forum', '51')); require_once(FOOTERF); @@ -223,7 +221,7 @@ if (!$parent_list) } $forum_string = ''; -foreach ($parent_list as $parent) +foreach ($forumList['parents'] as $parent) { $status = parse_parent($parent); $PARENTSTATUS = $status[0]; @@ -231,14 +229,13 @@ foreach ($parent_list as $parent) { $PARENTNAME = $parent['forum_name']; $forum_string .= preg_replace("/\{(.*?)\}/e", '$\1', $FORUM_MAIN_PARENT); - // $forums = $forum->forum_getforums($parent['forum_id']); - if (!count($forum_list[$parent['forum_id']])) + if (!count($forumList['forums'][$parent['forum_id']])) { $text .= "".LAN_52.""; } else { - foreach($forum_list[$parent['forum_id']] as $f) + foreach($forumList['forums'][$parent['forum_id']] as $f) { if ($f['forum_class'] == e_UC_ADMIN && ADMIN) { @@ -273,8 +270,8 @@ function parse_parent($parent) { if(check_class($parent['forum_class'])) { - $status[0]=""; - $status[1] = TRUE; + $status[0] = ''; + $status[1] = true; if(!check_class($parent['forum_postclass'])) { $status[0] = '( '.LAN_405.' )'; @@ -282,19 +279,20 @@ function parse_parent($parent) } else { - $status[1] = FALSE; + $status[1] = false; } return $status; } function parse_forum($f, $restricted_string = '') { - global $FORUM_MAIN_FORUM, $gen, $forum, $tp, $newflag_list, $sub_list; + global $FORUM_MAIN_FORUM, $gen, $forum, $newflag_list, $forumList; $e107 = e107::getInstance(); if(USER && is_array($newflag_list) && in_array($f['forum_id'], $newflag_list)) { - $NEWFLAG = "".IMAGE_new.""; + + $NEWFLAG = "".IMAGE_new.''; } else { @@ -305,58 +303,49 @@ function parse_forum($f, $restricted_string = '') { $f['forum_name'] = substr($f['forum_name'], 1); } - $f['forum_name'] = $tp -> toHTML($f['forum_name'], TRUE, 'no_hook'); - $f['forum_description'] = $tp -> toHTML($f['forum_description'], TRUE, 'no_hook'); - -// $e107->url->getUrl('forum', 'thread', array('func' => 'track'))) + $f['forum_name'] = $e107->tp->toHTML($f['forum_name'], true, 'no_hook'); + $f['forum_description'] = $e107->tp->toHTML($f['forum_description'], true, 'no_hook'); $FORUMNAME = "{$f['forum_name']}"; $FORUMDESCRIPTION = $f['forum_description'].($restricted_string ? "
$restricted_string" : ""); $THREADS = $f['forum_threads']; $REPLIES = $f['forum_replies']; - $FORUMSUBFORUMS = ""; + $FORUMSUBFORUMS = ''; - if(is_array($sub_list[$f['forum_parent']][$f['forum_id']])) + if(is_array($forumList['subs'][$f['forum_id']])) { - list($lastpost_datestamp, $lastpost_thread) = explode(".", $f['forum_lastpost_info']); - $ret = parse_subs($sub_list[$f['forum_parent']][$f['forum_id']], $lastpost_datestamp); + list($lastpost_datestamp, $lastpost_thread) = explode('.', $f['forum_lastpost_info']); + $ret = parse_subs($forumList['subs'][$f['forum_id']], $lastpost_datestamp); $FORUMSUBFORUMS = "
".FORLAN_444.": {$ret['text']}
"; $THREADS += $ret['threads']; $REPLIES += $ret['replies']; if(isset($ret['lastpost_info'])) { $f['forum_lastpost_info'] = $ret['lastpost_info']; + $f['forum_lastpost_user'] = $ret['lastpost_user']; + $f['forum_lastpost_user_anon'] = $ret['lastpost_user_anon']; $f['user_name'] = $ret['user_name']; } } - if ($f['forum_lastpost_user']) + if ($f['forum_lastpost_info']) { - list($lastpost_datestamp, $lastpost_thread) = explode(".", $f['forum_lastpost_info']); - $tmp = explode(".", $f['forum_lastpost_user'], 2); + list($lastpost_datestamp, $lastpost_thread) = explode('.', $f['forum_lastpost_info']); if ($f['user_name']) { - $lastpost_name = "{$f['user_name']}"; + + $lastpost_name = "{$f['user_name']}"; } else { - if(!$tmp[1]) - { - $lastpost_name = FORLAN_443; - } - else - { - $lastpost_name = $tp->toHTML($tmp[1]); - } + $lastpost_name = $e107->tp->toHTML($f['forum_lastpost_user_anon']); } $lastpost_datestamp = $gen->convert_date($lastpost_datestamp, 'forum'); -// $e107->url->getUrl('forum', 'thread', array('func' => 'last', 'id' => $lastpost_thread)); - $LASTPOST = $lastpost_datestamp.'
'.$lastpost_name." 'last', 'id' => $lastpost_thread))."'>".IMAGE_post2.''; } else { - $LASTPOST = "-"; + $LASTPOST = '-'; } return(preg_replace("/\{(.*?)\}/e", '$\1', $FORUM_MAIN_FORUM)); } @@ -365,7 +354,7 @@ function parse_subs($subList, $lastpost_datestamp) { $e107 = e107::getInstance(); $ret = array(); - $ret['text'] = ""; + $ret['text'] = ''; foreach($subList as $sub) { $ret['text'] .= ($ret['text'] ? ', ' : ''); @@ -377,6 +366,8 @@ function parse_subs($subList, $lastpost_datestamp) if($tmp[0] > $lastpost_datestamp) { $ret['lastpost_info'] = $sub['forum_lastpost_info']; + $ret['lastpost_user'] = $sub['forum_lastpost_user']; + $ret['lastpost_user_anon'] = $sub['lastpost_user_anon']; $ret['user_name'] = $sub['user_name']; $lastpost_datestamp = $tmp[0]; } @@ -386,12 +377,8 @@ function parse_subs($subList, $lastpost_datestamp) if (e_QUERY == 'track') { -// if(!USER) { return ; } if($trackedThreadList = $forum->getTrackedThreadList(USERID, 'list')) { - -// $sql2 = new db; -// $tmp = explode("-", USERREALM); $viewed = $forum->threadGetUserViewed(); $qry = " SELECT t.*, p.* from `#forum_thread` AS t @@ -488,12 +475,12 @@ require_once(FOOTERF); function forum_rules($action = 'check') { - global $tp, $sql, $ns; - if (ADMIN == TRUE) + $e107 = e107::getInstance(); + if (ADMIN == true) { $type = 'forum_rules_admin'; } - elseif(USER == TRUE) + elseif(USER == true) { $type = 'forum_rules_member'; } @@ -501,27 +488,18 @@ function forum_rules($action = 'check') { $type = 'forum_rules_guest'; } - $result = $sql->db_Select('generic', 'gen_chardata', "gen_type = '$type' AND gen_intdata = 1"); - if ($action == 'check') - { - if ($result) - { - return TRUE; - } - else - { - return FALSE; - } - } + $result = $e107->sql->db_Select('generic', 'gen_chardata', "gen_type = '$type' AND gen_intdata = 1"); + if ($action == 'check') { return $result; } + if ($result) { - $row = $sql->db_Fetch(); - $rules_text = $tp->toHTML($row['gen_chardata'], TRUE); + $row = $e107->sql->db_Fetch(); + $rules_text = $e107->tp->toHTML($row['gen_chardata'], true); } else { $rules_text = FORLAN_441; } - $ns->tablerender(LAN_433, "
{$rules_text}
", array('forum', 'forum_rules')); + $e107->ns->tablerender(LAN_433, "
{$rules_text}
", array('forum', 'forum_rules')); } ?> \ No newline at end of file diff --git a/e107_plugins/forum/forum_class.php b/e107_plugins/forum/forum_class.php index 84f16ac06..6364ddca5 100644 --- a/e107_plugins/forum/forum_class.php +++ b/e107_plugins/forum/forum_class.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_class.php,v $ -| $Revision: 1.27 $ -| $Date: 2008-12-15 00:29:20 $ +| $Revision: 1.28 $ +| $Date: 2008-12-17 04:22:37 $ | $Author: mcfly_e107 $ +----------------------------------------------------------------------------+ */ @@ -39,9 +39,9 @@ class e107forum $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_sticky'] = 'int'; $this->fieldTypes['forum_thread']['thread_forum_id'] = 'int'; - $this->fieldTypes['forum_thread']['thread_active'] = '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'; @@ -49,7 +49,6 @@ class e107forum $this->fieldTypes['forum']['forum_lastpost_user'] = 'int'; -// var_dump($this->permList); } function loadPermList() @@ -108,7 +107,6 @@ class e107forum } } } - //var_dump($this->permList); } @@ -188,8 +186,6 @@ class e107forum $threadInfo['_FIELD_TYPES'] = $this->fieldTypes['forum_thread']; $threadInfo['_FIELD_TYPES']['thread_total_replies'] = 'cmd'; -// var_dump($threadInfo); -// exit; $result = $e107->sql->db_Update('forum_thread', $threadInfo); } @@ -255,10 +251,7 @@ class e107forum $e107 = e107::getInstance(); $threadInfo['_FIELD_TYPES'] = $this->fieldTypes['forum_thread']; $threadInfo['WHERE'] = 'thread_id = '.(int)$threadId; -// var_dump($threadInfo); -// exit; $e107->sql->db_Update('forum_thread', $threadInfo); - //TODO: Add this } function postUpdate($postId, $postInfo) @@ -383,12 +376,12 @@ class e107forum $e107 = e107::getInstance(); if($uid == USERID) { - $viewed = $e107->currentUser['plugin_forum_user_viewed']; + $viewed = $e107->currentUser['user_plugin_forum_viewed']; } else { $tmp = get_user_data($uid); - $viewed = $tmp['plugin_forum_user_viewed']; + $viewed = $tmp['user_plugin_forum_viewed']; unset($tmp); } return explode(',', $viewed); @@ -467,28 +460,6 @@ class e107forum return $e107->sql->db_Count('forum_post', '(*)', "WHERE post_id <= {$postId} AND post_thread = {$threadId} ORDER BY post_id ASC"); } - - function thread_postnum($thread_id) - { - global $sql; - $ret = array(); - $ret['parent'] = $thread_id; - $query = " - SELECT ft.thread_id, fp.thread_id as parent - FROM #forum_t AS t - LEFT JOIN #forum_t AS ft ON ft.thread_parent = t.thread_parent AND ft.thread_id <= ".intval($thread_id)." - LEFT JOIN #forum_t as fp ON fp.thread_id = t.thread_parent - WHERE t.thread_id = ".intval($thread_id)." AND t.thread_parent != 0 - ORDER BY ft.thread_datestamp ASC - "; - if($ret['post_num'] = $sql->db_Select_gen($query)) - { - $row = $sql->db_Fetch(MYSQL_ASSOC); - $ret['parent'] = $row['parent']; - } - return $ret; - } - function forumUpdateLastpost($type, $id, $update_threads = FALSE) { global $sql, $tp; @@ -525,7 +496,6 @@ class e107forum } foreach($parentList as $id) { - // echo "Updating forum #{$id}
"; $this->update_lastpost('forum', $id, $update_threads); } } @@ -563,37 +533,53 @@ class e107forum } } - function forum_markasread($forum_id) + function forumMarkAsRead($forum_id) { - global $sql; - if ($forum_id != 'all') - { - $forum_id = intval($forum_id); - $extra = " AND thread_forum_id={$forum_id}"; - } - $qry = "thread_lastpost > ".USERLV." AND thread_parent = 0 {$extra} "; - if ($sql->db_Select('forum_t', 'thread_id', $qry)) - { - while ($row = $sql->db_Fetch(MYSQL_ASSOC)) + $e107 = e107::getInstance(); + $extra = ''; + $newIdList = array(); + if ($forum_id !== 0) { - $u_new .= $row['thread_id']."."; + $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)"; } - $u_new .= USERVIEWED; - $t = array_unique(explode('.',$u_new)); // Filter duplicates - $u_new = implode('.',$t); - $sql->db_Update('user', "user_viewed='{$u_new}' WHERE user_id=".USERID); - header("location:".e_SELF); + $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(); - $threadId = (int)$threadId; $_tmp = preg_split('#\,+#', $currentUser['user_plugin_forum_viewed']); - $_tmp[] = $threadId; + 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); @@ -602,7 +588,7 @@ class e107forum function forum_getparents() { global $sql; - if ($sql->db_Select('forum', '*', "forum_parent=0 ORDER BY forum_order ASC")) + if ($sql->db_Select('forum', '*', 'forum_parent=0 ORDER BY forum_order ASC')) { while ($row = $sql->db_Fetch(MYSQL_ASSOC)) { $ret[] = $row; @@ -612,7 +598,7 @@ class e107forum return FALSE; } - function forum_getmods($uclass = e_UC_ADMIN) + function forumGetMods($uclass = e_UC_ADMIN) { $e107 = e107::getInstance(); if($uclass == e_UC_ADMIN || trim($uclass) == '') @@ -630,6 +616,38 @@ class e107forum return $ret; } + 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; @@ -689,32 +707,33 @@ class e107forum return false; } - - function forum_newflag_list() + /** + * 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 - global $sql; - $viewed = ""; - if(USERVIEWED) + 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 = preg_replace("#\.+#", ".", USERVIEWED); - $viewed = preg_replace("#^\.#", "", $viewed); - $viewed = preg_replace("#\.$#", "", $viewed); - $viewed = str_replace(".", ",", $viewed); - } - if($viewed != "") - { - $viewed = " AND thread_id NOT IN (".$viewed.")"; + $viewed = " AND thread_id NOT IN (".$e107->currentUser['user_plugin_forum_viewed'].")"; } - $_newqry = " - SELECT DISTINCT ff.forum_sub, ft.thread_forum_id FROM #forum_t AS ft - LEFT JOIN #forum AS ff ON ft.thread_forum_id = ff.forum_id - WHERE thread_parent = 0 AND thread_lastpost > ".USERLV." {$viewed} - "; - if($sql->db_Select_gen($_newqry)) + $_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 = $sql->db_Fetch(MYSQL_ASSOC)) + while($row = $e107->sql->db_Fetch(MYSQL_ASSOC)) { $ret[] = $row['thread_forum_id']; if($row['forum_sub']) @@ -726,7 +745,7 @@ class e107forum } else { - return FALSE; + return false; } } @@ -823,19 +842,6 @@ class e107forum return $ret; } - function thread_update($thread_id, $newvals) - { - global $sql, $tp; - foreach($newvals as $var => $val) - { - $var = $tp -> toDB($var); - $val = $tp -> toDB($val); - $newvalArray[] = "{$var} = '{$val}'"; - } - $newString = implode(', ', $newvalArray)." WHERE thread_id=".intval($thread_id); - return $sql->db_Update('forum_t', $newString); - } - function forumGetThreads($forumId, $from, $view) { $e107 = e107::getInstance(); @@ -921,202 +927,13 @@ class e107forum return false; } - function thread_getprev($thread_id, $forum_id, $from = 0, $limit = 100) - { - global $sql; - $forum_id = intval($forum_id); - global $sql; - $ftab = MPREFIX.'forum_t'; - while (!$found) - { - $qry = " - SELECT t.thread_id from #forum_t AS t - WHERE t.thread_forum_id = $forum_id - AND t.thread_parent = 0 - ORDER BY - t.thread_sticky DESC, - t.thread_lastpost DESC, - t.thread_datestamp DESC - LIMIT ".intval($from).",".intval($limit); - if ($sql->db_Select_gen($qry)) - { - $i = 0; - while ($row = $sql->db_Fetch(MYSQL_ASSOC)) - { - $threadList[$i++] = $row['thread_id']; - } - - if (($id = array_search($thread_id, $threadList)) !== FALSE) - { - if ($id != 0) - { - return $threadList[$id-1]; - } - else - { - if ($from == 0) - { - return FALSE; - } - return $this->thread_getprev($thread_id, $forum_id, $from-1, 2); - } - } - } - else - { - return FALSE; - } - $from += 100; - } - } - - function thread_get($thread_id, $start = 0, $limit = 10) - { - $thread_id = intval($thread_id); - global $sql; - $ftab = MPREFIX.'forum_t'; - $utab = MPREFIX.'user'; - - if ($start === "last") - { - $tcount = $this->thread_count($thread_id); - $start = max(0, $tcount-$limit); - } - $start = max(0, $start); - if ($start != 0) - { - $array_start = 0; - } - else - { - $limit--; - $array_start = 1; - } - $sortdir = "ASC"; - - $qry = " - SELECT t.*, u.*, ue.* FROM #forum_t as t - LEFT JOIN #user AS u - ON SUBSTRING_INDEX(t.thread_user,'.',1) = u.user_id - LEFT JOIN #user_extended AS ue - ON SUBSTRING_INDEX(t.thread_user,'.',1) = ue.user_extended_id - WHERE t.thread_parent = $thread_id - ORDER by t.thread_datestamp {$sortdir} - LIMIT ".intval($start).",".intval($limit); - $ret = array(); - if ($sql->db_Select_gen($qry)) - { - $i = $array_start; - while ($row = $sql->db_Fetch(MYSQL_ASSOC)) - { - $ret[$i] = $row; - $i++; - } - } - $qry = " - SELECT t.*,u.*,ue.* from #forum_t AS t - LEFT JOIN #user AS u - ON SUBSTRING_INDEX(t.thread_user,'.',1) = u.user_id - LEFT JOIN #user_extended AS ue - ON SUBSTRING_INDEX(t.thread_user,'.',1) = ue.user_extended_id - WHERE t.thread_id = $thread_id - LIMIT 0,1 - "; - if ($sql->db_Select_gen($qry)) - { - $row = $sql->db_Fetch(MYSQL_ASSOC); - $ret['head'] = $row; - if (!array_key_exists(0, $ret)) - { - $ret[0] = $row; - } - } - return $ret; - } - - function thread_count($thread_id) - { - $thread_id = intval($thread_id); - global $sql; - return $sql->db_Count('forum_t', '(*)', "WHERE thread_parent = $thread_id")+1; - } - - function thread_count_list($thread_list) - { - global $sql, $tp; - $qry = " - SELECT t.thread_parent, t.COUNT(*) as thread_replies - FROM #forum_t AS t - WHERE t.thread_parent - IN ".$tp -> toDB($thread_list, true)." - GROUP BY t.thread_parent - "; - if ($sql->db_Select_gen($qry)) - { - while ($row = $sql->db_Fetch(MYSQL_ASSOC)) - { - $ret[$row['thread_parent']] = $row['thread_replies']; - } - } - return $ret; - } - function threadIncView($id) { $e107 = e107::getInstance(); - $id = (int)($id); + $id = (int)$id; return $e107->sql->db_Update('forum_thread', 'thread_views=thread_views+1 WHERE thread_id='.$id); } - - function thread_get_postinfo($thread_id, $head = FALSE) - { - $thread_id = intval($thread_id); - global $sql; - $ret = array(); - $qry = " - SELECT t.*, u.user_name, u.user_id, u.user_email from #forum_t AS t - LEFT JOIN #user AS u - ON SUBSTRING_INDEX(t.thread_user,'.',1) = u.user_id - WHERE t.thread_id = $thread_id - LIMIT 0,1 - "; - if ($sql->db_Select_gen($qry)) - { - $ret[0] = $sql->db_Fetch(MYSQL_ASSOC); - } - else - { - return FALSE; - } - if ($head == FALSE) - { - return $ret; - } - $parent_id = $ret[0]['thread_parent']; - if ($parent_id == 0) - { - $ret['head'] = $ret[0]; - } - else - { - $qry = " - SELECT t.*, u.user_name, u.user_id from #forum_t AS t - LEFT JOIN #user AS u - ON SUBSTRING_INDEX(t.thread_user,'.',1) = u.user_id - WHERE t.thread_id = ".intval($parent_id)." - LIMIT 0,1 - "; - if ($sql->db_Select_gen($qry)) - { - $row = $sql->db_Fetch(MYSQL_ASSOC); - $ret['head'] = $row; - } - } - return $ret; - } - - function _forum_lp_update($lp_type, $lp_user, $lp_info, $lp_forum_id, $lp_forum_sub) { global $sql; @@ -1127,98 +944,6 @@ class e107forum } } - function thread_insert($thread_name, $thread_thread, $thread_forum_id, $thread_parent, $thread_poster, $thread_active, $thread_sticky, $forum_sub) - { - $post_time = time(); - global $sql, $tp, $pref, $e107; - $forum_sub = intval($forum_sub); - $ip = $e107->getip(); - //Check for duplicate post - if ($sql->db_Count('forum_t', '(*)', "WHERE thread_thread='{$thread_thread}' and thread_datestamp > ".($post_time - 180))) - { - return -1; - } - - $post_user = $thread_poster['post_userid'].".".$thread_poster['post_user_name']; - $thread_post_user = $post_user; - if($thread_poster['post_userid'] == 0) - { - $thread_post_user = $post_user.chr(1).$ip; - } - - $post_last_user = ($thread_parent ? "" : $post_user); - $vals = "'0', '{$thread_name}', '{$thread_thread}', '".intval($thread_forum_id)."', '".intval($post_time)."', '".intval($thread_parent)."', '{$thread_post_user}', '0', '".intval($thread_active)."', '$post_time', '$thread_sticky', '0', '{$post_last_user}', '0'"; - $newthread_id = $sql->db_Insert('forum_t', $vals); - if(!$newthread_id) - { - echo "thread creation failed!
- Values sent were: ".htmlentities($vals)."

Please save these values for dev team for troubleshooting."; - exit; - } - - // Increment user thread count and set user as viewed this thread - if (USER) - { - $new_userviewed = USERVIEWED.".".($thread_parent ? intval($thread_parent) : $newthread_id); - $sql->db_Update('user', "user_forums=user_forums+1, user_viewed='{$new_userviewed}' WHERE user_id='".USERID."' "); - } - - //If post is a reply - if ($thread_parent) - { - $forum_lp_info = $post_time.".".intval($thread_parent); - $gen = new convert; - // Update main forum with last post info and increment reply count - $this->_forum_lp_update("forum_replies", $post_user, $forum_lp_info, $thread_forum_id, $forum_sub); - - // Update head post with last post info and increment reply count - $sql->db_Update('forum_t', "thread_lastpost={$post_time}, thread_lastuser='{$post_user}', thread_total_replies=thread_total_replies+1 WHERE thread_id = ".intval($thread_parent)); - - $parent_thread = $this->thread_get_postinfo($thread_parent); - global $PLUGINS_DIRECTORY; - $thread_name = $tp->toText($parent_thread[0]['thread_name']); - $datestamp = $gen->convert_date($post_time, "long"); - $email_post = $tp->toHTML($thread_thread, TRUE); - $mail_link = "".SITEURL.$PLUGINS_DIRECTORY."forum/forum_viewtopic.php?".$thread_parent.".last"; - if(!isset($pref['forum_eprefix'])) - { - $pref['forum_eprefix'] = "[forum]"; - } - // Send email to originator if 'notify' set - $email_addy = ''; - if ($pref['email_notify'] && $parent_thread[0]['thread_active'] == 99 && $parent_thread[0]['user_id'] != USERID) - { - $gen = new convert; - $email_name = $parent_thread[0]['user_name']; - $email_addy = $parent_thread[0]['user_email']; - $message = LAN_384.SITENAME.".

". LAN_382.$datestamp."
". LAN_94.": ".$thread_poster['post_user_name']."

". LAN_385.$email_post."

". LAN_383."

".$mail_link; - include_once(e_HANDLER."mail.php"); - sendemail($email_addy, $pref['forum_eprefix']." '".$thread_name."', ".LAN_381.SITENAME, $message, $email_name); - } - - - // Send email to all users tracking thread - except the one that's just posted - if ($pref['forum_track'] && $sql->db_Select("user", "user_id, user_email, user_name", "user_realm REGEXP('-".intval($thread_parent)."-') ")) - { - include_once(e_HANDLER.'mail.php'); - $message = LAN_385.SITENAME.".

". LAN_382.$datestamp."
". LAN_94.": ".$thread_poster['post_user_name']."

". LAN_385.$email_post."

". LAN_383."

".$mail_link; - while ($row = $sql->db_Fetch(MYSQL_ASSOC)) - { // Don't sent to self, nor to originator of thread if they've got 'notify' set - if ($row['user_email'] && ($row['user_email'] != $email_addy) && ($row['user_id'] != USERID)) // (May be wrong, but this could be faster than filtering current user in the query) - { - sendemail($row['user_email'], $pref['forum_eprefix']." '".$thread_name."', ".LAN_381.SITENAME, $message, $row['user_name']); - } - } - } - } - else - { - //post is a new thread - $forum_lp_info = $post_time.".".$newthread_id; - $this->_forum_lp_update("forum_threads", $post_user, $forum_lp_info, $thread_forum_id, $forum_sub); - } - return $newthread_id; - } function post_getnew($count = 50, $userviewed = USERVIEWED) { diff --git a/e107_plugins/forum/forum_conf.php b/e107_plugins/forum/forum_conf.php index fc1851e6b..6e60853a4 100644 --- a/e107_plugins/forum/forum_conf.php +++ b/e107_plugins/forum/forum_conf.php @@ -11,20 +11,27 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_conf.php,v $ -| $Revision: 1.3 $ -| $Date: 2007-09-26 19:28:47 $ -| $Author: e107steved $ +| $Revision: 1.4 $ +| $Date: 2008-12-17 04:22:37 $ +| $Author: mcfly_e107 $ +---------------------------------------------------------------+ */ -require_once("../../class2.php"); -@include_once e_PLUGIN.'forum/languages/'.e_LANGUAGE.'/lan_forum_conf.php'; -@include_once e_PLUGIN.'forum/languages/English/lan_forum_conf.php'; +require_once('../../class2.php'); +require_once(e_PLUGIN.'forum/forum_class.php'); +$forum = new e107forum; + +include_lan(e_PLUGIN.'forum/languages/English/lan_forum_conf.php'); $e_sub_cat = 'forum'; -$qs = explode(".", e_QUERY); -$action = $qs[0]; -$thread_id = intval($qs[1]); +if(!USER || !isset($_GET['f']) || !isset($_GET['id'])) +{ + header('location:'.$e107->url->getUrl('core:core', 'main', 'action=index')); + exit; +} + +$id = (int)$_GET['id']; +$action = $_GET['f']; $qry = " SELECT t.*, f.*, fp.forum_id AS forum_parent_id FROM #forum_t as t @@ -33,18 +40,16 @@ LEFT JOIN #forum AS fp ON fp.forum_id = f.forum_parent WHERE t.thread_id = {$thread_id} "; -if($sql->db_Select_gen($qry)) +$threadInfo = $forum->threadGet($id); +$modList = $forum->forumGetMods($threadInfo->forum_moderators); + +//var_dump($threadInfo); +//var_dump($modList); + +//If user is not a moderator of indicated forum, redirect to index page +if(!in_array(USERID, array_keys($modList))) { - $info=$sql->db_Fetch(); - if(!check_class($info['forum_moderators'])) - { - header("location:".e_BASE."index.php"); - exit; - } -} -else -{ - header("location:".e_BASE."index.php"); + header('location:'.$e107->url->getUrl('core:core', 'main', 'action=index')); exit; } @@ -127,10 +132,11 @@ if ($action == "delete_poll") exit; } -if ($action == "move") +if ($action == 'move') { + $postInfo = $forum->postGet($id, 0, 1); $text = " -
+
@@ -139,29 +145,26 @@ if ($action == "move") @@ -170,7 +173,7 @@ if ($action == "move") @@ -183,8 +186,8 @@ if ($action == "move")

".FORLAN_32."
".FORLAN_28."
- ".FORLAN_29." [".FORLAN_27."] ".FORLAN_30."
+ ".FORLAN_29.' ['.FORLAN_27.'] '.FORLAN_30."
".FORLAN_31."

"; - $text = $ns->tablerender($tp->toHTML($info['thread_name']), $tp->toHTML($info['thread_thread']), '', TRUE).$ns->tablerender("", $text, '', true); - $ns->tablerender(FORLAN_25, $text); + $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(FORLAN_25, $text); } require_once(FOOTERF); diff --git a/e107_plugins/forum/forum_shortcodes.php b/e107_plugins/forum/forum_shortcodes.php index d06fcd8d2..35064835b 100644 --- a/e107_plugins/forum/forum_shortcodes.php +++ b/e107_plugins/forum/forum_shortcodes.php @@ -244,12 +244,7 @@ SC_BEGIN REPORTIMG global $postInfo, $page; if (USER) { $e107 = e107::getInstance(); - $tmp = array ( - 'func' => 'report', - 'id' => $postInfo['post_thread'], - 'report' => $postInfo['post_id'] - ); - return "".IMAGE_report.' '; + return "".IMAGE_report.' '; } SC_END diff --git a/e107_plugins/forum/forum_viewforum.php b/e107_plugins/forum/forum_viewforum.php index 37ecedd04..1e97881c8 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.10 $ -* $Date: 2008-12-15 00:29:20 $ +* $Revision: 1.11 $ +* $Date: 2008-12-17 04:22:37 $ * $Author: mcfly_e107 $ * */ @@ -57,6 +57,8 @@ if (!$forum->checkPerm($forumId, 'view')) } $forumInfo = $forum->forum_get($forumId); +$threadsViewed = $forum->threadGetUserViewed(); + //var_dump($forumInfo); @@ -84,7 +86,7 @@ define('e_PAGETITLE', LAN_01.' / '.$_forum_name); //define('MODERATOR', $forum_info['forum_moderators'] != '' && check_class($forum_info['forum_moderators'])); //$modArray = $forum->forum_getmods($forum_info['forum_moderators']); -$modArray = $forum->forum_getmods($thread->forum_info['forum_moderators']); +$modArray = $forum->forumGetMods($thread->forum_info['forum_moderators']); define('MODERATOR', (USER && is_array($modArray) && in_array(USERID, array_keys($modArray)))); $message = ''; @@ -217,7 +219,7 @@ $gen = new convert; $SUBFORUMS = ''; if(is_array($subList) && isset($subList[$forumInfo['forum_parent']][$forumId])) { - $newflag_list = $forum->forum_newflag_list(); + $newflag_list = $forum->forumGetUnreadForums(); $sub_info = ''; foreach($subList[$forumInfo['forum_parent']][$forumId] as $sub) { @@ -313,7 +315,7 @@ require_once(FOOTERF); function parse_thread($thread_info) { - global $forum, $FORUM_VIEW_FORUM, $FORUM_VIEW_FORUM_STICKY, $FORUM_VIEW_FORUM_ANNOUNCE, $gen, $pref, $forum_id, $menu_pref; + global $forum, $FORUM_VIEW_FORUM, $FORUM_VIEW_FORUM_STICKY, $FORUM_VIEW_FORUM_ANNOUNCE, $gen, $pref, $menu_pref, $threadsViewed; $e107 = e107::getInstance(); $text = ''; @@ -345,14 +347,7 @@ function parse_thread($thread_info) $LASTPOST .= '
'.$lastpost_datestamp; } - $newflag = false; - if (USER) - { - if ($thread_info['thread_lastpost'] > USERLV && !$forum->threadViewed($thread_info['thread_id'])) - { - $newflag = true; - } - } + $newflag = (USER && $thread_info['thread_lastpost'] > USERLV && !in_array($thread_info['thread_id'], $threadsViewed)); $THREADDATE = $gen->convert_date($thread_info['thread_datestamp'], 'forum'); $ICON = ($newflag ? IMAGE_new : IMAGE_nonew); @@ -501,7 +496,8 @@ 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.""; + + $NEWFLAG = "".IMAGE_new.''; } else { diff --git a/e107_plugins/forum/forum_viewtopic.php b/e107_plugins/forum/forum_viewtopic.php index be19573c1..3f3c24b64 100644 --- a/e107_plugins/forum/forum_viewtopic.php +++ b/e107_plugins/forum/forum_viewtopic.php @@ -12,8 +12,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_viewtopic.php,v $ -| $Revision: 1.16 $ -| $Date: 2008-12-15 00:29:20 $ +| $Revision: 1.17 $ +| $Date: 2008-12-17 04:22:37 $ | $Author: mcfly_e107 $ +----------------------------------------------------------------------------+ */ @@ -74,7 +74,7 @@ if (USER && (USERID != $threadInfo['thread_user'] || $threadInfo['thread_total_r } 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')); -$modArray = $forum->forum_getmods($thread->threadInfo['forum_moderators']); +$modArray = $forum->forumGetMods($thread->threadInfo['forum_moderators']); define('MODERATOR', (USER && is_array($modArray) && in_array(USERID, array_keys($modArray)))); if (MODERATOR && isset($_POST['mod'])) @@ -86,7 +86,6 @@ if (MODERATOR && isset($_POST['mod'])) $postList = $forum->PostGet($thread->threadId, $thread->page * $thread->perPage, $thread->perPage); -//var_dump($thread->threadInfo); require_once (e_HANDLER . 'level_handler.php'); $gen = new convert; if ($thread->message) @@ -144,7 +143,6 @@ if ($pref['forum_track'] && USER)