/** * Set the template for the content * * @param AbstractController $controller * @param Application $application * @return void */ public static function setTemplate(AbstractController $controller, Application $application) { $template = null; if ($application->isRegistered('phire-content') && $controller instanceof \Phire\Content\Controller\IndexController && $controller->hasView()) { if (is_numeric($controller->getTemplate())) { if ($controller->getTemplate() == -1) { $template = Table\Templates::findBy(['name' => 'Error']); } else { if ($controller->getTemplate() == -2) { $template = Table\Templates::findBy(['name' => 'Date']); } else { $template = Table\Templates::findById((int) $controller->getTemplate()); } } } } if (null !== $template && isset($template->id)) { if (isset($template->id)) { $device = self::getDevice($controller->request()->getQuery('mobile')); if (null !== $device && $template->device != $device) { $childTemplate = 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(self::parse($tmpl)); } } }
/** * Set the template for the content * * @param AbstractController $controller * @param Application $application * @return void */ public static function setTemplate(AbstractController $controller, Application $application) { $template = null; $themePath = null; $parentThemePath = null; $realThemePath = null; $theme = Table\Themes::findBy(['active' => 1]); if (isset($theme->id)) { $themePath = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/themes/' . $theme->folder . '/'; if (null !== $theme->parent_id) { $parentTheme = Table\Themes::findById($theme->parent_id); if (isset($parentTheme->id)) { $parentThemePath = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/themes/' . $parentTheme->folder . '/'; } } } if ($application->isRegistered('phire-content') && $controller instanceof \Phire\Content\Controller\IndexController && $controller->hasView()) { if (null !== $controller->getTemplate()) { if (isset($theme->id)) { $controller->view()->themePath = $themePath; $controller->view()->parentThemePath = $parentThemePath; if ($controller->getTemplate() == -1 && (file_exists($themePath . 'error.phtml') || file_exists($themePath . 'error.php'))) { $template = file_exists($themePath . 'error.phtml') ? 'error.phtml' : 'error.php'; } else { if ($controller->getTemplate() == -2 && (file_exists($themePath . 'date.phtml') || file_exists($themePath . 'date.php'))) { $template = file_exists($themePath . 'date.phtml') ? 'date.phtml' : 'date.php'; } else { if (file_exists($themePath . $controller->getTemplate())) { $template = $controller->getTemplate(); } } } $realThemePath = $themePath; if (null === $template && null !== $parentThemePath) { if ($controller->getTemplate() == -1 && (file_exists($parentThemePath . 'error.phtml') || file_exists($parentThemePath . 'error.php'))) { $template = file_exists($parentThemePath . 'error.phtml') ? 'error.phtml' : 'error.php'; } else { if ($controller->getTemplate() == -2 && (file_exists($parentThemePath . 'date.phtml') || file_exists($parentThemePath . 'date.php'))) { $template = file_exists($parentThemePath . 'date.phtml') ? 'date.phtml' : 'date.php'; } else { if (file_exists($parentThemePath . $controller->getTemplate())) { $template = $controller->getTemplate(); } } } $realThemePath = $parentThemePath; } if (null !== $template && null !== $realThemePath) { $device = self::getDevice($controller->request()->getQuery('mobile')); if (null !== $device && file_exists($realThemePath . $device . '/' . $template)) { $template = $device . '/' . $template; } $controller->view()->setTemplate($realThemePath . $template); } } } } }