1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-03 22:27:54 +02:00

- BBCode parsing order should ALWAYS be censor_text(), bbcode_secon_pass(), bbcode_nl2br(), smiley_text(), parse_attachments()

- using \r on custom bbcodes to allow line breaks [Bug #10758]


git-svn-id: file:///svn/phpbb/trunk@8050 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Nils Adermann 2007-08-19 13:40:53 +00:00
parent b8b85e5aca
commit d104d3d969
19 changed files with 57 additions and 45 deletions

View File

@ -228,6 +228,8 @@ p a {
<li>[Fix] Made sure strip_bbcode cannot get the idea that a smiley is a BBCode (Bug #14030)</li>
<li>[Change] Added a filter for user objects to LDAP configuration and improved explanations (Bug #12627)</li>
<li>[Fix] Display searchable subforums of invisible parents in advanced search forum selection (Bug #11395)</li>
<li>[Fix] Allow line breaks in custom BBCodes (Bug #10758)</li>
<li>[Fix] Ordered BBcode parsing functions in the same way everywhere where they are used</li>
</ul>
</div>

View File

@ -925,7 +925,7 @@ class acp_profile
$lang_options[1]['lang_iso'] = $this->lang_defs['id'][$default_lang_id];
$lang_options[1]['fields'][$field] = array(
'TITLE' => $user->lang['CP_' . strtoupper($field)],
'FIELD' => '<dd>' . ((is_array($cp->vars[$field])) ? implode('<br />', $cp->vars[$field]) : str_replace("\n", '<br />', $cp->vars[$field])) . '</dd>'
'FIELD' => '<dd>' . ((is_array($cp->vars[$field])) ? implode('<br />', $cp->vars[$field]) : bbcode_nl2br($cp->vars[$field])) . '</dd>'
);
if (isset($user->lang['CP_' . strtoupper($field) . '_EXPLAIN']))

View File

@ -156,10 +156,9 @@ class bbcode
while ($row = $db->sql_fetchrow($result))
{
// To circumvent replacing newlines with <br /> for the generated html,
// we just remove newlines here. We do not do this within the admin panel to
// let the admin lay out his html code nicely
$row['bbcode_tpl'] = str_replace(array("\n", "\r"), '', $row['bbcode_tpl']);
$row['second_pass_replace'] = str_replace(array("\n", "\r"), '', $row['second_pass_replace']);
// we use carriage returns here. They are later changed back to newlines
$row['bbcode_tpl'] = str_replace("\n", "\r", $row['bbcode_tpl']);
$row['second_pass_replace'] = str_replace("\n", "\r", $row['second_pass_replace']);
$rowset[$row['bbcode_id']] = $row;
}

View File

@ -2571,8 +2571,7 @@ function generate_text_for_display($text, $uid, $bitfield, $flags)
$bbcode->bbcode_second_pass($text, $uid);
}
$text = str_replace("\n", '<br />', $text);
$text = bbcode_nl2br($text);
$text = smiley_text($text, !($flags & OPTION_FLAG_SMILIES));
return $text;
@ -2813,6 +2812,17 @@ function censor_text($text)
return $text;
}
/**
* custom version of nl2br which takes custom BBCodes into account
*/
function bbcode_nl2br($text)
{
// custom BBCodes might contain carriage returns so they
// are not converted into <br /> so now revert that
$text = str_replace(array("\n", "\r"), array('<br />', "\n"), $text);
return $text;
}
/**
* Smiley processing
*/
@ -2955,7 +2965,7 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count,
$size_lang = ($filesize >= 1048576) ? $user->lang['MB'] : ( ($filesize >= 1024) ? $user->lang['KB'] : $user->lang['BYTES'] );
$filesize = ($filesize >= 1048576) ? round((round($filesize / 1048576 * 100) / 100), 2) : (($filesize >= 1024) ? round((round($filesize / 1024 * 100) / 100), 2) : $filesize);
$comment = str_replace("\n", '<br />', censor_text($attachment['attach_comment']));
$comment = bbcode_nl2br(censor_text($attachment['attach_comment']));
$block_array += array(
'UPLOAD_ICON' => $upload_icon,

View File

@ -2429,11 +2429,11 @@ function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id
// If within the admin panel we do not censor text out
if (defined('IN_ADMIN'))
{
$log[$i]['action'] = str_replace("\n", '<br />', $log[$i]['action']);
$log[$i]['action'] = bbcode_nl2br($log[$i]['action']);
}
else
{
$log[$i]['action'] = str_replace("\n", '<br />', censor_text($log[$i]['action']));
$log[$i]['action'] = bbcode_nl2br(censor_text($log[$i]['action']));
}
}
else

View File

@ -1021,8 +1021,7 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id
$decoded_message = $message;
decode_message($decoded_message, $row['bbcode_uid']);
$decoded_message = censor_text($decoded_message);
$decoded_message = str_replace("\n", "<br />", $decoded_message);
$decoded_message = bbcode_nl2br($decoded_message);
}
if ($row['bbcode_bitfield'])
@ -1030,8 +1029,7 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id
$bbcode->bbcode_second_pass($message, $row['bbcode_uid'], $row['bbcode_bitfield']);
}
$message = str_replace("\n", '<br />', $message);
$message = bbcode_nl2br($message);
$message = smiley_text($message, !$row['enable_smilies']);
if (!empty($attachments[$row['post_id']]))

View File

@ -1774,13 +1774,13 @@ function message_history($msg_id, $user_id, $message_row, $folder, $in_post_mode
$message = $row['message_text'];
$message = censor_text($message);
$message = str_replace("\n", '<br />', $message);
if ($row['bbcode_bitfield'])
{
$bbcode->bbcode_second_pass($message, $row['bbcode_uid'], $row['bbcode_bitfield']);
}
$message = bbcode_nl2br($message);
$message = smiley_text($message, !$row['enable_smilies']);
$subject = censor_text($subject);

View File

@ -176,7 +176,7 @@ class custom_profile
if (!empty($field_data['field_validation']) && $field_data['field_validation'] != '.*')
{
$field_validate = ($field_type == FIELD_STRING) ? $field_value : str_replace("\n", ' ', $field_value);
$field_validate = ($field_type == FIELD_STRING) ? $field_value : bbcode_nl2br($field_value);
if (!preg_match('#^' . str_replace('\\\\', '\\', $field_data['field_validation']) . '$#i', $field_validate))
{
return 'FIELD_INVALID_CHARS';
@ -462,7 +462,7 @@ class custom_profile
$value = make_clickable($value);
$value = censor_text($value);
$value = str_replace("\n", '<br />', $value);
$value = bbcode_nl2br($value);
return $value;
break;

View File

@ -112,13 +112,15 @@ function mcp_post_details($id, $mode, $action)
// Process message, leave it uncensored
$message = $post_info['post_text'];
$message = str_replace("\n", '<br />', $message);
if ($post_info['bbcode_bitfield'])
{
include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
$bbcode = new bbcode($post_info['bbcode_bitfield']);
$bbcode->bbcode_second_pass($message, $post_info['bbcode_uid'], $post_info['bbcode_bitfield']);
}
$message = bbcode_nl2br($message);
$message = smiley_text($message);
if ($post_info['post_attachment'] && $auth->acl_get('u_download') && $auth->acl_get('f_download', $post_info['forum_id']))
@ -261,7 +263,7 @@ function mcp_post_details($id, $mode, $action)
'U_REPORTER' => ($row['user_id'] != ANONYMOUS) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $row['user_id']) : '',
'USER_NOTIFY' => ($row['user_notify']) ? true : false,
'REPORT_TIME' => $user->format_date($row['report_time']),
'REPORT_TEXT' => str_replace("\n", '<br />', trim($row['report_text'])))
'REPORT_TEXT' => bbcode_nl2br(trim($row['report_text']))))
);
}
while ($row = $db->sql_fetchrow($result));

View File

@ -119,13 +119,15 @@ class mcp_queue
// Process message, leave it uncensored
$message = $post_info['post_text'];
$message = str_replace("\n", '<br />', $message);
if ($post_info['bbcode_bitfield'])
{
include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
$bbcode = new bbcode($post_info['bbcode_bitfield']);
$bbcode->bbcode_second_pass($message, $post_info['bbcode_uid'], $post_info['bbcode_bitfield']);
}
$message = bbcode_nl2br($message);
$message = smiley_text($message);
if ($post_info['post_attachment'] && $auth->acl_get('u_download') && $auth->acl_get('f_download', $post_info['forum_id']))

View File

@ -128,13 +128,15 @@ class mcp_reports
// Process message, leave it uncensored
$message = $post_info['post_text'];
$message = str_replace("\n", '<br />', $message);
if ($post_info['bbcode_bitfield'])
{
include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
$bbcode = new bbcode($post_info['bbcode_bitfield']);
$bbcode->bbcode_second_pass($message, $post_info['bbcode_uid'], $post_info['bbcode_bitfield']);
}
$message = bbcode_nl2br($message);
$message = smiley_text($message);
if ($post_info['post_attachment'] && $auth->acl_get('u_download') && $auth->acl_get('f_download', $post_info['forum_id']))

View File

@ -175,13 +175,13 @@ function mcp_topic_view($id, $mode, $action)
{
$message = $row['post_text'];
$post_subject = ($row['post_subject'] != '') ? $row['post_subject'] : $topic_info['topic_title'];
$message = str_replace("\n", '<br />', $message);
if ($row['bbcode_bitfield'])
{
$bbcode->bbcode_second_pass($message, $row['bbcode_uid'], $row['bbcode_bitfield']);
}
$message = bbcode_nl2br($message);
$message = smiley_text($message);
if (!empty($attachments[$row['post_id']]))

View File

@ -253,8 +253,7 @@ class mcp_warn
// We want to make the message available here as a reminder
// Parse the message and subject
$message = $user_row['post_text'];
$message = str_replace("\n", '<br />', censor_text($message));
$message = censor_text($user_row['post_text']);
// Second parse bbcode here
if ($user_row['bbcode_bitfield'])
@ -265,7 +264,7 @@ class mcp_warn
$bbcode->bbcode_second_pass($message, $user_row['bbcode_uid'], $user_row['bbcode_bitfield']);
}
// Always process smilies after parsing bbcodes
$message = bbcode_nl2br($message);
$message = smiley_text($message);
// Generate the appropriate user information for the user we are looking at

View File

@ -1138,6 +1138,9 @@ class parse_message extends bbcode_firstpass
$this->parse($allow_bbcode, $allow_magic_url, $allow_smilies, $this->allow_img_bbcode, $this->allow_flash_bbcode, $this->allow_quote_bbcode, $this->allow_url_bbcode, true);
}
// Replace naughty words such as farty pants
$this->message = censor_text($this->message);
// Parse BBcode
if ($allow_bbcode)
{
@ -1147,11 +1150,9 @@ class parse_message extends bbcode_firstpass
$this->bbcode_second_pass($this->message, $this->bbcode_uid);
}
$this->message = bbcode_nl2br($this->message);
$this->message = smiley_text($this->message, !$allow_smilies);
// Replace naughty words such as farty pants
$this->message = str_replace("\n", '<br />', censor_text($this->message));
if (!$update_this_message)
{
unset($this->message);

View File

@ -121,7 +121,7 @@ class ucp_attachments
$template->assign_block_vars('attachrow', array(
'ROW_NUMBER' => $row_count + ($start + 1),
'FILENAME' => $row['real_filename'],
'COMMENT' => str_replace("\n", '<br />', $row['attach_comment']),
'COMMENT' => bbcode_nl2br($row['attach_comment']),
'EXTENSION' => $row['extension'],
'SIZE' => ($row['filesize'] >= 1048576) ? ($row['filesize'] >> 20) . ' ' . $user->lang['MB'] : (($row['filesize'] >= 1024) ? ($row['filesize'] >> 10) . ' ' . $user->lang['KB'] : $row['filesize'] . ' ' . $user->lang['BYTES']),
'DOWNLOAD_COUNT' => $row['download_count'],

View File

@ -56,8 +56,7 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row)
$user_info = get_user_information($author_id, $message_row);
// Parse the message and subject
$message = $message_row['message_text'];
$message = str_replace("\n", '<br />', censor_text($message));
$message = censor_text($message_row['message_text']);
// Second parse bbcode here
if ($message_row['bbcode_bitfield'])
@ -66,6 +65,7 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row)
}
// Always process smilies after parsing bbcodes
$message = bbcode_nl2br($message);
$message = smiley_text($message);
// Replace naughty words such as farty pants
@ -142,7 +142,6 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row)
if ($signature)
{
$signature = censor_text($signature);
$signature = str_replace("\n", '<br />', censor_text($signature));
if ($user_info['user_sig_bbcode_bitfield'])
{
@ -155,6 +154,7 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row)
$bbcode->bbcode_second_pass($signature, $user_info['user_sig_bbcode_uid'], $user_info['user_sig_bbcode_bitfield']);
}
$signature = bbcode_nl2br($signature);
$signature = smiley_text($signature);
}

View File

@ -471,7 +471,6 @@ switch ($mode)
if ($member['user_sig'])
{
$member['user_sig'] = censor_text($member['user_sig']);
$member['user_sig'] = str_replace("\n", '<br />', $member['user_sig']);
if ($member['user_sig_bbcode_bitfield'])
{
@ -480,6 +479,7 @@ switch ($mode)
$bbcode->bbcode_second_pass($member['user_sig'], $member['user_sig_bbcode_uid'], $member['user_sig_bbcode_bitfield']);
}
$member['user_sig'] = bbcode_nl2br($member['user_sig']);
$member['user_sig'] = smiley_text($member['user_sig']);
}

View File

@ -838,18 +838,19 @@ if ($keywords || $author || $author_id || $search_id || $submit)
{
// now find context for the searched words
$row['post_text'] = get_context($row['post_text'], array_filter(explode('|', $hilit), 'strlen'), $return_chars);
$row['post_text'] = str_replace("\n", '<br />', $row['post_text']);
$row['post_text'] = bbcode_nl2br($row['post_text']);
}
else
{
$row['post_text'] = str_replace("\n", '<br />', $row['post_text']);
// Second parse bbcode here
if ($row['bbcode_bitfield'])
{
$bbcode->bbcode_second_pass($row['post_text'], $row['bbcode_uid'], $row['bbcode_bitfield']);
}
$row['post_text'] = bbcode_nl2br($row['post_text']);
$row['post_text'] = smiley_text($row['post_text']);
if (!empty($attachments[$row['post_id']]))
{
parse_attachments($forum_id, $row['post_text'], $attachments[$row['post_id']], $update_count);
@ -857,9 +858,6 @@ if ($keywords || $author || $author_id || $search_id || $submit)
// we only display inline attachments
unset($attachments[$row['post_id']]);
}
// Always process smilies after parsing bbcodes
$row['post_text'] = smiley_text($row['post_text']);
}
if ($hilit)

View File

@ -747,23 +747,24 @@ if (!empty($topic_data['poll_start']))
for ($i = 0, $size = sizeof($poll_info); $i < $size; $i++)
{
$poll_info[$i]['poll_option_text'] = censor_text($poll_info[$i]['poll_option_text']);
$poll_info[$i]['poll_option_text'] = str_replace("\n", '<br />', $poll_info[$i]['poll_option_text']);
if ($poll_bbcode !== false)
{
$poll_bbcode->bbcode_second_pass($poll_info[$i]['poll_option_text'], $poll_info[$i]['bbcode_uid'], $poll_option['bbcode_bitfield']);
}
$poll_info[$i]['poll_option_text'] = bbcode_nl2br($poll_info[$i]['poll_option_text']);
$poll_info[$i]['poll_option_text'] = smiley_text($poll_info[$i]['poll_option_text']);
}
$topic_data['poll_title'] = censor_text($topic_data['poll_title']);
$topic_data['poll_title'] = str_replace("\n", '<br />', $topic_data['poll_title']);
if ($poll_bbcode !== false)
{
$poll_bbcode->bbcode_second_pass($topic_data['poll_title'], $poll_info[0]['bbcode_uid'], $poll_info[0]['bbcode_bitfield']);
}
$topic_data['poll_title'] = bbcode_nl2br($topic_data['poll_title']);
$topic_data['poll_title'] = smiley_text($topic_data['poll_title']);
unset($poll_bbcode);
@ -1222,13 +1223,13 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i)
if ($user_cache[$poster_id]['sig'] && $row['enable_sig'] && empty($user_cache[$poster_id]['sig_parsed']))
{
$user_cache[$poster_id]['sig'] = censor_text($user_cache[$poster_id]['sig']);
$user_cache[$poster_id]['sig'] = str_replace("\n", '<br />', $user_cache[$poster_id]['sig']);
if ($user_cache[$poster_id]['sig_bbcode_bitfield'])
{
$bbcode->bbcode_second_pass($user_cache[$poster_id]['sig'], $user_cache[$poster_id]['sig_bbcode_uid'], $user_cache[$poster_id]['sig_bbcode_bitfield']);
}
$user_cache[$poster_id]['sig'] = bbcode_nl2br($user_cache[$poster_id]['sig']);
$user_cache[$poster_id]['sig'] = smiley_text($user_cache[$poster_id]['sig']);
$user_cache[$poster_id]['sig_parsed'] = true;
}
@ -1242,9 +1243,7 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i)
$bbcode->bbcode_second_pass($message, $row['bbcode_uid'], $row['bbcode_bitfield']);
}
$message = str_replace("\n", '<br />', $message);
// Always process smilies after parsing bbcodes
$message = bbcode_nl2br($message);
$message = smiley_text($message);
if (!empty($attachments[$row['post_id']]))