Vergleich inc/functions_search.php - 1.8.6 - 1.8.13

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 229Zeile 229
 */
function clean_keywords($keywords)
{

 */
function clean_keywords($keywords)
{

 
	global $db;


	$keywords = my_strtolower($keywords);

	$keywords = my_strtolower($keywords);

	$keywords = str_replace("%", "\\%", $keywords);

	$keywords = $db->escape_string_like($keywords);

	$keywords = preg_replace("#\*{2,}#s", "*", $keywords);
$keywords = str_replace("*", "%", $keywords);

	$keywords = preg_replace("#\*{2,}#s", "*", $keywords);
$keywords = str_replace("*", "%", $keywords);

	$keywords = preg_replace("#([\[\]\|\.\,:'])#s", " ", $keywords);

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

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

 
	$keywords = str_replace('\\"', '"', $keywords);


// Search for "and" or "or" and remove if it's at the beginning
$keywords = trim($keywords);
if(my_strpos($keywords, "or") === 0)


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

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

	return $keywords;
}





/**
* Clean search keywords for fulltext searching, making them safe for querying
*

/**
* Clean search keywords for fulltext searching, making them safe for querying
*

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





	$words = array(array());

// Fulltext search syntax validation: http://dev.mysql.com/doc/refman/5.6/en/fulltext-boolean.html

	$words = array(array());

// Fulltext search syntax validation: http://dev.mysql.com/doc/refman/5.6/en/fulltext-boolean.html

Zeile 310Zeile 312
					if($last_char == '+' || $last_char == '-' || $last_char == '<' || $last_char == '>' || $last_char == '~')
{
$phrase_operator = $last_char;

					if($last_char == '+' || $last_char == '-' || $last_char == '<' || $last_char == '>' || $last_char == '~')
{
$phrase_operator = $last_char;

					}
}

					}
}

				foreach($split_words as $word)
{
$word = trim($word);

				foreach($split_words as $word)
{
$word = trim($word);

Zeile 332Zeile 334
					elseif($word == "and")
{
$boolean[$depth] = "+";

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

					}

					}

					elseif($word == "not")
{
$boolean[$depth] = "-";

					elseif($word == "not")
{
$boolean[$depth] = "-";

Zeile 373Zeile 375
							default:
$operator = $boolean[$depth];
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

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

Zeile 394Zeile 396

// Close mismatching braces
while($depth > 0)


// Close mismatching braces
while($depth > 0)

	{

	{

		$words[$depth-1][] = $boolean[$depth-1].'('.implode(' ', $words[$depth]).')';
--$depth;
}

		$words[$depth-1][] = $boolean[$depth-1].'('.implode(' ', $words[$depth]).')';
--$depth;
}

Zeile 723Zeile 725
 * @return array Array of search data with results mixed in
*/
function helpdocument_perform_search_mysql($search)

 * @return array Array of search data with results mixed in
*/
function helpdocument_perform_search_mysql($search)

{

{

	global $mybb, $db, $lang;

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

	global $mybb, $db, $lang;

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

Zeile 784Zeile 786
					// 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 865Zeile 867
				elseif($search['name'] && !$search['document'] && $name_lookin == " AND (")
{
// Just in a name?

				elseif($search['name'] && !$search['document'] && $name_lookin == " AND (")
{
// Just in a name?

					$error = true;

					$error = true;

				}
elseif(!$search['name'] && $search['document'] && $document_lookin == " {$string} (")

				}
elseif(!$search['name'] && $search['document'] && $document_lookin == " {$string} (")

				{

				{

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

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

Zeile 886Zeile 888
			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 908Zeile 910
			if($search['name'] == 1 && $search['document'] == 1)
{
$searchsql .= " AND ({$nfield} LIKE '%{$keywords}%' OR {$dfield} LIKE '%{$keywords}%')";

			if($search['name'] == 1 && $search['document'] == 1)
{
$searchsql .= " AND ({$nfield} LIKE '%{$keywords}%' OR {$dfield} LIKE '%{$keywords}%')";

			}

			}

			else
{
if($search['name'] == 1)

			else
{
if($search['name'] == 1)

Zeile 991Zeile 993
			$keywords_exp = explode("\"", $keywords);
$inquote = false;
$boolean = '';

			$keywords_exp = explode("\"", $keywords);
$inquote = false;
$boolean = '';





			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 1052Zeile 1054
					if($search['postthread'] == 1)
{
$message_lookin .= " $boolean {$pfield} LIKE '%{$phrase}%'";

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

					}

					}

					$boolean = 'AND';
}


					$boolean = 'AND';
}


Zeile 1092Zeile 1094
		if($search['matchusername'])
{
$user = get_user_by_username($search['author']);

		if($search['matchusername'])
{
$user = get_user_by_username($search['author']);

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




			if($user)
{
$userids[] = $user['uid'];
}

		}
else
{

		}
else
{

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

			$query = $db->simple_select("users", "uid", "{$field} LIKE '%".$db->escape_string_like($search['author'])."%'");
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

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

		}

		}

	}
$datecut = $post_datecut = $thread_datecut = '';
if($search['postdate'])

	}
$datecut = $post_datecut = $thread_datecut = '';
if($search['postdate'])

Zeile 1130Zeile 1135
		if($search['pddir'] == 0)
{
$datecut = "<=";

		if($search['pddir'] == 0)
{
$datecut = "<=";

		}
else
{

		}
else
{

			$datecut = ">=";
}
$now = TIME_NOW;

			$datecut = ">=";
}
$now = TIME_NOW;

Zeile 1146Zeile 1151
	if($search['numreplies'] != '' && $search['findthreadst'])
{
if((int)$search['findthreadst'] == 1)

	if($search['numreplies'] != '' && $search['findthreadst'])
{
if((int)$search['findthreadst'] == 1)

		{

		{

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

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

		}
}

		}
}


$thread_prefixcut = '';
$prefixlist = array();


$thread_prefixcut = '';
$prefixlist = array();

Zeile 1179Zeile 1184

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


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

	$searchin = array();
if(!is_array($search['forums']) || $search['forums'][0] != "all")

	if(!empty($search['forums']) && (!is_array($search['forums']) || $search['forums'][0] != "all"))


	{
if(!is_array($search['forums']))
{
$search['forums'] = array((int)$search['forums']);

	{
if(!is_array($search['forums']))
{
$search['forums'] = array((int)$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 = (int)$forum;

		}
foreach($search['forums'] as $forum)
{
$forum = (int)$forum;

			if(empty($searchin[$forum]))

			if($forum > 0)

			{

			{

				if(isset($add_groups) && is_array($add_groups))



				$fidlist[] = $forum;
$child_list = get_child_list($forum);
if(is_array($child_list))

				{

				{

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

					$fidlist = array_merge($fidlist, $child_list);
































				}
}
}

				}
}
}

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

		$fidlist = array_unique($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
if($group_permissions = forum_permissions())
{

	// Check group permissions if we can't view threads not started by us
if($group_permissions = forum_permissions())
{

Zeile 1267Zeile 1225
		}
}
if(!empty($onlyusfids))

		}
}
if(!empty($onlyusfids))

	{
$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 1506Zeile 1464
		if($search['matchusername'])
{
$user = get_user_by_username($search['author']);

		if($search['matchusername'])
{
$user = get_user_by_username($search['author']);

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




			if($user)
{
$userids[] = $user['uid'];
}

		}
else
{

		}
else
{

			switch($db->type)
{
case 'mysql':
case 'mysqli':
$field = 'username';
break;
default:
$field = 'LOWER(username)';
break;
}
$query = $db->simple_select("users", "uid", "{$field} LIKE '%".$db->escape_string_like($search['author'])."%'");

			$query = $db->simple_select("users", "uid", "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);
}
else

			error($lang->error_nosearchresults);
}
else

Zeile 1537Zeile 1488
			$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.")";

		}
}

		}
}

	$datecut = '';
if($search['postdate'])
{

	$datecut = '';
if($search['postdate'])
{

Zeile 1561Zeile 1512
	if($search['numreplies'] != '' && $search['findthreadst'])
{
if((int)$search['findthreadst'] == 1)

	if($search['numreplies'] != '' && $search['findthreadst'])
{
if((int)$search['findthreadst'] == 1)

		{

		{

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

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

		}

		}

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

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

Zeile 1573Zeile 1524
	$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;

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

Zeile 1581Zeile 1532
		}
}
if(count($prefixlist) == 1)

		}
}
if(count($prefixlist) == 1)

	{

	{

		$thread_prefixcut .= " AND t.prefix='$threadprefix' ";
}
else

		$thread_prefixcut .= " AND t.prefix='$threadprefix' ";
}
else

	{

	{

		if(count($prefixlist) > 1)

		if(count($prefixlist) > 1)

		{

		{

			$thread_prefixcut = " AND t.prefix IN (".implode(',', $prefixlist).")";
}
}

			$thread_prefixcut = " AND t.prefix IN (".implode(',', $prefixlist).")";
}
}

Zeile 1595Zeile 1546
	$forumin = '';
$fidlist = array();
$searchin = array();

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

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

	if(!empty($search['forums']) && (!is_array($search['forums']) || $search['forums'][0] != "all"))

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

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

		{

		{

			$search['forums'] = array((int)$search['forums']);

			$search['forums'] = array((int)$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 = (int)$forum;

		foreach($search['forums'] as $forum)
{
$forum = (int)$forum;

			if(empty($searchin[$forum]))
{
switch($db->type)
{
case "pgsql":
case "sqlite":
$query = $db->query("
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 ((p.fid) IS NULL OR p.cansearch=1)
");
break;
default:
$query = $db->query("
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 ((p.fid) IS NULL OR p.cansearch=1)
");
}
while($sforum = $db->fetch_array($query))

			if($forum > 0)
{
$fidlist[] = $forum;
$child_list = get_child_list($forum);
if(is_array($child_list))


















				{

				{

					$fidlist[] = $sforum['fid'];

					$fidlist = array_merge($fidlist, $child_list);

				}

				}

			}
}
if(count($fidlist) == 1)
{
$forumin .= " AND t.fid='$forum' ";
$searchin[$forum] = 1;

			}






		}

		}

		else


		$fidlist = array_unique($fidlist);
if(count($fidlist) >= 1)

		{

		{


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

			$forumin = " AND t.fid IN (".implode(',', $fidlist).")";





		}
}
$permsql = "";

		}
}
$permsql = "";