From 2756444870e0e97dc6970a681e3dd80eda4eaa1d Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Sat, 23 Apr 2016 17:47:01 +0200 Subject: [PATCH] Added support for template-based cms pages --- com.woltlab.wcf/templates/cms.tpl | 2 +- .../files/lib/data/page/Page.class.php | 18 ++++++++++ .../files/lib/data/page/PageAction.class.php | 34 +++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/com.woltlab.wcf/templates/cms.tpl b/com.woltlab.wcf/templates/cms.tpl index 134012f5b8..9b7a4e0c36 100644 --- a/com.woltlab.wcf/templates/cms.tpl +++ b/com.woltlab.wcf/templates/cms.tpl @@ -49,7 +49,7 @@ {elseif $page->pageType == 'html'} {@$content[content]} {elseif $page->pageType == 'tpl'} - {*todo*} + {include file=$page->getTplName($contentLanguageID)} {/if} {/if} diff --git a/wcfsetup/install/files/lib/data/page/Page.class.php b/wcfsetup/install/files/lib/data/page/Page.class.php index 20229c2c41..d41980b233 100644 --- a/wcfsetup/install/files/lib/data/page/Page.class.php +++ b/wcfsetup/install/files/lib/data/page/Page.class.php @@ -272,6 +272,24 @@ class Page extends DatabaseObject { return $this->boxIDs; } + /** + * Returns the template name of this page. + * + * @param integer $languageID + * @return string + */ + public function getTplName($languageID = null) { + if ($this->pageType == 'tpl') { + if ($this->isMultilingual) { + return '__cms_page_' . $this->pageID . '_' . $languageID; + } + + return '__cms_page_' . $this->pageID; + } + + return ''; + } + /** * Returns the page with the given identifier. * diff --git a/wcfsetup/install/files/lib/data/page/PageAction.class.php b/wcfsetup/install/files/lib/data/page/PageAction.class.php index 9091a0d1eb..82d72dd115 100644 --- a/wcfsetup/install/files/lib/data/page/PageAction.class.php +++ b/wcfsetup/install/files/lib/data/page/PageAction.class.php @@ -92,6 +92,15 @@ class PageAction extends AbstractDatabaseObjectAction implements ISearchAction, } } + // save template + if ($page->pageType == 'tpl') { + if (!empty($this->parameters['content'])) { + foreach ($this->parameters['content'] as $languageID => $content) { + file_put_contents(WCF_DIR . 'templates/' . $page->getTplName(($languageID ?: null)) . '.tpl', $content['content']); + } + } + } + return $page; } @@ -126,6 +135,13 @@ class PageAction extends AbstractDatabaseObjectAction implements ISearchAction, $content['customURL'] ]); } + + // save template + if ($page->pageType == 'tpl') { + foreach ($this->parameters['content'] as $languageID => $content) { + file_put_contents(WCF_DIR . 'templates/' . $page->getTplName(($languageID ?: null)) . '.tpl', $content['content']); + } + } } } @@ -207,4 +223,22 @@ class PageAction extends AbstractDatabaseObjectAction implements ISearchAction, public function getSearchResultList() { return $this->pageEditor->getHandler()->lookup($this->parameters['data']['searchString']); } + + /** + * @inheritDoc + */ + public function delete() { + foreach ($this->objects as $page) { + if ($page->pageType == 'tpl') { + foreach ($page->getPageContent() as $languageID => $content) { + $file = WCF_DIR . 'templates/' . $page->getTplName(($languageID ?: null)) . '.tpl'; + if (file_exists($file)) { + @unlink($file); + } + } + } + } + + parent::delete(); + } } -- 2.20.1