Fixed embedded objects in boxes
authorMarcel Werk <burntime@woltlab.com>
Mon, 17 Oct 2016 22:24:57 +0000 (00:24 +0200)
committerMarcel Werk <burntime@woltlab.com>
Mon, 17 Oct 2016 22:25:03 +0000 (00:25 +0200)
wcfsetup/install/files/lib/data/box/BoxAction.class.php
wcfsetup/install/files/lib/data/box/BoxList.class.php
wcfsetup/install/files/lib/data/box/content/BoxContent.class.php
wcfsetup/install/files/lib/data/box/content/BoxContentList.class.php

index 42e0f1ce0f968aa9024988cd6d7ce70d2f0cc0f0..c100bf66ecb29015b71110f25762aed75d6cfebb 100644 (file)
@@ -91,7 +91,9 @@ class BoxAction extends AbstractDatabaseObjectAction {
                                        }
                                }
                                else if ($box->boxType == 'html' || $box->boxType == 'tpl') {
-                                       HtmlSimpleParser::getInstance()->parse('com.woltlab.wcf.box.content', $boxContent->boxContentID, $boxContent->content);
+                                       if (HtmlSimpleParser::getInstance()->parse('com.woltlab.wcf.box.content', $boxContent->boxContentID, $boxContent->content)) {
+                                               $boxContentEditor->update(['hasEmbeddedObjects' => 1]);
+                                       }
                                }
                        }
                }
@@ -172,7 +174,9 @@ class BoxAction extends AbstractDatabaseObjectAction {
                                                }
                                        }
                                        else if ($box->boxType == 'html' || $box->boxType == 'tpl') {
-                                               HtmlSimpleParser::getInstance()->parse('com.woltlab.wcf.box.content', $boxContent->boxContentID, $boxContent->content);
+                                               if ($boxContent->hasEmbeddedObjects != HtmlSimpleParser::getInstance()->parse('com.woltlab.wcf.box.content', $boxContent->boxContentID, $boxContent->content)) {
+                                                       $boxContentEditor->update(['hasEmbeddedObjects' => $boxContent->hasEmbeddedObjects ? 0 : 1]);
+                                               }
                                        }
                                }
                                
index fb5f5fe150693f467942a0395f1cc1f3e46ca935..a4b2258e5560668ea15e656008161c9ee5186abc 100644 (file)
@@ -48,6 +48,7 @@ class BoxList extends DatabaseObjectList {
                        if (!empty($boxIDs)) {
                                $contentList = new BoxContentList();
                                $contentList->enableImageLoading();
+                               $contentList->enableEmbeddedObjectLoading();
                                $contentList->getConditionBuilder()->add('box_content.boxID IN (?)', [$this->objectIDs]);
                                $contentList->getConditionBuilder()->add('(box_content.languageID IS NULL OR box_content.languageID = ?)', [WCF::getLanguage()->languageID]);
                                $contentList->readObjects();
index 6571f8b54202535b68e0e37da92d04e582c869bf..9edd4fb37a36f65ab5ca5e8db3076d074cb2447b 100644 (file)
@@ -4,7 +4,6 @@ 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;
 
 /**
@@ -103,8 +102,6 @@ class BoxContent extends DatabaseObject {
         * @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);
                
@@ -117,8 +114,6 @@ class BoxContent extends DatabaseObject {
         * @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);
        }
        
@@ -129,7 +124,6 @@ class BoxContent extends DatabaseObject {
         * @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']);
index 97339892be21fec1ba867c1688fa413f60353320..e5d03dc4bdb9e4e4941d2842f5338eaf1766a9d0 100644 (file)
@@ -2,6 +2,7 @@
 namespace wcf\data\box\content;
 use wcf\data\media\ViewableMediaList;
 use wcf\data\DatabaseObjectList;
+use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
 
 /**
  * Represents a list of box content.
@@ -29,21 +30,30 @@ class BoxContentList extends DatabaseObjectList {
         */
        protected $imageLoading = false;
        
+       /**
+        * enables/disables the loading of embedded objects
+        * @var boolean
+        */
+       protected $embeddedObjectLoading = false;
+       
        /**
         * @inheritDoc
         */
        public function readObjects() {
                parent::readObjects();
                
-               if ($this->imageLoading) {
-                       $imageIDs = [];
-                       foreach ($this->getObjects() as $boxContent) {
-                               if ($boxContent->imageID) {
-                                       $imageIDs[] = $boxContent->imageID;
-                               }
+               $imageIDs = $embeddedObjectBoxContentIDs = [];
+               foreach ($this->getObjects() as $boxContent) {
+                       if ($boxContent->imageID) {
+                               $imageIDs[] = $boxContent->imageID;
                        }
                        
-                       // cache images
+                       if ($boxContent->hasEmbeddedObjects) {
+                               $embeddedObjectBoxContentIDs[] = $boxContent->boxContentID;
+                       }
+               }
+               
+               if ($this->imageLoading) {
                        if (!empty($imageIDs)) {
                                $mediaList = new ViewableMediaList();
                                $mediaList->setObjectIDs($imageIDs);
@@ -57,9 +67,14 @@ class BoxContentList extends DatabaseObjectList {
                                }
                        }
                }
+               
+               if ($this->embeddedObjectLoading) {
+                       if (!empty($embeddedObjectBoxContentIDs)) {
+                               MessageEmbeddedObjectManager::getInstance()->loadObjects('com.woltlab.wcf.box.content', $embeddedObjectBoxContentIDs);
+                       }
+               }
        }
        
-       
        /**
         * Enables/disables the loading of box content images.
         *
@@ -68,4 +83,13 @@ class BoxContentList extends DatabaseObjectList {
        public function enableImageLoading($enable = true) {
                $this->imageLoading = $enable;
        }
+       
+       /**
+        * Enables/disables the loading of embedded objects.
+        *
+        * @param       boolean         $enable
+        */
+       public function enableEmbeddedObjectLoading($enable = true) {
+               $this->embeddedObjectLoading = $enable;
+       }
 }