-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
exchange.php
326 lines (286 loc) · 13.5 KB
/
exchange.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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
<?php
/* Project: EQdkp-Plus
* Package: EQdkp-plus
* Link: http://eqdkp-plus.eu
*
* Copyright (C) 2006-2016 EQdkp-Plus Developer Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
define('EQDKP_INC', true);
$eqdkp_root_path = './';
define('NO_MMODE_REDIRECT', true);
//Create no session for external portal modules.
//Using Get here is neccessary, because input class not loaded yet and not working with the user input
if(isset($_GET['out']) && $_GET['out'] == 'portal'){
define('NO_NEW_SESSION', true);
}
include_once($eqdkp_root_path . 'common.php');
$myOut = '';
if (registry::register('config')->get('pk_maintenance_mode')){
if (registry::register('input')->get('format') == 'json'){
$myOut = json_encode(array('status' => 0, 'error' => 'maintenance'));
} else {
$myOut = '<?xml version="1.0" encoding="UTF-8"?><response><status>0</status><error>maintenance</error></response>';
}
echo($myOut);
exit;
}
if(registry::register('input')->get('out') != ''){
switch (registry::register('input')->get('out')){
case 'comments':
if(registry::register('input')->get('deleteid', 0)){
registry::register('comments')->Delete(registry::register('input')->get('page'), registry::register('input')->get('replies', 0));
}elseif(registry::register('input')->get('comment', '', 'htmlescape')){
registry::register('comments')->Save();
}else{
echo registry::register('comments')->Content(registry::register('input')->get('attach_id'), registry::register('input')->get('page'), registry::register('input')->get('replies', 0));
}
exit;
break;
case 'xsd': $myOut = $eqdkp_root_path.'core/xsd/data_export.xsd';
break;
case 'xml':
if (registry::register('input')->get('data', '') != ''){
$encrypt = registry::register('encrypt');
$data = unserialize_noclasses($encrypt->decrypt(rawurldecode(registry::register('input')->get('data'))));
if ($data){
$userid = registry::fetch('user')->getUserIDfromExchangeKey(registry::register('input')->get('key', ''));
foreach($data['perms'] as $perm){
if (!registry::fetch('user')->check_auth($perm, false, $userid)){
$myOut = '<?xml version="1.0" encoding="UTF-8"?><response><status>0</status><error>access denied</error></response>';
echo($myOut);
exit;
}
}
$myOut = registry::register('file_handler')->FileLink('rss/'.$data['url'], 'eqdkp', 'relative');
}
}
break;
// generate an ical feed
case 'icalfeed':
// the permissions for the single modules
$permissions = array(
'calendar' => 'po_calendarevent'
);
$modulename = registry::register('input')->get('module', '');
// check for permission
$userid = registry::fetch('user')->getUserIDfromExchangeKey(registry::register('input')->get('key', ''));
if (isset($permissions[$modulename]) && registry::fetch('user')->check_auth($permissions[$modulename], false, $userid)){
require($eqdkp_root_path.'libraries/icalcreator/iCalcreator.php');
$v = new vcalendar;
$v->setConfig('unique_id', registry::register('config')->get('server_name'));
$v->setProperty('x-wr-calname', sprintf(registry::fetch('user')->lang('icalfeed_name'), registry::register('config')->get('guildtag')));
$v->setProperty('X-WR-CALDESC', registry::fetch('user')->lang('icalfeed_description'));
// set the timezone - required by some clients
$timezone = registry::register('config')->get('timezone');
$v->setProperty( "X-WR-TIMEZONE", $timezone);
iCalUtilityFunctions::createTimezone( $v, $timezone, array( "X-LIC-LOCATION" => $timezone));
switch($modulename){
case 'calendar':
$eventtypes = registry::register('input')->get('type', 'raids');
switch($eventtypes){
case 'raids':
$eventsfilter = true;
break;
case 'all':
$eventsfilter = false;
break;
case 'appointments':
$eventsfilter = 'appointments';
break;
}
$calendars = registry::register('input')->get('calendars', '');
$calendarIds = $calendars ? explode(',', $calendars) : false;
$caleventids = registry::register('plus_datahandler')->get('calendar_events', 'id_list', array($eventsfilter, registry::register('time')->createRepeatableEvents(registry::register('time')->time, -30), PHP_INT_MAX, $calendarIds));
if(is_array($caleventids) && count($caleventids) > 0){
foreach($caleventids as $calid){
// the attendee stuff
$raidcal_status = registry::register('config')->get('calendar_raid_status');
$raidstatus = array();
if(is_array($raidcal_status)){
foreach($raidcal_status as $raidcalstat_id){
if($raidcalstat_id != 4){
$raidstatus[$raidcalstat_id] = registry::fetch('user')->lang(array('raidevent_raid_status', $raidcalstat_id));
}
}
}
// Build the Attendee Array
$attendees = array();
$attendees_raw = registry::register('plus_datahandler')->get('calendar_raids_attendees', 'attendees', array($calid));
if(is_array($attendees_raw)){
foreach($attendees_raw as $attendeeid=>$attendeerow){
$attendees[$attendeerow['signup_status']][$attendeeid] = registry::register('plus_datahandler')->get('member', 'name', array($attendeeid));
}
}
// Build the guest array
if(registry::register('config')->get('calendar_raid_guests') > 0){
$guestarray = registry::register('plus_datahandler')->get('calendar_raids_guests', 'members', array($calid));
if(is_array($guestarray)){
foreach($guestarray as $guest_row){
$attendees[(int)$guest_row['status']][] = $guest_row['name'];
}
}
}
// get the status counts
$counts = array();
if(is_array($raidstatus)){
foreach($raidstatus as $statusid=>$statusname){
$counts[$statusid] = ((isset($attendees[$statusid])) ? count($attendees[$statusid]) : 0);
}
}
// Build the user attendance
$description_usercontent = false;
if(isset($userid) && $userid > 0){
$attendancestatus = registry::register('plus_datahandler')->get('calendar_raids_attendees', 'html_status', array($calid, $userid, false));
if($attendancestatus != ''){
$description_usercontent = registry::fetch('user')->lang('calendar_export_statustext').' '.registry::fetch('user')->lang(array('raidevent_raid_status', $attendancestatus));
}
}
// build the description data
$description_data = registry::register('plus_datahandler')->get('calendar_events', 'notes', array($calid));
if($description_usercontent) { $description_data .= '\n'.$description_usercontent; }
$description_data .= (!empty($description_data)) ? '\n\n' : '';
if(is_array($counts) && count($counts) > 0){
foreach($counts as $countid=>$countdata){
$description_data .= $raidstatus[$countid].' ('.$countdata.'): '.((isset($attendees[$countid]) && count($attendees[$countid]) > 0) ? implode(', ',$attendees[$countid]) : '--').'\n';
}
}
// generate the ical output
$e = new vevent;
$e->setProperty('dtstart', array("timestamp" => registry::register('plus_datahandler')->get('calendar_events', 'time_start', array($calid)).'Z'));
$e->setProperty('dtend', array("timestamp" => registry::register('plus_datahandler')->get('calendar_events', 'time_end', array($calid)).'Z'));
$e->setProperty('summary', registry::register('plus_datahandler')->get('calendar_events', 'name', array($calid)));
$e->setProperty('description', rtrim($description_data));
$e->setProperty('class', 'PUBLIC');
$e->setProperty('categories', 'PERSONAL');
$v->setComponent($e);
// generate the alarm
if($description_usercontent){
$a = new valarm;
$a->setProperty('action', 'DISPLAY'); // set what to do
$a->setProperty('description', registry::register('plus_datahandler')->get('calendar_events', 'name', array($calid))); // describe alarm
$a->setProperty('trigger', array( 'hour' => 1 )); // set trigger one hour before
$e->setComponent($a); // add alarm component to event component as subcomponent
$v->setComponent($e); // add event component to calendar
}
}
}
break;
}
// Save or Output the ICS File..(for future usage, not used atm)
if($icsfile == true){
$v->setConfig('filename', $icsfile);
$v->saveCalendar();
}else{
header('Content-type: text/calendar; charset=utf-8;');
header('Content-Disposition: attachment; filename=raidevents.ics');
header('Cache-Control: max-age=10');
echo $v->createCalendar();
die();
}
}else{
die('Permission denied');
}
break;
case 'chartooltip':
header('content-type: text/html; charset=UTF-8');
echo registry::register('game')->chartooltip(registry::register('input')->get('charid', 0));
exit;
break;
case 'portal':
header('content-type: text/html; charset=UTF-8');
registry::register('core')->cors_headers();
echo registry::register('portal')->get_module_external(registry::register('input')->get('id', 0));
exit;
break;
case 'socialcounts':
header('Content-type: application/json; charset=utf-8');
echo registry::register('socialplugins')->getSocialButtonCount(rawurldecode(registry::register('input')->get('url')), registry::register('input')->get('target'));
exit;
break;
case 'styles':
header('content-type: text/html; charset=UTF-8');
$out = '<table class="table fullwidth colorswitch hoverrows">';
$intCurrentStyle = register('user')->style['style_id'];
foreach(register('pdh')->get('styles', 'styles', array(0, false)) as $styleid=>$row){
$plugin_code = $row['template_path'];
if (file_exists(registry::get_const('root_path').'templates/'.$plugin_code.'/screenshot.png' )){
$screenshot = '<img src="'.registry::get_const('server_path').'templates/'.$plugin_code.'/screenshot.png" style="max-width:200px;" alt="" />';
} elseif(file_exists(registry::get_const('root_path').'templates/'.$plugin_code.'/screenshot.jpg' )){
$screenshot = '<img src="'.registry::get_const('server_path').'templates/'.$plugin_code.'/screenshot.jpg" style="max-width:200px;" alt="" />';
} else $screenshot = "<img src='".registry::get_const('server_path')."images/global/default-image.svg' />";
if($styleid == $intCurrentStyle){
$current = " <i class='fa fa-check-circle fa-lg'></i>";
} else $current = "";
$url = filter_var($_SERVER['HTTP_REFERER'], FILTER_SANITIZE_STRING);
$link = sanitize(preg_replace('#style\=([0-9]*)#', "", preg_replace('#&style\=([0-9]*)#', "", $url))).((strpos($url, "?") === false) ? '?' : '&').'style='.$styleid;
$out .= '<tr><td width="10"><a href="'.$link.'">'.$screenshot.'</a></td><td><a href="'.$link.'">'.$row['style_name'].$current.'</a></td></tr>';
}
$out .= '</table>';
echo $out;
exit;
break;
case 'placepicker':
//Only for logged in users
if (!registry::fetch('user')->is_signedin()){
echo 'Permission denied';
exit;
}
$searchterm = registry::register('input')->get('term', '');
$result = register('geoloc')->getAutocompleteResult($searchterm, registry::fetch('user')->lang('XML_LANG'));
$out = array();
foreach($result['features'] as $resultkey=>$resultdata){
$result_name = $resultdata['properties']['name'];
$result_city = $resultdata['properties']['city'];
$result_country = $resultdata['properties']['country'];
if($resultdata['properties']['osm_value'] == 'city'){
$out[$resultkey] = (strlen($result_city)) ? $result_city : $result_name;
if($result_country){
$out[$resultkey] .= ', '.$result_country;
}
} elseif($resultdata['properties']['osm_value'] == 'residential') {
$out[$resultkey] = $result_name;
$out[$resultkey] .= ', '.$result_city;
if($result_country){
$out[$resultkey] .= ', '.$result_country;
}
} elseif($resultdata['properties']['osm_key'] == 'building') {
$out[$resultkey] = $resultdata['properties']['street'].' ';
$out[$resultkey] .= $resultdata['properties']['housenumber'];
$out[$resultkey] .= ', '.$result_city;
if($result_country){
$out[$resultkey] .= ', '.$result_country;
}
}
}
echo json_encode(array_values($out));
exit;
break;
}
if(is_file($myOut)){
ob_end_clean();
ob_start();
header('content-type: text/html; charset=UTF-8');
$outdata = file_get_contents($myOut);
echo((isset($outdata)) ? $outdata : '<?xml version="1.0" encoding="UTF-8"?><response><status>0</status><error>no data</error></response>');
}else{
echo '<?xml version="1.0" encoding="UTF-8"?><response><status>0</status><error>no file</error></response>';
}
exit;
}else{
echo '<?xml version="1.0" encoding="UTF-8"?><response><status>0</status><error>no selection</error></response>';
exit;
}
?>