Example #1
0
 /**
  * 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);
 }
Example #2
0
 /**
  * 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));
     }
 }
Example #3
0
 /**
  * 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);
     }
 }
Example #4
0
 /**
  * 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());
 }
Example #5
0
 /**
  * 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;
 }
Example #6
0
 /**
  * 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;
 }
Example #7
0
 /**
  * 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'));
 }
Example #8
0
 /**
  * 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);
 }
Example #9
0
 /**
  * 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;
 }
Example #10
0
 /**
  * Exection hook
  *
  * @param Stencil_Interface $controller Controller that initiated this class.
  */
 public function execute(Stencil_Interface $controller)
 {
     Stencil_Environment::trigger('search', $controller);
 }
Example #11
0
 /**
  * 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);
 }
Example #12
0
 /**
  * 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;
 }
Example #13
0
 /**
  * Exection hook
  *
  * @param Stencil_Interface $controller Controller that initiated this class.
  */
 public function execute(Stencil_Interface $controller)
 {
     Stencil_Environment::trigger('comments_popup', $controller);
 }
Example #14
0
 /**
  * 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'));
 }
Example #15
0
 /**
  * Called when the implementation is ready
  */
 protected function ready()
 {
     Stencil_Environment::trigger('engine_ready', $this);
 }
Example #16
0
 /**
  * Exection hook
  *
  * @param Stencil_Interface $controller Controller that initiated this class.
  */
 public function execute(Stencil_Interface $controller)
 {
     Stencil_Environment::trigger('home', $this);
 }
Example #17
0
 /**
  * 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);
 }
Example #18
0
 /**
  * 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);
 }