http://www.nulled.ws/showpost.php?p=1206543&postcount=12
в СЕ есть один баг в поиске если есть выпадающее меню и их много то мускуль загибается!!
Code:
/////////////////////////////////////////////////////
// THIS FUNCTION SEARCHES THROUGH PROFILE INFORMATION
// INPUT:
// OUTPUT:
function search_profile()
{
global $database, $url, $results_per_page, $p, $search_text, $t, $search_objects, $results, $total_results;
$q = "SELECT
profilefield_id AS field_id,
profilefield_type AS field_type,
profilefield_options AS field_options
FROM
se_profilefields
WHERE
profilefield_type<>'5' &&
(profilefield_dependency<>'0' OR (profilefield_dependency='0' AND profilefield_display<>'0'))";
// GET FIELDS
$fields = $database->database_query($q);
$sql = "SELECT * FROM `se_languagevars` WHERE `languagevar_id` >= 500001 AND `languagevar_id` <= 600000 AND languagevar_value LIKE '%{$search_text}%'";
$profile_query = "se_users.user_username LIKE '%{$search_text}%' OR CONCAT(se_users.user_fname, ' ', se_users.user_lname) LIKE '%{$search_text}%'";
$res = $database->database_query($sql);
while($sel = $database->database_fetch_assoc($res)){
$langid[] = $sel[languagevar_id];
}
// LOOP OVER FIELDS
while($field_info = $database->database_fetch_assoc($fields))
{
// TEXT FIELD OR TEXTAREA
if( $field_info['field_type'] == 1 || $field_info['field_type'] == 2 )
{
if( $profile_query ) $profile_query .= " OR ";
$profile_query .= "`se_profilevalues`.`profilevalue_{$field_info['field_id']}` LIKE '%{$search_text}%'";
}
// RADIO OR SELECT BOX
elseif($field_info[field_type] == 3 || $field_info[field_type] == 4)
{
$options = unserialize($field_info['field_options']);
$langids = Array();
$cases = Array();
foreach($options as $k=>$v){
if (in_array("$v[label]", $langid)) {
$k++;
$cases[] = "WHEN languagevar_id='{$v[label]}' THEN {$k}";
$langids[] = $v[label];
}
}
if(count($cases) != 0)
{
if( $profile_query ) $profile_query .= " OR ";
$profile_query .= "`se_profilevalues`.`profilevalue_{$field_info['field_id']}` IN (SELECT CASE ".implode(" ", $cases)." END AS value FROM se_languagevars WHERE languagevar_id IN (".implode(", ", $langids).") AND languagevar_value LIKE '%{$search_text}%')";
}
}
// CHECKBOX
elseif($field_info[field_type] == 6)
{
$options = unserialize($field_info['field_options']);
$langids = Array();
$cases = Array();
for($i=0,$max=count($options);$i<$max;$i++)
{
$cases[] = "WHEN languagevar_id='{$options[$i]['label']}' THEN ".(pow(2, $i));
$langids[] = $options[$i][label];
}
if(count($cases) != 0)
{
// if( $profile_query ) $profile_query .= " OR ";
// $profile_query .= "`se_profilevalues`.`profilevalue_{$field_info['field_id']}` & (SELECT sum(CASE ".implode(" ", $cases)." END) AS value FROM se_languagevars WHERE languagevar_id IN (".implode(", ", $langids).") AND languagevar_value LIKE '%{$search_text}%')";
}
}
}
// CONSTRUCT QUERY
$profile_query = "
SELECT
se_users.user_id,
se_users.user_username,
se_users.user_fname,
se_users.user_lname,
se_users.user_photo
FROM
se_profilevalues
LEFT JOIN
se_users
ON se_profilevalues.profilevalue_user_id=se_users.user_id
LEFT JOIN
se_levels
ON se_levels.level_id=se_users.user_level_id
WHERE
se_users.user_verified='1' AND
se_users.user_enabled='1' AND
(se_users.user_search='1' OR se_levels.level_profile_search='0') AND
($profile_query)
";
// GET TOTAL PROFILES
$total_profiles = $database->database_num_rows($database->database_query($profile_query." LIMIT 201"));
// IF NOT TOTAL ONLY
if($t == "0")
{
// MAKE PROFILE PAGES
$start = ($p - 1) * $results_per_page;
$limit = $results_per_page+1;
// SEARCH PROFILES
$online_users_array = online_users();
$profiles = $database->database_query($profile_query." ORDER BY se_users.user_id DESC LIMIT $start, $limit");
while($profile_info = $database->database_fetch_assoc($profiles))
{
// CREATE AN OBJECT FOR USER
$profile = new se_user();
$profile->user_info['user_id'] = $profile_info['user_id'];
$profile->user_info['user_username'] = $profile_info['user_username'];
$profile->user_info['user_fname'] = $profile_info['user_fname'];
$profile->user_info['user_lname'] = $profile_info['user_lname'];
$profile->user_info['user_photo'] = $profile_info['user_photo'];
$profile->user_displayname();
// DETERMINE IF USER IS ONLINE
$is_online = (bool) in_array($profile_info['user_username'], $online_users_array[0]);
$results[] = Array(
'result_url' => $url->url_create('profile', $profile_info['user_username']),
'result_icon' => $profile->user_photo('./images/nophoto.gif', TRUE),
'result_name' => 509,
'result_name_1' => $profile->user_displayname,
'result_desc' => '',
'result_online' => $is_online
);
}
// SET TOTAL RESULTS
$total_results = $total_profiles;
}
// SET ARRAY VALUES
SE_Language::_preload_multi(509, 1072);
if($total_profiles > 200) { $total_profiles = "200+"; }
$search_objects[] = Array(
'search_type' => '0',
'search_lang' => 1072,
'search_total' => $total_profiles
);
}
// END search_profile() FUNCTION
////////////////////////////////////////////////////////////////////