-
Notifications
You must be signed in to change notification settings - Fork 1
/
calendar.php
52 lines (45 loc) · 1.84 KB
/
calendar.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
<?php
require_once 'base.php';
require_once W2P_BASE_DIR . '/includes/config.php';
require_once W2P_BASE_DIR . '/includes/main_functions.php';
require_once W2P_BASE_DIR . '/includes/db_adodb.php';
require_once W2P_BASE_DIR . '/classes/ui.class.php';
$AppUI = new CAppUI;
$token = w2PgetParam($_GET, 'token', '');
$format = w2PgetParam($_GET, 'format', 'ical');
$userId = CUser::getUserIdByToken($token);
$AppUI->loadPrefs($userId);
$AppUI->user_id = $userId;
$AppUI->setUserLocale();
@include_once (W2P_BASE_DIR . '/locales/' . $AppUI->user_locale . '/locales.php');
include_once W2P_BASE_DIR . '/locales/core.php';
$defaultTZ = w2PgetConfig('system_timezone', 'Europe/London');
$defaultTZ = ('' == $defaultTZ) ? 'Europe/London' : $defaultTZ;
date_default_timezone_set($defaultTZ);
switch ($format) {
//TODO: We only output in vCal, are there others we need to consider?
case 'vcal':
default:
$format = 'vcal';
header ( 'Content-Type: text/calendar' );
header ( 'Content-disposition: attachment; filename="calendar.ics"' );
break;
}
if ($userId > 0) {
$moduleList = $AppUI->getLoadableModuleList();
$myTimezoneName = date('e');
$calendarHeader = "BEGIN:VCALENDAR\nPRODID:-//web2project//EN\nVERSION:2.0\nCALSCALE:GREGORIAN\nMETHOD:PUBLISH\nX-WR-TIMEZONE:Europe/London\n";
$calendarFooter = "END:VCALENDAR";
foreach ($moduleList as $module) {
$object = new $module['mod_main_class']();
if (is_callable(array($object, 'hook_calendar'))) {
$itemList = $object->hook_calendar($userId);
if (is_array($itemList)) {
foreach ($itemList as $calendarItem) {
$buffer .= w2p_API_iCalendar::formatCalendarItem($calendarItem, $module['mod_directory']);
}
}
}
}
echo $calendarHeader.$buffer.$calendarFooter;
}