Added support for template-based cms boxes
authorMarcel Werk <burntime@woltlab.com>
Wed, 27 Apr 2016 13:35:26 +0000 (15:35 +0200)
committerMarcel Werk <burntime@woltlab.com>
Wed, 27 Apr 2016 13:35:26 +0000 (15:35 +0200)
wcfsetup/install/files/acp/templates/boxAdd.tpl
wcfsetup/install/files/lib/data/box/Box.class.php
wcfsetup/install/files/lib/data/box/BoxAction.class.php

index dffbeac02f6597f4883049e89a1bf8e56166eb99..42d7f3f892dc325ae644037c9c76c06262643ef7 100644 (file)
                        
                        {foreach from=$availableLanguages item=availableLanguage}
                                <div id="language{@$availableLanguage->languageID}" class="tabMenuContent">
-                                       <div>
+                                       <div class="section">
                                                {if $__wcf->session->getPermission('admin.content.cms.canUseMedia')}
                                                        <dl{if $errorField == 'image'|concat:$availableLanguage->languageID} class="formError"{/if}>
                                                                <dt><label for="image{@$availableLanguage->languageID}">{lang}wcf.acp.box.image{/lang}</label></dt>
index 3082e4a0c14787855782acdf2f248911a1795aeb..b361ed0e5311298b11ef146e171bc415095c0729 100644 (file)
@@ -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.
         * 
index 19a91cc33b93c1d2718fcf10363efb3305006c80..4234338d297c0c4b26b43c94974abfddd46b66f4 100644 (file)
@@ -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();
+       }
 }