diff options
author | Meik Sievertsen <acydburn@phpbb.com> | 2007-01-05 11:21:09 +0000 |
---|---|---|
committer | Meik Sievertsen <acydburn@phpbb.com> | 2007-01-05 11:21:09 +0000 |
commit | 94b50f1797937c23bb400628dd51e09c6148c16d (patch) | |
tree | 0a1cbb0c590953eb32ad5ce982947c33196e4d32 /phpBB/search.php | |
parent | e86c24a4198a94d28af9455e43865874fe998eb2 (diff) | |
download | forums-94b50f1797937c23bb400628dd51e09c6148c16d.tar forums-94b50f1797937c23bb400628dd51e09c6148c16d.tar.gz forums-94b50f1797937c23bb400628dd51e09c6148c16d.tar.bz2 forums-94b50f1797937c23bb400628dd51e09c6148c16d.tar.xz forums-94b50f1797937c23bb400628dd51e09c6148c16d.zip |
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
Diffstat (limited to 'phpBB/search.php')
-rw-r--r-- | phpBB/search.php | 59 |
1 files changed, 34 insertions, 25 deletions
diff --git a/phpBB/search.php b/phpBB/search.php index 642b54b53e..681d47f0f1 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -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'] . ']', '⋅ ', $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'] . ']', '⋅ ', $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'] ); } |