}
$this->htmlInputProcessors[$language->languageID] = new HtmlInputProcessor();
- $this->htmlInputProcessors[$language->languageID]->process($this->content[$language->languageID]);
+ $this->htmlInputProcessors[$language->languageID]->process($this->content[$language->languageID], 'com.woltlab.wcf.article.content', 0);
}
}
else {
}
$this->htmlInputProcessors[0] = new HtmlInputProcessor();
- $this->htmlInputProcessors[0]->process($this->content[0]);
+ $this->htmlInputProcessors[0]->process($this->content[0], 'com.woltlab.wcf.article.content', 0);
}
}
// assign embedded objects
MessageEmbeddedObjectManager::getInstance()->setActiveMessage('com.woltlab.wcf.article.content', $this->articleContentID);
- // TODO
- return (new HtmlOutputProcessor())->process($this->content);
+ $processor = new HtmlOutputProcessor();
+ $processor->process($this->message, 'com.woltlab.wcf.article.content', $this->articleContentID);
+
+ return $processor->getHtml();
}
/**
--- /dev/null
+<?php
+namespace wcf\system\html;
+
+/**
+ * Default interface 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
+ */
+interface IHtmlProcessor {
+ /**
+ * Processes the input html string.
+ *
+ * @param string $html html string
+ * @param string $objectType object type identifier
+ * @param integer $objectID object id
+ */
+ public function process($html, $objectType, $objectID);
+
+ /**
+ * Returns the parsed html.
+ *
+ * @return string parsed html
+ */
+ public function getHtml();
+}
<?php
namespace wcf\system\html\input;
use wcf\system\bbcode\HtmlBBCodeParser;
+use wcf\system\html\IHtmlProcessor;
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 {
+class HtmlInputProcessor implements IHtmlProcessor {
/**
* list of embedded content grouped by type
* @var array
protected $htmlInputNodeProcessor;
/**
- * Processes input HTML by applying filters and parsing all nodes
- * including bbcodes.
- *
- * @param string $html html string
+ * @inheritDoc
*/
- public function process($html) {
+ public function process($html, $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()->process();
* @since 3.0
*/
abstract class AbstractHtmlNodeProcessor implements IHtmlNodeProcessor {
+ /**
+ * context data
+ * @var array
+ */
+ protected $context = [
+ 'objectType' => '',
+ 'objectID' => 0
+ ];
+
/**
* active DOM document
* @var \DOMDocument
* @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()`.');
+ }
+
$this->document = new \DOMDocument('1.0', 'UTF-8');
$this->xpath = null;
return $parsedAttributes;
}
+ /**
+ * @inheritDoc
+ */
+ public function setContext($objectType, $objectID) {
+ $this->context = [
+ 'objectType' => $objectType,
+ 'objectID' => $objectID
+ ];
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getContext() {
+ return $this->context;
+ }
+
/**
* Invokes a html node processor.
*
* @since 3.0
*/
interface IHtmlNodeProcessor {
+ /**
+ * Returns an array containing `objectType` and `objectID`.
+ *
+ * @return array
+ */
+ public function getContext();
+
/**
* Returns the currently loaded DOM document.
*
* 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\output\node\HtmlOutputNodeProcessor;
/**
- * TOOD documentation
- * @since 3.0
+ * Processes stored HTML for final display.
+ *
+ * @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\Output
+ * @since 3.0
*/
-class HtmlOutputProcessor {
+class HtmlOutputProcessor implements IHtmlProcessor {
/**
+ * output node processor instance
* @var HtmlOutputNodeProcessor
*/
protected $htmlOutputNodeProcessor;
- public function process($html) {
+ /**
+ * @inheritDoc
+ */
+ public function process($html, $objectType, $objectID) {
+ $this->getHtmlOutputNodeProcessor()->setContext($objectType, $objectID);
$this->getHtmlOutputNodeProcessor()->load($html);
$this->getHtmlOutputNodeProcessor()->process();
-
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getHtml() {
return $this->getHtmlOutputNodeProcessor()->getHtml();
}
+ /**
+ * Returns the output node processor instance.
+ *
+ * @return HtmlOutputNodeProcessor output node processor instance
+ */
protected function getHtmlOutputNodeProcessor() {
if ($this->htmlOutputNodeProcessor === null) {
$this->htmlOutputNodeProcessor = new HtmlOutputNodeProcessor();