Cleanup deprecated CRM_Core_BAO_Settings calls CRM-17507
[civicrm-core.git] / CRM / Event / Page / ICalendar.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
6a488035
TO
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 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
e7112fa7 31 * @copyright CiviCRM LLC (c) 2004-2015
6a488035
TO
32 * $Id$
33 *
34 */
35
36/**
37 * ICalendar class
38 *
39 */
40class 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 */
00be9182 51 public function run() {
353ffa53
TO
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);
6a488035 56 $iCalPage = CRM_Utils_Request::retrieve('list', 'Positive', $this, FALSE, 0);
353ffa53
TO
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);
6a488035
TO
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
aaffa79f 78 $enable_cart = Civi::settings()->get('enable_cart');
6a488035
TO
79 if ($enable_cart) {
80 $this->assign('registration_links', TRUE);
81 }
82 return parent::run();
83 }
84 else {
85 $calendar = $template->fetch('CRM/Core/Calendar/ICal.tpl');
86 $calendar = preg_replace('/(?<!\r)\n/', "\r\n", $calendar);
87 }
88
89 // Push output for feed or download
90 if ($iCalPage == 1) {
91 if ($gData || $rss) {
92 CRM_Utils_ICalendar::send($calendar, 'text/xml', 'utf-8');
93 }
94 else {
95 CRM_Utils_ICalendar::send($calendar, 'text/plain', 'utf-8');
96 }
97 }
98 else {
99 CRM_Utils_ICalendar::send($calendar, 'text/calendar', 'utf-8', 'civicrm_ical.ics', 'attachment');
100 }
101 CRM_Utils_System::civiExit();
102 }
96025800 103
6a488035 104}