Created
January 14, 2019 00:07
-
-
Save fergbrain/47f21bc8bb69000ae5af0ef64106c8af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Template Name: Events - Calendar - iCal | |
* | |
* Author: Andrew Ferguson, [email protected] / [email protected] | |
* Copyright (C) 2016 Andrew Ferguson | |
* | |
* This program is free software: you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation, either version 3 of the License, or | |
* (at your option) any later version. | |
* | |
* This program is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* | |
* You should have received a copy of the GNU General Public License | |
* along with this program. If not, see <https://www.gnu.org/licenses/>. | |
* | |
* This shows a page with monthly calendar. | |
* | |
* See theme support feature for 'ctfw-event-calendar-redirection' | |
* | |
* content.php outputs the page content. | |
* | |
* Place in wp-content/resurect-child/page-templates/events-calendar-ical.php | |
* Requires iCalcreator 2.22 (or greater): https://github.com/iCalcreator/iCalcreator | |
* Place iCalcreator in wp-content/resurect-child/page-templates/ | |
*/ | |
// No direct access | |
if ( ! defined( 'ABSPATH' ) ) exit; | |
function messiahlutheran_ical(){ | |
require_once(__DIR__."/../iCalcreator/iCalcreator.php"); | |
$tz = "America/Los_Angeles"; | |
$config = array("unique_id" => "messiahseattle.org", | |
"TZID" => $tz | |
); | |
$v = new vcalendar($config); | |
// required of some calendar software | |
$v->setProperty( "method", "PUBLISH" ); | |
$v->setProperty( "x-wr-calname", "Messiah Lutheran Church" ); | |
$v->setProperty( "X-WR-CALDESC", "Messiah Lutheran Church, Seattle, WA" ); | |
$v->setProperty( "X-WR-TIMEZONE", $tz ); | |
$xprops = array( "X-LIC-LOCATION" => $tz ); | |
// create timezone component(-s) opt. 1 based on present date | |
iCalUtilityFunctions::createTimezone( $v, $tz, $xprops ); | |
global $post; | |
// Get calendar data | |
$events = ctfw_get_events(); | |
foreach($events as $thisEvent){ | |
$event_data = ctfw_event_data($thisEvent->ID); | |
//print_r($event_data); | |
// create an event calendar component | |
$vevent = & $v->newComponent( "vevent" ); | |
$vevent->setSummary( $thisEvent->post_title ); | |
$vevent->setDescription(wp_strip_all_tags(html_entity_decode($thisEvent->post_content), TRUE)); | |
if( $event_data['venue'] != ""){ | |
if( $event_data['address'] != ""){ | |
$vevent->setLocation($event_data['venue'].", ".$event_data['address']); | |
} | |
else{ | |
$vevent->setLocation($event_data['venue']); | |
} | |
} | |
$start = array( "year" => substr($event_data['start_date'],0,4), | |
"month" => substr($event_data['start_date'],5,2), | |
"day" => substr($event_data['start_date'],8,2), | |
"hour" => substr($event_data['start_time'],0,2), | |
"min" => substr($event_data['start_time'],3,2), | |
"sec" => 0 | |
); | |
$vevent->setDtstart($start); | |
$end = array( "year" => substr($event_data['end_date'],0,4), | |
"month" => substr($event_data['end_date'],5,2), | |
"day" => substr($event_data['end_date'],8,2), | |
"hour" => substr($event_data['end_time'],0,2), | |
"min" => substr($event_data['end_time'],3,2), | |
"sec" => 0 | |
); | |
if( ($event_data['end_date'] != "") && ($event_data['end_time'] != "")){ | |
$vevent->setDtend($end); | |
} | |
$vevent->setUid(md5($thisEvent->guid)."@".$v->getConfig('UNIQUE_ID')); | |
$dtstamp = array( "year" => substr($thisEvent->post_date_gmt,0,4), | |
"month" => substr($thisEvent->post_date_gmt,5,2), | |
"day" => substr($thisEvent->post_date_gmt,8,2), | |
"hour" => substr($thisEvent->post_date_gmt,11,2), | |
"min" => substr($thisEvent->post_date_gmt,14,2), | |
"sec" => substr($thisEvent->post_date_gmt,17,2) | |
); | |
$vevent->setDtstamp($dtstamp); | |
$lastmodified = array( "year" => substr($thisEvent->post_modified_gmt,0,4), | |
"month" => substr($thisEvent->post_modified_gmt,5,2), | |
"day" => substr($thisEvent->post_modified_gmt,8,2), | |
"hour" => substr($thisEvent->post_modified_gmt,11,2), | |
"min" => substr($thisEvent->post_modified_gmt,14,2), | |
"sec" => substr($thisEvent->post_modified_gmt,17,2) | |
); | |
$vevent->setLastModified($lastmodified); | |
if($event_data['recurrence'] != 'none'){ | |
$rrule = []; | |
if($event_data['recurrence_end_date'] != ""){ | |
$rrule['UNTIL'] = array("timestamp" => strtotime($event_data['recurrence_end_date']) ); | |
} | |
if ('weekly' == $event_data['recurrence']){ | |
$rrule["FREQ"] = "WEEKLY"; | |
$rrule["INTERVAL"] = $event_data['recurrence_weekly_interval']; | |
$vevent->setRrule($rrule); | |
} | |
elseif ('monthly'== $event_data['recurrence']){ | |
$rrule["FREQ"] = "MONTHLY"; | |
$rrule["INTERVAL"] = $event_data['recurrence_monthly_interval']; | |
$vevent->setRrule($rrule); | |
} | |
} | |
//print_r($post); | |
} | |
//print_r($events); | |
//exit(); | |
$v->returnCalendar(); | |
exit(); | |
//$xmlstr = iCal2XML( $v ); | |
//print $xmlstr; | |
} | |
messiahlutheran_ical(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment