From 1e825b5176bd67d6dd1dff3c653b88bec0ff073b Mon Sep 17 00:00:00 2001 From: Matt Stein Date: Wed, 14 Aug 2013 16:23:42 -0700 Subject: [PATCH 1/2] Added ExpressionEngine < 2.6.0 compatibility and two new event parameters: localize and all_day. --- .../third_party/easy_ical/README.md | 13 ++++ .../third_party/easy_ical/pi.easy_ical.php | 62 +++++++++++++++++-- 2 files changed, 69 insertions(+), 6 deletions(-) diff --git a/system/expressionengine/third_party/easy_ical/README.md b/system/expressionengine/third_party/easy_ical/README.md index 6fd6a40..4f7cb65 100755 --- a/system/expressionengine/third_party/easy_ical/README.md +++ b/system/expressionengine/third_party/easy_ical/README.md @@ -73,6 +73,14 @@ The event summary (title). You probably want to pull this from a custom channel Allows you to add a link to the event. +### localize="yes" + +Choose whether to run dates through EE's localization class. Set to "no" when using Low Events. + +### all_day="yes" + +Drop time information and treat as an all-day event. (Also useful with Low Events.) + ### sequence="{event_sequence}" This adds a simple sequence number to the event. This is needed if you update an entry, otherwise @@ -81,6 +89,11 @@ iCal won't update the event. Use a simple counter custom field, like [Reevision] Changelog --------- +**1.2.1** *(2013-08-14)* + +* Re-added support for EE < 2.6.0 +* Added localize="" and all_day="" event parameters + **1.2** *(2013-07-08)* * ExpressionEngine 2.6 compatibility diff --git a/system/expressionengine/third_party/easy_ical/pi.easy_ical.php b/system/expressionengine/third_party/easy_ical/pi.easy_ical.php index ed75665..1badd72 100755 --- a/system/expressionengine/third_party/easy_ical/pi.easy_ical.php +++ b/system/expressionengine/third_party/easy_ical/pi.easy_ical.php @@ -40,7 +40,7 @@ class Easy_ical { - const VERSION = '1.2'; + const VERSION = '1.2.1'; public function calendar() { @@ -75,15 +75,42 @@ public function event() $out = "BEGIN:VEVENT\r\n". "UID:".$this->escape(ee()->TMPL->fetch_param('uid'))."\r\n"; + $all_day = FALSE; + $localize = TRUE; + + if (ee()->TMPL->fetch_param('all_day') !== FALSE) { + if ( + ee()->TMPL->fetch_param('all_day') === "y" OR + ee()->TMPL->fetch_param('all_day') === "yes" + ) { + $all_day = TRUE; + } + } + + if (ee()->TMPL->fetch_param('localize') !== FALSE) { + if ( + ee()->TMPL->fetch_param('localize') === "n" OR + ee()->TMPL->fetch_param('localize') === "no" + ) { + $localize = FALSE; + } + } + if (ee()->TMPL->fetch_param('location') !== FALSE) { $out .= "LOCATION:".$this->escape(ee()->TMPL->fetch_param('location'))."\r\n"; } - $out .= "DTSTAMP:".$this->ical_time(ee()->TMPL->fetch_param('start_time'))."\r\n"; - $out .= "DTSTART:".$this->ical_time(ee()->TMPL->fetch_param('start_time'))."\r\n"; + $out .= "DTSTAMP:".$this->ical_time(ee()->TMPL->fetch_param('start_time'), $all_day, $localize)."\r\n"; + $out .= "DTSTART:".$this->ical_time(ee()->TMPL->fetch_param('start_time'), $all_day, $localize)."\r\n"; if (ee()->TMPL->fetch_param('end_time') !== FALSE) { - $out .= "DTEND:".$this->ical_time(ee()->TMPL->fetch_param('end_time'))."\r\n"; + $end_time = ee()->TMPL->fetch_param('end_time'); + + if ($all_day) { + $end_time = strtotime('+1 day', $end_time); + } + + $out .= "DTEND:".$this->ical_time($end_time, $all_day, $localize)."\r\n"; } if (ee()->TMPL->fetch_param('summary') !== FALSE) { @@ -130,9 +157,32 @@ public function escape($str) return implode("\r\n ", $lines); } - public function ical_time($time) + public function ical_time($time, $all_day, $localize) { - return ee()->localize->format_date('%Y%m%dT%H%i%s', $time); + if ($localize) { + if (APP_VER >= '2.6.0') + { + if ($all_day) { + return ee()->localize->format_date('%Y%m%d', $time); + } else { + return ee()->localize->format_date('%Y%m%dT%H%i%s', $time); + } + } + else + { + if ($all_day) { + return ee()->localize->decode_date('%Y%m%d', $time); + } else { + return ee()->localize->decode_date('%Y%m%dT%H%i%s', $time); + } + } + } else { + if ($all_day) { + return date('Ymd', $time); + } else { + return date('Ymd\THis', $time); + } + } } public static function usage() From 3b88de7b560640601fcb7cf2ac0561cb3eb18464 Mon Sep 17 00:00:00 2001 From: Matt Stein Date: Wed, 9 Apr 2014 21:17:15 -0700 Subject: [PATCH 2/2] Removed pointless EE version check. --- .../third_party/easy_ical/pi.easy_ical.php | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/system/expressionengine/third_party/easy_ical/pi.easy_ical.php b/system/expressionengine/third_party/easy_ical/pi.easy_ical.php index 1badd72..83fde35 100755 --- a/system/expressionengine/third_party/easy_ical/pi.easy_ical.php +++ b/system/expressionengine/third_party/easy_ical/pi.easy_ical.php @@ -160,21 +160,10 @@ public function escape($str) public function ical_time($time, $all_day, $localize) { if ($localize) { - if (APP_VER >= '2.6.0') - { - if ($all_day) { - return ee()->localize->format_date('%Y%m%d', $time); - } else { - return ee()->localize->format_date('%Y%m%dT%H%i%s', $time); - } - } - else - { - if ($all_day) { - return ee()->localize->decode_date('%Y%m%d', $time); - } else { - return ee()->localize->decode_date('%Y%m%dT%H%i%s', $time); - } + if ($all_day) { + return ee()->localize->format_date('%Y%m%d', $time); + } else { + return ee()->localize->format_date('%Y%m%dT%H%i%s', $time); } } else { if ($all_day) {