-
Notifications
You must be signed in to change notification settings - Fork 23
/
opensearch.php
166 lines (142 loc) · 3.57 KB
/
opensearch.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
/*
* UDWBase: WOWDB Web Interface
*
* © UDW 2009-2011
*
* Released under the terms and conditions of the
* GNU General Public License (http://gnu.org).
*
*/
// Настройки
error_reporting(E_ALL | E_STRICT);
session_start();
if (!isset($_SESSION['locale']) || !is_int($_SESSION['locale']))
$_SESSION['locale'] = 0;
require_once 'configs/config.php';
// Для Ajax отключаем debug
$UDWBaseconf['debug'] = false;
// Для Ajax ненужен реалм
$UDWBaseconf['realmd'] = false;
// Настройка БД
global $DB;
require_once('includes/db.php');
$search_query = $_GET['search'];
if (strlen($search_query) < 2)
exit('["", []]');
$search_query = '%' . str_replace('%', '\%', $search_query) . '%';
echo '["' . str_replace('"', '\"', $_GET['search']) . '", [';
function SideByRace($race) {
switch ($race) {
case '0':
// Для всех?
return 3;
case '690':
// Орда?
return 2;
case '1101':
// Альянс?
return 1;
default:
return 0;
}
}
// Ищем вещи:
$rows = $DB->select('
SELECT i.entry, ?#, iconname, quality
FROM ?_aowow_icons a, ?_item_template i{, ?# l}
WHERE
?# LIKE ?
AND a.id = i.displayid
{ AND l.entry = i.entry AND ?}
ORDER BY i.quality DESC, i.name
LIMIT 3',
$_SESSION['locale'] == 0 ? 'name' : 'name_loc' . $_SESSION['locale'], // SELECT
$_SESSION['locale'] == 0 ? DBSIMPLE_SKIP : 'locales_item', // FROM
$_SESSION['locale'] == 0 ? 'name' : 'name_loc' . $_SESSION['locale'], // WHERE
$search_query,
$_SESSION['locale'] == 0 ? DBSIMPLE_SKIP : 1
);
foreach ($rows as $i => $row)
$found[$row['name'] . ' (Item)'] = array(
'type' => 3,
'entry' => $row['entry'],
'iconname' => $row['iconname'],
'quality' => $row['quality']
);
// Ищем объекты:
$rows = $DB->select('
SELECT entry, name
FROM ?_gameobject_template
WHERE
(name LIKE ?)
ORDER BY name
LIMIT 3
', $search_query
);
foreach ($rows as $i => $row)
$found[$row['name'] . ' (Object)'] = array(
'type' => 2,
'entry' => $row['entry'],
);
// Ищем квесты:
$rows = $DB->select('
SELECT entry, Title, RequiredRaces
FROM ?_quest_template
WHERE
(Title LIKE ?)
ORDER BY Title
LIMIT 3
', $search_query
);
foreach ($rows as $i => $row)
$found[$row['Title'] . ' (Quest)'] = array(
'type' => 5,
'entry' => $row['entry'],
'side' => SideByRace($row['RequiredRaces'])
);
// Ищем creature:
$rows = $DB->select('
SELECT entry, name
FROM ?_creature_template
WHERE
(name LIKE ?)
ORDER BY name
LIMIT 3
', $search_query
);
foreach ($rows as $i => $row)
$found[$row['name'] . ' (NPC)'] = array(
'type' => 1,
'entry' => $row['entry']
);
// Если ничего не найдено...
if (!IsSet($found)) {
echo ']]';
die();
}
ksort($found);
$found = array_slice($found, 0, 10);
$i = 0;
foreach ($found as $name => $fitem) {
echo '"' . str_replace('"', '\"', $name) . '"';
if ($i < count($found) - 1)
echo ', ';
$i++;
}
echo '], [], [], [], [], [], [';
$i = 0;
foreach ($found as $name => $fitem) {
echo '[' . $fitem['type'] . ', ' . $fitem['entry'];
if (IsSet($fitem['iconname']))
echo ', "' . $fitem['iconname'] . '"';
if (IsSet($fitem['quality']))
echo ", " . $fitem['quality'];
if (IsSet($fitem['side']))
echo ", " . $fitem['side'];
echo ']';
if ($i < count($found) - 1)
echo ',';
$i++;
}
echo ']]';