source: aowow/opensearch.php

Last change on this file was 170, checked in by maron, 16 years ago
  • Property svn:executable set to *
File size: 2.5 KB
Line 
1<?php
2
3// Настройки
4error_reporting(2039);
5require_once 'configs/config.php';
6// Для Ajax отключаем debug
7$AoWoWconf['debug'] = false;
8// Для Ajax ненужен реалм
9$AoWoWconf['realmd'] = false;
10// Настройка БД
11global $DB;
12require_once('includes/db.php');
13
14echo '["'.$_GET['search'].'", [';
15
16function SideByRace($race)
17{
18 switch ($race)
19 {
20 case '0':
21 // Для всех?
22 return 3;
23 case '690':
24 // Орда?
25 return 2;
26 case '1101':
27 // Альянс?
28 return 1;
29 default:
30 return 0;
31 }
32}
33
34// Ищем вещи:
35$rows = $DB->select('
36 SELECT entry, name, iconname, quality
37 FROM item_template i, ?_icons a
38 WHERE
39 ((i.name LIKE ?)
40 AND a.id=i.displayid)
41 ORDER BY i.quality DESC, i.name
42 LIMIT 3
43 ',
44 '%'.$_GET['search'].'%');
45
46foreach ($rows as $i => $row)
47 $found[$row['name'].' (Item)'] = array(
48 'type' => 3,
49 'entry' => $row['entry'],
50 'iconname' => $row['iconname'],
51 'quality' => $row['quality']
52 );
53
54// Ищем объекты:
55$rows = $DB->select('
56 SELECT entry, name
57 FROM gameobject_template
58 WHERE
59 (name LIKE ?)
60 ORDER BY name
61 LIMIT 3
62 ',
63 '%'.$_GET['search'].'%'
64);
65
66foreach ($rows as $i => $row)
67 $found[$row['name'].' (Object)'] = array(
68 'type' => 2,
69 'entry'=>$row['entry'],
70 );
71
72// Ищем квесты:
73$rows = $DB->select('
74 SELECT entry, Title, RequiredRaces
75 FROM quest_template
76 WHERE
77 (Title LIKE ?)
78 ORDER BY Title
79 LIMIT 3
80 ',
81 '%'.$_GET['search'].'%'
82);
83
84foreach ($rows as $i => $row)
85 $found[$row['Title'].' (Quest)'] = array(
86 'type' => 5,
87 'entry'=> $row['entry'],
88 'side' => SideByRace($row['RequiredRaces'])
89 );
90
91// Ищем creature:
92$rows = $DB->select('
93 SELECT entry, name
94 FROM creature_template
95 WHERE
96 (name LIKE ?)
97 ORDER BY name
98 LIMIT 3
99 ',
100 '%'.$_GET['search'].'%'
101);
102
103foreach ($rows as $i => $row)
104 $found[$row['name'].' (NPC)'] = array(
105 'type' => 1,
106 'entry'=> $row['entry']
107 );
108
109// Если ничего не найдено...
110if (!IsSet($found))
111{
112 echo ']]';
113 die();
114}
115
116ksort($found);
117
118$found = array_slice($found, 0, 10);
119
120$i=0;
121foreach ($found as $name => $fitem)
122{
123 echo '"'.str_replace('"','\"',$name).'"';
124 if ($i<count($found)-1)
125 echo ', ';
126 $i++;
127}
128
129echo '], [], [], [], [], [], [';
130
131$i=0;
132foreach ($found as $name => $fitem)
133{
134 echo '['.$fitem['type'].', '.$fitem['entry'];
135 if (IsSet($fitem['iconname'])) echo ', "'.$fitem['iconname'].'"';
136 if (IsSet($fitem['quality'])) echo ", ".$fitem['quality'];
137 if (IsSet($fitem['side'])) echo ", ".$fitem['side'];
138 echo ']';
139 if ($i<count($found)-1)
140 echo ',';
141 $i++;
142}
143
144echo ']]';
145
146?>
Note: See TracBrowser for help on using the repository browser.