Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | * $Id$ |
17 | * | |
18 | */ | |
19 | ||
20 | /** | |
21 | * ICalendar class | |
22 | * | |
23 | */ | |
24 | class CRM_Event_Page_ICalendar extends CRM_Core_Page { | |
25 | ||
26 | /** | |
27 | * Heart of the iCalendar data assignment process. The runner gets all the meta | |
28 | * data for the event and calls the method to output the iCalendar | |
29 | * to the user. If gData param is passed on the URL, outputs gData XML format. | |
30 | * Else outputs iCalendar format per IETF RFC2445. Page param true means send | |
31 | * to browser as inline content. Else, we send .ics file as attachment. | |
32 | * | |
33 | * @return void | |
34 | */ | |
00be9182 | 35 | public function run() { |
353ffa53 TO |
36 | $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, NULL, 'GET'); |
37 | $type = CRM_Utils_Request::retrieve('type', 'Positive', $this, FALSE, 0); | |
38 | $start = CRM_Utils_Request::retrieve('start', 'Positive', $this, FALSE, 0); | |
39 | $end = CRM_Utils_Request::retrieve('end', 'Positive', $this, FALSE, 0); | |
6a488035 | 40 | $iCalPage = CRM_Utils_Request::retrieve('list', 'Positive', $this, FALSE, 0); |
353ffa53 TO |
41 | $gData = CRM_Utils_Request::retrieve('gData', 'Positive', $this, FALSE, 0); |
42 | $html = CRM_Utils_Request::retrieve('html', 'Positive', $this, FALSE, 0); | |
43 | $rss = CRM_Utils_Request::retrieve('rss', 'Positive', $this, FALSE, 0); | |
6a488035 TO |
44 | |
45 | $info = CRM_Event_BAO_Event::getCompleteInfo($start, $type, $id, $end); | |
46 | $this->assign('events', $info); | |
47 | $this->assign('timezone', @date_default_timezone_get()); | |
48 | ||
49 | // Send data to the correct template for formatting (iCal vs. gData) | |
50 | $template = CRM_Core_Smarty::singleton(); | |
51 | $config = CRM_Core_Config::singleton(); | |
52 | if ($rss) { | |
53 | // rss 2.0 requires lower case dash delimited locale | |
54 | $this->assign('rssLang', str_replace('_', '-', strtolower($config->lcMessages))); | |
55 | $calendar = $template->fetch('CRM/Core/Calendar/Rss.tpl'); | |
56 | } | |
57 | elseif ($gData) { | |
58 | $calendar = $template->fetch('CRM/Core/Calendar/GData.tpl'); | |
59 | } | |
60 | elseif ($html) { | |
61 | // check if we're in shopping cart mode for events | |
aaffa79f | 62 | $enable_cart = Civi::settings()->get('enable_cart'); |
6a488035 TO |
63 | if ($enable_cart) { |
64 | $this->assign('registration_links', TRUE); | |
65 | } | |
66 | return parent::run(); | |
67 | } | |
68 | else { | |
69 | $calendar = $template->fetch('CRM/Core/Calendar/ICal.tpl'); | |
70 | $calendar = preg_replace('/(?<!\r)\n/', "\r\n", $calendar); | |
71 | } | |
72 | ||
73 | // Push output for feed or download | |
74 | if ($iCalPage == 1) { | |
75 | if ($gData || $rss) { | |
76 | CRM_Utils_ICalendar::send($calendar, 'text/xml', 'utf-8'); | |
77 | } | |
78 | else { | |
79 | CRM_Utils_ICalendar::send($calendar, 'text/plain', 'utf-8'); | |
80 | } | |
81 | } | |
82 | else { | |
83 | CRM_Utils_ICalendar::send($calendar, 'text/calendar', 'utf-8', 'civicrm_ical.ics', 'attachment'); | |
84 | } | |
85 | CRM_Utils_System::civiExit(); | |
86 | } | |
96025800 | 87 | |
6a488035 | 88 | } |