More bbcode fixes

git-svn-id: file:///svn/phpbb/trunk@3879 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Ludovic Arnaud 2003-04-17 23:47:26 +00:00
parent a79524cb33
commit ff6fdd67be
3 changed files with 22 additions and 18 deletions

View file

@ -312,18 +312,18 @@ class bbcode
switch ($type) switch ($type)
{ {
case 'php': case 'php':
$remove_tags = FALSE;
if (!preg_match('/<\?(php)? .*? \?>/', $code))
{
$remove_tags = TRUE;
$code = "<?php $code ?>";
}
$str_from = array('<', '>', '"', ':', '[', ']', '(', ')', '{', '}', '.', '@'); $str_from = array('<', '>', '"', ':', '[', ']', '(', ')', '{', '}', '.', '@');
$str_to = array('&lt;', '&gt;', '&quot;', '&#58;', '&#91;', '&#93;', '&#40;', '&#41;', '&#123;', '&#125;', '&#46;', '&#64;'); $str_to = array('&lt;', '&gt;', '&quot;', '&#58;', '&#91;', '&#93;', '&#40;', '&#41;', '&#123;', '&#125;', '&#46;', '&#64;');
$code = str_replace($str_to, $str_from, $code); $code = str_replace($str_to, $str_from, $code);
$remove_tags = FALSE;
if (!preg_match('/\<\?.*?\?\>/is', $code))
{
$remove_tags = TRUE;
$code = "<?php $code ?>";
}
ob_start(); ob_start();
highlight_string($code); highlight_string($code);
$code = ob_get_contents(); $code = ob_get_contents();
@ -331,10 +331,12 @@ class bbcode
if ($remove_tags) if ($remove_tags)
{ {
$code = preg_replace('/(.*?)&lt;\?php&nbsp;(.*)\?&gt;(.*?)/', '\1\2\3', $code); $code = preg_replace('!^<code>[\n\r\s\t]*<font color="#[a-z0-9]+">[\n\r\s\t]*(<font color="#[a-z0-9]+">)&lt;\?php&nbsp;(.*)\?&gt;</font>[\n\r\s\t]*(</font>)[\n\r\s\t]*</code>[\n\r\s\t]*!is', '\1\2\3', $code);
}
else
{
$code = preg_replace('!^<code>[\n\r\s\t]*<font color="#[a-z0-9]+">[\n\r\s\t]*(.*)</font>[\n\r\s\t]*</code>[\n\r\s\t]*!is', '\1', $code);
} }
$code = preg_replace('!^<code>[\n\r\s\t]*<font color="#[a-z0-9]+">[\n\r\s\t]*(.*)</font>[\n\r\s\t]*</code>[\n\r\s\t]*!is', '\\1', $code);
break; break;
default: default:

View file

@ -174,11 +174,11 @@ class parse_message
// [quote] moved to the second position // [quote] moved to the second position
$this->bbcode_array = array( $this->bbcode_array = array(
8 => array('#\[code(?:=([a-z]+))?\](.+\[/code\])#ise' => "\$this->bbcode_code('\\1', '\\2')"), 8 => array('#\[code(?:=([a-z]+))?\](.+\[/code\])#ise' => "\$this->bbcode_code('\\1', '\\2')"),
0 => array('#\[quote(?:="(.*?)")?\](.+?)\[/quote\]#ise' => "'[quote:" . $this->bbcode_uid . "' . \$this->bbcode_quote_username('\\1') . ']\\2[/quote:" . $this->bbcode_uid . "]'"), 0 => array('#\[quote(?:="(.*?)")?\](.+?)\[/quote\]#ise'=> "'[quote:" . $this->bbcode_uid . "' . \$this->bbcode_quote_username('\\1') . ']\\2[/quote:" . $this->bbcode_uid . "]'"),
// TODO: validation regexp // TODO: validation regexp
11 => array('#\[flash\](.*?)\[/flash\]#i' => '[flash:' . $this->bbcode_uid . ']\1[/flash:' . $this->bbcode_uid . ']'), 11 => array('#\[flash\](.*?)\[/flash\]#i' => '[flash:' . $this->bbcode_uid . ']\1[/flash:' . $this->bbcode_uid . ']'),
10 => array('#\[email(=.*?)?\](.*?)\[/email\]#ise' => '$this->validate_email("\1", "\2")'), 10 => array('#\[email(=.*?)?\](.*?)\[/email\]#ise' => "\$this->validate_email('\\1', '\\2')"),
9 => array('#\[list(=[a-z|0-1]+)?\].*\[/list\]#ise' => '$this->bbcode_list("\0")'), 9 => array('#\[list(=[a-z|0-1]+)?\].*\[/list\]#ise' => "\$this->bbcode_list('\\0')"),
7 => array('#\[u\](.*?)\[/u\]#is' => '[u:' . $this->bbcode_uid . ']\1[/u:' . $this->bbcode_uid . ']'), 7 => array('#\[u\](.*?)\[/u\]#is' => '[u:' . $this->bbcode_uid . ']\1[/u:' . $this->bbcode_uid . ']'),
6 => array('!\[color=(#[0-9A-F]{6}|[a-z\-]+)\](.*?)\[/color\]!is' 6 => array('!\[color=(#[0-9A-F]{6}|[a-z\-]+)\](.*?)\[/color\]!is'
=> '[color=\1:' . $this->bbcode_uid . ']\2[/color:' . $this->bbcode_uid . ']'), => '[color=\1:' . $this->bbcode_uid . ']\2[/color:' . $this->bbcode_uid . ']'),
@ -186,7 +186,7 @@ class parse_message
=> '[size=\1:' . $this->bbcode_uid . ']\2[/size:' . $this->bbcode_uid . ']'), => '[size=\1:' . $this->bbcode_uid . ']\2[/size:' . $this->bbcode_uid . ']'),
4 => array('#\[img\](https?://)([a-z0-9\-\.,\?!%\*_:;~\\&$@/=\+]+)\[/img\]#i' 4 => array('#\[img\](https?://)([a-z0-9\-\.,\?!%\*_:;~\\&$@/=\+]+)\[/img\]#i'
=> '[img:' . $this->bbcode_uid . ']\1\2[/img:' . $this->bbcode_uid . ']'), => '[img:' . $this->bbcode_uid . ']\1\2[/img:' . $this->bbcode_uid . ']'),
3 => array('#\[url=?(.*?)?\](.*?)\[/url\]#ise' => '$this->validate_url("\1", "\2")'), 3 => array('#\[url=?(.*?)?\](.*?)\[/url\]#ise' => "\$this->validate_url('\\1', '\\2')"),
2 => array('#\[i\](.*?)\[/i\]#is' => '[i:' . $this->bbcode_uid . ']\1[/i:' . $this->bbcode_uid . ']'), 2 => array('#\[i\](.*?)\[/i\]#is' => '[i:' . $this->bbcode_uid . ']\1[/i:' . $this->bbcode_uid . ']'),
1 => array('#\[b\](.*?)\[/b\]#is' => '[b:' . $this->bbcode_uid . ']\1[/b:' . $this->bbcode_uid . ']') 1 => array('#\[b\](.*?)\[/b\]#is' => '[b:' . $this->bbcode_uid . ']\1[/b:' . $this->bbcode_uid . ']')
); );
@ -366,9 +366,9 @@ class parse_message
} }
if ($valid) if ($valid)
{ {
return (empty($var1)) ? '[url:' . $this->bbcode_uid . ']' . $url . '[/url:' . $this->bbcode_uid . ']' : "[url=$url:" . $this->bbcode_uid . ']' . $var2 . '[/url:' . $this->bbcode_uid . ']'; return (empty($var1)) ? '[url:' . $this->bbcode_uid . ']' . $url . '[/url:' . $this->bbcode_uid . ']' : "[url=$url:" . $this->bbcode_uid . ']' . stripslashes($var2) . '[/url:' . $this->bbcode_uid . ']';
} }
return '[url' . $var1 . ']' . $var2 . '[/url]'; return '[url' . $var1 . ']' . stripslashes($var2) . '[/url]';
} }
// Replace magic urls of form http://xxx.xxx., www.xxx. and xxx@xxx.xxx. // Replace magic urls of form http://xxx.xxx., www.xxx. and xxx@xxx.xxx.

View file

@ -699,10 +699,12 @@ if ($preview)
} }
// Decode text for message display // Decode text for message display
decode_text($post_text, $message_parser->bbcode_uid); $bbcode_uid = ($mode == 'quote' && !$preview) ? $row['bbcode_uid'] : $message_parser->bbcode_uid;
decode_text($post_text, $bbcode_uid);
if ($subject) if ($subject)
{ {
decode_text($subject, $message_parser->bbcode_uid); decode_text($subject, $bbcode_uid);
} }
// Save us some processing time. ;) // Save us some processing time. ;)