Exemple #1
0
	/**
	 * this will create an array of result objects from an array of ids()
	 *
	 * @param array of integer $ids
	 * @return array of objects
	 */
	public static function create_array($ids)
	{
		$contenttypeid = vb_Types::instance()->getContentTypeId('vBCms_Article');
		$rst = vB::$vbulletin->db->query_read($sql = "
			SELECT a.contentid as itemid, a.htmlstate,
				u.username, a.contentid, n.nodeid, u.userid, i.html_title, a.blogid, n.setpublish AS published,
				n.url, n.showtitle, n.showuser, n.showpreviewonly,
				n.showupdated, n.showviewcount, n.settingsforboth,
				a.pagetext, i.title, i.description, n.publishdate, parent.title as parenttitle, i.viewcount,
				n.parentnode as parentid, a.threadid, a.postauthor, a.poststarter, a.blogpostid,
				a.postid, a.post_started, a.post_posted, thread.threadid AS comment_threadid , thread.title AS threadtitle, thread.replycount,
				thread.lastposterid, thread.lastposter, thread.dateline, thread.views, thread.lastpost
			FROM " . TABLE_PREFIX . "cms_article a
				LEFT JOIN " . TABLE_PREFIX . "cms_node n ON n.contentid = a.contentid
  			LEFT JOIN " . TABLE_PREFIX . "cms_nodeinfo i ON i.nodeid = n.nodeid
  			LEFT JOIN " . TABLE_PREFIX . "cms_nodeinfo AS parent ON parent.nodeid = n.parentnode
  			LEFT JOIN " . TABLE_PREFIX . "thread AS thread ON thread.threadid = i.associatedthreadid
  			LEFT JOIN " . TABLE_PREFIX . "user u ON u.userid = n.userid
			WHERE a.contentid IN (" . implode(', ', $ids) .") AND n.contenttypeid = " . $contenttypeid
		);

		$id_list = array();
		$items = array();

		if ($rst)
		{
			$bbcode_parser = new vBCms_BBCode_HTML(vB::$vbulletin, vBCms_BBCode_HTML::fetchCmsTags());
			$bbcode_parser->setOutputPage(1);
			while ($search_result = vB::$vbulletin->db->fetch_array($rst))
			{
				//If unpublished we hide this.
				if (!($search_result['publishdate'] < TIMENOW))
				{
					continue;
				}
				$item = new vBCms_Search_Result_Article();
				$item->itemid = $search_result['itemid'];
				$categories = array();
				$tags = array();
				$item->contenttypeid = $contenttypeid;
				$search_result['pagetext'] = $bbcode_parser->do_parse($search_result['pagetext'], true);
				$search_result['categories'] = $categories;
				$item->record = $search_result;
				$id_list[$search_result['nodeid']] = $search_result['itemid'];
				$items[$search_result['itemid']] = $item;
			}

			//avoid database error when all cms items are filtered out.
			if (!count($id_list))
			{
				return array();
			}

			$ids = implode(', ', array_keys($id_list));
			$rst1 = vB::$vbulletin->db->query_read(
				"SELECT cat.categoryid, cat.category, nc.nodeid FROM " .
				TABLE_PREFIX . "cms_nodecategory AS nc INNER JOIN " .	TABLE_PREFIX .
				"cms_category AS cat ON nc.categoryid = cat.categoryid WHERE nc.nodeid IN ($ids)"
			);

			if ($rst1)
			{
				$route = new vBCms_Route_List();
				$route->setParameter('action', 'list');

				while($record = vB::$vbulletin->db->fetch_array($rst1))
				{
					$itemid = $id_list[$record['nodeid']];
					$route_info = $record['categoryid'] .
						($record['category'] != '' ? '-' . $record['category'] : '');
					$record['category_url'] = vBCms_Route_List::getUrl(array('type' =>'category',
					 'value' => $route_info , 'page' => 1));
					$items[$itemid]->addCategory($record['categoryid'], $record)  ;
				}
			}

			if ($rst1 = vB::$vbulletin->db->query_read("SELECT tag.tagid, tag.tagtext, node.contentid FROM " .
				TABLE_PREFIX . "cms_node AS node INNER JOIN " .	TABLE_PREFIX .
				"tagcontent AS tc ON (tc.contentid = node.contentid AND  tc.contenttypeid = node.contenttypeid)
				INNER JOIN " .	TABLE_PREFIX .
				"tag AS tag ON tag.tagid = tc.tagid
				 WHERE node.nodeid IN ($ids) " ))
			{
				while($record = vB::$vbulletin->db->fetch_array($rst1))
				{
					$items[$record['contentid']]->addTag($record['tagid'], $record);
			}
			}
			return $items;
		}
		return false;
	}
Exemple #2
0
	public function getPageTitle()
	{
		if (!$this->pagelist)
		{
			$bbcode_parser = new vBCms_BBCode_HTML(vB::$vbulletin, vBCms_BBCode_HTML::fetchCmsTags());

			$bbcode_parser->setOutputPage($this->parameters['page']);
			$this->pagelist = $bbcode_parser->getPageTitles();
		}

		if ((count($this->pagelist) > 1)  AND isset($this->pagelist[$this->parameters['page']]))
		{
			return $this->content->getHtmlTitle() . '--' . $this->pagelist[$this->parameters['page']];
		}
		return $this->content->getHtmlTitle();

	}
Exemple #3
0
	public function getRendered($forceload = false)
	{
		$context = new vB_Context($this->package . '_' . $this->class . '_pagetext_' ,
			array( 'nodeid' => $this->nodeid,
			'permissions' => vB::$vbulletin->userinfo['permissions']['cms']));
		$hashkey = strval($context);
		if (!$forceload AND ($rendered = vB_Cache::instance()->read($hashkey, true, true)))
		{
			return $rendered;
		}
		$this->Load(self::INFO_CONTENT);

		$bbcode_parser = new vBCms_BBCode_HTML(vB::$vbulletin, vBCms_BBCode_HTML::fetchCmsTags());
		$bbcode_parser->setCanDownload($this->canDownload());
		$pages = array();
		// Articles will generally have an attachment but they should still keep a counter so that this query isn't always running
		require_once(DIR . '/packages/vbattach/attach.php');
		if ($this->canDownload())
		{
			$viewinfo = array();
			$attach = new vB_Attach_Display_Content(vB::$vbulletin, 'vBCms_Article');
			$attachments = $attach->fetch_postattach(0, $this->nodeid);
			$bbcode_parser->attachments = $attachments;
			$bbcode_parser->unsetattach = true;
		}

		$validpage = true;
		$pageno = 1;

		require_once DIR . '/includes/functions.php';
		while($validpage)
		{
			$bbcode_parser->setOutputPage($pageno);

			$pagetext = fetch_censored_text($bbcode_parser->do_parse(
				$this->pagetext,
				vBCMS_Permissions::canUseHtml($this->nodeid, $this->contenttypeid, $this->userid),
				$this->htmlstate
				));

			$validpage = $bbcode_parser->fetchedValidPage();

			if ($pageno == 1)
			{
				$pagelist = $bbcode_parser->getPageTitles();
			}

			if ($validpage)
			{
				$pages[$pageno] = $pagetext;
			}

			$pageno++;
		}
		if ($this->canDownload())
		{
			$attach->process_attachments($viewinfo, $bbcode_parser->attachments, false, false, true, false, true);
		}

		$rendered = array('pages' => $pages, 'attachments' => $bbcode_parser->attachments,
			'viewinfo' => $viewinfo, 'pagelist' => $pagelist);
		vB_Cache::instance()->write($hashkey ,
			$rendered, 1440, array_merge($this->getCacheEvents(), array($this->getContentCacheEvent())));
		//If we updated the page text we need to also update the preview.
		$this->getPreviewText(true);
		return $rendered;
	}