3 namespace wcf\system\html\output
;
5 use wcf\data\
object\type\ObjectTypeCache
;
6 use wcf\system\html\AbstractHtmlProcessor
;
7 use wcf\system\html\output\node\HtmlOutputNodeProcessor
;
8 use wcf\system\message\embedded\
object\MessageEmbeddedObjectManager
;
11 * Processes stored HTML for final display.
13 * @author Alexander Ebert
14 * @copyright 2001-2019 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
16 * @package WoltLabSuite\Core\System\Html\Output
19 class HtmlOutputProcessor
extends AbstractHtmlProcessor
22 * Generate the table of contents, implicitly enable this for certain object types on demand.
29 * Removes any link contained inside the message text.
33 public $removeLinks = false;
36 * output node processor instance
37 * @var HtmlOutputNodeProcessor
39 protected $htmlOutputNodeProcessor;
45 protected $languageID;
51 protected $outputType = 'text/html';
54 * enables rel=ugc for external links
57 public $enableUgc = true;
60 * Processes the input html string.
62 * @param string $html html string
63 * @param string $objectType object type identifier
64 * @param int $objectID object id
65 * @param bool $doKeywordHighlighting enable keyword highlighting
66 * @param int $languageID content language id
68 public function process($html, $objectType, $objectID, $doKeywordHighlighting = true, $languageID = null)
70 $this->languageID
= $languageID;
71 $this->setContext($objectType, $objectID);
73 $this->getHtmlOutputNodeProcessor()->setOutputType($this->outputType
);
74 $this->getHtmlOutputNodeProcessor()->enableKeywordHighlighting($doKeywordHighlighting);
75 $this->getHtmlOutputNodeProcessor()->load($this, $html);
76 $this->getHtmlOutputNodeProcessor()->process();
80 * Sets the desired output type.
82 * @param string $outputType desired output type
83 * @throws \InvalidArgumentException
85 public function setOutputType($outputType)
87 if (!\
in_array($outputType, ['text/html', 'text/simplified-html', 'text/plain'])) {
88 throw new \
InvalidArgumentException(
89 "Expected 'text/html', 'text/simplified-html' or 'text/plain', but received '" . $outputType . "'"
93 $this->outputType
= $outputType;
99 public function getHtml()
101 return $this->getHtmlOutputNodeProcessor()->getHtml();
106 * @throws \InvalidArgumentException
108 public function setContext($objectType, $objectID)
110 parent
::setContext($objectType, $objectID);
112 MessageEmbeddedObjectManager
::getInstance()->setActiveMessage($objectType, $objectID, $this->languageID
);
113 $objectType = ObjectTypeCache
::getInstance()->getObjectTypeByName('com.woltlab.wcf.message', $objectType);
114 if ($this->enableToc
=== null) {
115 $this->enableToc
= (!empty($objectType->additionalData
['enableToc']));
120 * Returns the output node processor instance.
122 * @return HtmlOutputNodeProcessor output node processor instance
124 protected function getHtmlOutputNodeProcessor()
126 if ($this->htmlOutputNodeProcessor
=== null) {
127 $this->htmlOutputNodeProcessor
= new HtmlOutputNodeProcessor();
130 return $this->htmlOutputNodeProcessor
;