Improved removing of code tags
authorMarcel Werk <burntime@woltlab.com>
Wed, 2 Jul 2014 13:34:59 +0000 (15:34 +0200)
committerMarcel Werk <burntime@woltlab.com>
Wed, 2 Jul 2014 13:34:59 +0000 (15:34 +0200)
wcfsetup/install/files/lib/system/bbcode/BBCodeParser.class.php
wcfsetup/install/files/lib/system/bbcode/MessageParser.class.php
wcfsetup/install/files/lib/system/message/embedded/object/MessageEmbeddedObjectManager.class.php

index 007af12a126a036f1ea0cc77666f05657512a4f3..004ace659133870f212271c9ffe8a6f5638e06f7 100644 (file)
@@ -51,12 +51,25 @@ class BBCodeParser extends SingletonFactory {
         */
        protected $textArray = array();
        
+       /**
+        * regular expression for source code tags
+        * @var string
+        */
+       protected $sourceCodeRegEx = '';
+       
        /**
         * @see \wcf\system\SingletonFactory::init()
         */
        protected function init() {
                // get bbcodes
                $this->bbcodes = BBCodeCache::getInstance()->getBBCodes();
+               
+               // handle source codes
+               $sourceCodeTags = array();
+               foreach ($this->bbcodes as $bbcode) {
+                       if ($bbcode->isSourceCode) $sourceCodeTags[] = $bbcode->bbcodeTag;
+               }
+               if (!empty($sourceCodeTags)) $this->sourceCodeRegEx = implode('|', $sourceCodeTags);
        }
        
        /**
@@ -531,4 +544,24 @@ class BBCodeParser extends SingletonFactory {
                
                return $usedDisallowedBBCodes;
        }
+       
+       /**
+        * Removes code bbcode occurrences in given message.
+        *
+        * @param       string          $message
+        * @return      string
+        */
+       public function removeCodeTags($message) {
+               if (!empty($this->sourceCodeRegEx)) {
+                       return preg_replace("~(\[(?:".$this->sourceCodeRegEx.")
+                               (?:=
+                                       (?:\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|[^,\]]*)
+                                       (?:,(?:\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|[^,\]]*))*
+                               )?\])
+                               (.*?)
+                               (?:\[/code\])~six", '', $message);
+               }
+               
+               return $message;
+       }
 }
index b6debe85cb5858023c6159d53722596c92a6ac92..b2ac2e7c26700bc8eff741d4c73bc3503a56abfa 100644 (file)
@@ -28,12 +28,6 @@ class MessageParser extends BBCodeParser {
         */
        protected $cachedCodes = array();
        
-       /**
-        * regular expression for source code tags
-        * @var string
-        */
-       protected $sourceCodeRegEx = '';
-       
        /**
         * currently parsed message
         * @var string
@@ -46,13 +40,6 @@ class MessageParser extends BBCodeParser {
        protected function init() {
                parent::init();
                
-               // handle source codes
-               $sourceCodeTags = array();
-               foreach ($this->bbcodes as $bbcode) {
-                       if ($bbcode->isSourceCode) $sourceCodeTags[] = $bbcode->bbcodeTag;
-               }
-               if (!empty($sourceCodeTags)) $this->sourceCodeRegEx = implode('|', $sourceCodeTags);
-               
                if (MODULE_SMILEY == 1) {
                        // get smilies
                        $smilies = SmileyCache::getInstance()->getSmilies();
index ad81560582db23d863be1d0349541e99798aceb3..2e47869a8b9bcc0f5f9f158bb1228f98e6593e61 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 namespace wcf\system\message\embedded\object;
 use wcf\data\object\type\ObjectTypeCache;
+use wcf\system\bbcode\BBCodeParser;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
 use wcf\system\SingletonFactory;
 use wcf\system\WCF;
@@ -56,7 +57,7 @@ class MessageEmbeddedObjectManager extends SingletonFactory {
         */
        public function registerObjects($messageObjectType, $messageID, $message) {
                // remove [code] tags
-               $message = self::removeCodeTags($message);
+               $message = BBCodeParser::getInstance()->removeCodeTags($message);
                
                // delete existing assignments
                $this->removeObjects($messageObjectType, array($messageID));
@@ -200,7 +201,7 @@ class MessageEmbeddedObjectManager extends SingletonFactory {
         */
        public function parseTemporaryMessage($message) {
                // remove [code] tags
-               $message = self::removeCodeTags($message);
+               $message = BBCodeParser::getInstance()->removeCodeTags($message);
                
                // set active message information
                $this->activeMessageObjectTypeID = -1;
@@ -246,20 +247,4 @@ class MessageEmbeddedObjectManager extends SingletonFactory {
                
                return $this->embeddedObjectHandlers[$objectTypeID];
        }
-       
-       /**
-        * Removes code bbcode occurrences in given message.
-        * 
-        * @param       string          $message
-        * @return      string
-        */
-       protected static function removeCodeTags($message) {
-               return preg_replace("~(\[code
-                       (?:=
-                               (?:\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|[^,\]]*)
-                               (?:,(?:\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|[^,\]]*))*
-                       )?\])
-                       (.*?)
-                       (?:\[/code\])~six", '', $message);
-       }
 }
\ No newline at end of file