$house = intval($_GET['house'], 10); $search = mb_strtolower(substr(trim($_GET['search'], " \t\n\r[]"), 0, 50)); if ($search == '') { json_return(array()); } BotCheck(); HouseETag($house); $locale = GetLocale(); $searchCacheKey = 'search_b2_' . $locale . '_' . md5($search); if ($json = MCGetHouse($house, $searchCacheKey)) { PopulateLocaleCols($json['battlepets'], [['func' => 'GetPetNames', 'key' => 'id', 'name' => 'name']]); PopulateLocaleCols($json['items'], [['func' => 'GetItemNames', 'key' => 'id', 'name' => 'name'], ['func' => 'GetItemBonusTagsByTag', 'key' => 'tagurl', 'name' => 'bonustag']]); json_return($json); } DBConnect(); $json = array('items' => SearchItems($house, $search, $locale), 'sellers' => SearchSellers($house, $search), 'battlepets' => SearchBattlePets($house, $search, $locale)); $ak = array_keys($json); foreach ($ak as $k) { if (count($json[$k]) == 0) { unset($json[$k]); } } MCSetHouse($house, $searchCacheKey, $json); PopulateLocaleCols($json['battlepets'], [['func' => 'GetPetNames', 'key' => 'id', 'name' => 'name']]); PopulateLocaleCols($json['items'], [['func' => 'GetItemNames', 'key' => 'id', 'name' => 'name'], ['func' => 'GetItemBonusTagsByTag', 'key' => 'tagurl', 'name' => 'bonustag']]); json_return($json); function SearchItems($house, $search, $locale) { global $db; $suffixes = MCGet('search_itemsuffixes_' . $locale); if ($suffixes === false) {
$fields = $_POST["field"]; } else { $projectList = $_POST["project"]; } $search_text = $_POST["search_text"]; $limit_author = $_POST["limit_author"]; $undocumented_only = array_key_exists("undocumented_only", $_POST) && $_POST["undocumented_only"] == 1; $startTimeStr = microtime(); $search_type = ""; if (array_key_exists("search_type", $_POST)) { $search_type = $_POST["search_type"]; } if (!isset($fields)) { $fields = ""; } $items = SearchItems($projectList, $search_text, $fields, $search_type, $limit_author, $undocumented_only, $_POST["results_limit"]); $endTimeStr = microtime(); $duration = MicrotimeDifference($startTimeStr, $endTimeStr); $tpl->SetVariable("SEARCH_DURATION", round($duration, 4)); if (!is_array($items)) { if (is_string($items)) { $tpl->SetVariable("RESULT_MESSAGE", $items); } else { $tpl->SetVariable("RESULT_MESSAGE", "No Items were found matching '" . $search_text . "'"); } $tpl->setCurrentBlock("item_list"); $tpl->parseCurrentBlock("item_list"); } else { $tpl->setCurrentBlock("item_list"); $result_message = count($items) . " items were found matching '" . $search_text . "' "; if ($limit_author != "") {