Vergleich inc/functions_search.php - 1.6.0 - 1.6.12

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 6Zeile 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$

 */

/**

 */

/**

Zeile 96Zeile 96
function get_unsearchable_forums($pid="0", $first=1)
{
global $db, $forum_cache, $permissioncache, $mybb, $unsearchableforums, $unsearchable, $templates, $forumpass;

function get_unsearchable_forums($pid="0", $first=1)
{
global $db, $forum_cache, $permissioncache, $mybb, $unsearchableforums, $unsearchable, $templates, $forumpass;

	



	$pid = intval($pid);

	$pid = intval($pid);

	



	if(!is_array($forum_cache))
{
// Get Forums

	if(!is_array($forum_cache))
{
// Get Forums

Zeile 111Zeile 111
	if(!is_array($permissioncache))
{
$permissioncache = forum_permissions();

	if(!is_array($permissioncache))
{
$permissioncache = forum_permissions();

	}

	}

	foreach($forum_cache as $fid => $forum)
{
if($permissioncache[$forum['fid']])

	foreach($forum_cache as $fid => $forum)
{
if($permissioncache[$forum['fid']])

Zeile 151Zeile 151
				$unsearchableforums .= ",";
}
$unsearchableforums .= "'{$forum['fid']}'";

				$unsearchableforums .= ",";
}
$unsearchableforums .= "'{$forum['fid']}'";

		}

		}

	}
$unsearchable = $unsearchableforums;

	}
$unsearchable = $unsearchableforums;

	



	// Get our unsearchable password protected forums
$pass_protected_forums = get_password_protected_forums();

	// Get our unsearchable password protected forums
$pass_protected_forums = get_password_protected_forums();

	



	if($unsearchable && $pass_protected_forums)

	if($unsearchable && $pass_protected_forums)

	{

	{

		$unsearchable .= ",";

		$unsearchable .= ",";

	}


	}


	if($pass_protected_forums)
{
$unsearchable .= implode(",", $pass_protected_forums);
}

	if($pass_protected_forums)
{
$unsearchable .= implode(",", $pass_protected_forums);
}

	



	return $unsearchable;
}


	return $unsearchable;
}


Zeile 180Zeile 180
function get_password_protected_forums($fids=array())
{
global $forum_cache, $mybb;

function get_password_protected_forums($fids=array())
{
global $forum_cache, $mybb;

	



	if(!is_array($fids))
{
return false;
}

	if(!is_array($fids))
{
return false;
}

	



	if(!is_array($forum_cache))
{
$forum_cache = cache_forums();

	if(!is_array($forum_cache))
{
$forum_cache = cache_forums();

Zeile 194Zeile 194
			return false;
}
}

			return false;
}
}

	



	if(empty($fids))
{
$fids = array_keys($forum_cache);

	if(empty($fids))
{
$fids = array_keys($forum_cache);

Zeile 207Zeile 207
		{
continue;
}

		{
continue;
}

		



		if(md5($mybb->user['uid'].$forum_cache[$fid]['password']) != $mybb->cookies['forumpass'][$fid])
{
$pass_fids[] = $fid;
$child_list = get_child_list($fid);
}

		if(md5($mybb->user['uid'].$forum_cache[$fid]['password']) != $mybb->cookies['forumpass'][$fid])
{
$pass_fids[] = $fid;
$child_list = get_child_list($fid);
}

		



		if(is_array($child_list))
{
$pass_fids = array_merge($pass_fids, $child_list);

		if(is_array($child_list))
{
$pass_fids = array_merge($pass_fids, $child_list);

Zeile 238Zeile 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);
}

	



	if(my_strpos($keywords, "and") === 0)
{
$keywords = substr_replace($keywords, "", 0, 3);
}

	if(my_strpos($keywords, "and") === 0)
{
$keywords = substr_replace($keywords, "", 0, 3);
}


return trim($keywords);


return $keywords;

}

/**

}

/**

Zeile 260Zeile 261
function clean_keywords_ft($keywords)
{
if(!$keywords)

function clean_keywords_ft($keywords)
{
if(!$keywords)

	{

	{

		return false;
}
$keywords = my_strtolower($keywords);

		return false;
}
$keywords = my_strtolower($keywords);

Zeile 268Zeile 269
	$keywords = preg_replace("#\*{2,}#s", "*", $keywords);
$keywords = preg_replace("#([\[\]\|\.\,:])#s", " ", $keywords);
$keywords = preg_replace("#\s+#s", " ", $keywords);

	$keywords = preg_replace("#\*{2,}#s", "*", $keywords);
$keywords = preg_replace("#([\[\]\|\.\,:])#s", " ", $keywords);
$keywords = preg_replace("#\s+#s", " ", $keywords);

	



	$words = array();

	$words = array();

	



	if(my_strpos($keywords, "\"") !== false)
{
$inquote = false;

	if(my_strpos($keywords, "\"") !== false)
{
$inquote = false;

Zeile 278Zeile 279
		foreach($keywords as $phrase)
{
if($phrase != '')

		foreach($keywords as $phrase)
{
if($phrase != '')

			{

			{

				if($inquote)
{
$words[] = "\"".trim($phrase)."\"";

				if($inquote)
{
$words[] = "\"".trim($phrase)."\"";

Zeile 324Zeile 325
	foreach($words as $word)
{
if($word == "or")

	foreach($words as $word)
{
if($word == "or")

		{
$boolean = '';
}

		{
$boolean = '';
}

		elseif($word == "and")
{
$boolean = "+";

		elseif($word == "and")
{
$boolean = "+";

Zeile 367Zeile 368
	{
$mybb->settings['minsearchword'] = 3;
}

	{
$mybb->settings['minsearchword'] = 3;
}

	



	$subject_lookin = "";
$message_lookin = "";
$searchsql = "uid='{$mybb->user['uid']}'";

	$subject_lookin = "";
$message_lookin = "";
$searchsql = "uid='{$mybb->user['uid']}'";

	
if($keywords)
{
// Complex search
$keywords = " {$keywords} ";
if(preg_match("# and|or #", $keywords))


if($keywords)
{
// Complex search
$keywords = " {$keywords} ";
if(preg_match("# and|or #", $keywords))

		{

		{

			$subject_lookin = " AND (";
$message_lookin = " AND (";











			$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;

			// 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 393Zeile 403
					// Expand out based on search operators (and, or)
$matches = preg_split("#\s{1,}(and|or)\s{1,}#", $phrase, -1, PREG_SPLIT_DELIM_CAPTURE);
$count_matches = count($matches);

					// Expand out based on search operators (and, or)
$matches = preg_split("#\s{1,}(and|or)\s{1,}#", $phrase, -1, PREG_SPLIT_DELIM_CAPTURE);
$count_matches = count($matches);

					



					for($i=0; $i < $count_matches; ++$i)

					for($i=0; $i < $count_matches; ++$i)

					{

					{

						$word = trim($matches[$i]);
if(empty($word))

						$word = trim($matches[$i]);
if(empty($word))

						{

						{

							continue;
}
// If this word is a search operator set the boolean
if($i % 2 && ($word == "and" || $word == "or"))
{

							continue;
}
// 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 423Zeile 452
							}
if($search['message'] == 1)
{

							}
if($search['message'] == 1)
{

								$searchsql .= " $boolean LOWER(message) LIKE '%{$word}%'";

								$message_lookin .= " $boolean LOWER(message) LIKE '%{$word}%'";

							}
}
}

							}
}
}

				}	

				}

				// In the middle of a quote (phrase)
else

				// In the middle of a quote (phrase)
else

				{

				{

					$phrase = str_replace(array("+", "-", "*"), '', trim($phrase));
if(my_strlen($phrase) < $mybb->settings['minsearchword'])
{
$lang->error_minsearchlength = $lang->sprintf($lang->error_minsearchlength, $mybb->settings['minsearchword']);
error($lang->error_minsearchlength);

					$phrase = str_replace(array("+", "-", "*"), '', trim($phrase));
if(my_strlen($phrase) < $mybb->settings['minsearchword'])
{
$lang->error_minsearchlength = $lang->sprintf($lang->error_minsearchlength, $mybb->settings['minsearchword']);
error($lang->error_minsearchlength);

					}

					}

					// Add phrase to search query
$subject_lookin .= " $boolean LOWER(subject) LIKE '%{$phrase}%'";
if($search['message'] == 1)
{
$message_lookin .= " $boolean LOWER(message) LIKE '%{$phrase}%'";

					// Add phrase to search query
$subject_lookin .= " $boolean LOWER(subject) LIKE '%{$phrase}%'";
if($search['message'] == 1)
{
$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}";
}
else

			$searchsql .= "{$subject_lookin} {$message_lookin}";
}
else

Zeile 459Zeile 522
				$lang->error_minsearchlength = $lang->sprintf($lang->error_minsearchlength, $mybb->settings['minsearchword']);
error($lang->error_minsearchlength);
}

				$lang->error_minsearchlength = $lang->sprintf($lang->error_minsearchlength, $mybb->settings['minsearchword']);
error($lang->error_minsearchlength);
}

			



			// 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)
{

Zeile 471Zeile 534
				{
$searchsql .= " AND LOWER(subject) LIKE '%{$keywords}%'";
}

				{
$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}%'";

Zeile 479Zeile 542
			}
}
}

			}
}
}

	



	if($search['sender'])
{
$userids = array();
$search['sender'] = my_strtolower($search['sender']);

	if($search['sender'])
{
$userids = array();
$search['sender'] = my_strtolower($search['sender']);

		



		$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'];
}

		$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'];
}

		



		if(count($userids) < 1)

		if(count($userids) < 1)

		{

		{

			error($lang->error_nosearchresults);

			error($lang->error_nosearchresults);

		}

		}

		else
{
$userids = implode(',', $userids);
$searchsql .= " AND fromid IN (".$userids.")";
}
}

		else
{
$userids = implode(',', $userids);
$searchsql .= " AND fromid IN (".$userids.")";
}
}

	



	if(!is_array($search['folder']))
{
$search['folder'] = array($search['folder']);
}

	if(!is_array($search['folder']))
{
$search['folder'] = array($search['folder']);
}

	



	if(!empty($search['folder']))

	if(!empty($search['folder']))

	{

	{

		$folderids = array();

		$folderids = array();

		



		$search['folder'] = array_map("intval", $search['folder']);

		$search['folder'] = array_map("intval", $search['folder']);

		



		$folderids = implode(',', $search['folder']);

		$folderids = implode(',', $search['folder']);

		



		if($folderids)
{
$searchsql .= " AND folder IN (".$folderids.")";

		if($folderids)
{
$searchsql .= " AND folder IN (".$folderids.")";

Zeile 524Zeile 587
	if($search['status'])
{
$searchsql .= " AND (";

	if($search['status'])
{
$searchsql .= " AND (";

		if($search['status']['new'])

		if($search['status']['new'])

		{
$statussql[] = " status='0' ";
}

		{
$statussql[] = " status='0' ";
}

Zeile 548Zeile 611
		$statussql = implode("OR", $statussql);
$searchsql .= $statussql.")";
}

		$statussql = implode("OR", $statussql);
$searchsql .= $statussql.")";
}

	



	// Run the search
$pms = array();
$query = $db->simple_select("privatemessages", "pmid", $searchsql);

	// Run the search
$pms = array();
$query = $db->simple_select("privatemessages", "pmid", $searchsql);

Zeile 556Zeile 619
	{
$pms[$pm['pmid']] = $pm['pmid'];
}

	{
$pms[$pm['pmid']] = $pm['pmid'];
}

	



	if(count($pms) < 1)
{
error($lang->error_nosearchresults);
}
$pms = implode(',', $pms);

	if(count($pms) < 1)
{
error($lang->error_nosearchresults);
}
$pms = implode(',', $pms);

	



	return array(
"querycache" => $pms
);
}

	return array(
"querycache" => $pms
);
}





/**
* Perform a thread and post search under MySQL or MySQLi
*

/**
* Perform a thread and post search under MySQL or MySQLi
*

Zeile 576Zeile 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'])
{

Zeile 597Zeile 660
		{
$subject_lookin = " AND (";
$message_lookin = " AND (";

		{
$subject_lookin = " AND (";
$message_lookin = " AND (";

			



			// Expand the string by double quotes
$keywords_exp = explode("\"", $keywords);
$inquote = false;

			// 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 610Zeile 673
					// Expand out based on search operators (and, or)
$matches = preg_split("#\s{1,}(and|or)\s{1,}#", $phrase, -1, PREG_SPLIT_DELIM_CAPTURE);
$count_matches = count($matches);

					// Expand out based on search operators (and, or)
$matches = preg_split("#\s{1,}(and|or)\s{1,}#", $phrase, -1, PREG_SPLIT_DELIM_CAPTURE);
$count_matches = count($matches);

					



					for($i=0; $i < $count_matches; ++$i)

					for($i=0; $i < $count_matches; ++$i)

					{

					{

						$word = trim($matches[$i]);
if(empty($word))

						$word = trim($matches[$i]);
if(empty($word))

						{

						{

							continue;
}
// If this word is a search operator set the boolean
if($i % 2 && ($word == "and" || $word == "or"))
{

							continue;
}
// 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 641Zeile 709
							}
}
}

							}
}
}

				}	

				}

				// In the middle of a quote (phrase)
else
{

				// In the middle of a quote (phrase)
else
{

Zeile 656Zeile 724
					if($search['postthread'] == 1)
{
$message_lookin .= " $boolean LOWER(p.message) LIKE '%{$phrase}%'";

					if($search['postthread'] == 1)
{
$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 .= ")";
$message_lookin .= ")";

				$inquote = !$inquote;
}
$subject_lookin .= ")";
$message_lookin .= ")";

		}
else

		}
else

		{
$keywords = str_replace("\"", '', trim($keywords));
if(my_strlen($keywords) < $mybb->settings['minsearchword'])
{
$lang->error_minsearchlength = $lang->sprintf($lang->error_minsearchlength, $mybb->settings['minsearchword']);
error($lang->error_minsearchlength);

		{
$keywords = str_replace("\"", '', trim($keywords));
if(my_strlen($keywords) < $mybb->settings['minsearchword'])
{
$lang->error_minsearchlength = $lang->sprintf($lang->error_minsearchlength, $mybb->settings['minsearchword']);
error($lang->error_minsearchlength);

			}

			}

			$subject_lookin = " AND LOWER(t.subject) LIKE '%{$keywords}%'";
if($search['postthread'] == 1)

			$subject_lookin = " AND LOWER(t.subject) LIKE '%{$keywords}%'";
if($search['postthread'] == 1)

			{

			{

				$message_lookin = " AND LOWER(p.message) LIKE '%{$keywords}%'";

				$message_lookin = " AND LOWER(p.message) LIKE '%{$keywords}%'";

			}
}
}
$post_usersql = '';
$thread_usersql = '';
if($search['author'])
{
$userids = array();
if($search['matchusername'])
{
$query = $db->simple_select("users", "uid", "username='".$db->escape_string($search['author'])."'");
}
else
{
$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))
{
$userids[] = $user['uid'];
}
if(count($userids) < 1)
{
error($lang->error_nosearchresults);
}
else
{
$userids = implode(',', $userids);
$post_usersql = " AND p.uid IN (".$userids.")";
$thread_usersql = " AND t.uid IN (".$userids.")";
}
}
$datecut = '';
if($search['postdate'])
{
if($search['pddir'] == 0)
{
$datecut = "<=";
}
else
{
$datecut = ">=";
}
$now = TIME_NOW;
$datelimit = $now-(86400 * $search['postdate']);
$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 = " AND t.replies >= '".intval($search['numreplies'])."'";
}
else
{
$thread_replycut = " AND t.replies <= '".intval($search['numreplies'])."'";
}
}

$thread_prefixcut = '';
if($search['threadprefix'] && $search['threadprefix'] != 'any')
{
$thread_prefixcut = " AND t.prefix='".intval($search['threadprefix'])."'";
}

$forumin = '';
$fidlist = array();
$searchin = array();
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
$user_groups = $mybb->user['usergroup'];
if($mybb->user['additionalgroups'])
{
$user_groups .= ",".$mybb->user['additionalgroups'];
}
foreach($search['forums'] as $forum)
{
$forum = intval($forum);
if(!$searchin[$forum])
{
switch($db->type)
{
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)
");
}
while($sforum = $db->fetch_array($query))
{
$fidlist[] = $sforum['fid'];
}
}
}
if(count($fidlist) == 1)
{
$forumin .= " AND t.fid='$forum' ";
$searchin[$fid] = 1;
}
else
{
if(count($fidlist) > 1)
{
$forumin = " AND t.fid IN (".implode(',', $fidlist).")";
}
}










			}
}
}
$post_usersql = '';
$thread_usersql = '';
if($search['author'])
{
$userids = array();
if($search['matchusername'])
{
$query = $db->simple_select("users", "uid", "username='".$db->escape_string($search['author'])."'");
}
else
{
$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))
{
$userids[] = $user['uid'];
}
if(count($userids) < 1)
{
error($lang->error_nosearchresults);
}
else
{
$userids = implode(',', $userids);
$post_usersql = " AND p.uid IN (".$userids.")";
$thread_usersql = " AND t.uid IN (".$userids.")";
}
}
$datecut = '';
if($search['postdate'])
{
if($search['pddir'] == 0)
{
$datecut = "<=";
}
else
{
$datecut = ">=";
}
$now = TIME_NOW;
$datelimit = $now-(86400 * $search['postdate']);
$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 = " AND t.replies >= '".intval($search['numreplies'])."'";
}
else
{
$thread_replycut = " AND t.replies <= '".intval($search['numreplies'])."'";
}
}

$thread_prefixcut = '';
if($search['threadprefix'] && $search['threadprefix'] != 'any')
{
$thread_prefixcut = " AND t.prefix='".intval($search['threadprefix'])."'";
}

$forumin = '';
$fidlist = array();
$searchin = array();
if($search['forums'][0] != "all")
{
if(!is_array($search['forums']))
{
$search['forums'] = array(intval($search['forums']));
}
// Generate a comma separated list of all groups the user belongs to
$user_groups = $mybb->user['usergroup'];
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])
{
if(is_array($add_groups))
{
$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'];
}
}
}
if(count($fidlist) == 1)
{
$forumin .= " AND t.fid='$forum' ";
$searchin[$fid] = 1;
}
else
{
if(count($fidlist) > 1)
{
$forumin = " AND t.fid IN (".implode(',', $fidlist).")";
}
}

	}

	}

	



	$permsql = "";
$onlyusfids = array();

	$permsql = "";
$onlyusfids = array();

	



	// Check group permissions if we can't view threads not started by us

	// 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($forum_permissions['canonlyviewownthreads'] == 1)

	if($group_permissions = forum_permissions())
{
foreach($group_permissions as $fid => $forum_permissions)


		{

		{

			$onlyusfids[] = $fid;




			if($forum_permissions['canonlyviewownthreads'] == 1)
{
$onlyusfids[] = $fid;
}

		}

		}

	}

	}

	if(!empty($onlyusfids))
{
$permsql .= "AND ((t.fid IN(".implode(',', $onlyusfids).") AND t.uid='{$mybb->user['uid']}') OR t.fid NOT IN(".implode(',', $onlyusfids)."))";
}

	if(!empty($onlyusfids))
{
$permsql .= "AND ((t.fid IN(".implode(',', $onlyusfids).") AND t.uid='{$mybb->user['uid']}') OR t.fid NOT IN(".implode(',', $onlyusfids)."))";
}

	



	$unsearchforums = get_unsearchable_forums();
if($unsearchforums)
{

	$unsearchforums = get_unsearchable_forums();
if($unsearchforums)
{

Zeile 837Zeile 924
	{
$permsql .= " AND t.fid NOT IN ($inactiveforums)";
}

	{
$permsql .= " AND t.fid NOT IN ($inactiveforums)";
}

	



	$visiblesql = $post_visiblesql = $plain_post_visiblesql = "";
if(isset($search['visible']))
{
if($search['visible'] == 1)
{
$visiblesql = " AND t.visible = '1'";

	$visiblesql = $post_visiblesql = $plain_post_visiblesql = "";
if(isset($search['visible']))
{
if($search['visible'] == 1)
{
$visiblesql = " AND t.visible = '1'";

			
if($search['postthread'] == 1)


if($search['postthread'] == 1)

			{
$post_visiblesql = " AND p.visible = '1'";
$plain_post_visiblesql = " AND visible = '1'";

			{
$post_visiblesql = " AND p.visible = '1'";
$plain_post_visiblesql = " AND visible = '1'";

Zeile 854Zeile 941
		else
{
$visiblesql = " AND t.visible != '1'";

		else
{
$visiblesql = " AND t.visible != '1'";

			



			if($search['postthread'] == 1)
{
$post_visiblesql = " AND p.visible != '1'";

			if($search['postthread'] == 1)
{
$post_visiblesql = " AND p.visible != '1'";

Zeile 868Zeile 955
	{
$tidsql = " AND t.tid='".intval($search['tid'])."'";
}

	{
$tidsql = " AND t.tid='".intval($search['tid'])."'";
}

	



	$limitsql = '';
if(intval($mybb->settings['searchhardlimit']) > 0)
{

	$limitsql = '';
if(intval($mybb->settings['searchhardlimit']) > 0)
{

Zeile 880Zeile 967
	$posts = array();
$firstposts = array();
if($search['postthread'] == 1)

	$posts = array();
$firstposts = array();
if($search['postthread'] == 1)

	{

	{

		// No need to search subjects when looking for results within a specific thread
if(!$search['tid'])
{

		// No need to search subjects when looking for results within a specific thread
if(!$search['tid'])
{

Zeile 897Zeile 984
				{
$posts[$thread['tid']] = $thread['firstpost'];
}

				{
$posts[$thread['tid']] = $thread['firstpost'];
}

			}

			}

		}

		}

		



		$query = $db->query("
SELECT p.pid, p.tid
FROM ".TABLE_PREFIX."posts p

		$query = $db->query("
SELECT p.pid, p.tid
FROM ".TABLE_PREFIX."posts p

Zeile 912Zeile 999
			$posts[$post['pid']] = $post['pid'];
$threads[$post['tid']] = $post['tid'];
}

			$posts[$post['pid']] = $post['pid'];
$threads[$post['tid']] = $post['tid'];
}

		



		if(count($posts) < 1 && count($threads) < 1)

		if(count($posts) < 1 && count($threads) < 1)

		{
error($lang->error_nosearchresults);

		{
error($lang->error_nosearchresults);

		}
$threads = implode(',', $threads);
$posts = implode(',', $posts);

		}
$threads = implode(',', $threads);
$posts = implode(',', $posts);

Zeile 948Zeile 1035
		if($firstposts)
{
$query = $db->simple_select("posts", "pid", "pid IN ($firstposts) {$plain_post_visiblesql} {$limitsql}");

		if($firstposts)
{
$query = $db->simple_select("posts", "pid", "pid IN ($firstposts) {$plain_post_visiblesql} {$limitsql}");

			while($post = $db->fetch_array($query))

			while($post = $db->fetch_array($query))

			{
$posts[$post['pid']] = $post['pid'];
}

			{
$posts[$post['pid']] = $post['pid'];
}

Zeile 976Zeile 1063
	if(!$keywords && !$search['author'])
{
error($lang->error_nosearchterms);

	if(!$keywords && !$search['author'])
{
error($lang->error_nosearchterms);

	}


	}


	// Attempt to determine minimum word length from MySQL for fulltext searches
$query = $db->query("SHOW VARIABLES LIKE 'ft_min_word_len';");
$min_length = $db->fetch_field($query, 'Value');
if(is_numeric($min_length))

	// Attempt to determine minimum word length from MySQL for fulltext searches
$query = $db->query("SHOW VARIABLES LIKE 'ft_min_word_len';");
$min_length = $db->fetch_field($query, 'Value');
if(is_numeric($min_length))

	{

	{

		$mybb->settings['minsearchword'] = $min_length;

		$mybb->settings['minsearchword'] = $min_length;

	}

	}

	// Otherwise, could not fetch - default back to MySQL fulltext default setting
else
{
$mybb->settings['minsearchword'] = 4;

	// Otherwise, could not fetch - default back to MySQL fulltext default setting
else
{
$mybb->settings['minsearchword'] = 4;

	}


	}


	if($keywords)
{
$keywords_exp = explode("\"", $keywords);

	if($keywords)
{
$keywords_exp = explode("\"", $keywords);

Zeile 1004Zeile 1091
				{
$word = str_replace(array("+", "-", "*"), '', $word);
if(!$word)

				{
$word = str_replace(array("+", "-", "*"), '', $word);
if(!$word)

					{

					{

						continue;
}
if(my_strlen($word) < $mybb->settings['minsearchword'])

						continue;
}
if(my_strlen($word) < $mybb->settings['minsearchword'])

Zeile 1032Zeile 1119
				}
}
$inquote = !$inquote;

				}
}
$inquote = !$inquote;

		}

		}

		// Show the minimum search term error only if all search terms are too short
if($all_too_short == true)
{

		// Show the minimum search term error only if all search terms are too short
if($all_too_short == true)
{

Zeile 1056Zeile 1143
			$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))
{
$userids[] = $user['uid'];
}

		while($user = $db->fetch_array($query))
{
$userids[] = $user['uid'];
}

		



		if(count($userids) < 1)
{
error($lang->error_nosearchresults);

		if(count($userids) < 1)
{
error($lang->error_nosearchresults);

Zeile 1090Zeile 1177
		$post_datecut = " AND p.dateline $datecut";
$thread_datecut = " AND t.dateline $datecut";
}

		$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'])."'";
}
else

			$thread_replycut = " AND t.replies >= '".intval($search['numreplies'])."'";
}
else

Zeile 1103Zeile 1190
			$thread_replycut = " AND t.replies <= '".intval($search['numreplies'])."'";
}
}

			$thread_replycut = " AND t.replies <= '".intval($search['numreplies'])."'";
}
}

	



	$thread_prefixcut = '';
if($search['threadprefix'] && $search['threadprefix'] != 'any')
{

	$thread_prefixcut = '';
if($search['threadprefix'] && $search['threadprefix'] != 'any')
{

Zeile 1113Zeile 1200
	$forumin = '';
$fidlist = array();
$searchin = array();

	$forumin = '';
$fidlist = array();
$searchin = array();

	if($search['forums'] != "all")

	if($search['forums'][0] != "all")

	{
if(!is_array($search['forums']))
{

	{
if(!is_array($search['forums']))
{

Zeile 1135Zeile 1222
					case "pgsql":
case "sqlite":
$query = $db->query("

					case "pgsql":
case "sqlite":
$query = $db->query("

							SELECT f.fid 
FROM ".TABLE_PREFIX."forums f

							SELECT 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(','||parentlist||',',',$forum,') > 0 AND active!=0 AND (ISNULL(p.fid) OR p.cansearch=1)
");
break;
default:
$query = $db->query("

							LEFT JOIN ".TABLE_PREFIX."forumpermissions p ON (f.fid=p.fid AND p.gid IN (".$user_groups."))
WHERE INSTR(','||parentlist||',',',$forum,') > 0 AND active!=0 AND (ISNULL(p.fid) OR p.cansearch=1)
");
break;
default:
$query = $db->query("

							SELECT f.fid 
FROM ".TABLE_PREFIX."forums f

							SELECT 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)
");

							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)
");

Zeile 1162Zeile 1249
		}
else
{

		}
else
{

			



			if(count($fidlist) > 1)
{
$forumin = " AND t.fid IN (".implode(',', $fidlist).")";

			if(count($fidlist) > 1)
{
$forumin = " AND t.fid IN (".implode(',', $fidlist).")";

Zeile 1171Zeile 1258
	}
$permsql = "";
$onlyusfids = array();

	}
$permsql = "";
$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)

	// Check group permissions if we can't view threads not started by us
$group_permissions = forum_permissions();
foreach($group_permissions as $fid => $forum_permissions)

Zeile 1185Zeile 1272
	{
$permsql .= "AND ((t.fid IN(".implode(',', $onlyusfids).") AND t.uid='{$mybb->user['uid']}') OR t.fid NOT IN(".implode(',', $onlyusfids)."))";
}

	{
$permsql .= "AND ((t.fid IN(".implode(',', $onlyusfids).") AND t.uid='{$mybb->user['uid']}') OR t.fid NOT IN(".implode(',', $onlyusfids)."))";
}

	



	$unsearchforums = get_unsearchable_forums();
if($unsearchforums)
{

	$unsearchforums = get_unsearchable_forums();
if($unsearchforums)
{

Zeile 1196Zeile 1283
	{
$permsql .= " AND t.fid NOT IN ($inactiveforums)";
}

	{
$permsql .= " AND t.fid NOT IN ($inactiveforums)";
}

	



	$visiblesql = $post_visiblesql = $plain_post_visiblesql = "";
if(isset($search['visible']))
{
if($search['visible'] == 1)
{
$visiblesql = " AND t.visible = '1'";

	$visiblesql = $post_visiblesql = $plain_post_visiblesql = "";
if(isset($search['visible']))
{
if($search['visible'] == 1)
{
$visiblesql = " AND t.visible = '1'";

			



			if($search['postthread'] == 1)
{
$post_visiblesql = " AND p.visible = '1'";

			if($search['postthread'] == 1)
{
$post_visiblesql = " AND p.visible = '1'";

Zeile 1213Zeile 1300
		else
{
$visiblesql = " AND t.visible != '1'";

		else
{
$visiblesql = " AND t.visible != '1'";

			



			if($search['postthread'] == 1)
{
$post_visiblesql = " AND p.visible != '1'";
$plain_post_visiblesql = " AND visible != '1'";
}
}

			if($search['postthread'] == 1)
{
$post_visiblesql = " AND p.visible != '1'";
$plain_post_visiblesql = " AND visible != '1'";
}
}

	}

	}


// Searching a specific thread?
if($search['tid'])
{
$tidsql = " AND t.tid='".intval($search['tid'])."'";
}


// Searching a specific thread?
if($search['tid'])
{
$tidsql = " AND t.tid='".intval($search['tid'])."'";
}

	



	$limitsql = '';
if(intval($mybb->settings['searchhardlimit']) > 0)
{

	$limitsql = '';
if(intval($mybb->settings['searchhardlimit']) > 0)
{