if (isset($this->textArray[$i + 1])) $this->parsedText .= $this->textArray[$i + 1];
}
+ /**
+ * Builds the bbcode output.
+ *
+ * @param string $name bbcode identifier
+ * @param array $attributes list of attributes
+ * @return string parsed bbcode
+ */
+ public function getHtmlOutput($name, array $attributes) {
+ if (isset($this->bbcodes[$name])) {
+ $openingTag = ['attributes' => $attributes, 'name' => $name];
+ $closingTag = ['name' => $name];
+
+ if ($this->bbcodes[$name]->getProcessor()) {
+ /** @var IBBCode $processor */
+ $processor = $this->bbcodes[$name]->getProcessor();
+ return $processor->getParsedTag($openingTag, '<!-- META_CODE_INNER_CONTENT -->', $closingTag, $this);
+ }
+ else {
+ return parent::buildOpeningTag($openingTag) . '<!-- META_CODE_INNER_CONTENT -->' . parent::buildClosingTag($closingTag);
+ }
+ }
+
+ // unknown bbcode, output plain tags
+ return $this->buildBBCodeTag($name, $attributes);
+ }
+
+ /**
+ * Builds a plain bbcode string, used for unknown bbcodes.
+ *
+ * @param string $name bbcode identifier
+ * @param array $attributes list of attributes
+ * @return string
+ */
+ protected function buildBBCodeTag($name, $attributes) {
+ if (!empty($attributes)) {
+ foreach ($attributes as &$attribute) {
+ $attribute = "'" . addcslashes($attribute, "'") . "'";
+ }
+ unset($attribute);
+
+ $attributes = '=' . implode(",", $attributes);
+ }
+ else {
+ $attributes = '';
+ }
+
+ return '[' . $name . $attributes . ']<!-- META_CODE_INNER_CONTENT -->[/' . $name . ']';
+ }
+
/**
* Compiles tag fragments into the custom HTML element.
*
}
// handle simple mapping types
- if (isset($name, $this->simpleMapping)) {
+ if (isset($this->simpleMapping[$name])) {
$newElement = $element->ownerDocument->createElement($this->simpleMapping[$name]);
DOMUtil::replaceElement($element, $newElement);
<?php
namespace wcf\system\html\input\node;
+use wcf\system\bbcode\HtmlBBCodeParser;
use wcf\system\exception\SystemException;
use wcf\system\html\node\AbstractHtmlNode;
use wcf\system\html\node\HtmlNodeProcessor;
/** @var \DOMElement $end */
$end = $pair['close'];
- $attributes = '';
- if (!empty($pair['attributes'])) {
- $pair['attributes'] = base64_decode($pair['attributes'], true);
- if ($pair['attributes'] !== false) {
- try {
- $pair['attributes'] = JSON::decode($pair['attributes']);
- }
- catch (SystemException $e) {
- $pair['attributes'] = [];
- }
-
- if (!empty($pair['attributes'])) {
- foreach ($pair['attributes'] as &$attribute) {
- $attribute = "'" . addcslashes($attribute, "'") . "'";
- }
- unset($attribute);
-
- $attributes = '=' . implode(",", $attributes);
- }
- }
- }
-
- $textNode = $start->ownerDocument->createTextNode('[' . $pair['name'] . $attributes . ']');
+ $attributes = (isset($pair['attributes'])) ? $pair['attributes'] : '';
+ $textNode = $start->ownerDocument->createTextNode(HtmlBBCodeParser::getInstance()->buildBBCodeTag($pair['name'], $attributes));
DOMUtil::insertBefore($textNode, $start);
DOMUtil::removeNode($start);
<?php
namespace wcf\system\html\node;
use wcf\system\exception\SystemException;
+use wcf\util\JSON;
/**
* TOOD documentation
];
}
+ public function parseAttributes($attributes) {
+ if (empty($attributes)) {
+ return [];
+ }
+
+ $parsedAttributes = base64_decode($attributes, true);
+ if ($parsedAttributes !== false) {
+ try {
+ $parsedAttributes = JSON::decode($parsedAttributes);
+ }
+ catch (SystemException $e) {
+ $parsedAttributes = [];
+ }
+ }
+
+ return $parsedAttributes;
+ }
+
protected function invokeHtmlNode(IHtmlNode $htmlNode) {
$tagName = $htmlNode->getTagName();
if (empty($tagName)) {
*/
class HtmlOutputNodeProcessor extends HtmlNodeProcessor {
public function process() {
+ $this->invokeHtmlNode(new HtmlOutputNodeWoltlabMetacode());
+
// TODO: this should be dynamic to some extent
$this->invokeHtmlNode(new HtmlOutputNodeBlockquote());
$this->invokeHtmlNode(new HtmlOutputNodeWoltlabMention());
--- /dev/null
+<?php
+namespace wcf\system\html\output\node;
+use wcf\system\bbcode\HtmlBBCodeParser;
+use wcf\system\html\node\AbstractHtmlNode;
+use wcf\system\html\node\HtmlNodeProcessor;
+use wcf\util\StringUtil;
+
+/**
+ * TOOD documentation
+ * @since 2.2
+ */
+class HtmlOutputNodeWoltlabMetacode extends AbstractHtmlNode {
+ protected $tagName = 'woltlab-metacode';
+
+ /**
+ * @inheritDoc
+ */
+ public function process(array $elements, HtmlNodeProcessor $htmlNodeProcessor) {
+ /** @var \DOMElement $element */
+ foreach ($elements as $element) {
+ $name = $element->getAttribute('data-name');
+ $attributes = $element->getAttribute('data-attributes');
+
+ $nodeIdentifier = StringUtil::getRandomID();
+ $htmlNodeProcessor->addNodeData($this, $nodeIdentifier, [
+ 'name' => $name,
+ 'attributes' => $htmlNodeProcessor->parseAttributes($attributes)
+ ]);
+
+ $htmlNodeProcessor->renameTag($element, 'wcfNode-' . $nodeIdentifier);
+ }
+ }
+
+ public function replaceTag(array $data) {
+ return HtmlBBCodeParser::getInstance()->getHtmlOutput($data['name'], $data['attributes']);
+ }
+}