Merge pull request #15890 from civicrm/5.20
[civicrm-core.git] / CRM / Event / Page / ICalendar.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
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 */
35 public function run() {
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);
40 $iCalPage = CRM_Utils_Request::retrieve('list', 'Positive', $this, FALSE, 0);
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);
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
62 $enable_cart = Civi::settings()->get('enable_cart');
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 }
87
88 }