@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | $query_where = array(); |
| 167 | 167 | $query_params = $search_data['params']; |
| 168 | 168 | |
| 169 | - if( $smcFunc['db_title'] == "PostgreSQL") |
|
| 169 | + if ($smcFunc['db_title'] == "PostgreSQL") |
|
| 170 | 170 | $modSettings['search_simple_fulltext'] = true; |
| 171 | 171 | |
| 172 | 172 | if ($query_params['id_search']) |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | |
| 210 | 210 | if (!empty($modSettings['search_simple_fulltext'])) |
| 211 | 211 | { |
| 212 | - if($smcFunc['db_title'] == "PostgreSQL") |
|
| 212 | + if ($smcFunc['db_title'] == "PostgreSQL") |
|
| 213 | 213 | { |
| 214 | 214 | $language_ftx = $smcFunc['db_search_language'](); |
| 215 | 215 | |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | // remove any indexed words that are used in the complex body search terms |
| 228 | 228 | $words['indexed_words'] = array_diff($words['indexed_words'], $words['complex_words']); |
| 229 | 229 | |
| 230 | - if($smcFunc['db_title'] == "PostgreSQL"){ |
|
| 230 | + if ($smcFunc['db_title'] == "PostgreSQL") { |
|
| 231 | 231 | $row = 0; |
| 232 | 232 | foreach ($words['indexed_words'] as $fulltextWord) { |
| 233 | 233 | $query_params['boolean_match'] .= ($row <> 0 ? '&' : ''); |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | |
| 244 | 244 | // if we have bool terms to search, add them in |
| 245 | 245 | if ($query_params['boolean_match']) { |
| 246 | - if($smcFunc['db_title'] == "PostgreSQL") |
|
| 246 | + if ($smcFunc['db_title'] == "PostgreSQL") |
|
| 247 | 247 | { |
| 248 | 248 | $language_ftx = $smcFunc['db_search_language'](); |
| 249 | 249 | |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - $ignoreRequest = $smcFunc['db_search_query']('insert_into_log_messages_fulltext', ($smcFunc['db_support_ignore'] ? ( ' |
|
| 259 | + $ignoreRequest = $smcFunc['db_search_query']('insert_into_log_messages_fulltext', ($smcFunc['db_support_ignore'] ? (' |
|
| 260 | 260 | INSERT IGNORE INTO {db_prefix}' . $search_data['insert_into'] . ' |
| 261 | 261 | (' . implode(', ', array_keys($query_select)) . ')') : '') . ' |
| 262 | 262 | SELECT ' . implode(', ', $query_select) . ' |
@@ -11,8 +11,9 @@ discard block |
||
| 11 | 11 | * @version 2.1 Beta 4 |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | -if (!defined('SMF')) |
|
| 14 | +if (!defined('SMF')) { |
|
| 15 | 15 | die('No direct access...'); |
| 16 | +} |
|
| 16 | 17 | |
| 17 | 18 | /** |
| 18 | 19 | * Class fulltext_search |
@@ -98,8 +99,9 @@ discard block |
||
| 98 | 99 | $smcFunc['db_free_result']($request); |
| 99 | 100 | } |
| 100 | 101 | // 4 is the MySQL default... |
| 101 | - else |
|
| 102 | - $min_word_length = 4; |
|
| 102 | + else { |
|
| 103 | + $min_word_length = 4; |
|
| 104 | + } |
|
| 103 | 105 | |
| 104 | 106 | return $min_word_length; |
| 105 | 107 | } |
@@ -138,8 +140,7 @@ discard block |
||
| 138 | 140 | $wordsSearch['words'][] = trim($word, "/*- "); |
| 139 | 141 | $wordsSearch['complex_words'][] = count($subwords) === 1 ? $word : '"' . $word . '"'; |
| 140 | 142 | } |
| 141 | - } |
|
| 142 | - elseif ($smcFunc['strlen'](trim($word, "/*- ")) < $this->min_word_length) |
|
| 143 | + } elseif ($smcFunc['strlen'](trim($word, "/*- ")) < $this->min_word_length) |
|
| 143 | 144 | { |
| 144 | 145 | // short words have feelings too |
| 145 | 146 | $wordsSearch['words'][] = trim($word, "/*- "); |
@@ -149,8 +150,9 @@ discard block |
||
| 149 | 150 | |
| 150 | 151 | $fulltextWord = count($subwords) === 1 ? $word : '"' . $word . '"'; |
| 151 | 152 | $wordsSearch['indexed_words'][] = $fulltextWord; |
| 152 | - if ($isExcluded) |
|
| 153 | - $wordsExclude[] = $fulltextWord; |
|
| 153 | + if ($isExcluded) { |
|
| 154 | + $wordsExclude[] = $fulltextWord; |
|
| 155 | + } |
|
| 154 | 156 | } |
| 155 | 157 | |
| 156 | 158 | /** |
@@ -166,44 +168,54 @@ discard block |
||
| 166 | 168 | $query_where = array(); |
| 167 | 169 | $query_params = $search_data['params']; |
| 168 | 170 | |
| 169 | - if( $smcFunc['db_title'] == "PostgreSQL") |
|
| 170 | - $modSettings['search_simple_fulltext'] = true; |
|
| 171 | + if( $smcFunc['db_title'] == "PostgreSQL") { |
|
| 172 | + $modSettings['search_simple_fulltext'] = true; |
|
| 173 | + } |
|
| 171 | 174 | |
| 172 | - if ($query_params['id_search']) |
|
| 173 | - $query_select['id_search'] = '{int:id_search}'; |
|
| 175 | + if ($query_params['id_search']) { |
|
| 176 | + $query_select['id_search'] = '{int:id_search}'; |
|
| 177 | + } |
|
| 174 | 178 | |
| 175 | 179 | $count = 0; |
| 176 | - if (empty($modSettings['search_simple_fulltext'])) |
|
| 177 | - foreach ($words['words'] as $regularWord) |
|
| 180 | + if (empty($modSettings['search_simple_fulltext'])) { |
|
| 181 | + foreach ($words['words'] as $regularWord) |
|
| 178 | 182 | { |
| 179 | 183 | $query_where[] = 'm.body' . (in_array($regularWord, $query_params['excluded_words']) ? ' NOT' : '') . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:complex_body_' . $count . '}'; |
| 184 | + } |
|
| 180 | 185 | $query_params['complex_body_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]'; |
| 181 | 186 | } |
| 182 | 187 | |
| 183 | - if ($query_params['user_query']) |
|
| 184 | - $query_where[] = '{raw:user_query}'; |
|
| 185 | - if ($query_params['board_query']) |
|
| 186 | - $query_where[] = 'm.id_board {raw:board_query}'; |
|
| 188 | + if ($query_params['user_query']) { |
|
| 189 | + $query_where[] = '{raw:user_query}'; |
|
| 190 | + } |
|
| 191 | + if ($query_params['board_query']) { |
|
| 192 | + $query_where[] = 'm.id_board {raw:board_query}'; |
|
| 193 | + } |
|
| 187 | 194 | |
| 188 | - if ($query_params['topic']) |
|
| 189 | - $query_where[] = 'm.id_topic = {int:topic}'; |
|
| 190 | - if ($query_params['min_msg_id']) |
|
| 191 | - $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
| 192 | - if ($query_params['max_msg_id']) |
|
| 193 | - $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
| 195 | + if ($query_params['topic']) { |
|
| 196 | + $query_where[] = 'm.id_topic = {int:topic}'; |
|
| 197 | + } |
|
| 198 | + if ($query_params['min_msg_id']) { |
|
| 199 | + $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
| 200 | + } |
|
| 201 | + if ($query_params['max_msg_id']) { |
|
| 202 | + $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
| 203 | + } |
|
| 194 | 204 | |
| 195 | 205 | $count = 0; |
| 196 | - if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) |
|
| 197 | - foreach ($query_params['excluded_phrases'] as $phrase) |
|
| 206 | + if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) { |
|
| 207 | + foreach ($query_params['excluded_phrases'] as $phrase) |
|
| 198 | 208 | { |
| 199 | 209 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_phrase_' . $count . '}'; |
| 210 | + } |
|
| 200 | 211 | $query_params['exclude_subject_phrase_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($phrase, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $phrase), '\\\'') . '[[:>:]]'; |
| 201 | 212 | } |
| 202 | 213 | $count = 0; |
| 203 | - if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) |
|
| 204 | - foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
| 214 | + if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) { |
|
| 215 | + foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
| 205 | 216 | { |
| 206 | 217 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_words_' . $count . '}'; |
| 218 | + } |
|
| 207 | 219 | $query_params['exclude_subject_words_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($excludedWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $excludedWord), '\\\'') . '[[:>:]]'; |
| 208 | 220 | } |
| 209 | 221 | |
@@ -215,12 +227,11 @@ discard block |
||
| 215 | 227 | |
| 216 | 228 | $query_where[] = 'to_tsvector({string:language_ftx},body) @@ to_tsquery({string:language_ftx},{string:body_match})'; |
| 217 | 229 | $query_params['language_ftx'] = $language_ftx; |
| 230 | + } else { |
|
| 231 | + $query_where[] = 'MATCH (body) AGAINST ({string:body_match})'; |
|
| 218 | 232 | } |
| 219 | - else |
|
| 220 | - $query_where[] = 'MATCH (body) AGAINST ({string:body_match})'; |
|
| 221 | 233 | $query_params['body_match'] = implode(' ', array_diff($words['indexed_words'], $query_params['excluded_index_words'])); |
| 222 | - } |
|
| 223 | - else |
|
| 234 | + } else |
|
| 224 | 235 | { |
| 225 | 236 | $query_params['boolean_match'] = ''; |
| 226 | 237 | |
@@ -234,10 +245,10 @@ discard block |
||
| 234 | 245 | $query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '!' : '') . $fulltextWord . ' '; |
| 235 | 246 | $row++; |
| 236 | 247 | } |
| 237 | - } |
|
| 238 | - else |
|
| 239 | - foreach ($words['indexed_words'] as $fulltextWord) |
|
| 248 | + } else { |
|
| 249 | + foreach ($words['indexed_words'] as $fulltextWord) |
|
| 240 | 250 | $query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '-' : '+') . $fulltextWord . ' '; |
| 251 | + } |
|
| 241 | 252 | |
| 242 | 253 | $query_params['boolean_match'] = substr($query_params['boolean_match'], 0, -1); |
| 243 | 254 | |
@@ -249,9 +260,9 @@ discard block |
||
| 249 | 260 | |
| 250 | 261 | $query_where[] = 'to_tsvector({string:language_ftx},body) @@ to_tsquery({string:language_ftx},{string:boolean_match})'; |
| 251 | 262 | $query_params['language_ftx'] = $language_ftx; |
| 263 | + } else { |
|
| 264 | + $query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)'; |
|
| 252 | 265 | } |
| 253 | - else |
|
| 254 | - $query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)'; |
|
| 255 | 266 | } |
| 256 | 267 | |
| 257 | 268 | } |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 4 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | // This defines two version types for checking the API's are compatible with this version of SMF. |
| 20 | 21 | $GLOBALS['search_versions'] = array( |
@@ -39,8 +40,9 @@ discard block |
||
| 39 | 40 | global $txt, $scripturl, $modSettings, $user_info, $context, $smcFunc, $sourcedir; |
| 40 | 41 | |
| 41 | 42 | // Is the load average too high to allow searching just now? |
| 42 | - if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) |
|
| 43 | - fatal_lang_error('loadavg_search_disabled', false); |
|
| 43 | + if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) { |
|
| 44 | + fatal_lang_error('loadavg_search_disabled', false); |
|
| 45 | + } |
|
| 44 | 46 | |
| 45 | 47 | loadLanguage('Search'); |
| 46 | 48 | // Don't load this in XML mode. |
@@ -88,23 +90,30 @@ discard block |
||
| 88 | 90 | @list ($k, $v) = explode('|\'|', $data); |
| 89 | 91 | $context['search_params'][$k] = $v; |
| 90 | 92 | } |
| 91 | - if (isset($context['search_params']['brd'])) |
|
| 92 | - $context['search_params']['brd'] = $context['search_params']['brd'] == '' ? array() : explode(',', $context['search_params']['brd']); |
|
| 93 | + if (isset($context['search_params']['brd'])) { |
|
| 94 | + $context['search_params']['brd'] = $context['search_params']['brd'] == '' ? array() : explode(',', $context['search_params']['brd']); |
|
| 95 | + } |
|
| 93 | 96 | } |
| 94 | 97 | |
| 95 | - if (isset($_REQUEST['search'])) |
|
| 96 | - $context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']); |
|
| 98 | + if (isset($_REQUEST['search'])) { |
|
| 99 | + $context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']); |
|
| 100 | + } |
|
| 97 | 101 | |
| 98 | - if (isset($context['search_params']['search'])) |
|
| 99 | - $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
| 100 | - if (isset($context['search_params']['userspec'])) |
|
| 101 | - $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
| 102 | - if (!empty($context['search_params']['searchtype'])) |
|
| 103 | - $context['search_params']['searchtype'] = 2; |
|
| 104 | - if (!empty($context['search_params']['minage'])) |
|
| 105 | - $context['search_params']['minage'] = (int) $context['search_params']['minage']; |
|
| 106 | - if (!empty($context['search_params']['maxage'])) |
|
| 107 | - $context['search_params']['maxage'] = (int) $context['search_params']['maxage']; |
|
| 102 | + if (isset($context['search_params']['search'])) { |
|
| 103 | + $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
| 104 | + } |
|
| 105 | + if (isset($context['search_params']['userspec'])) { |
|
| 106 | + $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
| 107 | + } |
|
| 108 | + if (!empty($context['search_params']['searchtype'])) { |
|
| 109 | + $context['search_params']['searchtype'] = 2; |
|
| 110 | + } |
|
| 111 | + if (!empty($context['search_params']['minage'])) { |
|
| 112 | + $context['search_params']['minage'] = (int) $context['search_params']['minage']; |
|
| 113 | + } |
|
| 114 | + if (!empty($context['search_params']['maxage'])) { |
|
| 115 | + $context['search_params']['maxage'] = (int) $context['search_params']['maxage']; |
|
| 116 | + } |
|
| 108 | 117 | |
| 109 | 118 | $context['search_params']['show_complete'] = !empty($context['search_params']['show_complete']); |
| 110 | 119 | $context['search_params']['subject_only'] = !empty($context['search_params']['subject_only']); |
@@ -116,11 +125,13 @@ discard block |
||
| 116 | 125 | $context['search_errors']['messages'] = array(); |
| 117 | 126 | foreach ($context['search_errors'] as $search_error => $dummy) |
| 118 | 127 | { |
| 119 | - if ($search_error === 'messages') |
|
| 120 | - continue; |
|
| 128 | + if ($search_error === 'messages') { |
|
| 129 | + continue; |
|
| 130 | + } |
|
| 121 | 131 | |
| 122 | - if ($search_error == 'string_too_long') |
|
| 123 | - $txt['error_string_too_long'] = sprintf($txt['error_string_too_long'], $context['search_string_limit']); |
|
| 132 | + if ($search_error == 'string_too_long') { |
|
| 133 | + $txt['error_string_too_long'] = sprintf($txt['error_string_too_long'], $context['search_string_limit']); |
|
| 134 | + } |
|
| 124 | 135 | |
| 125 | 136 | $context['search_errors']['messages'][] = $txt['error_' . $search_error]; |
| 126 | 137 | } |
@@ -143,12 +154,13 @@ discard block |
||
| 143 | 154 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 144 | 155 | { |
| 145 | 156 | // This category hasn't been set up yet.. |
| 146 | - if (!isset($context['categories'][$row['id_cat']])) |
|
| 147 | - $context['categories'][$row['id_cat']] = array( |
|
| 157 | + if (!isset($context['categories'][$row['id_cat']])) { |
|
| 158 | + $context['categories'][$row['id_cat']] = array( |
|
| 148 | 159 | 'id' => $row['id_cat'], |
| 149 | 160 | 'name' => $row['cat_name'], |
| 150 | 161 | 'boards' => array() |
| 151 | 162 | ); |
| 163 | + } |
|
| 152 | 164 | |
| 153 | 165 | // Set this board up, and let the template know when it's a child. (indent them..) |
| 154 | 166 | $context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array( |
@@ -159,8 +171,9 @@ discard block |
||
| 159 | 171 | ); |
| 160 | 172 | |
| 161 | 173 | // If a board wasn't checked that probably should have been ensure the board selection is selected, yo! |
| 162 | - if (!$context['categories'][$row['id_cat']]['boards'][$row['id_board']]['selected'] && (empty($modSettings['recycle_enable']) || $row['id_board'] != $modSettings['recycle_board'])) |
|
| 163 | - $context['boards_check_all'] = false; |
|
| 174 | + if (!$context['categories'][$row['id_cat']]['boards'][$row['id_board']]['selected'] && (empty($modSettings['recycle_enable']) || $row['id_board'] != $modSettings['recycle_board'])) { |
|
| 175 | + $context['boards_check_all'] = false; |
|
| 176 | + } |
|
| 164 | 177 | } |
| 165 | 178 | $smcFunc['db_free_result']($request); |
| 166 | 179 | |
@@ -182,18 +195,20 @@ discard block |
||
| 182 | 195 | } |
| 183 | 196 | |
| 184 | 197 | $max_boards = ceil(count($temp_boards) / 2); |
| 185 | - if ($max_boards == 1) |
|
| 186 | - $max_boards = 2; |
|
| 198 | + if ($max_boards == 1) { |
|
| 199 | + $max_boards = 2; |
|
| 200 | + } |
|
| 187 | 201 | |
| 188 | 202 | // Now, alternate them so they can be shown left and right ;). |
| 189 | 203 | $context['board_columns'] = array(); |
| 190 | 204 | for ($i = 0; $i < $max_boards; $i++) |
| 191 | 205 | { |
| 192 | 206 | $context['board_columns'][] = $temp_boards[$i]; |
| 193 | - if (isset($temp_boards[$i + $max_boards])) |
|
| 194 | - $context['board_columns'][] = $temp_boards[$i + $max_boards]; |
|
| 195 | - else |
|
| 196 | - $context['board_columns'][] = array(); |
|
| 207 | + if (isset($temp_boards[$i + $max_boards])) { |
|
| 208 | + $context['board_columns'][] = $temp_boards[$i + $max_boards]; |
|
| 209 | + } else { |
|
| 210 | + $context['board_columns'][] = array(); |
|
| 211 | + } |
|
| 197 | 212 | } |
| 198 | 213 | |
| 199 | 214 | if (!empty($_REQUEST['topic'])) |
@@ -225,8 +240,9 @@ discard block |
||
| 225 | 240 | ) |
| 226 | 241 | ); |
| 227 | 242 | |
| 228 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 229 | - fatal_lang_error('topic_gone', false); |
|
| 243 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 244 | + fatal_lang_error('topic_gone', false); |
|
| 245 | + } |
|
| 230 | 246 | |
| 231 | 247 | list ($context['search_topic']['subject']) = $smcFunc['db_fetch_row']($request); |
| 232 | 248 | $smcFunc['db_free_result']($request); |
@@ -256,11 +272,13 @@ discard block |
||
| 256 | 272 | global $excludedWords, $participants, $smcFunc; |
| 257 | 273 | |
| 258 | 274 | // if comming from the quick search box, and we want to search on members, well we need to do that ;) |
| 259 | - if (isset($_REQUEST['search_selection']) && $_REQUEST['search_selection'] === 'members') |
|
| 260 | - redirectexit($scripturl . '?action=mlist;sa=search;fields=name,email;search=' . urlencode($_REQUEST['search'])); |
|
| 275 | + if (isset($_REQUEST['search_selection']) && $_REQUEST['search_selection'] === 'members') { |
|
| 276 | + redirectexit($scripturl . '?action=mlist;sa=search;fields=name,email;search=' . urlencode($_REQUEST['search'])); |
|
| 277 | + } |
|
| 261 | 278 | |
| 262 | - if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) |
|
| 263 | - fatal_lang_error('loadavg_search_disabled', false); |
|
| 279 | + if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) { |
|
| 280 | + fatal_lang_error('loadavg_search_disabled', false); |
|
| 281 | + } |
|
| 264 | 282 | |
| 265 | 283 | // No, no, no... this is a bit hard on the server, so don't you go prefetching it! |
| 266 | 284 | if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') |
@@ -307,8 +325,9 @@ discard block |
||
| 307 | 325 | } |
| 308 | 326 | |
| 309 | 327 | // Zero weight. Weightless :P. |
| 310 | - if (empty($weight_total)) |
|
| 311 | - fatal_lang_error('search_invalid_weights'); |
|
| 328 | + if (empty($weight_total)) { |
|
| 329 | + fatal_lang_error('search_invalid_weights'); |
|
| 330 | + } |
|
| 312 | 331 | |
| 313 | 332 | // These vars don't require an interface, they're just here for tweaking. |
| 314 | 333 | $recentPercentage = 0.30; |
@@ -326,11 +345,13 @@ discard block |
||
| 326 | 345 | $context['search_string_limit'] = 100; |
| 327 | 346 | |
| 328 | 347 | loadLanguage('Search'); |
| 329 | - if (!isset($_REQUEST['xml'])) |
|
| 330 | - loadTemplate('Search'); |
|
| 348 | + if (!isset($_REQUEST['xml'])) { |
|
| 349 | + loadTemplate('Search'); |
|
| 350 | + } |
|
| 331 | 351 | //If we're doing XML we need to use the results template regardless really. |
| 332 | - else |
|
| 333 | - $context['sub_template'] = 'results'; |
|
| 352 | + else { |
|
| 353 | + $context['sub_template'] = 'results'; |
|
| 354 | + } |
|
| 334 | 355 | |
| 335 | 356 | // Are you allowed? |
| 336 | 357 | isAllowedTo('search_posts'); |
@@ -363,34 +384,39 @@ discard block |
||
| 363 | 384 | $search_params[$k] = $v; |
| 364 | 385 | } |
| 365 | 386 | |
| 366 | - if (isset($search_params['brd'])) |
|
| 367 | - $search_params['brd'] = empty($search_params['brd']) ? array() : explode(',', $search_params['brd']); |
|
| 387 | + if (isset($search_params['brd'])) { |
|
| 388 | + $search_params['brd'] = empty($search_params['brd']) ? array() : explode(',', $search_params['brd']); |
|
| 389 | + } |
|
| 368 | 390 | } |
| 369 | 391 | |
| 370 | 392 | // Store whether simple search was used (needed if the user wants to do another query). |
| 371 | - if (!isset($search_params['advanced'])) |
|
| 372 | - $search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1; |
|
| 393 | + if (!isset($search_params['advanced'])) { |
|
| 394 | + $search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1; |
|
| 395 | + } |
|
| 373 | 396 | |
| 374 | 397 | // 1 => 'allwords' (default, don't set as param) / 2 => 'anywords'. |
| 375 | - if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) |
|
| 376 | - $search_params['searchtype'] = 2; |
|
| 398 | + if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) { |
|
| 399 | + $search_params['searchtype'] = 2; |
|
| 400 | + } |
|
| 377 | 401 | |
| 378 | 402 | // Minimum age of messages. Default to zero (don't set param in that case). |
| 379 | - if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) |
|
| 380 | - $search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage']; |
|
| 403 | + if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) { |
|
| 404 | + $search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage']; |
|
| 405 | + } |
|
| 381 | 406 | |
| 382 | 407 | // Maximum age of messages. Default to infinite (9999 days: param not set). |
| 383 | - if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] < 9999)) |
|
| 384 | - $search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage']; |
|
| 408 | + if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] < 9999)) { |
|
| 409 | + $search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage']; |
|
| 410 | + } |
|
| 385 | 411 | |
| 386 | 412 | // Searching a specific topic? |
| 387 | 413 | if (!empty($_REQUEST['topic']) || (!empty($_REQUEST['search_selection']) && $_REQUEST['search_selection'] == 'topic')) |
| 388 | 414 | { |
| 389 | 415 | $search_params['topic'] = empty($_REQUEST['search_selection']) ? (int) $_REQUEST['topic'] : (isset($_REQUEST['sd_topic']) ? (int) $_REQUEST['sd_topic'] : ''); |
| 390 | 416 | $search_params['show_complete'] = true; |
| 417 | + } elseif (!empty($search_params['topic'])) { |
|
| 418 | + $search_params['topic'] = (int) $search_params['topic']; |
|
| 391 | 419 | } |
| 392 | - elseif (!empty($search_params['topic'])) |
|
| 393 | - $search_params['topic'] = (int) $search_params['topic']; |
|
| 394 | 420 | |
| 395 | 421 | if (!empty($search_params['minage']) || !empty($search_params['maxage'])) |
| 396 | 422 | { |
@@ -408,19 +434,21 @@ discard block |
||
| 408 | 434 | ) |
| 409 | 435 | ); |
| 410 | 436 | list ($minMsgID, $maxMsgID) = $smcFunc['db_fetch_row']($request); |
| 411 | - if ($minMsgID < 0 || $maxMsgID < 0) |
|
| 412 | - $context['search_errors']['no_messages_in_time_frame'] = true; |
|
| 437 | + if ($minMsgID < 0 || $maxMsgID < 0) { |
|
| 438 | + $context['search_errors']['no_messages_in_time_frame'] = true; |
|
| 439 | + } |
|
| 413 | 440 | $smcFunc['db_free_result']($request); |
| 414 | 441 | } |
| 415 | 442 | |
| 416 | 443 | // Default the user name to a wildcard matching every user (*). |
| 417 | - if (!empty($search_params['userspec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) |
|
| 418 | - $search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec']; |
|
| 444 | + if (!empty($search_params['userspec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) { |
|
| 445 | + $search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec']; |
|
| 446 | + } |
|
| 419 | 447 | |
| 420 | 448 | // If there's no specific user, then don't mention it in the main query. |
| 421 | - if (empty($search_params['userspec'])) |
|
| 422 | - $userQuery = ''; |
|
| 423 | - else |
|
| 449 | + if (empty($search_params['userspec'])) { |
|
| 450 | + $userQuery = ''; |
|
| 451 | + } else |
|
| 424 | 452 | { |
| 425 | 453 | $userString = strtr($smcFunc['htmlspecialchars']($search_params['userspec'], ENT_QUOTES), array('"' => '"')); |
| 426 | 454 | $userString = strtr($userString, array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_')); |
@@ -432,19 +460,21 @@ discard block |
||
| 432 | 460 | { |
| 433 | 461 | $possible_users[$k] = trim($possible_users[$k]); |
| 434 | 462 | |
| 435 | - if (strlen($possible_users[$k]) == 0) |
|
| 436 | - unset($possible_users[$k]); |
|
| 463 | + if (strlen($possible_users[$k]) == 0) { |
|
| 464 | + unset($possible_users[$k]); |
|
| 465 | + } |
|
| 437 | 466 | } |
| 438 | 467 | |
| 439 | 468 | // Create a list of database-escaped search names. |
| 440 | 469 | $realNameMatches = array(); |
| 441 | - foreach ($possible_users as $possible_user) |
|
| 442 | - $realNameMatches[] = $smcFunc['db_quote']( |
|
| 470 | + foreach ($possible_users as $possible_user) { |
|
| 471 | + $realNameMatches[] = $smcFunc['db_quote']( |
|
| 443 | 472 | '{string:possible_user}', |
| 444 | 473 | array( |
| 445 | 474 | 'possible_user' => $possible_user |
| 446 | 475 | ) |
| 447 | 476 | ); |
| 477 | + } |
|
| 448 | 478 | |
| 449 | 479 | // Retrieve a list of possible members. |
| 450 | 480 | $request = $smcFunc['db_query']('', ' |
@@ -456,9 +486,9 @@ discard block |
||
| 456 | 486 | ) |
| 457 | 487 | ); |
| 458 | 488 | // Simply do nothing if there're too many members matching the criteria. |
| 459 | - if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) |
|
| 460 | - $userQuery = ''; |
|
| 461 | - elseif ($smcFunc['db_num_rows']($request) == 0) |
|
| 489 | + if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) { |
|
| 490 | + $userQuery = ''; |
|
| 491 | + } elseif ($smcFunc['db_num_rows']($request) == 0) |
|
| 462 | 492 | { |
| 463 | 493 | $userQuery = $smcFunc['db_quote']( |
| 464 | 494 | 'm.id_member = {int:id_member_guest} AND ({raw:match_possible_guest_names})', |
@@ -467,12 +497,12 @@ discard block |
||
| 467 | 497 | 'match_possible_guest_names' => 'm.poster_name LIKE ' . implode(' OR m.poster_name LIKE ', $realNameMatches), |
| 468 | 498 | ) |
| 469 | 499 | ); |
| 470 | - } |
|
| 471 | - else |
|
| 500 | + } else |
|
| 472 | 501 | { |
| 473 | 502 | $memberlist = array(); |
| 474 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 475 | - $memberlist[] = $row['id_member']; |
|
| 503 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 504 | + $memberlist[] = $row['id_member']; |
|
| 505 | + } |
|
| 476 | 506 | $userQuery = $smcFunc['db_quote']( |
| 477 | 507 | '(m.id_member IN ({array_int:matched_members}) OR (m.id_member = {int:id_member_guest} AND ({raw:match_possible_guest_names})))', |
| 478 | 508 | array( |
@@ -486,22 +516,25 @@ discard block |
||
| 486 | 516 | } |
| 487 | 517 | |
| 488 | 518 | // If the boards were passed by URL (params=), temporarily put them back in $_REQUEST. |
| 489 | - if (!empty($search_params['brd']) && is_array($search_params['brd'])) |
|
| 490 | - $_REQUEST['brd'] = $search_params['brd']; |
|
| 519 | + if (!empty($search_params['brd']) && is_array($search_params['brd'])) { |
|
| 520 | + $_REQUEST['brd'] = $search_params['brd']; |
|
| 521 | + } |
|
| 491 | 522 | |
| 492 | 523 | // Ensure that brd is an array. |
| 493 | 524 | if ((!empty($_REQUEST['brd']) && !is_array($_REQUEST['brd'])) || (!empty($_REQUEST['search_selection']) && $_REQUEST['search_selection'] == 'board')) |
| 494 | 525 | { |
| 495 | - if (!empty($_REQUEST['brd'])) |
|
| 496 | - $_REQUEST['brd'] = strpos($_REQUEST['brd'], ',') !== false ? explode(',', $_REQUEST['brd']) : array($_REQUEST['brd']); |
|
| 497 | - else |
|
| 498 | - $_REQUEST['brd'] = isset($_REQUEST['sd_brd']) ? array($_REQUEST['sd_brd']) : array(); |
|
| 526 | + if (!empty($_REQUEST['brd'])) { |
|
| 527 | + $_REQUEST['brd'] = strpos($_REQUEST['brd'], ',') !== false ? explode(',', $_REQUEST['brd']) : array($_REQUEST['brd']); |
|
| 528 | + } else { |
|
| 529 | + $_REQUEST['brd'] = isset($_REQUEST['sd_brd']) ? array($_REQUEST['sd_brd']) : array(); |
|
| 530 | + } |
|
| 499 | 531 | } |
| 500 | 532 | |
| 501 | 533 | // Make sure all boards are integers. |
| 502 | - if (!empty($_REQUEST['brd'])) |
|
| 503 | - foreach ($_REQUEST['brd'] as $id => $brd) |
|
| 534 | + if (!empty($_REQUEST['brd'])) { |
|
| 535 | + foreach ($_REQUEST['brd'] as $id => $brd) |
|
| 504 | 536 | $_REQUEST['brd'][$id] = (int) $brd; |
| 537 | + } |
|
| 505 | 538 | |
| 506 | 539 | // Special case for boards: searching just one topic? |
| 507 | 540 | if (!empty($search_params['topic'])) |
@@ -520,17 +553,18 @@ discard block |
||
| 520 | 553 | ) |
| 521 | 554 | ); |
| 522 | 555 | |
| 523 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 524 | - fatal_lang_error('topic_gone', false); |
|
| 556 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 557 | + fatal_lang_error('topic_gone', false); |
|
| 558 | + } |
|
| 525 | 559 | |
| 526 | 560 | $search_params['brd'] = array(); |
| 527 | 561 | list ($search_params['brd'][0]) = $smcFunc['db_fetch_row']($request); |
| 528 | 562 | $smcFunc['db_free_result']($request); |
| 529 | 563 | } |
| 530 | 564 | // Select all boards you've selected AND are allowed to see. |
| 531 | - elseif ($user_info['is_admin'] && (!empty($search_params['advanced']) || !empty($_REQUEST['brd']))) |
|
| 532 | - $search_params['brd'] = empty($_REQUEST['brd']) ? array() : $_REQUEST['brd']; |
|
| 533 | - else |
|
| 565 | + elseif ($user_info['is_admin'] && (!empty($search_params['advanced']) || !empty($_REQUEST['brd']))) { |
|
| 566 | + $search_params['brd'] = empty($_REQUEST['brd']) ? array() : $_REQUEST['brd']; |
|
| 567 | + } else |
|
| 534 | 568 | { |
| 535 | 569 | $see_board = empty($search_params['advanced']) ? 'query_wanna_see_board' : 'query_see_board'; |
| 536 | 570 | $request = $smcFunc['db_query']('', ' |
@@ -548,19 +582,22 @@ discard block |
||
| 548 | 582 | ) |
| 549 | 583 | ); |
| 550 | 584 | $search_params['brd'] = array(); |
| 551 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 552 | - $search_params['brd'][] = $row['id_board']; |
|
| 585 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 586 | + $search_params['brd'][] = $row['id_board']; |
|
| 587 | + } |
|
| 553 | 588 | $smcFunc['db_free_result']($request); |
| 554 | 589 | |
| 555 | 590 | // This error should pro'bly only happen for hackers. |
| 556 | - if (empty($search_params['brd'])) |
|
| 557 | - $context['search_errors']['no_boards_selected'] = true; |
|
| 591 | + if (empty($search_params['brd'])) { |
|
| 592 | + $context['search_errors']['no_boards_selected'] = true; |
|
| 593 | + } |
|
| 558 | 594 | } |
| 559 | 595 | |
| 560 | 596 | if (count($search_params['brd']) != 0) |
| 561 | 597 | { |
| 562 | - foreach ($search_params['brd'] as $k => $v) |
|
| 563 | - $search_params['brd'][$k] = (int) $v; |
|
| 598 | + foreach ($search_params['brd'] as $k => $v) { |
|
| 599 | + $search_params['brd'][$k] = (int) $v; |
|
| 600 | + } |
|
| 564 | 601 | |
| 565 | 602 | // If we've selected all boards, this parameter can be left empty. |
| 566 | 603 | $request = $smcFunc['db_query']('', ' |
@@ -574,15 +611,16 @@ discard block |
||
| 574 | 611 | list ($num_boards) = $smcFunc['db_fetch_row']($request); |
| 575 | 612 | $smcFunc['db_free_result']($request); |
| 576 | 613 | |
| 577 | - if (count($search_params['brd']) == $num_boards) |
|
| 614 | + if (count($search_params['brd']) == $num_boards) { |
|
| 615 | + $boardQuery = ''; |
|
| 616 | + } elseif (count($search_params['brd']) == $num_boards - 1 && !empty($modSettings['recycle_board']) && !in_array($modSettings['recycle_board'], $search_params['brd'])) { |
|
| 617 | + $boardQuery = '!= ' . $modSettings['recycle_board']; |
|
| 618 | + } else { |
|
| 619 | + $boardQuery = 'IN (' . implode(', ', $search_params['brd']) . ')'; |
|
| 620 | + } |
|
| 621 | + } else { |
|
| 578 | 622 | $boardQuery = ''; |
| 579 | - elseif (count($search_params['brd']) == $num_boards - 1 && !empty($modSettings['recycle_board']) && !in_array($modSettings['recycle_board'], $search_params['brd'])) |
|
| 580 | - $boardQuery = '!= ' . $modSettings['recycle_board']; |
|
| 581 | - else |
|
| 582 | - $boardQuery = 'IN (' . implode(', ', $search_params['brd']) . ')'; |
|
| 583 | 623 | } |
| 584 | - else |
|
| 585 | - $boardQuery = ''; |
|
| 586 | 624 | |
| 587 | 625 | $search_params['show_complete'] = !empty($search_params['show_complete']) || !empty($_REQUEST['show_complete']); |
| 588 | 626 | $search_params['subject_only'] = !empty($search_params['subject_only']) || !empty($_REQUEST['subject_only']); |
@@ -596,11 +634,13 @@ discard block |
||
| 596 | 634 | 'id_msg', |
| 597 | 635 | ); |
| 598 | 636 | call_integration_hook('integrate_search_sort_columns', array(&$sort_columns)); |
| 599 | - if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) |
|
| 600 | - list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, ''); |
|
| 637 | + if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) { |
|
| 638 | + list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, ''); |
|
| 639 | + } |
|
| 601 | 640 | $search_params['sort'] = !empty($search_params['sort']) && in_array($search_params['sort'], $sort_columns) ? $search_params['sort'] : 'relevance'; |
| 602 | - if (!empty($search_params['topic']) && $search_params['sort'] === 'num_replies') |
|
| 603 | - $search_params['sort'] = 'id_msg'; |
|
| 641 | + if (!empty($search_params['topic']) && $search_params['sort'] === 'num_replies') { |
|
| 642 | + $search_params['sort'] = 'id_msg'; |
|
| 643 | + } |
|
| 604 | 644 | |
| 605 | 645 | // Sorting direction: descending unless stated otherwise. |
| 606 | 646 | $search_params['sort_dir'] = !empty($search_params['sort_dir']) && $search_params['sort_dir'] == 'asc' ? 'asc' : 'desc'; |
@@ -624,17 +664,19 @@ discard block |
||
| 624 | 664 | // What are we searching for? |
| 625 | 665 | if (empty($search_params['search'])) |
| 626 | 666 | { |
| 627 | - if (isset($_GET['search'])) |
|
| 628 | - $search_params['search'] = un_htmlspecialchars($_GET['search']); |
|
| 629 | - elseif (isset($_POST['search'])) |
|
| 630 | - $search_params['search'] = $_POST['search']; |
|
| 631 | - else |
|
| 632 | - $search_params['search'] = ''; |
|
| 667 | + if (isset($_GET['search'])) { |
|
| 668 | + $search_params['search'] = un_htmlspecialchars($_GET['search']); |
|
| 669 | + } elseif (isset($_POST['search'])) { |
|
| 670 | + $search_params['search'] = $_POST['search']; |
|
| 671 | + } else { |
|
| 672 | + $search_params['search'] = ''; |
|
| 673 | + } |
|
| 633 | 674 | } |
| 634 | 675 | |
| 635 | 676 | // Nothing?? |
| 636 | - if (!isset($search_params['search']) || $search_params['search'] == '') |
|
| 637 | - $context['search_errors']['invalid_search_string'] = true; |
|
| 677 | + if (!isset($search_params['search']) || $search_params['search'] == '') { |
|
| 678 | + $context['search_errors']['invalid_search_string'] = true; |
|
| 679 | + } |
|
| 638 | 680 | // Too long? |
| 639 | 681 | elseif ($smcFunc['strlen']($search_params['search']) > $context['search_string_limit']) |
| 640 | 682 | { |
@@ -648,8 +690,9 @@ discard block |
||
| 648 | 690 | $stripped_query = un_htmlspecialchars($smcFunc['strtolower']($stripped_query)); |
| 649 | 691 | |
| 650 | 692 | // This (hidden) setting will do fulltext searching in the most basic way. |
| 651 | - if (!empty($modSettings['search_simple_fulltext'])) |
|
| 652 | - $stripped_query = strtr($stripped_query, array('"' => '')); |
|
| 693 | + if (!empty($modSettings['search_simple_fulltext'])) { |
|
| 694 | + $stripped_query = strtr($stripped_query, array('"' => '')); |
|
| 695 | + } |
|
| 653 | 696 | |
| 654 | 697 | $no_regexp = preg_match('~&#(?:\d{1,7}|x[0-9a-fA-F]{1,6});~', $stripped_query) === 1; |
| 655 | 698 | |
@@ -672,8 +715,9 @@ discard block |
||
| 672 | 715 | { |
| 673 | 716 | if ($word === '-') |
| 674 | 717 | { |
| 675 | - if (($word = trim($phraseArray[$index], '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) |
|
| 676 | - $excludedWords[] = $word; |
|
| 718 | + if (($word = trim($phraseArray[$index], '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) { |
|
| 719 | + $excludedWords[] = $word; |
|
| 720 | + } |
|
| 677 | 721 | unset($phraseArray[$index]); |
| 678 | 722 | } |
| 679 | 723 | } |
@@ -683,8 +727,9 @@ discard block |
||
| 683 | 727 | { |
| 684 | 728 | if (strpos(trim($word), '-') === 0) |
| 685 | 729 | { |
| 686 | - if (($word = trim($word, '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) |
|
| 687 | - $excludedWords[] = $word; |
|
| 730 | + if (($word = trim($word, '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) { |
|
| 731 | + $excludedWords[] = $word; |
|
| 732 | + } |
|
| 688 | 733 | unset($wordArray[$index]); |
| 689 | 734 | } |
| 690 | 735 | } |
@@ -697,8 +742,9 @@ discard block |
||
| 697 | 742 | foreach ($searchArray as $index => $value) |
| 698 | 743 | { |
| 699 | 744 | // Skip anything practically empty. |
| 700 | - if (($searchArray[$index] = trim($value, '-_\' ')) === '') |
|
| 701 | - unset($searchArray[$index]); |
|
| 745 | + if (($searchArray[$index] = trim($value, '-_\' ')) === '') { |
|
| 746 | + unset($searchArray[$index]); |
|
| 747 | + } |
|
| 702 | 748 | // Skip blacklisted words. Make sure to note we skipped them in case we end up with nothing. |
| 703 | 749 | elseif (in_array($searchArray[$index], $blacklisted_words)) |
| 704 | 750 | { |
@@ -716,31 +762,37 @@ discard block |
||
| 716 | 762 | |
| 717 | 763 | // Create an array of replacements for highlighting. |
| 718 | 764 | $context['mark'] = array(); |
| 719 | - foreach ($searchArray as $word) |
|
| 720 | - $context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>'; |
|
| 765 | + foreach ($searchArray as $word) { |
|
| 766 | + $context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>'; |
|
| 767 | + } |
|
| 721 | 768 | |
| 722 | 769 | // Initialize two arrays storing the words that have to be searched for. |
| 723 | 770 | $orParts = array(); |
| 724 | 771 | $searchWords = array(); |
| 725 | 772 | |
| 726 | 773 | // Make sure at least one word is being searched for. |
| 727 | - if (empty($searchArray)) |
|
| 728 | - $context['search_errors']['invalid_search_string' . (!empty($foundBlackListedWords) ? '_blacklist' : '')] = true; |
|
| 774 | + if (empty($searchArray)) { |
|
| 775 | + $context['search_errors']['invalid_search_string' . (!empty($foundBlackListedWords) ? '_blacklist' : '')] = true; |
|
| 776 | + } |
|
| 729 | 777 | // All words/sentences must match. |
| 730 | - elseif (empty($search_params['searchtype'])) |
|
| 731 | - $orParts[0] = $searchArray; |
|
| 778 | + elseif (empty($search_params['searchtype'])) { |
|
| 779 | + $orParts[0] = $searchArray; |
|
| 780 | + } |
|
| 732 | 781 | // Any word/sentence must match. |
| 733 | - else |
|
| 734 | - foreach ($searchArray as $index => $value) |
|
| 782 | + else { |
|
| 783 | + foreach ($searchArray as $index => $value) |
|
| 735 | 784 | $orParts[$index] = array($value); |
| 785 | + } |
|
| 736 | 786 | |
| 737 | 787 | // Don't allow duplicate error messages if one string is too short. |
| 738 | - if (isset($context['search_errors']['search_string_small_words'], $context['search_errors']['invalid_search_string'])) |
|
| 739 | - unset($context['search_errors']['invalid_search_string']); |
|
| 788 | + if (isset($context['search_errors']['search_string_small_words'], $context['search_errors']['invalid_search_string'])) { |
|
| 789 | + unset($context['search_errors']['invalid_search_string']); |
|
| 790 | + } |
|
| 740 | 791 | // Make sure the excluded words are in all or-branches. |
| 741 | - foreach ($orParts as $orIndex => $andParts) |
|
| 742 | - foreach ($excludedWords as $word) |
|
| 792 | + foreach ($orParts as $orIndex => $andParts) { |
|
| 793 | + foreach ($excludedWords as $word) |
|
| 743 | 794 | $orParts[$orIndex][] = $word; |
| 795 | + } |
|
| 744 | 796 | |
| 745 | 797 | // Determine the or-branches and the fulltext search words. |
| 746 | 798 | foreach ($orParts as $orIndex => $andParts) |
@@ -754,8 +806,9 @@ discard block |
||
| 754 | 806 | ); |
| 755 | 807 | |
| 756 | 808 | // Sort the indexed words (large words -> small words -> excluded words). |
| 757 | - if ($searchAPI->supportsMethod('searchSort')) |
|
| 758 | - usort($orParts[$orIndex], 'searchSort'); |
|
| 809 | + if ($searchAPI->supportsMethod('searchSort')) { |
|
| 810 | + usort($orParts[$orIndex], 'searchSort'); |
|
| 811 | + } |
|
| 759 | 812 | |
| 760 | 813 | foreach ($orParts[$orIndex] as $word) |
| 761 | 814 | { |
@@ -767,15 +820,17 @@ discard block |
||
| 767 | 820 | if (!$is_excluded || count($subjectWords) === 1) |
| 768 | 821 | { |
| 769 | 822 | $searchWords[$orIndex]['subject_words'] = array_merge($searchWords[$orIndex]['subject_words'], $subjectWords); |
| 770 | - if ($is_excluded) |
|
| 771 | - $excludedSubjectWords = array_merge($excludedSubjectWords, $subjectWords); |
|
| 823 | + if ($is_excluded) { |
|
| 824 | + $excludedSubjectWords = array_merge($excludedSubjectWords, $subjectWords); |
|
| 825 | + } |
|
| 826 | + } else { |
|
| 827 | + $excludedPhrases[] = $word; |
|
| 772 | 828 | } |
| 773 | - else |
|
| 774 | - $excludedPhrases[] = $word; |
|
| 775 | 829 | |
| 776 | 830 | // Have we got indexes to prepare? |
| 777 | - if ($searchAPI->supportsMethod('prepareIndexes')) |
|
| 778 | - $searchAPI->prepareIndexes($word, $searchWords[$orIndex], $excludedIndexWords, $is_excluded); |
|
| 831 | + if ($searchAPI->supportsMethod('prepareIndexes')) { |
|
| 832 | + $searchAPI->prepareIndexes($word, $searchWords[$orIndex], $excludedIndexWords, $is_excluded); |
|
| 833 | + } |
|
| 779 | 834 | } |
| 780 | 835 | |
| 781 | 836 | // Search_force_index requires all AND parts to have at least one fulltext word. |
@@ -783,8 +838,7 @@ discard block |
||
| 783 | 838 | { |
| 784 | 839 | $context['search_errors']['query_not_specific_enough'] = true; |
| 785 | 840 | break; |
| 786 | - } |
|
| 787 | - elseif ($search_params['subject_only'] && empty($searchWords[$orIndex]['subject_words']) && empty($excludedSubjectWords)) |
|
| 841 | + } elseif ($search_params['subject_only'] && empty($searchWords[$orIndex]['subject_words']) && empty($excludedSubjectWords)) |
|
| 788 | 842 | { |
| 789 | 843 | $context['search_errors']['query_not_specific_enough'] = true; |
| 790 | 844 | break; |
@@ -812,8 +866,9 @@ discard block |
||
| 812 | 866 | $found_misspelling = false; |
| 813 | 867 | foreach ($searchArray as $word) |
| 814 | 868 | { |
| 815 | - if (empty($link)) |
|
| 816 | - continue; |
|
| 869 | + if (empty($link)) { |
|
| 870 | + continue; |
|
| 871 | + } |
|
| 817 | 872 | |
| 818 | 873 | // Don't check phrases. |
| 819 | 874 | if (preg_match('~^\w+$~', $word) === 0) |
@@ -828,8 +883,7 @@ discard block |
||
| 828 | 883 | $did_you_mean['search'][] = $word; |
| 829 | 884 | $did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word); |
| 830 | 885 | continue; |
| 831 | - } |
|
| 832 | - elseif (spell_check($link, $word)) |
|
| 886 | + } elseif (spell_check($link, $word)) |
|
| 833 | 887 | { |
| 834 | 888 | $did_you_mean['search'][] = $word; |
| 835 | 889 | $did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word); |
@@ -840,11 +894,13 @@ discard block |
||
| 840 | 894 | foreach ($suggestions as $i => $s) |
| 841 | 895 | { |
| 842 | 896 | // Search is case insensitive. |
| 843 | - if ($smcFunc['strtolower']($s) == $smcFunc['strtolower']($word)) |
|
| 844 | - unset($suggestions[$i]); |
|
| 897 | + if ($smcFunc['strtolower']($s) == $smcFunc['strtolower']($word)) { |
|
| 898 | + unset($suggestions[$i]); |
|
| 899 | + } |
|
| 845 | 900 | // Plus, don't suggest something the user thinks is rude! |
| 846 | - elseif ($suggestions[$i] != censorText($s)) |
|
| 847 | - unset($suggestions[$i]); |
|
| 901 | + elseif ($suggestions[$i] != censorText($s)) { |
|
| 902 | + unset($suggestions[$i]); |
|
| 903 | + } |
|
| 848 | 904 | } |
| 849 | 905 | |
| 850 | 906 | // Anything found? If so, correct it! |
@@ -854,8 +910,7 @@ discard block |
||
| 854 | 910 | $did_you_mean['search'][] = $suggestions[0]; |
| 855 | 911 | $did_you_mean['display'][] = '<em><strong>' . $smcFunc['htmlspecialchars']($suggestions[0]) . '</strong></em>'; |
| 856 | 912 | $found_misspelling = true; |
| 857 | - } |
|
| 858 | - else |
|
| 913 | + } else |
|
| 859 | 914 | { |
| 860 | 915 | $did_you_mean['search'][] = $word; |
| 861 | 916 | $did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word); |
@@ -872,8 +927,7 @@ discard block |
||
| 872 | 927 | { |
| 873 | 928 | $temp_excluded['search'][] = '-"' . $word . '"'; |
| 874 | 929 | $temp_excluded['display'][] = '-"' . $smcFunc['htmlspecialchars']($word) . '"'; |
| 875 | - } |
|
| 876 | - else |
|
| 930 | + } else |
|
| 877 | 931 | { |
| 878 | 932 | $temp_excluded['search'][] = '-' . $word; |
| 879 | 933 | $temp_excluded['display'][] = '-' . $smcFunc['htmlspecialchars']($word); |
@@ -885,11 +939,13 @@ discard block |
||
| 885 | 939 | |
| 886 | 940 | $temp_params = $search_params; |
| 887 | 941 | $temp_params['search'] = implode(' ', $did_you_mean['search']); |
| 888 | - if (isset($temp_params['brd'])) |
|
| 889 | - $temp_params['brd'] = implode(',', $temp_params['brd']); |
|
| 942 | + if (isset($temp_params['brd'])) { |
|
| 943 | + $temp_params['brd'] = implode(',', $temp_params['brd']); |
|
| 944 | + } |
|
| 890 | 945 | $context['params'] = array(); |
| 891 | - foreach ($temp_params as $k => $v) |
|
| 892 | - $context['did_you_mean_params'][] = $k . '|\'|' . $v; |
|
| 946 | + foreach ($temp_params as $k => $v) { |
|
| 947 | + $context['did_you_mean_params'][] = $k . '|\'|' . $v; |
|
| 948 | + } |
|
| 893 | 949 | $context['did_you_mean_params'] = base64_encode(implode('|"|', $context['did_you_mean_params'])); |
| 894 | 950 | $context['did_you_mean'] = implode(' ', $did_you_mean['display']); |
| 895 | 951 | } |
@@ -897,18 +953,20 @@ discard block |
||
| 897 | 953 | |
| 898 | 954 | // Let the user adjust the search query, should they wish? |
| 899 | 955 | $context['search_params'] = $search_params; |
| 900 | - if (isset($context['search_params']['search'])) |
|
| 901 | - $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
| 902 | - if (isset($context['search_params']['userspec'])) |
|
| 903 | - $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
| 956 | + if (isset($context['search_params']['search'])) { |
|
| 957 | + $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
| 958 | + } |
|
| 959 | + if (isset($context['search_params']['userspec'])) { |
|
| 960 | + $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
| 961 | + } |
|
| 904 | 962 | |
| 905 | 963 | // Do we have captcha enabled? |
| 906 | 964 | if ($user_info['is_guest'] && !empty($modSettings['search_enable_captcha']) && empty($_SESSION['ss_vv_passed']) && (empty($_SESSION['last_ss']) || $_SESSION['last_ss'] != $search_params['search'])) |
| 907 | 965 | { |
| 908 | 966 | // If we come from another search box tone down the error... |
| 909 | - if (!isset($_REQUEST['search_vv'])) |
|
| 910 | - $context['search_errors']['need_verification_code'] = true; |
|
| 911 | - else |
|
| 967 | + if (!isset($_REQUEST['search_vv'])) { |
|
| 968 | + $context['search_errors']['need_verification_code'] = true; |
|
| 969 | + } else |
|
| 912 | 970 | { |
| 913 | 971 | require_once($sourcedir . '/Subs-Editor.php'); |
| 914 | 972 | $verificationOptions = array( |
@@ -918,12 +976,14 @@ discard block |
||
| 918 | 976 | |
| 919 | 977 | if (is_array($context['require_verification'])) |
| 920 | 978 | { |
| 921 | - foreach ($context['require_verification'] as $error) |
|
| 922 | - $context['search_errors'][$error] = true; |
|
| 979 | + foreach ($context['require_verification'] as $error) { |
|
| 980 | + $context['search_errors'][$error] = true; |
|
| 981 | + } |
|
| 923 | 982 | } |
| 924 | 983 | // Don't keep asking for it - they've proven themselves worthy. |
| 925 | - else |
|
| 926 | - $_SESSION['ss_vv_passed'] = true; |
|
| 984 | + else { |
|
| 985 | + $_SESSION['ss_vv_passed'] = true; |
|
| 986 | + } |
|
| 927 | 987 | } |
| 928 | 988 | } |
| 929 | 989 | |
@@ -931,19 +991,22 @@ discard block |
||
| 931 | 991 | |
| 932 | 992 | // All search params have been checked, let's compile them to a single string... made less simple by PHP 4.3.9 and below. |
| 933 | 993 | $temp_params = $search_params; |
| 934 | - if (isset($temp_params['brd'])) |
|
| 935 | - $temp_params['brd'] = implode(',', $temp_params['brd']); |
|
| 994 | + if (isset($temp_params['brd'])) { |
|
| 995 | + $temp_params['brd'] = implode(',', $temp_params['brd']); |
|
| 996 | + } |
|
| 936 | 997 | $context['params'] = array(); |
| 937 | - foreach ($temp_params as $k => $v) |
|
| 938 | - $context['params'][] = $k . '|\'|' . $v; |
|
| 998 | + foreach ($temp_params as $k => $v) { |
|
| 999 | + $context['params'][] = $k . '|\'|' . $v; |
|
| 1000 | + } |
|
| 939 | 1001 | |
| 940 | 1002 | if (!empty($context['params'])) |
| 941 | 1003 | { |
| 942 | 1004 | // Due to old IE's 2083 character limit, we have to compress long search strings |
| 943 | 1005 | $params = @gzcompress(implode('|"|', $context['params'])); |
| 944 | 1006 | // Gzcompress failed, use try non-gz |
| 945 | - if (empty($params)) |
|
| 946 | - $params = implode('|"|', $context['params']); |
|
| 1007 | + if (empty($params)) { |
|
| 1008 | + $params = implode('|"|', $context['params']); |
|
| 1009 | + } |
|
| 947 | 1010 | // Base64 encode, then replace +/= with uri safe ones that can be reverted |
| 948 | 1011 | $context['params'] = str_replace(array('+', '/', '='), array('-', '_', '.'), base64_encode($params)); |
| 949 | 1012 | } |
@@ -969,8 +1032,9 @@ discard block |
||
| 969 | 1032 | } |
| 970 | 1033 | |
| 971 | 1034 | // Spam me not, Spam-a-lot? |
| 972 | - if (empty($_SESSION['last_ss']) || $_SESSION['last_ss'] != $search_params['search']) |
|
| 973 | - spamProtection('search'); |
|
| 1035 | + if (empty($_SESSION['last_ss']) || $_SESSION['last_ss'] != $search_params['search']) { |
|
| 1036 | + spamProtection('search'); |
|
| 1037 | + } |
|
| 974 | 1038 | // Store the last search string to allow pages of results to be browsed. |
| 975 | 1039 | $_SESSION['last_ss'] = $search_params['search']; |
| 976 | 1040 | |
@@ -1030,8 +1094,9 @@ discard block |
||
| 1030 | 1094 | 'where' => array(), |
| 1031 | 1095 | ); |
| 1032 | 1096 | |
| 1033 | - if ($modSettings['postmod_active']) |
|
| 1034 | - $subject_query['where'][] = 't.approved = {int:is_approved}'; |
|
| 1097 | + if ($modSettings['postmod_active']) { |
|
| 1098 | + $subject_query['where'][] = 't.approved = {int:is_approved}'; |
|
| 1099 | + } |
|
| 1035 | 1100 | |
| 1036 | 1101 | $numTables = 0; |
| 1037 | 1102 | $prev_join = 0; |
@@ -1043,8 +1108,7 @@ discard block |
||
| 1043 | 1108 | { |
| 1044 | 1109 | $subject_query['left_join'][] = '{db_prefix}log_search_subjects AS subj' . $numTables . ' ON (subj' . $numTables . '.word ' . (empty($modSettings['search_match_words']) ? 'LIKE {string:subject_words_' . $numTables . '_wild}' : '= {string:subject_words_' . $numTables . '}') . ' AND subj' . $numTables . '.id_topic = t.id_topic)'; |
| 1045 | 1110 | $subject_query['where'][] = '(subj' . $numTables . '.word IS NULL)'; |
| 1046 | - } |
|
| 1047 | - else |
|
| 1111 | + } else |
|
| 1048 | 1112 | { |
| 1049 | 1113 | $subject_query['inner_join'][] = '{db_prefix}log_search_subjects AS subj' . $numTables . ' ON (subj' . $numTables . '.id_topic = ' . ($prev_join === 0 ? 't' : 'subj' . $prev_join) . '.id_topic)'; |
| 1050 | 1114 | $subject_query['where'][] = 'subj' . $numTables . '.word ' . (empty($modSettings['search_match_words']) ? 'LIKE {string:subject_words_' . $numTables . '_wild}' : '= {string:subject_words_' . $numTables . '}'); |
@@ -1062,14 +1126,18 @@ discard block |
||
| 1062 | 1126 | } |
| 1063 | 1127 | $subject_query['where'][] = $userQuery; |
| 1064 | 1128 | } |
| 1065 | - if (!empty($search_params['topic'])) |
|
| 1066 | - $subject_query['where'][] = 't.id_topic = ' . $search_params['topic']; |
|
| 1067 | - if (!empty($minMsgID)) |
|
| 1068 | - $subject_query['where'][] = 't.id_first_msg >= ' . $minMsgID; |
|
| 1069 | - if (!empty($maxMsgID)) |
|
| 1070 | - $subject_query['where'][] = 't.id_last_msg <= ' . $maxMsgID; |
|
| 1071 | - if (!empty($boardQuery)) |
|
| 1072 | - $subject_query['where'][] = 't.id_board ' . $boardQuery; |
|
| 1129 | + if (!empty($search_params['topic'])) { |
|
| 1130 | + $subject_query['where'][] = 't.id_topic = ' . $search_params['topic']; |
|
| 1131 | + } |
|
| 1132 | + if (!empty($minMsgID)) { |
|
| 1133 | + $subject_query['where'][] = 't.id_first_msg >= ' . $minMsgID; |
|
| 1134 | + } |
|
| 1135 | + if (!empty($maxMsgID)) { |
|
| 1136 | + $subject_query['where'][] = 't.id_last_msg <= ' . $maxMsgID; |
|
| 1137 | + } |
|
| 1138 | + if (!empty($boardQuery)) { |
|
| 1139 | + $subject_query['where'][] = 't.id_board ' . $boardQuery; |
|
| 1140 | + } |
|
| 1073 | 1141 | if (!empty($excludedPhrases)) |
| 1074 | 1142 | { |
| 1075 | 1143 | if ($subject_query['from'] != '{db_prefix}messages AS m') |
@@ -1089,8 +1157,9 @@ discard block |
||
| 1089 | 1157 | foreach ($weight_factors as $type => $value) |
| 1090 | 1158 | { |
| 1091 | 1159 | $relevance .= $weight[$type]; |
| 1092 | - if (!empty($value['results'])) |
|
| 1093 | - $relevance .= ' * ' . $value['results']; |
|
| 1160 | + if (!empty($value['results'])) { |
|
| 1161 | + $relevance .= ' * ' . $value['results']; |
|
| 1162 | + } |
|
| 1094 | 1163 | $relevance .= ' + '; |
| 1095 | 1164 | } |
| 1096 | 1165 | $relevance = substr($relevance, 0, -3) . ') / ' . $weight_total . ' AS relevance'; |
@@ -1128,20 +1197,23 @@ discard block |
||
| 1128 | 1197 | while ($row = $smcFunc['db_fetch_row']($ignoreRequest)) |
| 1129 | 1198 | { |
| 1130 | 1199 | // No duplicates! |
| 1131 | - if (isset($inserts[$row[1]])) |
|
| 1132 | - continue; |
|
| 1200 | + if (isset($inserts[$row[1]])) { |
|
| 1201 | + continue; |
|
| 1202 | + } |
|
| 1133 | 1203 | |
| 1134 | - foreach ($row as $key => $value) |
|
| 1135 | - $inserts[$row[1]][] = (int) $row[$key]; |
|
| 1204 | + foreach ($row as $key => $value) { |
|
| 1205 | + $inserts[$row[1]][] = (int) $row[$key]; |
|
| 1206 | + } |
|
| 1136 | 1207 | } |
| 1137 | 1208 | $smcFunc['db_free_result']($ignoreRequest); |
| 1138 | 1209 | $numSubjectResults = count($inserts); |
| 1210 | + } else { |
|
| 1211 | + $numSubjectResults += $smcFunc['db_affected_rows'](); |
|
| 1139 | 1212 | } |
| 1140 | - else |
|
| 1141 | - $numSubjectResults += $smcFunc['db_affected_rows'](); |
|
| 1142 | 1213 | |
| 1143 | - if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results']) |
|
| 1144 | - break; |
|
| 1214 | + if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results']) { |
|
| 1215 | + break; |
|
| 1216 | + } |
|
| 1145 | 1217 | } |
| 1146 | 1218 | |
| 1147 | 1219 | // If there's data to be inserted for non-IGNORE databases do it here! |
@@ -1156,8 +1228,7 @@ discard block |
||
| 1156 | 1228 | } |
| 1157 | 1229 | |
| 1158 | 1230 | $_SESSION['search_cache']['num_results'] = $numSubjectResults; |
| 1159 | - } |
|
| 1160 | - else |
|
| 1231 | + } else |
|
| 1161 | 1232 | { |
| 1162 | 1233 | $main_query = array( |
| 1163 | 1234 | 'select' => array( |
@@ -1189,8 +1260,7 @@ discard block |
||
| 1189 | 1260 | $main_query['weights'] = $weight_factors; |
| 1190 | 1261 | |
| 1191 | 1262 | $main_query['group_by'][] = 't.id_topic'; |
| 1192 | - } |
|
| 1193 | - else |
|
| 1263 | + } else |
|
| 1194 | 1264 | { |
| 1195 | 1265 | // This is outrageous! |
| 1196 | 1266 | $main_query['select']['id_topic'] = 'm.id_msg AS id_topic'; |
@@ -1211,8 +1281,9 @@ discard block |
||
| 1211 | 1281 | $main_query['where'][] = 't.id_topic = {int:topic}'; |
| 1212 | 1282 | $main_query['parameters']['topic'] = $search_params['topic']; |
| 1213 | 1283 | } |
| 1214 | - if (!empty($search_params['show_complete'])) |
|
| 1215 | - $main_query['group_by'][] = 'm.id_msg, t.id_first_msg, t.id_last_msg'; |
|
| 1284 | + if (!empty($search_params['show_complete'])) { |
|
| 1285 | + $main_query['group_by'][] = 'm.id_msg, t.id_first_msg, t.id_last_msg'; |
|
| 1286 | + } |
|
| 1216 | 1287 | } |
| 1217 | 1288 | |
| 1218 | 1289 | // *** Get the subject results. |
@@ -1237,14 +1308,15 @@ discard block |
||
| 1237 | 1308 | ) !== false; |
| 1238 | 1309 | |
| 1239 | 1310 | // Clean up some previous cache. |
| 1240 | - if (!$createTemporary) |
|
| 1241 | - $smcFunc['db_search_query']('delete_log_search_topics', ' |
|
| 1311 | + if (!$createTemporary) { |
|
| 1312 | + $smcFunc['db_search_query']('delete_log_search_topics', ' |
|
| 1242 | 1313 | DELETE FROM {db_prefix}log_search_topics |
| 1243 | 1314 | WHERE id_search = {int:search_id}', |
| 1244 | 1315 | array( |
| 1245 | 1316 | 'search_id' => $_SESSION['search_cache']['id_search'], |
| 1246 | 1317 | ) |
| 1247 | 1318 | ); |
| 1319 | + } |
|
| 1248 | 1320 | |
| 1249 | 1321 | foreach ($searchWords as $orIndex => $words) |
| 1250 | 1322 | { |
@@ -1276,8 +1348,7 @@ discard block |
||
| 1276 | 1348 | $subject_query['where'][] = '(subj' . $numTables . '.word IS NULL)'; |
| 1277 | 1349 | $subject_query['where'][] = 'm.body NOT ' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:body_not_' . $count . '}'; |
| 1278 | 1350 | $subject_query['params']['body_not_' . $count++] = empty($modSettings['search_match_words']) || $no_regexp ? '%' . strtr($subjectWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $subjectWord), '\\\'') . '[[:>:]]'; |
| 1279 | - } |
|
| 1280 | - else |
|
| 1351 | + } else |
|
| 1281 | 1352 | { |
| 1282 | 1353 | $subject_query['inner_join'][] = '{db_prefix}log_search_subjects AS subj' . $numTables . ' ON (subj' . $numTables . '.id_topic = ' . ($prev_join === 0 ? 't' : 'subj' . $prev_join) . '.id_topic)'; |
| 1283 | 1354 | $subject_query['where'][] = 'subj' . $numTables . '.word LIKE {string:subject_like_' . $count . '}'; |
@@ -1332,8 +1403,9 @@ discard block |
||
| 1332 | 1403 | call_integration_hook('integrate_subject_search_query', array(&$subject_query)); |
| 1333 | 1404 | |
| 1334 | 1405 | // Nothing to search for? |
| 1335 | - if (empty($subject_query['where'])) |
|
| 1336 | - continue; |
|
| 1406 | + if (empty($subject_query['where'])) { |
|
| 1407 | + continue; |
|
| 1408 | + } |
|
| 1337 | 1409 | |
| 1338 | 1410 | $ignoreRequest = $smcFunc['db_search_query']('insert_log_search_topics', ($smcFunc['db_support_ignore'] ? ( ' |
| 1339 | 1411 | INSERT IGNORE INTO {db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_topics |
@@ -1356,19 +1428,21 @@ discard block |
||
| 1356 | 1428 | { |
| 1357 | 1429 | $ind = $createTemporary ? 0 : 1; |
| 1358 | 1430 | // No duplicates! |
| 1359 | - if (isset($inserts[$row[$ind]])) |
|
| 1360 | - continue; |
|
| 1431 | + if (isset($inserts[$row[$ind]])) { |
|
| 1432 | + continue; |
|
| 1433 | + } |
|
| 1361 | 1434 | |
| 1362 | 1435 | $inserts[$row[$ind]] = $row; |
| 1363 | 1436 | } |
| 1364 | 1437 | $smcFunc['db_free_result']($ignoreRequest); |
| 1365 | 1438 | $numSubjectResults = count($inserts); |
| 1439 | + } else { |
|
| 1440 | + $numSubjectResults += $smcFunc['db_affected_rows'](); |
|
| 1366 | 1441 | } |
| 1367 | - else |
|
| 1368 | - $numSubjectResults += $smcFunc['db_affected_rows'](); |
|
| 1369 | 1442 | |
| 1370 | - if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results']) |
|
| 1371 | - break; |
|
| 1443 | + if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results']) { |
|
| 1444 | + break; |
|
| 1445 | + } |
|
| 1372 | 1446 | } |
| 1373 | 1447 | |
| 1374 | 1448 | // Got some non-MySQL data to plonk in? |
@@ -1386,8 +1460,9 @@ discard block |
||
| 1386 | 1460 | { |
| 1387 | 1461 | $main_query['weights']['subject']['search'] = 'CASE WHEN MAX(lst.id_topic) IS NULL THEN 0 ELSE 1 END'; |
| 1388 | 1462 | $main_query['left_join'][] = '{db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_topics AS lst ON (' . ($createTemporary ? '' : 'lst.id_search = {int:id_search} AND ') . 'lst.id_topic = t.id_topic)'; |
| 1389 | - if (!$createTemporary) |
|
| 1390 | - $main_query['parameters']['id_search'] = $_SESSION['search_cache']['id_search']; |
|
| 1463 | + if (!$createTemporary) { |
|
| 1464 | + $main_query['parameters']['id_search'] = $_SESSION['search_cache']['id_search']; |
|
| 1465 | + } |
|
| 1391 | 1466 | } |
| 1392 | 1467 | } |
| 1393 | 1468 | |
@@ -1413,14 +1488,15 @@ discard block |
||
| 1413 | 1488 | ) !== false; |
| 1414 | 1489 | |
| 1415 | 1490 | // Clear, all clear! |
| 1416 | - if (!$createTemporary) |
|
| 1417 | - $smcFunc['db_search_query']('delete_log_search_messages', ' |
|
| 1491 | + if (!$createTemporary) { |
|
| 1492 | + $smcFunc['db_search_query']('delete_log_search_messages', ' |
|
| 1418 | 1493 | DELETE FROM {db_prefix}log_search_messages |
| 1419 | 1494 | WHERE id_search = {int:id_search}', |
| 1420 | 1495 | array( |
| 1421 | 1496 | 'id_search' => $_SESSION['search_cache']['id_search'], |
| 1422 | 1497 | ) |
| 1423 | 1498 | ); |
| 1499 | + } |
|
| 1424 | 1500 | |
| 1425 | 1501 | foreach ($searchWords as $orIndex => $words) |
| 1426 | 1502 | { |
@@ -1454,19 +1530,21 @@ discard block |
||
| 1454 | 1530 | while ($row = $smcFunc['db_fetch_row']($ignoreRequest)) |
| 1455 | 1531 | { |
| 1456 | 1532 | // No duplicates! |
| 1457 | - if (isset($inserts[$row[0]])) |
|
| 1458 | - continue; |
|
| 1533 | + if (isset($inserts[$row[0]])) { |
|
| 1534 | + continue; |
|
| 1535 | + } |
|
| 1459 | 1536 | |
| 1460 | 1537 | $inserts[$row[0]] = $row; |
| 1461 | 1538 | } |
| 1462 | 1539 | $smcFunc['db_free_result']($ignoreRequest); |
| 1463 | 1540 | $indexedResults = count($inserts); |
| 1541 | + } else { |
|
| 1542 | + $indexedResults += $smcFunc['db_affected_rows'](); |
|
| 1464 | 1543 | } |
| 1465 | - else |
|
| 1466 | - $indexedResults += $smcFunc['db_affected_rows'](); |
|
| 1467 | 1544 | |
| 1468 | - if (!empty($maxMessageResults) && $indexedResults >= $maxMessageResults) |
|
| 1469 | - break; |
|
| 1545 | + if (!empty($maxMessageResults) && $indexedResults >= $maxMessageResults) { |
|
| 1546 | + break; |
|
| 1547 | + } |
|
| 1470 | 1548 | } |
| 1471 | 1549 | } |
| 1472 | 1550 | |
@@ -1486,8 +1564,7 @@ discard block |
||
| 1486 | 1564 | $context['search_errors']['query_not_specific_enough'] = true; |
| 1487 | 1565 | $_REQUEST['params'] = $context['params']; |
| 1488 | 1566 | return PlushSearch1(); |
| 1489 | - } |
|
| 1490 | - elseif (!empty($indexedResults)) |
|
| 1567 | + } elseif (!empty($indexedResults)) |
|
| 1491 | 1568 | { |
| 1492 | 1569 | $main_query['inner_join'][] = '{db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_messages AS lsm ON (lsm.id_msg = m.id_msg)'; |
| 1493 | 1570 | if (!$createTemporary) |
@@ -1509,15 +1586,18 @@ discard block |
||
| 1509 | 1586 | foreach ($words['all_words'] as $regularWord) |
| 1510 | 1587 | { |
| 1511 | 1588 | $where[] = 'm.body' . (in_array($regularWord, $excludedWords) ? ' NOT' : '') . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}'; |
| 1512 | - if (in_array($regularWord, $excludedWords)) |
|
| 1513 | - $where[] = 'm.subject NOT' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}'; |
|
| 1589 | + if (in_array($regularWord, $excludedWords)) { |
|
| 1590 | + $where[] = 'm.subject NOT' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}'; |
|
| 1591 | + } |
|
| 1514 | 1592 | $main_query['parameters']['all_word_body_' . $count++] = empty($modSettings['search_match_words']) || $no_regexp ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]'; |
| 1515 | 1593 | } |
| 1516 | - if (!empty($where)) |
|
| 1517 | - $orWhere[] = count($where) > 1 ? '(' . implode(' AND ', $where) . ')' : $where[0]; |
|
| 1594 | + if (!empty($where)) { |
|
| 1595 | + $orWhere[] = count($where) > 1 ? '(' . implode(' AND ', $where) . ')' : $where[0]; |
|
| 1596 | + } |
|
| 1597 | + } |
|
| 1598 | + if (!empty($orWhere)) { |
|
| 1599 | + $main_query['where'][] = count($orWhere) > 1 ? '(' . implode(' OR ', $orWhere) . ')' : $orWhere[0]; |
|
| 1518 | 1600 | } |
| 1519 | - if (!empty($orWhere)) |
|
| 1520 | - $main_query['where'][] = count($orWhere) > 1 ? '(' . implode(' OR ', $orWhere) . ')' : $orWhere[0]; |
|
| 1521 | 1601 | |
| 1522 | 1602 | if (!empty($userQuery)) |
| 1523 | 1603 | { |
@@ -1555,8 +1635,9 @@ discard block |
||
| 1555 | 1635 | foreach ($main_query['weights'] as $type => $value) |
| 1556 | 1636 | { |
| 1557 | 1637 | $relevance .= $weight[$type]; |
| 1558 | - if (!empty($value['search'])) |
|
| 1559 | - $relevance .= ' * ' . $value['search']; |
|
| 1638 | + if (!empty($value['search'])) { |
|
| 1639 | + $relevance .= ' * ' . $value['search']; |
|
| 1640 | + } |
|
| 1560 | 1641 | $relevance .= ' + '; |
| 1561 | 1642 | $new_weight_total += $weight[$type]; |
| 1562 | 1643 | } |
@@ -1587,11 +1668,13 @@ discard block |
||
| 1587 | 1668 | while ($row = $smcFunc['db_fetch_row']($ignoreRequest)) |
| 1588 | 1669 | { |
| 1589 | 1670 | // No duplicates! |
| 1590 | - if (isset($inserts[$row[2]])) |
|
| 1591 | - continue; |
|
| 1671 | + if (isset($inserts[$row[2]])) { |
|
| 1672 | + continue; |
|
| 1673 | + } |
|
| 1592 | 1674 | |
| 1593 | - foreach ($row as $key => $value) |
|
| 1594 | - $inserts[$row[2]][] = (int) $row[$key]; |
|
| 1675 | + foreach ($row as $key => $value) { |
|
| 1676 | + $inserts[$row[2]][] = (int) $row[$key]; |
|
| 1677 | + } |
|
| 1595 | 1678 | } |
| 1596 | 1679 | $smcFunc['db_free_result']($ignoreRequest); |
| 1597 | 1680 | |
@@ -1599,8 +1682,9 @@ discard block |
||
| 1599 | 1682 | if (!empty($inserts)) |
| 1600 | 1683 | { |
| 1601 | 1684 | $query_columns = array(); |
| 1602 | - foreach ($main_query['select'] as $k => $v) |
|
| 1603 | - $query_columns[$k] = 'int'; |
|
| 1685 | + foreach ($main_query['select'] as $k => $v) { |
|
| 1686 | + $query_columns[$k] = 'int'; |
|
| 1687 | + } |
|
| 1604 | 1688 | |
| 1605 | 1689 | $smcFunc['db_insert']('', |
| 1606 | 1690 | '{db_prefix}log_search_results', |
@@ -1610,21 +1694,23 @@ discard block |
||
| 1610 | 1694 | ); |
| 1611 | 1695 | } |
| 1612 | 1696 | $_SESSION['search_cache']['num_results'] += count($inserts); |
| 1697 | + } else { |
|
| 1698 | + $_SESSION['search_cache']['num_results'] = $smcFunc['db_affected_rows'](); |
|
| 1613 | 1699 | } |
| 1614 | - else |
|
| 1615 | - $_SESSION['search_cache']['num_results'] = $smcFunc['db_affected_rows'](); |
|
| 1616 | 1700 | } |
| 1617 | 1701 | |
| 1618 | 1702 | // Insert subject-only matches. |
| 1619 | 1703 | if ($_SESSION['search_cache']['num_results'] < $modSettings['search_max_results'] && $numSubjectResults !== 0) |
| 1620 | 1704 | { |
| 1621 | 1705 | $relevance = '1000 * ('; |
| 1622 | - foreach ($weight_factors as $type => $value) |
|
| 1623 | - if (isset($value['results'])) |
|
| 1706 | + foreach ($weight_factors as $type => $value) { |
|
| 1707 | + if (isset($value['results'])) |
|
| 1624 | 1708 | { |
| 1625 | 1709 | $relevance .= $weight[$type]; |
| 1626 | - if (!empty($value['results'])) |
|
| 1627 | - $relevance .= ' * ' . $value['results']; |
|
| 1710 | + } |
|
| 1711 | + if (!empty($value['results'])) { |
|
| 1712 | + $relevance .= ' * ' . $value['results']; |
|
| 1713 | + } |
|
| 1628 | 1714 | $relevance .= ' + '; |
| 1629 | 1715 | } |
| 1630 | 1716 | $relevance = substr($relevance, 0, -3) . ') / ' . $weight_total . ' AS relevance'; |
@@ -1658,8 +1744,9 @@ discard block |
||
| 1658 | 1744 | while ($row = $smcFunc['db_fetch_row']($ignoreRequest)) |
| 1659 | 1745 | { |
| 1660 | 1746 | // No duplicates! |
| 1661 | - if (isset($usedIDs[$row[1]])) |
|
| 1662 | - continue; |
|
| 1747 | + if (isset($usedIDs[$row[1]])) { |
|
| 1748 | + continue; |
|
| 1749 | + } |
|
| 1663 | 1750 | |
| 1664 | 1751 | $usedIDs[$row[1]] = true; |
| 1665 | 1752 | $inserts[] = $row; |
@@ -1677,12 +1764,12 @@ discard block |
||
| 1677 | 1764 | ); |
| 1678 | 1765 | } |
| 1679 | 1766 | $_SESSION['search_cache']['num_results'] += count($inserts); |
| 1767 | + } else { |
|
| 1768 | + $_SESSION['search_cache']['num_results'] += $smcFunc['db_affected_rows'](); |
|
| 1680 | 1769 | } |
| 1681 | - else |
|
| 1682 | - $_SESSION['search_cache']['num_results'] += $smcFunc['db_affected_rows'](); |
|
| 1770 | + } elseif ($_SESSION['search_cache']['num_results'] == -1) { |
|
| 1771 | + $_SESSION['search_cache']['num_results'] = 0; |
|
| 1683 | 1772 | } |
| 1684 | - elseif ($_SESSION['search_cache']['num_results'] == -1) |
|
| 1685 | - $_SESSION['search_cache']['num_results'] = 0; |
|
| 1686 | 1773 | } |
| 1687 | 1774 | } |
| 1688 | 1775 | |
@@ -1752,14 +1839,16 @@ discard block |
||
| 1752 | 1839 | ) |
| 1753 | 1840 | ); |
| 1754 | 1841 | $posters = array(); |
| 1755 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1756 | - $posters[] = $row['id_member']; |
|
| 1842 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1843 | + $posters[] = $row['id_member']; |
|
| 1844 | + } |
|
| 1757 | 1845 | $smcFunc['db_free_result']($request); |
| 1758 | 1846 | |
| 1759 | 1847 | call_integration_hook('integrate_search_message_list', array(&$msg_list, &$posters)); |
| 1760 | 1848 | |
| 1761 | - if (!empty($posters)) |
|
| 1762 | - loadMemberData(array_unique($posters)); |
|
| 1849 | + if (!empty($posters)) { |
|
| 1850 | + loadMemberData(array_unique($posters)); |
|
| 1851 | + } |
|
| 1763 | 1852 | |
| 1764 | 1853 | // PG optimization to evade FIND_IN_SET |
| 1765 | 1854 | if ($smcFunc['db_title'] == 'PostgreSQL') |
@@ -1768,8 +1857,9 @@ discard block |
||
| 1768 | 1857 | $msg_list_size = count($msg_list); |
| 1769 | 1858 | for ($i = 0; $i < $msg_list_size; $i++) |
| 1770 | 1859 | { |
| 1771 | - if ($i > 0) |
|
| 1772 | - $orderJoin .= ','; |
|
| 1860 | + if ($i > 0) { |
|
| 1861 | + $orderJoin .= ','; |
|
| 1862 | + } |
|
| 1773 | 1863 | $orderJoin .= '(' . $i . ',' . $msg_list[$i] . ')'; |
| 1774 | 1864 | } |
| 1775 | 1865 | |
@@ -1809,8 +1899,9 @@ discard block |
||
| 1809 | 1899 | ); |
| 1810 | 1900 | |
| 1811 | 1901 | // If there are no results that means the things in the cache got deleted, so pretend we have no topics anymore. |
| 1812 | - if ($smcFunc['db_num_rows']($messages_request) == 0) |
|
| 1813 | - $context['topics'] = array(); |
|
| 1902 | + if ($smcFunc['db_num_rows']($messages_request) == 0) { |
|
| 1903 | + $context['topics'] = array(); |
|
| 1904 | + } |
|
| 1814 | 1905 | |
| 1815 | 1906 | // If we want to know who participated in what then load this now. |
| 1816 | 1907 | if (!empty($modSettings['enableParticipation']) && !$user_info['is_guest']) |
@@ -1828,8 +1919,9 @@ discard block |
||
| 1828 | 1919 | 'limit' => count($participants), |
| 1829 | 1920 | ) |
| 1830 | 1921 | ); |
| 1831 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
| 1832 | - $participants[$row['id_topic']] = true; |
|
| 1922 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
| 1923 | + $participants[$row['id_topic']] = true; |
|
| 1924 | + } |
|
| 1833 | 1925 | $smcFunc['db_free_result']($result); |
| 1834 | 1926 | } |
| 1835 | 1927 | } |
@@ -1838,15 +1930,17 @@ discard block |
||
| 1838 | 1930 | $context['page_index'] = constructPageIndex($scripturl . '?action=search2;params=' . $context['params'], $_REQUEST['start'], $num_results, $modSettings['search_results_per_page'], false); |
| 1839 | 1931 | |
| 1840 | 1932 | // Consider the search complete! |
| 1841 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
| 1842 | - cache_put_data('search_start:' . ($user_info['is_guest'] ? $user_info['ip'] : $user_info['id']), null, 90); |
|
| 1933 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
| 1934 | + cache_put_data('search_start:' . ($user_info['is_guest'] ? $user_info['ip'] : $user_info['id']), null, 90); |
|
| 1935 | + } |
|
| 1843 | 1936 | |
| 1844 | 1937 | $context['key_words'] = &$searchArray; |
| 1845 | 1938 | |
| 1846 | 1939 | // Setup the default topic icons... for checking they exist and the like! |
| 1847 | 1940 | $context['icon_sources'] = array(); |
| 1848 | - foreach ($context['stable_icons'] as $icon) |
|
| 1849 | - $context['icon_sources'][$icon] = 'images_url'; |
|
| 1941 | + foreach ($context['stable_icons'] as $icon) { |
|
| 1942 | + $context['icon_sources'][$icon] = 'images_url'; |
|
| 1943 | + } |
|
| 1850 | 1944 | |
| 1851 | 1945 | $context['sub_template'] = 'results'; |
| 1852 | 1946 | $context['page_title'] = $txt['search_results']; |
@@ -1877,26 +1971,31 @@ discard block |
||
| 1877 | 1971 | global $boards_can, $participants, $smcFunc; |
| 1878 | 1972 | static $recycle_board = null; |
| 1879 | 1973 | |
| 1880 | - if ($recycle_board === null) |
|
| 1881 | - $recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0; |
|
| 1974 | + if ($recycle_board === null) { |
|
| 1975 | + $recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0; |
|
| 1976 | + } |
|
| 1882 | 1977 | |
| 1883 | 1978 | // Remember which message this is. (ie. reply #83) |
| 1884 | 1979 | static $counter = null; |
| 1885 | - if ($counter == null || $reset) |
|
| 1886 | - $counter = $_REQUEST['start'] + 1; |
|
| 1980 | + if ($counter == null || $reset) { |
|
| 1981 | + $counter = $_REQUEST['start'] + 1; |
|
| 1982 | + } |
|
| 1887 | 1983 | |
| 1888 | 1984 | // If the query returned false, bail. |
| 1889 | - if ($messages_request == false) |
|
| 1890 | - return false; |
|
| 1985 | + if ($messages_request == false) { |
|
| 1986 | + return false; |
|
| 1987 | + } |
|
| 1891 | 1988 | |
| 1892 | 1989 | // Start from the beginning... |
| 1893 | - if ($reset) |
|
| 1894 | - return @$smcFunc['db_data_seek']($messages_request, 0); |
|
| 1990 | + if ($reset) { |
|
| 1991 | + return @$smcFunc['db_data_seek']($messages_request, 0); |
|
| 1992 | + } |
|
| 1895 | 1993 | |
| 1896 | 1994 | // Attempt to get the next message. |
| 1897 | 1995 | $message = $smcFunc['db_fetch_assoc']($messages_request); |
| 1898 | - if (!$message) |
|
| 1899 | - return false; |
|
| 1996 | + if (!$message) { |
|
| 1997 | + return false; |
|
| 1998 | + } |
|
| 1900 | 1999 | |
| 1901 | 2000 | // Can't have an empty subject can we? |
| 1902 | 2001 | $message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject']; |
@@ -1935,9 +2034,9 @@ discard block |
||
| 1935 | 2034 | |
| 1936 | 2035 | if ($smcFunc['strlen']($message['body']) > $charLimit) |
| 1937 | 2036 | { |
| 1938 | - if (empty($context['key_words'])) |
|
| 1939 | - $message['body'] = $smcFunc['substr']($message['body'], 0, $charLimit) . '<strong>...</strong>'; |
|
| 1940 | - else |
|
| 2037 | + if (empty($context['key_words'])) { |
|
| 2038 | + $message['body'] = $smcFunc['substr']($message['body'], 0, $charLimit) . '<strong>...</strong>'; |
|
| 2039 | + } else |
|
| 1941 | 2040 | { |
| 1942 | 2041 | $matchString = ''; |
| 1943 | 2042 | $force_partial_word = false; |
@@ -1946,18 +2045,20 @@ discard block |
||
| 1946 | 2045 | $keyword = un_htmlspecialchars($keyword); |
| 1947 | 2046 | $keyword = preg_replace_callback('~(&#(\d{1,7}|x[0-9a-fA-F]{1,6});)~', 'entity_fix__callback', strtr($keyword, array('\\\'' => '\'', '&' => '&'))); |
| 1948 | 2047 | |
| 1949 | - if (preg_match('~[\'\.,/@%&;:(){}\[\]_\-+\\\\]$~', $keyword) != 0 || preg_match('~^[\'\.,/@%&;:(){}\[\]_\-+\\\\]~', $keyword) != 0) |
|
| 1950 | - $force_partial_word = true; |
|
| 2048 | + if (preg_match('~[\'\.,/@%&;:(){}\[\]_\-+\\\\]$~', $keyword) != 0 || preg_match('~^[\'\.,/@%&;:(){}\[\]_\-+\\\\]~', $keyword) != 0) { |
|
| 2049 | + $force_partial_word = true; |
|
| 2050 | + } |
|
| 1951 | 2051 | $matchString .= strtr(preg_quote($keyword, '/'), array('\*' => '.+?')) . '|'; |
| 1952 | 2052 | } |
| 1953 | 2053 | $matchString = un_htmlspecialchars(substr($matchString, 0, -1)); |
| 1954 | 2054 | |
| 1955 | 2055 | $message['body'] = un_htmlspecialchars(strtr($message['body'], array(' ' => ' ', '<br>' => "\n", '[' => '[', ']' => ']', ':' => ':', '@' => '@'))); |
| 1956 | 2056 | |
| 1957 | - if (empty($modSettings['search_method']) || $force_partial_word) |
|
| 1958 | - preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?|^)(' . $matchString . ')(.{0,' . $charLimit . '}[\s\W]|[^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches); |
|
| 1959 | - else |
|
| 1960 | - preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?[\s\W]|^)(' . $matchString . ')([\s\W].{0,' . $charLimit . '}[\s\W]|[\s\W][^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches); |
|
| 2057 | + if (empty($modSettings['search_method']) || $force_partial_word) { |
|
| 2058 | + preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?|^)(' . $matchString . ')(.{0,' . $charLimit . '}[\s\W]|[^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches); |
|
| 2059 | + } else { |
|
| 2060 | + preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?[\s\W]|^)(' . $matchString . ')([\s\W].{0,' . $charLimit . '}[\s\W]|[\s\W][^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches); |
|
| 2061 | + } |
|
| 1961 | 2062 | |
| 1962 | 2063 | $message['body'] = ''; |
| 1963 | 2064 | foreach ($matches[0] as $index => $match) |
@@ -1970,8 +2071,7 @@ discard block |
||
| 1970 | 2071 | // Re-fix the international characters. |
| 1971 | 2072 | $message['body'] = preg_replace_callback('~(&#(\d{1,7}|x[0-9a-fA-F]{1,6});)~', 'entity_fix__callback', $message['body']); |
| 1972 | 2073 | } |
| 1973 | - } |
|
| 1974 | - else |
|
| 2074 | + } else |
|
| 1975 | 2075 | { |
| 1976 | 2076 | // Run BBC interpreter on the message. |
| 1977 | 2077 | $message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']); |
@@ -1990,21 +2090,26 @@ discard block |
||
| 1990 | 2090 | // Sadly, we need to check the icon ain't broke. |
| 1991 | 2091 | if (!empty($modSettings['messageIconChecks_enable'])) |
| 1992 | 2092 | { |
| 1993 | - if (!isset($context['icon_sources'][$message['first_icon']])) |
|
| 1994 | - $context['icon_sources'][$message['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['first_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 1995 | - if (!isset($context['icon_sources'][$message['last_icon']])) |
|
| 1996 | - $context['icon_sources'][$message['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['last_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 1997 | - if (!isset($context['icon_sources'][$message['icon']])) |
|
| 1998 | - $context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 1999 | - } |
|
| 2000 | - else |
|
| 2093 | + if (!isset($context['icon_sources'][$message['first_icon']])) { |
|
| 2094 | + $context['icon_sources'][$message['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['first_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 2095 | + } |
|
| 2096 | + if (!isset($context['icon_sources'][$message['last_icon']])) { |
|
| 2097 | + $context['icon_sources'][$message['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['last_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 2098 | + } |
|
| 2099 | + if (!isset($context['icon_sources'][$message['icon']])) { |
|
| 2100 | + $context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 2101 | + } |
|
| 2102 | + } else |
|
| 2001 | 2103 | { |
| 2002 | - if (!isset($context['icon_sources'][$message['first_icon']])) |
|
| 2003 | - $context['icon_sources'][$message['first_icon']] = 'images_url'; |
|
| 2004 | - if (!isset($context['icon_sources'][$message['last_icon']])) |
|
| 2005 | - $context['icon_sources'][$message['last_icon']] = 'images_url'; |
|
| 2006 | - if (!isset($context['icon_sources'][$message['icon']])) |
|
| 2007 | - $context['icon_sources'][$message['icon']] = 'images_url'; |
|
| 2104 | + if (!isset($context['icon_sources'][$message['first_icon']])) { |
|
| 2105 | + $context['icon_sources'][$message['first_icon']] = 'images_url'; |
|
| 2106 | + } |
|
| 2107 | + if (!isset($context['icon_sources'][$message['last_icon']])) { |
|
| 2108 | + $context['icon_sources'][$message['last_icon']] = 'images_url'; |
|
| 2109 | + } |
|
| 2110 | + if (!isset($context['icon_sources'][$message['icon']])) { |
|
| 2111 | + $context['icon_sources'][$message['icon']] = 'images_url'; |
|
| 2112 | + } |
|
| 2008 | 2113 | } |
| 2009 | 2114 | |
| 2010 | 2115 | // Do we have quote tag enabled? |
@@ -2014,12 +2119,14 @@ discard block |
||
| 2014 | 2119 | $colorClass = 'windowbg'; |
| 2015 | 2120 | |
| 2016 | 2121 | // Sticky topics should get a different color, too. |
| 2017 | - if ($message['is_sticky']) |
|
| 2018 | - $colorClass .= ' sticky'; |
|
| 2122 | + if ($message['is_sticky']) { |
|
| 2123 | + $colorClass .= ' sticky'; |
|
| 2124 | + } |
|
| 2019 | 2125 | |
| 2020 | 2126 | // Locked topics get special treatment as well. |
| 2021 | - if ($message['locked']) |
|
| 2022 | - $colorClass .= ' locked'; |
|
| 2127 | + if ($message['locked']) { |
|
| 2128 | + $colorClass .= ' locked'; |
|
| 2129 | + } |
|
| 2023 | 2130 | |
| 2024 | 2131 | $output = array_merge($context['topics'][$message['id_msg']], array( |
| 2025 | 2132 | 'id' => $message['id_topic'], |
@@ -2163,8 +2270,9 @@ discard block |
||
| 2163 | 2270 | |
| 2164 | 2271 | // Load up the search API we are going to use. |
| 2165 | 2272 | $modSettings['search_index'] = empty($modSettings['search_index']) ? 'standard' : $modSettings['search_index']; |
| 2166 | - if (!file_exists($sourcedir . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.php')) |
|
| 2167 | - fatal_lang_error('search_api_missing'); |
|
| 2273 | + if (!file_exists($sourcedir . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.php')) { |
|
| 2274 | + fatal_lang_error('search_api_missing'); |
|
| 2275 | + } |
|
| 2168 | 2276 | require_once($sourcedir . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.php'); |
| 2169 | 2277 | |
| 2170 | 2278 | // Create an instance of the search API and check it is valid for this version of SMF. |