From: Marcel Werk Date: Wed, 2 Jul 2014 13:34:59 +0000 (+0200) Subject: Improved removing of code tags X-Git-Tag: 2.1.0_Alpha_1~635 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=3a98c3a2cc2faa67c4df8974d1ee34ebf2a389e5;p=GitHub%2FWoltLab%2FWCF.git Improved removing of code tags --- diff --git a/wcfsetup/install/files/lib/system/bbcode/BBCodeParser.class.php b/wcfsetup/install/files/lib/system/bbcode/BBCodeParser.class.php index 007af12a12..004ace6591 100644 --- a/wcfsetup/install/files/lib/system/bbcode/BBCodeParser.class.php +++ b/wcfsetup/install/files/lib/system/bbcode/BBCodeParser.class.php @@ -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; + } } diff --git a/wcfsetup/install/files/lib/system/bbcode/MessageParser.class.php b/wcfsetup/install/files/lib/system/bbcode/MessageParser.class.php index b6debe85cb..b2ac2e7c26 100644 --- a/wcfsetup/install/files/lib/system/bbcode/MessageParser.class.php +++ b/wcfsetup/install/files/lib/system/bbcode/MessageParser.class.php @@ -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(); diff --git a/wcfsetup/install/files/lib/system/message/embedded/object/MessageEmbeddedObjectManager.class.php b/wcfsetup/install/files/lib/system/message/embedded/object/MessageEmbeddedObjectManager.class.php index ad81560582..2e47869a8b 100644 --- a/wcfsetup/install/files/lib/system/message/embedded/object/MessageEmbeddedObjectManager.class.php +++ b/wcfsetup/install/files/lib/system/message/embedded/object/MessageEmbeddedObjectManager.class.php @@ -1,6 +1,7 @@ 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