Vergleich inc/functions_search.php - 1.8.15 - 1.8.26

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 54Zeile 54
						$optionselected = '';
$selecteddone = "0";
}

						$optionselected = '';
$selecteddone = "0";
}

					if($forum['password'] != '')

					if(forum_password_validated($forum, true))

					{

					{

						if($mybb->cookies['forumpass'][$forum['fid']] === md5($mybb->user['uid'].$forum['password']))
{
$pwverified = 1;
}
else
{
$pwverified = 0;
}
}
if(empty($forum['password']) || $pwverified == 1)
{
eval("\$forumlistbits .= \"".$templates->get("search_forumlist_forum")."\";");

						eval("\$forumlistbits .= \"".$templates->get("search_forumlist_forum")."\";");












					}
if(!empty($pforumcache[$forum['fid']]))
{

					}
if(!empty($pforumcache[$forum['fid']]))
{

Zeile 83Zeile 72
		eval("\$forumlist = \"".$templates->get("search_forumlist")."\";");
}
return $forumlist;

		eval("\$forumlist = \"".$templates->get("search_forumlist")."\";");
}
return $forumlist;

}


}


/**
* Build a comma separated list of the forums this user cannot search
*

/**
* Build a comma separated list of the forums this user cannot search
*

Zeile 108Zeile 97
		}
}
if(!is_array($permissioncache))

		}
}
if(!is_array($permissioncache))

	{

	{

		$permissioncache = forum_permissions();
}
foreach($forum_cache as $fid => $forum)

		$permissioncache = forum_permissions();
}
foreach($forum_cache as $fid => $forum)

Zeile 116Zeile 105
		if($permissioncache[$forum['fid']])
{
$perms = $permissioncache[$forum['fid']];

		if($permissioncache[$forum['fid']])
{
$perms = $permissioncache[$forum['fid']];

		}

		}

		else

		else

		{

		{

			$perms = $mybb->usergroup;

			$perms = $mybb->usergroup;

		}

$pwverified = 1;
if($forum['password'] != '')
{
if($mybb->cookies['forumpass'][$forum['fid']] !== md5($mybb->user['uid'].$forum['password']))
{
$pwverified = 0;
}

 
		}

$parents = explode(",", $forum['parentlist']);

		}

$parents = explode(",", $forum['parentlist']);

Zeile 143Zeile 123
			}
}


			}
}


		if($perms['canview'] != 1 || $perms['cansearch'] != 1 || $pwverified == 0 || $forum['active'] == 0)

		if($perms['canview'] != 1 || $perms['cansearch'] != 1 || !forum_password_validated($forum, true) || $forum['active'] == 0)

		{
if($unsearchableforums)
{

		{
if($unsearchableforums)
{

Zeile 160Zeile 140
	if($unsearchable && $pass_protected_forums)
{
$unsearchable .= ",";

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

	}


	}


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

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

	}


	}


	return $unsearchable;

	return $unsearchable;

 
}

/**
* Build query condition for threads/posts the user is allowed to see.
* Will return for example:
* - visible = 1 - for normal users
* - visible >= -1 - for admins & super mods
* - (visible = 1 OR (visible = ? AND fid IN ...)) - for forum moderators
*
* @param string $table_alias The alias of the table eg t to use t.visible instead of visible
* @return string the query condition
*/
function get_visible_where($table_alias = null)
{
global $db, $mybb;

$aliasdot = '';
if(!empty($table_alias))
{
$aliasdot = $table_alias.'.';
}

if($mybb->usergroup['issupermod'] == 1)
{
// Super moderators (and admins)
return "{$aliasdot}visible >= -1";
}
elseif(is_moderator())
{
// Normal moderators
$unapprove_forums = array();
$deleted_forums = array();
$unapproved_where = "({$aliasdot}visible = 1";

$moderated_fids = get_moderated_fids($mybb->user['uid']);

if($moderated_fids !== false)
{
foreach($moderated_fids as $fid)
{
if(!is_moderator($fid))
{
// Shouldn't occur.
continue;
}

// Use moderates this forum
$modperms = get_moderator_permissions($fid, $mybb->user['uid']);

if($modperms['canviewunapprove'] == 1)
{
$unapprove_forums[] = $fid;
}

if($modperms['canviewdeleted'] == 1)
{
$deleted_forums[] = $fid;
}
}

if(!empty($unapprove_forums))
{
$unapproved_where .= " OR ({$aliasdot}visible = 0 AND {$aliasdot}fid IN(".implode(',', $unapprove_forums)."))";
}
if(!empty($deleted_forums))
{
$unapproved_where .= " OR ({$aliasdot}visible = -1 AND {$aliasdot}fid IN(".implode(',', $deleted_forums)."))";
}
$unapproved_where .= ')';

return $unapproved_where;
}
}

// Normal users
if($mybb->user['uid'] > 0 && $mybb->settings['showownunapproved'] == 1)
{
return "({$aliasdot}visible = 1 OR ({$aliasdot}visible = 0 AND {$aliasdot}uid = {$mybb->user['uid']}))";
}
return "{$aliasdot}visible = 1";

}

/**

}

/**

Zeile 186Zeile 246
	}

if(!is_array($forum_cache))

	}

if(!is_array($forum_cache))

	{

	{

		$forum_cache = cache_forums();
if(!$forum_cache)
{
return false;

		$forum_cache = cache_forums();
if(!$forum_cache)
{
return false;

		}
}

		}
}


if(empty($fids))
{


if(empty($fids))
{

Zeile 202Zeile 262
	$pass_fids = array();
foreach($fids as $fid)
{

	$pass_fids = array();
foreach($fids as $fid)
{

		if(empty($forum_cache[$fid]['password']))
{
continue;
}

if(md5($mybb->user['uid'].$forum_cache[$fid]['password']) !== $mybb->cookies['forumpass'][$fid])

		if(!forum_password_validated($forum_cache[$fid], true))






		{
$pass_fids[] = $fid;

		{
$pass_fids[] = $fid;

			$child_list = get_child_list($fid);
}

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

			$pass_fids = array_merge($pass_fids, get_child_list($fid));






		}
}
return array_unique($pass_fids);

		}
}
return array_unique($pass_fids);

Zeile 264Zeile 314
	if(!$keywords)
{
return false;

	if(!$keywords)
{
return false;

	}

	}

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

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

Zeile 272Zeile 322
	// 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;

$word_length_regex = '';
if($min_word_length > 1)
{
$word_length_regex = "{1,{$min_word_length}}";
}

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


$words = array(array());



$words = array(array());


Zeile 312Zeile 383
					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 457Zeile 528
			{
$string = "OR";
$subject_lookin = " AND (";

			{
$string = "OR";
$subject_lookin = " AND (";

			}


			}


			if($search['message'] == 1)
{
$message_lookin = " {$string} (";

			if($search['message'] == 1)
{
$message_lookin = " {$string} (";

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

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

 

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


// 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 746Zeile 824
	if($keywords)
{
switch($db->type)

	if($keywords)
{
switch($db->type)

		{

		{

			case 'mysql':
case 'mysqli':
$nfield = 'name';

			case 'mysql':
case 'mysqli':
$nfield = 'name';

Zeile 814Zeile 892
									// Just in a document?
continue;
}

									// Just in a document?
continue;
}

							}

							}


$boolean = $word;


$boolean = $word;

						}

						}

						// Otherwise check the length of the word as it is a normal search term
else
{

						// Otherwise check the length of the word as it is a normal search term
else
{

Zeile 827Zeile 905
							{
$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 terms to search query
if($search['name'] == 1)
{
$name_lookin .= " $boolean {$nfield} LIKE '%{$word}%'";

							// Add terms to search query
if($search['name'] == 1)
{
$name_lookin .= " $boolean {$nfield} LIKE '%{$word}%'";

							}
if($search['document'] == 1)
{
$document_lookin .= " $boolean {$dfield} LIKE '%{$word}%'";
}
}
}
}
// In the middle of a quote (phrase)
else
{
$phrase = str_replace(array("+", "-", "*"), '', trim($phrase));
if(my_strlen($phrase) < $mybb->settings['minsearchword'])
{

							}
if($search['document'] == 1)
{
$document_lookin .= " $boolean {$dfield} LIKE '%{$word}%'";
}
}
}
}
// 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);
}

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

Zeile 860Zeile 938
				// 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 (")

				{

				{

					// We're looking for anything, check for a name lookin

					// We're looking for anything, check for a name lookin

					$error = true;
}

					$error = true;
}

				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} (")
{
// Just in a document?
$error = true;

				elseif(!$search['name'] && $search['document'] && $document_lookin == " {$string} (")
{
// Just in a document?
$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);
}

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

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

				$inquote = !$inquote;
}

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

			}

			}


if($search['document'] == 1)
{


if($search['document'] == 1)
{

Zeile 916Zeile 994
				if($search['name'] == 1)
{
$searchsql .= " AND {$nfield} LIKE '%{$keywords}%'";

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

				}

				}


if($search['document'] == 1)
{


if($search['document'] == 1)
{

Zeile 930Zeile 1008
	$helpdocs = array();
$query = $db->simple_select("helpdocs", "hid", $searchsql);
while($help = $db->fetch_array($query))

	$helpdocs = array();
$query = $db->simple_select("helpdocs", "hid", $searchsql);
while($help = $db->fetch_array($query))

	{

	{

		$helpdocs[$help['hid']] = $help['hid'];

		$helpdocs[$help['hid']] = $help['hid'];

	}

	}


if(count($helpdocs) < 1)
{


if(count($helpdocs) < 1)
{

Zeile 944Zeile 1022
		"querycache" => $helpdocs
);
}

		"querycache" => $helpdocs
);
}





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

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

Zeile 956Zeile 1034
	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 1221Zeile 1295
			if(isset($forum_permissions['canonlyviewownthreads']) && $forum_permissions['canonlyviewownthreads'] == 1)
{
$onlyusfids[] = $fid;

			if(isset($forum_permissions['canonlyviewownthreads']) && $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)."))";
}

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

			}
}
}
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)
{
$permsql .= " AND t.fid NOT IN ($unsearchforums)";
}
$inactiveforums = get_inactive_forums();

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


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


	$visiblesql = $post_visiblesql = $plain_post_visiblesql = "";

	$visiblesql = $post_visiblesql = $plain_post_visiblesql = $unapproved_where_t = $unapproved_where_p = "";

	if(isset($search['visible']))
{
if($search['visible'] == 1)

	if(isset($search['visible']))
{
if($search['visible'] == 1)

Zeile 1271Zeile 1345
			{
$post_visiblesql = " AND p.visible == '0'";
$plain_post_visiblesql = " AND visible == '0'";

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

			}
}
}






			}
}
}

// Moderators can view unapproved threads and deleted threads from forums they moderate
$unapproved_where_t = get_visible_where('t');
$unapproved_where_p = get_visible_where('p');


	// Searching a specific thread?
$tidsql = '';
if(!empty($search['tid']))

	// Searching a specific thread?
$tidsql = '';
if(!empty($search['tid']))

Zeile 1300Zeile 1378
			$query = $db->query("
SELECT t.tid, t.firstpost
FROM ".TABLE_PREFIX."threads t

			$query = $db->query("
SELECT t.tid, t.firstpost
FROM ".TABLE_PREFIX."threads t

				WHERE 1=1 {$thread_datecut} {$thread_replycut} {$thread_prefixcut} {$forumin} {$thread_usersql} {$permsql} {$visiblesql} AND t.closed NOT LIKE 'moved|%' {$subject_lookin}

				WHERE 1=1 {$thread_datecut} {$thread_replycut} {$thread_prefixcut} {$forumin} {$thread_usersql} {$permsql} {$visiblesql} AND ({$unapproved_where_t}) AND t.closed NOT LIKE 'moved|%' {$subject_lookin}

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

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

Zeile 1317Zeile 1395
			SELECT p.pid, p.tid
FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)

			SELECT p.pid, p.tid
FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)

			WHERE 1=1 {$post_datecut} {$thread_replycut} {$thread_prefixcut} {$forumin} {$post_usersql} {$permsql} {$tidsql} {$visiblesql} {$post_visiblesql} AND t.closed NOT LIKE 'moved|%' {$message_lookin}

			WHERE 1=1 {$post_datecut} {$thread_replycut} {$thread_prefixcut} {$forumin} {$post_usersql} {$permsql} {$tidsql} {$visiblesql} {$post_visiblesql} AND ({$unapproved_where_t}) AND ({$unapproved_where_p}) AND t.closed NOT LIKE 'moved|%' {$message_lookin}

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

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

Zeile 1354Zeile 1432
		if(count($threads) < 1)
{
error($lang->error_nosearchresults);

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

		}

		}


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


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

Zeile 1386Zeile 1464
	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');
if(is_numeric($min_length))
{
$mybb->settings['minsearchword'] = $min_length;
}
// Otherwise, could not fetch - default back to MySQL fulltext default setting
else

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









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

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

Zeile 1599Zeile 1665
		$permsql .= " AND t.fid NOT IN ($inactiveforums)";
}


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


	$visiblesql = $post_visiblesql = $plain_post_visiblesql = "";

	$visiblesql = $post_visiblesql = $plain_post_visiblesql = $unapproved_where_t = $unapproved_where_p = "";

	if(isset($search['visible']))
{
if($search['visible'] == 1)

	if(isset($search['visible']))
{
if($search['visible'] == 1)

Zeile 1633Zeile 1699
			}
}
}

			}
}
}

 

// Moderators can view unapproved threads and deleted threads from forums they moderate
$unapproved_where_t = get_visible_where('t');
$unapproved_where_p = get_visible_where('p');


// Searching a specific thread?
if($search['tid'])


// Searching a specific thread?
if($search['tid'])

Zeile 1658Zeile 1728
			$query = $db->query("
SELECT t.tid, t.firstpost
FROM ".TABLE_PREFIX."threads t

			$query = $db->query("
SELECT t.tid, t.firstpost
FROM ".TABLE_PREFIX."threads t

				WHERE 1=1 {$thread_datecut} {$thread_replycut} {$thread_prefixcut} {$forumin} {$thread_usersql} {$permsql} {$visiblesql} AND t.closed NOT LIKE 'moved|%' {$subject_lookin}

				WHERE 1=1 {$thread_datecut} {$thread_replycut} {$thread_prefixcut} {$forumin} {$thread_usersql} {$permsql} {$visiblesql} AND ({$unapproved_where_t}) AND t.closed NOT LIKE 'moved|%' {$subject_lookin}

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

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

Zeile 1675Zeile 1745
			SELECT p.pid, p.tid
FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)

			SELECT p.pid, p.tid
FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)

			WHERE 1=1 {$post_datecut} {$thread_replycut} {$thread_prefixcut} {$forumin} {$post_usersql} {$permsql} {$tidsql} {$post_visiblesql} {$visiblesql} AND t.closed NOT LIKE 'moved|%' {$message_lookin}

			WHERE 1=1 {$post_datecut} {$thread_replycut} {$thread_prefixcut} {$forumin} {$post_usersql} {$permsql} {$tidsql} {$post_visiblesql} {$visiblesql} AND ({$unapproved_where_t}) AND {$unapproved_where_p} AND t.closed NOT LIKE 'moved|%' {$message_lookin}

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

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