5d60a0ad8b1cc80e497f009f47da8c2b07bbb365
[civicrm-core.git] / CRM / Event / Page / ICalendar.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2013
32 * $Id$
33 *
34 */
35
36 /**
37 * ICalendar class
38 *
39 */
40 class CRM_Event_Page_ICalendar extends CRM_Core_Page {
41
42 /**
43 * Heart of the iCalendar data assignment process. The runner gets all the meta
44 * data for the event and calls the method to output the iCalendar
45 * to the user. If gData param is passed on the URL, outputs gData XML format.
46 * Else outputs iCalendar format per IETF RFC2445. Page param true means send
47 * to browser as inline content. Else, we send .ics file as attachment.
48 *
49 * @return void
50 */
51 function run() {
52 $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, NULL, 'GET');
53 $type = CRM_Utils_Request::retrieve('type', 'Positive', $this, FALSE, 0);
54 $start = CRM_Utils_Request::retrieve('start', 'Positive', $this, FALSE, 0);
55 $end = CRM_Utils_Request::retrieve('end', 'Positive', $this, FALSE, 0);
56 $iCalPage = CRM_Utils_Request::retrieve('list', 'Positive', $this, FALSE, 0);
57 $gData = CRM_Utils_Request::retrieve('gData', 'Positive', $this, FALSE, 0);
58 $html = CRM_Utils_Request::retrieve('html', 'Positive', $this, FALSE, 0);
59 $rss = CRM_Utils_Request::retrieve('rss', 'Positive', $this, FALSE, 0);
60
61 $info = CRM_Event_BAO_Event::getCompleteInfo($start, $type, $id, $end);
62 $this->assign('events', $info);
63 $this->assign('timezone', @date_default_timezone_get());
64
65 // Send data to the correct template for formatting (iCal vs. gData)
66 $template = CRM_Core_Smarty::singleton();
67 $config = CRM_Core_Config::singleton();
68 if ($rss) {
69 // rss 2.0 requires lower case dash delimited locale
70 $this->assign('rssLang', str_replace('_', '-', strtolower($config->lcMessages)));
71 $calendar = $template->fetch('CRM/Core/Calendar/Rss.tpl');
72 }
73 elseif ($gData) {
74 $calendar = $template->fetch('CRM/Core/Calendar/GData.tpl');
75 }
76 elseif ($html) {
77 // check if we're in shopping cart mode for events
78 $enable_cart = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME,
79 'enable_cart'
80 );
81 if ($enable_cart) {
82 $this->assign('registration_links', TRUE);
83 }
84 return parent::run();
85 }
86 else {
87 $calendar = $template->fetch('CRM/Core/Calendar/ICal.tpl');
88 $calendar = preg_replace('/(?<!\r)\n/', "\r\n", $calendar);
89 }
90
91 // Push output for feed or download
92 if ($iCalPage == 1) {
93 if ($gData || $rss) {
94 CRM_Utils_ICalendar::send($calendar, 'text/xml', 'utf-8');
95 }
96 else {
97 CRM_Utils_ICalendar::send($calendar, 'text/plain', 'utf-8');
98 }
99 }
100 else {
101 CRM_Utils_ICalendar::send($calendar, 'text/calendar', 'utf-8', 'civicrm_ical.ics', 'attachment');
102 }
103 CRM_Utils_System::civiExit();
104 }
105 }
106