/** * Exection hook * * @param Stencil_Interface $controller Controller that initiated this class. */ public function execute(Stencil_Interface $controller) { $list = array(); if (have_posts()) { while (have_posts()) { the_post(); $object = get_post(); /** * Respect post_as_object filter */ $post_as_object = Stencil_Environment::filter('post_as_object', true); if ($post_as_object) { /** * Apply fancy Human Made Post object if loaded */ if (class_exists('Post', false)) { $item = Post::get($object->ID); } else { $item = $object; } } else { $item = (array) $object; } // Add item to the list. $list[] = $item; // Clean up. unset($item); } } wp_reset_postdata(); $controller->set('posts', $list); }
/** * Exection hook * * @param Stencil_Interface $controller Controller that initiated this class. */ public function execute(Stencil_Interface $controller) { $url = (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $controller->set('self', $url); // Loading post(s) as object or array. $post_as_object = Stencil_Environment::filter('post_as_object', true); $object = get_queried_object(); if ($object && is_a($object, 'WP_Post')) { /** * Filter to chose whether the 'post' variable is set as array or object */ if ($post_as_object) { if (class_exists('Post', false)) { $controller->set('post', Post::get($object->ID)); } else { $controller->set('post', $object); } } else { $controller->set('post', (array) $object); } // Additional handy variables. $controller->set('id', $object->ID); $controller->set('post_type', get_post_type($object)); } }
/** * Exection hook * * @param Stencil_Interface $controller Controller that initiated this class. */ public function execute(Stencil_Interface $controller) { $post_type = get_post_type(); Stencil_Environment::trigger('single', $controller); Stencil_Environment::trigger($post_type, $controller); Stencil_Environment::trigger(get_the_ID(), $controller); $page_template = get_page_template(); if ($page_template) { // Always include template file. include $page_template; $page_template_base = basename($page_template); Stencil_File_System::load($page_template_base); Stencil_Environment::trigger(rtrim($page_template_base, '.php'), $controller); Stencil_Environment::trigger($page_template_base, $controller); } }
/** * Exection hook * * @param Stencil_Interface $controller Controller that initiated this class. */ public function execute(Stencil_Interface $controller) { /** * Filter: force the page to have the permalink presentation */ $force_permalink = Stencil_Environment::filter('force_permalink', false); if ($force_permalink) { $url = $controller->get('self'); $permalink = get_permalink(); if ($url && $permalink) { if ($permalink !== $url) { wp_redirect($permalink); die; } } } Stencil_Environment::trigger('singular', $controller, get_queried_object()); }
/** * Include a file from child or root theme * * @param string $file File to include. * * @return bool True if a file was found. */ public static function load($file) { $file = rtrim($file, '.php') . '.php'; /** * Filter controllers directory */ $directory = Stencil_Environment::filter('path-controllers', 'controllers'); if (empty($directory)) { return false; } $paths = self::get_potential_directories($directory); foreach ($paths as $path) { if (is_file($path . $file)) { include $path . $file; return true; } } return false; }
/** * 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; }
/** * Detach hooks to load the wp_head and wp_footer variables */ private function unhook_wp_header_and_footer() { /** * Add wp_head and wp_footer variable recording */ remove_action(Stencil_Environment::format_hook('pre_display'), array($this, 'set_wp_head_footer')); remove_action(Stencil_Environment::format_hook('pre_fetch'), array($this, 'set_wp_head_footer')); }
/** * Exection hook * * @param Stencil_Interface $controller Controller that initiated this class. */ public function execute(Stencil_Interface $controller) { Stencil_Environment::trigger('error', $controller); Stencil_Environment::trigger('404', $controller); }
/** * Rewrite all scripts to index.php of the theme * * @param string $template Template that is being loaded. * * @return mixed */ public static function template_include_override($template) { /** * Only apply if theme uses Stencil */ $theme = Stencil_Environment::filter('require', false); if (false !== $theme) { /** * Make it optional with default disabled */ $force = Stencil_Environment::filter('template_index_only', false); if ($force) { return get_index_template(); } } return $template; }
/** * Exection hook * * @param Stencil_Interface $controller Controller that initiated this class. */ public function execute(Stencil_Interface $controller) { Stencil_Environment::trigger('search', $controller); }
/** * Exection hook * * @param Stencil_Interface $controller Controller that initiated this class. */ public function execute(Stencil_Interface $controller) { Stencil_Environment::trigger('category', $controller); Stencil_Environment::trigger('category.' . get_query_var('cat'), $controller); }
/** * Get the required implementation if found, otherwise first in list. * * @return bool */ public static function implementation() { $engines = Stencil_Environment::filter('register-engine', array()); if (!is_array($engines) || array() === $engines) { return false; } /** * Get theme required addon information * * If the addon that the theme needs is registered, return it */ $required = Stencil_Environment::filter('require', false); if (in_array($required, $engines, true)) { return $required; } /** * Otherwise return first registered one */ return false; }
/** * Exection hook * * @param Stencil_Interface $controller Controller that initiated this class. */ public function execute(Stencil_Interface $controller) { Stencil_Environment::trigger('comments_popup', $controller); }
/** * Exection hook * * @param Stencil_Interface $controller Controller that initiated this class. */ public function execute(Stencil_Interface $controller) { add_filter(Stencil_Environment::format_filter('views-custom'), array($this, 'set_template_as_first_option')); }
/** * Called when the implementation is ready */ protected function ready() { Stencil_Environment::trigger('engine_ready', $this); }
/** * Exection hook * * @param Stencil_Interface $controller Controller that initiated this class. */ public function execute(Stencil_Interface $controller) { Stencil_Environment::trigger('home', $this); }
/** * Exection hook * * @param Stencil_Interface $controller Controller that initiated this class. */ public function execute(Stencil_Interface $controller) { Stencil_Environment::trigger('archive', $controller); Stencil_Environment::trigger('archive_' . get_post_type(), $controller); }
/** * Exection hook * * @param Stencil_Interface $controller Controller that initiated this class. */ public function execute(Stencil_Interface $controller) { Stencil_Environment::trigger('author', $controller); Stencil_Environment::trigger('author.' . get_the_ID(), $controller); }