示例#1
0
文件: cms.php 项目: 0hyeah/yurivn
function do_get_cms_section()
{
    global $vbulletin, $db;
    $vbulletin->input->clean_array_gpc('r', array('sectionid' => TYPE_UINT, 'page' => TYPE_UINT, 'perpage' => TYPE_UINT));
    $sectionid = $vbulletin->GPC['sectionid'];
    if (!$vbulletin->GPC_exists['sectionid']) {
        $sectionid = 1;
    }
    $sectionid = intval($sectionid);
    $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;
    }
    $limitsql = 'LIMIT ' . ($page - 1) * $perpage . ', ' . $perpage;
    if (!isset(vB::$vbulletin->userinfo['permissions']['cms'])) {
        vBCMS_Permissions::getUserPerms();
    }
    $config = $vbulletin->db->query_first("\n\tSELECT config1.value AS priority, config2.value AS contentfrom, nodeinfo.title AS section_title\n\tFROM " . TABLE_PREFIX . "cms_node AS node\n\tLEFT JOIN " . TABLE_PREFIX . "cms_nodeconfig AS config1 ON config1.nodeid = node.nodeid AND config1.name = 'section_priority'\n\tLEFT JOIN " . TABLE_PREFIX . "cms_nodeconfig AS config2 ON config2.nodeid = node.nodeid AND config2.name = 'contentfrom'\n\tLEFT JOIN " . TABLE_PREFIX . "cms_nodeinfo AS nodeinfo ON nodeinfo.nodeid = node.nodeid\n\tWHERE node.nodeid = {$sectionid}\n\tGROUP BY node.nodeid\n    ");
    $sortby = 3;
    $exact = false;
    $section_title = 'News';
    if ($config) {
        if (isset($config['priority'])) {
            $sortby = intval($config['priority']);
        }
        if (isset($config['contentfrom'])) {
            if (intval($config['contentfrom']) != 2) {
                $exact = true;
            }
        }
        if (isset($config['section_title'])) {
            $section_title = $config['section_title'];
        }
    }
    $extrasql = $orderby = '';
    if ($sortby == 3) {
        $extrasql = " INNER JOIN (SELECT parentnode, MAX(lastupdated) AS lastupdated\n\t    FROM " . TABLE_PREFIX . "cms_node  AS node WHERE contenttypeid <> " . vb_Types::instance()->getContentTypeID("vBCms_Section") . " AND\t" . vBCMS_Permissions::getPermissionString() . " GROUP BY parentnode ) AS ordering ON ordering.parentnode = node.parentnode\n\t    AND node.lastupdated = ordering.lastupdated WHERE 1=1";
        $orderby = " ORDER BY node.setpublish DESC, node.publishdate DESC ";
    } else {
        if ($sortby == 2) {
            $orderby = " ORDER BY node.publishdate DESC ";
        } else {
            if ($sortby == 4) {
                $orderby = " ORDER BY info.title ASC ";
            } else {
                if ($sortby == 5) {
                    $orderby = " ORDER BY sectionorder.displayorder ASC ";
                } else {
                    $orderby = " ORDER BY CASE WHEN sectionorder.displayorder > 0 THEN sectionorder.displayorder ELSE 9999999 END ASC,\n\t    node.publishdate DESC";
                }
            }
        }
    }
    $sql = "\n\tSELECT SQL_CALC_FOUND_ROWS\n\t    node.nodeid AS itemid,\n\t    (node.nodeleft = 1) AS isroot, node.nodeid, node.contenttypeid, node.contentid, node.url, node.parentnode, node.styleid, node.userid,\n\t    node.layoutid, node.publishdate, node.setpublish, node.issection, parent.permissionsfrom as parentpermissions,\n\t    node.permissionsfrom, node.publicpreview, node.showtitle, node.showuser, node.showpreviewonly, node.showall,\n\t    node.showupdated, node.showviewcount, node.showpublishdate, node.settingsforboth, node.includechildren, node.editshowchildren,\n\t    node.shownav, node.hidden, node.nosearch, node.nodeleft,\n\t    info.description, info.title, info.html_title, info.viewcount, info.creationdate, info.workflowdate,\n\t    info.workflowstatus, info.workflowcheckedout, info.workflowlevelid, info.associatedthreadid,\n\t    user.username, sectionorder.displayorder, thread.replycount, parentinfo.title AS parenttitle\n\tFROM " . TABLE_PREFIX . "cms_node AS node\n\tINNER JOIN " . TABLE_PREFIX . "cms_nodeinfo AS info ON info.nodeid = node.nodeid\n\tLEFT JOIN " . TABLE_PREFIX . "user AS user ON user.userid = node.userid\n\tLEFT JOIN " . TABLE_PREFIX . "thread AS thread ON thread.threadid = info.associatedthreadid\n\tLEFT JOIN " . TABLE_PREFIX . "cms_sectionorder AS sectionorder ON sectionorder.sectionid = {$sectionid}\n\tAND sectionorder.nodeid = node.nodeid\n\tLEFT JOIN " . TABLE_PREFIX . "cms_node AS parent ON parent.nodeid = node.parentnode\n\tLEFT JOIN " . TABLE_PREFIX . "cms_nodeinfo AS parentinfo ON parentinfo.nodeid = parent.nodeid\n\t" . ($sectionid ? " INNER JOIN " . TABLE_PREFIX . "cms_node AS rootnode\n\t\t\t\t\tON rootnode.nodeid = {$sectionid}\n\t\t\t\t\tAND (node.nodeleft >= rootnode.nodeleft AND node.nodeleft <= rootnode.noderight) AND node.nodeleft != rootnode.nodeleft " : '') . $extrasql . " AND node.contenttypeid <> " . vb_Types::instance()->getContentTypeID("vBCms_Section") . " AND node.new != 1 " . " AND ( (" . vBCMS_Permissions::getPermissionString() . ") OR (node.setpublish AND node.publishdate <" . TIMENOW . " AND node.publicpreview > 0)) " . ($exact ? "AND (node.parentnode = " . intval($sectionid) . " OR sectionorder.displayorder > 0 )" : '') . ($sortby == 5 ? " AND sectionorder.displayorder > 0 " : '') . "\n\t\t\t\t{$orderby}\n\t\t\t\t{$limitsql}\n    ";
    $articles = array();
    $items = $vbulletin->db->query_read_slave($sql);
    $total = $vbulletin->db->found_rows();
    while ($item = $vbulletin->db->fetch_array($items)) {
        $article = new vBCms_Item_Content_Article($item['nodeid'], vBCms_Item_Content::INFO_CONTENT);
        $tmp = array('articleid' => $article->getNodeId(), 'title' => prepare_utf8_string($article->getTitle()), 'pubdate' => prepare_utf8_string(vbdate('M j, Y g:i A T', $article->getPublishDate())), 'preview' => prepare_utf8_string(preview_chop(str_replace(array("\n", "\r", "\t"), array('', '', ''), strip_tags($article->getPreviewText(false))), FR_PREVIEW_LEN)));
        $thread_id = $article->getThreadId();
        if ($thread_id) {
            $tmp['threadid'] = $thread_id;
        }
        $previewimage = $article->getPreviewImage();
        if ($previewimage) {
            if (strpos($previewimage, 'http') === false) {
                $previewimage = $vbulletin->options['bburl'] . '/' . $previewimage;
            }
            $tmp['image'] = $vbulletin->options['bburl'] . "/forumrunner/image.php?url={$previewimage}&w=160&h=160";
        }
        $articles[] = $tmp;
    }
    $out = array('total_articles' => $total, 'articles' => $articles, 'section_title' => prepare_utf8_string(strip_tags($section_title)));
    return $out;
}
示例#2
0
	/** Gets the preview text for the article
	 *
	 * @return	string	previewtext
	 ***/
	public function getPreviewText($article)
	{
		$context = new vB_Context('vbcms_article_previewtext_' . $article['nodeid']);
		$hashkey = strval($context);
		if ($rendered = vB_Cache::instance()->read($hashkey, true, true))
		{
			return $rendered;
		}

		$item =  new vBCms_Item_Content_Article($article['nodeid'], vBCms_Item_Content::INFO_CONTENT);
		return fetch_censored_text($item->getPreviewText()) ;
	}