Zeile 6 | Zeile 6 |
---|
* Website: http://mybb.com * License: http://mybb.com/about/license *
|
* Website: http://mybb.com * License: http://mybb.com/about/license *
|
* $Id: functions_search.php 5132 2010-07-28 08:18:14Z RyanGordon $
| * $Id: functions_search.php 5458 2011-05-01 21:12:31Z jammerx2 $
|
*/
/**
| */
/**
|
Zeile 238 | Zeile 238 |
---|
$keywords = preg_replace("#\s+#s", " ", $keywords);
// Search for "and" or "or" and remove if it's at the beginning
|
$keywords = preg_replace("#\s+#s", " ", $keywords);
// Search for "and" or "or" and remove if it's at the beginning
|
| $keywords = trim($keywords);
|
if(my_strpos($keywords, "or") === 0) { $keywords = substr_replace($keywords, "", 0, 2);
| if(my_strpos($keywords, "or") === 0) { $keywords = substr_replace($keywords, "", 0, 2);
|
Zeile 248 | Zeile 249 |
---|
$keywords = substr_replace($keywords, "", 0, 3); }
|
$keywords = substr_replace($keywords, "", 0, 3); }
|
return trim($keywords);
| return $keywords;
|
}
/**
| }
/**
|
Zeile 370 | Zeile 371 |
---|
$subject_lookin = ""; $message_lookin = "";
|
$subject_lookin = ""; $message_lookin = "";
|
$searchsql = "uid='{$mybb->user['uid']}'"; if($keywords) { // Complex search $keywords = " {$keywords} "; if(preg_match("# and|or #", $keywords)) { $subject_lookin = " AND ("; $message_lookin = " AND ("; // Expand the string by double quotes $keywords_exp = explode("\"", $keywords); $inquote = false;
| $searchsql = "uid='{$mybb->user['uid']}'"; if($keywords) { // Complex search $keywords = " {$keywords} "; if(preg_match("# and|or #", $keywords)) { $string = "AND"; if($search['subject'] == 1) { $string = "OR"; $subject_lookin = " AND ("; }
if($search['message'] == 1) { $message_lookin = " {$string} ("; } // Expand the string by double quotes $keywords_exp = explode("\"", $keywords); $inquote = false;
|
foreach($keywords_exp as $phrase) { // If we're not in a double quoted section
| foreach($keywords_exp as $phrase) { // If we're not in a double quoted section
|
Zeile 404 | Zeile 414 |
---|
// If this word is a search operator set the boolean if($i % 2 && ($word == "and" || $word == "or")) {
|
// If this word is a search operator set the boolean if($i % 2 && ($word == "and" || $word == "or")) {
|
| if($i <= 1) { if($search['subject'] && $search['message'] && $subject_lookin == " AND (") { // We're looking for anything, check for a subject lookin continue; } elseif($search['subject'] && !$search['message'] && $subject_lookin == " AND (") { // Just in a subject? continue; } elseif(!$search['subject'] && $search['message'] && $message_lookin == " {$string} (") { // Just in a message? continue; } }
|
$boolean = $word; } // Otherwise check the length of the word as it is a normal search term
| $boolean = $word; } // Otherwise check the length of the word as it is a normal search term
|
Zeile 418 | Zeile 447 |
---|
} // Add terms to search query if($search['subject'] == 1)
|
} // Add terms to search query if($search['subject'] == 1)
|
{
| {
|
$subject_lookin .= " $boolean LOWER(subject) LIKE '%{$word}%'"; } if($search['message'] == 1) {
|
$subject_lookin .= " $boolean LOWER(subject) LIKE '%{$word}%'"; } if($search['message'] == 1) {
|
$searchsql .= " $boolean LOWER(message) LIKE '%{$word}%'";
| $message_lookin .= " $boolean LOWER(message) LIKE '%{$word}%'";
|
} } }
| } } }
|
Zeile 444 | Zeile 473 |
---|
$message_lookin .= " $boolean LOWER(message) LIKE '%{$phrase}%'"; } }
|
$message_lookin .= " $boolean LOWER(message) LIKE '%{$phrase}%'"; } }
|
| // Check to see if we have any search terms and not a malformed SQL string $error = false; if($search['subject'] && $search['message'] && $subject_lookin == " AND (") { // We're looking for anything, check for a subject lookin $error = true; } elseif($search['subject'] && !$search['message'] && $subject_lookin == " AND (") { // Just in a subject? $error = true; } elseif(!$search['subject'] && $search['message'] && $message_lookin == " {$string} (") { // Just in a message? $error = true; }
if($error == true) { // There are no search keywords to look for $lang->error_minsearchlength = $lang->sprintf($lang->error_minsearchlength, $mybb->settings['minsearchword']); error($lang->error_minsearchlength); }
|
$inquote = !$inquote; }
|
$inquote = !$inquote; }
|
$subject_lookin .= ")"; $message_lookin .= ")";
| if($search['subject'] == 1) { $subject_lookin .= ")"; }
if($search['message'] == 1) { $message_lookin .= ")"; }
|
$searchsql .= "{$subject_lookin} {$message_lookin}";
|
$searchsql .= "{$subject_lookin} {$message_lookin}";
|
} else { $keywords = str_replace("\"", '', trim($keywords));
| } else { $keywords = str_replace("\"", '', trim($keywords));
|
if(my_strlen($keywords) < $mybb->settings['minsearchword']) { $lang->error_minsearchlength = $lang->sprintf($lang->error_minsearchlength, $mybb->settings['minsearchword']);
| if(my_strlen($keywords) < $mybb->settings['minsearchword']) { $lang->error_minsearchlength = $lang->sprintf($lang->error_minsearchlength, $mybb->settings['minsearchword']);
|
Zeile 462 | Zeile 525 |
---|
// If we're looking in both, then find matches in either the subject or the message if($search['subject'] == 1 && $search['message'] == 1)
|
// If we're looking in both, then find matches in either the subject or the message if($search['subject'] == 1 && $search['message'] == 1)
|
{
| {
|
$searchsql .= " AND (LOWER(subject) LIKE '%{$keywords}%' OR LOWER(message) LIKE '%{$keywords}%')"; } else
| $searchsql .= " AND (LOWER(subject) LIKE '%{$keywords}%' OR LOWER(message) LIKE '%{$keywords}%')"; } else
|
Zeile 470 | Zeile 533 |
---|
if($search['subject'] == 1) { $searchsql .= " AND LOWER(subject) LIKE '%{$keywords}%'";
|
if($search['subject'] == 1) { $searchsql .= " AND LOWER(subject) LIKE '%{$keywords}%'";
|
}
| }
|
if($search['message'] == 1) { $searchsql .= " AND LOWER(message) LIKE '%{$keywords}%'"; } }
|
if($search['message'] == 1) { $searchsql .= " AND LOWER(message) LIKE '%{$keywords}%'"; } }
|
} }
| } }
|
if($search['sender']) { $userids = array();
| if($search['sender']) { $userids = array();
|
Zeile 487 | Zeile 550 |
---|
$query = $db->simple_select("users", "uid", "LOWER(username) LIKE '%".$db->escape_string_like($db->escape_string($search['sender']))."%'"); while($user = $db->fetch_array($query))
|
$query = $db->simple_select("users", "uid", "LOWER(username) LIKE '%".$db->escape_string_like($db->escape_string($search['sender']))."%'"); while($user = $db->fetch_array($query))
|
{
| {
|
$userids[] = $user['uid']; }
| $userids[] = $user['uid']; }
|
Zeile 512 | Zeile 575 |
---|
$folderids = array(); $search['folder'] = array_map("intval", $search['folder']);
|
$folderids = array(); $search['folder'] = array_map("intval", $search['folder']);
|
|
|
$folderids = implode(',', $search['folder']); if($folderids) { $searchsql .= " AND folder IN (".$folderids.")";
|
$folderids = implode(',', $search['folder']); if($folderids) { $searchsql .= " AND folder IN (".$folderids.")";
|
} }
| } }
|
if($search['status']) { $searchsql .= " AND (";
| if($search['status']) { $searchsql .= " AND (";
|
Zeile 529 | Zeile 592 |
---|
$statussql[] = " status='0' "; } if($search['status']['replied'])
|
$statussql[] = " status='0' "; } if($search['status']['replied'])
|
{
| {
|
$statussql[] = " status='3' ";
|
$statussql[] = " status='3' ";
|
}
| }
|
if($search['status']['forwarded']) { $statussql[] = " status='4' "; } if($search['status']['read'])
|
if($search['status']['forwarded']) { $statussql[] = " status='4' "; } if($search['status']['read'])
|
{
| {
|
$statussql[] = " (status != '0' AND readtime > '0') "; } // Sent Folder
| $statussql[] = " (status != '0' AND readtime > '0') "; } // Sent Folder
|
Zeile 576 | Zeile 639 |
---|
*/ function perform_search_mysql($search) {
|
*/ function perform_search_mysql($search) {
|
global $mybb, $db, $lang;
| global $mybb, $db, $lang, $cache;
|
$keywords = clean_keywords($search['keywords']); if(!$keywords && !$search['author'])
|
$keywords = clean_keywords($search['keywords']); if(!$keywords && !$search['author'])
|
{
| {
|
error($lang->error_nosearchterms);
|
error($lang->error_nosearchterms);
|
}
| }
|
if($mybb->settings['minsearchword'] < 1) { $mybb->settings['minsearchword'] = 3;
|
if($mybb->settings['minsearchword'] < 1) { $mybb->settings['minsearchword'] = 3;
|
}
| }
|
if($keywords) { // Complex search
| if($keywords) { // Complex search
|
Zeile 621 | Zeile 684 |
---|
// If this word is a search operator set the boolean if($i % 2 && ($word == "and" || $word == "or")) {
|
// If this word is a search operator set the boolean if($i % 2 && ($word == "and" || $word == "or")) {
|
| if($i <= 1 && $subject_lookin == " AND (") { continue; }
|
$boolean = $word; } // Otherwise check the length of the word as it is a normal search term
| $boolean = $word; } // Otherwise check the length of the word as it is a normal search term
|
Zeile 658 | Zeile 726 |
---|
$message_lookin .= " $boolean LOWER(p.message) LIKE '%{$phrase}%'"; } }
|
$message_lookin .= " $boolean LOWER(p.message) LIKE '%{$phrase}%'"; } }
|
| if($subject_lookin == " AND (") { // There are no search keywords to look for $lang->error_minsearchlength = $lang->sprintf($lang->error_minsearchlength, $mybb->settings['minsearchword']); error($lang->error_minsearchlength); }
|
$inquote = !$inquote; } $subject_lookin .= ")";
| $inquote = !$inquote; } $subject_lookin .= ")";
|
Zeile 691 | Zeile 767 |
---|
{ $search['author'] = my_strtolower($search['author']); $query = $db->simple_select("users", "uid", "LOWER(username) LIKE '%".$db->escape_string_like($db->escape_string($search['author']))."%'");
|
{ $search['author'] = my_strtolower($search['author']); $query = $db->simple_select("users", "uid", "LOWER(username) LIKE '%".$db->escape_string_like($db->escape_string($search['author']))."%'");
|
}
| }
|
while($user = $db->fetch_array($query))
|
while($user = $db->fetch_array($query))
|
{
| {
|
$userids[] = $user['uid']; } if(count($userids) < 1) { error($lang->error_nosearchresults);
|
$userids[] = $user['uid']; } if(count($userids) < 1) { error($lang->error_nosearchresults);
|
}
| }
|
else { $userids = implode(',', $userids);
| else { $userids = implode(',', $userids);
|
Zeile 723 | Zeile 799 |
---|
$datecut .= "'$datelimit'"; $post_datecut = " AND p.dateline $datecut"; $thread_datecut = " AND t.dateline $datecut";
|
$datecut .= "'$datelimit'"; $post_datecut = " AND p.dateline $datecut"; $thread_datecut = " AND t.dateline $datecut";
|
}
| }
|
$thread_replycut = ''; if($search['numreplies'] != '' && $search['findthreadst']) { if(intval($search['findthreadst']) == 1)
|
$thread_replycut = ''; if($search['numreplies'] != '' && $search['findthreadst']) { if(intval($search['findthreadst']) == 1)
|
{
| {
|
$thread_replycut = " AND t.replies >= '".intval($search['numreplies'])."'";
|
$thread_replycut = " AND t.replies >= '".intval($search['numreplies'])."'";
|
} else {
| } else {
|
$thread_replycut = " AND t.replies <= '".intval($search['numreplies'])."'"; } }
| $thread_replycut = " AND t.replies <= '".intval($search['numreplies'])."'"; } }
|
Zeile 750 | Zeile 826 |
---|
if($search['forums'] != "all") { if(!is_array($search['forums']))
|
if($search['forums'] != "all") { if(!is_array($search['forums']))
|
{
| {
|
$search['forums'] = array(intval($search['forums'])); } // Generate a comma separated list of all groups the user belongs to
| $search['forums'] = array(intval($search['forums'])); } // Generate a comma separated list of all groups the user belongs to
|
Zeile 758 | Zeile 834 |
---|
if($mybb->user['additionalgroups']) { $user_groups .= ",".$mybb->user['additionalgroups'];
|
if($mybb->user['additionalgroups']) { $user_groups .= ",".$mybb->user['additionalgroups'];
|
}
| // Setup some quick permissions for us $fcache = $cache->read("forumpermissions"); $add_groups = explode(",", $mybb->user['additionalgroups']); }
|
foreach($search['forums'] as $forum) { $forum = intval($forum); if(!$searchin[$forum]) {
|
foreach($search['forums'] as $forum) { $forum = intval($forum); if(!$searchin[$forum]) {
|
switch($db->type)
| if(is_array($add_groups))
|
{
|
{
|
case "pgsql": $query = $db->query(" SELECT DISTINCT f.fid FROM ".TABLE_PREFIX."forums f LEFT JOIN ".TABLE_PREFIX."forumpermissions p ON (f.fid=p.fid AND p.gid IN (".$user_groups.")) WHERE (','||parentlist||',' LIKE ',%{$forum}%,') = true AND active!=0 AND (p.fid IS NULL OR p.cansearch=1) "); break; case "sqlite": $query = $db->query(" SELECT DISTINCT f.fid FROM ".TABLE_PREFIX."forums f LEFT JOIN ".TABLE_PREFIX."forumpermissions p ON (f.fid=p.fid AND p.gid IN (".$user_groups.")) WHERE (','||parentlist||',' LIKE ',%{$forum}%,') > 0 AND active!=0 AND (p.fid = NULL OR p.cansearch=1) "); break; default: $query = $db->query(" SELECT DISTINCT f.fid FROM ".TABLE_PREFIX."forums f LEFT JOIN ".TABLE_PREFIX."forumpermissions p ON (f.fid=p.fid AND p.gid IN (".$user_groups.")) WHERE INSTR(CONCAT(',',parentlist,','),',$forum,') > 0 AND active!=0 AND (ISNULL(p.fid) OR p.cansearch=1) ");
| $can_search = 0; foreach($add_groups as $add_group) { // Check to make sure that we have sufficient permissions to search this forum if(!is_array($fcache[$forum][$add_group]) || $fcache[$forum][$add_group]['cansearch'] == 1 || $mybb->usergroup['cansearch'] == 1) { $can_search = 1; } }
if($can_search == 0) { // We can't search this forum... continue; }
|
}
|
}
|
| switch($db->type) { case "pgsql": $query = $db->simple_select("forums", "DISTINCT fid", "(','||parentlist||',' LIKE ',%{$forum}%,') = true AND active != 0"); break; case "sqlite": $query = $db->simple_select("forums", "DISTINCT fid", "(','||parentlist||',' LIKE ',%{$forum}%,') > 0 AND active != 0"); break; default: $query = $db->simple_select("forums", "DISTINCT fid", "INSTR(CONCAT(',',parentlist,','),',{$forum},') > 0 AND active != 0"); }
|
while($sforum = $db->fetch_array($query)) { $fidlist[] = $sforum['fid'];
| while($sforum = $db->fetch_array($query)) { $fidlist[] = $sforum['fid'];
|
Zeile 814 | Zeile 899 |
---|
$onlyusfids = array(); // Check group permissions if we can't view threads not started by us
|
$onlyusfids = array(); // Check group permissions if we can't view threads not started by us
|
$group_permissions = forum_permissions(); foreach($group_permissions as $fid => $forum_permissions)
| if($group_permissions = forum_permissions())
|
{
|
{
|
if($forum_permissions['canonlyviewownthreads'] == 1)
| foreach($group_permissions as $fid => $forum_permissions)
|
{
|
{
|
$onlyusfids[] = $fid;
| if($forum_permissions['canonlyviewownthreads'] == 1) { $onlyusfids[] = $fid; }
|
} } if(!empty($onlyusfids))
| } } if(!empty($onlyusfids))
|