コード例 #1
0
ファイル: cms.php プロジェクト: 0hyeah/yurivn
function do_get_cms_article()
{
    global $vbulletin, $db, $contenttype;
    $vbulletin->input->clean_array_gpc('r', array('articleid' => TYPE_UINT, 'page' => TYPE_UINT, 'perpage' => TYPE_UINT));
    if (!$vbulletin->GPC['articleid']) {
        json_error(ERR_NO_PERMISSION);
    }
    $page = 1;
    if ($vbulletin->GPC['page']) {
        $page = $vbulletin->GPC['page'];
    }
    $perpage = 10;
    if ($vbulletin->GPC['perpage']) {
        $perpage = $vbulletin->GPC['perpage'];
    }
    if ($perpage > 50 || $perpage < 5) {
        $perpage = 10;
    }
    if ($page < 1) {
        $page = 1;
    }
    $articleid = $vbulletin->GPC['articleid'];
    $article = new vBCms_Item_Content_Article($articleid, vBCms_Item_Content::INFO_CONTENT);
    $associated_thread_id = $article->getAssociatedThreadId();
    if (!$associated_thread_id) {
        $associated_thread_id = create_associated_thread($article);
        if ($associated_thread_id) {
            $article->setAssociatedThread($associated_thread_id);
        }
    }
    $posts_out = array();
    $fr_images = array();
    // Display article if on first page of comments
    if ($page == 1) {
        // First, the article
        $postdate = vbdate($vbulletin->options['dateformat'], $article->getPublishDate(), 1);
        $posttime = vbdate($vbulletin->options['timeformat'], $article->getPublishDate());
        // Parse the post for quotes and inline images
        $contenttype = vB_Types::instance()->getContentTypeID("vBCms_Article");
        // Attachments (images).
        if (count($post['attachments']) > 0) {
            foreach ($post['attachments'] as $attachment) {
                $lfilename = strtolower($attachment['filename']);
                if (strpos($lfilename, '.jpe') !== false || strpos($lfilename, '.png') !== false || strpos($lfilename, '.gif') !== false || strpos($lfilename, '.jpg') !== false || strpos($lfilename, '.jpeg') !== false) {
                    $fr_images[] = array('img' => $vbulletin->options['bburl'] . '/attachment.php?attachmentid=' . $attachment['attachmentid'], 'tmb' => $vbulletin->options['bburl'] . '/attachment.php?attachmentid=' . $attachment['attachmentid'] . '&stc=1&thumb=1');
                }
            }
        }
        list($text, $nuked_quotes, $images) = parse_post(strip_tags($article->getPageText()), false);
        if (count($fr_images) > 0) {
            $text .= "<br/>";
            foreach ($fr_images as $attachment) {
                $text .= "<img src=\"{$attachment['img']}\"/>";
            }
        }
        foreach ($images as $image) {
            $fr_images[] = array('img' => $image);
        }
        $avatarurl = '';
        // Avatar work
        if ($vbulletin->options['avatarenabled']) {
            require_once DIR . '/includes/functions_user.php';
            $userinfo = fetch_userinfo($article->getUserId(), FETCH_USERINFO_AVATAR);
            fetch_avatar_from_userinfo($userinfo);
            if ($userinfo['avatarurl']) {
                $avatarurl = process_avatarurl($userinfo['avatarurl']);
            }
        }
        $tmp = array('post_id' => $article->getPostId() ? $article->getPostId() : 999999999, 'thread_id' => $associated_thread_id, 'username' => prepare_utf8_string($article->getUsername()), 'joindate' => prepare_utf8_string($userinfo['joindate']), 'usertitle' => prepare_utf8_string(strip_tags($userinfo['usertitle'])), 'numposts' => $userinfo['posts'], 'userid' => $userinfo['userid'], 'post_timestamp' => prepare_utf8_string(date_trunc($postdate) . ' ' . $posttime), 'fr_images' => $fr_images, 'image_thumbs' => array());
        $tmp['text'] = $text;
        $tmp['quotable'] = $nuked_quotes;
        if ($post['editlink']) {
            $tmp['canedit'] = true;
            $tmp['edittext'] = prepare_utf8_string($post['pagetext']);
        }
        if ($avatarurl != '') {
            $tmp['avatarurl'] = $avatarurl;
        }
        if ($article->getPreviewVideo()) {
            if (preg_match(',data="(.*?)",', $article->getPreviewVideo(), $matches)) {
                $video = $matches[1];
                if (strpos($matches[1], 'vimeo')) {
                    $clip_id = 0;
                    if (preg_match(',clip_id=(\\d+),', $matches[1], $matches2)) {
                        $clip_id = $matches2[1];
                    } else {
                        if (preg_match(',vimeo\\.com/(\\d*)?,', $matches[1], $matches2)) {
                            $clip_id = $matches2[1];
                        } else {
                            $clip_id = $matches[1];
                        }
                    }
                    $video = "<iframe src=\"http://player.vimeo.com/video/{$clip_id}\" ignore=\"%@\" width=\"%0.0f\" height=\"%d\" frameborder=\"0\"></iframe>";
                } else {
                    $video = <<<EOF
<object id="videoc" width="%0.0f" height="%d">
<param name="movie" value="{$matches[1]}"></param>
<param name="wmode" value="transparent"></param>
<embed wmode="transparent" id="video" src="{$matches[1]}" type="application/x-shockwave-flash" width="%0.0f" height="%d"></embed>
</object>
EOF;
                }
                $tmp['video'] = prepare_utf8_string($video);
            }
        }
        $posts_out[] = $tmp;
    }
    $this_user = new vB_Legacy_CurrentUser();
    $threadinfo = verify_id('thread', $associated_thread_id, 0, 1);
    // Now, get the posts
    $total = 0;
    if ($associated_thread_id) {
        $comments = get_article_comments($article, $associated_thread_id, $this_user, $page, $perpage, $total);
        $posts_out = array_merge($posts_out, $comments);
    }
    $canpost = true;
    $userid = $this_user->get_field('userid');
    if (empty($userid)) {
        $canpost = false;
    }
    if ($userid != $threadinfo['postuserid']) {
        $canpost = $this_user->hasForumPermission($threadinfo['forumid'], 'canreplyothers');
    } else {
        $canpost = $this_user->hasForumPermission($threadinfo['forumid'], 'canreplyown');
    }
    return array('posts' => $posts_out, 'total_posts' => $total, 'page' => $page, 'canpost' => $canpost, 'threadid' => $associated_thread_id, 'title' => prepare_utf8_string($article->getTitle()));
}