Fix AbstractHtmlInputNodeProcessorListener::replaceLinksWithBBCode()
authorMatthias Schmidt <gravatronics@live.com>
Sun, 29 Jan 2017 13:17:59 +0000 (14:17 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 29 Jan 2017 13:18:02 +0000 (14:18 +0100)
… if multiple links are replaced

wcfsetup/install/files/lib/system/event/listener/AbstractHtmlInputNodeProcessorListener.class.php

index 9f0cec5e3aa38596a0d6243b78ba93b03dc34055..ad93c7f1cb15390885082d8afc64e7e7134f6cf2 100644 (file)
@@ -61,6 +61,7 @@ abstract class AbstractHtmlInputNodeProcessorListener implements IParameterizedE
         * @param       string                          $bbcodeName
         */
        protected function replaceLinksWithBBCode(HtmlInputNodeProcessor $processor, Regex $regex, array $objects, $bbcodeName) {
+               $elements = [];
                foreach ($processor->getDocument()->getElementsByTagName('a') as $element) {
                        /** @var \DOMElement $element */
                        if ($element->getAttribute('href') === $element->textContent) {
@@ -68,15 +69,22 @@ abstract class AbstractHtmlInputNodeProcessorListener implements IParameterizedE
                                        $objectID = $regex->getMatches()[2][0];
                                        
                                        if (isset($objects[$objectID])) {
-                                               $metacodeElement = $processor->getDocument()->createElement('woltlab-metacode');
-                                               $metacodeElement->setAttribute('data-name', $bbcodeName);
-                                               $metacodeElement->setAttribute('data-attributes', base64_encode(JSON::encode([$objectID])));
-                                               
-                                               DOMUtil::replaceElement($element, $metacodeElement, false);
+                                               $elements[] = [
+                                                       'element' => $element,
+                                                       'objectID' => $objectID
+                                               ];
                                        }
                                }
                        }
                }
+               
+               foreach ($elements as $elementData) {
+                       $metacodeElement = $processor->getDocument()->createElement('woltlab-metacode');
+                       $metacodeElement->setAttribute('data-name', $bbcodeName);
+                       $metacodeElement->setAttribute('data-attributes', base64_encode(JSON::encode([$elementData['objectID']])));
+                       
+                       DOMUtil::replaceElement($elementData['element'], $metacodeElement, false);
+               }
        }
        
        /**