Added support for template-based cms pages
authorMarcel Werk <burntime@woltlab.com>
Sat, 23 Apr 2016 15:47:01 +0000 (17:47 +0200)
committerMarcel Werk <burntime@woltlab.com>
Sat, 23 Apr 2016 15:47:12 +0000 (17:47 +0200)
com.woltlab.wcf/templates/cms.tpl
wcfsetup/install/files/lib/data/page/Page.class.php
wcfsetup/install/files/lib/data/page/PageAction.class.php

index 134012f5b8cc9f2d11fc4eb06e2145540698338f..9b7a4e0c367b9c629e5743956dfa4113e0a025b4 100644 (file)
@@ -49,7 +49,7 @@
        {elseif $page->pageType == 'html'}
                {@$content[content]}
        {elseif $page->pageType == 'tpl'}
-               {*todo*}
+               {include file=$page->getTplName($contentLanguageID)}
        {/if}
 {/if}
 
index 20229c2c412ebdef441c025e9c29c971ab6c59a5..d41980b2334811752f9adf055c0e4e827d3e2040 100644 (file)
@@ -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.
         * 
index 9091a0d1eb9c6ad1b9b2ce735cdede55ff611259..82d72dd115b9035088779baa105d7dfbf4a6b4cb 100644 (file)
@@ -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();
+       }
 }