/** * 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 forum as read. * * @param int The forum ID */ function mark_forum_read($fid) { global $mybb, $db; // Can only do "true" tracking for registered users if ($mybb->settings['threadreadcut'] > 0 && $mybb->user['uid']) { // Experimental setting to mark parent forums as read $forums_to_read = array(); if ($mybb->settings['readparentforums']) { $ignored_forums = array(); $forums = array_reverse(explode(",", get_parent_list($fid))); unset($forums[0]); if (!empty($forums)) { $ignored_forums[] = $fid; foreach ($forums as $forum) { $fids = array($forum); $ignored_forums[] = $forum; $children = explode(",", get_parent_list($forum)); foreach ($children as $child) { if (in_array($child, $ignored_forums)) { continue; } $fids[] = $child; $ignored_forums[] = $child; } if (fetch_unread_count(implode(",", $fids)) == 0) { $forums_to_read[] = $forum; } } } } switch ($db->type) { case "pgsql": case "sqlite": add_shutdown(array($db, "replace_query"), array("forumsread", array('fid' => $fid, 'uid' => $mybb->user['uid'], 'dateline' => TIME_NOW), array("fid", "uid"))); if (!empty($forums_to_read)) { foreach ($forums_to_read as $forum) { add_shutdown(array($db, "replace_query"), array("forumsread", array('fid' => $forum, 'uid' => $mybb->user['uid'], 'dateline' => TIME_NOW), array('fid', 'uid'))); } } break; default: $child_sql = ''; if (!empty($forums_to_read)) { foreach ($forums_to_read as $forum) { $child_sql .= ", ('{$forum}', '{$mybb->user['uid']}', '" . TIME_NOW . "')"; } } $db->shutdown_query("\n\t\t\t\t\tREPLACE INTO " . TABLE_PREFIX . "forumsread (fid, uid, dateline)\n\t\t\t\t\tVALUES('{$fid}', '{$mybb->user['uid']}', '" . TIME_NOW . "'){$child_sql}\n\t\t\t\t"); } } else { my_set_array_cookie("forumread", $fid, TIME_NOW, -1); } }
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')); }
} if (is_moderator($fid, "canapproveunapproveposts")) { 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?
break; default: $query = $db->simple_select("modtools", 'tid, name', "(CONCAT(',',forums,',') LIKE '%,{$fid},%' OR CONCAT(',',forums,',') LIKE '%,-1,%' OR forums='') AND type = 't'"); } while ($tool = $db->fetch_array($query)) { eval("\$customthreadtools .= \"" . $templates->get("forumdisplay_inlinemoderation_custom_tool") . "\";"); } if (!empty($customthreadtools)) { eval("\$customthreadtools = \"" . $templates->get("forumdisplay_inlinemoderation_custom") . "\";"); } 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"; if (fetch_unread_count($fid) == 0 && $unread_forums == 0) { mark_forum_read($fid); } // Subscription status $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; } else { $add_remove_subscription = 'add'; $add_remove_subscription_text = $lang->subscribe_forum; } // Is this a real forum with threads? if ($foruminfo['type'] != "c") { if (!$threadcount) { eval("\$threads = \"" . $templates->get("forumdisplay_nothreads") . "\";");