From d4739d5d6c5ca4824e32c1a48ffcf774f88ce213 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Wed, 27 Apr 2016 15:35:26 +0200 Subject: [PATCH] Added support for template-based cms boxes --- .../install/files/acp/templates/boxAdd.tpl | 2 +- .../install/files/lib/data/box/Box.class.php | 21 ++++++++++++ .../files/lib/data/box/BoxAction.class.php | 34 +++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/acp/templates/boxAdd.tpl b/wcfsetup/install/files/acp/templates/boxAdd.tpl index dffbeac02f..42d7f3f892 100644 --- a/wcfsetup/install/files/acp/templates/boxAdd.tpl +++ b/wcfsetup/install/files/acp/templates/boxAdd.tpl @@ -238,7 +238,7 @@ {foreach from=$availableLanguages item=availableLanguage}
-
+
{if $__wcf->session->getPermission('admin.content.cms.canUseMedia')} languageID} class="formError"{/if}>
diff --git a/wcfsetup/install/files/lib/data/box/Box.class.php b/wcfsetup/install/files/lib/data/box/Box.class.php index 3082e4a0c1..b361ed0e53 100644 --- a/wcfsetup/install/files/lib/data/box/Box.class.php +++ b/wcfsetup/install/files/lib/data/box/Box.class.php @@ -168,6 +168,9 @@ class Box extends DatabaseObject { else if ($this->boxType == 'menu') { return $this->getMenu()->getContent(); } + else if ($this->boxType == 'tpl') { + return WCF::getTPL()->fetch($this->getTplName(WCF::getLanguage()->languageID), 'wcf', [], true); + } $boxContent = $this->getBoxContent(); $content = ''; @@ -315,6 +318,24 @@ class Box extends DatabaseObject { return false; } + /** + * Returns the template name of this box. + * + * @param integer $languageID + * @return string + */ + public function getTplName($languageID = null) { + if ($this->boxType == 'tpl') { + if ($this->isMultilingual) { + return '__cms_box_' . $this->boxID . '_' . $languageID; + } + + return '__cms_box_' . $this->boxID; + } + + return ''; + } + /** * Returns box to page assignments. * diff --git a/wcfsetup/install/files/lib/data/box/BoxAction.class.php b/wcfsetup/install/files/lib/data/box/BoxAction.class.php index 19a91cc33b..4234338d29 100644 --- a/wcfsetup/install/files/lib/data/box/BoxAction.class.php +++ b/wcfsetup/install/files/lib/data/box/BoxAction.class.php @@ -81,6 +81,15 @@ class BoxAction extends AbstractDatabaseObjectAction { } } + // save template + if ($box->boxType == 'tpl') { + if (!empty($this->parameters['content'])) { + foreach ($this->parameters['content'] as $languageID => $content) { + file_put_contents(WCF_DIR . 'templates/' . $box->getTplName(($languageID ?: null)) . '.tpl', $content['content']); + } + } + } + return $box; } @@ -113,6 +122,13 @@ class BoxAction extends AbstractDatabaseObjectAction { $content['imageID'] ]); } + + // save template + if ($box->boxType == 'tpl') { + foreach ($this->parameters['content'] as $languageID => $content) { + file_put_contents(WCF_DIR . 'templates/' . $box->getTplName(($languageID ?: null)) . '.tpl', $content['content']); + } + } } } @@ -150,4 +166,22 @@ class BoxAction extends AbstractDatabaseObjectAction { } } } + + /** + * @inheritDoc + */ + public function delete() { + foreach ($this->objects as $box) { + if ($box->boxType == 'tpl') { + foreach ($box->getBoxContent() as $languageID => $content) { + $file = WCF_DIR . 'templates/' . $box->getTplName(($languageID ?: null)) . '.tpl'; + if (file_exists($file)) { + @unlink($file); + } + } + } + } + + parent::delete(); + } } -- 2.20.1