private static function getNewBlogs($user) { global $vbulletin; global $vbphrase; if (! file_exists(DIR . '/packages/vbblog/search/searchcontroller/newblogentry.php') or ! (vB_Search_Core::get_instance()->get_cansearch('vBBlog', 'BlogEntry') )) { return; } include_once DIR . '/packages/vbblog/search/searchcontroller/newblogentry.php' ; require_once DIR . '/vb/search/core.php' ; require_once DIR . '/vb/search/criteria.php' ; require_once DIR . '/includes/functions_databuild.php' ; //We can use the existing new structures to create this feed. We don't // have to, we could do a direct sql query. But this structure is tested // and we know it handles permissions properly. //First we need a criteria object fetch_phrase_group('vbcms'); $criteria = vB_Search_Core::get_instance()->create_criteria(vB_Search_Core::SEARCH_NEW); //Set the count, which may have been passed to us. $max_count = 10; if ($vbulletin->GPC_exists['count'] AND intval($vbulletin->GPC['count']) and intval($vbulletin->GPC['count']) < 21) { $max_count = intval($vbulletin->GPC['count']); } //Do we get a user? If so, limit the query. if ($vbulletin->GPC_exists['userid'] AND intval($vbulletin->GPC['userid'])) { $criteria->add_userid_filter($vbulletin->GPC['userid'], true); } else if ($vbulletin->GPC_exists['searchuser']) { $criteria->add_user_filter($vbulletin->GPC['searchuser'], true); } //and set the date limit if ($vbulletin->GPC_exists['days'] AND intval($vbulletin->GPC['days'] )) { $datelimit = TIMENOW - ( intval($vbulletin->GPC['days']) * 86400); } else { $datelimit = TIMENOW - ( 3 * 86400); } $criteria->add_newitem_filter($datelimit, null, null); $search_controller = new vBBlog_Search_SearchController_NewBlogEntry; $results = vB_Search_Results::create_from_cache($user, $criteria, $search_controller); if (! $results = vB_Search_Results::create_from_cache($user, $criteria, $search_controller)) { $results = vB_Search_Results::create_from_criteria($user, $criteria, $search_controller); } $page = $results->get_page(1, $max_count, 1); $headers = array( 'title' => $vbulletin->options['hometitle'] , 'link' => $vbulletin->options['bburl'], 'description' => construct_phrase($vbphrase['recent_blogs_from_x'], $vbulletin->options['hometitle']) , 'language' => 'en-us', 'updated' => date('Y-m-d\TH:i:s', TIMENOW), 'lastBuildDate' => date('Y-m-d\TH:i:s', TIMENOW) ); $items= array(); if (count($page)) { $parser = new vBCms_BBCode_HTML(vB::$vbulletin, vBCms_BBCode_HTML::fetchCmsTags()); foreach ($page as $result) { if ($blog = $result->get_record()) { $items[] = array( 'title' => $blog['title'], 'summary' => $parser->get_preview($blog['pagetext'], 800), 'link' => $vbulletin->options['bburl'] . '/blog.php?blogid=' . $blog['blogid'], 'author' => 'noreply@noreply.com-' . $blog['username']); } } } return self::makeXml($headers, null, $items); }
/** This function prepares the preview text for an article or other bbcode text * * @param string the text to be parsed * @param int the number of chars to be returned * @param bool can this user use HTML in their content * @param str the html state of the text - on, off, or on_nl2br * * @return string * ***/ public static function makePreviewText($pagetext, $chars, $canUseHtml, $htmlstate = null) { //We don't want any table content to display when we generate the preview- unless there // is nothing else $pagetext = trim(preg_replace('/\<(\s*)TABLE(.+)\<\/TABLE\>/is', ' ', $pagetext)); $tableless_text = trim(preg_replace('/\[TABLE(.+)\[\/TABLE\]/is', ' ', $pagetext)); if ($tableless_text =='') { $tableless_text = $pagetext; } $parser = new vBCms_BBCode_HTML(vB::$vbulletin, vBCms_BBCode_HTML::fetchCmsTags()); $previewtext = $parser->get_preview( $tableless_text, $chars, $canUseHtml, true, $htmlstate); if ($previewtext =='') { $previewtext = $parser->get_preview( $pagetext, $chars, $canUseHtml, true, $htmlstate); } //We tend to get some blank lines that we don't need. $previewtext = preg_replace('/^\<br\>$/i', '', $previewtext); $previewtext = preg_replace('/^\<br\/\>$/i', '', $previewtext); $previewtext = preg_replace('/^\<br \/\>$/i', '', $previewtext); return $previewtext; }
/** This function gets the article information based on the defined criteria * * @return array */ protected function getContent() { // First, compose the sql $sql = "SELECT article.pagetext, article.previewimage, article.imagewidth, article.imageheight, article.previewvideo, article.htmlstate, node.url, node.publishdate, node.userid, node.setpublish, node.publicpreview, info.title, user.username, node.showuser, node.nodeid, node.contenttypeid, thread.replycount FROM " . TABLE_PREFIX . "cms_article AS article INNER JOIN " . TABLE_PREFIX . "cms_node AS node ON (node.contentid = article.contentid AND node.contenttypeid = " . vb_Types::instance()->getContentTypeID("vBCms_Article") . ") INNER JOIN " . TABLE_PREFIX . "cms_nodeinfo AS info on info.nodeid = node.nodeid " . ( (($this->config['categories'] != '') AND ($this->config['categories'] != '0')) ? " INNER JOIN " . TABLE_PREFIX . "cms_nodecategory nc ON nc.nodeid = node.nodeid " : '') . " LEFT JOIN " . TABLE_PREFIX . "user AS user ON user.userid = node.userid LEFT JOIN " . TABLE_PREFIX . "thread AS thread ON thread.threadid = info.associatedthreadid WHERE " . vBCMS_Permissions::getPermissionString() ; if (($this->config['categories'] != '') AND ($this->config['categories'] != '0') ) { $sql .= "\n AND nc.categoryid IN (" . $this->config['categories'] . ")\n"; } if (($this->config['sections'] != '') AND ($this->config['sections'] != '0')) { $sql .= "\n AND node.parentnode IN (" . $this->config['sections'] . ")\n"; } if (isset($this->config['days']) AND (intval($this->config['days'])) ) { $sql .= "\n AND node.publishdate > " . (TIMENOW - (86400 * $this->config['days'])) . "\n"; } $sql .= "\n ORDER BY node.publishdate DESC LIMIT " . $this->config['count']; $articles = array(); //Execute if ($rst = vB::$db->query_read($sql)) { $current_record = array('contentid' => -1); $contenttypeid = vb_Types::instance()->getContentTypeId($this->package . '_' . $this->view_class); //now build the results array $bbcode_parser = new vBCms_BBCode_HTML(vB::$vbulletin, vBCms_BBCode_HTML::fetchCmsTags()); while($article = vB::$db->fetch_array($rst)) { $article['categories'] = array(); $article['tags'] = array(); $allow_html = vBCMS_Permissions::canUseHtml($article['nodeid'], $contenttypeid, $article['userid']); $pagetext = $bbcode_parser->get_preview(fetch_censored_text($article['pagetext']), vB::$vbulletin->options['default_cms_previewlength'], $allow_html); $article['previewtext'] = strip_bbcode($pagetext); //get the avatar if (vB::$vbulletin->options['avatarenabled']) { $article['avatar'] = fetch_avatar_url($article['userid']); } $articles[$article['nodeid']] = $article; } //Let's get the tags and the categories // we can do that with one query each. if (count($articles)) { //first let's get categories $nodeids = implode(', ', array_keys($articles)); $sql = "SELECT nc.nodeid, nc.categoryid, category.category FROM " . TABLE_PREFIX . "cms_nodecategory AS nc INNER JOIN " . TABLE_PREFIX . "cms_category AS category ON category.categoryid = nc.categoryid WHERE nc.nodeid IN ($nodeids)"; if ($rst = vB::$db->query_read($sql)) { while ($record = vB::$db->fetch_array($rst)) { $route_info = $record['categoryid'] . ($record['category'] != '' ? '-' . str_replace(' ', '-', $record['category']) : ''); $record['route_info'] = $route_info; $record['category_url'] = vB_Route::create('vBCms_Route_List', "category/" . $record['route_info'] . "/1")->getCurrentURL(); $articles[$record['nodeid']]['categories'][$record['categoryid']] = $record; } } //next tags; $sql = "SELECT tag.tagid, node.nodeid, tag.tagtext 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 ($nodeids) "; if ($rst = vB::$db->query_read($sql)) { while ($record = vB::$db->fetch_array($rst)) { $articles[$record['nodeid']]['tags'][$record['tagid']] = $record['tagtext']; } } } } return $articles; }