예제 #1
0
	public function sitemap(){
		$view  = $this->getView();
		$req   = $this->getPageRequest();

		// Give me every registered (public) page!
		$factory = new ModelFactory('PageModel');
		$factory->where('indexable = 1');
		$factory->order('title');
		// Multisite?
		if(Core::IsComponentAvailable('multisite') && MultiSiteHelper::IsEnabled()){
			$factory->whereGroup(
				'OR',
				array(
					'site = ' . MultiSiteHelper::GetCurrentSiteID(),
					'site = -1'
				)
			);
			$site = MultiSiteHelper::GetCurrentSiteID();
		}
		else{
			$site = null;
		}

		// Run this through the streamer, just in case there are a lot of pages...
		$stream = new \Core\Datamodel\DatasetStream($factory->getDataset());

		$user = \Core\user();
		$toshow = array();
		while(($record = $stream->getRecord())){
			if(!$user->checkAccess( $record['access'] )){
				// Skip any further operations if the user does not have access to this page
				continue;
			}

			if($record['published_status'] != 'published'){
				// Skip any further operations if the page isn't even marked as published.
				continue;
			}

			$page = new PageModel();
			$page->_loadFromRecord($record);

			if(!$page->isPublished()){
				// Skip out if the page is not marked as published.
				// This has extended checks other than simply if the status is set as "published",
				// such as publish date and expiration date.
				continue;
			}

			$toshow[] = $page;
		}

		// Anything else?
		$extra = HookHandler::DispatchHook('/sitemap/getlisting');
		$toshow = array_merge($toshow, $extra);

		// This page allows for a few content types.
		switch($req->ctype){
			case View::CTYPE_XML:
				$view->contenttype = View::CTYPE_XML;
				break;
			case View::CTYPE_HTML:
				$view->contenttype = View::CTYPE_HTML;
				break;
		}

		$view->title = 'Sitemap';
		$view->assign('pages', $toshow);
		$view->assign('site', $site);
	}