Added support for embedded objects in box content
authorMarcel Werk <burntime@woltlab.com>
Sun, 9 Oct 2016 20:18:07 +0000 (22:18 +0200)
committerMarcel Werk <burntime@woltlab.com>
Sun, 9 Oct 2016 20:18:12 +0000 (22:18 +0200)
wcfsetup/install/files/acp/templates/__boxAddContent.tpl
wcfsetup/install/files/lib/data/box/Box.class.php
wcfsetup/install/files/lib/data/box/BoxAction.class.php
wcfsetup/install/files/lib/data/box/content/BoxContent.class.php

index c2e60887e53e0c0244880b999a78472714919a61..f9b79b4245cd42367182dbdac2e3f5b9a3083e15 100644 (file)
@@ -1,3 +1,28 @@
+<script data-relocate="true">
+       require(['Language'], function (Language) {
+               Language.addObject({
+                       'wcf.page.search': '{lang}wcf.page.search{/lang}',
+                       'wcf.page.search.error.tooShort': '{lang}wcf.page.search.error.tooShort{/lang}',
+                       'wcf.page.search.error.noResults': '{lang}wcf.page.search.error.noResults{/lang}',
+                       'wcf.page.search.name': '{lang}wcf.page.search.name{/lang}',
+                       'wcf.page.search.results': '{lang}wcf.page.search.results{/lang}'
+               });
+       })
+</script>
+
+{if $boxType == 'html' || $boxType == 'tpl'}
+       <ul class="codemirrorToolbar">
+               <li><a href="#" id="codemirror-content{@$languageID}-media" class="jsTooltip" title="{lang}wcf.editor.button.media{/lang}"><span class="icon icon16 fa-file-o"></span></a></li>
+               <li><a href="#" id="codemirror-content{@$languageID}-page" class="jsTooltip" title="{lang}wcf.editor.button.page{/lang}"><span class="icon icon16 fa-file-text-o"></span></a></li>
+       </ul>
+       <script data-relocate="true">
+               require(['WoltLabSuite/Core/Acp/Ui/CodeMirror/Media', 'WoltLabSuite/Core/Acp/Ui/CodeMirror/Page'], function(AcpUiCodeMirrorMedia, AcpUiCodeMirrorPage) {
+                       new AcpUiCodeMirrorMedia('content{@$languageID}');
+                       new AcpUiCodeMirrorPage('content{@$languageID}');
+               });
+       </script>
+{/if}
+
 {if $boxType == 'text'}
        <textarea name="content[{@$languageID}]" id="content{@$languageID}"
                {if $boxType == 'text'}
index 650957f40aeedf88a9769e1f0b35a9a33b7ee24b..8e5b8b332e1780a8b2eb2abe64be5b8307d6a99f 100644 (file)
@@ -239,13 +239,14 @@ class Box extends DatabaseObject {
                
                if ($boxContent !== null) {
                        if ($this->boxType == 'text') {
-                               $processor = new HtmlOutputProcessor();
-                               $processor->process($boxContent->content, 'com.woltlab.wcf.box.content', $boxContent->boxContentID);
-                               
-                               return $processor->getHtml();
+                               return $boxContent->getFormattedContent();
+                       }
+                       else if ($this->boxType == 'html') {
+                               return $boxContent->getParsedContent();
+                       }
+                       else if ($this->boxType == 'tpl') {
+                               return $boxContent->getParsedTemplate($this->getTplName(WCF::getLanguage()->languageID));
                        }
-                       
-                       return $boxContent->content;
                }
                return '';
        }
index 7a3df6321d0ce4a7ff15d0dc759934dee5199e6d..42e0f1ce0f968aa9024988cd6d7ce70d2f0cc0f0 100644 (file)
@@ -8,6 +8,7 @@ use wcf\data\AbstractDatabaseObjectAction;
 use wcf\system\box\IConditionBoxController;
 use wcf\system\exception\PermissionDeniedException;
 use wcf\system\exception\UserInputException;
+use wcf\system\html\simple\HtmlSimpleParser;
 use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
 use wcf\system\WCF;
 
@@ -89,6 +90,9 @@ class BoxAction extends AbstractDatabaseObjectAction {
                                                $boxContentEditor->update(['hasEmbeddedObjects' => 1]);
                                        }
                                }
+                               else if ($box->boxType == 'html' || $box->boxType == 'tpl') {
+                                       HtmlSimpleParser::getInstance()->parse('com.woltlab.wcf.box.content', $boxContent->boxContentID, $boxContent->content);
+                               }
                        }
                }
                
@@ -145,6 +149,7 @@ class BoxAction extends AbstractDatabaseObjectAction {
                                                        'content' => $content['content'],
                                                        'imageID' => $content['imageID']
                                                ]);
+                                               $boxContent = BoxContent::getBoxContent($box->boxID, ($languageID ?: null));
                                        }
                                        else {
                                                /** @var BoxContent $boxContent */
@@ -166,6 +171,9 @@ class BoxAction extends AbstractDatabaseObjectAction {
                                                        $boxContentEditor->update(['hasEmbeddedObjects' => $boxContent->hasEmbeddedObjects ? 0 : 1]);
                                                }
                                        }
+                                       else if ($box->boxType == 'html' || $box->boxType == 'tpl') {
+                                               HtmlSimpleParser::getInstance()->parse('com.woltlab.wcf.box.content', $boxContent->boxContentID, $boxContent->content);
+                                       }
                                }
                                
                                // save template
index dc84b72f5cd3abc335d5bc6e49836a2b430ae19e..6571f8b54202535b68e0e37da92d04e582c869bf 100644 (file)
@@ -2,6 +2,9 @@
 namespace wcf\data\box\content;
 use wcf\data\media\ViewableMedia;
 use wcf\data\DatabaseObject;
+use wcf\system\html\output\HtmlOutputProcessor;
+use wcf\system\html\simple\HtmlSimpleParser;
+use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
 use wcf\system\WCF;
 
 /**
@@ -93,4 +96,48 @@ class BoxContent extends DatabaseObject {
        public function setImage(ViewableMedia $image) {
                $this->image = $image;
        }
+       
+       /**
+        * Returns the box's formatted content.
+        *
+        * @return      string
+        */
+       public function getFormattedContent() {
+               MessageEmbeddedObjectManager::getInstance()->loadObjects('com.woltlab.wcf.box.content', [$this->boxContentID]);
+               
+               $processor = new HtmlOutputProcessor();
+               $processor->process($this->content, 'com.woltlab.wcf.box.content', $this->boxContentID);
+               
+               return $processor->getHtml();
+       }
+       
+       /**
+        * Parses simple placeholders embedded in raw html.
+        *
+        * @return      string          parsed content
+        */
+       public function getParsedContent() {
+               MessageEmbeddedObjectManager::getInstance()->loadObjects('com.woltlab.wcf.box.content', [$this->boxContentID]);
+               
+               return HtmlSimpleParser::getInstance()->replaceTags('com.woltlab.wcf.box.content', $this->boxContentID, $this->content);
+       }
+       
+       /**
+        * Parses simple placeholders embedded in HTML with template scripting.
+        *
+        * @param       string          $templateName           content template name
+        * @return      string          parsed template
+        */
+       public function getParsedTemplate($templateName) {
+               MessageEmbeddedObjectManager::getInstance()->loadObjects('com.woltlab.wcf.box.content', [$this->boxContentID]);
+               HtmlSimpleParser::getInstance()->setContext('com.woltlab.wcf.box.content', $this->boxContentID);
+               
+               WCF::getTPL()->registerPrefilter(['simpleEmbeddedObject']);
+               
+               $returnValue = WCF::getTPL()->fetch($templateName);
+               
+               WCF::getTPL()->removePrefilter('simpleEmbeddedObject');
+               
+               return $returnValue;
+       }
 }