-
Notifications
You must be signed in to change notification settings - Fork 184
/
character-achievements.php
253 lines (251 loc) · 10.6 KB
/
character-achievements.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<?php
/**
* @package World of Warcraft Armory
* @version Release Candidate 1
* @revision 208
* @copyright (c) 2009-2010 Shadez
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
**/
define('__ARMORY__', true);
define('load_characters_class', true);
define('load_achievements_class', true);
if(isset($_GET['c'])) {
define('load_mangos_class', true);
}
if(!@include('includes/armory_loader.php')) {
die('<b>Fatal error:</b> unable to load system files.');
}
header('Content-type: text/xml');
// Load XSLT template
if(isset($_GET['c'])) {
$xml->LoadXSLT('character/achievements-async.xsl');
$achievement_category = (int) $_GET['c'];
}
else {
$xml->LoadXSLT('character/achievements.xsl');
$achievement_category = 0;
}
if(isset($_GET['n'])) {
$name = $_GET['n'];
}
elseif(isset($_GET['cn'])) {
$name = $_GET['cn'];
}
else {
$name = false;
}
$characters->BuildCharacter($name);
$isCharacter = $characters->CheckPlayer();
$achievements->guid = $characters->GetGUID();
if(!isset($_GET['r']) || !$armory->currentRealmInfo) {
$isCharacter = false;
}
// Get page cache
if($characters->GetGUID() > 0 && $isCharacter && $armory->armoryconfig['useCache'] == true && !isset($_GET['skipCache'])) {
if($achievement_category > 0) {
$cache_id = $utils->GenerateCacheId('character-achievements-c'.$achievement_category, $characters->GetName(), $armory->currentRealmInfo['name']);
}
else {
$cache_id = $utils->GenerateCacheId('character-achievements', $characters->GetName(), $armory->currentRealmInfo['name']);
}
if($cache_data = $utils->GetCache($cache_id)) {
echo $cache_data;
echo sprintf('<!-- Restored from cache; id: %s -->', $cache_id);
exit;
}
}
if($achievement_category > 0) {
$xml->XMLWriter()->startElement('achievements');
$xml->XMLWriter()->writeAttribute('lang', $armory->_locale);
$xml->XMLWriter()->writeAttribute('requestUrl', 'character-achievements.xml');
$xml->XMLWriter()->startElement('category');
$achievements_page = $achievements->LoadAchievementPage($achievement_category, ($characters->GetFaction() == 1) ? 0 : 1);
$i = 0;
if(isset($achievements_page['completed'])) {
foreach($achievements_page['completed'] as $achievement) {
if($achievement['display'] == 0) {
continue;
}
$xml->XMLWriter()->startElement('achievement');
if(isset($achievement['data'])) {
foreach($achievement['data'] as $a_data_key => $a_data_value) {
$xml->XMLWriter()->writeAttribute($a_data_key, $a_data_value);
}
}
if(isset($achievement['criteria']) && is_array($achievement['criteria'])) {
foreach($achievement['criteria'] as $criteria) {
$xml->XMLWriter()->startElement('criteria');
foreach($criteria as $c_key => $c_value) {
$xml->XMLWriter()->writeAttribute($c_key, $c_value);
}
$xml->XMLWriter()->endElement(); //criteria
}
}
if(isset($achievement['achievement_tree'])) {
foreach($achievement['achievement_tree'] as $achievement_tree) {
$xml->XMLWriter()->startElement('achievement');
foreach($achievement_tree as $a_tree_key => $a_tree_value) {
$xml->XMLWriter()->writeAttribute($a_tree_key, $a_tree_value);
}
$xml->XMLWriter()->endElement(); //achievement
}
}
$xml->XMLWriter()->endElement(); //achievement
}
}
if(isset($achievements_page['incompleted'])) {
foreach($achievements_page['incompleted'] as $achievement) {
if(isset($achievement['display']) && $achievement['display'] == 0) {
continue;
}
$xml->XMLWriter()->startElement('achievement');
if(isset($achievement['data'])) {
foreach($achievement['data'] as $a_data_key => $a_data_value) {
$xml->XMLWriter()->writeAttribute($a_data_key, $a_data_value);
}
}
if(isset($achievement['criteria']) && is_array($achievement['criteria'])) {
foreach($achievement['criteria'] as $criteria) {
$xml->XMLWriter()->startElement('criteria');
foreach($criteria as $c_key => $c_value) {
$xml->XMLWriter()->writeAttribute($c_key, $c_value);
}
$xml->XMLWriter()->endElement(); //criteria
}
}
if(isset($achievement['achievement_tree'])) {
foreach($achievement['achievement_tree'] as $achievement_tree) {
$xml->XMLWriter()->startElement('achievement');
foreach($achievement_tree as $a_tree_key => $a_tree_value) {
$xml->XMLWriter()->writeAttribute($a_tree_key, $a_tree_value);
}
$xml->XMLWriter()->endElement(); //achievement
}
}
$xml->XMLWriter()->endElement(); //achievement
}
}
$xml->XMLWriter()->endElement(); //category
$xml->XMLWriter()->endElement(); //achievements
$xml_cache_data = $xml->StopXML();
echo $xml_cache_data;
if($armory->armoryconfig['useCache'] == true && !isset($_GET['skipCache'])) {
// Write cache to file
$cache_data = $utils->GenerateCacheData($characters->GetName(), $characters->GetGUID(), 'character-achievements');
$cache_handler = $utils->WriteCache($cache_id, $cache_data, $xml_cache_data);
}
exit;
}
/** Basic info **/
$tabUrl = $characters->GetUrlString();
/** Header **/
$xml->XMLWriter()->startElement('page');
$xml->XMLWriter()->writeAttribute('globalSearch', 1);
$xml->XMLWriter()->writeAttribute('lang', $armory->_locale);
$xml->XMLWriter()->writeAttribute('requestUrl', 'character-achievements.xml');
$xml->XMLWriter()->startElement('tabInfo');
$xml->XMLWriter()->writeAttribute('subTab', 'achievements');
$xml->XMLWriter()->writeAttribute('tab', 'character');
$xml->XMLWriter()->writeAttribute('tabGroup', 'character');
$xml->XMLWriter()->writeAttribute('tabUrl', $tabUrl);
$xml->XMLWriter()->endElement(); //tabInfo
if(!$isCharacter) {
$xml->XMLWriter()->startElement('characterInfo');
$xml->XMLWriter()->writeAttribute('errCode', 'noCharacter');
$xml->XMLWriter()->endElement(); // characterInfo
$xml->XMLWriter()->endElement(); //page
$xml_cache_data = $xml->StopXML();
echo $xml_cache_data;
exit;
}
$character_title = $characters->GetChosenTitleInfo();
$character_element = $characters->GetHeader($achievements);
$xml->XMLWriter()->startElement('characterInfo');
$xml->XMLWriter()->startElement('character');
foreach($character_element as $c_elem_name => $c_elem_value) {
$xml->XMLWriter()->writeAttribute($c_elem_name, $c_elem_value);
}
$xml->XMLWriter()->endElement(); //character
$xml->XMLWriter()->endElement(); //characterInfo
$xml->XMLWriter()->startElement('achievements');
$xml->XMLWriter()->startElement('summary');
$xml->XMLWriter()->startElement('c');
$info_summary = $achievements->GetSummaryAchievementData(0);
if(is_array($info_summary)) {
foreach($info_summary as $info_key => $info_value) {
$xml->XMLWriter()->writeAttribute($info_key, $info_value);
}
}
$xml->XMLWriter()->endElement(); //c
$info_categories = array(92, 96, 97, 95, 168, 169, 201, 155, 81);
foreach($info_categories as $achievement_category) {
$xml->XMLWriter()->startElement('category');
$current_category = $achievements->GetSummaryAchievementData($achievement_category);
if($current_category) {
$xml->XMLWriter()->startElement('c');
foreach($current_category as $category_key => $category_value) {
$xml->XMLWriter()->writeAttribute($category_key, $category_value);
}
$xml->XMLWriter()->endElement(); //c
}
$xml->XMLWriter()->endElement(); //category
}
// Last 5 achievements
$last_achievements = $achievements->GetLastAchievements();
if(is_array($last_achievements)) {
foreach($last_achievements as $l_achievement) {
if(is_array($l_achievement)) {
$xml->XMLWriter()->startElement('achievement');
foreach($l_achievement as $l_a_key => $l_a_value) {
$xml->XMLWriter()->writeAttribute($l_a_key, $l_a_value);
}
$xml->XMLWriter()->endElement(); //achievement
}
}
}
$xml->XMLWriter()->endElement(); //summary
// root
$xml->XMLWriter()->startElement('rootCategories');
$root_categories = $achievements->BuildCategoriesTree();
if($root_categories && is_array($root_categories)) {
foreach($root_categories as $category) {
$xml->XMLWriter()->startElement('category');
$xml->XMLWriter()->writeAttribute('id', $category['id']);
$xml->XMLWriter()->writeAttribute('name', $category['name']);
if(isset($category['child']) && is_array($category['child'])) {
foreach($category['child'] as $category_child) {
$xml->XMLWriter()->startElement('category');
$xml->XMLWriter()->writeAttribute('name', $category_child['name']);
$xml->XMLWriter()->writeAttribute('id', $category_child['id']);
$xml->XMLWriter()->endElement(); //category
}
}
$xml->XMLWriter()->endElement(); //category
}
}
$xml->XMLWriter()->endElement(); //rootCategories
$xml->XMLWriter()->endElement(); //achievements
$xml->XMLWriter()->endElement(); //page
$xml_cache_data = $xml->StopXML();
echo $xml_cache_data;
if($armory->armoryconfig['useCache'] == true && !isset($_GET['skipCache'])) {
// Write cache to file
$cache_data = $utils->GenerateCacheData($characters->GetName(), $characters->GetGUID(), 'character-achievements');
$cache_handler = $utils->WriteCache($cache_id, $cache_data, $xml_cache_data);
}
exit;
?>