Exemple #1
0
	public function showpage($pagenumber, $perpage, $base, $navbits, $print_output = true)
	{
		global $vbulletin;
		global $show;
		$errors = array();
		($hook = vBulletinHook::fetch_hook('search_before_process')) ? eval($hook) : false;

		$perpage = fetch_perpage($perpage, $this->maxpagesize, $vbulletin->options['searchperpage']);
		$pagenumber = max(intval($pagenumber), 1);

		if (!$this->results)
		{
			eval(standard_error(fetch_error('searchnoresults', $displayCommon), '', false));
		}
		$page_results = $this->results->get_page($pagenumber, $perpage, $this->window);

		if (!$page_results)
		{
			eval(standard_error(fetch_error('searchnoresults', $displayCommon), '', false));
		}
		$criteria = $this->results->get_criteria();
		//When we have better template features, the display strings should be passed as
		//an array to the template and handled there.
		$this->template->register('criteriaDisplay', implode('; ', $criteria->get_display_strings()));
		$this->template->register('displayCommon', $criteria->get_common_words_string());

		$this->render_searchbits($page_results);
		$show['results'] = (bool) count($page_results);

		($hook = vBulletinHook::fetch_hook('search_complete')) ? eval($hook) : false;

		//figure searchtime -- time it took to run the search in seconds
		$this->template->register('searchtime', $this->results->get_searchtime());

		//"searchminutes" in the template is minutes since the search was generated.
		$sincegenerated = floor((TIMENOW - $this->results->get_dateline()) / 60);

		if ($sincegenerated >= 1)
		{
			$this->template->register('searchminutes', $sincegenerated);
			$show['generated'] = true;
		}

		$search['showposts'] = true;

		$pagenav = construct_window_page_nav($pagenumber, $this->window, $perpage,
			$this->results->get_confirmed_count(),	$base);

		$this->template->register('navbar', render_navbar_template(construct_navbits($navbits)));
		$this->template->register('base', $base);
		$startat = ($pagenumber-1) * $perpage;
		$this->template->register('first', $startat + 1);
		$this->template->register('last', $startat + count($page_results));
		$this->template->register('total', $this->results->get_confirmed_count());
		$this->template->register('search', $search);
		$this->template->register('pagenav', $pagenav);
		$this->template->register('show', $show);
		$this->template->register('search_back_url', $criteria->get_url());
		$this->template->register_page_templates();
		
		if ($print_output)
		{
			print_output($this->template->render());
		}
		else
		{
			return $this->template->render();
		}
	}
Exemple #2
0
	/**
	 * Populates a view with the expected info from a content item.
	 *
	 * @param vB_View $view
	 * @param int $viewtype
	 */
	protected function populateViewContent(vB_View $view, $viewtype)
	{
		global $vbphrase;
		global $show;

		if ($_REQUEST['do'] == 'apply' OR $_REQUEST['do'] == 'update' OR $_REQUEST['do'] == 'movenode')
		{
			$this->checkSaveData($view);
		}
		//Make sure the proper data is loaded.
		$this->content->requireInfo(vBCms_Item_Content::INFO_BASIC  &
			vBCms_Item_Content::INFO_DEPTH & vBCms_Item_Content::INFO_CONFIG & vBCms_Item_Content::INFO_NODE &
			vBCms_Item_Content::INFO_NAVIGATION & vBCms_Item_Content::INFO_PARENTS);
		$this->content->isValid();

		($hook = vBulletinHook::fetch_hook('vbcms_section_populate_start')) ? eval($hook) : false;

		//See if we're deleting
		if ($_REQUEST['do'] == 'delete')
		{

			//We can't delete if there is content below
			if ($record = vB::$vbulletin->db->query_first("SELECT nodeid FROM " . TABLE_PREFIX .
				"cms_node WHERE parentnode = " . $this->content->getNodeId() . " limit 1")
				and intval($record['nodeid']))
			{
				return $vbphrase['cannot_delete_with_subnodes'];
			}
			$dm = $this->content->getDM();
			$dm->delete();

			$events = $this->getCleanCacheEvents();
			vB_Cache::instance()->event($events);
			vB_Cache::instance()->cleanNow();
			return $vbphrase['section_deleted'];
		}

		//We don't want the child nodes trying to save data.
		$_REQUEST['do'] = 'view';

		$view->nodeid = $this->content->getNodeId();
		$this->config = $this->getConfig();
		$view->contenttypeid = vB_Types::instance()->getContentTypeID("vBCms_Section");

		$route_info = 'section/' .	$this->content->getURLSegment();
		$view->section_list_url = vB_Route::create('vBCms_Route_List', "$route_info")->getCurrentURL();
		$view->showall = $this->content->getShowall();

		parent::populateViewContent($view, $viewtype);
		$view->publishdatelocal = vbdate(vB::$vbulletin->options['dateformat'], $this->content->getPublishDateLocal());
		$view->publishtimelocal = date(vB::$vbulletin->options['timeformat'], $this->content->getPublishDateLocal());
		$view->setpublish = $this->content->getSetPublish();
		$view->published = ($this->content->getSetPublish() AND ($this->content->getPublishDate() < TIMENOW)) ?
			1 : 0;

		if (self::VIEW_PAGE == $viewtype)
		{
			$view->unpublished = $this->parameters['unpublished'];

			if (!$this->content->canView())
			{
				return '';
			}

			$page_nav = false;
			$aggregate =  $this->aggregateContent($viewtype, $page_nav);
			$results = $aggregate['results'];
			$view_content = new vB_View_Content('vbcms_content_section_type' . $this->config['content_layout']);
			$view->result_count = count($results);
			$view_content->class = 'Section';
			$view_content->package = 'vBCms';
			$view->can_create = $this->content->canCreate();
			$view->can_publish = $this->content->canPublish();

			if ($results AND sizeof($results))
			{
				$contents = array();
				$i = 1;
				foreach ($results as $id => $result)
				{
					$contents[$i++] = $result;
				}

				$view_content->result_count = count($results);
				$view_content->contents = $contents;
				$show['lightbox'] = (vB::$vbulletin->options['lightboxenabled'] AND vB::$vbulletin->options['usepopups']);

				$view->content = $view_content;

		 		$page_info = $aggregate['aggregate']->getCounts();
				if ($this->config['pagination_links'])
				{
					if ($this->config['simple_paging'])
					{
						// from $rawcount we know how many more we definitely have,
						// so we construct from that.
						$route = vB_Route::create('vBCms_Route_Content');
						$route->node = $this->content->getUrlSegment();
						$pageurl = $route->getCurrentURL();
						$view->pagenav = construct_window_page_nav (
						$this->current_page,
						6,
						intval($this->config['items_perhomepage']),
						$page_info['total'],
						$pageurl);
					}
					else if (intval($page_info['total']))
					{
						$route = vB_Route::create('vBCms_Route_Content');
						$route->node = $this->content->getUrlSegment();
						$pageurl = $route->getCurrentURL();
						$view->pagenav = construct_page_nav($this->current_page, intval($this->config['items_perhomepage']), $page_info['total'], $pageurl);
					}
				}
			}
			else
			{
				$view_content->result_count = 0;
				$view->no_results_phrase = new vB_Phrase('vbcms', 'no_content_in_section');
				$title = $this->content->getTitle();
				$view->title = $view_content->title = $this->content->getTitle();
			}
		}
		$this->content->cacheNow();
		($hook = vBulletinHook::fetch_hook('vbcms_section_populate_end')) ? eval($hook) : false;
	}