| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 5 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
| 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-2019 |
| 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 | public 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 = Civi::settings()->get('enable_cart'); |
| 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 | } |
| 103 | |
| 104 | } |