Ejemplo n.º 1
0
    /**
     * returns forum topics XML
     * @param $forum_id		forum id
     * @param $wp			return whole page XML
     * @param $start		record to start with
     */
    function getTopicsXML($forum_id, $wp, $start = 0)
    {
        global $gConf;
        $fdb = new DbForum();
        $f = $fdb->getForum($forum_id);
        $user = $this->getLoginUser();
        if (!$this->_checkUserPerm($user, $f['forum_type'], 'read')) {
            return $this->_no_access($wp);
        }
        encode_post_text($f['forum_title'], $wp);
        encode_post_text($f['forum_desc'], $wp);
        $x1 = <<<EOF
<forum>
\t<id>{$forum_id}</id>
\t<title>{$f['forum_title']}</title>
\t<desc>{$f['forum_desc']}</desc>
\t<type>{$f['forum_type']}</type>
</forum>
EOF;
        $cat_title = $fdb->getCatTitle($f['cat_id']);
        encode_post_text($cat_title, $wp);
        $x2 = <<<EOF
<cat>
\t<id>{$f['cat_id']}</id>
\t<title>{$cat_title}</title>
</cat>
EOF;
        $user_last_act = (int) $fdb->getUserLastActivity($user);
        $a = $fdb->getTopics($forum_id, $start);
        reset($a);
        $t = '';
        while (list(, $r) = each($a)) {
            $td = $fdb->getTopicDesc($r['topic_id']);
            $this->_buld_topic_desc($td);
            if (!$user) {
                $new_topic = 0;
            } else {
                $new_topic = $this->isNewTopic($r['topic_id'], $r['last_post_when'], $user_last_act) ? 1 : 0;
            }
            encode_post_text($r['topic_title'], $wp, 1);
            $t .= <<<EOF
<topic id="{$r['topic_id']}" new="{$new_topic}" lpt="{$r['last_post_when']}" lut="{$user_last_act}" sticky="{$r['topic_sticky']}" locked="{$r['topic_locked']}">
\t<url>javascript:void(0);</url>
\t<onclick>return f.selectTopic({$r['topic_id']});</onclick>
\t<title>{$r['topic_title']}</title>
\t<desc>{$td}</desc>
\t<count>{$r['count_posts']}</count>
\t<last_u>{$r['last_post_user']}</last_u>
\t<last_d>{$r['last_when']}</last_d>
\t<first_u>{$r['first_post_user']}</first_u>
\t<first_d>{$r['first_when']}</first_d>
</topic>
EOF;
        }
        $p = '';
        $num = $fdb->getTopicsNum($forum_id);
        for ($i = 0; $i < $num; $i += $gConf['topics_per_page']) {
            $p .= '<p c="' . ($start >= $i && $start < $i + $gConf['topics_per_page'] ? 1 : 0) . '" start="' . $i . '">' . ($i / $gConf['topics_per_page'] + 1) . '</p>';
        }
        if ($wp) {
            $li = $this->_getLoginInfo($user);
            return $this->addHeaderFooter($li, "<topics><pages>{$p}</pages>{$x2}{$x1}{$t}</topics>");
        } else {
            $cu = $this->getUrlsXml();
            return "<root>{$cu}<topics><pages>{$p}</pages>{$x2}{$x1}{$t}</topics></root>";
        }
    }