// save embedded objects
if (!empty($content['htmlInputProcessor'])) {
- if (MessageEmbeddedObjectManager::getInstance()->registerObjects($content['htmlInputProcessor'], 'com.woltlab.wcf.article.content', $articleContent->articleContentID)) {
+ if (MessageEmbeddedObjectManager::getInstance()->registerObjects($content['htmlInputProcessor'])) {
$articleContentEditor->update(['hasEmbeddedObjects' => 1]);
}
}
// save embedded objects
if (!empty($content['htmlInputProcessor'])) {
- if ($articleContent->hasEmbeddedObjects != MessageEmbeddedObjectManager::getInstance()->registerObjects($content['htmlInputProcessor'], 'com.woltlab.wcf.article.content', $articleContent->articleContentID)) {
+ if ($articleContent->hasEmbeddedObjects != MessageEmbeddedObjectManager::getInstance()->registerObjects($content['htmlInputProcessor'])) {
$articleContentEditor->update(['hasEmbeddedObjects' => ($articleContent->hasEmbeddedObjects ? 0 : 1)]);
}
}
--- /dev/null
+<?php
+namespace wcf\system\html;
+use wcf\data\object\type\ObjectTypeCache;
+use wcf\system\exception\SystemException;
+
+/**
+ * Default implementation for html processors.
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2016 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Html
+ * @since 3.0
+ */
+abstract class AbstractHtmlProcessor implements IHtmlProcessor {
+ /**
+ * message context data
+ * @var array
+ */
+ protected $context = [
+ 'objectType' => '',
+ 'objectTypeID' => 0,
+ 'objectID' => 0
+ ];
+
+ /**
+ * Sets the message context data.
+ *
+ * @param string $objectType object type identifier
+ * @param integer $objectID object id
+ * @throws SystemException
+ */
+ public function setContext($objectType, $objectID) {
+ $objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName('com.woltlab.wcf.message', $objectType);
+ if ($objectTypeID === null) {
+ throw new SystemException("Invalid object type '" . $objectType . "' for definition 'com.woltlab.wcf.message'.");
+ }
+
+ $this->context = [
+ 'objectType' => $objectType,
+ 'objectTypeID' => $objectTypeID,
+ 'objectID' => $objectID
+ ];
+ }
+
+ /**
+ * Returns the message context data.
+ *
+ * @return array message context data
+ */
+ public function getContext() {
+ return $this->context;
+ }
+}
<?php
namespace wcf\system\html\input;
use wcf\system\bbcode\HtmlBBCodeParser;
-use wcf\system\html\IHtmlProcessor;
+use wcf\system\html\AbstractHtmlProcessor;
use wcf\system\html\input\filter\IHtmlInputFilter;
use wcf\system\html\input\filter\MessageHtmlInputFilter;
use wcf\system\html\input\node\HtmlInputNodeProcessor;
* @package WoltLabSuite\Core\System\Html\Input
* @since 3.0
*/
-class HtmlInputProcessor implements IHtmlProcessor {
+class HtmlInputProcessor extends AbstractHtmlProcessor {
/**
* list of embedded content grouped by type
* @var array
* @inheritDoc
*/
public function process($html, $objectType, $objectID) {
+ $this->setContext($objectType, $objectID);
+
// enforce consistent newlines
$html = StringUtil::unifyNewlines($html);
// filter HTML
$html = $this->getHtmlInputFilter()->apply($html);
- $this->getHtmlInputNodeProcessor()->setContext($objectType, $objectID);
-
// pre-parse HTML
- $this->getHtmlInputNodeProcessor()->load($html);
+ $this->getHtmlInputNodeProcessor()->load($this, $html);
$this->getHtmlInputNodeProcessor()->process();
$this->embeddedContent = $this->getHtmlInputNodeProcessor()->getEmbeddedContent();
}
<?php
namespace wcf\system\html\node;
use wcf\system\exception\SystemException;
+use wcf\system\html\IHtmlProcessor;
use wcf\util\JSON;
/**
* @since 3.0
*/
abstract class AbstractHtmlNodeProcessor implements IHtmlNodeProcessor {
- /**
- * context data
- * @var array
- */
- protected $context = [
- 'objectType' => '',
- 'objectID' => 0
- ];
-
/**
* active DOM document
* @var \DOMDocument
*/
protected $document;
+ /**
+ * html processor instance
+ * @var IHtmlProcessor
+ */
+ protected $htmlProcessor;
+
/**
* storage for node replacements
* @var array
/**
* @inheritDOc
*/
- public function load($html) {
- if (empty($this->context['objectType'])) {
- throw new SystemException('Missing object type, please set the context before attempting to call `load()`.');
- }
+ public function load(IHtmlProcessor $htmlProcessor, $html) {
+ $this->htmlProcessor = $htmlProcessor;
$this->document = new \DOMDocument('1.0', 'UTF-8');
$this->xpath = null;
/**
* @inheritDoc
*/
- public function setContext($objectType, $objectID) {
- $this->context = [
- 'objectType' => $objectType,
- 'objectID' => $objectID
- ];
- }
-
- /**
- * @inheritDoc
- */
- public function getContext() {
- return $this->context;
+ public function getHtmlProcessor() {
+ return $this->htmlProcessor;
}
/**
<?php
namespace wcf\system\html\node;
+use wcf\system\html\IHtmlProcessor;
/**
* Default interface for html node processors.
* @since 3.0
*/
interface IHtmlNodeProcessor {
- /**
- * Returns an array containing `objectType` and `objectID`.
- *
- * @return array
- */
- public function getContext();
-
/**
* Returns the currently loaded DOM document.
*
*/
public function getHtml();
+ /**
+ * Returns the html processor instance.
+ *
+ * @return IHtmlProcessor html processor instance
+ */
+ public function getHtmlProcessor();
+
/**
* Loads a HTML string for processing.
*
- * @param string $html HTML string
+ * @param IHtmlProcessor $htmlProcessor html processor
+ * @param string $html HTML string
*/
- public function load($html);
+ public function load(IHtmlProcessor $htmlProcessor, $html);
/**
* Processes the HTML and transforms it depending on the output type.
*/
public function process();
-
- /**
- * Sets the context of provided HTML, `$objectID` should be
- * `0` for objects in creation.
- *
- * @param string $objectType object type identifier
- * @param integer $objectID object id
- */
- public function setContext($objectType, $objectID);
}
<?php
namespace wcf\system\html\output;
-use wcf\system\html\IHtmlProcessor;
+use wcf\system\html\AbstractHtmlProcessor;
use wcf\system\html\output\node\HtmlOutputNodeProcessor;
/**
* @package WoltLabSuite\Core\System\Html\Output
* @since 3.0
*/
-class HtmlOutputProcessor implements IHtmlProcessor {
+class HtmlOutputProcessor extends AbstractHtmlProcessor {
/**
* output node processor instance
* @var HtmlOutputNodeProcessor
* @inheritDoc
*/
public function process($html, $objectType, $objectID) {
- $this->getHtmlOutputNodeProcessor()->setContext($objectType, $objectID);
- $this->getHtmlOutputNodeProcessor()->load($html);
+ $this->setContext($objectType, $objectID);
+
+ $this->getHtmlOutputNodeProcessor()->load($this, $html);
$this->getHtmlOutputNodeProcessor()->process();
}
* object type of the active message
* @var integer
*/
- protected $activeMessageObjectTypeID = null;
+ protected $activeMessageObjectTypeID;
/**
* id of the active message
* @var integer
*/
- protected $activeMessageID = null;
+ protected $activeMessageID;
/**
* list of embedded object handlers
* @var array
*/
- protected $embeddedObjectHandlers = null;
+ protected $embeddedObjectHandlers;
/**
* Registers the embedded objects found in given message.
*
* @param HtmlInputProcessor $htmlInputProcessor html input processor instance holding embedded object data
- * @param string $messageObjectType message object type
- * @param integer $messageID message id
* @return boolean true if at least one embedded object was found
*/
- public function registerObjects(HtmlInputProcessor $htmlInputProcessor, $messageObjectType, $messageID) {
+ public function registerObjects(HtmlInputProcessor $htmlInputProcessor) {
+ $context = $htmlInputProcessor->getContext();
+
+ $messageObjectType = $context['objectType'];
+ $messageObjectTypeID = $context['objectTypeID'];
+ $messageID = $context['objectID'];
+
// delete existing assignments
$this->removeObjects($messageObjectType, [$messageID]);
- // get object type id
- $messageObjectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName('com.woltlab.wcf.message', $messageObjectType);
-
// prepare statement
$sql = "INSERT INTO wcf".WCF_N."_message_embedded_object
(messageObjectTypeID, messageID, embeddedObjectTypeID, embeddedObjectID)