Added output type and basic implementations
authorAlexander Ebert <ebert@woltlab.com>
Mon, 27 Jun 2016 11:12:30 +0000 (13:12 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 27 Jun 2016 11:12:30 +0000 (13:12 +0200)
21 files changed:
wcfsetup/install/files/lib/system/html/input/node/AbstractHtmlInputNode.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeImg.class.php
wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php
wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeWoltlabMention.class.php
wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeWoltlabMetacode.class.php
wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeWoltlabMetacodeMarker.class.php
wcfsetup/install/files/lib/system/html/node/AbstractHtmlNodeProcessor.class.php
wcfsetup/install/files/lib/system/html/output/HtmlOutputProcessor.class.php
wcfsetup/install/files/lib/system/html/output/node/AbstractHtmlOutputNode.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeBlockquote.class.php
wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodePre.class.php
wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeProcessor.class.php
wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeWoltlabColor.class.php
wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeWoltlabMention.class.php
wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeWoltlabMetacode.class.php
wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeWoltlabSize.class.php
wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeWoltlabSpoiler.class.php
wcfsetup/install/files/lib/system/html/output/node/IHtmlOutputNode.class.php
wcfsetup/install/files/lib/util/DOMUtil.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

diff --git a/wcfsetup/install/files/lib/system/html/input/node/AbstractHtmlInputNode.class.php b/wcfsetup/install/files/lib/system/html/input/node/AbstractHtmlInputNode.class.php
new file mode 100644 (file)
index 0000000..945877e
--- /dev/null
@@ -0,0 +1,14 @@
+<?php
+namespace wcf\system\html\input\node;
+use wcf\system\html\node\AbstractHtmlNode;
+
+/**
+ * Default implementation for html input nodes.
+ * 
+ * @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\Input\Node
+ * @since       3.0
+ */
+abstract class AbstractHtmlInputNode extends AbstractHtmlNode implements IHtmlInputNode {}
index 12e9b64c0f3ce44b9ae74391d0e239abf6ccfc37..f3c3de97832467982fa646e3d365f904579cec8a 100644 (file)
@@ -1,12 +1,11 @@
 <?php
 namespace wcf\system\html\input\node;
-use wcf\system\html\node\AbstractHtmlNode;
 use wcf\system\html\node\AbstractHtmlNodeProcessor;
 use wcf\util\DOMUtil;
 use wcf\util\JSON;
 
 /**
- * Proccesses `<img>` to handle embedded attachments.
+ * Processes `<img>` to handle embedded attachments.
  * 
  * @author      Alexander Ebert
  * @copyright   2001-2016 WoltLab GmbH
@@ -14,7 +13,7 @@ use wcf\util\JSON;
  * @package     WoltLabSuite\Core\System\Html\Input\Node
  * @since       3.0
  */
-class HtmlInputNodeImg extends AbstractHtmlNode {
+class HtmlInputNodeImg extends AbstractHtmlInputNode {
        /**
         * @inheritDoc
         */
index 0d2c8e5e96ded0b7729beadddb5e9ddddabdb911..8e2b59ea1f1ac54723df39a587b7f0a0c19b9e8e 100644 (file)
@@ -19,6 +19,11 @@ class HtmlInputNodeProcessor extends AbstractHtmlNodeProcessor {
         */
        protected $embeddedContent = [];
        
+       /**
+        * @inheritDoc
+        */
+       protected $nodeInterface = IHtmlInputNode::class;
+       
        /**
         * @inheritDoc
         */
index 253add68daab32ecb7ea89f482a03c90c3fda7a2..3f520f9a7fad366eebfc4483691d3acdd712d396 100644 (file)
@@ -1,10 +1,9 @@
 <?php
 namespace wcf\system\html\input\node;
-use wcf\system\html\node\AbstractHtmlNode;
 use wcf\system\html\node\AbstractHtmlNodeProcessor;
 
 /**
- * Proccesses `<woltlab-mention>`.
+ * Processes `<woltlab-mention>`.
  * 
  * @author      Alexander Ebert
  * @copyright   2001-2016 WoltLab GmbH
@@ -12,7 +11,7 @@ use wcf\system\html\node\AbstractHtmlNodeProcessor;
  * @package     WoltLabSuite\Core\System\Html\Input\Node
  * @since       3.0
  */
-class HtmlInputNodeWoltlabMention extends AbstractHtmlNode {
+class HtmlInputNodeWoltlabMention extends AbstractHtmlInputNode {
        /**
         * @inheritDoc
         */
index 23acfc86810b407b3c907fd665844b4ffe05fc6f..8b8251d838482f55fed3cbe95e0c56dd145e1998 100644 (file)
@@ -1,12 +1,11 @@
 <?php
 namespace wcf\system\html\input\node;
 use wcf\system\html\metacode\converter\IMetacodeConverter;
-use wcf\system\html\node\AbstractHtmlNode;
 use wcf\system\html\node\AbstractHtmlNodeProcessor;
 use wcf\util\DOMUtil;
 
 /**
- * Proccesses `<woltlab-metacode>` and converts them if appropriate.
+ * Processes `<woltlab-metacode>` and converts them if appropriate.
  *
  * @author      Alexander Ebert
  * @copyright   2001-2016 WoltLab GmbH
@@ -14,7 +13,7 @@ use wcf\util\DOMUtil;
  * @package     WoltLabSuite\Core\System\Html\Input\Node
  * @since       3.0
  */
-class HtmlInputNodeWoltlabMetacode extends AbstractHtmlNode {
+class HtmlInputNodeWoltlabMetacode extends AbstractHtmlInputNode {
        /**
         * static mapping of attribute-less metacodes that map to
         * an exact HTML tag without the need of further processing
index 8a90cb92f8a9be43cd5d928f9efefe08cb408933..38ef3622422e5fd2c29c17d4317b6c11c8728cd5 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 namespace wcf\system\html\input\node;
 use wcf\system\bbcode\HtmlBBCodeParser;
-use wcf\system\html\node\AbstractHtmlNode;
 use wcf\system\html\node\AbstractHtmlNodeProcessor;
 use wcf\util\DOMUtil;
 
@@ -15,7 +14,7 @@ use wcf\util\DOMUtil;
  * @package    WoltLabSuite\Core\System\Html\Input\Node
  * @since      3.0
  */
-class HtmlInputNodeWoltlabMetacodeMarker extends AbstractHtmlNode {
+class HtmlInputNodeWoltlabMetacodeMarker extends AbstractHtmlInputNode {
        /**
         * list of bbcodes that represent block elements
         * @var string[]
index a8e7ac5e7a8f31efcbf88b7f4f7136ecc9fa0c0f..8c757d32ba5440446d787b0a232425621fde5ad6 100644 (file)
@@ -26,6 +26,12 @@ abstract class AbstractHtmlNodeProcessor implements IHtmlNodeProcessor {
         */
        protected $htmlProcessor;
        
+       /**
+        * required interface for html nodes
+        * @var string
+        */
+       protected $nodeInterface = '';
+       
        /**
         * storage for node replacements
         * @var array
@@ -124,6 +130,18 @@ abstract class AbstractHtmlNodeProcessor implements IHtmlNodeProcessor {
                return $newElement;
        }
        
+       /**
+        * Replaces an element with plain text.
+        * 
+        * @param       \DOMElement     $element        target element
+        * @param       string          $text           text used to replace target element
+        */
+       public function replaceElementWithText(\DOMElement $element, $text) {
+               $textNode = $element->ownerDocument->createTextNode($text);
+               $element->parentNode->insertBefore($textNode, $element);
+               $element->parentNode->removeChild($element);
+       }
+       
        /**
         * Removes an element but preserves child nodes by moving them into
         * its original position.
@@ -191,6 +209,10 @@ abstract class AbstractHtmlNodeProcessor implements IHtmlNodeProcessor {
         * @param       IHtmlNode       $htmlNode       html node processor
         */
        protected function invokeHtmlNode(IHtmlNode $htmlNode) {
+               if (!($htmlNode instanceof $this->nodeInterface)) {
+                       throw new \InvalidArgumentException("Node '" . get_class($htmlNode) . "' does not implement the interface '" . $this->nodeInterface . "'.");
+               }
+               
                $tagName = $htmlNode->getTagName();
                if (empty($tagName)) {
                        throw new \UnexpectedValueException("Missing tag name for " . get_class($htmlNode));
index 23b63fbe5668e41b34a4803793f2b2ae65796e64..e0fb3f036505d105c640b1f285dbaacc36b84939 100644 (file)
@@ -19,16 +19,37 @@ class HtmlOutputProcessor extends AbstractHtmlProcessor {
         */
        protected $htmlOutputNodeProcessor;
        
+       /**
+        * desired output type
+        * @var string
+        */
+       protected $outputType = 'text/html';
+       
        /**
         * @inheritDoc
         */
        public function process($html, $objectType, $objectID) {
                $this->setContext($objectType, $objectID);
                
+               $this->getHtmlOutputNodeProcessor()->setOutputType($this->outputType);
                $this->getHtmlOutputNodeProcessor()->load($this, $html);
                $this->getHtmlOutputNodeProcessor()->process();
        }
        
+       /**
+        * Sets the desired output type.
+        * 
+        * @param       string          $outputType     desired output type
+        * @throws      \InvalidArgumentException
+        */
+       public function setOutputType($outputType) {
+               if (!in_array($outputType, ['text/html', 'text/simplified-html', 'text/plain'])) {
+                       throw new \InvalidArgumentException("Expected 'text/html', 'text/simplified-html' or 'text/plain', but received '" . $outputType . "'");
+               }
+               
+               $this->outputType = $outputType;
+       }
+       
        /**
         * @inheritDoc
         */
diff --git a/wcfsetup/install/files/lib/system/html/output/node/AbstractHtmlOutputNode.class.php b/wcfsetup/install/files/lib/system/html/output/node/AbstractHtmlOutputNode.class.php
new file mode 100644 (file)
index 0000000..fd5898b
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+namespace wcf\system\html\output\node;
+use wcf\system\html\node\AbstractHtmlNode;
+
+/**
+ * Default implementation for html output nodes.
+ * 
+ * @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\Node
+ * @since       3.0
+ */
+abstract class AbstractHtmlOutputNode extends AbstractHtmlNode implements IHtmlOutputNode {
+       /**
+        * desired output type
+        * @var string
+        */
+       protected $outputType = 'text/html';
+       
+       /**
+        * @inheritDoc
+        */
+       public function setOutputType($outputType) {
+               $this->outputType = $outputType;
+       }
+}
index d1fdea2009722a05ea4905e3b6180282dceb082d..5ffc96d3a712f06444fec204775917cfab37ec65 100644 (file)
@@ -1,11 +1,11 @@
 <?php
 namespace wcf\system\html\output\node;
 use wcf\system\application\ApplicationHandler;
-use wcf\system\html\node\AbstractHtmlNode;
 use wcf\system\html\node\AbstractHtmlNodeProcessor;
 use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
 use wcf\system\request\RouteHandler;
 use wcf\system\WCF;
+use wcf\util\DOMUtil;
 use wcf\util\StringUtil;
 
 /**
@@ -17,7 +17,7 @@ use wcf\util\StringUtil;
  * @package     WoltLabSuite\Core\System\Html\Output\Node
  * @since       3.0
  */
-class HtmlOutputNodeBlockquote extends AbstractHtmlNode {
+class HtmlOutputNodeBlockquote extends AbstractHtmlOutputNode {
        /**
         * @inheritDoc
         */
@@ -29,13 +29,31 @@ class HtmlOutputNodeBlockquote extends AbstractHtmlNode {
        public function process(array $elements, AbstractHtmlNodeProcessor $htmlNodeProcessor) {
                /** @var \DOMElement $element */
                foreach ($elements as $element) {
-                       $nodeIdentifier = StringUtil::getRandomID();
-                       $htmlNodeProcessor->addNodeData($this, $nodeIdentifier, [
-                               'author' => ($element->hasAttribute('data-author')) ? $element->getAttribute('data-author') : '',
-                               'url' => ($element->hasAttribute('data-url')) ? $element->getAttribute('data-url') : ''
-                       ]);
-                       
-                       $htmlNodeProcessor->renameTag($element, 'wcfNode-' . $nodeIdentifier);
+                       switch ($this->outputType) {
+                               case 'text/html':
+                                       $nodeIdentifier = StringUtil::getRandomID();
+                                       $htmlNodeProcessor->addNodeData($this, $nodeIdentifier, [
+                                               'author' => $element->getAttribute('data-author'),
+                                               'url' => $element->getAttribute('data-url')
+                                       ]);
+                                       
+                                       $htmlNodeProcessor->renameTag($element, 'wcfNode-' . $nodeIdentifier);
+                                       break;
+                               
+                               case 'text/simplified-html':
+                               case 'text/plain':
+                                       // check if this quote is within another
+                                       if (DOMUtil::hasParent($element, 'blockquote')) {
+                                               DOMUtil::removeNode($element);
+                                       }
+                                       else {
+                                               $htmlNodeProcessor->replaceElementWithText(
+                                                       $element,
+                                                       WCF::getLanguage()->getDynamicVariable('wcf.bbcode.quote.simplified', ['cite' => $element->getAttribute('data-author')])."\n"
+                                               );
+                                       }
+                                       break;
+                       }
                }
        }
        
index 79184f5bb989edd235edb7d17e62e3bc26d814f9..95d4c94d37777ab998b64302a6807a53167d6850 100644 (file)
@@ -13,7 +13,6 @@ use wcf\system\bbcode\highlighter\PythonHighlighter;
 use wcf\system\bbcode\highlighter\SqlHighlighter;
 use wcf\system\bbcode\highlighter\TexHighlighter;
 use wcf\system\bbcode\highlighter\XmlHighlighter;
-use wcf\system\html\node\AbstractHtmlNode;
 use wcf\system\html\node\AbstractHtmlNodeProcessor;
 use wcf\system\Regex;
 use wcf\system\WCF;
@@ -28,7 +27,7 @@ use wcf\util\StringUtil;
  * @package     WoltLabSuite\Core\System\Html\Output\Node
  * @since       3.0
  */
-class HtmlOutputNodePre extends AbstractHtmlNode {
+class HtmlOutputNodePre extends AbstractHtmlOutputNode {
        /**
         * @inheritDoc
         */
@@ -46,15 +45,24 @@ class HtmlOutputNodePre extends AbstractHtmlNode {
        public function process(array $elements, AbstractHtmlNodeProcessor $htmlNodeProcessor) {
                /** @var \DOMElement $element */
                foreach ($elements as $element) {
-                       $nodeIdentifier = StringUtil::getRandomID();
-                       $htmlNodeProcessor->addNodeData($this, $nodeIdentifier, [
-                               'content' => $element->textContent,
-                               'file' => ($element->hasAttribute('data-file')) ? $element->getAttribute('data-file') : '',
-                               'highlighter' => ($element->hasAttribute('data-highlighter')) ? $element->getAttribute('data-highlighter') : '',
-                               'line' => ($element->hasAttribute('data-line')) ? $element->getAttribute('data-line') : 1
-                       ]);
-                       
-                       $htmlNodeProcessor->renameTag($element, 'wcfNode-' . $nodeIdentifier);
+                       switch ($this->outputType) {
+                               case 'text/html':
+                                       $nodeIdentifier = StringUtil::getRandomID();
+                                       $htmlNodeProcessor->addNodeData($this, $nodeIdentifier, [
+                                               'content' => $element->textContent,
+                                               'file' => ($element->hasAttribute('data-file')) ? $element->getAttribute('data-file') : '',
+                                               'highlighter' => ($element->hasAttribute('data-highlighter')) ? $element->getAttribute('data-highlighter') : '',
+                                               'line' => ($element->hasAttribute('data-line')) ? $element->getAttribute('data-line') : 1
+                                       ]);
+                                       
+                                       $htmlNodeProcessor->renameTag($element, 'wcfNode-' . $nodeIdentifier);
+                                       break;
+                               
+                               case 'text/simplified-html':
+                               case 'text/plain':
+                                       return WCF::getLanguage()->getDynamicVariable('wcf.bbcode.code.simplified', ['lines' => substr_count($element->nodeValue, "\n") + 1]);
+                                       break;
+                       }
                }
        }
        
index 015203c17658f3f8431762f54c29d31555ac0b73..cf0adb66cc8669082c2ffa712b1288411080d49d 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 namespace wcf\system\html\output\node;
 use wcf\system\html\node\AbstractHtmlNodeProcessor;
+use wcf\system\html\node\IHtmlNode;
 
 /**
  * Processes a HTML string and renders the final output for display.
@@ -12,6 +13,26 @@ use wcf\system\html\node\AbstractHtmlNodeProcessor;
  * @since       3.0
  */
 class HtmlOutputNodeProcessor extends AbstractHtmlNodeProcessor {
+       /**
+        * @inheritDoc
+        */
+       protected $nodeInterface = IHtmlOutputNode::class;
+       
+       /**
+        * desired output type
+        * @var string
+        */
+       protected $outputType = 'text/html';
+       
+       /**
+        * Sets the desired output type.
+        * 
+        * @param       string          $outputType     desired output type
+        */
+       public function setOutputType($outputType) {
+               $this->outputType = $outputType;
+       }
+       
        /**
         * @inheritDoc
         */
@@ -21,4 +42,14 @@ class HtmlOutputNodeProcessor extends AbstractHtmlNodeProcessor {
                // dynamic node handlers
                $this->invokeNodeHandlers('wcf\system\html\output\node\HtmlOutputNode', ['woltlab-metacode']);
        }
+       
+       /**
+        * @inheritDoc
+        */
+       protected function invokeHtmlNode(IHtmlNode $htmlNode) {
+               /** @var IHtmlOutputNode $htmlNode */
+               $htmlNode->setOutputType($this->outputType);
+               
+               parent::invokeHtmlNode($htmlNode);
+       }
 }
index f6829e093d50a7c8a73a5a8deb21a8faae8f9259..5e45e0199552e3e58f5bd1399da146cb38656810 100644 (file)
@@ -1,6 +1,5 @@
 <?php
 namespace wcf\system\html\output\node;
-use wcf\system\html\node\AbstractHtmlNode;
 use wcf\system\html\node\AbstractHtmlNodeProcessor;
 use wcf\util\StringUtil;
 
@@ -13,7 +12,7 @@ use wcf\util\StringUtil;
  * @package     WoltLabSuite\Core\System\Html\Output\Node
  * @since       3.0
  */
-class HtmlOutputNodeWoltlabColor extends AbstractHtmlNode {
+class HtmlOutputNodeWoltlabColor extends AbstractHtmlOutputNode {
        /**
         * @inheritDoc
         */
@@ -23,16 +22,16 @@ class HtmlOutputNodeWoltlabColor extends AbstractHtmlNode {
         * @inheritDoc
         */
        public function process(array $elements, AbstractHtmlNodeProcessor $htmlNodeProcessor) {
-               /** @var \DOMElement $element */
-               foreach ($elements as $element) {
-                       // parse color
-                       if (preg_match('~^woltlab-color-(?P<color>[A-F0-9]{6})$~', $element->getAttribute('class'), $matches)) {
-                               $nodeIdentifier = StringUtil::getRandomID();
-                               $htmlNodeProcessor->addNodeData($this, $nodeIdentifier, [
-                                       'color' => $matches['color']
-                               ]);
-                               
-                               $htmlNodeProcessor->renameTag($element, 'wcfNode-' . $nodeIdentifier);
+               if ($this->outputType === 'text/html' || $this->outputType === 'text/simplified-html') {
+                       /** @var \DOMElement $element */
+                       foreach ($elements as $element) {
+                               // parse color
+                               if (preg_match('~^woltlab-color-(?P<color>[A-F0-9]{6})$~', $element->getAttribute('class'), $matches)) {
+                                       $nodeIdentifier = StringUtil::getRandomID();
+                                       $htmlNodeProcessor->addNodeData($this, $nodeIdentifier, ['color' => $matches['color']]);
+                                       
+                                       $htmlNodeProcessor->renameTag($element, 'wcfNode-' . $nodeIdentifier);
+                               }
                        }
                }
        }
index e2821b253ec900022dfd09b2eed87fe1907815be..3ae4183a50f39d7e804dcc13d359c4dcaebd0ad2 100644 (file)
@@ -2,7 +2,6 @@
 namespace wcf\system\html\output\node;
 use wcf\data\user\UserProfile;
 use wcf\system\cache\runtime\UserProfileRuntimeCache;
-use wcf\system\html\node\AbstractHtmlNode;
 use wcf\system\html\node\AbstractHtmlNodeProcessor;
 use wcf\system\WCF;
 use wcf\util\DOMUtil;
@@ -17,7 +16,7 @@ use wcf\util\StringUtil;
  * @package     WoltLabSuite\Core\System\Html\Output\Node
  * @since       3.0
  */
-class HtmlOutputNodeWoltlabMention extends AbstractHtmlNode {
+class HtmlOutputNodeWoltlabMention extends AbstractHtmlOutputNode {
        /**
         * @inheritDoc
         */
@@ -32,31 +31,36 @@ class HtmlOutputNodeWoltlabMention extends AbstractHtmlNode {
         * @inheritDoc
         */
        public function process(array $elements, AbstractHtmlNodeProcessor $htmlNodeProcessor) {
-               $this->userProfiles = [];
-               
-               $userIds = [];
-               /** @var \DOMElement $element */
-               foreach ($elements as $element) {
-                       $userId = ($element->hasAttribute('data-user-id')) ? intval($element->getAttribute('data-user-id')) : 0;
-                       $username = ($element->hasAttribute('data-username')) ? StringUtil::trim($element->getAttribute('data-username')) : '';
+               if ($this->outputType === 'text/html' || $this->outputType === 'text/simplified-html') {
+                       $this->userProfiles = [];
                        
-                       if ($userId === 0 || $username === '') {
-                               DOMUtil::removeNode($element);
-                               continue;
+                       $userIds = [];
+                       /** @var \DOMElement $element */
+                       foreach ($elements as $element) {
+                               $userId = intval($element->getAttribute('data-user-id'));
+                               $username = StringUtil::trim($element->getAttribute('data-username'));
+                               
+                               if ($userId === 0 || $username === '') {
+                                       DOMUtil::removeNode($element);
+                                       continue;
+                               }
+                               
+                               $userIds[] = $userId;
+                               $nodeIdentifier = StringUtil::getRandomID();
+                               $htmlNodeProcessor->addNodeData($this, $nodeIdentifier, ['userId' => $userId, 'username' => $username]);
+                               
+                               $htmlNodeProcessor->renameTag($element, 'wcfNode-' . $nodeIdentifier);
                        }
                        
-                       $userIds[] = $userId;
-                       $nodeIdentifier = StringUtil::getRandomID();
-                       $htmlNodeProcessor->addNodeData($this, $nodeIdentifier, [
-                               'userId' => $userId,
-                               'username' => $username
-                       ]);
-                       
-                       $htmlNodeProcessor->renameTag($element, 'wcfNode-' . $nodeIdentifier);
+                       if (!empty($userIds)) {
+                               $this->userProfiles = UserProfileRuntimeCache::getInstance()->getObjects($userIds);
+                       }
                }
-               
-               if (!empty($userIds)) {
-                       $this->userProfiles = UserProfileRuntimeCache::getInstance()->getObjects($userIds);
+               else if ($this->outputType === 'text/plain') {
+                       /** @var \DOMElement $element */
+                       foreach ($elements as $element) {
+                               $htmlNodeProcessor->replaceElementWithText($element, '@' . $element->getAttribute('data-username'));
+                       }
                }
        }
        
index 98a2df63e183cdc41ad5a56881dc41e24bf92d9d..368c418e6b7f857fc2c6ca34ac9b0ffbd9ffdc48 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 namespace wcf\system\html\output\node;
 use wcf\system\bbcode\HtmlBBCodeParser;
-use wcf\system\html\node\AbstractHtmlNode;
 use wcf\system\html\node\AbstractHtmlNodeProcessor;
 use wcf\util\StringUtil;
 
@@ -14,7 +13,7 @@ use wcf\util\StringUtil;
  * @package     WoltLabSuite\Core\System\Html\Output\Node
  * @since       3.0
  */
-class HtmlOutputNodeWoltlabMetacode extends AbstractHtmlNode {
+class HtmlOutputNodeWoltlabMetacode extends AbstractHtmlOutputNode {
        /**
         * @inheritDoc
         */
@@ -43,6 +42,8 @@ class HtmlOutputNodeWoltlabMetacode extends AbstractHtmlNode {
         * @inheritDoc
         */
        public function replaceTag(array $data) {
+               HtmlBBCodeParser::getInstance()->setOutputType($this->outputType);
+               
                return HtmlBBCodeParser::getInstance()->getHtmlOutput($data['name'], $data['attributes']);
        }
 }
index 094d96f7a570f5a6fe83685aa98fe65d9f6ba090..ca817d49ceb16065db9a740b30428754178e7b8a 100644 (file)
@@ -1,6 +1,5 @@
 <?php
 namespace wcf\system\html\output\node;
-use wcf\system\html\node\AbstractHtmlNode;
 use wcf\system\html\node\AbstractHtmlNodeProcessor;
 use wcf\util\StringUtil;
 
@@ -13,7 +12,7 @@ use wcf\util\StringUtil;
  * @package     WoltLabSuite\Core\System\Html\Output\Node
  * @since       3.0
  */
-class HtmlOutputNodeWoltlabSize extends AbstractHtmlNode {
+class HtmlOutputNodeWoltlabSize extends AbstractHtmlOutputNode {
        /**
         * @inheritDoc
         */
@@ -23,16 +22,16 @@ class HtmlOutputNodeWoltlabSize extends AbstractHtmlNode {
         * @inheritDoc
         */
        public function process(array $elements, AbstractHtmlNodeProcessor $htmlNodeProcessor) {
-               /** @var \DOMElement $element */
-               foreach ($elements as $element) {
-                       // parse color
-                       if (preg_match('~^woltlab-size-(?P<size>[0-9]{1,2})$~', $element->getAttribute('class'), $matches)) {
-                               $nodeIdentifier = StringUtil::getRandomID();
-                               $htmlNodeProcessor->addNodeData($this, $nodeIdentifier, [
-                                       'size' => $matches['size']
-                               ]);
-                               
-                               $htmlNodeProcessor->renameTag($element, 'wcfNode-' . $nodeIdentifier);
+               if ($this->outputType === 'text/html' || $this->outputType === 'text/simplified-html') {
+                       /** @var \DOMElement $element */
+                       foreach ($elements as $element) {
+                               // parse color
+                               if (preg_match('~^woltlab-size-(?P<size>[0-9]{1,2})$~', $element->getAttribute('class'), $matches)) {
+                                       $nodeIdentifier = StringUtil::getRandomID();
+                                       $htmlNodeProcessor->addNodeData($this, $nodeIdentifier, ['size' => $matches['size']]);
+                                       
+                                       $htmlNodeProcessor->renameTag($element, 'wcfNode-' . $nodeIdentifier);
+                               }
                        }
                }
        }
index 982172626cf3554dcc363b73cb6cd96cbcb6919a..2305900c0a56c30a270fc3e2f3406831108f4921 100644 (file)
@@ -1,8 +1,8 @@
 <?php
 namespace wcf\system\html\output\node;
-use wcf\system\html\node\AbstractHtmlNode;
 use wcf\system\html\node\AbstractHtmlNodeProcessor;
 use wcf\system\WCF;
+use wcf\util\DOMUtil;
 use wcf\util\StringUtil;
 
 /**
@@ -14,7 +14,7 @@ use wcf\util\StringUtil;
  * @package     WoltLabSuite\Core\System\Html\Output\Node
  * @since       3.0
  */
-class HtmlOutputNodeWoltlabSpoiler extends AbstractHtmlNode {
+class HtmlOutputNodeWoltlabSpoiler extends AbstractHtmlOutputNode {
        /**
         * @inheritDoc
         */
@@ -24,14 +24,20 @@ class HtmlOutputNodeWoltlabSpoiler extends AbstractHtmlNode {
         * @inheritDoc
         */
        public function process(array $elements, AbstractHtmlNodeProcessor $htmlNodeProcessor) {
-               /** @var \DOMElement $element */
-               foreach ($elements as $element) {
-                       $nodeIdentifier = StringUtil::getRandomID();
-                       $htmlNodeProcessor->addNodeData($this, $nodeIdentifier, [
-                               'label' => ($element->hasAttribute('data-label')) ? $element->getAttribute('data-label') : ''
-                       ]);
-                       
-                       $htmlNodeProcessor->renameTag($element, 'wcfNode-' . $nodeIdentifier);
+               if ($this->outputType === 'text/html' || $this->outputType === 'text/simplified-html') {
+                       /** @var \DOMElement $element */
+                       foreach ($elements as $element) {
+                               $nodeIdentifier = StringUtil::getRandomID();
+                               $htmlNodeProcessor->addNodeData($this, $nodeIdentifier, ['label' => $element->getAttribute('data-label')]);
+                               
+                               $htmlNodeProcessor->renameTag($element, 'wcfNode-' . $nodeIdentifier);
+                       }
+               }
+               else if ($this->outputType === 'text/plain') {
+                       /** @var \DOMElement $element */
+                       foreach ($elements as $element) {
+                               DOMUtil::removeNode($element);
+                       }
                }
        }
        
index 1dd8700bdd318d0fccefc845b9b1ec8450d68dd9..c92a06eba46bf675268d0496d92fbe33d9b1b343 100644 (file)
@@ -11,4 +11,11 @@ use wcf\system\html\node\IHtmlNode;
  * @package     WoltLabSuite\Core\System\Html\Output\Node
  * @since       3.0
  */
-interface IHtmlOutputNode extends IHtmlNode {}
+interface IHtmlOutputNode extends IHtmlNode {
+       /**
+        * Sets the desired output type.
+        * 
+        * @param       string          $outputType     desired output type
+        */
+       public function setOutputType($outputType);
+}
index 149e34483f36d33c100868f8c02c188d3379a495..c255353badee35a000288e0bbff65e38464ded67 100644 (file)
@@ -176,6 +176,23 @@ final class DOMUtil {
                throw new \RuntimeException("Unable to determine relative node position.");
        }
        
+       /**
+        * Returns true if there is at least one parent with the provided tag name.
+        * 
+        * @param       \DOMElement     $element        start element
+        * @param       string          $tagName        tag name to match
+        * @return      boolean         true if there is at least one parent with the provided tag name
+        */
+       public static function hasParent(\DOMElement $element, $tagName) {
+               while ($element = $element->parentNode) {
+                       if ($element->nodeName === $tagName) {
+                               return true;
+                       }
+               }
+               
+               return false;
+       }
+       
        /**
         * Inserts given DOM node after the reference node.
         * 
index 59b5a38a82abdc4460a90ab4fc925fb5c5e19e6c..a031972b7e0f2c3ffd48be3ee8ac4c96be5cb0e1 100644 (file)
@@ -1826,11 +1826,11 @@ Erlaubte Dateiendungen: {', '|implode:$attachmentHandler->getFormattedAllowedExt
                <item name="wcf.bbcode.code.php.title"><![CDATA[PHP]]></item>
                <item name="wcf.bbcode.code.plain.title"><![CDATA[Code]]></item>
                <item name="wcf.bbcode.code.sql.title"><![CDATA[SQL]]></item>
-               <item name="wcf.bbcode.code.text"><![CDATA[{@$highlighterTitle} ({#$lines} Zeile{if $lines != 1}n{/if})]]></item>
                <item name="wcf.bbcode.code.python.title"><![CDATA[Python]]></item>
                <item name="wcf.bbcode.code.tex.title"><![CDATA[TeX]]></item>
                <item name="wcf.bbcode.code.tpl.title"><![CDATA[Smarty]]></item>
                <item name="wcf.bbcode.code.xml.title"><![CDATA[XML]]></item>
+               <item name="wcf.bbcode.code.simplified"><![CDATA[(Quelltext, {#$lines} Zeile{if $lines != 1}n{/if})]]></item>
                <item name="wcf.bbcode.image.source"><![CDATA[Bild-Link]]></item>
                <item name="wcf.bbcode.quote.delete"><![CDATA[Zitat löschen]]></item>
                <item name="wcf.bbcode.quote.edit"><![CDATA[Zitat bearbeiten]]></item>
@@ -1840,7 +1840,7 @@ Erlaubte Dateiendungen: {', '|implode:$attachmentHandler->getFormattedAllowedExt
                <item name="wcf.bbcode.quote.title"><![CDATA[{@$quoteAuthor} schrieb:]]></item>
                <item name="wcf.bbcode.quote.title.clickToSet"><![CDATA[(Klicken um eine Quelle anzugeben)]]></item>
                <item name="wcf.bbcode.quote.title.javascript"><![CDATA[{literal}{$quoteAuthor} schrieb:{/literal}]]></item>
-               <item name="wcf.bbcode.quote.text"><![CDATA[Zitat{if $cite} von {@$cite}{/if}: „{@$content}“]]></item>
+               <item name="wcf.bbcode.quote.simplified"><![CDATA[(Zitat{if $cite} von {$cite}{/if})]]></item>
                <item name="wcf.bbcode.spoiler.hide"><![CDATA[Spoiler ausblenden]]></item>
                <item name="wcf.bbcode.spoiler.show"><![CDATA[Spoiler anzeigen]]></item>
                <item name="wcf.bbcode.spoiler.text"><![CDATA[(Versteckter Text)]]></item>
index fa4131eb945ae048f5bde252d953be6764ba7a8f..c78b025e76d35bc7372dd244dabc4c2aae4d66ea 100644 (file)
@@ -1835,9 +1835,9 @@ Allowed extensions: {', '|implode:$attachmentHandler->getFormattedAllowedExtensi
                <item name="wcf.bbcode.code.python.title"><![CDATA[Python]]></item>
                <item name="wcf.bbcode.code.sql.title"><![CDATA[SQL]]></item>
                <item name="wcf.bbcode.code.tex.title"><![CDATA[TeX]]></item>
-               <item name="wcf.bbcode.code.text"><![CDATA[{@$highlighterTitle} ({#$lines} line{if $lines != 1}s{/if})]]></item>
                <item name="wcf.bbcode.code.tpl.title"><![CDATA[Smarty]]></item>
                <item name="wcf.bbcode.code.xml.title"><![CDATA[XML]]></item>
+               <item name="wcf.bbcode.code.simplified"><![CDATA[(Code, {#$lines} line{if $lines != 1}s{/if})]]></item>
                <item name="wcf.bbcode.image.source"><![CDATA[Image Link]]></item>
                <item name="wcf.bbcode.quote.delete"><![CDATA[Delete Quote]]></item>
                <item name="wcf.bbcode.quote.edit"><![CDATA[Edit Quote]]></item>
@@ -1847,7 +1847,7 @@ Allowed extensions: {', '|implode:$attachmentHandler->getFormattedAllowedExtensi
                <item name="wcf.bbcode.quote.title"><![CDATA[{@$quoteAuthor} wrote:]]></item>
                <item name="wcf.bbcode.quote.title.clickToSet"><![CDATA[(Click to set source)]]></item>
                <item name="wcf.bbcode.quote.title.javascript"><![CDATA[{literal}{$quoteAuthor} wrote:{/literal}]]></item>
-               <item name="wcf.bbcode.quote.text"><![CDATA[Quote{if $cite} from {@$cite}{/if}: “{@$content}”]]></item>
+               <item name="wcf.bbcode.quote.simplified"><![CDATA[(Quote{if $cite} from {$cite}{/if})]]></item>
                <item name="wcf.bbcode.spoiler.hide"><![CDATA[Hide Spoiler]]></item>
                <item name="wcf.bbcode.spoiler.show"><![CDATA[Display Spoiler]]></item>
                <item name="wcf.bbcode.spoiler.text"><![CDATA[(Hidden Content)]]></item>