diff options
author | Nils Adermann <naderman@naderman.de> | 2006-08-28 17:20:21 +0000 |
---|---|---|
committer | Nils Adermann <naderman@naderman.de> | 2006-08-28 17:20:21 +0000 |
commit | c0a880b6652d330b760b7da7cdde8076f854d836 (patch) | |
tree | e83ab0835afa5660ff8f582535a25c2a1c1f0f69 | |
parent | 1d37b69ddd79d9d6bc1346f3761a899d20305636 (diff) | |
download | forums-c0a880b6652d330b760b7da7cdde8076f854d836.tar forums-c0a880b6652d330b760b7da7cdde8076f854d836.tar.gz forums-c0a880b6652d330b760b7da7cdde8076f854d836.tar.bz2 forums-c0a880b6652d330b760b7da7cdde8076f854d836.tar.xz forums-c0a880b6652d330b760b7da7cdde8076f854d836.zip |
- birthdays/age in user's timezone and not server's local time
- parse bbcode in posts with fewer characters than selected maximum on search results page
- retrieve search word context in posts which are longer than maximum characters (no raw BBCode anymore)
- formatted text is processed in the same order everywhere now: censor_text, replace newlines, bbcode, smileys, attachments, highlighting [including Bug #2048]
- highlighting pattern updated to exclude style and script (e.g custom BBCode) [Bug #3856]
- fixed a style problem in Opera [Bug #3770]
- performance increase for user::img()
- slight adjustments to search
git-svn-id: file:///svn/phpbb/trunk@6321 89ea8834-ac86-4346-8a33-228a782c2dd0
-rw-r--r-- | phpBB/adm/style/admin.css | 2 | ||||
-rw-r--r-- | phpBB/includes/functions.php | 143 | ||||
-rw-r--r-- | phpBB/includes/functions_posting.php | 5 | ||||
-rw-r--r-- | phpBB/includes/mcp/mcp_post.php | 2 | ||||
-rw-r--r-- | phpBB/includes/mcp/mcp_queue.php | 1 | ||||
-rwxr-xr-x | phpBB/includes/mcp/mcp_reports.php | 1 | ||||
-rw-r--r-- | phpBB/includes/mcp/mcp_topic.php | 2 | ||||
-rwxr-xr-x | phpBB/includes/mcp/mcp_warn.php | 4 | ||||
-rwxr-xr-x | phpBB/includes/search/fulltext_native.php | 21 | ||||
-rw-r--r-- | phpBB/includes/session.php | 22 | ||||
-rw-r--r-- | phpBB/includes/ucp/ucp_pm_viewmessage.php | 12 | ||||
-rw-r--r-- | phpBB/index.php | 2 | ||||
-rw-r--r-- | phpBB/language/en/search.php | 2 | ||||
-rw-r--r-- | phpBB/memberlist.php | 28 | ||||
-rw-r--r-- | phpBB/search.php | 94 | ||||
-rw-r--r-- | phpBB/viewtopic.php | 19 |
16 files changed, 291 insertions, 69 deletions
diff --git a/phpBB/adm/style/admin.css b/phpBB/adm/style/admin.css index da00033931..0073581ab7 100644 --- a/phpBB/adm/style/admin.css +++ b/phpBB/adm/style/admin.css @@ -258,7 +258,7 @@ span.corners-top span, span.corners-bottom span { border-top: 1px solid #FFFFFF; } -#menu li a:hover span, #menu li#activemenu span { +#menu li a:hover span, #menu li#activemenu span, #menu li a:hover { text-decoration: none; background-color: #FFA34F; color: #FFFFFF; diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 4227a8a9a3..02f1553c43 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2015,6 +2015,117 @@ function bump_topic_allowed($forum_id, $topic_bumped, $last_post_time, $topic_po } /** +* Generates a text with approx. the specified length which contains the specified words and their context +* +* @param string $text The full text from which context shall be extracted +* @param string $words An array of words which should be contained in the result, * is allowed as a wildcard +* @param int $length The desired length of the resulting text, however the result might be shorter or longer than this value +* +* @return string Context of the specified words seperated by "..." +*/ +function get_context($text, $words, $length = 400) +{ + // first replace all whitespaces with single spaces + $text = preg_replace('/\s+/', ' ', $text); + + $word_indizes = array(); + if (sizeof($words)) + { + $match = ''; + // find the starting indizes of all words + foreach ($words as $word) + { + if (preg_match('#(?: |^)(' . str_replace('\*', '\w*?', preg_quote($word, '#')) . ')(?: |$)#i', $text, $match)) + { + $pos = strpos($text, $match[1]); + if ($pos !== false) + { + $word_indizes[] = $pos; + } + } + } + unset($match); + + if (sizeof($word_indizes)) + { + $word_indizes = array_unique($word_indizes); + sort($word_indizes); + + $wordnum = sizeof($word_indizes); + // number of characters on the right and left side of each word + $sequence_length = (int) ($length / (2 * $wordnum)) - 2; + $final_text = ''; + $word = $j = 0; + $final_text_index = -1; + + // cycle through every character in the original text + for ($i = $word_indizes[$word], $n = strlen($text); $i < $n; $i++) + { + // if the current position is the start of one of the words then append $sequence_length characters to the final text + if (isset($word_indizes[$word]) && ($i == $word_indizes[$word])) + { + if ($final_text_index < $i - $sequence_length - 1) + { + $final_text .= '... ' . preg_replace('#^([^ ]*)#', '', substr($text, $i - $sequence_length, $sequence_length)); + } + else + { + // if the final text is already nearer to the current word than $sequence_length we only append the text + // from its current index on and distribute the unused length to all other sequenes + $sequence_length += (int) (($final_text_index - $i + $sequence_length + 1) / (2 * $wordnum)); + $final_text .= substr($text, $final_text_index + 1, $i - $final_text_index - 1); + } + $final_text_index = $i - 1; + + // add the following characters to the final text (see below) + $word++; + $j = 1; + } + + if ($j > 0) + { + // add the character to the final text and increment the sequence counter + $final_text .= $text[$i]; + $final_text_index++; + $j++; + + // if this is a whitespace then check whether we are done with this sequence + if ($text[$i] == ' ') + { + // only check whether we have to exit the context generation completely if we haven't already reached the end anyway + if ($i + 4 < $n) + { + if (($j > $sequence_length && $word >= $wordnum) || strlen($final_text) > $length) + { + $final_text .= ' ...'; + break; + } + } + else + { + // make sure the text really reaches the end + $j -= 4; + } + + // stop context generation and wait for the next word + if ($j > $sequence_length) + { + $j = 0; + } + } + } + } + return $final_text; + } + } + + if (!sizeof($words) || !sizeof($word_indizes)) + { + return (strlen($text) >= $length + 3) ? substr($text, 0, $length) . '...' : $text; + } +} + +/** * Decode text whereby text is coming from the db and expected to be pre-parsed content * We are placing this outside of the message parser because we are often in need of it... */ @@ -2053,6 +2164,33 @@ function decode_message(&$message, $bbcode_uid = '') } /** +* Strips all bbcode from a text and returns the plain content +*/ +function strip_bbcode(&$text, $uid = '') +{ + if (!$uid) + { + $uid = '[0-9a-z]{5,}'; + } + + $text = preg_replace("#\[\/?[a-z0-9\*\+\-]+(?:=.*?)?(?::[a-z])?(\:?$uid)\]#", ' ', $text); + + $match = array( + '#<!\-\- e \-\-><a href="mailto:(.*?)">.*?</a><!\-\- e \-\->#', + '#<!\-\- m \-\-><a href="(.*?)" target="_blank">.*?</a><!\-\- m \-\->#', + '#<!\-\- w \-\-><a href="http:\/\/(.*?)" target="_blank">.*?</a><!\-\- w \-\->#', + '#<!\-\- l \-\-><a href="(.*?)">.*?</a><!\-\- l \-\->#', + '#<!\-\- s(.*?) \-\-><img src="\{SMILIES_PATH\}\/.*? \/><!\-\- s\1 \-\->#', + '#<!\-\- .*? \-\->#s', + '#<.*?>#s' + ); + + $replace = array('\1', '\1', '\1', '\1', '\1', '', ''); + + $text = preg_replace($match, $replace, $text); +} + +/** * For display of custom parsed text on user-facing pages * Expects $text to be the value directly from the database (stored value) */ @@ -2065,6 +2203,8 @@ function generate_text_for_display($text, $uid, $bitfield, $flags) return ''; } + $text = str_replace("\n", '<br />', censor_text($text)); + // Parse bbcode if bbcode uid stored and bbcode enabled if ($uid && ($flags & 1)) { @@ -2074,7 +2214,7 @@ function generate_text_for_display($text, $uid, $bitfield, $flags) include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx); } - if (empty($__bbcode)) + if (empty($bbcode)) { $bbcode = new bbcode($bitfield); } @@ -2087,7 +2227,6 @@ function generate_text_for_display($text, $uid, $bitfield, $flags) } $text = smiley_text($text, !($flags & 2)); - $text = str_replace("\n", '<br />', censor_text($text)); return $text; } diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 2ac732746e..a8c7078057 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -873,6 +873,8 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id $post_subject = $row['post_subject']; $message = $row['post_text']; + $message = censor_text($message); + $message = str_replace("\n", '<br />', $message); $decoded_message = false; if ($show_quote_button && $auth->acl_get('f_reply', $forum_id)) @@ -892,14 +894,13 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id $message = smiley_text($message, !$row['enable_smilies']); $post_subject = censor_text($post_subject); - $message = censor_text($message); $template->assign_block_vars($mode . '_row', array( 'POSTER_NAME' => $poster, 'POST_SUBJECT' => $post_subject, 'MINI_POST_IMG' => $user->img('icon_post_target', $user->lang['POST']), 'POST_DATE' => $user->format_date($row['post_time']), - 'MESSAGE' => str_replace("\n", '<br />', $message), + 'MESSAGE' => $message, 'DECODED_MESSAGE' => $decoded_message, 'U_POST_ID' => $row['post_id'], diff --git a/phpBB/includes/mcp/mcp_post.php b/phpBB/includes/mcp/mcp_post.php index 08bcc713f8..9cb3ec278b 100644 --- a/phpBB/includes/mcp/mcp_post.php +++ b/phpBB/includes/mcp/mcp_post.php @@ -95,6 +95,7 @@ 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); @@ -102,7 +103,6 @@ function mcp_post_details($id, $mode, $action) $bbcode->bbcode_second_pass($message, $post_info['bbcode_uid'], $post_info['bbcode_bitfield']); } $message = smiley_text($message); - $message = str_replace("\n", '<br />', $message); $template->assign_vars(array( 'U_MCP_ACTION' => "$url&i=main&quickmod=1", // Use this for mode paramaters diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 95e89fa9dc..3deeff6d1f 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -109,6 +109,7 @@ 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); diff --git a/phpBB/includes/mcp/mcp_reports.php b/phpBB/includes/mcp/mcp_reports.php index a52bc02359..67af086292 100755 --- a/phpBB/includes/mcp/mcp_reports.php +++ b/phpBB/includes/mcp/mcp_reports.php @@ -117,6 +117,7 @@ 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); diff --git a/phpBB/includes/mcp/mcp_topic.php b/phpBB/includes/mcp/mcp_topic.php index 7f1bc2a0c4..466459415d 100644 --- a/phpBB/includes/mcp/mcp_topic.php +++ b/phpBB/includes/mcp/mcp_topic.php @@ -110,6 +110,7 @@ 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']) { @@ -117,7 +118,6 @@ function mcp_topic_view($id, $mode, $action) } $message = smiley_text($message); - $message = str_replace("\n", '<br />', $message); if (!$row['post_approved']) { diff --git a/phpBB/includes/mcp/mcp_warn.php b/phpBB/includes/mcp/mcp_warn.php index bc428570ab..9a6ae1ab8f 100755 --- a/phpBB/includes/mcp/mcp_warn.php +++ b/phpBB/includes/mcp/mcp_warn.php @@ -247,6 +247,7 @@ function mcp_warn_post_view($id, $mode, $action) // We want to make the message available here as a reminder // Parse the message and subject $message = $userrow['post_text']; + $message = str_replace("\n", '<br />', censor_text($message)); // Second parse bbcode here if ($userrow['bbcode_bitfield']) @@ -260,9 +261,6 @@ function mcp_warn_post_view($id, $mode, $action) // Always process smilies after parsing bbcodes $message = smiley_text($message); - // Replace naughty words such as farty pants - $message = str_replace("\n", '<br />', censor_text($message)); - // Generate the appropriate user information for the user we are looking at $rank_title = $rank_img = ''; // get_user_rank($userrow['user_rank'], $userrow['user_posts'], $rank_title, $rank_img); diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php index e4ff1f8fc2..90da8abcd1 100755 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/includes/search/fulltext_native.php @@ -119,6 +119,15 @@ class fulltext_native extends search_backend // remove some useless bracket combinations which might be created by the previous regexps $keywords = str_replace(array('()', ')|('), array('', '|'), $keywords); + $keywords = preg_replace_callback( + '#\((?:(?:[^)]*?) )*?[^)]*?\)#', + create_function( + '$matches', + 'return str_replace(" ", "|", $matches[0]);' + ), + $keywords + ); + // $keywords input format: each word seperated by a space, words in a bracket are not seperated // the user wants to search for any word, convert the search query @@ -187,7 +196,7 @@ class fulltext_native extends search_backend // a group of which at least one may not be in the resulting posts if ($word[0] == '(') { - $word = explode('|', substr($word, 1, -1)); + $word = array_unique(explode('|', substr($word, 1, -1))); $mode = 'must_exclude_one'; } // one word which should not be in the resulting posts @@ -209,7 +218,7 @@ class fulltext_native extends search_backend // a group of words of which at least one word should be in every resulting post if ($word[0] == '(') { - $word = explode('|', substr($word, 1, -1)); + $word = array_unique(explode('|', substr($word, 1, -1))); } $ignore_no_id = false; $mode = 'must_contain'; @@ -880,7 +889,7 @@ class fulltext_native extends search_backend // Do not index code $match[] = '#\[code(?:=.*?)?(\:?[0-9a-z]{5,})\].*?\[\/code(\:?[0-9a-z]{5,})\]#is'; // BBcode - $match[] = '#\[\/?[a-z\*\+\-]+(?:=.*?)?(\:?[0-9a-z]{5,})\]#'; + $match[] = '#\[\/?[a-z0-9\*\+\-]+(?:=.*?)?(?::[a-z])?(\:?[0-9a-z]{5,})\]#'; $min = $config['fulltext_native_min_chars']; $max = $config['fulltext_native_max_chars']; @@ -890,7 +899,7 @@ class fulltext_native extends search_backend /** * Clean up the string, remove HTML tags, remove BBCodes */ - $word = strtok($this->cleanup(preg_replace($match, ' ', strip_tags($text)), '', $user->lang['ENCODING']), ' '); + $word = strtok($this->cleanup(preg_replace($match, ' ', strip_tags($text)), -1, $user->lang['ENCODING']), ' '); while (isset($word[0])) { @@ -1146,14 +1155,14 @@ class fulltext_native extends search_backend $destroy_cache_words = array(); - // Remove common (> 60% of posts ) words + // Remove common (> 20% of posts ) words if ($config['num_posts'] >= 100) { // First, get the IDs of common words $sql = 'SELECT word_id FROM ' . SEARCH_WORDMATCH_TABLE . ' GROUP BY word_id - HAVING COUNT(word_id) > ' . floor($config['num_posts'] * 0.6); + HAVING COUNT(word_id) > ' . floor($config['num_posts'] * 0.2); $result = $db->sql_query($sql); $sql_in = array(); diff --git a/phpBB/includes/session.php b/phpBB/includes/session.php index 0e934edb8a..5441f7e556 100644 --- a/phpBB/includes/session.php +++ b/phpBB/includes/session.php @@ -1340,13 +1340,15 @@ class user extends session static $imgs; global $phpbb_root_path; - if (empty($imgs[$img . $suffix]) || $width !== false) + $img_data = $imgs[$img . $suffix]; + + if (empty($img_data) || $width !== false) { if (!isset($this->theme[$img]) || !$this->theme[$img]) { // Do not fill the image to let designers decide what to do if the image is empty - $imgs[$img . $suffix] = ''; - return $imgs[$img . $suffix]; + $img_data = ''; + return $img_data; } // Do not include dimensions? @@ -1372,9 +1374,9 @@ class user extends session $imgsrc = str_replace('{SUFFIX}', $suffix, $imgsrc); } - $imgs[$img . $suffix]['src'] = $phpbb_root_path . 'styles/' . $this->theme['imageset_path'] . '/imageset/' . str_replace('{LANG}', $this->img_lang, $imgsrc); - $imgs[$img . $suffix]['width'] = $width; - $imgs[$img . $suffix]['height'] = $height; + $img_data['src'] = $phpbb_root_path . 'styles/' . $this->theme['imageset_path'] . '/imageset/' . str_replace('{LANG}', $this->img_lang, $imgsrc); + $img_data['width'] = $width; + $img_data['height'] = $height; } $alt = (!empty($this->lang[$alt])) ? $this->lang[$alt] : $alt; @@ -1382,19 +1384,19 @@ class user extends session switch ($type) { case 'src': - return $imgs[$img . $suffix]['src']; + return $img_data['src']; break; case 'width': - return $imgs[$img . $suffix]['width']; + return $img_data['width']; break; case 'height': - return $imgs[$img . $suffix]['height']; + return $img_data['height']; break; default: - return '<img src="' . $imgs[$img . $suffix]['src'] . '"' . (($imgs[$img . $suffix]['width']) ? ' width="' . $imgs[$img . $suffix]['width'] . '"' : '') . (($imgs[$img . $suffix]['height']) ? ' height="' . $imgs[$img . $suffix]['height'] . '"' : '') . ' alt="' . $alt . '" title="' . $alt . '" />'; + return '<img src="' . $img_data['src'] . '"' . (($img_data['width']) ? ' width="' . $img_data['width'] . '"' : '') . (($img_data['height']) ? ' height="' . $img_data['height'] . '"' : '') . ' alt="' . $alt . '" title="' . $alt . '" />'; break; } } diff --git a/phpBB/includes/ucp/ucp_pm_viewmessage.php b/phpBB/includes/ucp/ucp_pm_viewmessage.php index f0fa234944..3ffc19df55 100644 --- a/phpBB/includes/ucp/ucp_pm_viewmessage.php +++ b/phpBB/includes/ucp/ucp_pm_viewmessage.php @@ -54,6 +54,7 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row) // Parse the message and subject $message = $message_row['message_text']; + $message = str_replace("\n", '<br />', censor_text($message)); // Second parse bbcode here if ($message_row['bbcode_bitfield']) @@ -66,7 +67,6 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row) // Replace naughty words such as farty pants $message_row['message_subject'] = censor_text($message_row['message_subject']); - $message = str_replace("\n", '<br />', censor_text($message)); // Editing information if ($message_row['message_edit_count'] && $config['display_last_edited']) @@ -146,6 +146,9 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row) // End signature parsing, only if needed if ($signature) { + $signature = censor_text($signature); + $signature = str_replace("\n", '<br />', censor_text($signature)); + if ($user_info['user_sig_bbcode_bitfield']) { if ($bbcode === false) @@ -158,7 +161,6 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row) } $signature = smiley_text($signature); - $signature = str_replace("\n", '<br />', censor_text($signature)); } $url = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm'); @@ -318,6 +320,9 @@ function message_history($msg_id, $user_id, $message_row, $folder) $subject = $row['message_subject']; $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']); @@ -326,7 +331,6 @@ function message_history($msg_id, $user_id, $message_row, $folder) $message = smiley_text($message, !$row['enable_smilies']); $subject = censor_text($subject); - $message = censor_text($message); if ($id == $msg_id) { @@ -339,7 +343,7 @@ function message_history($msg_id, $user_id, $message_row, $folder) 'AUTHOR_NAME' => $author, 'SUBJECT' => $subject, 'SENT_DATE' => $user->format_date($row['message_time']), - 'MESSAGE' => str_replace("\n", '<br />', $message), + 'MESSAGE' => $message, 'FOLDER' => implode(', ', $row['folder']), 'S_CURRENT_MSG' => ($row['msg_id'] == $msg_id), diff --git a/phpBB/index.php b/phpBB/index.php index d1655267e4..23f29e6f37 100644 --- a/phpBB/index.php +++ b/phpBB/index.php @@ -54,7 +54,7 @@ $db->sql_freeresult($result); $birthday_list = ''; if ($config['load_birthdays']) { - $now = getdate(); + $now = getdate(time() + $this->timezone + $this->dst); $sql = 'SELECT user_id, username, user_colour, user_birthday FROM ' . USERS_TABLE . " WHERE user_birthday LIKE '" . $db->sql_escape(sprintf('%2d-%2d-', $now['mday'], $now['mon'])) . "%' diff --git a/phpBB/language/en/search.php b/phpBB/language/en/search.php index 25d0000bb8..569c40a53d 100644 --- a/phpBB/language/en/search.php +++ b/phpBB/language/en/search.php @@ -38,7 +38,7 @@ $lang = array_merge($lang, array( 'FOUND_SEARCH_MATCHES' => 'Search found %d matches', 'FOUND_MORE_SEARCH_MATCHES' => 'Search found more than %d matches', - 'GLOBAL' => 'Global topic', + 'GLOBAL' => 'Global announcement', 'IGNORED_TERMS' => 'ignored', 'IGNORED_TERMS_EXPLAIN' => 'The following words in your search query were ignored: <b>%s</b>', diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index 218365c95f..fdb6e3adf2 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -396,16 +396,20 @@ switch ($mode) $posts_per_day = $member['user_posts'] / $memberdays; $percentage = ($config['num_posts']) ? min(100, ($member['user_posts'] / $config['num_posts']) * 100) : 0; - if ($member['user_sig_bbcode_bitfield'] && $member['user_sig']) - { - include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx); - $bbcode = new bbcode(); - $bbcode->bbcode_second_pass($member['user_sig'], $member['user_sig_bbcode_uid'], $member['user_sig_bbcode_bitfield']); - } if ($member['user_sig']) { - $member['user_sig'] = censor_text(smiley_text($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']) + { + include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx); + $bbcode = new bbcode(); + $bbcode->bbcode_second_pass($member['user_sig'], $member['user_sig_bbcode_uid'], $member['user_sig_bbcode_bitfield']); + } + + $member['user_sig'] = smiley_text($member['user_sig']); } $poster_avatar = ''; @@ -459,7 +463,7 @@ switch ($mode) 'OCCUPATION' => (!empty($member['user_occ'])) ? censor_text($member['user_occ']) : '', 'INTERESTS' => (!empty($member['user_interests'])) ? censor_text($member['user_interests']) : '', - 'SIGNATURE' => (!empty($member['user_sig'])) ? str_replace("\n", '<br />', $member['user_sig']) : '', + 'SIGNATURE' => $member['user_sig'], 'AVATAR_IMG' => $poster_avatar, 'PM_IMG' => $user->img('icon_contact_pm', $user->lang['SEND_PRIVATE_MESSAGE']), @@ -1329,19 +1333,19 @@ function show_profile($data) if ($bday_year) { - $time = time() + $user->timezone + $user->dst; + $now = getdate(time() + $user->timezone + $user->dst); - $diff = date('n', $time) - $bday_month; + $diff = $now['mon'] - $bday_month; if ($diff == 0) { - $diff = (date('j', $time) - $bday_day < 0) ? 1 : 0; + $diff = ($now['mday'] - $bday_day < 0) ? 1 : 0; } else { $diff = ($diff < 0) ? 1 : 0; } - $age = (int) (date('Y', $time) - $bday_year - $diff); + $age = (int) ($now['year'] - $bday_year - $diff); } } diff --git a/phpBB/search.php b/phpBB/search.php index 6fa500d761..e949cf3ce4 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -47,11 +47,6 @@ $sort_dir = request_var('sd', 'd'); $return_chars = request_var('ch', ($topic_id) ? -1 : 200); $search_forum = request_var('fid', array(0)); -if ($search_forum == array(0)) -{ - $search_forum = array(); -} - // Is user able to search? Has search been disabled? if (!$auth->acl_get('u_search') || !$auth->acl_getf_global('f_search') || !$config['load_search']) { @@ -609,11 +604,55 @@ if ($keywords || $author || $author_id || $search_id || $submit) } else { + $bbcode_bitfield = ''; + $attach_list = array(); + while ($row = $db->sql_fetchrow($result)) { $rowset[] = $row; + if (($return_chars == -1) || (strlen($row['post_text']) < $return_chars + 3)) + { + $bbcode_bitfield = $bbcode_bitfield | base64_decode($row['bbcode_bitfield']); + + // Does this post have an attachment? If so, add it to the list + if ($row['post_attachment'] && $config['allow_attachments']) + { + $attach_list[] = $row['post_id']; + } + } } $db->sql_freeresult($result); + + // Instantiate BBCode if needed + if ($bbcode_bitfield !== '') + { + include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx); + $bbcode = new bbcode(base64_encode($bbcode_bitfield)); + } + + // Pull attachment data + if (sizeof($attach_list)) + { + if ($auth->acl_gets('f_download', 'u_download', $forum_id)) + { + $sql = 'SELECT * + FROM ' . ATTACHMENTS_TABLE . ' + WHERE ' . $db->sql_in_set('post_msg_id', $attach_list) . ' + AND in_message = 0 + ORDER BY filetime ' . ((!$config['display_order']) ? 'DESC' : 'ASC') . ', post_msg_id ASC'; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $attachments[$row['post_msg_id']][] = $row; + } + $db->sql_freeresult($result); + } + else + { + $display_notice = true; + } + } } if ($hilit) @@ -727,28 +766,53 @@ if ($keywords || $author || $author_id || $search_id || $submit) continue; } - decode_message($row['post_text'], $row['bbcode_uid']); + // Replace naughty words such as farty pants + $row['post_subject'] = censor_text($row['post_subject']); + $message = $row['post_text']; + - if ($return_chars != -1) + if (($return_chars != -1) && (strlen($message) >= $return_chars + 3)) { - $row['post_text'] = (strlen($row['post_text']) < $return_chars + 3) ? $row['post_text'] : substr($row['post_text'], 0, $return_chars) . '...'; + $message = censor_text($message); + strip_bbcode($message, $row['bbcode_uid']); + + // now find context for the searched words + $message = get_context($message, array_filter(explode('|', $hilit), 'strlen'), $return_chars); + + $message = str_replace("\n", '<br />', $message); } + else + { + $message = censor_text($message); + $message = str_replace("\n", '<br />', $message); - // Replace naughty words such as farty pants - $row['post_subject'] = censor_text($row['post_subject']); - $row['post_text'] = str_replace("\n", '<br />', censor_text($row['post_text'])); + // Second parse bbcode here + if ($row['bbcode_bitfield']) + { + $bbcode->bbcode_second_pass($message, $row['bbcode_uid'], $row['bbcode_bitfield']); + } - // post highlighting - $row['post_text'] = preg_replace('#(?!<.*)(?<!\w)(' . $hilit . ')(?!\w|[^<>]*>)#i', '<span class="posthilit">$1</span>', $row['post_text']); + if (isset($attachments[$row['post_id']]) && sizeof($attachments[$row['post_id']])) + { + parse_inline_attachments($message, $attachments[$row['post_id']], $update_count, $forum_id); + + // we only display inline attachments + unset($attachments[$row['post_id']]); + } - $row['post_text'] = smiley_text($row['post_text']); + // Always process smilies after parsing bbcodes + $message = smiley_text($message); + } + + // post highlighting + $message = preg_replace('#(?!(?:<(?:s(?:cript|tyle))?)[^<]*)(?<!\w)(' . $hilit . ')(?!\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">$1</span>', $message); $tpl_ary = array( 'POSTER_NAME' => ($row['poster_id'] == ANONYMOUS) ? ((!empty($row['post_username'])) ? $row['post_username'] : $user->lang['GUEST']) : $row['username'], 'U_PROFILE' => ($row['poster_id'] != ANONYMOUS) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&u=' . $row['poster_id']) : '', 'POST_SUBJECT' => $row['post_subject'], 'POST_DATE' => (!empty($row['post_time'])) ? $user->format_date($row['post_time']) : '', - 'MESSAGE' => $row['post_text'] + 'MESSAGE' => $message ); } diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index f05030493c..6390b72876 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -717,6 +717,7 @@ 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) { @@ -724,17 +725,16 @@ if (!empty($topic_data['poll_start'])) } $poll_info[$i]['poll_option_text'] = smiley_text($poll_info[$i]['poll_option_text']); - $poll_info[$i]['poll_option_text'] = str_replace("\n", '<br />', $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'] = smiley_text($topic_data['poll_title']); - $topic_data['poll_title'] = str_replace("\n", '<br />', $topic_data['poll_title']); unset($poll_bbcode); @@ -862,8 +862,7 @@ $sql = $db->sql_build_query('SELECT', array( $result = $db->sql_query($sql); -$today = explode('-', date('j-n-Y', time() + $user->timezone + $user->dst)); -$today = array('day' => (int) $today[0], 'month' => (int) $today[1], 'year' => (int) $today[2]); +$now = getdate(time() + $user->timezone + $user->dst); // Posts are stored in the $rowset array while $attach_list, $user_cache // and the global bbcode_bitfield are built @@ -1087,17 +1086,17 @@ while ($row = $db->sql_fetchrow($result)) if ($bday_year) { - $diff = $today['month'] - $bday_month; + $diff = $now['mon'] - $bday_month; if ($diff == 0) { - $diff = ($today['day'] - $bday_day < 0) ? 1 : 0; + $diff = ($now['mday'] - $bday_day < 0) ? 1 : 0; } else { $diff = ($diff < 0) ? 1 : 0; } - $user_cache[$poster_id]['age'] = (int) ($today['year'] - $bday_year - $diff); + $user_cache[$poster_id]['age'] = (int) ($now['year'] - $bday_year - $diff); } } } @@ -1248,6 +1247,7 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i) if ($user_cache[$poster_id]['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']) { @@ -1255,12 +1255,12 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i) } $user_cache[$poster_id]['sig'] = smiley_text($user_cache[$poster_id]['sig']); - $user_cache[$poster_id]['sig'] = str_replace("\n", '<br />', $user_cache[$poster_id]['sig']); $user_cache[$poster_id]['sig_parsed'] = true; } // Parse the message and subject $message = censor_text($row['post_text']); + $message = str_replace("\n", '<br />', $message); // Second parse bbcode here if ($row['bbcode_bitfield']) @@ -1285,12 +1285,11 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i) // Highlight active words (primarily for search) if ($highlight_match) { - $message = preg_replace('#(?!<.*)(?<!\w)(' . $highlight_match . ')(?!\w|[^<>]*>)#i', '<span class="posthilit">\1</span>', $message); + $message = preg_replace('#(?!(?:<(?:s(?:cript|tyle))?)[^<]*)(?<!\w)(' . $highlight_match . ')(?!\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">\1</span>', $message); } // Replace naughty words such as farty pants $row['post_subject'] = censor_text($row['post_subject']); - $message = str_replace("\n", '<br />', $message); // Editing information if (($row['post_edit_count'] && $config['display_last_edited']) || $row['post_edit_reason']) |