1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-06 07:35:29 +02:00

fix message length calculation for parsing bbcodes as well as saving some bytes of memory. ;)

git-svn-id: file:///svn/phpbb/trunk@6841 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Meik Sievertsen 2007-01-05 11:21:09 +00:00
parent e86c24a419
commit 94b50f1797

View File

@ -453,7 +453,6 @@ if ($keywords || $author || $author_id || $search_id || $submit)
}
// define some vars for urls
// @todo preg_replace still needed?
$hilit = htmlspecialchars(implode('|', explode(' ', preg_replace('#\s+#u', ' ', str_replace(array('+', '-', '|', '(', ')'), ' ', $keywords)))));
$u_hilit = urlencode($keywords);
$u_show_results = ($show_results != 'posts') ? '&sr=' . $show_results : '';
@ -498,9 +497,7 @@ if ($keywords || $author || $author_id || $search_id || $submit)
{
if ($show_results == 'posts')
{
/**
* @todo Joining this query to the one below?
*/
// @todo Joining this query to the one below?
$sql = 'SELECT zebra_id, friend, foe
FROM ' . ZEBRA_TABLE . '
WHERE user_id = ' . $user->data['user_id'];
@ -628,14 +625,26 @@ if ($keywords || $author || $author_id || $search_id || $submit)
}
else
{
$bbcode_bitfield = '';
$bbcode_bitfield = $text_only_message = '';
$attach_list = array();
while ($row = $db->sql_fetchrow($result))
{
$rowset[] = $row;
if (($return_chars == -1) || (utf8_strlen($row['post_text']) < $return_chars + 3))
// We pre-process some variables here for later usage
$row['post_text'] = censor_text($row['post_text']);
$text_only_message = $row['post_text'];
// make list items visible as such
if ($row['bbcode_uid'])
{
$text_only_message = str_replace('[*:' . $row['bbcode_uid'] . ']', '&sdot;&nbsp;', $text_only_message);
// no BBCode in text only message
strip_bbcode($text_only_message, $row['bbcode_uid']);
}
if ($return_chars == -1 || utf8_strlen($text_only_message) < ($return_chars + 3))
{
$row['display_text_only'] = false;
$bbcode_bitfield = $bbcode_bitfield | base64_decode($row['bbcode_bitfield']);
// Does this post have an attachment? If so, add it to the list
@ -644,9 +653,18 @@ if ($keywords || $author || $author_id || $search_id || $submit)
$attach_list[$row['forum_id']][] = $row['post_id'];
}
}
else
{
$row['post_text'] = $text_only_message;
$row['display_text_only'] = true;
}
$rowset[] = $row;
}
$db->sql_freeresult($result);
unset($text_only_message);
// Instantiate BBCode if needed
if ($bbcode_bitfield !== '')
{
@ -802,48 +820,39 @@ if ($keywords || $author || $author_id || $search_id || $submit)
// Replace naughty words such as farty pants
$row['post_subject'] = censor_text($row['post_subject']);
$message = censor_text($row['post_text']);
$text_only_message = $message;
// make list items visible as such
$text_only_message = str_replace('[*:' . $row['bbcode_uid'] . ']', '&sdot;&nbsp;', $message);
// no BBCode in text only message
strip_bbcode($text_only_message, $row['bbcode_uid']);
if ($return_chars != -1 && utf8_strlen($text_only_message) >= ($return_chars + 3))
if ($row['display_text_only'])
{
// now find context for the searched words
$message = get_context($text_only_message, array_filter(explode('|', $hilit), 'strlen'), $return_chars);
$message = str_replace("\n", '<br />', $message);
$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']);
}
else
{
$message = str_replace("\n", '<br />', $message);
$row['post_text'] = str_replace("\n", '<br />', $row['post_text']);
// Second parse bbcode here
if ($row['bbcode_bitfield'])
{
$bbcode->bbcode_second_pass($message, $row['bbcode_uid'], $row['bbcode_bitfield']);
$bbcode->bbcode_second_pass($row['post_text'], $row['bbcode_uid'], $row['bbcode_bitfield']);
}
if (!empty($attachments[$row['post_id']]))
{
parse_attachments($forum_id, $message, $attachments[$row['post_id']], $update_count);
parse_attachments($forum_id, $row['post_text'], $attachments[$row['post_id']], $update_count);
// we only display inline attachments
unset($attachments[$row['post_id']]);
}
// Always process smilies after parsing bbcodes
$message = smiley_text($message);
$row['post_text'] = smiley_text($row['post_text']);
}
unset($text_only_message);
if ($hilit)
{
// post highlighting
$message = preg_replace('#(?!<.*)(?<!\w)(' . $hilit . ')(?!\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">$1</span>', $message);
$row['post_text'] = preg_replace('#(?!<.*)(?<!\w)(' . $hilit . ')(?!\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">$1</span>', $row['post_text']);
}
$tpl_ary = array(
@ -854,7 +863,7 @@ if ($keywords || $author || $author_id || $search_id || $submit)
'POST_SUBJECT' => $row['post_subject'],
'POST_DATE' => (!empty($row['post_time'])) ? $user->format_date($row['post_time']) : '',
'MESSAGE' => $message
'MESSAGE' => $row['post_text']
);
}