コード例 #1
0
ファイル: Search.php プロジェクト: phirecms/phire-search
 /**
  * Set the search template
  *
  * @param  AbstractController $controller
  * @param  Application        $application
  * @return void
  */
 public static function setTemplate(AbstractController $controller, Application $application)
 {
     if ($application->isRegistered('phire-templates') && $controller instanceof \Phire\Search\Controller\IndexController && $controller->hasView()) {
         $template = \Phire\Templates\Table\Templates::findBy(['name' => 'Search']);
         if (isset($template->id)) {
             if (isset($template->id)) {
                 $device = \Phire\Templates\Event\Template::getDevice($controller->request()->getQuery('mobile'));
                 if (null !== $device && $template->device != $device) {
                     $childTemplate = \Phire\Templates\Table\Templates::findBy(['parent_id' => $template->id, 'device' => $device]);
                     if (isset($childTemplate->id)) {
                         $tmpl = $childTemplate->template;
                     } else {
                         $tmpl = $template->template;
                     }
                 } else {
                     $tmpl = $template->template;
                 }
                 $controller->view()->setTemplate(\Phire\Templates\Event\Template::parse($tmpl));
             }
         }
     } else {
         if ($application->isRegistered('phire-themes') && $controller instanceof \Phire\Search\Controller\IndexController && $controller->hasView()) {
             $theme = \Phire\Themes\Table\Themes::findBy(['active' => 1]);
             if (isset($theme->id)) {
                 $themePath = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/themes/' . $theme->folder . '/';
                 if (file_exists($themePath . 'search.phtml') || file_exists($themePath . 'search.php')) {
                     $template = file_exists($themePath . 'search.phtml') ? 'search.phtml' : 'search.php';
                     $device = \Phire\Themes\Event\Theme::getDevice($controller->request()->getQuery('mobile'));
                     if (null !== $device && file_exists($themePath . $device . '/' . $template)) {
                         $template = $device . '/' . $template;
                     }
                     $controller->view()->setTemplate($themePath . $template);
                 }
             }
         }
     }
 }
コード例 #2
0
ファイル: Tag.php プロジェクト: phirecms/phire-tags
 /**
  * Set the tag template
  *
  * @param  AbstractController $controller
  * @param  Application        $application
  * @return void
  */
 public static function setTemplate(AbstractController $controller, Application $application)
 {
     if ($application->isRegistered('phire-templates') && $controller instanceof \Phire\Content\Controller\IndexController && $controller->hasView() && $controller->view()->isStream()) {
         if (null !== $controller->view()->tag_title) {
             $template = \Phire\Templates\Table\Templates::findBy(['name' => 'Tag ' . $controller->view()->tag_title]);
             if (!isset($template->id)) {
                 $template = \Phire\Templates\Table\Templates::findBy(['name' => 'Tag']);
             }
         } else {
             $template = \Phire\Templates\Table\Templates::findBy(['name' => 'Tag']);
         }
         if (isset($template->id)) {
             if (isset($template->id)) {
                 $device = \Phire\Templates\Event\Template::getDevice($controller->request()->getQuery('mobile'));
                 if (null !== $device && $template->device != $device) {
                     $childTemplate = \Phire\Templates\Table\Templates::findBy(['parent_id' => $template->id, 'device' => $device]);
                     if (isset($childTemplate->id)) {
                         $tmpl = $childTemplate->template;
                     } else {
                         $tmpl = $template->template;
                     }
                 } else {
                     $tmpl = $template->template;
                 }
                 $controller->view()->setTemplate(\Phire\Templates\Event\Template::parse($tmpl));
             }
         }
     } else {
         if ($application->isRegistered('phire-themes') && $controller instanceof \Phire\Content\Controller\IndexController && $controller->hasView() && $controller->view()->isFile()) {
             $theme = \Phire\Themes\Table\Themes::findBy(['active' => 1]);
             if (isset($theme->id)) {
                 $template = null;
                 $themePath = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/themes/' . $theme->folder . '/';
                 if (null !== $controller->view()->tag_slug) {
                     $tagSlug = 'tag-' . str_replace('/', '-', $controller->view()->tag_slug);
                     if (file_exists($themePath . $tagSlug . '.phtml') || file_exists($themePath . $tagSlug . '.php')) {
                         $template = file_exists($themePath . $tagSlug . '.phtml') ? $tagSlug . '.phtml' : $tagSlug . '.php';
                     } else {
                         if (file_exists($themePath . 'tag.phtml') || file_exists($themePath . 'tag.php')) {
                             $template = file_exists($themePath . 'tag.phtml') ? 'tag.phtml' : 'tag.php';
                         }
                     }
                 } else {
                     if (file_exists($themePath . 'tag.phtml') || file_exists($themePath . 'tag.php')) {
                         $template = file_exists($themePath . 'tag.phtml') ? 'tag.phtml' : 'tag.php';
                     }
                 }
                 if (null !== $template) {
                     $device = \Phire\Themes\Event\Theme::getDevice($controller->request()->getQuery('mobile'));
                     if (null !== $device && file_exists($themePath . $device . '/' . $template)) {
                         $template = $device . '/' . $template;
                     }
                     $controller->view()->setTemplate($themePath . $template);
                 }
             }
         }
     }
 }