Browse Source

Replaced un_preparsecode /e preg_replace with a callback.

Signed-off-by: Jeremy D <[email protected]>
Jeremy D 11 years ago
parent
commit
602835fb5d
1 changed files with 18 additions and 3 deletions
  1. 18 3
      Sources/Subs-Post.php

+ 18 - 3
Sources/Subs-Post.php

@@ -267,11 +267,11 @@ function un_preparsecode($message)
 		// If $i is a multiple of four (0, 4, 8, ...) then it's not a code section...
 		if ($i % 4 == 0)
 		{
-			$parts[$i] = preg_replace('~\[html\](.+?)\[/html\]~ie', '\'[html]\' . strtr(htmlspecialchars(\'$1\', ENT_QUOTES), array(\'\\&quot;\' => \'&quot;\', \'&amp;#13;\' => \'<br />\', \'&amp;#32;\' => \' \', \'&amp;#91;\' => \'[\', \'&amp;#93;\' => \']\')) . \'[/html]\'', $parts[$i]);
-			// $parts[$i] = preg_replace('~\[html\](.+?)\[/html\]~ie', '\'[html]\' . strtr(htmlspecialchars(\'$1\', ENT_QUOTES), array(\'\\&quot;\' => \'&quot;\', \'&amp;#13;\' => \'<br />\', \'&amp;#32;\' => \' \', \'&amp;#38;\' => \'&#38;\', \'&amp;#91;\' => \'[\', \'&amp;#93;\' => \']\')) . \'[/html]\'', $parts[$i]);
+			$parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~i', create_function('$m', 'return \'[html]\' . strtr(htmlspecialchars(\'$m[1]\', ENT_QUOTES), array(\'\\&quot;\' => \'&quot;\', \'&amp;#13;\' => \'<br />\', \'&amp;#32;\' => \' \', \'&amp;#91;\' => \'[\', \'&amp;#93;\' => \']\')) . \'[/html]\';
+'), $parts[$i]);
 
 			// Attempt to un-parse the time to something less awful.
-			$parts[$i] = preg_replace('~\[time\](\d{0,10})\[/time\]~ie', '\'[time]\' . timeformat(\'$1\', false) . \'[/time]\'', $parts[$i]);
+			$parts[$i] = preg_replace('~\[time\](\d{0,10})\[/time\]~i', create_function('$m', ' return \'[time]\' . timeformat(\'$m[1]\', false) . \'[/time]\';'), $parts[$i]);
 		}
 	}
 
@@ -279,6 +279,21 @@ function un_preparsecode($message)
 	return preg_replace('~<br( /)?' . '>~', "\n", str_replace('&nbsp;', ' ', implode('', $parts)));
 }
 
+function un_preparsecodeCallback($matches)
+{
+			return '[html]' .
+				strtr(
+					htmlspecialchars('$matches[1]', ENT_QUOTES),
+					array(
+						'\\&quot;' => '&quot;',
+						'&amp;#13;' => '<br />',
+						'&amp;#32;' => ' ',
+						'&amp;#91;' => '[',
+						'&amp;#93;' => ']'
+					)
+				) . '[/html]';
+}
+
 /**
  * Fix any URLs posted - ie. remove 'javascript:'.
  * Used by preparsecode, fixes links in message and returns nothing.