Example #1
0
	/**
	 * vBCms_Rssfeed::makeRss()
	 * This is the function that processes the request. All the parameters
	 * we need are in vbulletin->GPC. The variables we look for are
	 * 'type' => TYPE_UINT,
	 * 'count' => TYPE_UINT,
	 * 'id' => TYPE_UINT,
	 * 'grouped' => TYPE_UINT,
	 * 'days' => TYPE_UINT, (date limit)
	 * 'detail' => TYPE_STR, (can be any extra info)
	 * 'name' => TYPE_STR
	 * We need at least the type, but the others may or may not be needed by
	 * a particular feed
	 *
	 * @param vB_Legacy_User
	 */
	public static function makeRss()
	{
		global $vbulletin;
		
		$user = vB_Legacy_User::createFromId(0);

		if (!intval($vbulletin->options['externalcache']) OR $vbulletin->options['externalcache'] > 1440)
		{
			$externalcache = 60;
		}
		else
		{
			$externalcache = $vbulletin->options['externalcache'];
		}

		$cachehash = md5(
			$vbulletin->GPC['days'] . '|' .
			$vbulletin->GPC['type'] . '|' .
			$vbulletin->GPC['count'] . '|' .
			$vbulletin->GPC['grouped'] . '|' .
			$vbulletin->GPC['detail'] . '|' .
			$vbulletin->GPC['name']
		);

		$result = vB_Cache::instance()->read($cachehash, true, false);

		if (!$result)
		{

			switch($vbulletin->GPC['type'])
			{
				case 'newposts':
					$result = self::getNewPosts($user);
					break;
				case 'newblogs':
					$result = self::getNewBlogs($user);
					break;
				case 'newcontent':
						$result = self::getNewContent($user);
					break;
				default:
					$result = '';
			} // switch
			vB_Cache::instance()->write($cachehash ,
				$result, $externalcache);
		}
		header('Content-Type: text/xml' . (vB_Template_Runtime::fetchStyleVar('charset') != '' ? '; charset=' .  vB_Template_Runtime::fetchStyleVar('charset') : ''));

		echo $result ;
	}
Example #2
0
 /**
  * Get the user for this post
  *
  * @return vB_Legacy_User
  */
 public function get_user()
 {
     if (is_null($this->user)) {
         return vB_Legacy_User::createFromId($this->record['userid']);
     }
     return $this->user;
 }
Example #3
0
	private function renderResult($config, $results, $criteria, $current_user)
	{
		require_once DIR . "/includes/functions_user.php";
		//None of the search result renderers do this right. Instead
		// we need two templates- one for the header and one for each row
		if (count($results))
		{
			//Here we have something of a dilemma. We need to verify permissions
			// for each post. That requires that we instantiate the object, so we've got
			// two sql calls per object. We could reduce that by instantiating an array, but we
			// still make a second query to get the thread. So I guess we'll just brute-force it.
			$views =	'' ;
			$current_user = new vB_Legacy_CurrentUser();
			$count = 0;
			foreach ($results as $result)
			{
				// title comes in encoded already and gets encoded again in the view
				$result['title'] = unhtmlspecialchars($result['title']);
				$post = vB_Legacy_Post::create_from_id($result['postid']);
				if (!empty($post) AND is_object($post) AND $post->can_view($current_user))
				{
					$view = new vB_View($config['inner_template']);
					$user = vB_Legacy_User::createFromId($post->get_field('userid'));

					if (vB::$vbulletin->options['avatarenabled'])
					{
						$avatar = fetch_avatar_url($result['userid']);
					}

					$view->avatar = $avatar;
					$view->record = $result;
					$view->node_url = vB_Route::create('vBCms_Route_Content', $result['nodeid'] .
						($result['url'] != '' ? '-' . $result['url'] : '') )->getCurrentURL();
					$view->node_title = htmlspecialchars_uni($result['title']);

					// Comment url
					$join_char = strpos($view->node_url,'?') ? '&' : '?';
					$view->comment_url = $view->node_url . $join_char . "commentid=" . $post->get_field('postid') . "#post" . $post->get_field('postid');

					$view->post = $this->addVariables($post);
					$thread = $post->get_thread();
					$view->threadinfo = array('threadid' => $thread->get_field('threadid'),
						 'title' => $thread->get_field('title'));
					$view->dateformat = $vbulletin->options['dateformat'];
					$view->timeformat = $vbulletin->options['default_timeformat'];
					$view->dateline =  $post->get_field('dateline');

					$views .= $view->render();
					$count++;
					if ($count >= intval($config['count']))
					{
						break;
					}

				}
			}
			return $views;

		}
	}
Example #4
0
	/**
	 * function to return the rendered html for this result
	 *
	 * @param string $current_user
	 * @param object $criteria
	 * @return
	 */
	public function render($current_user, $criteria, $template_name = '')
	{
		global $vbulletin;
		global $show;
		require_once DIR . '/vb/search/searchtools.php';
		require_once DIR . "/includes/functions_user.php";
		require_once DIR . "/includes/functions.php";

		if (!strlen($template_name))
		{
			$template_name = 'vbcms_searchresult_article_general';
		}
		$template = vB_Template::create($template_name);

		$template->register('title', vBCMS_Permissions::canUseHtml($this->record['nodeid'], vb_Types::instance()->getContentTypeId('vBCms_Article'),
			 $this->record['userid']) ? $this->record['title'] : htmlspecialchars_uni($this->record['title']));
		$template->register('html_title', vBCMS_Permissions::canUseHtml($this->record['nodeid'], vb_Types::instance()->getContentTypeId('vBCms_Article'),
			 $this->record['userid']) ? $this->record['html_title'] : htmlspecialchars_uni($this->record['html_title']));

		// Bug 35855: due to a different bug, 35413, users are able to save articles with
		// invalid seo url aliases. this causes the getCurrentUrl to throw a vB_Exception_Router
		// exception when attempting to build article URL's for search. so, to prevent
		// the search from blowing up on these articles results, we will trap these exceptions,
		// and generate the url without the alias in that case
		try
		{
			$page_url = vB_Route::create('vBCms_Route_Content', $this->record['nodeid'] .
				($this->record['url'] == '' ? '' : '-' . $this->record['url'] ))->getCurrentURL();
		}
		catch (vB_Exception_Router $e)
		{
			$page_url = vB_Route::create('vBCms_Route_Content', $this->record['nodeid'])->getCurrentURL();
		}
		$template->register('page_url', $page_url);
		$this->record['page_url'] = $page_url;
		try
		{
			$parent_url = vB_Route::create('vBCms_Route_Content', $this->record['parentid'] .
				($this->record['parenttitle'] == '' ? '' : '-' . $this->record['parenttitle'] )	)->getCurrentURL();
		}
		catch (vB_Exception_Router $e)
		{
			$parent_url = vB_Route::create('vBCms_Route_Content', $this->record['parentid'])->getCurrentURL();
		}
		$template->register('parent_url', $parent_url);

		$template->register('lastcomment_url', $page_url . "#new_comment");
		$template->register('username', $this->record['username']);
		$template->register('description', $this->record['description']);
		$template->register('parenttitle' , htmlspecialchars_uni($this->record['parenttitle']) );
		$template->register('parentid' , $this->record['parentid'] );
		$template->register('threadid' , $this->record['threadid'] );
		$template->register('postauthor' , $this->record['postauthor'] );
		$template->register('poststarter' , $this->record['poststarter'] );
		$template->register('blogpostid' , $this->record['blogpostid'] );
		$template->register('parentnode' , $this->record['parentnode'] );
		$template->register('postid' , $this->record['postid'] );
		$template->register('post_started' , $this->record['post_started'] );
		$template->register('post_posted' , $this->record['post_posted'] );
		$can_use_html = vBCMS_Permissions::canUseHtml($this->record['nodeid'], vb_Types::instance()->getContentTypeId('vBCms_Article'),
			 $this->record['userid']) ;
		$template->register('previewtext', $this->getPreviewText($this->record));
		$template->register('pagetext',
			 $can_use_html ? fetch_censored_text($this->record['pagetext']) :
			 fetch_censored_text(htmlspecialchars_uni($this->record['pagetext'])));
		$template->register('publish_phrase', ($this->record['publishdate'] ?
			$vbphrase['page_published'] : $vbphrase['page_unpublished']) );
		$template->register('author_phrase', 'author');
		$template->register('published', ($this->record['publishdate'] ?
			true : false));
		$template->register('categories', $this->categories);
		$template->register('tags', $this->tags);
		$template->register('replycount', ($this->record['replycount'] ?
			$this->record['replycount'] : '0'));
		$template->register('article', $this->record);
		$template->register('publishdate', vbdate($vbulletin->options['dateformat'], $this->record['publishdate'], true));
		$template->register('publishtime', vbdate($vbulletin->options['timeformat'], $this->record['publishdate']));
		$template->register('lastpostdate', vbdate($vbulletin->options['dateformat'], $this->record['lastpost'], true));
		$template->register('lastpostdatetime', vbdate($vbulletin->options['timeformat'], $this->record['lastpost']));
		$template->register('lastposter', $this->record['lastposter']);
		$template->register('lastposterinfo', array('userid'=>$this->record['lastposterid'], 'username'=>$this->record['lastposter']));
		$template->register('dateformat', $vbulletin->options['dateformat']);
		$template->register('timeformat', $vbulletin->options['default_timeformat']);
		$user = vB_Legacy_User::createFromId($this->record['userid']);

		//get the avatar
		if (intval($this->record['userid']))
		{
			$avatar = fetch_avatar_url($this->record['userid']);
		}

		if (!isset($avatar) OR (count($avatar) < 2))
		{
			$avatar = false;
		}
		$template->register('avatar', $avatar);
		$result = $template->render();

		return $result;
	}