/**
	 * Fetches the standard page view for a widget.
	 *
	 * @return vBCms_View_Widget				- The resolved view, or array of views
	 */
	public function getPageView()
	{

		//Make sure blogs is active
		if (!isset(vB::$vbulletin->products['vbblog']) OR !vB::$vbulletin->products['vbblog'])
		{
			return '';
		}
		$this->assertWidget();

		// Create view
		$this->config = $this->widget->getConfig();
		if (!isset($this->config['template_name']) OR ($this->config['template_name'] == '') )
		{
			$this->config['template_name'] = 'vbcms_widget_recentblog_page';
		}
		if (!isset($this->config['cache_ttl']) OR !intval($this->config['cache_ttl'])
			OR (intval($this->config['cache_ttl'])< 1 )
			OR (intval($this->config['cache_ttl']) > 43200 ))
		{
			$this->config['cache_ttl'] = 1440;
		}

		// Create view
		$view = new vBCms_View_Widget($this->config['template_name']);
		$view->class = $this->widget->getClass();
		$view->title = $this->widget->getTitle();
		$view->description = $this->widget->getDescription();
		$view->avatarenabled = vB::$vbulletin->options['avatarenabled'];

		$hashkey = $this->getHash();
		$comments = vB_Cache::instance()->read($hashkey);
		if (!$comments)
		{
			$comments = $this->getComments();

			if (!isset($this->config['cache_ttl']) OR !intval($this->config['cache_ttl'])
				OR (intval($this->config['cache_ttl'])< 1 )
				OR (intval($this->config['cache_ttl']) > 43200 ))
			{
				$this->config['cache_ttl'] = 5;
			}
			vB_Cache::instance()->write($hashkey,
				   $comments, $this->config['cache_ttl'], 'blogcomments_updated');
		}

		if (!$comments)
		{
			$view->setDisplayView(false);
		}
		$view->comments = $comments;
		return $view;
	}
Exemple #2
0
	/**
	 * Fetches the standard page view for a widget.
	 *
	 * @return vBCms_View_Widget				- The resolved view, or array of views
	 */
	public function getPageView()
	{
		global $vbphrase, $vbulletin;

		// Ensure the model is loaded
		$this->assertWidget();

		// Normalise widget config
		$config = $this->widget->getConfig();

		// Use fallback template name if none configured
		$config['template_name'] = (isset($config['template_name']) AND $config['template_name'])
									? $config['template_name']
									: 'vbcms_widget_rss_page';

		// Sanitize max items
		$config['max_items'] = max(min($config['max_items'], 20), 1);

		// Load RSS
		$rss = array();
		if (!($rss = vB_Cache::instance()->read($this->getHash($this->widget->getId()), false, true)))
		{
			// get feed
			require_once DIR . '/includes/class_rss_poster.php';
			$feed = new vB_RSS_Poster($vbulletin);
			$feed->fetch_xml($config['url']);

			// TODO: Add config values for encoding behaviour
			$feed->parse_xml(false, true, false, true);

			// get rss elements
			if ($rss['items'] = $feed->fetch_normalised_items())
			{
				$rss['title']		= $feed->xml_array['channel']['title'];
				$rss['description']	= $feed->xml_array['channel']['description'];
				$rss['link']		= $feed->xml_array['channel']['link'];

				// check quantity
				if (sizeof($rss['items']) > $config['max_items'])
				{
					$rss['more'] = true;
					$rss['items'] = array_slice($rss['items'], 0, $config['max_items']);
				}

				$rss['url'] = vB::$vbulletin->input->xss_clean_url($config['url']);
			}

			// write cache
			vB_Cache::instance()->write($this->getHash($this->widget->getId()), $rss, $this->cache_ttl);
		}

		// Create view
		$view = new vBCms_View_Widget($config['template_name']);

		if (!$rss['items'])
		{
			$view->setDisplayView(false);
		}

		// Add widget details
		$view->class = $this->widget->getClass();
		$view->title = $this->widget->getTitle();
		$view->description = $this->widget->getDescription();
		$view->widget_title = $this->widget->getTitle();

		// Add rss
		$view->addArray($rss, 'rss_');

		// Phrases
		$view->no_items = empty($rss['items']) ? $vbphrase['invalid_data'] : false;

		return $view;
	}
	/**
	 * Fetches the standard page view for a widget.
	 *
	 * @param bool $skip_errors					- If using a collection, omit widgets that throw errors
	 * @return vBCms_View_Widget				- The resolved view, or array of views
	 */
	public function getPageView()
	{
		include_once DIR . '/includes/functions_search.php';
		$this->assertWidget();
		$config = $this->widget->getConfig();

		if (!isset($config['template']) OR ($config['template'] == '') )
		{
			$config['template'] = 'vbcms_widget_recentcmscomments_page';
		}

		if (!isset($config['inner_template']) OR ($config['inner_template'] == '') )
		{
			$config['inner_template'] = 'vbcms_searchresult_newcomment';
		}

		if (!isset($config['days']) OR ($config['days'] == '') )
		{
			$config['days'] = 7;
		}

		if (!isset($config['count']) OR (intval($config['count'])> 20)
				OR (intval($config['count'])== 0 ))
		{
			$config['count'] = 5;
		}

		if (!isset($config['cache_ttl']) OR !intval($config['cache_ttl'])
			OR (intval($config['cache_ttl'])< 5 )
			OR (intval($config['cache_ttl']) > 43200 ))
		{
			$config['cache_ttl'] = 1440;
		}
		$view = new vBCms_View_Widget($config['template']);
		$view->class = $this->widget->getClass();
		$view->title = $this->widget->getTitle();
		$view->description = $this->widget->getDescription();
		$view->widget_title = $this->widget->getTitle();

		if (!$results = vB_Cache::instance()->read($hash = $this->getHash($this->widget->getId()), true, false))
		{
			$results = $this->makeResults($config);
			vB_Cache::instance()->write($hash,
			   $results, $config['cache_ttl'], array('cms_comments_change'));
		}

		$view->result_html = $this->renderResult($config, $results, $criteria, $current_user);

		if (!$results OR !$view->result_html)
		{
			$view->setDisplayView(false);
		}

		return $view;
	}
Exemple #4
0
	/**
	 * Fetches the standard page view for a widget.
	 *
	 * @param bool $skip_errors					- If using a collection, omit widgets that throw errors
	 * @return vBCms_View_Widget				- The resolved view, or array of views
	 */
	public function getPageView()
	{
		include_once DIR . '/includes/functions_search.php';
		$this->assertWidget();
		$config = $this->widget->getConfig();


		if (!isset($config['main_template']) OR ($config['main_template'] == '') )
		{
			$config['main_template'] = 'vbcms_widget_recent_page';
		}

		$view = new vBCms_View_Widget($config['main_template']);
		$view->class = $this->widget->getClass();
		$view->title = $this->widget->getTitle();
		$view->description = $this->widget->getDescription();
		$view->widget_title = $this->widget->getTitle();

		$view->result_html = $this->makeResults($config);

		if (!$view->result_html)
		{
			$view->setDisplayView(false);
		}


		return $view;
	}
Exemple #5
0
	/**
	 * Fetches the standard page view for a widget.
	 *
	 * @param vBCms_Item_Widget					- Optional new widget to work with, or a collection of widgets
	 * @param bool $skip_errors					- If using a collection, omit widgets that throw errors
	 * @return vBCms_View_Widget				- The resolved view, or array of views
	 */
	public function getPageView($widget = null)
	{
		$this->assertWidget();
		$config = $this->widget->getConfig();

		// Create view
		$view = new vBCms_View_Widget($config['template_name']);
		$view->class = $this->widget->getClass();
		$view->title = $this->widget->getTitle();
		$view->description = $this->widget->getDescription();
		$hashkey = $this->getHash($this->widget->getId());

		//if we need to hit the database
		$results = $this->getResults($config);

		if (!$results)
		{
			return '';
		}
		$view->result_html = $this->renderResult($config, $results);
		$view->widget_title = $this->widget->getTitle();

		if (!$view->result_html)
		{
			$view->setDisplayView(false);
		}

		return $view;
	}
Exemple #6
0
	/**
	 * This does the actual work of creating the navigation elements. T
	 * We use the existing search functionality. It's already all there, we just need
	 * to
	 *
	 * @return string;
	 */
	private function makeResults($config)
	{
		include_once DIR . '/includes/functions_misc.php';
		$search_core = vB_Search_Core::get_instance();

		$hashkey = $this->getHash($this->widget->getId());
		$data = vB_Cache::instance()->read($hashkey, true, true);
		if (!$data)
		{
			$criteria = $search_core->create_criteria($search_core->get_search_type('vBForum',
				'Post'));
			$contenttypeid = $search_core->get_contenttypeid('vBForum',	'Post');
			$criteria->add_contenttype_filter($contenttypeid);
			$criteria->set_advanced_typeid($contenttypeid);

			if ($config['ids'])
			{
				$criteria->add_group_filter( explode(",", $config['ids']));
				$criteria->set_grouped(vB_Search_Core::GROUP_YES);

			}
			else
			{
				if ($config['forumchoice'])
				{
					$criteria->add_forumid_filter($config['forumchoice'], $config['childforums']);
				}

				if ($config['days'])
				{
					$timelimit = TIMENOW - (86400 * $config['days']);
					$criteria->add_date_filter(vB_Search_Core::OP_GT, $timelimit);
				}

				$criteria->add_filter('pollid', vB_Search_Core::OP_GT, 1, true);

				$search_type = vB_Search_Core::get_instance()->get_search_type_from_id($contenttypeid);
				$search_type->add_advanced_search_filters($criteria, vB::$vbulletin);
				$criteria->set_grouped(vB_Search_Core::GROUP_YES);

			}

			//Set the configuration parameters
			if (! intval($config['count']))
			{
				$config['count'] = 5;
			}

			if (intval($config['count']) > 12)
			{
				$config['count'] = 5;
			}

			if (!isset($config['template_name']) OR ($config['template_name'] == ''))
			{
				$config['template_name'] = 'vbcms_widget_poll_page';
			}

			if (!isset($config['detail_template']) OR ($config['detail_template'] == ''))
			{
				$config['detail_template'] = 'vbcms_widget_poll_resultdetail';
			}


			$criteria->set_sort('dateline', 'desc');
			$current_user = new vB_Legacy_CurrentUser();
			$results = vB_Search_Results::create_from_cache($current_user, $criteria);

			if (!$results)
			{
				$results = vB_Search_Results::create_from_criteria($current_user, $criteria);
			}

			$page = $results->get_page(1, $config['count'], 0);

			if (count($page))
			{
				$threads = array();
				foreach ($page as $result)
				{
					$threads[] = $result->get_thread()->get_field('threadid');
				}
				$where = implode(', ', $threads);
				$sql = "SELECT p.question, p.options,
				p.votes, t.threadid FROM " . TABLE_PREFIX . "poll p INNER JOIN " . TABLE_PREFIX . "thread t
	 			ON t.pollid = p.pollid WHERE t.threadid IN ( " . $where . ");";


				if ($rst = vB::$vbulletin->db->query_read($sql))
				{
					$data = array();
					require_once(DIR . '/includes/class_bbcode_alt.php');
					while ($row = vB::$vbulletin->db->fetch_array($rst))
					{
						$this_item = array();
						$options = explode('|||', $row['options'] );
						$votes = explode('|||', $row['votes'] );
						$this_item['totalvotes'] = 0;
						for($i = 0; $i < count($votes); $i++)
						{
							$this_item['totalvotes'] += $votes[$i];
						}
						$detail = array();
						$parser = new vB_BbCodeParser_Wysiwyg(vB::$vbulletin, fetch_tag_list('', true), true);
						for ($i = 0; $i < count($options); $i++)
						{
							$this_option = $parser->do_parse($options[$i]);
							$percent = ($this_item['totalvotes'] != 0) ? $votes[$i] / $this_item['totalvotes'] * 100 : 0;

							$detail[] = array(
								'option'        => $this_option,
								'votes'         => $votes[$i],
								'percent'       => vb_number_format($percent, 2),
								'percentraw'    => $percent,
								'number'        => $i + 1,
								'graphicnumber' => (($i + 1) % 6) + 1,
							);
						}
						$detailview = new vBCms_View_Widget($config['detail_template']);
						$detailview->resultdetail = $detail;
						$this_item['resultdetail'] = $detailview->render();
						$this_item['threadid'] = $row['threadid'];
						$this_item['question'] = $row['question'];
						$data[$row['threadid']] = $this_item;
					}

					if (!isset($config['template_name']) OR ($config['template_name'] == ''))
					{
						$config['template_name'] = 'vbcms_widget_poll_page';
					}
				}
			}

			vB_Cache::instance()->write($hashkey,
			   $data, $this->cache_ttl);
		}
		// Create view
		$view = new vBCms_View_Widget($config['template_name']);
		$view->poll_data = $data;
		$view->class = $this->widget->getClass();
		$view->title = $this->widget->getTitle();
		$view->description = $this->widget->getDescription();
		if (empty($view->poll_data))
		{
			$view->setDisplayView(false);
		}

		return $view;
	}
Exemple #7
0
	/**
	 * Fetches the standard page view for a widget.
	 *
	 * @return vBCms_View_Widget				- The resolved view, or array of views
	 */
	public function getPageView()
	{
		$this->assertWidget();

		$config = $this->widget->getConfig();
		// Create view
		if (!isset($config['template_name']) OR ($config['template_name'] == '') )
		{
			$config['template_name'] = 'vbcms_widget_static_page';
		}

		// Create view
		$view = new vBCms_View_Widget($config['template_name']);
		$view->class = $this->widget->getClass();
		$view->title = $view->widget_title = $this->widget->getTitle();
		$view->description = $this->widget->getDescription();
		$view->static_html = $config['statichtml'];

		if (empty($view->static_html))
		{
			$view->setDisplayView(false);
		}

		return $view;
	}