} else {
     $forum_read = intval(my_get_array_cookie("forumread", $fid));
 }
 if ($mybb->settings['threadreadcut'] > 0 && $mybb->user['uid'] && $thread['lastpost'] > $forum_read) {
     $cutoff = TIME_NOW - $mybb->settings['threadreadcut'] * 60 * 60 * 24;
     if ($thread['lastpost'] > $cutoff) {
         if ($thread_read) {
             $lastread = $thread_read;
         } else {
             // Set $lastread to zero to make sure 'lastpost' is invoked in the last IF
             $lastread = 0;
         }
     }
 }
 if (!$lastread) {
     $readcookie = $threadread = intval(my_get_array_cookie("threadread", $thread['tid']));
     if ($readcookie > $forum_read) {
         $lastread = $readcookie;
     } else {
         $lastread = $forum_read;
     }
 }
 if ($cutoff && $lastread < $cutoff) {
     $lastread = $cutoff;
 }
 // Next, find the proper pid to link to.
 $options = array("limit_start" => 0, "limit" => 1, "order_by" => "dateline", "order_dir" => "asc");
 $lastread = intval($lastread);
 $query = $db->simple_select("posts", "pid", "tid='{$tid}' AND dateline > '{$lastread}' {$visibleonly}", $options);
 $newpost = $db->fetch_array($query);
 if ($newpost['pid'] && $lastread) {
/**
 * Fetch the status indicator for a forum based on its last post and the read date
 *
 * @param array Array of information about the forum
 * @param array Array of information about the lastpost date
 * @return array Array of the folder image to be shown and the alt text
 */
function get_forum_lightbulb($forum, $lastpost, $locked = 0)
{
    global $mybb, $lang, $db, $unread_forums;
    // This forum is closed, so override the folder icon with the "offlock" icon.
    if ($forum['open'] == 0 || $locked) {
        $folder = "offlock";
        $altonoff = $lang->forum_locked;
    } else {
        // Fetch the last read date for this forum
        if ($forum['lastread']) {
            $forum_read = $forum['lastread'];
        } else {
            $forum_read = my_get_array_cookie("forumread", $forum['fid']);
        }
        if (!$forum_read) {
            $forum_read = $mybb->user['lastvisit'];
        }
        // If the lastpost is greater than the last visit and is greater than the forum read date, we have a new post
        if ($lastpost['lastpost'] > $forum_read && $lastpost['lastpost'] != 0) {
            $unread_forums++;
            $folder = "on";
            $altonoff = $lang->new_posts;
        } else {
            $folder = "off";
            $altonoff = $lang->no_new_posts;
        }
    }
    return array("folder" => $folder, "altonoff" => $altonoff);
}
Esempio n. 3
0
     $read_cutoff = TIME_NOW - $mybb->settings['threadreadcut'] * 60 * 60 * 24;
     if ($forum_read == 0 || $forum_read < $read_cutoff) {
         $forum_read = $read_cutoff;
     }
 }
 if ($mybb->settings['threadreadcut'] > 0 && $thread['lastpost'] > $forum_read) {
     $cutoff = TIME_NOW - $mybb->settings['threadreadcut'] * 60 * 60 * 24;
 }
 $cutoff = 0;
 if ($thread['lastpost'] > $cutoff) {
     if ($thread['lastread']) {
         $lastread = $thread['lastread'];
     }
 }
 if (!$lastread) {
     $readcookie = $threadread = my_get_array_cookie("threadread", $thread['tid']);
     if ($readcookie > $forum_read) {
         $lastread = $readcookie;
     } else {
         $lastread = $forum_read;
     }
 }
 // Folder Icons
 if ($thread['doticon']) {
     $folder = "dot_";
     $folder_label .= $lang->icon_dot;
 }
 if ($thread['lastpost'] > $lastread && $lastread) {
     $folder .= "new";
     $folder_label .= $lang->icon_new;
     $new_class = "subject_new";
Esempio n. 4
0
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'));
}
/**
 * Fetch the status indicator for a forum based on its last post and the read date
 *
 * @param array Array of information about the forum
 * @param array Array of information about the lastpost date
 * @return array Array of the folder image to be shown and the alt text
 */
function get_forum_lightbulb($forum, $lastpost, $locked = 0)
{
    global $mybb, $lang, $db, $unread_forums;
    // This forum is closed, so override the folder icon with the "offlock" icon.
    if ($forum['open'] == 0 || $locked) {
        $folder = "offlock";
        $altonoff = $lang->forum_locked;
    } else {
        // Fetch the last read date for this forum
        if (!empty($forum['lastread'])) {
            $forum_read = $forum['lastread'];
        } elseif (!empty($mybb->cookies['mybb']['readallforums'])) {
            // We've hit the read all forums as a guest, so use the lastvisit of the user
            $forum_read = $mybb->cookies['mybb']['lastvisit'];
        } else {
            $forum_read = 0;
            $threadcut = TIME_NOW - 60 * 60 * 24 * $mybb->settings['threadreadcut'];
            // If the user is a guest, do they have a forumsread cookie?
            if (!$mybb->user['uid'] && $mybb->cookies['mybb']['forumread']) {
                // If they've visited us before, then they'll have this cookie - otherwise everything is unread...
                $forum_read = my_get_array_cookie("forumread", $forum['fid']);
            } else {
                if ($mybb->user['uid'] && $mybb->settings['threadreadcut'] > 0 && $threadcut > $lastpost['lastpost']) {
                    // We have a user, the forum's unread and we're over our threadreadcut limit for the lastpost - we mark these as read
                    $forum_read = $lastpost['lastpost'] + 1;
                }
            }
        }
        //if(!$forum_read)
        //{
        //$forum_read = $mybb->user['lastvisit'];
        //}
        // If the lastpost is greater than the last visit and is greater than the forum read date, we have a new post
        if ($lastpost['lastpost'] > $forum_read && $lastpost['lastpost'] != 0) {
            $unread_forums++;
            $folder = "on";
            $altonoff = $lang->new_posts;
        } else {
            $folder = "off";
            $altonoff = $lang->no_new_posts;
        }
    }
    return array("folder" => $folder, "altonoff" => $altonoff);
}
Esempio n. 6
0
 $folder_label = '';
 if (isset($thread['doticon'])) {
     $folder = "dot_";
     $folder_label .= $lang->icon_dot;
 }
 $gotounread = '';
 $isnew = 0;
 $donenew = 0;
 if ($mybb->settings['threadreadcut'] > 0 && $mybb->user['uid'] && $thread['lastpost'] > $forum_read) {
     if (!empty($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";
     $thread['newpostlink'] = get_thread_link($thread['tid'], 0, "newpost");
     eval("\$gotounread = \"" . $templates->get("forumdisplay_thread_gotounread") . "\";");
     $unreadpost = 1;
 } else {
     $folder_label .= $lang->icon_no_new;
     $new_class = "subject_old";
 }
function get_subscribed_topic_func($xmlrpc_params)
{
    global $db, $lang, $theme, $plugins, $mybb, $session, $settings, $cache, $time, $mybbgroups;
    $lang->load("usercp");
    $parser = new postParser();
    $input = Tapatalk_Input::filterXmlInput(array('start_num' => Tapatalk_Input::INT, 'last_num' => Tapatalk_Input::INT), $xmlrpc_params);
    if ($mybb->user['uid'] == 0 || $mybb->usergroup['canusercp'] == 0) {
        return tt_no_permission();
    }
    $query = $db->simple_select("forumpermissions", "*", "gid='" . $db->escape_string($mybb->user['usergroup']) . "'");
    while ($permissions = $db->fetch_array($query)) {
        $permissioncache[$permissions['gid']][$permissions['fid']] = $permissions;
    }
    while ($forum = $db->fetch_array($query)) {
        if ($mybb->user['uid'] == 0) {
            if ($forumsread[$forum['fid']]) {
                $forum['lastread'] = $forumsread[$forum['fid']];
            }
        }
        $readforums[$forum['fid']] = $forum['lastread'];
    }
    require_once MYBB_ROOT . "inc/functions_forumlist.php";
    $fpermissions = forum_permissions();
    list($start, $limit) = process_page($input['start_num'], $input['last_num']);
    // Thread visiblity
    $visible = "AND t.visible != 0";
    if (is_moderator() == true) {
        $visible = '';
    }
    // Do Multi Pages
    $query = $db->query("\n\t\tSELECT COUNT(ts.tid) as threads\n\t\tFROM " . TABLE_PREFIX . "threadsubscriptions ts\n\t\tLEFT JOIN " . TABLE_PREFIX . "threads t ON (t.tid = ts.tid)\n\t\tWHERE ts.uid = '" . $mybb->user['uid'] . "' {$visible}\n\t");
    $threadcount = $db->fetch_field($query, "threads");
    // Fetch subscriptions
    $query = $db->query("\n\t\tSELECT s.*, t.*, t.username AS threadusername, u.username, u.username, u.avatar, if({$mybb->user['uid']} > 0 and s.uid = {$mybb->user['uid']}, 1, 0) as subscribed, po.message, f.name as forumname, IF(b.lifted > UNIX_TIMESTAMP() OR b.lifted = 0, 1, 0) as isbanned\n\t\tFROM " . TABLE_PREFIX . "threadsubscriptions s\n\t\tLEFT JOIN " . TABLE_PREFIX . "threads t ON (s.tid=t.tid)\n\t\tLEFT JOIN " . TABLE_PREFIX . "users u ON (u.uid = t.uid)\n\t\tLEFT JOIN " . TABLE_PREFIX . "banned b ON (b.uid = t.uid)\n\t\tLEFT JOIN " . TABLE_PREFIX . "posts po ON (po.pid = t.firstpost)\n\t\tleft join " . TABLE_PREFIX . "forums f on f.fid = t.fid\n\t\tWHERE s.uid='" . $mybb->user['uid'] . "' {$visible}\n\t\tORDER BY t.lastpost DESC\n\t\tLIMIT {$start}, {$limit}\n\t");
    while ($subscription = $db->fetch_array($query)) {
        $forumpermissions = $fpermissions[$subscription['fid']];
        if ($forumpermissions['canview'] == 0 || $forumpermissions['canviewthreads'] == 0) {
            // Hmm, you don't have permission to view this thread - unsubscribe!
            $del_subscriptions[] = $subscription['tid'];
        } else {
            if ($subscription['tid']) {
                $subscriptions[$subscription['tid']] = $subscription;
            }
        }
    }
    if (is_array($del_subscriptions)) {
        $tids = implode(',', $del_subscriptions);
        if ($tids) {
            $db->delete_query("threadsubscriptions", "tid IN ({$tids}) AND uid='{$mybb->user['uid']}'");
        }
    }
    $topic_list = array();
    if (is_array($subscriptions)) {
        $tids = implode(",", array_keys($subscriptions));
        // Build a forum cache.
        $query = $db->query("\n\t\t\tSELECT f.fid, fr.dateline AS lastread\n\t\t\tFROM " . TABLE_PREFIX . "forums f\n\t\t\tLEFT JOIN " . TABLE_PREFIX . "forumsread fr ON (fr.fid=f.fid AND fr.uid='{$mybb->user['uid']}')\n\t\t\tWHERE f.active != 0\n\t\t\tORDER BY pid, disporder\n\t\t");
        while ($forum = $db->fetch_array($query)) {
            if ($mybb->user['uid'] == 0) {
                if ($forumsread[$forum['fid']]) {
                    $forum['lastread'] = $forumsread[$forum['fid']];
                }
            }
            $readforums[$forum['fid']] = $forum['lastread'];
        }
        // Read threads
        if ($mybb->settings['threadreadcut'] > 0) {
            $query = $db->simple_select("threadsread", "*", "uid='{$mybb->user['uid']}' AND tid IN ({$tids})");
            while ($readthread = $db->fetch_array($query)) {
                $subscriptions[$readthread['tid']]['lastread'] = $readthread['dateline'];
            }
        }
        // Now we can build our subscription list
        foreach ($subscriptions as $thread) {
            $bgcolor = alt_trow();
            $folder = '';
            $prefix = '';
            // If this thread has a prefix, insert a space between prefix and subject
            if ($thread['prefix'] != 0) {
                $thread['threadprefix'] .= '&nbsp;';
            }
            // Sanitize
            $thread['subject'] = $parser->parse_badwords($thread['subject']);
            $gotounread = '';
            $isnew = 0;
            $donenew = 0;
            $lastread = 0;
            $unreadpost = 0;
            if ($mybb->settings['threadreadcut'] > 0 && $mybb->user['uid']) {
                $forum_read = $readforums[$thread['fid']];
                $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 = $forumsread[$thread['fid']];
            }
            if ($mybb->settings['threadreadcut'] > 0 && $thread['lastpost'] > $forum_read) {
                $cutoff = TIME_NOW - $mybb->settings['threadreadcut'] * 60 * 60 * 24;
            }
            if ($thread['lastpost'] > $cutoff) {
                if ($thread['lastpost'] > $cutoff) {
                    if ($thread['lastread']) {
                        $lastread = $thread['lastread'];
                    } else {
                        $lastread = 1;
                    }
                }
            }
            if (!$lastread) {
                $readcookie = $threadread = my_get_array_cookie("threadread", $thread['tid']);
                if ($readcookie > $forum_read) {
                    $lastread = $readcookie;
                } else {
                    $lastread = $forum_read;
                }
            }
            if ($thread['lastpost'] > $lastread && $lastread) {
                $unreadpost = 1;
            }
            $topic_list[] = new xmlrpcval(array('forum_id' => new xmlrpcval($thread['fid'], 'string'), 'forum_name' => new xmlrpcval(basic_clean($thread['forumname']), 'base64'), 'topic_id' => new xmlrpcval($thread['tid'], 'string'), 'topic_title' => new xmlrpcval($thread['subject'], 'base64'), 'topic_author_id' => new xmlrpcval($thread['uid'], 'string'), 'post_author_name' => new xmlrpcval($thread['username'], 'base64'), 'can_subscribe' => new xmlrpcval(true, 'boolean'), 'is_subscribed' => new xmlrpcval((bool) $thread['subscribed'], 'boolean'), 'is_closed' => new xmlrpcval((bool) $thread['closed'], 'boolean'), 'short_content' => new xmlrpcval(process_short_content($thread['message'], $parser), 'base64'), 'icon_url' => new xmlrpcval(absolute_url($thread['avatar']), 'string'), 'post_time' => new xmlrpcval(mobiquo_iso8601_encode($thread['lastpost']), 'dateTime.iso8601'), 'reply_number' => new xmlrpcval($thread['replies'], 'int'), 'view_number' => new xmlrpcval($thread['views'], 'int'), 'new_post' => new xmlrpcval($unreadpost, 'boolean'), 'can_delete' => new xmlrpcval(is_moderator($thread['fid'], "candeleteposts"), 'boolean'), 'can_close' => new xmlrpcval(is_moderator($thread['fid'], "canopenclosethreads"), 'boolean'), 'can_approve' => new xmlrpcval(is_moderator($thread['fid'], "canopenclosethreads"), 'boolean'), 'can_stick' => new xmlrpcval(is_moderator($thread['fid'], "canmanagethreads"), 'boolean'), 'can_merge' => new xmlrpcval(is_moderator($thread['fid'], "canmanagethreads"), 'boolean'), 'can_merge_post' => new xmlrpcval(is_moderator($thread['fid'], "canmanagethreads"), 'boolean'), 'can_move' => new xmlrpcval(is_moderator($thread['fid'], "canmovetononmodforum"), 'boolean'), 'can_ban' => new xmlrpcval($mybb->usergroup['canmodcp'] == 1, 'boolean'), 'can_rename' => new xmlrpcval(false, 'boolean'), 'is_ban' => new xmlrpcval($thread['isbanned'], 'boolean'), 'is_sticky' => new xmlrpcval($thread['sticky'], 'boolean'), 'is_approved' => new xmlrpcval(!!$thread['visible'], 'boolean'), 'is_deleted' => new xmlrpcval(false, 'boolean')), 'struct');
        }
    }
    $result = new xmlrpcval(array('total_topic_num' => new xmlrpcval($threadcount, 'int'), 'topics' => new xmlrpcval($topic_list, 'array')), 'struct');
    return new xmlrpcresp($result);
}
function latest_threads_get_threadlist($settings, $width)
{
    global $db, $mybb, $templates, $lang, $cache, $gotounread, $theme;
    if (!$lang->asb_addon) {
        $lang->load('asb_addon');
    }
    if ($mybb->user['uid'] == 0) {
        $query = $db->query("\n\t\t\tSELECT\n\t\t\t\tfid\n\t\t\tFROM {$db->table_prefix}forums\n\t\t\tWHERE\n\t\t\t\tactive != 0\n\t\t\tORDER BY\n\t\t\t\tpid, disporder\n\t\t");
        $forumsread = my_unserialize($mybb->cookies['mybb']['forumread']);
    } else {
        $query = $db->query("\n\t\t\tSELECT\n\t\t\t\tf.fid, fr.dateline AS lastread\n\t\t\tFROM {$db->table_prefix}forums f\n\t\t\tLEFT JOIN {$db->table_prefix}forumsread fr ON (fr.fid=f.fid AND fr.uid='{$mybb->user['uid']}')\n\t\t\tWHERE\n\t\t\t\tf.active != 0\n\t\t\tORDER BY\n\t\t\t\tpid, disporder\n\t\t");
    }
    while ($forum = $db->fetch_array($query)) {
        if ($mybb->user['uid'] == 0) {
            if ($forumsread[$forum['fid']]) {
                $forum['lastread'] = $forumsread[$forum['fid']];
            }
        }
        $readforums[$forum['fid']] = $forum['lastread'];
    }
    // Build a post parser
    require_once MYBB_ROOT . 'inc/class_parser.php';
    $parser = new postParser();
    // get forums user cannot view
    $unviewable = get_unviewable_forums(true);
    if ($unviewable) {
        $unviewwhere = " AND t.fid NOT IN ({$unviewable})";
    }
    // get inactive forums
    $inactive = get_inactive_forums();
    if ($inactive) {
        $inactivewhere = " AND t.fid NOT IN ({$inactive})";
    }
    // new threads only?
    if ((int) $settings['new_threads_only'] > 0) {
        // use admin's time limit
        $thread_time_limit = TIME_NOW - 60 * 60 * 24 * (int) $settings['new_threads_only'];
        $new_threads = " AND t.dateline > {$thread_time_limit}";
    }
    if ($settings['important_threads_only']) {
        $important_threads = ' AND NOT t.sticky=0';
    }
    // build the exclude conditions
    $show['fids'] = asb_build_id_list($settings['forum_show_list'], 't.fid');
    $show['tids'] = asb_build_id_list($settings['thread_show_list'], 't.tid');
    $hide['fids'] = asb_build_id_list($settings['forum_hide_list'], 't.fid');
    $hide['tids'] = asb_build_id_list($settings['thread_hide_list'], 't.tid');
    $where['show'] = asb_build_SQL_where($show, ' OR ');
    $where['hide'] = asb_build_SQL_where($hide, ' OR ', ' NOT ');
    $query_where = $new_threads . $important_threads . $unviewwhere . $inactivewhere . asb_build_SQL_where($where, ' AND ', ' AND ');
    $altbg = alt_trow();
    $maxtitlelen = 48;
    $threadlist = '';
    // query for the latest forum discussions
    $query = $db->query("\n\t\tSELECT\n\t\t\tt.*,\n\t\t\tu.username, u.avatar, u.usergroup, u.displaygroup\n\t\tFROM {$db->table_prefix}threads t\n\t\tLEFT JOIN {$db->table_prefix}users u ON (u.uid=t.lastposteruid)\n\t\tWHERE\n\t\t\tt.visible='1' AND t.closed NOT LIKE 'moved|%'{$query_where}\n\t\tORDER BY\n\t\t\tt.lastpost DESC\n\t\tLIMIT\n\t\t\t0, " . (int) $settings['max_threads']);
    if ($db->num_rows($query) == 0) {
        // no content
        return false;
    }
    $thread_cache = array();
    while ($thread = $db->fetch_array($query)) {
        $thread_cache[$thread['tid']] = $thread;
    }
    $thread_ids = implode(",", array_keys($thread_cache));
    // fetch the read threads.
    if ($mybb->user['uid'] && $mybb->settings['threadreadcut'] > 0) {
        $query = $db->simple_select('threadsread', 'tid,dateline', "uid='{$mybb->user['uid']}' AND tid IN({$thread_ids})");
        while ($readthread = $db->fetch_array($query)) {
            $thread_cache[$readthread['tid']]['lastread'] = $readthread['dateline'];
        }
    }
    foreach ($thread_cache as $thread) {
        $forumpermissions[$thread['fid']] = forum_permissions($thread['fid']);
        // make sure we can view this thread
        if ($forumpermissions[$thread['fid']]['canview'] == 0 || $forumpermissions[$thread['fid']]['canviewthreads'] == 0 || $forumpermissions[$thread['fid']]['canonlyviewownthreads'] == 1 && $thread['uid'] != $mybb->user['uid']) {
            continue;
        }
        $lastpostdate = my_date($mybb->settings['dateformat'], $thread['lastpost']);
        $lastposttime = my_date($mybb->settings['timeformat'], $thread['lastpost']);
        // don't link to guest's profiles (they have no profile).
        if ($thread['lastposteruid'] == 0) {
            $lastposterlink = $thread['lastposter'];
        } else {
            if ($settings['last_poster_avatar']) {
                if (strlen(trim($thread['avatar'])) == 0) {
                    $thread['avatar'] = "{$theme['imgdir']}/default_avatar.gif";
                }
                $avatar_width = (int) min($width / 2, max($width / 8, $settings['avatar_width']));
                $last_poster_name = <<<EOF
<img src="{$thread['avatar']}" alt="{$thread['last_post']}" title="{$thread['lastposter']}'s profile" style="width: {$avatar_width}px;"/>
EOF;
                format_name($thread['lastposter'], $thread['usergroup'], $thread['displaygroup']);
                $lp_template = 'asb_latest_threads_last_poster_avatar';
            } else {
                $last_poster_name = format_name($thread['lastposter'], $thread['usergroup'], $thread['displaygroup']);
                $lp_template = 'asb_latest_threads_last_poster_name';
            }
            $lastposterlink = build_profile_link($last_poster_name, $thread['lastposteruid']);
        }
        if (my_strlen($thread['subject']) > $maxtitlelen) {
            $thread['subject'] = my_substr($thread['subject'], 0, $maxtitlelen) . "...";
        }
        $thread['subject'] = htmlspecialchars_uni($parser->parse_badwords($thread['subject']));
        $thread['threadlink'] = get_thread_link($thread['tid']);
        $thread['lastpostlink'] = get_thread_link($thread['tid'], 0, "lastpost");
        eval("\$last_poster = \"" . $templates->get($lp_template) . "\";");
        $gotounread = '';
        $last_read = 0;
        if ($mybb->settings['threadreadcut'] > 0 && $mybb->user['uid']) {
            $forum_read = $readforums[$thread['fid']];
            $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 = $forumsread[$thread['fid']];
        }
        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 && $last_read) {
            $thread['newpostlink'] = get_thread_link($thread['tid'], 0, 'newpost');
            eval("\$gotounread = \"" . $templates->get("asb_latest_threads_gotounread") . "\";");
            $unreadpost = 1;
        }
        eval("\$threadlist .= \"" . $templates->get("asb_latest_threads_thread") . "\";");
        $altbg = alt_trow();
    }
    if ($threadlist) {
        return $threadlist;
    }
    // no content
    return false;
}