1 | <?php |
---|
2 | /* |
---|
3 | * Create a syndication feed of kills stored on this board. |
---|
4 | * |
---|
5 | * Flags |
---|
6 | * week = week |
---|
7 | * year = year |
---|
8 | * lastkllid = return all kills lastkllid on (ordered by kll_id) |
---|
9 | * range = return all kills with lastkllid <= id <= lastkllid + range |
---|
10 | * APIkills = restrict results to kills with an external id set |
---|
11 | * pilot = pilot to retrieve kills for |
---|
12 | * corp = corp_name = corp to retrieve kills for |
---|
13 | * alli = alli_name = alliance to retrieve kills for |
---|
14 | * master = retrieve all kills |
---|
15 | * friend = set pilot/corp/alli as involved killer (default is victim) |
---|
16 | * combined = return both kills and losses |
---|
17 | * |
---|
18 | */ |
---|
19 | @set_time_limit(120); |
---|
20 | require_once('kbconfig.php'); |
---|
21 | require_once('common/includes/class.corp.php'); |
---|
22 | require_once('common/includes/class.alliance.php'); |
---|
23 | require_once('common/includes/class.killlist.php'); |
---|
24 | require_once('common/includes/class.kill.php'); |
---|
25 | require_once('common/includes/class.config.php'); |
---|
26 | // include feed_fetcher to get version number |
---|
27 | require_once('common/admin/feed_fetcher.php'); |
---|
28 | |
---|
29 | $config = new Config(KB_SITE); |
---|
30 | // maximum amount of kills to return. |
---|
31 | $maxreturned = 100; |
---|
32 | $html = '<?xml version="1.0" encoding="UTF-8" ?> |
---|
33 | <rss version="2.0"> |
---|
34 | <channel> |
---|
35 | <title>'.KB_TITLE.'</title> |
---|
36 | <link>'.KB_HOST.'</link> |
---|
37 | <description>Kill Feed '.$feedversion.'</description> |
---|
38 | <copyright>'.KB_TITLE."</copyright>\n"; |
---|
39 | if($_GET['combined']) $html .= "<combined>true</combined>\n"; |
---|
40 | if($_GET['APIkills']) $html .= "<apikills>true</apikills>\n"; |
---|
41 | $klist = new KillList(); |
---|
42 | $klist->setPodsNoobShips(true); |
---|
43 | |
---|
44 | $w = intval($_GET['week']); |
---|
45 | if ($w) |
---|
46 | { |
---|
47 | $klist->setWeek($w); |
---|
48 | } |
---|
49 | elseif (!isset($_GET['lastkllid'])) |
---|
50 | { |
---|
51 | $klist->setWeek(kbdate("W")); |
---|
52 | } |
---|
53 | |
---|
54 | $y = intval($_GET['year']); |
---|
55 | if ($y) |
---|
56 | { |
---|
57 | $klist->setYear($y); |
---|
58 | } |
---|
59 | elseif (!isset($_GET['lastkllid'])) |
---|
60 | { |
---|
61 | $klist->setYear(kbdate("Y")); |
---|
62 | } |
---|
63 | |
---|
64 | $kid = intval($_GET['lastkllid']); |
---|
65 | if (isset($_GET['lastkllid'])) |
---|
66 | { |
---|
67 | $klist->setMinKllID($kid); |
---|
68 | $klist->setOrderBy(' kll.kll_id ASC'); |
---|
69 | $klist->setOrdered(true); |
---|
70 | $klist->setLimit($maxreturned); |
---|
71 | if(intval($_GET['range'])) $klist->setMaxKllID(intval($_GET['range'])+$kid); |
---|
72 | } |
---|
73 | // If asked, set feed to only retrieve kills with an external id set. |
---|
74 | if (intval($_GET['APIkills'])) $klist->setAPIKill(); |
---|
75 | if ($_GET['pilot'] || $_GET['pilot_name']) |
---|
76 | { |
---|
77 | if ($_GET['pilot']) |
---|
78 | { |
---|
79 | $p = $_GET['pilot']; |
---|
80 | } |
---|
81 | if ($_GET['pilot_name']) |
---|
82 | { |
---|
83 | $p = $_GET['pilot_name']; |
---|
84 | } |
---|
85 | $pilot = new Pilot(); |
---|
86 | $pilot->lookup(urldecode($p)); |
---|
87 | } |
---|
88 | |
---|
89 | if ($_GET['corp'] || $_GET['corp_name']) |
---|
90 | { |
---|
91 | if ($_GET['corp']) |
---|
92 | { |
---|
93 | $c = $_GET['corp']; |
---|
94 | } |
---|
95 | if ($_GET['corp_name']) |
---|
96 | { |
---|
97 | $c = $_GET['corp_name']; |
---|
98 | } |
---|
99 | $corp = new Corporation(); |
---|
100 | $corp->lookup(urldecode($c)); |
---|
101 | } |
---|
102 | |
---|
103 | if ($_GET['alli'] || $_GET['alliance_name']) |
---|
104 | { |
---|
105 | if ($_GET['alli']) |
---|
106 | { |
---|
107 | $a = $_GET['alli']; |
---|
108 | } |
---|
109 | if ($_GET['alliance_name']) |
---|
110 | { |
---|
111 | $a = $_GET['alliance_name']; |
---|
112 | } |
---|
113 | $alli = new Alliance(); |
---|
114 | $alli->add(urldecode($a)); |
---|
115 | } |
---|
116 | |
---|
117 | if ($_GET['master'] == 1 && config::get('feed_allowmaster') == 1) |
---|
118 | { |
---|
119 | $master = true; |
---|
120 | } |
---|
121 | |
---|
122 | if (!$master && $_GET['losses']) |
---|
123 | { |
---|
124 | if (PILOT_ID && !$pilot && !corp && !$alli) // local |
---|
125 | { |
---|
126 | $klist->addVictimPilot(new Pilot(PILOT_ID)); |
---|
127 | } |
---|
128 | if (CORP_ID && !pilot && !$corp && !$alli) // local |
---|
129 | { |
---|
130 | $klist->addVictimCorp(new Corporation(CORP_ID)); |
---|
131 | } |
---|
132 | if (ALLIANCE_ID && !pilot && !$corp && !$alli) // local |
---|
133 | { |
---|
134 | $klist->addVictimAlliance(new Alliance(ALLIANCE_ID)); |
---|
135 | } |
---|
136 | if ($pilot && $_GET['friend']) // remote friend |
---|
137 | { |
---|
138 | $klist->addVictimPilot($pilot); |
---|
139 | } |
---|
140 | if ($corp && $_GET['friend']) // remote friend |
---|
141 | { |
---|
142 | $klist->addVictimCorp($corp); |
---|
143 | } |
---|
144 | if ($alli && $_GET['friend']) // remote friend |
---|
145 | { |
---|
146 | $klist->addVictimAlliance($alli); |
---|
147 | } |
---|
148 | if ($pilot && !$_GET['friend']) // remote |
---|
149 | { |
---|
150 | $klist->addInvolvedPilot($pilot); |
---|
151 | } |
---|
152 | if ($corp && !$_GET['friend']) // remote |
---|
153 | { |
---|
154 | $klist->addInvolvedCorp($corp); |
---|
155 | } |
---|
156 | if ($alli && !$_GET['friend']) // remote |
---|
157 | { |
---|
158 | $klist->addInvolvedAlliance($alli); |
---|
159 | } |
---|
160 | } |
---|
161 | else if(!$master && $_GET['combined']) |
---|
162 | { |
---|
163 | if($pilot) $klist->addCombinedPilot($pilot); |
---|
164 | if($corp) $klist->addCombinedCorp($corp); |
---|
165 | if($alli) $klist->addCombinedAlliance($alli); |
---|
166 | } |
---|
167 | else if (!$master) |
---|
168 | { |
---|
169 | if (PILOT_ID && !$pilot && !corp && !$alli) // local |
---|
170 | { |
---|
171 | $klist->addInvolvedPilot(new Pilot(PILOT_ID)); |
---|
172 | } |
---|
173 | if (CORP_ID && !$pilot && !$corp && !$alli) // local |
---|
174 | { |
---|
175 | $klist->addInvolvedCorp(new Corporation(CORP_ID)); |
---|
176 | } |
---|
177 | if (ALLIANCE_ID && !$pilot && !$corp && !$alli) // local |
---|
178 | { |
---|
179 | $klist->addInvolvedAlliance(new Alliance(ALLIANCE_ID)); |
---|
180 | } |
---|
181 | if ($pilot && $_GET['friend']) // remote friend |
---|
182 | { |
---|
183 | $klist->addInvolvedPilot($pilot); |
---|
184 | } |
---|
185 | if ($corp && $_GET['friend']) // remote friend |
---|
186 | { |
---|
187 | $klist->addInvolvedCorp($corp); |
---|
188 | } |
---|
189 | if ($alli && $_GET['friend']) // remote friend |
---|
190 | { |
---|
191 | $klist->addInvolvedAlliance($alli); |
---|
192 | } |
---|
193 | if ($pilot && !$_GET['friend']) // remote |
---|
194 | { |
---|
195 | $klist->addVictimPilot($pilot); |
---|
196 | } |
---|
197 | if ($corp && !$_GET['friend']) // remote |
---|
198 | { |
---|
199 | $klist->addVictimCorp($corp); |
---|
200 | } |
---|
201 | if ($alli && !$_GET['friend']) // remote |
---|
202 | { |
---|
203 | $klist->addVictimAlliance($alli); |
---|
204 | } |
---|
205 | } |
---|
206 | |
---|
207 | $kills = array(); |
---|
208 | $finalkill = 0; |
---|
209 | while ($kill = $klist->getKill()) |
---|
210 | { |
---|
211 | if ($kill->isClassified()) |
---|
212 | { |
---|
213 | continue; |
---|
214 | } |
---|
215 | if($finalkill < $kill->getID())$finalkill = $kill->getID(); |
---|
216 | $kills[$kill->getID()] = $kill->getTimestamp(); |
---|
217 | } |
---|
218 | if (!$kid) |
---|
219 | { |
---|
220 | asort($kills); |
---|
221 | } |
---|
222 | $qry = new DBQuery(); |
---|
223 | // If kills returned = $maxreturned assume that it was limited and set |
---|
224 | // last kill as the lower of highest kill id returned or highest non-classified |
---|
225 | // kill |
---|
226 | if($klist->getCount() != $maxreturned) |
---|
227 | { |
---|
228 | $qry = new DBQuery(); |
---|
229 | if(config::get('kill_classified')) |
---|
230 | { |
---|
231 | $qry->execute('SELECT max(kll_id) as finalkill FROM kb3_kills WHERE kll_timestamp < "'.(date('Y-m-d H:i:s',time()-config::get('kill_classified')*60*60)).'"'); |
---|
232 | } |
---|
233 | else $qry->execute('SELECT max(kll_id) as finalkill FROM kb3_kills'); |
---|
234 | $row=$qry->getRow(); |
---|
235 | $finalkill = intval($row['finalkill']); |
---|
236 | } |
---|
237 | elseif(config::get('kill_classified')) |
---|
238 | { |
---|
239 | // Check if there are classified kills with lower kill ids still to come. |
---|
240 | $qry->execute('SELECT max(kll_id) as finalkill FROM kb3_kills WHERE kll_timestamp < "'.(date('Y-m-d H:i:s',time()-config::get('kill_classified')*60*60)).'"'); |
---|
241 | $row=$qry->getRow(); |
---|
242 | if($finalkill > intval($row['finalkill'])) $finalkill = intval($row['finalkill']); |
---|
243 | } |
---|
244 | |
---|
245 | $html .= '<finalkill>'.$finalkill."</finalkill>\n"; |
---|
246 | foreach ($kills as $id => $timestamp) |
---|
247 | { |
---|
248 | $kill = new Kill($id); |
---|
249 | $html .= '<item> |
---|
250 | <title>'.$id.'</title> |
---|
251 | <description><![CDATA[ '.$kill->getRawMail().' ]]></description> |
---|
252 | <guid>?a=kill_detail&kll_id='.$id.'</guid> |
---|
253 | <pubDate>'.strftime("%a, %d %b %Y %T %Z", strtotime($timestamp))."</pubDate>\n"; |
---|
254 | if($kill->getExternalID()) $html .= "<apiID>".$kill->getExternalID()."</apiID>\n"; |
---|
255 | $html .= "</item>\n"; |
---|
256 | } |
---|
257 | $html .= '</channel></rss>'; |
---|
258 | |
---|
259 | if ($_GET['gz']) |
---|
260 | { |
---|
261 | echo gzdeflate($html,6); |
---|
262 | } |
---|
263 | else |
---|
264 | { |
---|
265 | echo $html; |
---|
266 | } |
---|
267 | ?> |
---|