Exemple #1
0
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()));
}
/**
 * get_article
 * 
 * 
 * 
 * 
 * 
 * 
 */
function get_article($article_id = '')
{
    $article_id = (int) $article_id;
    $conn = reader_connect();
    $query = "SELECT\n\t\t\t\t\tarticles.id, \n\t\t\t\t \tarticles.title, \n\t\t\t\t\tarticles.url, \n\t\t\t\t\tarticles.summary, \n\t\t\t\t\tarticles.body, \n\t\t\t\t\tarticles.date_uploaded, \n\t\t\t\t\tarticles.date_amended,\n\t\t\t\t\tcategories.title AS category_title, \n\t\t\t\t\tcategories.url AS category_url,\n\t\t\t\t\tparent.title AS parent_category_title,\n\t\t\t\t\tparent.url AS parent_category_url,\n\t\t\t\t\tauthors.name AS author_name, \n\t\t\t\t\tauthors.url AS author_url,\n\t\t\t\t\tauthors.email AS author_email,\n\t\t\t\t\tauthors.contact_flag, \n\t\t\t\t\tarticles.seo_title,\n\t\t\t\t\tarticles.seo_desc, \n\t\t\t\t\tarticles.seo_keywords,\n\t\t\t\t\tarticles.redirect_url,\n\t\t\t\t\tarticles.redirect_code,\n\t\t\t\t\tarticles.comments_disable, \n\t\t\t\t\tarticles.comments_hide\n\t\t\t\tFROM articles\n\t\t\t\t\tLEFT JOIN authors ON articles.author_id = authors.id \n\t\t\t\t\tLEFT JOIN categories ON articles.category_id = categories.id\n\t\t\t\t\tLEFT JOIN categories AS parent ON categories.category_id = parent.id\n\t\t\t\tWHERE articles.status IN('P','A')\n\t\t\t\t\tAND articles.date_uploaded <= UTC_TIMESTAMP()";
    $query .= !empty($article_id) ? " AND articles.id = " . $article_id : " ORDER BY articles.id DESC LIMIT 0,1";
    $result = $conn->query($query);
    $row = $result->fetch_assoc();
    // if a redirect url has been set we redirect right here
    if (!empty($row['redirect_url'])) {
        // send 301 redirect unless another valid code has been set
        $redirect_code = (int) $row['redirect_code'];
        $redirect_code = !empty($redirect_code) ? $redirect_code : 301;
        redirect_article($row['redirect_url'], $redirect_code);
    }
    $row = stripslashes_deep($row);
    $result->close();
    // adjust times to local timezone if necessary
    $ts = strtotime($row['date_uploaded']);
    $offset = date('Z');
    $row['date_ts'] = $ts + $offset;
    $row['date_uploaded'] = date('Y-m-d H:i:s', $row['date_ts']);
    // fix relative urls
    $row['body'] = convert_relative_urls($row['body']);
    // check pagination
    $row['pages'] = paginate_article_body($row['body']);
    $row['total_pages'] = count($row['pages']);
    // create links
    $row['link']['blog'] = WW_REAL_WEB_ROOT . '/' . date('Y/m/d', $row['date_ts']) . '/' . $row['url'] . '/';
    $row['link']['cms'] = WW_REAL_WEB_ROOT . '/' . $row['category_url'] . '/' . $row['url'] . '/';
    // put category url in a get param if not set (for custom css styles)
    $_GET['category_url'] = isset($_GET['category_url']) ? $_GET['category_url'] : $row['category_url'];
    // get tags
    $tags = get_article_tags($article_id);
    $row['tags'] = !empty($tags) ? $tags : '';
    // get attachments
    $attachments = get_article_attachments($article_id);
    $row['attachments'] = !empty($attachments) ? $attachments : '';
    // get comments
    if (empty($row['comments_hide'])) {
        $comments = get_article_comments($article_id);
        $row['comments'] = !empty($comments) ? $comments : '';
    }
    return $row;
}
/**
 * get_article
 * 
 * 
 * 
 * 
 * 
 * 
 */
function get_article($article_id = '')
{
    $article_id = (int) $article_id;
    $conn = reader_connect();
    $query = "SELECT\n\t\t\t\t\tarticles.id, \n\t\t\t\t \tarticles.title, \n\t\t\t\t\tarticles.url, \n\t\t\t\t\tarticles.summary, \n\t\t\t\t\tarticles.body, \n\t\t\t\t\tarticles.date_uploaded, \n\t\t\t\t\tarticles.date_amended,\n\t\t\t\t\tcategories.title AS category_title, \n\t\t\t\t\tcategories.url AS category_url,\n\t\t\t\t\tparent.title AS parent_category_title,\n\t\t\t\t\tparent.url AS parent_category_url,\n\t\t\t\t\tauthors.name AS author_name, \n\t\t\t\t\tauthors.url AS author_url,\n\t\t\t\t\tauthors.email AS author_email,\n\t\t\t\t\tauthors.contact_flag, \n\t\t\t\t\tarticles.seo_title,\n\t\t\t\t\tarticles.seo_desc, \n\t\t\t\t\tarticles.seo_keywords,\n\t\t\t\t\tarticles.comments_disable, \n\t\t\t\t\tarticles.comments_hide\n\t\t\t\tFROM articles\n\t\t\t\t\tLEFT JOIN authors ON articles.author_id = authors.id \n\t\t\t\t\tLEFT JOIN categories ON articles.category_id = categories.id\n\t\t\t\t\tLEFT JOIN categories AS parent ON categories.category_id = parent.id\n\t\t\t\tWHERE articles.status IN('P','A')\n\t\t\t\t\tAND articles.date_uploaded <= NOW()";
    $query .= !empty($article_id) ? " AND articles.id = " . $article_id : " ORDER BY articles.id DESC LIMIT 0,1";
    // echo $query;
    $result = $conn->query($query);
    $row = $result->fetch_assoc();
    $row = stripslashes_deep($row);
    $result->close();
    // fix relative urls
    $row['body'] = convert_relative_urls($row['body']);
    // check pagination
    $row['pages'] = paginate_article_body($row['body']);
    $row['total_pages'] = count($row['pages']);
    // create links
    $row['link']['blog'] = WW_REAL_WEB_ROOT . '/' . date('Y/m/d', strtotime($row['date_uploaded'])) . '/' . $row['url'] . '/';
    $row['link']['cms'] = WW_REAL_WEB_ROOT . '/' . $row['category_url'] . '/' . $row['url'] . '/';
    // get tags
    $tags = get_article_tags($article_id);
    $row['tags'] = !empty($tags) ? $tags : '';
    // get attachments
    $attachments = get_article_attachments($article_id);
    $row['attachments'] = !empty($attachments) ? $attachments : '';
    // get comments
    if (empty($row['comments_hide'])) {
        $comments = get_article_comments($article_id);
        $row['comments'] = !empty($comments) ? $comments : '';
    }
    return $row;
}
Exemple #4
0
 function get($slug)
 {
     $article = get_article_by_slug($slug);
     $comments = get_article_comments($article['id']);
     include "views/article.php";
 }