1 --- ./viewtopic.php.org Sun Dec 8 03:13:40 2002
2 +++ ./viewtopic.php Sun Dec 8 03:24:49 2002
4 // Was a highlight request part of the URI? Yes, this idea was
\r
5 // taken from vB but we did already have a highlighter in place
\r
6 // in search itself ... it's just been extended a bit!
\r
9 +$highlight_match = $highlight = '';
\r
10 if ( isset($HTTP_GET_VARS['highlight']) )
\r
12 - $highlight_match = array();
\r
15 // Split words and phrases
\r
17 - $words = explode(' ', trim(urldecode($HTTP_GET_VARS['highlight'])));
\r
18 + $words = explode(' ', trim(htmlspecialchars(urldecode($HTTP_GET_VARS['highlight']))));
\r
20 for($i = 0; $i < count($words); $i++)
\r
22 if ( trim($words[$i]) != '' )
\r
24 - $highlight_match[] = '#\b(' . str_replace("*", "([\w]+)?", $words[$i]) . ')\b#is';
\r
25 + $highlight_match .= (($highlight_match != '') ? '|' : '') . str_replace('*', '\w*', phpbb_preg_quote($words[$i], '#'));
\r
30 - $highlight_active = ( count($highlight_match) ) ? true : false;
\r
34 - $highlight_active = false;
\r
35 + $highlight = urlencode($HTTP_GET_VARS['highlight']);
\r
41 // If we've got a hightlight set pass it on to pagination,
\r
42 // I get annoyed when I lose my highlight after the first page.
\r
45 -$pagination = ( $highlight_active ) ? generate_pagination("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&postdays=$post_days&postorder=$post_order&highlight=" . $HTTP_GET_VARS['highlight'], $total_replies, $board_config['posts_per_page'], $start) : generate_pagination("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&postdays=$post_days&postorder=$post_order", $total_replies, $board_config['posts_per_page'], $start);
\r
46 +$pagination = ( $highlight_match ) ? generate_pagination("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&postdays=$post_days&postorder=$post_order&highlight=$highlight",$total_replies, $board_config['posts_per_page'], $start) :generate_pagination("viewtopic.$phpEx?" . POST_TOPIC_URL ."=$topic_id&postdays=$post_days&postorder=$post_order", $total_replies,$board_config['posts_per_page'], $start);
\r
49 // Send vars to template
\r
52 $template->assign_vars(array(
\r
53 'FORUM_ID' => $forum_id,
\r
54 - 'FORUM_NAME' => $forum_name,
\r
55 - 'TOPIC_ID' => $topic_id,
\r
56 - 'TOPIC_TITLE' => $topic_title,
\r
57 + 'FORUM_NAME' => $forum_name,
\r
58 + 'TOPIC_ID' => $topic_id,
\r
59 + 'TOPIC_TITLE' => $topic_title,
\r
60 'PAGINATION' => $pagination,
\r
61 - 'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $board_config['posts_per_page'] ) + 1 ), ceil( $total_replies / $board_config['posts_per_page'] )),
\r
63 + 'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $board_config['posts_per_page'] ) + 1 ),ceil( $total_replies / $board_config['posts_per_page'] )),
\r
64 'POST_IMG' => $post_img,
\r
65 'REPLY_IMG' => $reply_img,
\r
67 'L_AUTHOR' => $lang['Author'],
\r
68 'L_MESSAGE' => $lang['Message'],
\r
69 - 'L_POSTED' => $lang['Posted'],
\r
70 + 'L_POSTED' => $lang['Posted'],
\r
71 'L_POST_SUBJECT' => $lang['Post_subject'],
\r
72 'L_VIEW_NEXT_TOPIC' => $lang['View_next_topic'],
\r
73 'L_VIEW_PREVIOUS_TOPIC' => $lang['View_previous_topic'],
\r
74 - 'L_POST_NEW_TOPIC' => $post_alt,
\r
75 - 'L_POST_REPLY_TOPIC' => $reply_alt,
\r
76 + 'L_POST_NEW_TOPIC' => $post_alt,
\r
77 + 'L_POST_REPLY_TOPIC' => $reply_alt,
\r
78 'L_BACK_TO_TOP' => $lang['Back_to_top'],
\r
79 'L_DISPLAY_POSTS' => $lang['Display_posts'],
\r
80 - 'L_LOCK_TOPIC' => $lang['Lock_topic'],
\r
81 - 'L_UNLOCK_TOPIC' => $lang['Unlock_topic'],
\r
82 - 'L_MOVE_TOPIC' => $lang['Move_topic'],
\r
83 - 'L_SPLIT_TOPIC' => $lang['Split_topic'],
\r
84 - 'L_DELETE_TOPIC' => $lang['Delete_topic'],
\r
85 - 'L_GOTO_PAGE' => $lang['Goto_page'],
\r
86 + 'L_LOCK_TOPIC' => $lang['Lock_topic'],
\r
87 + 'L_UNLOCK_TOPIC' => $lang['Unlock_topic'],
\r
88 + 'L_MOVE_TOPIC' => $lang['Move_topic'],
\r
89 + 'L_SPLIT_TOPIC' => $lang['Split_topic'],
\r
90 + 'L_DELETE_TOPIC' => $lang['Delete_topic'],
\r
91 + 'L_GOTO_PAGE' => $lang['Goto_page'],
\r
93 - 'S_TOPIC_LINK' => POST_TOPIC_URL,
\r
94 + 'S_TOPIC_LINK' => POST_TOPIC_URL,
\r
95 'S_SELECT_POST_DAYS' => $select_post_days,
\r
96 'S_SELECT_POST_ORDER' => $select_post_order,
\r
97 - 'S_POST_DAYS_ACTION' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . '=' . $topic_id . "&start=$start"),
\r
98 + 'S_POST_DAYS_ACTION' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . '=' . $topic_id ."&start=$start"),
\r
99 'S_AUTH_LIST' => $s_auth_can,
\r
100 'S_TOPIC_ADMIN' => $topic_mod,
\r
101 'S_WATCH_TOPIC' => $s_watching_topic,
\r
103 - 'U_VIEW_TOPIC' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&start=$start&postdays=$post_days&postorder=$post_order&highlight=" . $HTTP_GET_VARS['highlight']),
\r
104 + 'U_VIEW_TOPIC' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL .
\r
105 + "=$topic_id&start=$start&postdays=$post_days&postorder=$post_order&highlight=$highlight"),
\r
106 'U_VIEW_FORUM' => $view_forum_url,
\r
107 'U_VIEW_OLDER_TOPIC' => $view_prev_topic_url,
\r
108 'U_VIEW_NEWER_TOPIC' => $view_next_topic_url,
\r
109 @@ -1052,82 +1050,15 @@
112 // Highlight active words (primarily for search)
\r
115 - if ( $highlight_active )
\r
116 + if ($highlight_match)
\r
118 - if ( preg_match('/<.*>/', $message) )
\r
120 - $message = preg_replace($highlight_match, '<!-- #sh -->\1<!-- #eh -->', $message);
\r
124 - $temp_message = '';
\r
125 - $message = ' ' . $message . ' ';
\r
127 - while( $start_html = strpos($message, '<', $start_html) )
\r
129 - $grab_length = $start_html - $end_html - 1;
\r
130 - $temp_message .= substr($message, $end_html + 1, $grab_length);
\r
132 - if ( $end_html = strpos($message, '>', $start_html) )
\r
134 - $length = $end_html - $start_html + 1;
\r
135 - $hold_string = substr($message, $start_html, $length);
\r
137 - if ( strrpos(' ' . $hold_string, '<') != 1 )
\r
139 - $end_html = $start_html + 1;
\r
140 - $end_counter = 1;
\r
142 - while ( $end_counter && $end_html < strlen($message) )
\r
144 - if ( substr($message, $end_html, 1) == '>' )
\r
148 - else if ( substr($message, $end_html, 1) == '<' )
\r
156 - $length = $end_html - $start_html + 1;
\r
157 - $hold_string = substr($message, $start_html, $length);
\r
158 - $hold_string = str_replace('<!-- #sh -->', '', $hold_string);
\r
159 - $hold_string = str_replace('<!-- #eh -->', '', $hold_string);
\r
161 - else if ( $hold_string == '<!-- #sh -->' )
\r
163 - $hold_string = str_replace('<!-- #sh -->', '<span style="color:#' . $theme['fontcolor3'] . '"><b>', $hold_string);
\r
165 - else if ( $hold_string == '<!-- #eh -->' )
\r
167 - $hold_string = str_replace('<!-- #eh -->', '</b></span>', $hold_string);
\r
170 - $temp_message .= $hold_string;
\r
172 - $start_html += $length;
\r
176 - $start_html = strlen($message);
\r
180 - $grab_length = strlen($message) - $end_html - 1;
\r
181 - $temp_message .= substr($message, $end_html + 1, $grab_length);
\r
183 - $message = trim($temp_message);
\r
187 - $message = preg_replace($highlight_match, '<span style="color:#' . $theme['fontcolor3'] . '"><b>\1</b></span>', $message);
\r
189 + // This was shamelessly 'borrowed' from volker at multiartstudio dot de
\r
190 + // via php.net's annotated manual
\r
191 + $message = str_replace('\"', '"', substr(preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se',"preg_replace('#\b(" . $highlight_match . ")\b#i', '<span style=\"color:#" . $theme['fontcolor3']. "\"><b>\\\\1</b></span>', '\\0')", '>' . $message . '<'), 1, -1));
\r
196 // Replace naughty words
\r
198 @@ -1246,4 +1177,4 @@
200 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
\r
203 \ No newline at end of file