mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-27 21:58:52 +00: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:
parent
e86c24a419
commit
94b50f1797
1 changed files with 34 additions and 25 deletions
|
@ -453,7 +453,6 @@ if ($keywords || $author || $author_id || $search_id || $submit)
|
||||||
}
|
}
|
||||||
|
|
||||||
// define some vars for urls
|
// define some vars for urls
|
||||||
// @todo preg_replace still needed?
|
|
||||||
$hilit = htmlspecialchars(implode('|', explode(' ', preg_replace('#\s+#u', ' ', str_replace(array('+', '-', '|', '(', ')'), ' ', $keywords)))));
|
$hilit = htmlspecialchars(implode('|', explode(' ', preg_replace('#\s+#u', ' ', str_replace(array('+', '-', '|', '(', ')'), ' ', $keywords)))));
|
||||||
$u_hilit = urlencode($keywords);
|
$u_hilit = urlencode($keywords);
|
||||||
$u_show_results = ($show_results != 'posts') ? '&sr=' . $show_results : '';
|
$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')
|
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
|
$sql = 'SELECT zebra_id, friend, foe
|
||||||
FROM ' . ZEBRA_TABLE . '
|
FROM ' . ZEBRA_TABLE . '
|
||||||
WHERE user_id = ' . $user->data['user_id'];
|
WHERE user_id = ' . $user->data['user_id'];
|
||||||
|
@ -628,14 +625,26 @@ if ($keywords || $author || $author_id || $search_id || $submit)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$bbcode_bitfield = '';
|
$bbcode_bitfield = $text_only_message = '';
|
||||||
$attach_list = array();
|
$attach_list = array();
|
||||||
|
|
||||||
while ($row = $db->sql_fetchrow($result))
|
while ($row = $db->sql_fetchrow($result))
|
||||||
{
|
{
|
||||||
$rowset[] = $row;
|
// We pre-process some variables here for later usage
|
||||||
if (($return_chars == -1) || (utf8_strlen($row['post_text']) < $return_chars + 3))
|
$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'] . ']', '⋅ ', $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']);
|
$bbcode_bitfield = $bbcode_bitfield | base64_decode($row['bbcode_bitfield']);
|
||||||
|
|
||||||
// Does this post have an attachment? If so, add it to the list
|
// 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'];
|
$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);
|
$db->sql_freeresult($result);
|
||||||
|
|
||||||
|
unset($text_only_message);
|
||||||
|
|
||||||
// Instantiate BBCode if needed
|
// Instantiate BBCode if needed
|
||||||
if ($bbcode_bitfield !== '')
|
if ($bbcode_bitfield !== '')
|
||||||
{
|
{
|
||||||
|
@ -802,48 +820,39 @@ if ($keywords || $author || $author_id || $search_id || $submit)
|
||||||
|
|
||||||
// Replace naughty words such as farty pants
|
// Replace naughty words such as farty pants
|
||||||
$row['post_subject'] = censor_text($row['post_subject']);
|
$row['post_subject'] = censor_text($row['post_subject']);
|
||||||
$message = censor_text($row['post_text']);
|
|
||||||
|
|
||||||
$text_only_message = $message;
|
if ($row['display_text_only'])
|
||||||
// make list items visible as such
|
|
||||||
$text_only_message = str_replace('[*:' . $row['bbcode_uid'] . ']', '⋅ ', $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))
|
|
||||||
{
|
{
|
||||||
// now find context for the searched words
|
// now find context for the searched words
|
||||||
$message = get_context($text_only_message, array_filter(explode('|', $hilit), 'strlen'), $return_chars);
|
$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']);
|
||||||
$message = str_replace("\n", '<br />', $message);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$message = str_replace("\n", '<br />', $message);
|
$row['post_text'] = str_replace("\n", '<br />', $row['post_text']);
|
||||||
|
|
||||||
// Second parse bbcode here
|
// Second parse bbcode here
|
||||||
if ($row['bbcode_bitfield'])
|
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']]))
|
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
|
// we only display inline attachments
|
||||||
unset($attachments[$row['post_id']]);
|
unset($attachments[$row['post_id']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always process smilies after parsing bbcodes
|
// Always process smilies after parsing bbcodes
|
||||||
$message = smiley_text($message);
|
$row['post_text'] = smiley_text($row['post_text']);
|
||||||
}
|
}
|
||||||
unset($text_only_message);
|
|
||||||
|
|
||||||
if ($hilit)
|
if ($hilit)
|
||||||
{
|
{
|
||||||
// post highlighting
|
// 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(
|
$tpl_ary = array(
|
||||||
|
@ -854,7 +863,7 @@ if ($keywords || $author || $author_id || $search_id || $submit)
|
||||||
|
|
||||||
'POST_SUBJECT' => $row['post_subject'],
|
'POST_SUBJECT' => $row['post_subject'],
|
||||||
'POST_DATE' => (!empty($row['post_time'])) ? $user->format_date($row['post_time']) : '',
|
'POST_DATE' => (!empty($row['post_time'])) ? $user->format_date($row['post_time']) : '',
|
||||||
'MESSAGE' => $message
|
'MESSAGE' => $row['post_text']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue