/** * Determine which view is available for loading * * @param string $page Page to get hierarchy of. * * @return array * @throws Exception When handler doesn't return expected type. */ public function get_view_hierarchy($page) { /** * Get the possible views for specified page: */ $options = Stencil_Handler_Factory::get_hierarchy_handler($page); if (!is_array($options) && !$options instanceof Traversable) { throw new Exception('Expected array got ' . gettype($options)); } if (is_array($options)) { $options = new ArrayIterator($options); } /** * Add archive option for archive pages: */ if ('archived' !== $page && in_array($page, $this->archive_pages, true)) { $this->add_to_options('archived', $options); } /** * Add paged option for paged pages: */ if ('paged' !== $page && is_paged()) { $this->add_to_options('paged', $options); } /** * Convert to array for filtering and return ouput */ $options = iterator_to_array($options); // Apply filter. $options = Stencil_Environment::filter('views-' . $page, $options); return $options; }
/** * Run the main process * * @param string|null $page Optional. Fake a certain page. */ public function run($page = null) { if (empty($page) || !is_string($page)) { $page = Stencil_Environment::get_page(); } // Add to template. $this->set('page', $page); // Get actions that need to be run. $actions = self::$flow->get_page_actions($page); // Execute actions. if (is_array($actions) && array() !== $actions) { foreach ($actions as $action) { // Apply variables. Stencil_Handler_Factory::run_page_type_handler($action, $this); Stencil_Handler_Factory::run_page_type_hook($action, $this); } } // Get available views. $options = self::$flow->get_view_hierarchy($page); $view = self::$handler->get_usable_view($options); // Display the view. self::$handler->display($view); }