public function process($html, $objectType, $objectID, $doKeywordHighlighting = true, $languageID = null) {
$this->languageID = $languageID;
$this->setContext($objectType, $objectID);
-
- $this->getHtmlOutputNodeProcessor()->setOutputType($this->outputType);
- $this->getHtmlOutputNodeProcessor()->enableKeywordHighlighting($doKeywordHighlighting);
- $this->getHtmlOutputNodeProcessor()->load($this, $html);
- $this->getHtmlOutputNodeProcessor()->process();
+
+ MessageEmbeddedObjectManager::getInstance()->setActiveMessage($objectType, $objectID, $this->languageID);
+
+ try {
+ $this->getHtmlOutputNodeProcessor()->setOutputType($this->outputType);
+ $this->getHtmlOutputNodeProcessor()->enableKeywordHighlighting($doKeywordHighlighting);
+ $this->getHtmlOutputNodeProcessor()->load($this, $html);
+ $this->getHtmlOutputNodeProcessor()->process();
+ }
+ finally {
+ MessageEmbeddedObjectManager::getInstance()->reset();
+ }
}
/**
* @inheritDoc
*/
public function getHtml() {
- return $this->getHtmlOutputNodeProcessor()->getHtml();
+ $context = $this->getContext();
+ MessageEmbeddedObjectManager::getInstance()->setActiveMessage($context['objectType'], $context['objectID'], $this->languageID);
+
+ try {
+ $html = $this->getHtmlOutputNodeProcessor()->getHtml();
+ }
+ finally {
+ MessageEmbeddedObjectManager::getInstance()->reset();
+ }
+
+ return $html;
}
/**
public function setContext($objectType, $objectID) {
parent::setContext($objectType, $objectID);
- MessageEmbeddedObjectManager::getInstance()->setActiveMessage($objectType, $objectID, $this->languageID);
$objectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.message', $objectType);
if ($this->enableToc === null) {
$this->enableToc = (!empty($objectType->additionalData['enableToc']));
'insert' => [],
'remove' => []
];
+
+ /**
+ * A list of previous active message settings used to restore
+ * the internal state in case of nested message processing.
+ */
+ protected $activeMessageHistory = [];
/**
* Registers the embedded objects found in given message.
* @param integer $languageID
*/
public function setActiveMessage($messageObjectType, $messageID, $languageID = null) {
+ if ($this->activeMessageObjectTypeID) {
+ $this->activeMessageHistory[] = [
+ 'activeMessageID' => $this->activeMessageID,
+ 'activeMessageLanguageID' => $this->activeMessageLanguageID,
+ 'activeMessageObjectTypeID' => $this->activeMessageObjectTypeID,
+ ];
+ }
+
$this->activeMessageObjectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName('com.woltlab.wcf.message', $messageObjectType);
$this->activeMessageID = $messageID;
$this->activeMessageLanguageID = $languageID;
}
+
+ /**
+ * Restores the internal state in case of nested message processing.
+ */
+ public function reset() {
+ $newState = \array_pop($this->activeMessageHistory);
+ if ($newState === null) {
+ $newState = [
+ 'activeMessageID' => null,
+ 'activeMessageLanguageID' => null,
+ 'activeMessageObjectTypeID' => null,
+ ];
+ }
+
+ $this->activeMessageID = $newState['activeMessageID'];
+ $this->activeMessageLanguageID = $newState['activeMessageLanguageID'];
+ $this->activeMessageObjectTypeID = $newState['activeMessageObjectTypeID'];
+ }
/**
* Returns the language id of the active message.