예제 #1
0
    /**
     * returns topic posts XML
     * @param $topic_id
     * @param $wp			return whole page XML
     */
    function getPostsXML($topic_uri, $wp)
    {
        global $gConf;
        $ui = array();
        $fdb = new DbForum();
        $u = $this->_getLoginUser();
        $a = $fdb->getPostsByUri($topic_uri, $u);
        $topic_id = $a[0]['topic_id'];
        // check user permission to read this topic posts
        $f = $fdb->getForum($a[0]['forum_id']);
        $forum_id = $f['forum_id'];
        $forum_type = $f['forum_type'];
        if (!$this->_checkUserPerm($u, $forum_type, 'read', $forum_id)) {
            return $this->_no_access($wp);
        }
        $canPost = (string) (int) $this->_checkUserPerm($u, $forum_type, 'post', $forum_id);
        $perm = "<perm><can_post>{$canPost}</can_post></perm>";
        $this->setTrackTopic($topic_id);
        // check user permissions to delete or edit posts
        $gl_allow_edit = 0;
        $gl_allow_del = 0;
        if ($this->_checkUserPerm($u, $forum_type, 'edit', $forum_id)) {
            $gl_allow_edit = 1;
        }
        if ($this->_checkUserPerm($u, $forum_type, 'del', $forum_id)) {
            $gl_allow_del = 1;
        }
        reset($a);
        $p = '';
        while (list(, $r) = each($a)) {
            // acquire user info
            if (!$ui[$r['user']]) {
                $aa = $this->_getUserInfo($r['user']);
                $ui[$r['user']] = array('posts' => $fdb->getUserPosts($r['user']), 'avatar' => $aa['avatar'], 'url' => $aa['profile_url'], 'onclick' => $aa['profile_onclick']);
            }
            $allow_edit = $gl_allow_edit;
            $allow_del = $gl_allow_del;
            if (!$allow_edit && $r['user'] == $u) {
                if ($this->_checkUserPerm($r['user'], 'own', 'edit', $forum_id)) {
                    $allow_edit = 1;
                }
            }
            if (!$allow_del && $r['user'] == $u) {
                if ($this->_checkUserPerm($r['user'], 'own', 'del', $forum_id)) {
                    $allow_del = 1;
                }
            }
            encode_post_text($r['post_text'], $wp, 1);
            $p .= <<<EOF
<post id="{$r['post_id']}"  force_show="0">
\t<text>{$r['post_text']}</text>
\t<when>{$r['when']}</when>
\t<allow_edit>{$allow_edit}</allow_edit>
\t<allow_del>{$allow_del}</allow_del>
\t<points>{$r['votes']}</points>
\t<vote_user_point>{$r['vote_user_point']}</vote_user_point>\t
\t<user posts="{$ui[$r['user']]['posts']}" name="{$r['user']}">
\t\t<avatar>{$ui[$r['user']]['avatar']}</avatar>
\t\t<url>{$ui[$r['user']]['url']}</url>
\t\t<onclick>{$ui[$r['user']]['onclick']}</onclick>
\t</user>
\t<min_point>{$gConf['min_point']}</min_point>
</post>
EOF;
            $rr = $r;
        }
        $t = $fdb->getTopic($rr['topic_id']);
        $cat = $fdb->getCat($f['cat_id']);
        encode_post_text($cat['cat_name'], $wp);
        $x0 = <<<EOF
<cat>
    <id>{$cat['cat_id']}</id>
    <uri>{$cat['cat_uri']}</uri>
\t<title>{$cat['cat_name']}</title>
</cat>
EOF;
        encode_post_text($t['forum_title'], $wp);
        encode_post_text($t['forum_desc'], $wp);
        $x1 = <<<EOF
<forum>
    <id>{$f['forum_id']}</id>
    <uri>{$f['forum_uri']}</uri>
\t<title>{$t['forum_title']}</title>
\t<desc>{$t['forum_desc']}</desc>
\t<type>{$f['forum_type']}</type>
</forum>
EOF;
        encode_post_text($t['topic_title'], $wp, 1);
        $x2 = <<<EOF
<topic>
    <id>{$t['topic_id']}</id>
\t<uri>{$t['topic_uri']}</uri>
    <title>{$t['topic_title']}</title>
    <locked>{$t['topic_locked']}</locked>
</topic>
EOF;
        if ($wp) {
            $li = $this->_getLoginInfo($u);
            return $this->addHeaderFooter($li, "<posts>{$perm}{$x0}{$x1}{$x2}{$p}</posts>");
        } else {
            $cu = $this->getUrlsXml();
            $li = $this->_getLoginInfo($u);
            return "<root><logininfo>" . array2xml($li) . "</logininfo>{$cu}<posts>{$perm}{$x0}{$x1}{$x2}{$p}</posts></root>";
        }
    }