Vergleich inc/functions_search.php - 1.8.19 - 1.8.21

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 272Zeile 272
	// Separate braces for further processing
$keywords = preg_replace("#((\+|-|<|>|~)?\(|\))#s", " $1 ", $keywords);
$keywords = preg_replace("#\s+#s", " ", $keywords);

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

 
	
global $mybb;

$min_word_length = (int) $mybb->settings['minsearchword'];
if($min_word_length <= 0)
{
$min_word_length = 3;
}
$min_word_length -= 1;

// Replaces less than 3 characters
$keywords = preg_replace("/(\b.{1,{$min_word_length}})(\s)|(\b.{1,{$min_word_length}}$)/", '$2', $keywords);
// Collapse multiple spaces
$keywords = preg_replace('/(\s)+/', '$1', $keywords);
$keywords = trim($keywords);


$words = array(array());



$words = array(array());


Zeile 288Zeile 303
		if($phrase != '')
{
if($inquote)

		if($phrase != '')
{
if($inquote)

			{

			{

				if($phrase_operator)

				if($phrase_operator)

				{

				{

					$boolean[$depth] = $phrase_operator;
}
// Phrases do not need further processing

					$boolean[$depth] = $phrase_operator;
}
// Phrases do not need further processing

Zeile 304Zeile 319
				if(!is_array($split_words))
{
continue;

				if(!is_array($split_words))
{
continue;

				}

				}

				if(!$inquote)
{
// Save possible operator in front of phrase

				if(!$inquote)
{
// Save possible operator in front of phrase

Zeile 353Zeile 368
					elseif($word == '+(' || $word == '-(' || $word == '<(' || $word == '>(' || $word == '~(' || $word == '(')
{
if(strlen($word) == 2)

					elseif($word == '+(' || $word == '-(' || $word == '<(' || $word == '>(' || $word == '~(' || $word == '(')
{
if(strlen($word) == 2)

						{

						{

							$boolean[$depth] = substr($word, 0, 1);
}
$words[++$depth] = array();

							$boolean[$depth] = substr($word, 0, 1);
}
$words[++$depth] = array();

Zeile 403Zeile 418

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


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

}

/* Database engine specific search functions */

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

}

/* Database engine specific search functions */

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

 * @param array $search Array of search data
* @return array Array of search data with results mixed in
*/
function privatemessage_perform_search_mysql($search)
{
global $mybb, $db, $lang;

 * @param array $search Array of search data
* @return array Array of search data with results mixed in
*/
function privatemessage_perform_search_mysql($search)
{
global $mybb, $db, $lang;





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

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

	}

	}


if($mybb->settings['minsearchword'] < 1)
{
$mybb->settings['minsearchword'] = 3;
}


if($mybb->settings['minsearchword'] < 1)
{
$mybb->settings['minsearchword'] = 3;
}





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

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

Zeile 479Zeile 494
					$count_matches = count($matches);

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

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

Zeile 547Zeile 562
					if($search['message'] == 1)
{
$message_lookin .= " $boolean {$mfield} LIKE '%{$phrase}%'";

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

					}
$boolean = 'AND';
}

					}
$boolean = 'AND';
}


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


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

					$error = true;

				}
elseif($search['subject'] && !$search['message'] && $subject_lookin == " AND (")
{

				}
elseif($search['subject'] && !$search['message'] && $subject_lookin == " AND (")
{

Zeile 564Zeile 579
					$error = true;
}
elseif(!$search['subject'] && $search['message'] && $message_lookin == " {$string} (")

					$error = true;
}
elseif(!$search['subject'] && $search['message'] && $message_lookin == " {$string} (")

				{

				{

					// Just in a message?
$error = true;
}

					// Just in a message?
$error = true;
}

Zeile 598Zeile 613
			{
$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 649Zeile 664
		{
$userids = implode(',', $userids);
$searchsql .= " AND fromid IN (".$userids.")";

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

		}
}

		}
}


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


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

Zeile 685Zeile 700
		if($search['status']['forwarded'])
{
$statussql[] = " status='4' ";

		if($search['status']['forwarded'])
{
$statussql[] = " status='4' ";

		}
if($search['status']['read'])
{
$statussql[] = " (status != '0' AND readtime > '0') ";
}

		}
if($search['status']['read'])
{
$statussql[] = " (status != '0' AND readtime > '0') ";
}

		// Sent Folder
if(in_array(2, $search['folder']))
{

		// Sent Folder
if(in_array(2, $search['folder']))
{

Zeile 701Zeile 716

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


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

	{

	{

		$limitsql = " LIMIT ".(int)$mybb->settings['searchhardlimit'];
}
$searchsql .= $limitsql;

		$limitsql = " LIMIT ".(int)$mybb->settings['searchhardlimit'];
}
$searchsql .= $limitsql;

Zeile 803Zeile 818
						}
// 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['name'] && $search['document'] && $name_lookin == " AND (")
{
// We're looking for anything, check for a name lookin

							if($i <= 1)
{
if($search['name'] && $search['document'] && $name_lookin == " AND (")
{
// We're looking for anything, check for a name lookin

									continue;
}

									continue;
}

								elseif($search['name'] && !$search['document'] && $name_lookin == " AND (")

								elseif($search['name'] && !$search['document'] && $name_lookin == " AND (")

								{

								{

									// Just in a name?

									// Just in a name?

									continue;

									continue;

								}
elseif(!$search['name'] && $search['document'] && $document_lookin == " {$string} (")
{
// Just in a document?
continue;
}

								}
elseif(!$search['name'] && $search['document'] && $document_lookin == " {$string} (")
{
// Just in a document?
continue;
}

							}

$boolean = $word;
}
// Otherwise check the length of the word as it is a normal search term
else
{
$word = trim($word);
// Word is too short - show error message

							}

$boolean = $word;
}
// Otherwise check the length of the word as it is a normal search term
else
{
$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);

							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['name'] == 1)
{

							// Add terms to search query
if($search['name'] == 1)
{

Zeile 845Zeile 860
								$document_lookin .= " $boolean {$dfield} LIKE '%{$word}%'";
}
}

								$document_lookin .= " $boolean {$dfield} LIKE '%{$word}%'";
}
}

					}
}

					}
}

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

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

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

					}

					}

					// Add phrase to search query
$name_lookin .= " $boolean {$nfield} LIKE '%{$phrase}%'";
if($search['document'] == 1)
{
$document_lookin .= " $boolean {$dfield} LIKE '%{$phrase}%'";
}

					// Add phrase to search query
$name_lookin .= " $boolean {$nfield} LIKE '%{$phrase}%'";
if($search['document'] == 1)
{
$document_lookin .= " $boolean {$dfield} LIKE '%{$phrase}%'";
}

				}


				}


				// Check to see if we have any search terms and not a malformed SQL string
$error = false;
if($search['name'] && $search['document'] && $name_lookin == " AND (")

				// Check to see if we have any search terms and not a malformed SQL string
$error = false;
if($search['name'] && $search['document'] && $name_lookin == " AND (")

Zeile 895Zeile 910
			if($search['name'] == 1)
{
$name_lookin .= ")";

			if($search['name'] == 1)
{
$name_lookin .= ")";

			}


			}


			if($search['document'] == 1)
{
$document_lookin .= ")";

			if($search['document'] == 1)
{
$document_lookin .= ")";

Zeile 946Zeile 961
		error($lang->error_nosearchresults);
}
$helpdocs = implode(',', $helpdocs);

		error($lang->error_nosearchresults);
}
$helpdocs = implode(',', $helpdocs);





	return array(
"querycache" => $helpdocs
);

	return array(
"querycache" => $helpdocs
);

Zeile 963Zeile 978
	global $mybb, $db, $lang, $cache;

$keywords = clean_keywords($search['keywords']);

	global $mybb, $db, $lang, $cache;

$keywords = clean_keywords($search['keywords']);

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

 

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


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

Zeile 1113Zeile 1124
				case 'mysql':
case 'mysqli':
$field = 'username';

				case 'mysql':
case 'mysqli':
$field = 'username';

					break;

					break;

				default:
$field = 'LOWER(username)';
break;

				default:
$field = 'LOWER(username)';
break;

			}

			}

			$query = $db->simple_select("users", "uid", "{$field} LIKE '%".$db->escape_string_like($search['author'])."%'");
while($user = $db->fetch_array($query))
{

			$query = $db->simple_select("users", "uid", "{$field} LIKE '%".$db->escape_string_like($search['author'])."%'");
while($user = $db->fetch_array($query))
{

Zeile 1126Zeile 1137
		}

if(count($userids) < 1)

		}

if(count($userids) < 1)

		{

		{

			error($lang->error_nosearchresults);

			error($lang->error_nosearchresults);

		}
else
{

		}
else
{

			$userids = implode(',', $userids);
$post_usersql = " AND p.uid IN (".$userids.")";
$thread_usersql = " AND t.uid IN (".$userids.")";

			$userids = implode(',', $userids);
$post_usersql = " AND p.uid IN (".$userids.")";
$thread_usersql = " AND t.uid IN (".$userids.")";

Zeile 1164Zeile 1175
		else
{
$thread_replycut = " AND t.replies <= '".(int)$search['numreplies']."'";

		else
{
$thread_replycut = " AND t.replies <= '".(int)$search['numreplies']."'";

		}
}

		}
}


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


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

	{

	{

		foreach($search['threadprefix'] as $threadprefix)
{
$threadprefix = (int)$threadprefix;
$prefixlist[] = $threadprefix;
}

		foreach($search['threadprefix'] as $threadprefix)
{
$threadprefix = (int)$threadprefix;
$prefixlist[] = $threadprefix;
}

	}

	}

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

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

	{

	{

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

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

Zeile 1234Zeile 1245
	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)
{


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

			}
}

			}
}

		elseif($search['visible'] == -1)

		elseif($search['visible'] == -1)

		{

		{

			$visiblesql = " AND t.visible = '-1'";

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

			$visiblesql = " AND t.visible = '-1'";

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

Zeile 1271Zeile 1282
			}
}
else

			}
}
else

		{

		{

			$visiblesql = " AND t.visible == '0'";

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

			$visiblesql = " AND t.visible == '0'";

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

Zeile 1280Zeile 1291
				$plain_post_visiblesql = " AND visible == '0'";
}
}

				$plain_post_visiblesql = " AND visible == '0'";
}
}

	}

	}


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


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

	}


	}


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

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

Zeile 1339Zeile 1350
		}
$threads = implode(',', $threads);
$posts = implode(',', $posts);

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


}


}

	// Searching only thread titles
else
{

	// Searching only thread titles
else
{

Zeile 1393Zeile 1404
	global $mybb, $db, $lang;

$keywords = clean_keywords_ft($search['keywords']);

	global $mybb, $db, $lang;

$keywords = clean_keywords_ft($search['keywords']);

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

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