From be58327fa212947358693ad7c57a34c8f3f6f868 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Tue, 18 Oct 2016 00:24:57 +0200 Subject: [PATCH] Fixed embedded objects in boxes --- .../files/lib/data/box/BoxAction.class.php | 8 +++- .../files/lib/data/box/BoxList.class.php | 1 + .../lib/data/box/content/BoxContent.class.php | 6 --- .../data/box/content/BoxContentList.class.php | 40 +++++++++++++++---- 4 files changed, 39 insertions(+), 16 deletions(-) diff --git a/wcfsetup/install/files/lib/data/box/BoxAction.class.php b/wcfsetup/install/files/lib/data/box/BoxAction.class.php index 42e0f1ce0f..c100bf66ec 100644 --- a/wcfsetup/install/files/lib/data/box/BoxAction.class.php +++ b/wcfsetup/install/files/lib/data/box/BoxAction.class.php @@ -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]); + } } } diff --git a/wcfsetup/install/files/lib/data/box/BoxList.class.php b/wcfsetup/install/files/lib/data/box/BoxList.class.php index fb5f5fe150..a4b2258e55 100644 --- a/wcfsetup/install/files/lib/data/box/BoxList.class.php +++ b/wcfsetup/install/files/lib/data/box/BoxList.class.php @@ -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(); diff --git a/wcfsetup/install/files/lib/data/box/content/BoxContent.class.php b/wcfsetup/install/files/lib/data/box/content/BoxContent.class.php index 6571f8b542..9edd4fb37a 100644 --- a/wcfsetup/install/files/lib/data/box/content/BoxContent.class.php +++ b/wcfsetup/install/files/lib/data/box/content/BoxContent.class.php @@ -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']); diff --git a/wcfsetup/install/files/lib/data/box/content/BoxContentList.class.php b/wcfsetup/install/files/lib/data/box/content/BoxContentList.class.php index 97339892be..e5d03dc4bd 100644 --- a/wcfsetup/install/files/lib/data/box/content/BoxContentList.class.php +++ b/wcfsetup/install/files/lib/data/box/content/BoxContentList.class.php @@ -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; + } } -- 2.20.1