1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
|
/* Thread durchsuchen by Viktor */
if ($_GET['action'] == 'sthread') {
$searchstring = wbb_trim($_POST['searchthread']);
$sthreadid = intval($_POST['threadid']);
if (!$searchstring) redirect($lang->get("LANG_SEARCH_ERROR_INVALIDSEARCH"), "thread.php?threadid=" . $sthreadid . $SID_ARG_1ST);
$postids = '';
if ($searchstring) {
$searchstring = preg_replace("/( \+|^\+)/s", " AND ", $searchstring);
$searchstring = preg_replace("/( \-|^\-)/s", " NOT ", $searchstring);
$searchstring = preg_replace("/[\/,\.:;\(\)\[\]?!#{}%_\-+=\\\\]/s", " ", $searchstring);
$searchstring = preg_replace("/['\"]/s", "", $searchstring);
$searchstring = preg_replace("/\s{2,}/", " ", $searchstring);
$tempsearchstring = $searchstring;
$searchstring = str_replace("*", "%", $searchstring);
$searchstring = preg_replace("/(%){2,}/s", "%", $searchstring);
$searchwords = preg_split("/[\s]/", wbb_strtolower($searchstring), - 1, PREG_SPLIT_NO_EMPTY);
$badwords = array();
if ($badsearchwords) {
$temp = explode("\n", wbb_strtolower($badsearchwords));
while (list($key, $val) = each($temp)) $badwords[wbb_trim($val)] = 1;
}
$goodwords = array();
if ($goodsearchwords) {
$temp = explode("\n", wbb_strtolower($goodsearchwords));
while (list($key, $val) = each($temp)) {
unset($badwords[wbb_trim($val)]);
$goodwords[wbb_trim($val)] = 1;
}
}
$count_total = 0;
$count_bad = 0;
$firstloop = 1;
$addsplit = '';
$wordids = '';
$tempwordids = array();
$wordidcache = array();
$andlist = array();
$orlist = array();
$notlist = array();
$tempwordids = array();
$foundwordids = array();
$wordcache = array();
$doublecount = 0;
$i = array("AND" => 0, "OR" => 0, "NOT" => 0);
while (list($key, $val) = each($searchwords)) {
if ($val == "and" || $val == "or" || $val == "not") {
$addsplit = wbb_strtoupper($val);
continue;
}
$count_total++;
if ((!isset($goodwords[$val]) && !$goodwords[$val]) && ((isset($badwords[$val]) && $badwords[$val] == 1) || wbb_strlen($val) < $minwordlength || wbb_strlen($val) > $maxwordlength)) {
$count_bad++;
continue;
}
$result = $db->query("SELECT wordid FROM bb".$n."_wordlist WHERE word LIKE '$val'");
if ($db->num_rows($result)) {
while ($row = $db->fetch_array($result)) {
if ($firstloop == 1) $tempwordids[] = $row['wordid'];
else {
if ($addsplit == '') $addsplit = "AND";
$wordidcache[$addsplit][$i[$addsplit]][] = $row['wordid'];
if (count($tempwordids)) {
reset($tempwordids);
$doublecount = 1;
while (list($key2, $wordid) = each($tempwordids)) {
if ($addsplit == "NOT") $wordidcache['AND'][$i[$addsplit] + 1][] = $wordid;
else $wordidcache[$addsplit][$i[$addsplit] + 1][] = $wordid;
}
$tempwordids = array();
}
}
$wordids .= ",".$row['wordid'];
}
$firstloop = 0;
}
elseif ($firstloop == 0 && $addsplit == "AND") {
unset($wordids);
break;
}
if ($doublecount == 1) {
$i[$addsplit]++;
$doublecount = 0;
}
$i[$addsplit]++;
}
if ($count_bad > 0 && $count_bad == $count_total) redirect($lang->get("LANG_SEARCH_ERROR_SEARCHBAD", array('$minwordlength' => $minwordlength, '$maxwordlength' => $maxwordlength)), "thread.php?threadid=" . $sthreadid . $SID_ARG_1ST);
if (count($tempwordids)) {
reset($tempwordids);
while (list($key2, $wordid) = each($tempwordids)) $wordidcache['AND'][$i[$addsplit]][] = $wordid;
}
$foundpostids = array();
if ($wordids) {
$result = $db->unbuffered_query("SELECT wordid, postid FROM bb".$n."_wordmatch
LEFT JOIN bb".$n."_posts USING (postid)
WHERE threadid = '".$sthreadid."'
AND wordid IN (0$wordids)".(($topiconly == 1) ? (" AND intopic=1") : ("")));
while ($row = $db->fetch_array($result)) {
$foundpostids[$row['wordid']][$row['postid']] = 1;
}
}
function myArrayMerge($array, $add) {
while (list($key, $val) = each($add)) $array[$key] = $val;
return $array;
}
function mySearchArray($array, $add, $mode) {
if ($mode == "OR") return myArrayMerge($array, $add);
if ($mode == "AND") {
$newarray = array();
while (list($key, $val) = each($array)) if ($add[$key] == 1) $newarray[$key] = 1;
return $newarray;
}
if ($mode == "NOT") {
while (list($key, $val) = each($add)) if ($array[$key] == 1) $array[$key] = 0;
return $array;
}
}
$globalarray = array();
$addsplit = array("AND", "OR", "NOT");
for ($i = 0; $i < 3; $i++) {
$savearray = array();
$count = 0;
if (count($wordidcache[$addsplit[$i]])) {
reset($wordidcache[$addsplit[$i]]);
while (list($key, $wordids) = each($wordidcache[$addsplit[$i]])) {
$savearray[$count] = array();
$badx = 1;
while (list($key2, $wordid) = each($wordids)) {
if (isset($foundpostids[$wordid])) {
$badx = 0;
$savearray[$count] = myArrayMerge($savearray[$count], $foundpostids[$wordid]);
}
}
if ($badx == 0) {
if (!count($globalarray)) $globalarray = $savearray[$count];
else $globalarray = mySearchArray($globalarray, $savearray[$count], $addsplit[$i]);
}
$count++;
}
}
}
$postids = '';
while (list($key, $val) = each($globalarray)) {
if ($val != 1) continue;
if ($postids == '') $postids = $key;
else $postids .= ",$key";
}
}
if (!$userids && !$postids) redirect($lang->get("LANG_GLOBAL_ERROR_SEARCHNORESULT"), "thread.php?threadid=" . $sthreadid . $SID_ARG_1ST);
$savepostids = '';
$result = $db->unbuffered_query("SELECT p.postid FROM bb".$n."_posts p, bb".$n."_threads t WHERE p.threadid=t.threadid AND p.visible=1 AND p.postid IN (".$postids.")");
while ($row = $db->fetch_array($result)) $savepostids .= ','.$row['postid'];
if (!$savepostids) redirect($lang->get("LANG_GLOBAL_ERROR_SEARCHNORESULT"), "thread.php?threadid=" . $sthreadid . $SID_ARG_1ST);
$result = $db->query_first("SELECT searchid FROM bb".$n."_searchs WHERE searchhash = '".getQueryHash($savepostids, 1, $_POST['sortby'], $_POST['sortorder'], $wbbuserdata['userid'], $REMOTE_ADDR)."'");
if ($result['searchid']) {
header("Location: search.php?searchid=".$result['searchid'].$SID_ARG_2ND_UN);
exit();
}
$db->query("INSERT INTO bb".$n."_searchs (searchhash,searchstring,searchuserid,postids,showposts,sortby,sortorder,searchtime,userid,ipaddress)
VALUES ('".getQueryHash($savepostids, 1, $_POST['sortby'], $_POST['sortorder'], $wbbuserdata['userid'], $REMOTE_ADDR)."','".addslashes($tempsearchstring)."','".((!strstr($userids, ',')) ? (intval($userids)) : (0))."','$savepostids','1','".addslashes($_POST['sortby'])."','".addslashes($_POST['sortorder'])."','".time()."','$wbbuserdata[userid]','$REMOTE_ADDR')");
$searchid = $db->insert_id();
header("Location: search.php?searchid=$searchid".$SID_ARG_2ND_UN);
exit();
}
/* Thread durchsuchen by Viktor */
|