6 |
kaklik |
1 |
<?php
|
|
|
2 |
/*************************
|
|
|
3 |
Coppermine Photo Gallery
|
|
|
4 |
************************
|
|
|
5 |
Copyright (c) 2003-2005 Coppermine Dev Team
|
|
|
6 |
v1.1 originaly written by Gregory DEMAR
|
|
|
7 |
|
|
|
8 |
This program is free software; you can redistribute it and/or modify
|
|
|
9 |
it under the terms of the GNU General Public License as published by
|
|
|
10 |
the Free Software Foundation; either version 2 of the License, or
|
|
|
11 |
(at your option) any later version.
|
|
|
12 |
********************************************
|
|
|
13 |
Coppermine version: 1.3.3
|
|
|
14 |
$Source: /cvsroot/coppermine/stable/include/search.inc.php,v $
|
|
|
15 |
$Revision: 1.6 $
|
|
|
16 |
$Author: gaugau $
|
|
|
17 |
$Date: 2005/04/19 03:17:11 $
|
|
|
18 |
**********************************************/
|
|
|
19 |
|
|
|
20 |
/**
|
|
|
21 |
* functions_search.php
|
|
|
22 |
*
|
|
|
23 |
* -------------------
|
|
|
24 |
*
|
|
|
25 |
* begin : Wed Sep 05 2001
|
|
|
26 |
*
|
|
|
27 |
* copyright : (C) 2001 The phpBB Group
|
|
|
28 |
*
|
|
|
29 |
* email : support@phpbb.com
|
|
|
30 |
*
|
|
|
31 |
*
|
|
|
32 |
*
|
|
|
33 |
* $Id: search.inc.php,v 1.6 2005/04/19 03:17:11 gaugau Exp $
|
|
|
34 |
*/
|
|
|
35 |
|
|
|
36 |
// encoding match for workaround
|
|
|
37 |
|
|
|
38 |
$multibyte_charset = 'utf-8, big5, shift_jis, euc-kr, gb2312';
|
|
|
39 |
|
|
|
40 |
$charset = $CONFIG['charset'] == 'language file' ? $GLOBALS['lang_charset'] : $CONFIG['charset'];
|
|
|
41 |
|
|
|
42 |
$mb_charset = stristr($multibyte_charset, $charset);
|
|
|
43 |
|
|
|
44 |
function clean_words(&$entry, $mb_charset)
|
|
|
45 |
{
|
|
|
46 |
global $charset, $multibyte_charset;
|
|
|
47 |
|
|
|
48 |
static $drop_char_match = array('^', '$', '&', '(', ')', '<', '>', '`', '\'', '"', '|', ',', '@', '_', '?', '%', '~', '.', '[', ']', '{', '}', ':', '\\', '/', '=', '#', '\'', ';', '!');
|
|
|
49 |
|
|
|
50 |
static $drop_char_replace = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', '', '', ' ', ' ', ' ', ' ', '', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' , ' ', ' ', ' ', ' ', ' ', ' ');
|
|
|
51 |
|
|
|
52 |
$entry = ' ' . strtolower($entry) . ' ';
|
|
|
53 |
// Replace line endings by a space
|
|
|
54 |
$entry = preg_replace('/[\n\r]/is', ' ', $entry);
|
|
|
55 |
// + and - becomes and & not
|
|
|
56 |
$entry = str_replace(' +', ' and ', $entry);
|
|
|
57 |
|
|
|
58 |
$entry = str_replace(' -', ' not ', $entry);
|
|
|
59 |
|
|
|
60 |
// Filter out strange characters like ^, $, &, change "it's" to "its"
|
|
|
61 |
|
|
|
62 |
if (!$mb_charset) for($i = 0; $i < count($drop_char_match); $i++) {
|
|
|
63 |
$entry = str_replace($drop_char_match[$i], $drop_char_replace[$i], $entry);
|
|
|
64 |
}
|
|
|
65 |
// 'words' that consist of <3 or >20 characters are removed.
|
|
|
66 |
// $entry = preg_replace('/\b([a-z0-9]{1,2}|[a-z0-9]{21,})\b/',' ', $entry);
|
|
|
67 |
return $entry;
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
if (defined('USE_MYSQL_SEARCH') && $query_all) {
|
|
|
71 |
// If using MySQL 4 or above we use boolean search
|
|
|
72 |
$mysql_version = mysql_get_server_info();
|
|
|
73 |
|
|
|
74 |
if ($mysql_version >= '4') {
|
|
|
75 |
$boolean_mode = 'IN BOOLEAN MODE';
|
|
|
76 |
} else {
|
|
|
77 |
$boolean_mode = '';
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
$result = db_query("SELECT COUNT(*) FROM {$CONFIG['TABLE_PICTURES']} WHERE MATCH(filename, title, caption, keywords) AGAINST ('$search_string' $boolean_mode) AND approved = 'YES' $ALBUM_SET");
|
|
|
81 |
|
|
|
82 |
$nbEnr = mysql_fetch_array($result);
|
|
|
83 |
|
|
|
84 |
$count = $nbEnr[0];
|
|
|
85 |
|
|
|
86 |
mysql_free_result($result);
|
|
|
87 |
|
|
|
88 |
if ($select_columns != '*') $select_columns .= ', title, caption';
|
|
|
89 |
|
|
|
90 |
$result = db_query("SELECT $select_columns FROM {$CONFIG['TABLE_PICTURES']} WHERE MATCH(filename, title, caption, keywords) AGAINST ('$search_string' $boolean_mode) AND approved = 'YES' $ALBUM_SET $limit");
|
|
|
91 |
|
|
|
92 |
$rowset = db_fetch_rowset($result);
|
|
|
93 |
|
|
|
94 |
mysql_free_result($result);
|
|
|
95 |
|
|
|
96 |
if ($set_caption) foreach ($rowset as $key => $row) {
|
|
|
97 |
$caption = $rowset[$key]['title'] ? "<span class=\"thumb_title\">" . $rowset[$key]['title'] . "</span>" : '';
|
|
|
98 |
|
|
|
99 |
if ($CONFIG['caption_in_thumbview']) {
|
|
|
100 |
$caption .= $rowset[$key]['caption'] ? "<span class=\"thumb_caption\">" . bb_decode($rowset[$key]['caption']) . "</span>" : '';
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
$rowset[$key]['caption_text'] = $caption;
|
|
|
104 |
}
|
|
|
105 |
} elseif ($search_string != '') {
|
|
|
106 |
$split_search = array();
|
|
|
107 |
|
|
|
108 |
$split_search = split(' ', clean_words($search_string, $mb_charset));
|
|
|
109 |
|
|
|
110 |
$current_match_type = 'and';
|
|
|
111 |
|
|
|
112 |
$pic_set = '';
|
|
|
113 |
|
|
|
114 |
for($i = 0; $i < count($split_search); $i++) {
|
|
|
115 |
switch ($split_search[$i]) {
|
|
|
116 |
case 'and':
|
|
|
117 |
|
|
|
118 |
$current_match_type = 'and';
|
|
|
119 |
|
|
|
120 |
break;
|
|
|
121 |
|
|
|
122 |
case 'or':
|
|
|
123 |
|
|
|
124 |
$current_match_type = 'or';
|
|
|
125 |
|
|
|
126 |
break;
|
|
|
127 |
|
|
|
128 |
case 'not':
|
|
|
129 |
|
|
|
130 |
$current_match_type = 'not';
|
|
|
131 |
|
|
|
132 |
break;
|
|
|
133 |
|
|
|
134 |
default:
|
|
|
135 |
|
|
|
136 |
if (empty($split_search[$i])) break;
|
|
|
137 |
|
|
|
138 |
$match_word = '%' . str_replace('*', '%', addslashes($split_search[$i])) . '%';
|
|
|
139 |
|
|
|
140 |
$match_keyword = '% ' . str_replace('*', '%', addslashes($split_search[$i])) . ' %';
|
|
|
141 |
|
|
|
142 |
$sql = "SELECT pid " . "FROM {$CONFIG['TABLE_PICTURES']} " . "WHERE CONCAT(' ', keywords, ' ') LIKE '$match_keyword' ";
|
|
|
143 |
|
|
|
144 |
if ($query_all) $sql .= "OR filename LIKE '$match_word' " . "OR title LIKE '$match_word' " . "OR caption LIKE '$match_word' " . "OR user1 LIKE '$match_word' " . "OR user2 LIKE '$match_word' " . "OR user3 LIKE '$match_word' " . "OR user4 LIKE '$match_word' ";
|
|
|
145 |
|
|
|
146 |
$result = db_query($sql);
|
|
|
147 |
|
|
|
148 |
$set = '';
|
|
|
149 |
|
|
|
150 |
while ($row = mysql_fetch_array($result)) {
|
|
|
151 |
$set .= $row['pid'] . ',';
|
|
|
152 |
} // while
|
|
|
153 |
if (empty($set)) {
|
|
|
154 |
$set = "'',";
|
|
|
155 |
}
|
|
|
156 |
|
|
|
157 |
if (empty($pic_set)) {
|
|
|
158 |
if ($current_match_type == 'not') {
|
|
|
159 |
$pic_set .= ' pid not in (' . substr($set, 0, -1) . ') ';
|
|
|
160 |
} else {
|
|
|
161 |
$pic_set .= ' pid in (' . substr($set, 0, -1) . ') ';
|
|
|
162 |
}
|
|
|
163 |
} else {
|
|
|
164 |
if ($current_match_type == 'not') {
|
|
|
165 |
$pic_set .= ' and pid not in (' . substr($set, 0, -1) . ') ';
|
|
|
166 |
} else {
|
|
|
167 |
$pic_set .= ' ' . $current_match_type . ' pid in (' . substr($set, 0, -1) . ') ';
|
|
|
168 |
}
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
mysql_free_result($result);
|
|
|
172 |
|
|
|
173 |
$current_match_type = 'and';
|
|
|
174 |
}
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
if (!empty($pic_set)) {
|
|
|
178 |
$sql = "SELECT COUNT(*) " . "FROM {$CONFIG['TABLE_PICTURES']} " . "WHERE ($pic_set) " . "AND approved = 'YES' " . "$ALBUM_SET";
|
|
|
179 |
|
|
|
180 |
$result = db_query($sql);
|
|
|
181 |
|
|
|
182 |
$nbEnr = mysql_fetch_array($result);
|
|
|
183 |
|
|
|
184 |
$count = $nbEnr[0];
|
|
|
185 |
|
|
|
186 |
mysql_free_result($result);
|
|
|
187 |
|
|
|
188 |
if ($select_columns != '*') $select_columns .= ', title, caption';
|
|
|
189 |
|
|
|
190 |
$sql = "SELECT $select_columns " . "FROM {$CONFIG['TABLE_PICTURES']} " . "WHERE ($pic_set) " . "AND approved = 'YES' " . "$ALBUM_SET $limit";
|
|
|
191 |
|
|
|
192 |
$result = db_query($sql);
|
|
|
193 |
|
|
|
194 |
$rowset = db_fetch_rowset($result);
|
|
|
195 |
|
|
|
196 |
mysql_free_result($result);
|
|
|
197 |
|
|
|
198 |
if ($set_caption) foreach ($rowset as $key => $row) {
|
|
|
199 |
$caption = $rowset[$key]['title'] ? "<span class=\"thumb_title\">" . $rowset[$key]['title'] . "</span>" : '';
|
|
|
200 |
|
|
|
201 |
if ($CONFIG['caption_in_thumbview']) {
|
|
|
202 |
$caption .= $rowset[$key]['caption'] ? "<span class=\"thumb_caption\">" . bb_decode($rowset[$key]['caption']) . "</span>" : '';
|
|
|
203 |
}
|
|
|
204 |
|
|
|
205 |
$rowset[$key]['caption_text'] = $caption;
|
|
|
206 |
}
|
|
|
207 |
} else {
|
|
|
208 |
$count = 0;
|
|
|
209 |
|
|
|
210 |
$rowset = array();
|
|
|
211 |
}
|
|
|
212 |
} else {
|
|
|
213 |
$count = 0;
|
|
|
214 |
|
|
|
215 |
$rowset = array();
|
|
|
216 |
}
|
|
|
217 |
|
|
|
218 |
?>
|