1 | <?php |
---|
2 | /* |
---|
3 | * EDK Feed Syndication v1.7 |
---|
4 | * based on liq's feed syndication mod v1.5 |
---|
5 | * |
---|
6 | */ |
---|
7 | |
---|
8 | // set this to 1 if you are running a master killboard and want |
---|
9 | // to even fetch mails not related to your corp / alliance |
---|
10 | define('MASTER', 0); |
---|
11 | |
---|
12 | @set_time_limit(0); |
---|
13 | require_once('feed_fetcher.php'); |
---|
14 | require_once('common/admin/admin_menu.php'); |
---|
15 | require_once('common/includes/class.corp.php'); |
---|
16 | require_once('common/includes/class.alliance.php'); |
---|
17 | |
---|
18 | $page = new Page("Administration - Feed Syndication " . $feedversion); |
---|
19 | $page->setCachable(false); |
---|
20 | $page->setAdmin(); |
---|
21 | $validurl = "/^(http|https):\/\/([A-Za-z0-9_]{1,8}(:[A-Za-z0-9_]{1,8})?@)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}((:[0-9]{1,5})?\/.*)?$/i"; |
---|
22 | $html .= "<script language=\"JavaScript\">function checkAll(checkname, exby) {for (i = 0; i < checkname.length; i++)checkname[i].checked = exby.checked? true:false}</script>"; |
---|
23 | $html .= "<table class=kb-subtable>"; |
---|
24 | |
---|
25 | if (config::get('fetch_feed_count')) |
---|
26 | $feedcount = config::get('fetch_feed_count'); |
---|
27 | else |
---|
28 | $feedcount = 3; |
---|
29 | // saving urls and options |
---|
30 | if ($_POST['submit'] || $_POST['fetch']) |
---|
31 | { |
---|
32 | if (ctype_digit($_POST['fetch_feed_count']) && $_POST['fetch_feed_count'] > 0) |
---|
33 | { |
---|
34 | $feedcount = $_POST['fetch_feed_count']; |
---|
35 | for ($i = config::get('fetch_feed_count'); $i > $feedcount; $i--) |
---|
36 | { |
---|
37 | config::del('fetch_url_' . $i); |
---|
38 | } |
---|
39 | config::set('fetch_feed_count', $feedcount); |
---|
40 | } |
---|
41 | if ($_POST['fetch_verbose']) |
---|
42 | config::set('fetch_verbose', '1'); |
---|
43 | else |
---|
44 | config::set('fetch_verbose', '0'); |
---|
45 | |
---|
46 | if ($_POST['fetch_compress']) |
---|
47 | config::set('fetch_compress', '0'); |
---|
48 | else |
---|
49 | config::set('fetch_compress', '1'); |
---|
50 | |
---|
51 | if ($_POST['fetch_comment']) |
---|
52 | config::set('fetch_comment', $_POST['fetch_comment']); |
---|
53 | else |
---|
54 | config::set('fetch_comment', ''); |
---|
55 | |
---|
56 | for ($i = 1; $i <= $feedcount; $i++) |
---|
57 | { |
---|
58 | $url = "fetch_url_" . $i; |
---|
59 | if (preg_match($validurl , $_POST[$url])) |
---|
60 | { |
---|
61 | if ($_POST['friend'] && in_array ($i, $_POST['friend'])) |
---|
62 | $friends = "on"; |
---|
63 | else $friends = ""; |
---|
64 | if ($_POST['apikills'] && in_array ($i, $_POST['apikills'])) |
---|
65 | $apikills = "on"; |
---|
66 | else $apikills = ""; |
---|
67 | $fstr = config::get('fetch_url_' . $i); |
---|
68 | $ftmp = explode(':::', $fstr); |
---|
69 | // reset the feed lastkill details if the URL, friends or api status has changed |
---|
70 | if($_POST[$url] != $ftmp[0] || $friends != $ftmp[2] || $apikills != $ftmp[3] || |
---|
71 | ($_POST['newkills'] && !in_array ($i, $_POST['newkills'])) ) |
---|
72 | config::set($url, $_POST[$url] . ':::' . 0 . ':::' . $friends . ':::' . $apikills); |
---|
73 | } |
---|
74 | else |
---|
75 | config::set($url, ''); |
---|
76 | $feed[$i] = ''; |
---|
77 | } |
---|
78 | } |
---|
79 | $feed = array(); |
---|
80 | $feedlast = array(); |
---|
81 | for ($i = 1; $i <= $feedcount; $i++) |
---|
82 | { |
---|
83 | $str = config::get('fetch_url_' . $i); |
---|
84 | $tmp = explode(':::', $str); |
---|
85 | $feed[$i] = $tmp[0]; |
---|
86 | $feedlast[$i] = $tmp[1]; |
---|
87 | if ($tmp[2] == "on") |
---|
88 | $friend[$i] = $tmp[2]; |
---|
89 | if ($tmp[3] == "on") |
---|
90 | $apikills[$i] = $tmp[3]; |
---|
91 | } |
---|
92 | // building the request query and fetching of the feeds |
---|
93 | if ($_POST['fetch']) |
---|
94 | { |
---|
95 | if (CORP_ID && !MASTER) |
---|
96 | { |
---|
97 | $corp = new Corporation(CORP_ID); |
---|
98 | $myid = '&corp=' . urlencode($corp->getName()); |
---|
99 | } |
---|
100 | if (ALLIANCE_ID && !MASTER) |
---|
101 | { |
---|
102 | $alli = new Alliance(ALLIANCE_ID); |
---|
103 | $myid = '&alli=' . urlencode($alli->getName()); |
---|
104 | } |
---|
105 | for ($i = 1; $i <= $feedcount; $i++) |
---|
106 | { |
---|
107 | $feedfetch = new Fetcher(); |
---|
108 | $cfg = "fetch_url_" . $i; |
---|
109 | if (preg_match($validurl , $feed[$i]) && $_POST['fetch_feed'] && in_array ($i, $_POST['fetch_feed'])) |
---|
110 | { |
---|
111 | $str = ''; |
---|
112 | if ($feedlast[$i]) |
---|
113 | $str .= '&lastkllid='.$feedlast[$i]; |
---|
114 | if ($friend[$i]) |
---|
115 | $str .= '&friend=1'; |
---|
116 | if ($apikills[$i]) |
---|
117 | $str .= '&apikills=1'; |
---|
118 | if ($_POST['fetch_losses']) |
---|
119 | $str .= "&losses=1"; |
---|
120 | if (!config::get('fetch_compress')) |
---|
121 | $str .= "&gz=1"; |
---|
122 | if ($_POST['range1'] && $_POST['range2']) |
---|
123 | { |
---|
124 | if ($_POST['range1'] > $_POST['range2']) |
---|
125 | { |
---|
126 | $range1 = $_POST['range2']; |
---|
127 | $range2 = $_POST['range1']; |
---|
128 | } |
---|
129 | else |
---|
130 | { |
---|
131 | $range1 = $_POST['range1']; |
---|
132 | $range2 = $_POST['range2']; |
---|
133 | } |
---|
134 | for ($l = $range1; $l <= $range2; $l++) |
---|
135 | { |
---|
136 | $html .= "<b>Week: " . $l . "</b><br>"; |
---|
137 | $html .= $feedfetch->grab($feed[$i] . "&year=" . $_POST['year'] . "&week=" . $l, $myid . $str, $friend[$i], $cfg); |
---|
138 | } |
---|
139 | } |
---|
140 | else |
---|
141 | $html .= $feedfetch->grab($feed[$i], $myid . $str); |
---|
142 | } |
---|
143 | // If kills are fetched then change the last kill id for the feed |
---|
144 | if(intval($feedfetch->lastkllid_)) |
---|
145 | { |
---|
146 | config::set($cfg, $feed[$i] . ':::' . intval($feedfetch->lastkllid_) . ':::' . $friend[$i]); |
---|
147 | $feedlast[$i] = intval($feedfetch->lastkllid); |
---|
148 | } |
---|
149 | } |
---|
150 | } |
---|
151 | // generating the html |
---|
152 | $html .= '<form id="options" name="options" method="post" action="?a=admin_feedsyndication">'; |
---|
153 | $html .= "</table>"; |
---|
154 | |
---|
155 | $html .= "<div class=block-header2>Feeds</div><table>"; |
---|
156 | for ($i = 1; $i <= $feedcount; $i++) |
---|
157 | { |
---|
158 | $html .= "<tr><td width=85px><b>Feed url #" . $i . "</b></td><td><input type=text name=fetch_url_" . $i . " size=50 class=password value=\""; |
---|
159 | if ($feed[$i]) |
---|
160 | $html .= $feed[$i]; |
---|
161 | $html .= "\"></td>"; |
---|
162 | |
---|
163 | $html .= "<td><input type=checkbox name=friend[] id=friend value=" . $i; |
---|
164 | if ($friend[$i]) |
---|
165 | $html .= " checked=\"checked\""; |
---|
166 | $html .= "><b>Friend?</b></td>"; |
---|
167 | |
---|
168 | $html .= "<td><input type=checkbox name=newkills[] id=newkills value=" . $i; |
---|
169 | if ($feed[$i]) |
---|
170 | $html .= " checked=\"checked\""; |
---|
171 | $html .= "><b>New kills only?</b><br>"; |
---|
172 | |
---|
173 | $html .= "<td><input type=checkbox name=apikills[] id=apikills value=" . $i; |
---|
174 | if ($apikills[$i]) |
---|
175 | $html .= " checked=\"checked\""; |
---|
176 | $html .= "><b>API verified only?</b><br>"; |
---|
177 | |
---|
178 | $html .= "<td><input type=checkbox name=fetch_feed[] id=fetch value=" . $i; |
---|
179 | if ($feed[$i]) |
---|
180 | $html .= " checked=\"checked\""; |
---|
181 | $html .= "><b>Fetch?</b><br>"; |
---|
182 | |
---|
183 | $html .= "<input type=hidden name=fetch_time_" . $i . " value=\""; |
---|
184 | if($feedlast[$i]) $html .= $feedlast[$i]; |
---|
185 | $html .= "\"></td>"; |
---|
186 | $html .= "</td></tr>"; |
---|
187 | } |
---|
188 | $html .= '<tr><td colspan=2><i>Example: http://killboard.eve-d2.com/?a=feed</i></td><td>'; |
---|
189 | $html .= '<input type="checkbox" name="all" onclick="checkAll(this.form.friend,this)"><i>all/none</i></td><td>'; |
---|
190 | $html .= '<input type="checkbox" name="all" onclick="checkAll(this.form.fetch,this)"><i>all/none</i>'; |
---|
191 | $html .= "</td></tr><br></table><br><br><br>"; |
---|
192 | |
---|
193 | $html .= "<table><tr><td height=20px width=150px><b>First week:</b></td>"; |
---|
194 | $html .= '<td><select name="range1">'; |
---|
195 | $now = gmdate("W"); |
---|
196 | for ($i = 1; $i <= 52; $i++) |
---|
197 | { |
---|
198 | if ($now == $i) |
---|
199 | $html .= '<option selected="selected "value="' . $i . '">' . $i . '</option>'; |
---|
200 | else |
---|
201 | $html .= '<option value="' . $i . '">' . $i . '</option>'; |
---|
202 | } |
---|
203 | $html .= '</select>'; |
---|
204 | $html .= "<i></i></td></tr>"; |
---|
205 | $html .= "<tr><td height=20px width=150px><b>Last week:</b></td>"; |
---|
206 | $html .= '<td><select name="range2">'; |
---|
207 | for ($i = 1; $i <= 53; $i++) |
---|
208 | { |
---|
209 | if ($now == $i) |
---|
210 | $html .= '<option selected="selected "value="' . $i . '">' . $i . '</option>'; |
---|
211 | else |
---|
212 | $html .= '<option value="' . $i . '">' . $i . '</option>'; |
---|
213 | } |
---|
214 | $html .= '</select>'; |
---|
215 | $html .= "<i></i></td></tr>"; |
---|
216 | |
---|
217 | $html .= "<tr><td height=20px width=150px><b>Year:</b></td>"; |
---|
218 | $html .= '<td><select name="year">'; |
---|
219 | for($dateit = 2005; $dateit <= gmdate('Y'); $dateit++) |
---|
220 | { |
---|
221 | $html .='<option '; |
---|
222 | if($dateit == gmdate('Y')) $html .= 'selected="selected"'; |
---|
223 | $html .=' value="'.$dateit.'">'.$dateit.'</option> '; |
---|
224 | } |
---|
225 | $html .= '</select>'; |
---|
226 | $html .= "</td></tr>"; |
---|
227 | $html .= "<tr><td height=40px width=150px><b>Get kills instead of losses?</b></td>"; |
---|
228 | $html .= "<td><input type=checkbox name=fetch_losses id=fetch_losses>"; |
---|
229 | $html .= "<i> (by default only their kills, your losses, get fetched, when ticked this is inversed)</i></td></tr>"; |
---|
230 | $html .= "</table><br><br>"; |
---|
231 | $html .= "<input type=submit id=submit name=fetch value=\"Fetch!\"><br><br>"; |
---|
232 | |
---|
233 | $html .= "<div class=block-header2>Options</div><table>"; |
---|
234 | $html .= "<tr><td height=30px width=150px><b>Number of feeds:</b></td>"; |
---|
235 | $html .= "<td><input type=text name=fetch_feed_count size=2 maxlength=2 class=password value=\"" . $feedcount . "\"></td></tr>"; |
---|
236 | $html .= "<tr><td height=50px width=150px><b>Comment for automatically parsed killmails?</b></td>"; |
---|
237 | $html .= "<td><input type=text size=50 class=password name=fetch_comment id=fetch_comment value=\""; |
---|
238 | if (config::get('fetch_comment')) |
---|
239 | $html .= config::get('fetch_comment'); |
---|
240 | $html .= "\"><br><i> (leave blank for none)</i><br></td></tr>"; |
---|
241 | $html .= "<tr><td height=30px width=150px><b>Enable compression?</b></td>"; |
---|
242 | $html .= "<td><input type=checkbox name=fetch_compress id=fetch_compress"; |
---|
243 | if (!config::get('fetch_compress')) |
---|
244 | $html .= " checked=\"checked\""; |
---|
245 | $html .= "><i> (enables GZip compression for feeds that support this feature, for streams that do not support GZip compression regular html mode will be used automatically)</i></td>"; |
---|
246 | $html .= "</tr>"; |
---|
247 | $html .= "<tr><td height=30px width=150px><b>Verbose mode?</b></td>"; |
---|
248 | $html .= "<td><input type=checkbox name=fetch_verbose id=fetch_verbose"; |
---|
249 | if (config::get('fetch_verbose')) |
---|
250 | $html .= " checked=\"checked\""; |
---|
251 | $html .= "><i> (displays advanced feed request information and errormessages when the imported mail is rejected for being malformed, already exists or is not related to your corp or alliance)</i></td>"; |
---|
252 | $html .= "</tr></table><br><br>"; |
---|
253 | $html .= "<input type=submit id=submit name=submit value=\"Save\">"; |
---|
254 | $html .= "</form>"; |
---|
255 | |
---|
256 | $page->addContext($menubox->generate()); |
---|
257 | $page->setContent($html); |
---|
258 | $page->generate(); |
---|
259 | |
---|
260 | ?> |
---|