1 | <?php |
---|
2 | ////// |
---|
3 | ////// ////// |
---|
4 | ////// liq's feed syndication mod v1.5 |
---|
5 | //////////// |
---|
6 | //////////// |
---|
7 | //////////// |
---|
8 | //////////// |
---|
9 | |
---|
10 | |
---|
11 | // set this to 1 if you are running a master killboard and want |
---|
12 | // to even fetch mails not related to your corp / alliance |
---|
13 | define( MASTER, 0 ); |
---|
14 | |
---|
15 | $version = "v1.5"; |
---|
16 | @set_time_limit(0); |
---|
17 | require_once( 'feed_fetcher.php' ); |
---|
18 | require_once( 'common/admin/admin_menu.php' ); |
---|
19 | require_once( 'common/includes/class.corp.php' ); |
---|
20 | require_once( 'common/includes/class.alliance.php' ); |
---|
21 | |
---|
22 | |
---|
23 | $page = new Page( "Administration - Feed Syndication " . $version ); |
---|
24 | $page->setCachable(false); |
---|
25 | $page->setAdmin(); |
---|
26 | |
---|
27 | $validurl = "/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}((:[0-9]{1,5})?\/.*)?$/i"; |
---|
28 | $html .= "<script language=\"JavaScript\">function checkAll(checkname, exby) {for (i = 0; i < checkname.length; i++)checkname[i].checked = exby.checked? true:false}</script>"; |
---|
29 | $html .= "<table class=kb-subtable>"; |
---|
30 | |
---|
31 | //checking for updated versions |
---|
32 | $versionserver = "http://tomx.org/feed/version.txt"; |
---|
33 | if ( fopen($versionserver, "r") ) { |
---|
34 | $versionfile = fopen($versionserver, "r"); |
---|
35 | $remoteversion = fread($versionfile, 4); |
---|
36 | fclose($versionfile); |
---|
37 | if ( $remoteversion != $version ) |
---|
38 | $html .= '<div class="kl-loss"><b>Your version ('.$version.') is outdated! </b></div><br>There is a newer version ('.$remoteversion.') available <a href="http://tomx.org/feed/mod_feed_'.$remoteversion.'.zip"><b>here</b></a>. <br>Please update!<br><br>'; |
---|
39 | } else |
---|
40 | $html .= '<div class="kl-loss">Cant retrieve version information from: '.$versionserver.'</div><br><br>'; |
---|
41 | |
---|
42 | if (getConfig('fetch_feed_count')) |
---|
43 | $feedcount = getConfig('fetch_feed_count'); |
---|
44 | else |
---|
45 | $feedcount = 3; |
---|
46 | |
---|
47 | //saving urls and options |
---|
48 | if ( $_POST['submit'] || $_POST['fetch'] ) { |
---|
49 | if ( ctype_digit($_POST['fetch_feed_count']) && $_POST['fetch_feed_count'] > 0) { |
---|
50 | $feedcount = $_POST['fetch_feed_count']; |
---|
51 | setConfig('fetch_feed_count', $feedcount); |
---|
52 | for ($i = 99; $i>=$feedcount; $i--) { |
---|
53 | delConfig('fetch_url_'.$i); |
---|
54 | } |
---|
55 | } |
---|
56 | if ( $_POST['fetch_verbose'] ) |
---|
57 | setConfig('fetch_verbose', '1'); |
---|
58 | else |
---|
59 | setConfig('fetch_verbose', '0'); |
---|
60 | |
---|
61 | if ( $_POST['fetch_compress'] ) |
---|
62 | setConfig('fetch_compress', '0'); |
---|
63 | else |
---|
64 | setConfig('fetch_compress', '1'); |
---|
65 | |
---|
66 | if ( $_POST['fetch_comment'] ) |
---|
67 | setConfig('fetch_comment', $_POST['fetch_comment']); |
---|
68 | else |
---|
69 | setConfig('fetch_comment', ''); |
---|
70 | |
---|
71 | for ($i = 1; $i<=$feedcount; $i++) { |
---|
72 | $url = "fetch_url_".$i; |
---|
73 | if ( preg_match($validurl ,$_POST[$url]) ) { |
---|
74 | if ( $_POST['friend'] && in_array ($i, $_POST['friend']) ) |
---|
75 | $friends = "on"; |
---|
76 | else $friends = ""; |
---|
77 | setConfig($url, $_POST[$url].':::'.$time[$i].':::'.$friends); |
---|
78 | $feed[$i] = $_POST[$url]; |
---|
79 | } else |
---|
80 | setConfig($url, ''); |
---|
81 | $feed[$i] = ''; |
---|
82 | } |
---|
83 | } |
---|
84 | $feed = array(); |
---|
85 | for ($i = 1; $i<=$feedcount; $i++) { |
---|
86 | $str = getConfig('fetch_url_'.$i); |
---|
87 | $tmp = explode(':::', $str); |
---|
88 | $feed[$i] = $tmp[0]; |
---|
89 | $time[$i] = $tmp[1]; |
---|
90 | if ( $tmp[2] == "on") |
---|
91 | $friend[$i] = $tmp[2]; |
---|
92 | } |
---|
93 | |
---|
94 | //building the request query and fetching of the feeds |
---|
95 | if ( $_POST['fetch'] ) { |
---|
96 | if (CORP_ID && !MASTER) { |
---|
97 | $corp = new Corporation(CORP_ID); |
---|
98 | $myid = '&corp='.urlencode($corp->getName()); |
---|
99 | } |
---|
100 | if (ALLIANCE_ID && !MASTER) { |
---|
101 | $alli = new Alliance(ALLIANCE_ID); |
---|
102 | $myid = '&alli='.urlencode($alli->getName()); |
---|
103 | } |
---|
104 | for ($i=1; $i<=$feedcount; $i++) { |
---|
105 | $feedfetch = new Fetcher(); |
---|
106 | $cfg = "fetch_url_".$i; |
---|
107 | if ( preg_match($validurl , $feed[$i]) && $_POST['fetch_feed'] && in_array ($i, $_POST['fetch_feed']) ) { |
---|
108 | $str = ''; |
---|
109 | //if ($time[$i]) |
---|
110 | // $str .= '&lastkllid='.$time[$i]; |
---|
111 | if ($friend[$i]) |
---|
112 | $str .= '&friend=1'; |
---|
113 | if ( $_POST['fetch_losses'] ) |
---|
114 | $str .= "&losses=1"; |
---|
115 | if ( !getConfig('fetch_compress') ) |
---|
116 | $str .= "&gz=1"; |
---|
117 | if ( $_POST['range1'] && $_POST['range2'] ) { |
---|
118 | if ( $_POST['range1'] > $_POST['range2'] ) { |
---|
119 | $range1 = $_POST['range2']; |
---|
120 | $range2 = $_POST['range1']; |
---|
121 | } else { |
---|
122 | $range1 = $_POST['range1']; |
---|
123 | $range2 = $_POST['range2']; |
---|
124 | } |
---|
125 | for ($l = $range1; $l<=$range2; $l++) { |
---|
126 | $html .= "<b>Week: ". $l ."</b><br>"; |
---|
127 | $html .= $feedfetch->grab( $feed[$i]."&year=".$_POST['year']."&week=".$l, $myid.$str ); |
---|
128 | } |
---|
129 | } else |
---|
130 | $html .= $feedfetch->grab( $feed[$i], $myid.$str ); |
---|
131 | } |
---|
132 | setConfig($cfg, $feed[$i].':::'.$lastkllid.':::'.$friend); |
---|
133 | $time[$i] = $lastkllid; |
---|
134 | } |
---|
135 | } |
---|
136 | //generating the html |
---|
137 | $html .= '<form id="options" name="options" method="post" action="?a=settings_feed_syndication">'; |
---|
138 | $html .= "</table>"; |
---|
139 | |
---|
140 | $html .= "<div class=block-header2>Feeds</div><table>"; |
---|
141 | for ($i = 1; $i<=$feedcount; $i++) { |
---|
142 | $html .= "<tr><td width=85px><b>Feed url #".$i."</b></td><td><input type=text name=fetch_url_".$i." size=50 class=password value=\""; |
---|
143 | if ( $feed[$i] ) |
---|
144 | $html .= $feed[$i]; |
---|
145 | $html .= "\"></td>"; |
---|
146 | |
---|
147 | $html .= "<td><input type=checkbox name=friend[] id=friend value=".$i; |
---|
148 | if ( $friend[$i] ) |
---|
149 | $html .= " checked=\"checked\""; |
---|
150 | $html .= "><b>Friend?</b></td>"; |
---|
151 | |
---|
152 | $html .= "<td><input type=checkbox name=fetch_feed[] id=fetch value=".$i; |
---|
153 | if ( $feed[$i] ) |
---|
154 | $html .= " checked=\"checked\""; |
---|
155 | $html .= "><b>Fetch?</b><br>"; |
---|
156 | $html .= "</td></tr>"; |
---|
157 | } |
---|
158 | $html .= '<tr><td colspan=2><i>Example: http://killboard.eve-d2.com/?a=feed</i></td><td>'; |
---|
159 | $html .= '<input type="checkbox" name="all" onclick="checkAll(this.form.friend,this)"><i>all/none</i></td><td>'; |
---|
160 | $html .= '<input type="checkbox" name="all" onclick="checkAll(this.form.fetch,this)"><i>all/none</i>'; |
---|
161 | $html .= "</td></tr><br></table><br><br><br>"; |
---|
162 | |
---|
163 | $html .= "<table><tr><td height=20px width=150px><b>First week:</b></td>"; |
---|
164 | $html .= '<td><select name="range1">'; |
---|
165 | $now = date("W"); |
---|
166 | for ($i = 1; $i<=52; $i++) { |
---|
167 | if ( $now == $i ) |
---|
168 | $html .= '<option selected="selected "value="'.$i.'">'.$i.'</option>'; |
---|
169 | else |
---|
170 | $html .= '<option value="'.$i.'">'.$i.'</option>'; |
---|
171 | } |
---|
172 | $html .= '</select>'; |
---|
173 | $html .= "<i></i></td></tr>"; |
---|
174 | $html .= "<tr><td height=20px width=150px><b>Last week:</b></td>"; |
---|
175 | $html .= '<td><select name="range2">'; |
---|
176 | for ($i = 1; $i<=52; $i++) { |
---|
177 | if ( $now == $i ) |
---|
178 | $html .= '<option selected="selected "value="'.$i.'">'.$i.'</option>'; |
---|
179 | else |
---|
180 | $html .= '<option value="'.$i.'">'.$i.'</option>'; |
---|
181 | } |
---|
182 | $html .= '</select>'; |
---|
183 | $html .= "<i></i></td></tr>"; |
---|
184 | |
---|
185 | $html .= "<tr><td height=20px width=150px><b>Year:</b></td>"; |
---|
186 | $html .= '<td><select name="year">'; |
---|
187 | $html .= '<option "value="2005">2005</option>'; |
---|
188 | $html .= '<option "value="2006">2006</option>'; |
---|
189 | $html .= '<option selected="selected "value="2007">2007</option>'; |
---|
190 | $html .= '<option "value="2008">2008</option>'; |
---|
191 | $html .= '<option "value="2009">2009</option>'; |
---|
192 | $html .= '</select>'; |
---|
193 | $html .= "</td></tr>"; |
---|
194 | $html .= "<tr><td height=40px width=150px><b>Get kills instead of losses?</b></td>"; |
---|
195 | $html .= "<td><input type=checkbox name=fetch_losses id=fetch_losses>"; |
---|
196 | $html .= "<i> (by default only their kills, your losses, get fetched, when ticked this is inversed)</i></td></tr>"; |
---|
197 | $html .= "</table><br><br>"; |
---|
198 | $html .= "<input type=submit id=submit name=fetch value=\"Fetch!\"><br><br>"; |
---|
199 | |
---|
200 | $html .= "<div class=block-header2>Options</div><table>"; |
---|
201 | $html .= "<tr><td height=30px width=150px><b>Number of feeds:</b></td>"; |
---|
202 | $html .= "<td><input type=text name=fetch_feed_count size=2 maxlength=2 class=password value=\"".$feedcount."\"></td></tr>"; |
---|
203 | $html .= "<tr><td height=50px width=150px><b>Comment for automatically parsed killmails?</b></td>"; |
---|
204 | $html .= "<td><input type=text size=50 class=password name=fetch_comment id=fetch_comment value=\""; |
---|
205 | if ( getConfig('fetch_comment') ) |
---|
206 | $html .= getConfig('fetch_comment'); |
---|
207 | $html .= "\"><br><i> (leave blank for none)</i><br></td></tr>"; |
---|
208 | $html .= "<tr><td height=30px width=150px><b>Enable compression?</b></td>"; |
---|
209 | $html .= "<td><input type=checkbox name=fetch_compress id=fetch_compress"; |
---|
210 | if ( !getConfig('fetch_compress') ) |
---|
211 | $html .= " checked=\"checked\""; |
---|
212 | $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>"; |
---|
213 | $html .= "</tr>"; |
---|
214 | $html .= "<tr><td height=30px width=150px><b>Verbose mode?</b></td>"; |
---|
215 | $html .= "<td><input type=checkbox name=fetch_verbose id=fetch_verbose"; |
---|
216 | if ( getConfig('fetch_verbose') ) |
---|
217 | $html .= " checked=\"checked\""; |
---|
218 | $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>"; |
---|
219 | $html .= "</tr></table><br><br>"; |
---|
220 | $html .= "<input type=submit id=submit name=submit value=\"Save\">"; |
---|
221 | $html .= "</form>"; |
---|
222 | |
---|
223 | $page->addContext( $menubox->generate() ); |
---|
224 | $page->setContent( $html ); |
---|
225 | $page->generate(); |
---|
226 | ?> |
---|