mirror of
https://github.com/phpbb/phpbb.git
synced 2025-05-05 23:25:30 +02:00
First-pass syntax highlightning. Will fix quotes later
git-svn-id: file:///svn/phpbb/trunk@3901 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
parent
2abf7dc744
commit
5107b7aafa
@ -70,7 +70,6 @@ class bbcode
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (count($str['search']))
|
||||
{
|
||||
$message = str_replace($str['search'], $str['replace'], $message);
|
||||
@ -307,38 +306,11 @@ class bbcode
|
||||
|
||||
function bbcode_second_pass_code($type, $code)
|
||||
{
|
||||
$code = stripslashes(str_replace("\r\n", "\n", $code));
|
||||
$code = stripslashes($code);
|
||||
|
||||
switch ($type)
|
||||
{
|
||||
case 'php':
|
||||
$str_from = array('<', '>', '"', ':', '[', ']', '(', ')', '{', '}', '.', '@');
|
||||
$str_to = array('<', '>', '"', ':', '[', ']', '(', ')', '{', '}', '.', '@');
|
||||
|
||||
$code = str_replace($str_to, $str_from, $code);
|
||||
|
||||
$remove_tags = FALSE;
|
||||
if (!preg_match('/\<\?.*?\?\>/is', $code))
|
||||
{
|
||||
$remove_tags = TRUE;
|
||||
$code = "<?php $code ?>";
|
||||
}
|
||||
|
||||
ob_start();
|
||||
highlight_string($code);
|
||||
$code = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
if ($remove_tags)
|
||||
{
|
||||
$code = preg_replace('!^<code>[\n\r\s\t]*<font color="#[a-z0-9]+">[\n\r\s\t]*(<font color="#[a-z0-9]+">)<\?php (.*)\?></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);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$code = str_replace("\t", ' ', $code);
|
||||
$code = str_replace(' ', ' ', $code);
|
||||
|
@ -101,6 +101,7 @@ function decode_text(&$message, $bbcode_uid)
|
||||
'#<!\-\- w \-\-><a href="http:\/\/(.*?)" target="_blank">.*?</a><!\-\- w \-\->#',
|
||||
'#<!\-\- l \-\-><a href="(.*?)" target="_blank">.*?</a><!\-\- l \-\->#',
|
||||
'#<!\-\- s(.*?) \-\-><img src="\{SMILE_PATH\}\/.*? \/><!\-\- s\1 \-\->#',
|
||||
'#<.*?>#s'
|
||||
);
|
||||
|
||||
$replace = array(
|
||||
@ -109,6 +110,7 @@ function decode_text(&$message, $bbcode_uid)
|
||||
'\1',
|
||||
$server_protocol . trim($config['server_name']) . $server_port . preg_replace('/^\/?(.*?)(\/)?$/', '\1', trim($config['script_path'])) . '/\1',
|
||||
'\1',
|
||||
''
|
||||
);
|
||||
|
||||
if (empty($censors))
|
||||
@ -118,6 +120,7 @@ function decode_text(&$message, $bbcode_uid)
|
||||
}
|
||||
|
||||
$message = str_replace(":$bbcode_uid", '', $message);
|
||||
$message = str_replace('<br />', "\n", $message);
|
||||
$message = preg_replace($match, $replace, $message);
|
||||
|
||||
return;
|
||||
|
@ -215,47 +215,73 @@ class parse_message
|
||||
}
|
||||
|
||||
// Expects the argument to start right after the opening [code] tag and to end with [/code]
|
||||
function bbcode_code($type, $in)
|
||||
function bbcode_code($stx, $in)
|
||||
{
|
||||
$str_from = array('<', '>', '"', ':', '[', ']', '(', ')', '{', '}', '.', '@');
|
||||
$str_to = array('<', '>', '"', ':', '[', ']', '(', ')', '{', '}', '.', '@');
|
||||
|
||||
// if I remember correctly, preg_replace() will slash passed vars
|
||||
$in = stripslashes($in);
|
||||
$in = str_replace("\r\n", "\n", stripslashes($in));
|
||||
$out = '';
|
||||
|
||||
do
|
||||
{
|
||||
$pos = stripos($in, '[/code]') + 7;
|
||||
$buffer = substr($in, 0, $pos);
|
||||
$code = substr($in, 0, $pos);
|
||||
$in = substr($in, $pos);
|
||||
|
||||
// $buffer contains everything that was between code tags (including the ending tag) but we're trying to grab as much extra text as possible, as long as it does not contain open [code] tags
|
||||
// $code contains everything that was between code tags (including the ending tag) but we're trying to grab as much extra text as possible, as long as it does not contain open [code] tags
|
||||
while ($in)
|
||||
{
|
||||
$pos = stripos($in, '[/code]') + 7;
|
||||
$sub_buffer = substr($in, 0, $pos);
|
||||
$buffer = substr($in, 0, $pos);
|
||||
|
||||
if (preg_match('#\[code(?:=([a-z]+))?\]#i', $sub_buffer))
|
||||
if (preg_match('#\[code(?:=([a-z]+))?\]#i', $buffer))
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
$in = substr($in, $pos);
|
||||
$buffer .= $sub_buffer;
|
||||
$code .= $buffer;
|
||||
}
|
||||
}
|
||||
|
||||
$buffer = substr($buffer, 0, -7);
|
||||
switch ($type)
|
||||
$code = substr($code, 0, -7);
|
||||
$code = preg_replace('#^[\r\n]*(.*?)[\n\r\s\t]*$#s', '\1', $code);
|
||||
|
||||
switch (strtolower($stx))
|
||||
{
|
||||
case 'php':
|
||||
$out .= '[code=php:' . $this->bbcode_uid . ']' . str_replace($str_from, $str_to, $buffer) . '[/code:' . $this->bbcode_uid . ']';
|
||||
$remove_tags = FALSE;
|
||||
if (!preg_match('/\<\?.*?\?\>/is', $code))
|
||||
{
|
||||
$remove_tags = TRUE;
|
||||
$code = "<?php $code ?>";
|
||||
}
|
||||
|
||||
ob_start();
|
||||
highlight_string($code);
|
||||
$code = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
if ($remove_tags)
|
||||
{
|
||||
$code = preg_replace('!^<code>[\n\r\s\t]*<font color="#[a-z0-9]+">[\n\r\s\t]*(<font color="#[a-z0-9]+">)<\?php (.*)\?></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);
|
||||
}
|
||||
|
||||
$str_from = array('[', ']', '.');
|
||||
$str_to = array('[', ']', '.');
|
||||
|
||||
$out .= "[code=$stx:" . $this->bbcode_uid . ']' . str_replace($str_from, $str_to, $code) . '[/code:' . $this->bbcode_uid . ']';
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
$out .= '[code:' . $this->bbcode_uid . ']' . str_replace($str_from, $str_to, $buffer) . '[/code:' . $this->bbcode_uid . ']';
|
||||
$str_from = array('<', '>', '[', ']', '.');
|
||||
$str_to = array('<', '>', '[', ']', '.');
|
||||
|
||||
$out .= '[code:' . $this->bbcode_uid . ']' . str_replace($str_from, $str_to, $code) . '[/code:' . $this->bbcode_uid . ']';
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user