/** * Uninstall themes * * @param array $ids * @return void */ public function uninstall($ids) { $themePath = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/themes'; foreach ($ids as $id) { $theme = Table\Themes::findById((int) $id); if (isset($theme->id)) { // Remove the theme folder and files if (file_exists($themePath . '/' . $theme->folder)) { $dir = new Dir($themePath . '/' . $theme->folder); $dir->emptyDir(true); } // Remove the theme file if (file_exists($themePath . '/' . $theme->file) && is_writable($themePath . '/' . $theme->file)) { unlink($themePath . '/' . $theme->file); } $children = Table\Themes::findBy(['parent_id' => $theme->id]); if ($children->hasRows()) { foreach ($children->rows() as $child) { $childThemePath = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/themes/' . $child->folder; // Remove the child theme folder and files if (file_exists($childThemePath)) { $dir = new Dir($childThemePath); $dir->emptyDir(true); } $c = Table\Themes::findById($child->id); if (isset($c->id)) { $c->delete(); } } } $theme->delete(); } } }
/** * 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); } } } } }