Ejemplo n.º 1
0
 public function execute()
 {
     $view = $this->getView();
     $fac = new ModelFactory('PageModel');
     $fac->where('baseurl LIKE /blog/view/%');
     $fac->where('published_status = published');
     $fac->where('published <= ' . \Core\Date\DateTime::NowGMT());
     $fac->limit($this->getSetting('count'));
     switch ($this->getSetting('sort')) {
         case 'newest':
             $fac->order('published DESC');
             break;
         case 'popular':
             $fac->order('popularity DESC');
             break;
         case 'random':
             $fac->order('RAND()');
             break;
     }
     if (!$fac->count()) {
         // If there are no results found, then do not display the widget.
         return '';
     }
     $view->assign('sort', $this->getSetting('sort'));
     $view->assign('title', $this->getSetting('title'));
     $view->assign('links', $fac->get());
 }
Ejemplo n.º 2
0
 public function execute()
 {
     $view = $this->getView();
     $fac = new ModelFactory('PageModel');
     if ($this->getSetting('blog')) {
         $fac->where('parenturl = /blog/view/' . $this->getSetting('blog'));
     }
     $fac->where('parenturl LIKE /blog/view/%');
     $fac->where('published_status = published');
     $fac->where('published <= ' . \Core\Date\DateTime::NowGMT());
     $fac->limit($this->getSetting('count'));
     switch ($this->getSetting('sort')) {
         case 'newest':
             $fac->order('published DESC');
             break;
         case 'popular':
             $fac->order('popularity DESC');
             break;
         case 'random':
             $fac->order('RAND()');
             break;
     }
     if (!$fac->count()) {
         // If there are no results found, then do not display the widget.
         return '';
     }
     $view->assign('count', $this->getSetting('count'));
     $view->assign('sort', $this->getSetting('sort'));
     $view->assign('title', $this->getSetting('title'));
     // The template is expecting an array, if count is 1, only a single Model is returned from the factory.
     $view->assign('links', $this->getSetting('count') == 1 ? [$fac->get()] : $fac->get());
 }
Ejemplo n.º 3
0
 public function view()
 {
     $view = $this->getView();
     $factory = new ModelFactory('GalleryImageModel');
     if ($this->getSetting('order') == 'random') {
         $factory->order('RAND()');
     } else {
         $factory->order($this->getSetting('order'));
     }
     if ($this->getSetting('album')) {
         $factory->where('albumid = ' . $this->getSetting('album'));
         $album = GalleryAlbumModel::Construct($this->getSetting('album'));
         $link = $album->get('baseurl');
     } else {
         $link = null;
     }
     $factory->limit($this->getSetting('count'));
     $images = $factory->get();
     $view->assign('images', $images);
     $view->assign('dimensions', $this->getSetting('dimensions'));
     $view->assign('link', $link);
     $view->assign('uselightbox', $this->getSetting('uselightbox') && Core::IsComponentAvailable('jquery-lightbox'));
 }
 /**
  * Page to display and manage all gallery widgets.
  */
 public function admin()
 {
     $view = $this->getView();
     $request = $this->getPageRequest();
     if (!\Core\user()->checkAccess('p:/gallery/manage_all')) {
         return View::ERROR_ACCESSDENIED;
     }
     $factory = new ModelFactory('WidgetModel');
     $factory->where('baseurl LIKE /gallery/view/%');
     $factory->order('title');
     $widgets = $factory->get();
     $view->title = 'Gallery Widgets';
     $view->assign('can_manage_theme', \Core\user()->checkAccess('g:admin'));
     $view->assign('widgets', $widgets);
     $view->addControl('Create Gallery Widget', '/gallerywidget/update', 'add');
 }
	public function index(){

		$view = $this->getView();

		$permissionmanager = \Core\user()->checkAccess('p:/user/permissions/manage');

		$factory = new ModelFactory('UserGroupModel');

		if(Core::IsComponentAvailable('multisite') && MultiSiteHelper::IsEnabled()){
			if(MultiSiteHelper::GetCurrentSiteID()){
				// Child site, only display global and site-specific sites.
				$w = new \Core\Datamodel\DatasetWhereClause();
				$w->setSeparator('or');
				$w->addWhere('site = ' . MultiSiteHelper::GetCurrentSiteID());
				$w->addWhere('site = -1');
				$factory->where($w);

				$displayglobal = true;
				$multisite = false;
			}
			else {
				// Root site, display all groups across all sites.
				$factory->where('site != -2');
				$displayglobal = false;
				$multisite = true;
			}
			$site = MultiSiteHelper::GetCurrentSiteID();
		}
		else{
			$displayglobal = false;
			$multisite = false;
			$site = null;
		}

		$factory->order('name');
		$groups = $factory->get();

		$view->title = 'User Group Administration';
		$view->assign('groups', $groups);
		$view->assign('permissionmanager', $permissionmanager);
		$view->assign('display_global', $displayglobal);
		$view->assign('site', $site);
		$view->assign('multisite', $multisite);
		$view->addControl('Add Group', '/usergroupadmin/create', 'add');
	}
Ejemplo n.º 6
0
 /**
  * The view for the admin dashboard.  Gets the last executed crons and displays that to the admin.
  */
 public function dashboard()
 {
     // This dashboard has no effect if the user can't view crons.
     if (!\Core\user()->checkAccess('p:/cron/viewlog')) {
         return '';
     }
     $view = $this->getView();
     // Get the latest cron and its execution information and display that to the dashboard.
     $checks = [['cron' => 'hourly', 'modify' => '-1 hour', 'label' => 'hour'], ['cron' => 'daily', 'modify' => '-1 day', 'label' => 'day'], ['cron' => 'weekly', 'modify' => '-1 week', 'label' => 'week'], ['cron' => 'monthly', 'modify' => '-1 month', 'label' => 'month']];
     $crons = array();
     foreach ($checks as $k => $check) {
         $time = new CoreDateTime();
         $cronfac = new ModelFactory('CronLogModel');
         $cronfac->limit(1);
         $cronfac->where('cron = ' . $check['cron']);
         $cronfac->order('created desc');
         $c = $cronfac->get();
         if ($c) {
             $crons[] = $c;
         }
     }
     $view->title = 't:STRING_LATEST_CRON_RESULTS';
     $view->assign('crons', $crons);
 }
Ejemplo n.º 7
0
	/**
	 * Factory shortcut function to do a search for the specific records and return them as a raw array.
	 *
	 * @static
	 *
	 * @param array $where
	 * @param null  $limit
	 * @param null  $order
	 *
	 * @return array
	 */
	public static function FindRaw($where = [], $limit = null, $order = null) {
		$fac = new ModelFactory(get_called_class());
		$fac->where($where);
		$fac->limit($limit);
		$fac->order($order);
		//var_dump($fac);
		return $fac->getRaw();
	}
Ejemplo n.º 8
0
	/**
	 * Given all the user defined filter, sort, and what not, apply those values to the ModelFactory if possible.
	 *
	 * @since 2.4.0
	 * @param ModelFactory $factory
	 */
	public function applyToFactory(ModelFactory $factory){
		if($this->hassort){
			$factory->order($this->getOrder());
		}

		if($this->haspagination){
			// Determine the starting count if the page is requested.
			if($this->_currentpage > 1){
				$startat = $this->_limit * ($this->_currentpage - 1);
				$factory->limit($startat . ', ' . $this->_limit);
			}
			else{
				$factory->limit($this->_limit);
			}
		}

		foreach($this->_elements as $el){
			/** @var $el FormElement */
			$name = $el->get('name');
			$idxname = $name;

			if(strpos($name, 'filter[') === 0){
				$name = substr($name, 7, -1);
			}

			// If this element is not in the index of elements, skip to the next element.
			if(!isset($this->_elementindexes[$idxname])){
				continue;
			}

			// If this doesn't have a link attribute, just skip.
			if(!$el->get('link')){
				continue;
			}

			// No value, just skip.
			if($el->get('value') === '' || $el->get('value') === null){
				continue;
			}

			// If there is a "" option, interpret that as empty and allow "0" to be used.
			if($el->get('value') === '0'){
				if($el->get('options') && isset($el->get('options')[''])){
					// '' is set... proceed.
				}
				else{
					continue;
				}
			}

			$value = $el->get('value');

			// Was there a prefix and/or suffix requested?
			if($el->get('linkvalueprefix')){
				$value = $el->get('linkvalueprefix') . $value;
			}
			if($el->get('linkvaluesuffix')){
				$value = $value . $el->get('linkvaluesuffix');
			}

			// If this link is a date object, convert a date string to its unix timestamp representation.
			if($el instanceof FormDateInput || $el->get('dateformat')){
				// Default to a unix timestamp, but allow the user to override this.
				// This is useful for saving a date in the datastore as a human-readable format.
				$format = $el->get('dateformat') ? $el->get('dateformat') : 'U';
				$date = new CoreDateTime($value);
				$value = $date->getFormatted($format, Time::TIMEZONE_GMT);
			}

			if($el->get('linkname')){
				$name = $el->get('linkname');
			}

			// New support for multiple link names!
			if(!is_array($name)){
				$name = [$name];
			}
			$statements = [];

			foreach($name as $n){
				switch($el->get('link')){
					case FilterForm::LINK_TYPE_STANDARD:
					case FilterForm::LINK_TYPE_GT:
					case FilterForm::LINK_TYPE_GE:
					case FilterForm::LINK_TYPE_LT:
					case FilterForm::LINK_TYPE_LE:
						$statements[] = $n . $el->get('link') . $value;
						break;
					case FilterForm::LINK_TYPE_STARTSWITH:
						$statements[] = $n . ' LIKE ' . $value . '%';
						break;
					case FilterForm::LINK_TYPE_CONTAINS:
						$statements[] = $n . ' LIKE %' . $value . '%';
						break;
				}
			}

			if(sizeof($statements) > 1){
				// Create a sub where clause for these.
				$subwhere = new \Core\Datamodel\DatasetWhereClause();
				$subwhere->setSeparator('OR');
				foreach($statements as $s){
					$subwhere->addWhere($s);
				}
				// Add this sub clause to the main where clause.
				$factory->where($subwhere);
			}
			else{
				// A single command just gets added to the main clause.
				$factory->where($statements[0]);
			}
		}

		// Might as well update the count now, it can always be updated later.
		$this->setTotalCount($factory->count());
	}
Ejemplo n.º 9
0
/**
 * @todo Finish documentation of smarty_function_widgetarea
 * @param array  $params  Associative (and/or indexed) array of smarty parameters passed in from the template
 * @param Smarty_Internal_Template $smarty  Parent Smarty template object
 *
 * @return string|void
 */
function smarty_function_widgetarea($params, $smarty) {
	// Get all widgets set to load in this area.

	$body     = '';
	$baseurl  = PageRequest::GetSystemRequest()->getBaseURL();
	$template = $smarty->template_resource;
	$tmpl     = $smarty->getTemplateVars('__core_template');
	$topview  = ($tmpl instanceof \Core\Templates\TemplateInterface) ? $tmpl->getView() : \Core\view();

	$parameters  = [];
	$name        = null;
	$installable = null;
	$assign      = null;
	foreach($params as $k => $v){
		switch($k){
			case 'name':
				$name = $v;
				break;
			case 'installable':
				$installable = $v;
				break;
			case 'assign':
				$assign = $v;
				break;
			default:
				$parameters[$k] = $v;
				break;
		}
	}

	// I need to resolve the page template down to the base version in order for the lookup to work.
	foreach(Core\Templates\Template::GetPaths() as $base){
		if(strpos($template, $base) === 0){
			$template = substr($template, strlen($base));
			break;
		}
	}

	// Given support for page-level widgets, this logic gets slightly more difficult...
	$factory = new ModelFactory('WidgetInstanceModel');
	$factory->order('weight');
	if(Core::IsComponentAvailable('multisite') && MultiSiteHelper::IsEnabled()){
		$factory->whereGroup('or', ['site = -1', 'site = ' . MultiSiteHelper::GetCurrentSiteID()]);
	}

	$subwhere = new Core\Datamodel\DatasetWhereClause();
	$subwhere->setSeparator('OR');

	// First, the skin-level where clause.
	$skinwhere = new Core\Datamodel\DatasetWhereClause();
	$skinwhere->setSeparator('AND');
	$skinwhere->addWhere('template = ' . $template);
	$skinwhere->addWhere('widgetarea = ' . $name);
	$subwhere->addWhere($skinwhere);

	// And second, the page-level where clause.
	if($baseurl){
		$pagewhere = new Core\Datamodel\DatasetWhereClause();
		$pagewhere->setSeparator('AND');
		$pagewhere->addWhere('page_baseurl = ' . $baseurl);
		$pagewhere->addWhere('widgetarea = ' . $name);
		$subwhere->addWhere($pagewhere);
	}

	$factory->where($subwhere);


	$widgetcount = 0;
	try{
		$widgets = $factory->get();
	}
	catch(Exception $e){
		if(DEVELOPMENT_MODE){
			$body .= '<p class="message-error">Exception while trying to load widget area ' . $name . '!</p>';
			$body .= '<pre class="xdebug-var-dump">' . $e->getMessage() . '</pre>';
		}
		else{
			\Core\ErrorManagement\exception_handler($e, false);
		}
		$widgets = [];
		++$widgetcount;
	}


	foreach ($widgets as $wi) {
		/** @var $wi WidgetInstanceModel */
		// User cannot access this widget? Don't display it...
		if(!\Core\user()){
			continue;
		}
		if (!\Core\user()->checkAccess($wi->get('access'))){
			continue;
		}

		if($installable){
			$wi->set('installable', $installable);
		}
		$view = $wi->execute($parameters);

		// Some widgets may return simply a blank string.  Those should just be ignored.
		if ($view == ''){
			continue;
		}

		// If it's just a string, return that.
		if (is_string($view)) {
			$contents = $view;
		}
		elseif($view->error == View::ERROR_NOERROR){
			// Ensure that the widget's View knows it's linked to a parent!
			$view->parent = $topview;

			$contents = $view->fetch();
		}
		else{
			$contents = 'Error displaying widget [' . $wi->get('baseurl') . '], returned error [' . $view->error . ']';
		}
		++$widgetcount;
		
		// Does this widget have controls attached to it?
		$widget = $wi->getWidget();
		if($widget->controls instanceof ViewControls && $widget->controls->hasLinks()){
			$contents = '<div class="widget-controls-wrapper">' .
				'<menu id="widget-controls-' . $wi->get('id') . '">' . 
				$widget->controls->fetch() . 
				'</menu>' . 
				'</div>' .
				$contents;
		}

		$body .= '<div class="widget">' . $contents . '</div>';
	}

	// Do some sanitizing for the css data
	$class = 'widgetarea-' . strtolower(str_replace(' ', '', $name));

	$html = '<div class="widgetarea ' . $class . '" widgetarea="' . $name . '">' . $body . '</div>';

	// No widgets, no inner content!
	if($widgetcount == 0){
		$html = '';
	}

	if($assign){
		$smarty->assign($assign, $html);
	}
	else{
		return $html;
	}
}
Ejemplo n.º 10
0
	/**
	 * Display a listing of all widgets registered in the system.
	 */
	public function admin(){
		$view = $this->getView();
		$request = $this->getPageRequest();

		$viewer = \Core\user()->checkAccess('p:/core/widgets/manage');
		$manager = \Core\user()->checkAccess('p:/core/widgets/manage');
		if(!($viewer || $manager)){
			return View::ERROR_ACCESSDENIED;
		}

		// Build a list of create pages for all registered components.
		$components    = Core::GetComponents();
		$pages         = [];
		$skins         = [];
		$selected      = null;
		$selectedtype  = null;
		$baseurl       = null;
		$selectoptions = [];
		$links         = [];
		$theme         = ThemeHandler::GetTheme();
		$formtheme     = null;
		$formskin      = null;
		$formtemplate  = null;

		foreach($components as $c){
			/** @var Component_2_1 $c */

			$viewdir = $c->getViewSearchDir();
			if($viewdir){
				$dirlen = strlen($viewdir);
				$component = $c->getName();

				$dh = \Core\Filestore\Factory::Directory($viewdir);
				//$pagetplfiles = $dh->ls('tpl', true);
				$pagetplfiles = $dh->ls(null, true);

				// not sure why getFilename(path) isn't working as expected, but this works too.
				foreach($pagetplfiles as $obj){

					// I don't want directories.
					if($obj instanceof \Core\Filestore\Directory) continue;

					/** @var $obj \Core\Filestore\File */
					$file = substr($obj->getFilename(), $dirlen);

					// Since this is a template, it may actually be in a different location than where the package maintainer put it.
					// ie: user template user/templates/pages/user/view.tpl may be installed to themes/myawesometheme/pages/user/view.tpl instead.
					$tpl = Core\Templates\Template::Factory($file);

					if($tpl->hasWidgetAreas()){
						$pagetitle = $file;
						if(strpos($pagetitle, 'pages/') === 0){
							$pagetitle = substr($pagetitle, 6);
						}
						// Replace directory slashes with a space
						$pagetitle = str_replace(['/', '-'], ' ', $pagetitle);
						// Capitalize them
						$pagetitle = ucwords($pagetitle);
						// And trim off the ".tpl" suffix.
						$pagetitle = substr($pagetitle, 0, -4);
						$pages[$file] = $pagetitle;
					}
				}
			}

			foreach($c->getXML()->getElements('/widgets/widgetcreate') as $node){
				/** @var DOMElement $node */

				if($node->getAttribute('baseurl')){
					$nodebaseurl = $node->getAttribute('baseurl');
					$image = '';
				}
				elseif($node->getAttribute('class')){
					/** @var Widget_2_1 $obj */
					$obj = Widget_2_1::Factory($node->getAttribute('class'));
					$nodebaseurl = '/widget/create?class=' . $node->getAttribute('class');
					if($obj){
						$image = $obj->getPreviewImage();
					}
					else{
						\Core\set_message('Invalid "widgetcreate" found in ' .$node->getAttribute('class') . ', ' . $node->getAttribute('title'), 'error');
						$image = '';
					}
				}
				else{
					\Core\set_message('Invalid "widgetcreate" found in ' . $c->getName() . ', ' . $node->getAttribute('title'), 'error');
					continue;
				}

				$links[] = [
					'baseurl' => $nodebaseurl,
					'title' => $node->getAttribute('title'),
				    'preview' => $image,
				];
			}
		}

		// Build the array of skins for the current theme
		$themeskins  = $theme->getSkins();
		$defaultskin = null;
		foreach($themeskins as $dat){

			$skins[ 'skins/' . $dat['file'] ] = $dat['title'];

			if($dat['default']){
				$defaultskin = 'skins/' . $dat['file'];
			}
		}

		// Now that the various templates have been loaded into a flat array, I need to sort them.
		asort($pages);
		asort($skins);

		foreach($skins as $k => $v){
			$selectoptions[ $k ] = 'Skin: ' . $v;
		}
		foreach($pages as $k => $v){
			$selectoptions[ $k ] = 'Page: ' . $v;
		}

		if($request->getParameter('baseurl')){
			// It's a URL-specific request, lookup which template that page used last.
			$baseurl  = $request->getParameter('baseurl');
			$page     = PageModel::Construct($baseurl);

			if(!isset($pages[ $page->get('last_template') ])){
				\Core\set_message('Requested page template does not seem to contain any widget areas.', 'error');
				\Core\go_back();
			}

			$selected = $page->get('last_template');
			$selectedtype = 'url';
			$formtemplate = $selected;
		}
		elseif($request->getParameter('template')){
			$selected = $request->getParameter('template');

			if(isset($pages[ $selected ])){
				$selectedtype = 'page';
				$formtemplate = $selected;
			}
			else{
				$selectedtype = 'skin';
				$formtheme = $theme->getKeyName();
				$formskin  = $selected;
			}
		}
		else{
			// Just use the default theme skin.
			$selected = $defaultskin;
			$selectedtype = 'skin';$formtheme = $theme->getKeyName();
			$formskin  = $selected;
		}

		$template     = \Core\Templates\Template::Factory($selected);
		$areas        = $template->getWidgetAreas();
		$installables = [0 => ''];

		foreach($areas as $k => $dat){
			// Ensure that each area has a widgets array, (even if it's empty)
			$areas[$k]['widgets'] = [];
			$installables[] = $dat['installable'];
		}
		$installables = array_unique($installables);

		$factory = new ModelFactory('WidgetInstanceModel');
		$factory->order('weight');
		if(Core::IsComponentAvailable('multisite') && MultiSiteHelper::IsEnabled()){
			$factory->whereGroup('or', ['site = -1', 'site = ' . MultiSiteHelper::GetCurrentSiteID()]);
		}

		if($selectedtype == 'skin'){
			// First, the skin-level where clause.
			$skinwhere = new Core\Datamodel\DatasetWhereClause();
			$skinwhere->setSeparator('AND');
			//$skinwhere->addWhere('theme = ' . $theme->getKeyName());
			$skinwhere->addWhere('template = ' . $selected);
			$factory->where($skinwhere);
		}
		elseif($selectedtype == 'page'){
			$factory->where('template = ' . $selected);
		}
		elseif($selectedtype == 'url'){
			$factory->where('page_baseurl = ' . $baseurl);
		}
		else{
			\Core\set_message('Invalid/unknown template type', 'error');
			\Core\go_back();
		}


		foreach($factory->get() as $wi){
			/** @var $wi WidgetInstanceModel */

			$a = $wi->get('widgetarea');
			$areas[$a]['widgets'][] = $wi;
		}

		$available = WidgetModel::Find(['installable IN ' . implode(', ', $installables)]);

		/*
		$table = new Core\ListingTable\Table();
		$table->setName('/admin/widgets');
		$table->setModelName('WidgetModel');
		// Add in all the columns for this listing table.
		$table->addColumn('Title', 'title');
		if(Core::IsComponentAvailable('enterprise') && MultiSiteHelper::IsEnabled() && \Core\user()->checkAccess('g:admin')){
			$table->addColumn('Site', 'site', false);
			$ms = true;
		}
		else{
			$ms = false;
		}
		$table->getModelFactory()->where('installable IN ' . implode(', ', $installables));
		$table->addColumn('Base URL', 'baseurl');
		$table->addColumn('Installable', 'installable');
		$table->addColumn('Created', 'created');

		$table->loadFiltersFromRequest();
		*/

		$view->mastertemplate = 'admin';
		$view->title = 'All Widgets';
		//$view->assign('table', $table);
		$view->assign('available_widgets', $available);
		$view->assign('links', $links);
		$view->assign('manager', $manager);
		$view->assign('theme', $formtheme);
		$view->assign('skin', $formskin);
		$view->assign('template', $selected);
		$view->assign('page_template', $formtemplate);
		$view->assign('page_baseurl', $baseurl);
		$view->assign('options', $selectoptions);
		$view->assign('selected', $selected);
		$view->assign('areas', $areas);
		//$view->assign('multisite', $ms);
	}
Ejemplo n.º 11
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);
	}
Ejemplo n.º 12
0
 /**
  * View controller for a blog article listing page.
  * This will only display articles under this same blog.
  *
  * @param BlogModel $blog
  */
 private function _viewBlog(BlogModel $blog)
 {
     $view = $this->getView();
     $page = $blog->getLink('Page');
     $request = $this->getPageRequest();
     $manager = \Core\user()->checkAccess('p:/blog/manage_all');
     $editor = \Core\user()->checkAccess($blog->get('manage_articles_permission ')) || $manager;
     $viewer = \Core\user()->checkAccess($blog->get('access')) || $editor;
     // Get the latest published article's update date.  This will be used for the blog updated timestamp.
     // (This doesn't have a whole lot of benefit above the ModelFactory, simply illustrating a different way to query data).
     $latest = \Core\Datamodel\Dataset::Init()->select('*')->table('page')->where('parenturl = ' . $blog->get('baseurl'))->where('published_status = published')->order('published DESC')->limit(1)->current();
     $filters = new FilterForm();
     $filters->haspagination = true;
     // Allow different type of requests to come in here.
     switch ($request->ctype) {
         case 'application/atom+xml':
             $view->templatename = 'pages/blog/view-blog.atom.tpl';
             $view->contenttype = $request->ctype;
             $view->mastertemplate = false;
             $filters->setLimit(200);
             break;
         case 'application/rss+xml':
             $view->templatename = 'pages/blog/view-blog.rss.tpl';
             $view->contenttype = $request->ctype;
             $view->mastertemplate = false;
             $filters->setLimit(200);
             break;
         default:
             $view->templatename = 'pages/blog/view-blog.tpl';
             $filters->setLimit(20);
             break;
     }
     $filters->load($this->getPageRequest());
     $factory = new ModelFactory('PageModel');
     if ($request->getParameter('q')) {
         $query = $request->getParameter('q');
         $factory->where(\Core\Search\Helper::GetWhereClause($request->getParameter('q')));
     } else {
         $query = null;
     }
     $factory->where('parenturl = ' . $blog->get('baseurl'));
     $factory->order('published DESC');
     if (!$editor) {
         // Limit these to published articles.
         $factory->where('published_status = published');
         // And where the published date is >= now.
         $factory->where('published <= ' . CoreDateTime::Now('U', Time::TIMEZONE_GMT));
     }
     $filters->applyToFactory($factory);
     $articles = $factory->get();
     $view->mode = View::MODE_PAGEORAJAX;
     $view->assign('blog', $blog);
     $view->assign('articles', $articles);
     $view->assign('page', $page);
     $view->assign('filters', $filters);
     $view->assign('canonical_url', \Core\resolve_link($blog->get('baseurl')));
     $view->assign('last_updated', $latest ? $latest['updated'] : 0);
     $view->assign('servername', SERVERNAME_NOSSL);
     $view->assign('editor', $editor);
     $view->assign('add_article_link', '/content/create?page_template=blog-article.tpl&parenturl=' . $blog->get('baseurl'));
     // Add the extra view types for this page
     $view->addHead('<link rel="alternate" type="application/atom+xml" title="' . $page->get('title') . ' Atom Feed" href="' . \Core\resolve_link($blog->get('baseurl')) . '.atom"/>');
     $view->addHead('<link rel="alternate" type="application/rss+xml" title="' . $page->get('title') . ' RSS Feed" href="' . \Core\resolve_link($blog->get('baseurl')) . '.rss"/>');
     if ($editor) {
         if ($blog->get('type') == 'remote') {
             $view->addControl('Import Feed', '/blog/import/' . $blog->get('id'), 'exchange');
         } else {
             $view->addControl('Add Article', '/content/create?page_template=blog-article.tpl&parenturl=' . $blog->get('baseurl'), 'add');
         }
     }
     if ($manager) {
         $view->addControl('Edit Blog', '/blog/update/' . $blog->get('id'), 'edit');
         $view->addControl('All Articles', '/admin/pages/?filter[parenturl]=' . $blog->get('baseurl'), 'tasks');
     }
     $view->addControl('RSS Feed', \Core\resolve_link($blog->get('baseurl')) . '.rss', 'rss');
     //$view->addControl('Atom Feed', \Core\resolve_link($blog->get('baseurl')) . '.atom', 'rss');
 }