/**
  * Heart of the iCalendar data assignment process. The runner gets all the meta
  * data for the event and calls the  method to output the iCalendar
  * to the user. If gData param is passed on the URL, outputs gData XML format.
  * Else outputs iCalendar format per IETF RFC2445. Page param true means send
  * to browser as inline content. Else, we send .ics file as attachment.
  *
  * @return void
  */
 public function run()
 {
     $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, NULL, 'GET');
     $type = CRM_Utils_Request::retrieve('type', 'Positive', $this, FALSE, 0);
     $start = CRM_Utils_Request::retrieve('start', 'Positive', $this, FALSE, 0);
     $end = CRM_Utils_Request::retrieve('end', 'Positive', $this, FALSE, 0);
     $iCalPage = CRM_Utils_Request::retrieve('list', 'Positive', $this, FALSE, 0);
     $gData = CRM_Utils_Request::retrieve('gData', 'Positive', $this, FALSE, 0);
     $html = CRM_Utils_Request::retrieve('html', 'Positive', $this, FALSE, 0);
     $rss = CRM_Utils_Request::retrieve('rss', 'Positive', $this, FALSE, 0);
     $info = CRM_Event_BAO_Event::getCompleteInfo($start, $type, $id, $end, false);
     $this->assign('events', $info);
     $this->assign('timezone', @date_default_timezone_get());
     // Send data to the correct template for formatting (iCal vs. gData)
     $template = CRM_Core_Smarty::singleton();
     $config = CRM_Core_Config::singleton();
     if ($rss) {
         // rss 2.0 requires lower case dash delimited locale
         $this->assign('rssLang', str_replace('_', '-', strtolower($config->lcMessages)));
         $calendar = $template->fetch('CRM/Core/Calendar/Rss.tpl');
     } elseif ($gData) {
         $calendar = $template->fetch('CRM/Core/Calendar/GData.tpl');
     } elseif ($html) {
         // check if we're in shopping cart mode for events
         $enable_cart = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME, 'enable_cart');
         if ($enable_cart) {
             $this->assign('registration_links', TRUE);
         }
         return parent::run();
     } else {
         $calendar = $template->fetch('CRM/Core/Calendar/ICal.tpl');
         $calendar = preg_replace('/(?<!\\r)\\n/', "\r\n", $calendar);
     }
     // Push output for feed or download
     if ($iCalPage == 1) {
         if ($gData || $rss) {
             CRM_Utils_ICalendar::send($calendar, 'text/xml', 'utf-8');
         } else {
             CRM_Utils_ICalendar::send($calendar, 'text/plain', 'utf-8');
         }
     } else {
         CRM_Utils_ICalendar::send($calendar, 'text/calendar', 'utf-8', 'civicrm_ical.ics', 'attachment');
     }
     CRM_Utils_System::civiExit();
 }
Example #2
0
function smarty_modifier_crmICalText($str)
{
    return CRM_Utils_ICalendar::formatText($str);
}
/**
 * Format the given text in an ical suitable format
 *
 * @param string $str
 *
 * @param bool $gdata
 *
 * @return string
 *   formatted text
 */
function smarty_modifier_crmICalDate($str, $gdata = FALSE)
{
    return CRM_Utils_ICalendar::formatDate($str, $gdata);
}
Example #4
0
 /**
  * Heart of the iCalendar data assignment process. The runner gets all the meta
  * data for the event and calls the  method to output the iCalendar
  * to the user. If gData param is passed on the URL, outputs gData XML format.
  * Else outputs iCalendar format per IETF RFC2445. Page param true means send
  * to browser as inline content. Else, we send .ics file as attachment.
  *
  * @return void
  */
 function run()
 {
     require_once "CRM/Utils/Request.php";
     $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, false, null, 'GET');
     $type = CRM_Utils_Request::retrieve('type', 'Positive', $this, false, 0);
     $start = CRM_Utils_Request::retrieve('start', 'Positive', $this, false, 0);
     $end = CRM_Utils_Request::retrieve('end', 'Positive', $this, false, 0);
     $iCalPage = CRM_Utils_Request::retrieve('page', 'Positive', $this, false, 0);
     $gData = CRM_Utils_Request::retrieve('gData', 'Positive', $this, false, 0);
     $html = CRM_Utils_Request::retrieve('html', 'Positive', $this, false, 0);
     $rss = CRM_Utils_Request::retrieve('rss', 'Positive', $this, false, 0);
     require_once "CRM/Event/BAO/Event.php";
     $info = CRM_Event_BAO_Event::getCompleteInfo($start, $type, $id, $end);
     $this->assign('events', $info);
     // Send data to the correct template for formatting (iCal vs. gData)
     $template = CRM_Core_Smarty::singleton();
     $config = CRM_Core_Config::singleton();
     if ($rss) {
         // rss 2.0 requires lower case dash delimited locale
         $this->assign('rssLang', str_replace('_', '-', strtolower($config->lcMessages)));
         $calendar = $template->fetch('CRM/Core/Calendar/Rss.tpl');
     } else {
         if ($gData) {
             $calendar = $template->fetch('CRM/Core/Calendar/GData.tpl');
         } else {
             if ($html) {
                 return parent::run();
             } else {
                 $calendar = $template->fetch('CRM/Core/Calendar/ICal.tpl');
             }
         }
     }
     // Push output for feed or download
     require_once "CRM/Utils/ICalendar.php";
     if ($iCalPage == 1) {
         if ($gData || $rss) {
             CRM_Utils_ICalendar::send($calendar, 'text/xml', 'utf-8');
         } else {
             CRM_Utils_ICalendar::send($calendar, 'text/plain', 'utf-8');
         }
     } else {
         CRM_Utils_ICalendar::send($calendar, 'text/calendar', 'utf-8', 'civicrm_ical.ics', 'attachment');
     }
     CRM_Utils_System::civiExit();
 }
Example #5
0
 /**
  * @param string $testString
  * @dataProvider escapeExamples
  */
 public function testParseStrings($testString)
 {
     $this->assertEquals($testString, CRM_Utils_ICalendar::unformatText(CRM_Utils_ICalendar::formatText($testString)));
 }