Verzeichnisstruktur phpBB-2.0.0
- Veröffentlicht
- 03.04.2002
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
functions_search.php
001 <?php
002 /***************************************************************************
003 * functions_search.php
004 * -------------------
005 * begin : Wed Sep 05 2001
006 * copyright : (C) 2002 The phpBB Group
007 * email : support@phpbb.com
008 *
009 * $Id$
010 *
011 ****************************************************************************/
012
013 /***************************************************************************
014 *
015 * This program is free software; you can redistribute it and/or modify
016 * it under the terms of the GNU General Public License as published by
017 * the Free Software Foundation; either version 2 of the License, or
018 * (at your option) any later version.
019 *
020 ***************************************************************************/
021
022 function clean_words($mode, &$entry, &$stopword_list, &$synonym_list)
023 {
024 static $drop_char_match = array('^', '$', '&', '(', ')', '<', '>', '`', '\'', '"', '|', ',', '@', '_', '?', '%', '-', '~', '+', '.', '[', ']', '{', '}', ':', '\\', '/', '=', '#', '\'', ';', '!');
025 static $drop_char_replace = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', '', '', ' ', ' ', ' ', ' ', '', ' ', ' ', '', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' , ' ', ' ', ' ', ' ', ' ', ' ');
026
027 $entry = ' ' . strip_tags(strtolower($entry)) . ' ';
028
029 if ( $mode == 'post' )
030 {
031 // Replace line endings by a space
032 $entry = preg_replace('/[\n\r]/is', ' ', $entry);
033 // HTML entities like
034 $entry = preg_replace('/\b&[a-z]+;\b/', ' ', $entry);
035 // Remove URL's
036 $entry = preg_replace('/\b[a-z0-9]+:\/\/[a-z0-9\.\-]+(\/[a-z0-9\?\.%_\-\+=&\/]+)?/', ' ', $entry);
037 // Quickly remove BBcode.
038 $entry = preg_replace('/\[img:[a-z0-9]{10,}\].*?\[\/img:[a-z0-9]{10,}\]/', ' ', $entry);
039 $entry = preg_replace('/\[\/?url(=.*?)?\]/', ' ', $entry);
040 $entry = preg_replace('/\[\/?[a-z\*=\+\-]+(\:?[0-9a-z]+)?:[a-z0-9]{10,}(\:[a-z0-9]+)?=?.*?\]/', ' ', $entry);
041 }
042 else if ( $mode == 'search' )
043 {
044 $entry = str_replace(' +', ' and ', $entry);
045 $entry = str_replace(' -', ' not ', $entry);
046 }
047
048 //
049 // Filter out strange characters like ^, $, &, change "it's" to "its"
050 //
051 for($i = 0; $i < count($drop_char_match); $i++)
052 {
053 $entry = str_replace($drop_char_match[$i], $drop_char_replace[$i], $entry);
054 }
055
056 if ( $mode == 'post' )
057 {
058 $entry = str_replace('*', ' ', $entry);
059
060 // 'words' that consist of <3 or >20 characters are removed.
061 $entry = preg_replace('/[ ]([\S]{1,2}|[\S]{21,})[ ]/',' ', $entry);
062 }
063
064 if ( !empty($stopword_list) )
065 {
066 for ($j = 0; $j < count($stopword_list); $j++)
067 {
068 $stopword = trim($stopword_list[$j]);
069
070 if ( $mode == 'post' || ( $stopword != 'not' && $stopword != 'and' && $stopword != 'or' ) )
071 {
072 $entry = str_replace(' ' . trim($stopword) . ' ', ' ', $entry);
073 }
074 }
075 }
076
077 if ( !empty($synonym_list) )
078 {
079 for ($j = 0; $j < count($synonym_list); $j++)
080 {
081 list($replace_synonym, $match_synonym) = split(' ', trim(strtolower($synonym_list[$j])));
082 if ( $mode == 'post' || ( $match_synonym != 'not' && $match_synonym != 'and' && $match_synonym != 'or' ) )
083 {
084 $entry = str_replace(' ' . trim($match_synonym) . ' ', ' ' . trim($replace_synonym) . ' ', $entry);
085 }
086 }
087 }
088
089 return $entry;
090 }
091
092 function split_words($entry, $mode = 'post')
093 {
094 // If you experience problems with the new method, uncomment this block.
095 /*
096 $rex = ( $mode == 'post' ) ? "/\b([\w��-�][\w��-�']*[\w��-�]+|[\w��-�]+?)\b/" : '/(\*?[a-z0-9��-�]+\*?)|\b([a-z0-9��-�]+)\b/';
097 preg_match_all($rex, $entry, $split_entries);
098
099 return $split_entries[1];
100 */
101 // Trim 1+ spaces to one space and split this trimmed string into words.
102 return explode(' ', trim(preg_replace('#\s+#', ' ', $entry)));
103 }
104
105 function add_search_words($mode, $post_id, $post_text, $post_title = '')
106 {
107 global $db, $phpbb_root_path, $board_config, $lang;
108
109 $stopword_array = @file($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . "/search_stopwords.txt");
110 $synonym_array = @file($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . "/search_synonyms.txt");
111
112 $search_raw_words = array();
113 $search_raw_words['text'] = split_words(clean_words('post', $post_text, $stopword_array, $synonym_array));
114 $search_raw_words['title'] = split_words(clean_words('post', $post_title, $stopword_array, $synonym_array));
115
116 @set_time_limit(0);
117
118 $word = array();
119 $word_insert_sql = array();
120 while ( list($word_in, $search_matches) = @each($search_raw_words) )
121 {
122 $word_insert_sql[$word_in] = '';
123 if ( !empty($search_matches) )
124 {
125 for ($i = 0; $i < count($search_matches); $i++)
126 {
127 $search_matches[$i] = trim($search_matches[$i]);
128
129 if( $search_matches[$i] != '' )
130 {
131 $word[] = $search_matches[$i];
132 if ( !strstr($word_insert_sql[$word_in], "'" . $search_matches[$i] . "'") )
133 {
134 $word_insert_sql[$word_in] .= ( $word_insert_sql[$word_in] != "" ) ? ", '" . $search_matches[$i] . "'" : "'" . $search_matches[$i] . "'";
135 }
136 }
137 }
138 }
139 }
140
141 if ( count($word) )
142 {
143 sort($word);
144
145 $prev_word = '';
146 $word_text_sql = '';
147 $temp_word = array();
148 for($i = 0; $i < count($word); $i++)
149 {
150 if ( $word[$i] != $prev_word )
151 {
152 $temp_word[] = $word[$i];
153 $word_text_sql .= ( ( $word_text_sql != '' ) ? ', ' : '' ) . "'" . $word[$i] . "'";
154 }
155 $prev_word = $word[$i];
156 }
157 $word = $temp_word;
158
159 $check_words = array();
160 switch( SQL_LAYER )
161 {
162 case 'postgresql':
163 case 'msaccess':
164 case 'mssql-odbc':
165 case 'oracle':
166 case 'db2':
167 $sql = "SELECT word_id, word_text
168 FROM " . SEARCH_WORD_TABLE . "
169 WHERE word_text IN ($word_text_sql)";
170 if ( !($result = $db->sql_query($sql)) )
171 {
172 message_die(GENERAL_ERROR, 'Could not select words', '', __LINE__, __FILE__, $sql);
173 }
174
175 while ( $row = $db->sql_fetchrow($result) )
176 {
177 $check_words[$row['word_text']] = $row['word_id'];
178 }
179 break;
180 }
181
182 $value_sql = '';
183 $match_word = array();
184 for ($i = 0; $i < count($word); $i++)
185 {
186 $new_match = true;
187 if ( isset($check_words[$word[$i]]) )
188 {
189 $new_match = false;
190 }
191
192 if ( $new_match )
193 {
194 switch( SQL_LAYER )
195 {
196 case 'mysql':
197 case 'mysql4':
198 $value_sql .= ( ( $value_sql != '' ) ? ', ' : '' ) . '(\'' . $word[$i] . '\', 0)';
199 break;
200 case 'mssql':
201 case 'mssql-odbc':
202 $value_sql .= ( ( $value_sql != '' ) ? ' UNION ALL ' : '' ) . "SELECT '" . $word[$i] . "', 0";
203 break;
204 default:
205 $sql = "INSERT INTO " . SEARCH_WORD_TABLE . " (word_text, word_common)
206 VALUES ('" . $word[$i] . "', 0)";
207 if( !$db->sql_query($sql) )
208 {
209 message_die(GENERAL_ERROR, 'Could not insert new word', '', __LINE__, __FILE__, $sql);
210 }
211 break;
212 }
213 }
214 }
215
216 if ( $value_sql != '' )
217 {
218 switch ( SQL_LAYER )
219 {
220 case 'mysql':
221 case 'mysql4':
222 $sql = "INSERT IGNORE INTO " . SEARCH_WORD_TABLE . " (word_text, word_common)
223 VALUES $value_sql";
224 break;
225 case 'mssql':
226 case 'mssql-odbc':
227 $sql = "INSERT INTO " . SEARCH_WORD_TABLE . " (word_text, word_common)
228 $value_sql";
229 break;
230 }
231
232 if ( !$db->sql_query($sql) )
233 {
234 message_die(GENERAL_ERROR, 'Could not insert new word', '', __LINE__, __FILE__, $sql);
235 }
236 }
237 }
238
239 while( list($word_in, $match_sql) = @each($word_insert_sql) )
240 {
241 $title_match = ( $word_in == 'title' ) ? 1 : 0;
242
243 if ( $match_sql != '' )
244 {
245 $sql = "INSERT INTO " . SEARCH_MATCH_TABLE . " (post_id, word_id, title_match)
246 SELECT $post_id, word_id, $title_match
247 FROM " . SEARCH_WORD_TABLE . "
248 WHERE word_text IN ($match_sql)
249 AND word_common <> 1";
250 if ( !$db->sql_query($sql) )
251 {
252 message_die(GENERAL_ERROR, 'Could not insert new word matches', '', __LINE__, __FILE__, $sql);
253 }
254 }
255 }
256
257 if ($mode == 'single')
258 {
259 remove_common('single', 4/10, $word);
260 }
261
262 return;
263 }
264
265 //
266 // Check if specified words are too common now
267 //
268 function remove_common($mode, $fraction, $word_id_list = array())
269 {
270 global $db;
271
272 $sql = "SELECT COUNT(post_id) AS total_posts
273 FROM " . POSTS_TABLE;
274 if ( !($result = $db->sql_query($sql)) )
275 {
276 message_die(GENERAL_ERROR, 'Could not obtain post count', '', __LINE__, __FILE__, $sql);
277 }
278
279 $row = $db->sql_fetchrow($result);
280
281 if ( $row['total_posts'] >= 100 )
282 {
283 $common_threshold = floor($row['total_posts'] * $fraction);
284
285 if ( $mode == 'single' && count($word_id_list) )
286 {
287 $word_id_sql = '';
288 for($i = 0; $i < count($word_id_list); $i++)
289 {
290 $word_id_sql .= ( ( $word_id_sql != '' ) ? ', ' : '' ) . "'" . $word_id_list[$i] . "'";
291 }
292
293 $sql = "SELECT m.word_id
294 FROM " . SEARCH_MATCH_TABLE . " m, " . SEARCH_WORD_TABLE . " w
295 WHERE w.word_text IN ($word_id_sql)
296 AND m.word_id = w.word_id
297 GROUP BY m.word_id
298 HAVING COUNT(m.word_id) > $common_threshold";
299 }
300 else
301 {
302 $sql = "SELECT word_id
303 FROM " . SEARCH_MATCH_TABLE . "
304 GROUP BY word_id
305 HAVING COUNT(word_id) > $common_threshold";
306 }
307
308 if ( !($result = $db->sql_query($sql)) )
309 {
310 message_die(GENERAL_ERROR, 'Could not obtain common word list', '', __LINE__, __FILE__, $sql);
311 }
312
313 $common_word_id = '';
314 while ( $row = $db->sql_fetchrow($result) )
315 {
316 $common_word_id .= ( ( $common_word_id != '' ) ? ', ' : '' ) . $row['word_id'];
317 }
318 $db->sql_freeresult($result);
319
320 if ( $common_word_id != '' )
321 {
322 $sql = "UPDATE " . SEARCH_WORD_TABLE . "
323 SET word_common = " . TRUE . "
324 WHERE word_id IN ($common_word_id)";
325 if ( !$db->sql_query($sql) )
326 {
327 message_die(GENERAL_ERROR, 'Could not delete word list entry', '', __LINE__, __FILE__, $sql);
328 }
329
330 $sql = "DELETE FROM " . SEARCH_MATCH_TABLE . "
331 WHERE word_id IN ($common_word_id)";
332 if ( !$db->sql_query($sql) )
333 {
334 message_die(GENERAL_ERROR, 'Could not delete word match entry', '', __LINE__, __FILE__, $sql);
335 }
336 }
337 }
338
339 return;
340 }
341
342 function remove_search_post($post_id_sql)
343 {
344 global $db;
345
346 $words_removed = false;
347
348 switch ( SQL_LAYER )
349 {
350 case 'mysql':
351 case 'mysql4':
352 $sql = "SELECT word_id
353 FROM " . SEARCH_MATCH_TABLE . "
354 WHERE post_id IN ($post_id_sql)
355 GROUP BY word_id";
356 if ( $result = $db->sql_query($sql) )
357 {
358 $word_id_sql = '';
359 while ( $row = $db->sql_fetchrow($result) )
360 {
361 $word_id_sql .= ( $word_id_sql != '' ) ? ', ' . $row['word_id'] : $row['word_id'];
362 }
363
364 $sql = "SELECT word_id
365 FROM " . SEARCH_MATCH_TABLE . "
366 WHERE word_id IN ($word_id_sql)
367 GROUP BY word_id
368 HAVING COUNT(word_id) = 1";
369 if ( $result = $db->sql_query($sql) )
370 {
371 $word_id_sql = '';
372 while ( $row = $db->sql_fetchrow($result) )
373 {
374 $word_id_sql .= ( $word_id_sql != '' ) ? ', ' . $row['word_id'] : $row['word_id'];
375 }
376
377 if ( $word_id_sql != '' )
378 {
379 $sql = "DELETE FROM " . SEARCH_WORD_TABLE . "
380 WHERE word_id IN ($word_id_sql)";
381 if ( !$db->sql_query($sql) )
382 {
383 message_die(GENERAL_ERROR, 'Could not delete word list entry', '', __LINE__, __FILE__, $sql);
384 }
385
386 $words_removed = $db->sql_affectedrows();
387 }
388 }
389 }
390 break;
391
392 default:
393 $sql = "DELETE FROM " . SEARCH_WORD_TABLE . "
394 WHERE word_id IN (
395 SELECT word_id
396 FROM " . SEARCH_MATCH_TABLE . "
397 WHERE word_id IN (
398 SELECT word_id
399 FROM " . SEARCH_MATCH_TABLE . "
400 WHERE post_id IN ($post_id_sql)
401 GROUP BY word_id
402 )
403 GROUP BY word_id
404 HAVING COUNT(word_id) = 1
405 )";
406 if ( !$db->sql_query($sql) )
407 {
408 message_die(GENERAL_ERROR, 'Could not delete old words from word table', '', __LINE__, __FILE__, $sql);
409 }
410
411 $words_removed = $db->sql_affectedrows();
412
413 break;
414 }
415
416 $sql = "DELETE FROM " . SEARCH_MATCH_TABLE . "
417 WHERE post_id IN ($post_id_sql)";
418 if ( !$db->sql_query($sql) )
419 {
420 message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
421 }
422
423 return $words_removed;
424 }
425
426 //
427 // Username search
428 //
429 function username_search($search_match)
430 {
431 global $db, $board_config, $template, $lang, $images, $theme, $phpEx, $phpbb_root_path;
432 global $starttime, $gen_simple_header;
433
434 $gen_simple_header = TRUE;
435
436 $username_list = '';
437 if ( !empty($search_match) )
438 {
439 $username_search = preg_replace('/\*/', '%', phpbb_clean_username($search_match));
440
441 $sql = "SELECT username
442 FROM " . USERS_TABLE . "
443 WHERE username LIKE '" . str_replace("\'", "''", $username_search) . "' AND user_id <> " . ANONYMOUS . "
444 ORDER BY username";
445 if ( !($result = $db->sql_query($sql)) )
446 {
447 message_die(GENERAL_ERROR, 'Could not obtain search results', '', __LINE__, __FILE__, $sql);
448 }
449
450 if ( $row = $db->sql_fetchrow($result) )
451 {
452 do
453 {
454 $username_list .= '<option value="' . $row['username'] . '">' . $row['username'] . '</option>';
455 }
456 while ( $row = $db->sql_fetchrow($result) );
457 }
458 else
459 {
460 $username_list .= '<option>' . $lang['No_match']. '</option>';
461 }
462 $db->sql_freeresult($result);
463 }
464
465 $page_title = $lang['Search'];
466 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
467
468 $template->set_filenames(array(
469 'search_user_body' => 'search_username.tpl')
470 );
471
472 $template->assign_vars(array(
473 'USERNAME' => (!empty($search_match)) ? phpbb_clean_username($search_match) : '',
474
475 'L_CLOSE_WINDOW' => $lang['Close_window'],
476 'L_SEARCH_USERNAME' => $lang['Find_username'],
477 'L_UPDATE_USERNAME' => $lang['Select_username'],
478 'L_SELECT' => $lang['Select'],
479 'L_SEARCH' => $lang['Search'],
480 'L_SEARCH_EXPLAIN' => $lang['Search_author_explain'],
481 'L_CLOSE_WINDOW' => $lang['Close_window'],
482
483 'S_USERNAME_OPTIONS' => $username_list,
484 'S_SEARCH_ACTION' => append_sid("search.$phpEx?mode=searchuser"))
485 );
486
487 if ( $username_list != '' )
488 {
489 $template->assign_block_vars('switch_select_name', array());
490 }
491
492 $template->pparse('search_user_body');
493
494 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
495
496 return;
497 }
498
499 ?>