/** * Mark a particular thread as read for the current user. * * @param int The thread ID * @param int The forum ID of the thread */ function mark_thread_read($tid, $fid) { global $mybb, $db; // Can only do "true" tracking for registered users if ($mybb->settings['threadreadcut'] > 0 && $mybb->user['uid']) { // For registered users, store the information in the database. switch ($db->type) { case "pgsql": case "sqlite2": case "sqlite3": $db->shutdown_query($db->build_replace_query("threadsread", array('tid' => $tid, 'uid' => $mybb->user['uid'], 'dateline' => TIME_NOW), "tid")); break; default: $db->write_query("\n\t\t\t\t\tREPLACE INTO " . TABLE_PREFIX . "threadsread (tid, uid, dateline)\n\t\t\t\t\tVALUES('{$tid}', '{$mybb->user['uid']}', '" . TIME_NOW . "')\n\t\t\t\t"); } // Fetch ALL of the child forums of this forum $forums = get_child_list($fid); $forums[] = $fid; $forums = implode(",", $forums); $unread_count = fetch_unread_count($forums); if ($unread_count == 0) { mark_forum_read($fid); } } else { my_set_array_cookie("threadread", $tid, TIME_NOW); } }
/** * Mark a particular thread as read for the current user. * * @param int The thread ID * @param int The forum ID of the thread */ function mark_thread_read($tid, $fid, $mark_time = 0) { global $mybb, $db; // START - Unread posts MOD // Disable mark read if not needed if (function_exists("unreadPosts_is_installed") && unreadPosts_is_installed()) { // For idiots who can't use hooks if (THIS_SCRIPT != 'newreply.php' && THIS_SCRIPT != 'newthread.php' && THIS_SCRIPT != 'showthread.php') { $mark_time = TIME_NOW; } if (!$mark_time || !$mybb->user['uid'] || !$mybb->settings['threadreadcut']) { return; } switch ($db->type) { case "pgsql": case "sqlite": $db->replace_query("threadsread", array('tid' => $tid, 'uid' => $mybb->user['uid'], 'dateline' => $mark_time), array("tid", "uid")); break; default: $db->write_query("\n REPLACE INTO " . TABLE_PREFIX . "threadsread (tid, uid, dateline)\n VALUES('{$tid}', '{$mybb->user['uid']}', '{$mark_time}')\n "); } $unread_count = fetch_unread_count($fid); if ($unread_count == 0) { mark_forum_read($fid); } return; } // END - Unread posts MOD // Can only do "true" tracking for registered users if ($mybb->settings['threadreadcut'] > 0 && $mybb->user['uid']) { // For registered users, store the information in the database. switch ($db->type) { case "pgsql": case "sqlite": $db->replace_query("threadsread", array('tid' => $tid, 'uid' => $mybb->user['uid'], 'dateline' => TIME_NOW), array("tid", "uid")); break; default: $db->write_query("\n REPLACE INTO " . TABLE_PREFIX . "threadsread (tid, uid, dateline)\n VALUES('{$tid}', '{$mybb->user['uid']}', '" . TIME_NOW . "')\n "); } } else { my_set_array_cookie("threadread", $tid, TIME_NOW, -1); } $unread_count = fetch_unread_count($fid); if ($unread_count == 0) { mark_forum_read($fid); } }
function mark_all_as_read_func($xmlrpc_params) { global $db, $lang, $theme, $plugins, $mybb, $session, $settings, $cache, $time, $mybbgroups, $forum_cache; $input = Tapatalk_Input::filterXmlInput(array('forum_id' => Tapatalk_Input::INT), $xmlrpc_params); if (!empty($input['forum_id'])) { $validforum = get_forum($input['forum_id']); if (!$validforum) { return xmlrespfalse('Invalid forum'); } require_once MYBB_ROOT . "/inc/functions_indicators.php"; mark_forum_read($input['forum_id']); } else { require_once MYBB_ROOT . "/inc/functions_indicators.php"; mark_all_forums_read(); } return xmlresptrue(); }
/** * Marks a thread as read using the appropriate method. * * @param array Array of data for the thread being marked * @param array Array of data for the forum the thread is in * @param integer User ID this thread is being marked read for * @param integer Unix timestamp that the thread is being marked read */ function mark_thread_read(&$threadinfo, &$foruminfo, $userid, $time) { global $vbulletin, $db; $userid = intval($userid); $time = intval($time); if ($vbulletin->options['threadmarking'] AND $userid) { // can't be shutdown as we do a read query below on this table $db->query_write(" REPLACE INTO " . TABLE_PREFIX . "threadread (threadid, userid, readtime) VALUES ($threadinfo[threadid], $userid, $time) "); } else { set_bbarray_cookie('thread_lastview', $threadinfo['threadid'], $time); } // now if applicable search to see if this was the last thread requiring marking in this forum if ($vbulletin->options['threadmarking'] == 2 AND $userid) { // forum can only be marked as read if all the children are read as well, // so determine which children "count" if ($foruminfo['childlist'] AND $userid == $vbulletin->userinfo['userid']) { $children = '-1'; foreach (explode(',', $foruminfo['childlist']) AS $child_forum) { $child_forum = intval($child_forum); $forumperms = $vbulletin->userinfo['forumpermissions']["$child_forum"]; if (empty($forumperms) OR !($forumperms & $vbulletin->bf_ugp_forumpermissions['canview']) OR !($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewthreads']) OR !($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewothers'])) { // invalid forum, can't be viewed, can't view threads, can't view others threads // means we can't include this when trying to mark a thread as read continue; } $children .= ',' . $child_forum; } } else { $children = $threadinfo['forumid']; } $cutoff = TIMENOW - ($vbulletin->options['markinglimit'] * 86400); $unread = $db->query_first(" SELECT COUNT(*) AS count FROM " . TABLE_PREFIX . "thread AS thread LEFT JOIN " . TABLE_PREFIX . "threadread AS threadread ON (threadread.threadid = thread.threadid AND threadread.userid = $userid) LEFT JOIN " . TABLE_PREFIX . "forumread AS forumread ON (forumread.forumid = thread.forumid AND forumread.userid = $userid) WHERE thread.forumid IN ($children) AND thread.visible = 1 AND thread.sticky IN (0,1) AND thread.lastpost > IF(threadread.readtime IS NULL, $cutoff, threadread.readtime) AND thread.lastpost > IF(forumread.readtime IS NULL, $cutoff, forumread.readtime) AND thread.lastpost > $cutoff AND thread.open <> 10 "); if ($unread['count'] == 0) { mark_forum_read($foruminfo, $userid, TIMENOW); } } }
$foruminfo['bottomcolspan']++; } $show['threadslist'] = true; ///////////////////////////////// } // end forum can contain threads else { $show['threadslist'] = false; } ///////////////////////////////// if (!$vbulletin->GPC['prefixid'] AND $newthreads < 1 AND $unreadchildforums < 1) { mark_forum_read($foruminfo, $vbulletin->userinfo['userid'], TIMENOW); } $forumhome_markread_script = vB_Template::create('forumhome_markread_script')->render(); construct_forum_rules($foruminfo, $forumperms); // Revisit this at a later date as it can be made to work with each SEO option $show['displayoptions'] = (!$vbulletin->options['friendlyurl']); $show['forumsearch'] = (!$show['search_engine'] AND $forumperms & $vbulletin->bf_ugp_forumpermissions['cansearch'] AND $vbulletin->options['enablesearches']); $show['forumslist'] = $forumshown ? true : false; $show['stickies'] = ($threadbits_sticky != ''); $show['optionbox'] = ($show['moderators'] OR $show['activeusers'] OR $show['displayoptions']); $ad_location['forum_below_threadlist'] = vB_Template::create('ad_forum_below_threadlist')->render();
/** * Marks a forum, its child forums and all contained posts as read * * @param integer Forum ID to be marked as read - leave blank to mark all forums as read * * @return array Array of affected forum IDs */ function mark_forums_read($forumid = false) { global $vbulletin; $db =& $vbulletin->db; $return_url = $vbulletin->options['forumhome'] . '.php' . $vbulletin->session->vars['sessionurl_q']; $return_phrase = 'markread'; $return_forumids = array(); if (!$forumid) { if ($vbulletin->userinfo['userid']) { // init user data manager $userdata =& datamanager_init('User', $vbulletin, ERRTYPE_STANDARD); $userdata->set_existing($vbulletin->userinfo); $userdata->set('lastactivity', TIMENOW); $userdata->set('lastvisit', TIMENOW - 1); $userdata->save(); if ($vbulletin->options['threadmarking']) { $query = ''; foreach ($vbulletin->forumcache as $fid => $finfo) { // mark the forum and all child forums read $query .= ", ({$fid}, " . $vbulletin->userinfo['userid'] . ", " . TIMENOW . ")"; } if ($query) { $query = substr($query, 2); $db->query_write("\n\t\t\t\t\t\tREPLACE INTO " . TABLE_PREFIX . "forumread\n\t\t\t\t\t\t\t(forumid, userid, readtime)\n\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t\t{$query}\n\t\t\t\t\t"); } } } else { vbsetcookie('lastvisit', TIMENOW); } $return_forumids = array_keys($vbulletin->forumcache); } else { // temp work around code, I need to find another way to mass set some values to the cookie $vbulletin->input->clean_gpc('c', COOKIE_PREFIX . 'forum_view', TYPE_STR); global $bb_cache_forum_view; $bb_cache_forum_view = @unserialize(convert_bbarray_cookie($vbulletin->GPC[COOKIE_PREFIX . 'forum_view'])); require_once DIR . '/includes/functions_misc.php'; $childforums = fetch_child_forums($forumid, 'ARRAY'); $return_forumids = $childforums; $return_forumids[] = $forumid; if ($vbulletin->options['threadmarking'] and $vbulletin->userinfo['userid']) { $query = "({$forumid}, " . $vbulletin->userinfo['userid'] . ", " . TIMENOW . ")"; foreach ($childforums as $child_forumid) { // mark the forum and all child forums read $query .= ", ({$child_forumid}, " . $vbulletin->userinfo['userid'] . ", " . TIMENOW . ")"; } $db->query_write("\n\t\t\t\tREPLACE INTO " . TABLE_PREFIX . "forumread\n\t\t\t\t\t(forumid, userid, readtime)\n\t\t\t\tVALUES\n\t\t\t\t\t{$query}\n\t\t\t"); require_once DIR . '/includes/functions_bigthree.php'; $foruminfo = fetch_foruminfo($forumid); $parent_marks = mark_forum_read($foruminfo, $vbulletin->userinfo['userid'], TIMENOW); if (is_array($parent_marks)) { $return_forumids = array_unique(array_merge($return_forumids, $parent_marks)); } } else { foreach ($childforums as $child_forumid) { // mark the forum and all child forums read $bb_cache_forum_view["{$child_forumid}"] = TIMENOW; } set_bbarray_cookie('forum_view', $forumid, TIMENOW); } if ($vbulletin->forumcache["{$forumid}"]['parentid'] == -1) { $return_url = $vbulletin->options['forumhome'] . '.php' . $vbulletin->session->vars['sessionurl_q']; } else { $return_url = 'forumdisplay.php?' . $vbulletin->session->vars['sessionurl'] . 'f=' . $vbulletin->forumcache["{$forumid}"]['parentid']; } $return_phrase = 'markread_single'; } return array('url' => $return_url, 'phrase' => $return_phrase, 'forumids' => $return_forumids); }
if ($mybb->user['uid'] && verify_post_check($mybb->get_input('my_post_key'), true) !== true) { // Protect our user's unread forums from CSRF error($lang->invalid_post_code); } if (isset($mybb->input['fid'])) { $validforum = get_forum($mybb->input['fid']); if (!$validforum) { if (!isset($mybb->input['ajax'])) { error($lang->error_invalidforum); } else { echo 0; exit; } } require_once MYBB_ROOT . "/inc/functions_indicators.php"; mark_forum_read($mybb->input['fid']); $plugins->run_hooks("misc_markread_forum"); if (!isset($mybb->input['ajax'])) { redirect(get_forum_link($mybb->input['fid']), $lang->redirect_markforumread); } else { echo 1; exit; } } else { $plugins->run_hooks("misc_markread_end"); require_once MYBB_ROOT . "/inc/functions_indicators.php"; mark_all_forums_read(); redirect("index.php", $lang->redirect_markforumsread); } } elseif ($mybb->input['action'] == "clearpass") { $plugins->run_hooks("misc_clearpass");
function get_topic_func($xmlrpc_params) { global $db, $lang, $theme, $plugins, $mybb, $session, $settings, $time, $mybbgroups; $lang->load("member"); $parser = new postParser(); $input = Tapatalk_Input::filterXmlInput(array('forum_id' => Tapatalk_Input::INT, 'start_num' => Tapatalk_Input::INT, 'last_num' => Tapatalk_Input::INT, 'mode' => Tapatalk_Input::STRING), $xmlrpc_params); $lang->load("forumdisplay"); $fid = $input['forum_id']; $foruminfo = get_forum($fid); if (!$foruminfo) { return xmlrespfalse($lang->error_invalidforum); } list($start, $limit) = process_page($input['start_num'], $input['last_num']); $forumpermissions = forum_permissions(); $fpermissions = $forumpermissions[$fid]; if ($fpermissions['canview'] != 1) { return tt_no_permission(); } switch ($input['mode']) { case 'TOP': $stickyonly = " AND sticky=1 "; $tstickyonly = " AND t.sticky=1 "; break; case 'ANN': return get_announcement_list($foruminfo, $fid); break; default: $stickyonly = " AND sticky=0 "; $tstickyonly = " AND t.sticky=0 "; break; } if ($mybb->user['uid'] == 0) { // Build a forum cache. $query = $db->query("\n SELECT *\n FROM " . TABLE_PREFIX . "forums\n WHERE active != 0\n ORDER BY pid, disporder\n "); $forumsread = unserialize($mybb->cookies['mybb']['forumread']); if (!is_array($forumsread)) { $forumsread = array(); } } else { // Build a forum cache. $query = $db->query("\n SELECT f.*, fr.dateline AS lastread\n FROM " . TABLE_PREFIX . "forums f\n LEFT JOIN " . TABLE_PREFIX . "forumsread fr ON (fr.fid=f.fid AND fr.uid='{$mybb->user['uid']}')\n WHERE f.active != 0\n ORDER BY pid, disporder\n "); } while ($forum = $db->fetch_array($query)) { if ($mybb->user['uid'] == 0) { if ($forumsread[$forum['fid']]) { $forum['lastread'] = $forumsread[$forum['fid']]; } } $fcache[$forum['pid']][$forum['disporder']][$forum['fid']] = $forum; } tt_check_forum_password($foruminfo['fid']); if ($foruminfo['linkto']) { return xmlrespfalse('This forum is a link'); } $visibleonly = "AND visible='1'"; $tvisibleonly = "AND t.visible='1'"; // Check if the active user is a moderator and get the inline moderation tools. if (is_moderator($fid)) { $ismod = true; $inlinecount = "0"; $inlinecookie = "inlinemod_forum" . $fid; $visibleonly = " AND (visible='1' OR visible='0')"; $tvisibleonly = " AND (t.visible='1' OR t.visible='0')"; } else { $inlinemod = ''; $ismod = false; } if (is_moderator($fid, "caneditposts") || $fpermissions['caneditposts'] == 1) { $can_edit_titles = 1; } else { $can_edit_titles = 0; } $t = "t."; $sortby = "lastpost"; $sortfield = "lastpost"; $sortordernow = "desc"; $threadcount = 0; $useronly = $tuseronly = ""; if ($fpermissions['canonlyviewownthreads'] == 1) { $useronly = "AND uid={$mybb->user['uid']}"; $tuseronly = "AND t.uid={$mybb->user['uid']}"; } if ($fpermissions['canviewthreads'] != 0) { // How many posts are there? if ($datecut > 0 || $fpermissions['canonlyviewownthreads'] == 1) { $query = $db->simple_select("threads", "COUNT(tid) AS threads", "fid = '{$fid}' {$useronly} {$visibleonly} {$stickyonly}"); $threadcount = $db->fetch_field($query, "threads"); } else { $query = $db->simple_select("threads", "COUNT(tid) AS threads", "fid = '{$fid}' {$useronly} {$visibleonly} {$stickyonly}", array('limit' => 1)); $threadcount = $db->fetch_field($query, "threads"); } } // count unread stickies $query = $db->query("\n select COUNT(t.tid) AS threads\n from " . TABLE_PREFIX . "threads t\n left join " . TABLE_PREFIX . "threadsread tr on t.tid = tr.tid and tr.uid = '{$mybb->user['uid']}'\n where t.fid = '{$fid}' {$tuseronly} {$tvisibleonly} and t.sticky=1 and (tr.dateline < t.lastpost or tr.dateline is null)\n "); $unreadStickyCount = $db->fetch_field($query, "threads"); if ($fpermissions['canviewthreads'] != 0) { // Start Getting Threads $query = $db->query("\n SELECT t.*, {$ratingadd}{$select_rating_user}t.username AS threadusername, u.username, u.avatar, s.sid as subscribed, po.message, IF(b.lifted > UNIX_TIMESTAMP() OR b.lifted = 0, 1, 0) as isbanned\n FROM " . TABLE_PREFIX . "threads t\n LEFT JOIN " . TABLE_PREFIX . "users u ON (u.uid = t.uid){$select_voting}\n LEFT JOIN " . TABLE_PREFIX . "banned b ON (b.uid = t.uid) \n LEFT JOIN " . TABLE_PREFIX . "threadsubscriptions s ON (s.tid = t.tid) AND (s.uid = '{$mybb->user['uid']}')\n LEFT JOIN " . TABLE_PREFIX . "posts po ON (po.pid = t.firstpost)\n WHERE t.fid='{$fid}' {$tuseronly} {$tvisibleonly} {$tstickyonly}\n GROUP BY t.tid\n ORDER BY t.sticky DESC, {$t}{$sortfield} {$sortordernow} {$sortfield2}\n LIMIT {$start}, {$limit}\n "); while ($thread = $db->fetch_array($query)) { $threadcache[$thread['tid']] = $thread; // If this is a moved thread - set the tid for participation marking and thread read marking to that of the moved thread if (substr($thread['closed'], 0, 5) == "moved") { $tid = substr($thread['closed'], 6); if (!$tids[$tid]) { $moved_threads[$tid] = $thread['tid']; $tids[$thread['tid']] = $tid; } } else { $tids[$thread['tid']] = $thread['tid']; if ($moved_threads[$tid]) { unset($moved_threads[$tid]); } } } } else { $threadcache = $tids = null; } if ($tids) { $tids = implode(",", $tids); } if ($mybb->settings['dotfolders'] != 0 && $mybb->user['uid'] && $threadcache) { $query = $db->simple_select("posts", "tid,uid", "uid='{$mybb->user['uid']}' AND tid IN ({$tids})"); while ($post = $db->fetch_array($query)) { if ($moved_threads[$post['tid']]) { $post['tid'] = $moved_threads[$post['tid']]; } if ($threadcache[$post['tid']]) { $threadcache[$post['tid']]['doticon'] = 1; } } } if ($mybb->user['uid'] && $mybb->settings['threadreadcut'] > 0 && $threadcache) { $query = $db->simple_select("threadsread", "*", "uid='{$mybb->user['uid']}' AND tid IN ({$tids})"); while ($readthread = $db->fetch_array($query)) { if ($moved_threads[$readthread['tid']]) { $readthread['tid'] = $moved_threads[$readthread['tid']]; } if ($threadcache[$readthread['tid']]) { $threadcache[$readthread['tid']]['lastread'] = $readthread['dateline']; } } } if ($mybb->settings['threadreadcut'] > 0 && $mybb->user['uid']) { $query = $db->simple_select("forumsread", "dateline", "fid='{$fid}' AND uid='{$mybb->user['uid']}'"); $forum_read = $db->fetch_field($query, "dateline"); $read_cutoff = TIME_NOW - $mybb->settings['threadreadcut'] * 60 * 60 * 24; if ($forum_read == 0 || $forum_read < $read_cutoff) { $forum_read = $read_cutoff; } } else { $forum_read = my_get_array_cookie("forumread", $fid); } $threads = ''; $load_inline_edit_js = 0; $topic_list = array(); if (is_array($threadcache)) { reset($threadcache); foreach ($threadcache as $thread) { $unreadpost = false; $moved = explode("|", $thread['closed']); $thread['author'] = $thread['uid']; if (!$thread['username']) { $thread['username'] = $thread['threadusername']; $thread['profilelink'] = $thread['threadusername']; } else { $thread['profilelink'] = build_profile_link($thread['username'], $thread['uid']); } // If this thread has a prefix, insert a space between prefix and subject if ($thread['prefix'] != 0) { $threadprefix = build_prefixes($thread['prefix']); $thread['displayprefix'] = $threadprefix['displaystyle']; } $thread['subject'] = $parser->parse_badwords($thread['subject']); $prefix = ''; if ($thread['poll']) { $prefix = $lang->poll_prefix; } $thread['posts'] = $thread['replies'] + 1; if ($moved[0] == "moved") { $prefix = $lang->moved_prefix; $thread['replies'] = "-"; $thread['views'] = "-"; } $gotounread = ''; $isnew = 0; $donenew = 0; if ($mybb->settings['threadreadcut'] > 0 && $mybb->user['uid'] && $thread['lastpost'] > $forum_read) { if ($thread['lastread']) { $last_read = $thread['lastread']; } else { $last_read = $read_cutoff; } } else { $last_read = my_get_array_cookie("threadread", $thread['tid']); } if ($forum_read > $last_read) { $last_read = $forum_read; } if ($thread['lastpost'] > $last_read && $moved[0] != "moved") { $folder .= "new"; $folder_label .= $lang->icon_new; $new_class = "subject_new"; $unreadpost = true; } else { $folder_label .= $lang->icon_no_new; $new_class = "subject_old"; } if (!empty($thread['closed'])) { $moved = explode("|", $thread['closed']); if ($moved[0] == "moved") { $thread['subject'] = $lang->moved_prefix . ' ' . $thread['subject']; } } $new_topic = array('forum_id' => new xmlrpcval($thread['fid'], 'string'), 'topic_id' => new xmlrpcval($thread['tid'], 'string'), 'topic_title' => new xmlrpcval(basic_clean($thread['subject']), 'base64'), 'prefix' => new xmlrpcval(basic_clean($thread['displayprefix']), 'base64'), 'topic_author_id' => new xmlrpcval($thread['uid'], 'string'), 'topic_author_name' => new xmlrpcval(basic_clean($thread['username']), 'base64'), 'icon_url' => new xmlrpcval(absolute_url($thread['avatar']), 'string'), 'last_reply_time' => new xmlrpcval(mobiquo_iso8601_encode($thread['lastpost']), 'dateTime.iso8601'), 'timestamp' => new xmlrpcval($thread['lastpost'], 'string'), 'short_content' => new xmlrpcval(process_short_content($thread['message'], $parser), 'base64'), 'reply_number' => new xmlrpcval(intval($thread['replies']), 'int'), 'view_number' => new xmlrpcval(intval($thread['views']), 'int'), 'is_approved' => new xmlrpcval($thread['visible'], 'boolean'), 'is_moved' => new xmlrpcval(isset($moved[0]) && $moved[0] == "moved" ? true : false, 'boolean'), 'real_topic_id' => new xmlrpcval(isset($moved[1]) ? $moved[1] : $thread['tid'])); $forumpermissions = forum_permissions($thread['fid']); if ($forumpermissions['canview'] == 0 || $forumpermissions['canviewthreads'] == 0) { $new_topic['can_subscribe'] = new xmlrpcval(false, 'boolean'); } else { $new_topic['can_subscribe'] = new xmlrpcval(true, 'boolean'); } //can_rename topic $can_rename = (is_moderator($fid, "caneditposts") || $forumpermissions['caneditposts'] == 1 && $mybb->user['uid'] == $thread['uid']) && $mybb->user['uid'] != 0; if ($unreadpost) { $new_topic['new_post'] = new xmlrpcval(true, 'boolean'); } if ($thread['sticky']) { $new_topic['is_sticky'] = new xmlrpcval(true, 'boolean'); } if (!empty($thread['subscribed'])) { $new_topic['is_subscribed'] = new xmlrpcval(true, 'boolean'); } else { $new_topic['is_subscribed'] = new xmlrpcval(false, 'boolean'); } if ($thread['closed']) { $new_topic['is_closed'] = new xmlrpcval(true, 'boolean'); } if ($thread['isbanned']) { $new_topic['is_ban'] = new xmlrpcval(true, 'boolean'); } if ($mybb->usergroup['canmodcp'] == 1) { $new_topic['can_ban'] = new xmlrpcval(true, 'boolean'); } if (is_moderator($fid, "canmanagethreads")) { $new_topic['can_move'] = new xmlrpcval(true, 'boolean'); $new_topic['can_merge'] = new xmlrpcval(true, 'boolean'); $new_topic['can_merge_post'] = new xmlrpcval(true, 'boolean'); } if (is_moderator($fid, "canopenclosethreads")) { $new_topic['can_close'] = new xmlrpcval(true, 'boolean'); } if (is_moderator($fid, "candeleteposts")) { $new_topic['can_delete'] = new xmlrpcval(true, 'boolean'); } if (is_moderator($fid, "canmanagethreads")) { $new_topic['can_stick'] = new xmlrpcval(true, 'boolean'); } if (is_moderator($fid, "canopenclosethreads")) { $new_topic['can_approve'] = new xmlrpcval(true, 'boolean'); } if ($can_rename) { $new_topic['can_rename'] = new xmlrpcval(true, 'boolean'); } $topic_list[] = new xmlrpcval($new_topic, 'struct'); } $customthreadtools = ''; } // If there are no unread threads in this forum and no unread child forums - mark it as read require_once MYBB_ROOT . "inc/functions_indicators.php"; if (fetch_unread_count($fid) == 0 && $unread_forums == 0) { mark_forum_read($fid); } $prefix_list = array(); // Does this user have additional groups? if ($mybb->user['additionalgroups']) { $exp = explode(",", $mybb->user['additionalgroups']); // Because we like apostrophes... $imps = array(); foreach ($exp as $group) { $imps[] = "'{$group}'"; } $additional_groups = implode(",", $imps); $extra_sql = "groups IN ({$additional_groups}) OR "; } else { $extra_sql = ''; } if ($mybb->version_code >= 1600 && $mybb->user['uid']) { $prefixes = get_prefix_list($fid); foreach ($prefixes as $prefix) { $prefix_list[] = new xmlrpcval(array('prefix_id' => new xmlrpcval($prefix['pid'], "string"), 'prefix_display_name' => new xmlrpcval(basic_clean($prefix['prefix']), "base64")), "struct"); } } $read_only_forums = explode(",", $settings['tapatalk_forum_read_only']); $can_post = true; if (empty($read_only_forums) || !is_array($read_only_forums)) { $read_only_forums = array(); } if (!($foruminfo['type'] == "f" && $foruminfo['open'] != 0 && $mybb->user['uid'] > 0 && $mybb->usergroup['canpostthreads']) || in_array($fid, $read_only_forums)) { $can_post = false; } $result = array('total_topic_num' => new xmlrpcval($threadcount, 'int'), 'forum_id' => new xmlrpcval($fid, 'string'), 'forum_name' => new xmlrpcval(basic_clean($foruminfo['name']), 'base64'), 'can_post' => new xmlrpcval($can_post, 'boolean'), 'prefixes' => new xmlrpcval($prefix_list, 'array'), 'can_upload' => new xmlrpcval($fpermissions['canpostattachments'], 'boolean')); if ($unreadStickyCount) { $result['unread_sticky_count'] = new xmlrpcval($unreadStickyCount, 'int'); } if ($mybb->user['uid']) { $query = $db->simple_select("forumsubscriptions", "fid", "fid='" . $fid . "' AND uid='{$mybb->user['uid']}'", array('limit' => 1)); if ($db->fetch_field($query, 'fid')) { $result['is_subscribed'] = new xmlrpcval(true, 'boolean'); } } $result['topics'] = new xmlrpcval($topic_list, 'array'); return new xmlrpcresp(new xmlrpcval($result, 'struct')); }
eval("\$inlinemodapproveunapprove = \"" . $templates->get("forumdisplay_inlinemoderation_approveunapprove") . "\";"); } if (!empty($inlinemodopenclose) || !empty($inlinemodstickunstick) || !empty($inlinemodsoftdelete) || !empty($inlinemodrestore) || !empty($inlinemoddelete) || !empty($inlinemodmanage) || !empty($inlinemodapproveunapprove)) { eval("\$standardthreadtools = \"" . $templates->get("forumdisplay_inlinemoderation_standard") . "\";"); } // Only show inline mod menu if there's options to show if (!empty($standardthreadtools) || !empty($customthreadtools)) { eval("\$inlinemod = \"" . $templates->get("forumdisplay_inlinemoderation") . "\";"); } } } // If there are no unread threads in this forum and no unread child forums - mark it as read require_once MYBB_ROOT . "inc/functions_indicators.php"; $unread_threads = fetch_unread_count($fid); if ($unread_threads !== false && $unread_threads == 0 && empty($unread_forums)) { mark_forum_read($fid); } // Subscription status $add_remove_subscription = 'add'; $add_remove_subscription_text = $lang->subscribe_forum; if ($mybb->user['uid']) { $query = $db->simple_select("forumsubscriptions", "fid", "fid='" . $fid . "' AND uid='{$mybb->user['uid']}'", array('limit' => 1)); if ($db->fetch_field($query, 'fid')) { $add_remove_subscription = 'remove'; $add_remove_subscription_text = $lang->unsubscribe_forum; } } $inline_edit_js = $clearstoredpass = ''; // Is this a real forum with threads? if ($foruminfo['type'] != "c") { if (!$threadcount) {
function do_get_forum() { global $vbulletin, $db, $show, $vbphrase, $foruminfo; $canpost = true; $vbulletin->input->clean_array_gpc('r', array('fid' => TYPE_INT, 'previewtype' => TYPE_INT)); $previewtype = $vbulletin->GPC['previewtype']; if (!$previewtype) { $previewtype = 1; } if (empty($foruminfo['forumid'])) { $forumid = -1; } else { $vbulletin->input->clean_array_gpc('r', array('password' => TYPE_STR)); // Check the forum password if ($vbulletin->GPC['password'] && $foruminfo['password'] == $vbulletin->GPC['password']) { // Set a temp cookie for guests if (!$vbulletin->userinfo['userid']) { set_bbarray_cookie('forumpwd', $foruminfo['forumid'], md5($vbulletin->userinfo['userid'] . $vbulletin->GPC['password'])); } else { set_bbarray_cookie('forumpwd', $foruminfo['forumid'], md5($vbulletin->userinfo['userid'] . $vbulletin->GPC['password']), 1); } } $perpage = $vbulletin->input->clean_gpc('r', 'perpage', TYPE_UINT); $pagenumber = $vbulletin->input->clean_gpc('r', 'pagenumber', TYPE_UINT); $daysprune = $vbulletin->input->clean_gpc('r', 'daysprune', TYPE_INT); $sortfield = $vbulletin->input->clean_gpc('r', 'sortfield', TYPE_STR); // get permission to view forum $_permsgetter_ = 'forumdisplay'; $forumperms = fetch_permissions($foruminfo['forumid']); if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canview'])) { json_error(ERR_NO_PERMISSION); } // Check for forum password! if (!verify_forum_password($foruminfo['forumid'], $foruminfo['password'], false)) { json_error(ERR_NEED_PASSWORD, RV_NEED_FORUM_PASSWORD); } // Can we post in this forum? if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canpostnew'])) { $canpost = false; } $forumid = $foruminfo['forumid']; } // Can forum contain threads? $announcements_out = array(); // These $_REQUEST values will get used in the sort template so they are assigned to normal variables $perpage = $vbulletin->input->clean_gpc('r', 'perpage', TYPE_UINT); $pagenumber = $vbulletin->input->clean_gpc('r', 'pagenumber', TYPE_UINT); $daysprune = $vbulletin->input->clean_gpc('r', 'daysprune', TYPE_INT); $sortfield = $vbulletin->input->clean_gpc('r', 'sortfield', TYPE_STR); // get permission to view forum $_permsgetter_ = 'forumdisplay'; $forumperms = fetch_permissions($foruminfo['forumid']); if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canview'])) { json_error(ERR_NO_PERMISSION); } // disable thread preview if we can't view threads if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewthreads'])) { $vbulletin->options['threadpreview'] = 0; } // check if there is a forum password and if so, ensure the user has it set verify_forum_password($foruminfo['forumid'], $foruminfo['password']); // verify that we are at the canonical SEO url // and redirect to this if not //verify_seo_url('forum', $foruminfo, array('pagenumber' => $_REQUEST['pagenumber'])); // get vbulletin->iforumcache - for use by makeforumjump and forums list // fetch the forum even if they are invisible since its needed // for the title but we'll unset that further down // also fetch subscription info for $show['subscribed'] variable cache_ordered_forums(1, 1, $vbulletin->userinfo['userid']); $show['newthreadlink'] = iif(!$show['search_engine'] and $foruminfo['allowposting'], true, false); $show['threadicons'] = iif($foruminfo['allowicons'], true, false); $show['threadratings'] = iif($foruminfo['allowratings'], true, false); $show['subscribed_to_forum'] = $vbulletin->forumcache["{$foruminfo['forumid']}"]['subscribeforumid'] != '' ? true : false; if (!$daysprune) { if ($vbulletin->userinfo['daysprune']) { $daysprune = $vbulletin->userinfo['daysprune']; } else { $daysprune = iif($foruminfo['daysprune'], $foruminfo['daysprune'], 30); } } $daysprune = -1; // FRNR // ### GET FORUMS, PERMISSIONS, MODERATOR iCACHES ######################## cache_moderators(); // draw nav bar $navbits = array(); $navbits[$vbulletin->options['forumhome'] . '.php' . $vbulletin->session->vars['sessionurl_q']] = $vbphrase['forum']; $parentlist = array_reverse(explode(',', substr($foruminfo['parentlist'], 0, -3))); foreach ($parentlist as $forumID) { $forumTitle = $vbulletin->forumcache["{$forumID}"]['title']; $navbits[fetch_seo_url('forum', array('forumid' => $forumID, 'title' => $forumTitle))] = $forumTitle; } // pop the last element off the end of the $nav array so that we can show it without a link array_pop($navbits); $navbits[''] = $foruminfo['title']; $navbits = construct_navbits($navbits); $navbar = render_navbar_template($navbits); $moderatorslist = ''; $listexploded = explode(',', $foruminfo['parentlist']); $showmods = array(); $show['moderators'] = false; $totalmods = 0; foreach ($listexploded as $parentforumid) { if (!$imodcache["{$parentforumid}"] or $parentforumid == -1) { continue; } foreach ($imodcache["{$parentforumid}"] as $moderator) { if ($showmods["{$moderator['userid']}"] === true) { continue; } $showmods["{$moderator['userid']}"] = true; $show['comma_leader'] = $moderatorslist != ''; $show['moderators'] = true; $totalmods++; } } // ### BUILD FORUMS LIST ################################################# // get an array of child forum ids for this forum $foruminfo['childlist'] = explode(',', $foruminfo['childlist']); // define max depth for forums display based on $vbulletin->options[forumhomedepth] define('MAXFORUMDEPTH', $vbulletin->options['forumdisplaydepth']); if (($vbulletin->options['showforumusers'] == 1 or $vbulletin->options['showforumusers'] == 2 or $vbulletin->options['showforumusers'] > 2 and $vbulletin->userinfo['userid']) and !$show['search_engine']) { $datecut = TIMENOW - $vbulletin->options['cookietimeout']; $forumusers = $db->query_read_slave("\n \t\tSELECT user.username, (user.options & " . $vbulletin->bf_misc_useroptions['invisible'] . ") AS invisible, user.usergroupid,\n \t\t\tsession.userid, session.inforum, session.lastactivity, session.badlocation,\n \t\t\tIF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid, infractiongroupid\n \t\tFROM " . TABLE_PREFIX . "session AS session\n \t\tLEFT JOIN " . TABLE_PREFIX . "user AS user ON(user.userid = session.userid)\n \t\tWHERE session.lastactivity > {$datecut}\n \t\tORDER BY" . iif($vbulletin->options['showforumusers'] == 1 or $vbulletin->options['showforumusers'] == 3, " username ASC,") . " lastactivity DESC\n \t"); $numberregistered = 0; $numberguest = 0; $doneuser = array(); if ($vbulletin->userinfo['userid']) { // fakes the user being in this forum $loggedin = array('userid' => $vbulletin->userinfo['userid'], 'username' => $vbulletin->userinfo['username'], 'invisible' => $vbulletin->userinfo['invisible'], 'invisiblemark' => $vbulletin->userinfo['invisiblemark'], 'inforum' => $foruminfo['forumid'], 'lastactivity' => TIMENOW, 'musername' => $vbulletin->userinfo['musername']); $numberregistered = 1; fetch_online_status($loggedin); $show['comma_leader'] = false; $doneuser["{$vbulletin->userinfo['userid']}"] = 1; } $inforum = array(); // this require the query to have lastactivity ordered by DESC so that the latest location will be the first encountered. while ($loggedin = $db->fetch_array($forumusers)) { if ($loggedin['badlocation']) { continue; } if (empty($doneuser["{$loggedin['userid']}"])) { if (in_array($loggedin['inforum'], $foruminfo['childlist']) and $loggedin['inforum'] != -1) { if (!$loggedin['userid']) { // this is a guest $numberguest++; $inforum["{$loggedin['inforum']}"]++; } else { $numberregistered++; $inforum["{$loggedin['inforum']}"]++; if (fetch_online_status($loggedin)) { fetch_musername($loggedin); $show['comma_leader'] = $activeusers != ''; } } } if ($loggedin['userid']) { $doneuser["{$loggedin['userid']}"] = 1; } } } if (!$vbulletin->userinfo['userid']) { $numberguest = $numberguest == 0 ? 1 : $numberguest; } $totalonline = $numberregistered + $numberguest; unset($joingroupid, $key, $datecut, $invisibleuser, $userinfo, $userid, $loggedin, $index, $value, $forumusers, $parentarray); $show['activeusers'] = true; } else { $show['activeusers'] = false; } // ############################################################################# // get read status for this forum and children $unreadchildforums = 0; foreach ($foruminfo['childlist'] as $val) { if ($val == -1 or $val == $foruminfo['forumid']) { continue; } if ($vbulletin->options['threadmarking'] and $vbulletin->userinfo['userid']) { $lastread_child = max($vbulletin->forumcache["{$val}"]['forumread'], TIMENOW - $vbulletin->options['markinglimit'] * 86400); } else { $lastread_child = max(intval(fetch_bbarray_cookie('forum_view', $val)), $vbulletin->userinfo['lastvisit']); } if ($vbulletin->forumcache["{$val}"]['lastpost'] > $lastread_child) { $unreadchildforums = 1; break; } } $forumbits = fr_construct_forum_bit($forumid); // admin tools $show['post_queue'] = can_moderate($foruminfo['forumid'], 'canmoderateposts'); $show['attachment_queue'] = can_moderate($foruminfo['forumid'], 'canmoderateattachments'); $show['mass_move'] = can_moderate($foruminfo['forumid'], 'canmassmove'); $show['mass_prune'] = can_moderate($foruminfo['forumid'], 'canmassprune'); $show['post_new_announcement'] = can_moderate($foruminfo['forumid'], 'canannounce'); $show['addmoderator'] = $permissions['adminpermissions'] & $vbulletin->bf_ugp_adminpermissions['cancontrolpanel']; $show['adminoptions'] = ($show['post_queue'] or $show['attachment_queue'] or $show['mass_move'] or $show['mass_prune'] or $show['addmoderator'] or $show['post_new_announcement']); $navpopup = array('id' => 'forumdisplay_navpopup', 'title' => $foruminfo['title_clean'], 'link' => fetch_seo_url('forum', $foruminfo)); construct_quick_nav($navpopup); ///////////////////////////////// if ($foruminfo['cancontainthreads']) { ///////////////////////////////// if ($vbulletin->options['threadmarking'] and $vbulletin->userinfo['userid']) { $foruminfo['forumread'] = $vbulletin->forumcache["{$foruminfo['forumid']}"]['forumread']; $lastread = max($foruminfo['forumread'], TIMENOW - $vbulletin->options['markinglimit'] * 86400); } else { $bbforumview = intval(fetch_bbarray_cookie('forum_view', $foruminfo['forumid'])); $lastread = max($bbforumview, $vbulletin->userinfo['lastvisit']); } // Inline Moderation $show['movethread'] = can_moderate($forumid, 'canmanagethreads') ? true : false; $show['deletethread'] = (can_moderate($forumid, 'candeleteposts') or can_moderate($forumid, 'canremoveposts')) ? true : false; $show['approvethread'] = can_moderate($forumid, 'canmoderateposts') ? true : false; $show['openthread'] = can_moderate($forumid, 'canopenclose') ? true : false; $show['inlinemod'] = ($show['movethread'] or $show['deletethread'] or $show['approvethread'] or $show['openthread']) ? true : false; $show['spamctrls'] = ($show['inlinemod'] and $show['deletethread']); $url = $show['inlinemod'] ? SCRIPTPATH : ''; // fetch popup menu if ($show['popups'] and $show['inlinemod']) { } else { $threadadmin_imod_thread_menu = ''; } // get announcements $announcebits = ''; if ($show['threadicons'] and $show['inlinemod']) { $announcecolspan = 6; } else { if (!$show['threadicons'] and !$show['inlinemod']) { $announcecolspan = 4; } else { $announcecolspan = 5; } } $mindate = TIMENOW - 2592000; // 30 days $hook_query_fields = $hook_query_joins = $hook_query_where = ''; $announcements = $db->query_read_slave("\n \t\tSELECT\n \t\t\tannouncement.announcementid, startdate, title, announcement.views,\n \t\t\tuser.username, user.userid, user.usertitle, user.customtitle, user.usergroupid,\n \t\t\tIF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid, infractiongroupid\n \t\t\t" . ($vbulletin->userinfo['userid'] ? ", NOT ISNULL(announcementread.announcementid) AS readannounce" : "") . "\n \t\t\t{$hook_query_fields}\n \t\tFROM " . TABLE_PREFIX . "announcement AS announcement\n \t\t" . ($vbulletin->userinfo['userid'] ? "LEFT JOIN " . TABLE_PREFIX . "announcementread AS announcementread ON (announcementread.announcementid = announcement.announcementid AND announcementread.userid = " . $vbulletin->userinfo['userid'] . ")" : "") . "\n \t\tLEFT JOIN " . TABLE_PREFIX . "user AS user ON(user.userid = announcement.userid)\n \t\t{$hook_query_joins}\n \t\tWHERE startdate <= " . TIMENOW . "\n \t\t\tAND enddate >= " . TIMENOW . "\n \t\t\tAND " . fetch_forum_clause_sql($foruminfo['forumid'], 'forumid') . "\n \t\t\t{$hook_query_where}\n \t\tORDER BY startdate DESC, announcement.announcementid DESC\n \t\t" . iif($vbulletin->options['oneannounce'], "LIMIT 1")); while ($announcement = $db->fetch_array($announcements)) { fetch_musername($announcement); $announcement['title'] = fetch_censored_text($announcement['title']); $announcement['postdate'] = vbdate($vbulletin->options['dateformat'], $announcement['startdate']); if ($announcement['readannounce'] or $announcement['startdate'] <= $mindate) { $announcement['statusicon'] = 'old'; } else { $announcement['statusicon'] = 'new'; } $announcement['views'] = vb_number_format($announcement['views']); $announcementidlink = iif(!$vbulletin->options['oneannounce'], "&a={$announcement['announcementid']}"); // FRNR START if ($pagenumber == 1) { $avatarurl = ''; $userinfoavatar = fetch_userinfo($announcement['userid'], FETCH_USERINFO_AVATAR); fetch_avatar_from_userinfo($userinfoavatar, true, false); if ($userinfoavatar['avatarurl'] != '') { $avatarurl = process_avatarurl($userinfoavatar['avatarurl']); } unset($userinfoavatar); $tmp = array('thread_id' => $foruminfo['forumid'], 'announcement' => 1, 'new_posts' => $announcement['readannounce'] ? 0 : 1, 'thread_title' => prepare_utf8_string(strip_tags($announcement['title'])), 'thread_preview' => prepare_utf8_string(preview_chop(html_entity_decode($announcement['pagetext']), FR_PREVIEW_LEN)), 'post_userid' => $announcement['userid'], 'post_lastposttime' => prepare_utf8_string(date_trunc($announcement['postdate'])), 'post_username' => prepare_utf8_string(strip_tags($announcement['username']))); if ($avatarurl != '') { $tmp['avatarurl'] = $avatarurl; } $announcements_out[] = $tmp; } // FRNR END } // display threads if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewothers'])) { $limitothers = "AND postuserid = " . $vbulletin->userinfo['userid'] . " AND " . $vbulletin->userinfo['userid'] . " <> 0"; } else { $limitothers = ''; } if (can_moderate($foruminfo['forumid'])) { $redirectjoin = "LEFT JOIN " . TABLE_PREFIX . "threadredirect AS threadredirect ON(thread.open = 10 AND thread.threadid = threadredirect.threadid)"; } else { $redirectjoin = ''; } // filter out deletion notices if can't be seen if ($forumperms & $vbulletin->bf_ugp_forumpermissions['canseedelnotice'] or can_moderate($foruminfo['forumid'])) { $canseedelnotice = true; $deljoin = "LEFT JOIN " . TABLE_PREFIX . "deletionlog AS deletionlog ON(thread.threadid = deletionlog.primaryid AND deletionlog.type = 'thread')"; } else { $canseedelnotice = false; $deljoin = ''; } // remove threads from users on the global ignore list if user is not a moderator if ($Coventry = fetch_coventry('string') and !can_moderate($foruminfo['forumid'])) { $globalignore = "AND postuserid NOT IN ({$Coventry}) "; } else { $globalignore = ''; } // look at thread limiting options $stickyids = ''; $stickycount = 0; if ($daysprune != -1) { if ($vbulletin->userinfo['userid'] and in_coventry($vbulletin->userinfo['userid'], true)) { $tachyjoin = "LEFT JOIN " . TABLE_PREFIX . "tachythreadpost AS tachythreadpost ON " . "(tachythreadpost.threadid = thread.threadid AND tachythreadpost.userid = " . $vbulletin->userinfo['userid'] . ")"; $datecut = " AND (thread.lastpost >= " . (TIMENOW - $daysprune * 86400) . " OR tachythreadpost.lastpost >= " . (TIMENOW - $daysprune * 86400) . ")"; } else { $datecut = "AND lastpost >= " . (TIMENOW - $daysprune * 86400); $tachyjoin = ""; } $show['noposts'] = false; } else { $tachyjoin = ""; $datecut = ""; $show['noposts'] = true; } // complete form fields on page $daysprunesel = iif($daysprune == -1, 'all', $daysprune); $daysprunesel = array($daysprunesel => 'selected="selected"'); $vbulletin->input->clean_array_gpc('r', array('sortorder' => TYPE_NOHTML, 'prefixid' => TYPE_NOHTML)); // prefix options $prefix_options = fetch_prefix_html($foruminfo['forumid'], $vbulletin->GPC['prefixid']); $prefix_selected = array('anythread', 'anythread' => '', 'none' => ''); if ($vbulletin->GPC['prefixid']) { //no prefix id if ($vbulletin->GPC['prefixid'] == '-1') { $prefix_filter = "AND thread.prefixid = ''"; $prefix_selected['none'] = ' selected="selected"'; } else { if ($vbulletin->GPC['prefixid'] == '-2') { $prefix_filter = "AND thread.prefixid <> ''"; $prefix_selected['anyprefix'] = ' selected="selected"'; } else { $prefix_filter = "AND thread.prefixid = '" . $db->escape_string($vbulletin->GPC['prefixid']) . "'"; } } } else { $prefix_filter = ''; $prefix_selected['anythread'] = ' selected="selected"'; } // default sorting methods if (empty($sortfield)) { $sortfield = $foruminfo['defaultsortfield']; } if (empty($vbulletin->GPC['sortorder'])) { $vbulletin->GPC['sortorder'] = $foruminfo['defaultsortorder']; } // look at sorting options: if ('asc' != ($sortorder = $vbulletin->GPC['sortorder'])) { $sqlsortorder = 'DESC'; $order = array('desc' => 'checked="checked"'); $vbulletin->GPC['sortorder'] = 'desc'; } else { $sqlsortorder = ''; $order = array('asc' => 'checked="checked"'); } $sqlsortfield2 = ''; switch ($sortfield) { case 'title': $sqlsortfield = 'thread.title'; break; case 'lastpost': $sqlsortfield = 'lastpost'; break; case 'replycount': case 'views': $sqlsortfield = 'views'; case 'postusername': $sqlsortfield = $sortfield; break; case 'voteavg': if ($foruminfo['allowratings']) { $sqlsortfield = 'voteavg'; $sqlsortfield2 = 'votenum'; break; } case 'dateline': $sqlsortfield = 'thread.dateline'; break; // else, use last post // else, use last post default: $handled = false; if (!$handled) { $sqlsortfield = 'lastpost'; $sortfield = 'lastpost'; } } $sort = array($sortfield => 'selected="selected"'); $visiblethreads = " AND visible = 1"; /*if (!can_moderate($forumid, 'canmoderateposts')) { if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canseedelnotice'])) { $visiblethreads = " AND visible = 1 "; } else { $visiblethreads = " AND visible IN (1,2)"; } } else { $visiblethreads = " AND visible IN (0,1,2)"; }*/ $hook_query_fields = $hook_query_joins = $hook_query_where = ''; # Include visible IN (0,1,2) in order to hit upon the 4 column index $threadscount = $db->query_first_slave("\n \t\tSELECT COUNT(*) AS threads, SUM(IF(thread.lastpost > {$lastread} AND open <> 10, 1, 0)) AS newthread\n \t\t{$hook_query_fields}\n \t\tFROM " . TABLE_PREFIX . "thread AS thread\n \t\t{$tachyjoin}\n \t\t{$hook_query_joins}\n \t\tWHERE forumid = {$foruminfo['forumid']}\n \t\t\tAND sticky = 0\n \t\t\t{$prefix_filter}\n \t\t\t{$visiblethreads}\n \t\t\t{$globalignore}\n \t\t\t{$limitothers}\n \t\t\t{$datecut}\n \t\t\t{$hook_query_where}\n \t"); $totalthreads = $threadscount['threads']; $newthreads = $threadscount['newthread']; // set defaults sanitize_pageresults($totalthreads, $pagenumber, $perpage, 200, $vbulletin->options['maxthreads']); // get number of sticky threads for the first page // on the first page there will be the sticky threads PLUS the $perpage other normal threads // not quite a bug, but a deliberate feature! if ($pagenumber == 1) { $stickies = $db->query_read_slave("\n \t\t\tSELECT thread.threadid, lastpost, open\n \t\t\tFROM " . TABLE_PREFIX . "thread AS thread\n \t\t\tWHERE forumid = {$foruminfo['forumid']}\n \t\t\t\tAND sticky = 1\n \t\t\t\t{$prefix_filter}\n \t\t\t\t{$visiblethreads}\n \t\t\t\t{$limitothers}\n \t\t\t\t{$globalignore}\n \t\t"); while ($thissticky = $db->fetch_array($stickies)) { $stickycount++; if ($thissticky['lastpost'] >= $lastread and $thissticky['open'] != 10) { $newthreads++; } $stickyids .= ",{$thissticky['threadid']}"; } $db->free_result($stickies); unset($thissticky, $stickies); } $limitlower = ($pagenumber - 1) * $perpage; $limitupper = $pagenumber * $perpage; if ($limitupper > $totalthreads) { $limitupper = $totalthreads; if ($limitlower > $totalthreads) { $limitlower = $totalthreads - $perpage - 1; } } if ($limitlower < 0) { $limitlower = 0; } if ($foruminfo['allowratings']) { $vbulletin->options['showvotes'] = intval($vbulletin->options['showvotes']); $votequery = "\n \t\t\tIF(votenum >= " . $vbulletin->options['showvotes'] . ", votenum, 0) AS votenum,\n \t\t\tIF(votenum >= " . $vbulletin->options['showvotes'] . " AND votenum > 0, votetotal / votenum, 0) AS voteavg,\n \t\t"; } else { $votequery = ''; } if ($previewtype == 1) { $previewfield = "post.pagetext AS preview, post.username AS lastpost_username, post.userid AS lastpost_userid,"; $previewjoin = "LEFT JOIN " . TABLE_PREFIX . "post AS post ON(post.postid = thread.firstpostid)"; } else { $previewfield = "post.pagetext AS preview, post.username AS lastpost_username, post.userid AS lastpost_userid,"; $previewjoin = "LEFT JOIN " . TABLE_PREFIX . "post AS post ON(post.postid = thread.lastpostid)"; } if ($vbulletin->userinfo['userid'] and in_coventry($vbulletin->userinfo['userid'], true)) { $tachyjoin = "\n \t\t\tLEFT JOIN " . TABLE_PREFIX . "tachythreadpost AS tachythreadpost ON\n \t\t\t\t(tachythreadpost.threadid = thread.threadid AND tachythreadpost.userid = " . $vbulletin->userinfo['userid'] . ")\n \t\t\tLEFT JOIN " . TABLE_PREFIX . "tachythreadcounter AS tachythreadcounter ON\n \t\t\t\t(tachythreadcounter.threadid = thread.threadid AND tachythreadcounter.userid = " . $vbulletin->userinfo['userid'] . ")\n \t\t"; $tachy_columns = "\n \t\t\tIF(tachythreadpost.userid IS NULL, thread.lastpost, tachythreadpost.lastpost) AS lastpost,\n \t\t\tIF(tachythreadpost.userid IS NULL, thread.lastposter, tachythreadpost.lastposter) AS lastposter,\n \t\t\tIF(tachythreadpost.userid IS NULL, thread.lastposterid, tachythreadpost.lastposterid) AS lastposterid,\n \t\t\tIF(tachythreadpost.userid IS NULL, thread.lastpostid, tachythreadpost.lastpostid) AS lastpostid,\n \t\t\tIF(tachythreadcounter.userid IS NULL, thread.replycount, thread.replycount + tachythreadcounter.replycount) AS replycount,\n \t\t\tIF(thread.views<=IF(tachythreadcounter.userid IS NULL, thread.replycount, thread.replycount + tachythreadcounter.replycount), IF(tachythreadcounter.userid IS NULL, thread.replycount, thread.replycount + tachythreadcounter.replycount)+1, thread.views) AS views\n \t\t"; } else { $tachyjoin = ''; $tachy_columns = 'thread.lastpost, thread.lastposter, thread.lastposterid, thread.lastpostid, thread.replycount, IF(thread.views<=thread.replycount, thread.replycount+1, thread.views) AS views'; } $hook_query_fields = $hook_query_joins = $hook_query_where = ''; $getthreadids = $db->query_read_slave("\n \t\tSELECT " . iif($sortfield == 'voteavg', $votequery) . " thread.threadid,\n \t\t\t{$tachy_columns}\n \t\t\t{$hook_query_fields}\n \t\tFROM " . TABLE_PREFIX . "thread AS thread\n \t\t{$tachyjoin}\n \t\t{$hook_query_joins}\n \t\tWHERE forumid = {$foruminfo['forumid']}\n \t\t\tAND sticky = 0\n \t\t\t{$prefix_filter}\n \t\t\t{$visiblethreads}\n \t\t\t{$globalignore}\n \t\t\t{$limitothers}\n \t\t\t{$datecut}\n \t\t\t{$hook_query_where}\n \t\tORDER BY sticky DESC, {$sqlsortfield} {$sqlsortorder}" . (!empty($sqlsortfield2) ? ", {$sqlsortfield2} {$sqlsortorder}" : '') . "\n \t\tLIMIT {$limitlower}, {$perpage}\n \t"); $ids = ''; while ($thread = $db->fetch_array($getthreadids)) { $ids .= ',' . $thread['threadid']; } $ids .= $stickyids; $db->free_result($getthreadids); unset($thread, $getthreadids); $hook_query_fields = $hook_query_joins = $hook_query_where = ''; $threads = $db->query_read_slave("\n \t\tSELECT {$votequery} {$previewfield}\n \t\t\tthread.threadid, thread.title AS threadtitle, thread.forumid, pollid, open, postusername, postuserid, thread.iconid AS threadiconid,\n \t\t\tthread.dateline, notes, thread.visible, sticky, votetotal, thread.attach, {$tachy_columns},\n \t\t\tthread.prefixid, thread.taglist, hiddencount, deletedcount,\n \t\t\tuser.usergroupid, user.homepage, user.options AS useroptions, IF(userlist.friend = 'yes', 1, 0) AS isfriend\n \t\t\t" . (($vbulletin->options['threadsubscribed'] and $vbulletin->userinfo['userid']) ? ", NOT ISNULL(subscribethread.subscribethreadid) AS issubscribed" : "") . "\n \t\t\t" . ($deljoin ? ", deletionlog.userid AS del_userid, deletionlog.username AS del_username, deletionlog.reason AS del_reason" : "") . "\n \t\t\t" . (($vbulletin->options['threadmarking'] and $vbulletin->userinfo['userid']) ? ", threadread.readtime AS threadread" : "") . "\n \t\t\t" . ($redirectjoin ? ", threadredirect.expires" : "") . "\n \t\t\t{$hook_query_fields}\n \t\tFROM " . TABLE_PREFIX . "thread AS thread\n \t\t\tLEFT JOIN " . TABLE_PREFIX . "user AS user ON (user.userid = thread.lastposterid)\n \t\t\tLEFT JOIN " . TABLE_PREFIX . "userlist AS userlist ON (userlist.relationid = user.userid AND userlist.type = 'buddy' AND userlist.userid = " . $vbulletin->userinfo['userid'] . ")\n \t\t\t{$deljoin}\n \t\t\t" . (($vbulletin->options['threadsubscribed'] and $vbulletin->userinfo['userid']) ? " LEFT JOIN " . TABLE_PREFIX . "subscribethread AS subscribethread ON(subscribethread.threadid = thread.threadid AND subscribethread.userid = " . $vbulletin->userinfo['userid'] . " AND canview = 1)" : "") . "\n \t\t\t" . (($vbulletin->options['threadmarking'] and $vbulletin->userinfo['userid']) ? " LEFT JOIN " . TABLE_PREFIX . "threadread AS threadread ON (threadread.threadid = thread.threadid AND threadread.userid = " . $vbulletin->userinfo['userid'] . ")" : "") . "\n \t\t\t{$previewjoin}\n \t\t\t{$tachyjoin}\n \t\t\t{$redirectjoin}\n \t\t\t{$hook_query_joins}\n \t\tWHERE thread.threadid IN (0{$ids}) {$hook_query_where}\n \t\tORDER BY sticky DESC, {$sqlsortfield} {$sqlsortorder}" . (!empty($sqlsortfield2) ? ", {$sqlsortfield2} {$sqlsortorder}" : '') . "\n \t"); unset($limitothers, $delthreadlimit, $deljoin, $datecut, $votequery, $sqlsortfield, $sqlsortorder, $threadids, $sqlsortfield2); // Get Dot Threads $dotthreads = fetch_dot_threads_array($ids); if ($vbulletin->options['showdots'] and $vbulletin->userinfo['userid']) { $show['dotthreads'] = true; } else { $show['dotthreads'] = false; } unset($ids); $pageinfo = array(); if ($vbulletin->GPC['prefixid']) { $pageinfo['prefixid'] = $vbulletin->GPC['prefixid']; } if ($vbulletin->GPC['daysprune']) { $pageinfo['daysprune'] = $daysprune; } $show['fetchseo'] = true; $oppositesort = $vbulletin->GPC['sortorder'] == 'asc' ? 'desc' : 'asc'; $pageinfo_voteavg = $pageinfo + array('sort' => 'voteavg', 'order' => 'voteavg' == $sortfield ? $oppositesort : 'desc'); $pageinfo_title = $pageinfo + array('sort' => 'title', 'order' => 'title' == $sortfield ? $oppositesort : 'asc'); $pageinfo_postusername = $pageinfo + array('sort' => 'postusername', 'order' => 'postusername' == $sortfield ? $oppositesort : 'asc'); $pageinfo_flastpost = $pageinfo + array('sort' => 'lastpost', 'order' => 'lastpost' == $sortfield ? $oppositesort : 'asc'); $pageinfo_replycount = $pageinfo + array('sort' => 'replycount', 'order' => 'replycount' == $sortfield ? $oppositesort : 'desc'); $pageinfo_views = $pageinfo + array('sort' => 'views', 'order' => 'views' == $sortfield ? $oppositesort : 'desc'); $pageinfo_sort = $pageinfo + array(sort => $sortfield, 'order' => $oppositesort, 'pp' => $perpage, 'page' => $pagenumber); if ($totalthreads > 0 or $stickyids) { if ($totalthreads > 0) { $limitlower++; } // check to see if there are any threads to display. If there are, do so, otherwise, show message if ($vbulletin->options['threadpreview'] > 0) { // Get Buddy List $buddy = array(); if (trim($vbulletin->userinfo['buddylist'])) { $buddylist = preg_split('/( )+/', trim($vbulletin->userinfo['buddylist']), -1, PREG_SPLIT_NO_EMPTY); foreach ($buddylist as $buddyuserid) { $buddy["{$buddyuserid}"] = 1; } } DEVDEBUG('buddies: ' . implode(', ', array_keys($buddy))); // Get Ignore Users $ignore = array(); if (trim($vbulletin->userinfo['ignorelist'])) { $ignorelist = preg_split('/( )+/', trim($vbulletin->userinfo['ignorelist']), -1, PREG_SPLIT_NO_EMPTY); foreach ($ignorelist as $ignoreuserid) { if (!$buddy["{$ignoreuserid}"]) { $ignore["{$ignoreuserid}"] = 1; } } } DEVDEBUG('ignored users: ' . implode(', ', array_keys($ignore))); } $show['threads'] = true; $threadbits = ''; $threadbits_sticky = ''; $counter = 0; $toread = 0; while ($thread = $db->fetch_array($threads)) { // AND $counter++ < $perpage) // build thread data $thread = process_thread_array($thread, $lastread, $foruminfo['allowicons']); $realthreadid = $thread['realthreadid']; if ($thread['sticky']) { $threadbit =& $threadbits_sticky; } else { $threadbit =& $threadbits; } // Soft Deleted Thread if ($thread['visible'] == 2) { $thread['deletedcount']++; $show['threadtitle'] = (can_moderate($forumid) or $vbulletin->userinfo['userid'] != 0 and $vbulletin->userinfo['userid'] == $thread['postuserid']) ? true : false; $show['deletereason'] = !empty($thread['del_reason']) ? true : false; $show['viewthread'] = can_moderate($forumid) ? true : false; $show['managethread'] = (can_moderate($forumid, 'candeleteposts') or can_moderate($forumid, 'canremoveposts')) ? true : false; $show['moderated'] = ($thread['hiddencount'] > 0 and can_moderate($forumid, 'canmoderateposts')) ? true : false; $show['deletedthread'] = $canseedelnotice; } else { if (!$thread['visible']) { $thread['hiddencount']++; } $show['moderated'] = ($thread['hiddencount'] > 0 and can_moderate($forumid, 'canmoderateposts')) ? true : false; $show['deletedthread'] = ($thread['deletedcount'] > 0 and $canseedelnotice) ? true : false; $pageinfo_lastpage = array(); if ($show['pagenavmore']) { $pageinfo_lastpage['page'] = $thread['totalpages']; } $pageinfo_newpost = array('goto' => 'newpost'); $pageinfo_lastpost = array('p' => $thread['lastpostid']); // prepare the member action drop-down menu $memberaction_dropdown = construct_memberaction_dropdown(fetch_lastposter_userinfo($thread)); } // FRNR Start $avatarurl = ''; if ($thread['lastpost_userid'] > 0) { $userinfoavatar = fetch_userinfo($thread['lastpost_userid'], FETCH_USERINFO_AVATAR); fetch_avatar_from_userinfo($userinfoavatar, true, false); if ($userinfoavatar['avatarurl'] != '') { $avatarurl = process_avatarurl($userinfoavatar['avatarurl']); } unset($userinfoavatar); } $tmp = array('thread_id' => $thread['threadid'], 'new_posts' => $show['gotonewpost'] ? 1 : 0, 'forum_id' => $thread['forumid'], 'total_posts' => $thread['totalposts'] ? $thread['totalposts'] : 0, 'thread_title' => prepare_utf8_string(strip_tags($thread['threadtitle'])), 'thread_preview' => prepare_utf8_string(preview_chop(html_entity_decode($thread['preview']), FR_PREVIEW_LEN)), 'post_userid' => $thread['lastpost_userid'], 'post_lastposttime' => prepare_utf8_string(date_trunc($thread['lastpostdate']) . ' ' . $thread['lastposttime']), 'post_username' => prepare_utf8_string(strip_tags($thread['lastpost_username']))); if ($avatarurl != '') { $tmp['avatarurl'] = $avatarurl; } if ($thread['prefixid']) { $tmp['prefix'] = prepare_utf8_string(strip_tags($vbphrase["prefix_{$thread['prefixid']}_title_plain"])); } if ($thread['attach']) { $tmp['attach'] = true; } if ($thread['pollid']) { $tmp['poll'] = true; } if ($thread['open'] == 10) { // Special case for redirect threads $tmp = array_merge($tmp, array('post_userid' => $thread['postuserid'], 'post_username' => prepare_utf8_string(strip_tags($thread['postusername'])), 'poll' => false)); } if ($thread['sticky']) { $thread_data_sticky[] = $tmp; } else { $thread_data[] = $tmp; } // FRNR Stop } $db->free_result($threads); unset($thread, $counter); $pageinfo_pagenav = array(); if (!empty($vbulletin->GPC['perpage'])) { $pageinfo_pagenav['pp'] = $perpage; } if (!empty($vbulletin->GPC['prefixid'])) { $pageinfo_pagenav['prefixid'] = $vbulletin->GPC['prefixid']; } if (!empty($vbulletin->GPC['sortfield'])) { $pageinfo_pagenav['sort'] = $sortfield; } if (!empty($vbulletin->GPC['sortorder'])) { $pageinfo_pagenav['order'] = $vbulletin->GPC['sortorder']; } if (!empty($vbulletin->GPC['daysprune'])) { $pageinfo_pagenav['daysprune'] = $daysprune; } $pagenav = construct_page_nav($pagenumber, $perpage, $totalthreads, 'forumdisplay.php?' . $vbulletin->session->vars['sessionurl'] . "f={$foruminfo['forumid']}", '', '', 'forum', $foruminfo, $pageinfo_pagenav); } unset($threads, $dotthreads); // get colspan for bottom bar $foruminfo['bottomcolspan'] = 5; if ($foruminfo['allowicons']) { $foruminfo['bottomcolspan']++; } if ($show['inlinemod']) { $foruminfo['bottomcolspan']++; } $show['threadslist'] = true; ///////////////////////////////// } else { $show['threadslist'] = false; $canpost = false; // FRNR } ///////////////////////////////// if (!$vbulletin->GPC['prefixid'] and $newthreads < 1 and $unreadchildforums < 1) { mark_forum_read($foruminfo, $vbulletin->userinfo['userid'], TIMENOW); } // FNRN Below $out = array(); if (is_array($thread_data) && count($thread_data) > 0) { $out['threads'] = $thread_data; } else { $out['threads'] = array(); } if (is_array($thread_data_sticky) && count($thread_data_sticky) > 0) { $out['threads_sticky'] = $thread_data_sticky; $out['total_sticky_threads'] = count($thread_data_sticky); } else { $out['threads_sticky'] = array(); $out['total_sticky_threads'] = 0; } // Announcements become #1 on the threads if (is_array($announcements_out) && count($announcements_out) == 1) { array_unshift($out['threads'], $announcements_out[0]); $totalthreads++; } $out['total_threads'] = $totalthreads ? $totalthreads : 0; if ($forumbits) { $out['forums'] = $forumbits; } else { $out['forums'] = array(); } $out['canpost'] = $canpost ? 1 : 0; $out['canattach'] = ($forumperms & $vbulletin->bf_ugp_forumpermissions['canpostattachment'] and $vbulletin->userinfo['userid']); // Get thread prefixes for this forum (if any) $prefix_out = array(); if ($prefixsets = fetch_prefix_array($forumid)) { foreach ($prefixsets as $prefixsetid => $prefixes) { $optgroup_options = ''; foreach ($prefixes as $prefixid => $prefix) { if ($permcheck and !can_use_prefix($prefixid, $prefix['restrictions'])) { continue; } $optionvalue = $prefixid; $optiontitle = htmlspecialchars_uni($vbphrase["prefix_{$prefixid}_title_plain"]); $prefix_out[] = array('prefixid' => $prefixid, 'prefixcaption' => prepare_utf8_string($optiontitle)); } } } if ($foruminfo['options'] & $vbulletin->bf_misc_forumoptions['prefixrequired']) { $out['prefixrequired'] = true; } else { $out['prefixrequired'] = false; } $out['prefixes'] = $prefix_out; return $out; }
function MarkForumRead($who, $forumid) { global $db, $vbulletin, $server, $structtypes, $lastpostarray; $result = RegisterService($who); if ($result['Code'] != 0) { $retval['Result'] = $result; return $retval; } $foruminfo = fetch_foruminfo($forumid); mark_forum_read($foruminfo, $vbulletin->userinfo['userid'], TIMENOW); $result['RemoteUser'] = ConsumeArray($vbulletin->userinfo, $structtypes['RemoteUser']); $retval['Result'] = $result; return $retval; }