Vergleich inc/functions_search.php - 1.6.2 - 1.6.17

  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 243Zeile 243
	{
$keywords = substr_replace($keywords, "", 0, 2);
}

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

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

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

 
	// Separate braces for further processing
$keywords = preg_replace("#((\+|-|<|>|~)?\(|\))#s", " $1 ", $keywords);

	$keywords = preg_replace("#\s+#s", " ", $keywords);

	$keywords = preg_replace("#\s+#s", " ", $keywords);

	
$words = array();

if(my_strpos($keywords, "\"") !== false)
{
$inquote = false;
$keywords = explode("\"", $keywords);
foreach($keywords as $phrase)
{
if($phrase != '')


















$words = array(array());

// Fulltext search syntax validation: http://dev.mysql.com/doc/refman/5.6/en/fulltext-boolean.html
// Search for phrases
$keywords = explode("\"", $keywords);
$boolean = array('+');
// Brace depth
$depth = 0;
$phrase_operator = '+';
foreach($keywords as $phrase)
{
$phrase = trim($phrase);
if($phrase != '')
{
if($inquote)
{
if($phrase_operator)
{
$boolean[$depth] = $phrase_operator;
}
// Phrases do not need further processing
$words[$depth][] = "{$boolean[$depth]}\"{$phrase}\"";
$boolean[$depth] = $phrase_operator = '+';
}
else

			{

			{

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












				// Split words
$split_words = preg_split("#\s{1,}#", $phrase, -1);
if(!is_array($split_words))
{
continue;
}
if(!$inquote)
{
// Save possible operator in front of phrase
$last_char = substr($phrase, -1);
if($last_char == '+' || $last_char == '-' || $last_char == '<' || $last_char == '>' || $last_char == '~')
{
$phrase_operator = $last_char;
}

				}

				}

				else
{
$split_words = preg_split("#\s{1,}#", $phrase, -1);
if(!is_array($split_words))

				foreach($split_words as $word)
{
$word = trim($word);
if($word == "or")

					{

					{

						continue;





























						$boolean[$depth] = '';
// Remove "and" operator from previous element
$last = array_pop($words[$depth]);
if($last)
{
if(substr($last, 0, 1) == '+')
{
$last = substr($last, 1);
}
$words[$depth][] = $last;
}
}
elseif($word == "and")
{
$boolean[$depth] = "+";
}
elseif($word == "not")
{
$boolean[$depth] = "-";
}
// Closing braces
elseif($word == ")")
{
// Ignore when no brace was opened
if($depth > 0)
{
$words[$depth-1][] = $boolean[$depth-1].'('.implode(' ', $words[$depth]).')';
--$depth;
}

					}

					}

					foreach($split_words as $word)


					// Valid operators for opening braces
elseif($word == '+(' || $word == '-(' || $word == '<(' || $word == '>(' || $word == '~(' || $word == '(')

					{

					{

						if(!$word)






























						if(strlen($word) == 2)
{
$boolean[$depth] = substr($word, 0, 1);
}
$words[++$depth] = array();
$boolean[$depth] = '+';
}
else
{
$operator = substr($word, 0, 1);
switch($operator)
{
// Allowed operators
case '-':
case '+':
case '>':
case '<':
case '~':
$word = substr($word, 1);
break;
default:
$operator = $boolean[$depth];
break;
}
// Removed operators that are only allowed at the beginning
$word = preg_replace("#(-|\+|<|>|~|@)#s", '', $word);
// Removing wildcards at the beginning http://bugs.mysql.com/bug.php?id=72605
$word = preg_replace("#^\*#s", '', $word);
$word = $operator.$word;
if(strlen($word) <= 1)

						{
continue;
}

						{
continue;
}

						$words[] = trim($word);


						$words[$depth][] = $word;
$boolean[$depth] = '+';

					}
}
}

					}
}
}

			$inquote = !$inquote;
}
}
else
{
$split_words = preg_split("#\s{1,}#", $keywords, -1);
if(!is_array($split_words))
{
continue;

 
		}

		}

		foreach($split_words as $word)
{
if(!$word)
{
continue;
}
$words[] = trim($word);
}


		$inquote = !$inquote;









	}

	}

	$keywords = '';
foreach($words as $word)
{
if($word == "or")
{
$boolean = '';
}
elseif($word == "and")
{
$boolean = "+";
}
elseif($word == "not")
{
$boolean = "-";
}
else
{
$keywords .= " ".$boolean.$word;
$boolean = '';
}


// Close mismatching braces
while($depth > 0)
{
$words[$depth-1][] = $boolean[$depth-1].'('.implode(' ', $words[$depth]).')';
--$depth;















	}

	}

	$keywords = "+".trim($keywords);



$keywords = implode(' ', $words[0]);

	return $keywords;
}


	return $keywords;
}


Zeile 368Zeile 426
	{
$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

	if($keywords)
{
// Complex search

Zeile 384Zeile 442
			{
$string = "OR";
$subject_lookin = " AND (";

			{
$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
if(!$inquote)
{
// 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)
{

			}

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
if(!$inquote)
{
// 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)
{

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

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

						{

						{

							continue;

							continue;

						}

						}

						// 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 422Zeile 499
							$word = trim($word);
// Word is too short - show error message
if(my_strlen($word) < $mybb->settings['minsearchword'])

							$word = trim($word);
// Word is too short - show error message
if(my_strlen($word) < $mybb->settings['minsearchword'])

							{

							{

								$lang->error_minsearchlength = $lang->sprintf($lang->error_minsearchlength, $mybb->settings['minsearchword']);
error($lang->error_minsearchlength);
}
// Add terms to search query
if($search['subject'] == 1)

								$lang->error_minsearchlength = $lang->sprintf($lang->error_minsearchlength, $mybb->settings['minsearchword']);
error($lang->error_minsearchlength);
}
// 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)

Zeile 437Zeile 514
							}
}
}

							}
}
}

				}	

				}

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

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

Zeile 452Zeile 529
					if($search['message'] == 1)
{
$message_lookin .= " $boolean LOWER(message) 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;
}


Zeile 473Zeile 576
		{
$keywords = str_replace("\"", '', trim($keywords));
if(my_strlen($keywords) < $mybb->settings['minsearchword'])

		{
$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);
}

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

			{

			{

				$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 489Zeile 592
				{
$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 497Zeile 600
			}
}
}

			}
}
}

	



	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']))."%'");


$query = $db->simple_select("users", "uid", "LOWER(username) LIKE '%".$db->escape_string_like($search['sender'])."%'");

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

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

		{

		{

			$userids[] = $user['uid'];
}

			$userids[] = $user['uid'];
}

		



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

		if(count($userids) < 1)
{
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']))
{
$folderids = array();

	if(!empty($search['folder']))
{
$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)

		if($folderids)

		{

		{

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

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

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

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

		{

		{

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

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

		}

		}

		if($search['status']['replied'])
{
$statussql[] = " status='3' ";

		if($search['status']['replied'])
{
$statussql[] = " status='3' ";

		}
if($search['status']['forwarded'])

		}
if($search['status']['forwarded'])

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

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

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

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

	}


	}


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

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

	{

	{

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

Zeile 598Zeile 701

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


if($mybb->settings['minsearchword'] < 1)

	{

	{

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


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


Zeile 611Zeile 714
	{
// Complex search
$keywords = " {$keywords} ";

	{
// Complex search
$keywords = " {$keywords} ";

		if(preg_match("# and|or #", $keywords))

		if(preg_match("#\s(and|or)\s#", $keywords))

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

 
			$boolean = '';


foreach($keywords_exp as $phrase)
{


foreach($keywords_exp as $phrase)
{

Zeile 628Zeile 732
					// 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)
{
$word = trim($matches[$i]);

					for($i=0; $i < $count_matches; ++$i)
{
$word = trim($matches[$i]);

Zeile 639Zeile 743
						// 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 657Zeile 766
							{
$message_lookin .= " $boolean LOWER(p.message) LIKE '%{$word}%'";
}

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

 
							$boolean = 'AND';

						}
}

						}
}

				}	

				}

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

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

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

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

					}					









					}
$boolean = 'AND';
}

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 708Zeile 827
		else
{
$search['author'] = my_strtolower($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']))."%'");

			$query = $db->simple_select("users", "uid", "LOWER(username) LIKE '%".$db->escape_string_like($search['author'])."%'");

		}
while($user = $db->fetch_array($query))
{

		}
while($user = $db->fetch_array($query))
{

Zeile 742Zeile 861
		$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

		{

		{

			$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 = '';
$prefixlist = array();
if($search['threadprefix'] && $search['threadprefix'][0] != 'any')
{
foreach($search['threadprefix'] as $threadprefix)
{
$threadprefix = intval($threadprefix);
$prefixlist[] = $threadprefix;
}
}
if(count($prefixlist) == 1)

	{

	{

		$thread_prefixcut = " AND t.prefix='".intval($search['threadprefix'])."'";
}








		$thread_prefixcut .= " AND t.prefix='$threadprefix' ";
}
else
{
if(count($prefixlist) > 1)
{
$thread_prefixcut = " AND t.prefix IN (".implode(',', $prefixlist).")";
}
}


$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 815Zeile 950
 						break;
default:
$query = $db->simple_select("forums", "DISTINCT fid", "INSTR(CONCAT(',',parentlist,','),',{$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;
}

 				}

while($sforum = $db->fetch_array($query))
{
$fidlist[] = $sforum['fid'];
}
}
}
if(count($fidlist) == 1)
{
$forumin .= " AND t.fid='$forum' ";
$searchin[$fid] = 1;
}

		else

		else

		{			

		{

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

			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)
{
$onlyusfids[] = $fid;
}



	if($group_permissions = forum_permissions())
{
foreach($group_permissions as $fid => $forum_permissions)
{
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)

	{

	{

		$permsql .= " AND t.fid NOT IN ($unsearchforums)";

		$permsql .= " AND t.fid NOT IN ($unsearchforums)";

	}

	}

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

	$inactiveforums = get_inactive_forums();
if($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 881Zeile 1018
		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 895Zeile 1032
	{
$tidsql = " AND t.tid='".intval($search['tid'])."'";
}

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

	



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

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

	}


	}


	// Searching both posts and thread titles
$threads = array();
$posts = array();

	// Searching both posts and thread titles
$threads = array();
$posts = array();

Zeile 918Zeile 1055
				{$limitsql}
");
while($thread = $db->fetch_array($query))

				{$limitsql}
");
while($thread = $db->fetch_array($query))

			{

			{

				$threads[$thread['tid']] = $thread['tid'];
if($thread['firstpost'])
{

				$threads[$thread['tid']] = $thread['tid'];
if($thread['firstpost'])
{

Zeile 926Zeile 1063
				}
}
}

				}
}
}

		



		$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 935Zeile 1072
			{$limitsql}
");
while($post = $db->fetch_array($query))

			{$limitsql}
");
while($post = $db->fetch_array($query))

		{

		{

			$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)
{
error($lang->error_nosearchresults);

		if(count($posts) < 1 && count($threads) < 1)
{
error($lang->error_nosearchresults);

Zeile 963Zeile 1100
			if($thread['firstpost'])
{
$firstposts[$thread['tid']] = $thread['firstpost'];

			if($thread['firstpost'])
{
$firstposts[$thread['tid']] = $thread['firstpost'];

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


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


		$threads = implode(',', $threads);
$firstposts = implode(',', $firstposts);
if($firstposts)

		$threads = implode(',', $threads);
$firstposts = implode(',', $firstposts);
if($firstposts)

Zeile 1019Zeile 1156
	}

if($keywords)

	}

if($keywords)

	{

	{

		$keywords_exp = explode("\"", $keywords);
$inquote = false;
foreach($keywords_exp as $phrase)

		$keywords_exp = explode("\"", $keywords);
$inquote = false;
foreach($keywords_exp as $phrase)

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

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

					{

					{

						$all_too_short = true;
}
else

						$all_too_short = true;
}
else

Zeile 1068Zeile 1205
		}
$message_lookin = "AND MATCH(message) AGAINST('".$db->escape_string($keywords)."' IN BOOLEAN MODE)";
$subject_lookin = "AND MATCH(subject) AGAINST('".$db->escape_string($keywords)."' IN BOOLEAN MODE)";

		}
$message_lookin = "AND MATCH(message) AGAINST('".$db->escape_string($keywords)."' IN BOOLEAN MODE)";
$subject_lookin = "AND MATCH(subject) AGAINST('".$db->escape_string($keywords)."' IN BOOLEAN MODE)";

	}

	}

	$post_usersql = '';
$thread_usersql = '';
if($search['author'])
{
$userids = array();
if($search['matchusername'])

	$post_usersql = '';
$thread_usersql = '';
if($search['author'])
{
$userids = array();
if($search['matchusername'])

		{

		{

			$query = $db->simple_select("users", "uid", "username='".$db->escape_string($search['author'])."'");

			$query = $db->simple_select("users", "uid", "username='".$db->escape_string($search['author'])."'");

		}

		}

		else

		else

		{

		{

			$search['author'] = my_strtolower($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']))."%'");

			$query = $db->simple_select("users", "uid", "LOWER(username) LIKE '%".$db->escape_string_like($search['author'])."%'");

		}

		}

		



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

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

		else
{
$userids = implode(',', $userids);

Zeile 1104Zeile 1241
	if($search['postdate'])
{
if($search['pddir'] == 0)

	if($search['postdate'])
{
if($search['pddir'] == 0)

		{

		{

			$datecut = "<=";
}
else

			$datecut = "<=";
}
else

Zeile 1117Zeile 1254
		$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'])."'";

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

		}
}


		}
}


	$thread_prefixcut = '';

	$thread_prefixcut = '';

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


	$prefixlist = array();
if($search['threadprefix'] && $search['threadprefix'][0] != 'any')

	{

	{

		$thread_prefixcut = " AND t.prefix='".intval($search['threadprefix'])."'";
















		foreach($search['threadprefix'] as $threadprefix)
{
$threadprefix = intval($threadprefix);
$prefixlist[] = $threadprefix;
}
}
if(count($prefixlist) == 1)
{
$thread_prefixcut .= " AND t.prefix='$threadprefix' ";
}
else
{
if(count($prefixlist) > 1)
{
$thread_prefixcut = " AND t.prefix IN (".implode(',', $prefixlist).")";
}

	}

$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 1162Zeile 1315
					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."))

							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)

							WHERE INSTR(','||parentlist||',',',$forum,') > 0 AND active!=0 AND ((p.fid) IS NULL OR p.cansearch=1)

						");
break;
default:
$query = $db->query("

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

							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)

							WHERE INSTR(CONCAT(',',parentlist,','),',$forum,') > 0 AND active!=0 AND ((p.fid) IS NULL OR p.cansearch=1)

						");
}
while($sforum = $db->fetch_array($query))
{
$fidlist[] = $sforum['fid'];
}

						");
}
while($sforum = $db->fetch_array($query))
{
$fidlist[] = $sforum['fid'];
}

			}
}

			}
}

		if(count($fidlist) == 1)

		if(count($fidlist) == 1)

		{

		{

			$forumin .= " AND t.fid='$forum' ";
$searchin[$fid] = 1;
}
else
{

			$forumin .= " AND t.fid='$forum' ";
$searchin[$fid] = 1;
}
else
{

			



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

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

Zeile 1198Zeile 1351
	}
$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 1212Zeile 1365
	{
$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)
{
$permsql .= " AND t.fid NOT IN ($unsearchforums)";

	$unsearchforums = get_unsearchable_forums();
if($unsearchforums)
{
$permsql .= " AND t.fid NOT IN ($unsearchforums)";

	}

	}

	$inactiveforums = get_inactive_forums();
if($inactiveforums)

	$inactiveforums = get_inactive_forums();
if($inactiveforums)

	{

	{

		$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'";
$plain_post_visiblesql = " AND visible = '1'";

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

			}
}

			}
}

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