Skip to content

Commit

Permalink
img tags inside code tags shouldnt be removed when quoting a post.
Browse files Browse the repository at this point in the history
  • Loading branch information
reines committed Oct 20, 2010
1 parent 24de589 commit 405d3dd
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 37 deletions.
36 changes: 36 additions & 0 deletions include/functions.php
Expand Up @@ -1794,6 +1794,42 @@ function forum_list_plugins($is_admin)
return $plugins;
}


//
// Split text into chunks ($inside contains all text inside $start and $end, and $outside contains all text outside)
//
function split_text($text, $start, $end, &$errors, $retab = true)
{
global $pun_config, $lang_common;

$tokens = explode($start, $text);

$outside[] = $tokens[0];

$num_tokens = count($tokens);
for ($i = 1; $i < $num_tokens; ++$i)
{
$temp = explode($end, $tokens[$i]);

if (count($temp) != 2)
{
$errors[] = $lang_common['BBCode code problem'];
return array(null, array($text));
}
$inside[] = $temp[0];
$outside[] = $temp[1];
}

if ($pun_config['o_indent_num_spaces'] != 8 && $retab)
{
$spaces = str_repeat(' ', $pun_config['o_indent_num_spaces']);
$inside = str_replace("\t", $spaces, $inside);
}

return array($inside, $outside);
}


// DEBUG FUNCTIONS BELOW

//
Expand Down
39 changes: 2 additions & 37 deletions include/parser.php
Expand Up @@ -100,15 +100,15 @@ function preparse_bbcode($text, &$errors, $is_signature = false)
$text = '';

$num_tokens = count($outside);

for ($i = 0; $i < $num_tokens; ++$i)
{
$text .= $outside[$i];
if (isset($inside[$i]))
$text .= '[code]'.$inside[$i].'[/code]';
}

unset($inside);
}
unset($inside);

$temp_text = false;
if (empty($errors))
Expand Down Expand Up @@ -609,41 +609,6 @@ function preparse_list_tag($content, $type = '*', &$errors)
}


//
// Split text into chunks ($inside contains all text inside $start and $end, and $outside contains all text outside)
//
function split_text($text, $start, $end, &$errors, $retab = true)
{
global $pun_config, $lang_common;

$tokens = explode($start, $text);

$outside[] = $tokens[0];

$num_tokens = count($tokens);
for ($i = 1; $i < $num_tokens; ++$i)
{
$temp = explode($end, $tokens[$i]);

if (count($temp) != 2)
{
$errors[] = $lang_common['BBCode code problem'];
return array(null, array($text));
}
$inside[] = $temp[0];
$outside[] = $temp[1];
}

if ($pun_config['o_indent_num_spaces'] != 8 && $retab)
{
$spaces = str_repeat(' ', $pun_config['o_indent_num_spaces']);
$inside = str_replace("\t", $spaces, $inside);
}

return array($inside, $outside);
}


//
// Truncate URL if longer than 55 characters (add http:// or ftp:// if missing)
//
Expand Down
28 changes: 28 additions & 0 deletions post.php
Expand Up @@ -417,9 +417,37 @@

list($q_poster, $q_message) = $db->fetch_row($result);

// If the message contains a code tag we have to split it up (text within [code][/code] shouldn't be touched)
if (strpos($q_message, '[code]') !== false && strpos($q_message, '[/code]') !== false)
{
$errors = array();
list($inside, $outside) = split_text($q_message, '[code]', '[/code]', $errors);
if (!empty($errors)) // Technically this shouldn't happen, since $q_message is an existing post it should only exist if it previously passed validation
message($errors[0]);

$q_message = implode("\1", $outside);
}

// Remove [img] tags from quoted message
$q_message = preg_replace('%\[img(?:=(?:[^\[]*?))?\]((ht|f)tps?://)([^\s<"]*?)\[/img\]%U', '\1\3', $q_message);

// If we split up the message before we have to concatenate it together again (code tags)
if (isset($inside))
{
$outside = explode("\1", $q_message);
$q_message = '';

$num_tokens = count($outside);
for ($i = 0; $i < $num_tokens; ++$i)
{
$q_message .= $outside[$i];
if (isset($inside[$i]))
$q_message .= '[code]'.$inside[$i].'[/code]';
}

unset($inside);
}

if ($pun_config['o_censoring'] == '1')
$q_message = censor_words($q_message);

Expand Down

0 comments on commit 405d3dd

Please sign in to comment.