if ( isset($_REQUEST['eventId']) && $eventId = filter_var($_REQUEST['eventId'], FILTER_VALIDATE_INT)) {
$search = true;
$action = 'event-ical';
- }
+ }
if ( !isset($eventId) || !$eventId ) {
$action = 'event-list-ical';
- }
+ }
$output = '';
exit;
break;
case 'event-list-ical':
+ $icalHeader = <<<EOD
+\r\nBEGIN:VCALENDAR
+PRODID:-//Gaslight Media Inc//Gaslight Events Calendar v2.0/EN
+VERSION:2.0
+CALSCALE:GREGORIAN
+METHOD:PUBLISH
+EOD;
+
+ $icalFooter = <<<EOD
+\nEND:VCALENDAR
+EOD;
+
$eventSql = "
- SELECT id
+ SELECT id
FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX. "events
WHERE id IN (
SELECT event
AND " . $this->dateRange . "
)
ORDER BY id";
+ $output .= $icalHeader;
$events = $this->wpdb->get_results( $eventSql, ARRAY_A );
if ( isset($events) && !empty($events) ) {
foreach ( $events as $key => $event ) {
$output .= $this->getEventOutput( $event['id'] );
}
}
+ $output .= $icalFooter;
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: inline; filename=events.ics');
echo $output;
$this->postAddRecurrences = true;
$event = $this->getModelEventData($eventId);
$this->postAddRecurrences = false;
- $icalHeader = <<<EOD
-\r\nBEGIN:VCALENDAR
-PRODID:-//Gaslight Media Inc//Gaslight Events Calendar v2.0/EN
-VERSION:2.0
-CALSCALE:GREGORIAN
-METHOD:PUBLISH
-EOD;
-
- $icalFooter = <<<EOD
-\nEND:VCALENDAR
-EOD;
-
$eventTemplateStart = <<<EOD
\r\nBEGIN:VEVENT
UID:%d@%s
-ORGANIZER:CN=%s
+ORGANIZER;CN="%s"
CREATED:%s
DTSTAMP:%s
DTSTART:%s
$timeStampFormat = 'Ymd\THis';
$weekdays =
array(1 => 'SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA');
- $output .= $icalHeader;
// clean description
$description = 'DESCRIPTION:' . str_replace("\n", "\\n", strip_tags($event['descr']));
$description = str_replace("\r", '', $description);
$urlParts = parse_url(get_bloginfo('url'), PHP_URL_HOST);
$urlHost = str_replace('www.', '', $urlParts);
+ if ( $event['image'] ) {
+ // get file extension
+ $extension = end( explode( '.', $event['image'] ) );
+ if ( $extension ) {
+ switch ( strtolower( $extension ) ) {
+ case 'jpeg':
+ case 'jpg':
+ $description .= "\nATTACH;FMTTYPE=image/jpeg:" . GLM_MEMBERS_PLUGIN_MEDIA_URL . "/images/large/{$event['image']}";
+ break;
+ case 'gif':
+ $description .= "\nATTACH;FMTTYPE=image/gif:" . GLM_MEMBERS_PLUGIN_MEDIA_URL . "/images/large/{$event['image']}";
+ break;
+ case 'png':
+ $description .= "\nATTACH;FMTTYPE=image/png:" . GLM_MEMBERS_PLUGIN_MEDIA_URL . "/images/large/{$event['image']}";
+ break;
+ }
+ }
+ }
+ if ( $event['url'] ) {
+ $http
+ = (trim($event['url']) && !preg_match('%http[s]?://%i', $event['url']))
+ ? 'http://'
+ : '';
+ $description .= "\nURL:{$http}{$event['url']}";
+ }
$eventDataStart = sprintf($eventTemplateStart,
$event['id'],
$urlHost,
);
$output .= $eventDataStart;
// geo location (lat lon)
- if ( $event['use_member_location']['value']
+ if ( $event['use_member_location']['value']
&& $event['member']
) {
if ( $event['member']['lat'] && $event['member']['lon'] ) {
}
} else if ( !empty( $event['locations'] ) ) {
// location (address city state zip)
- $output .= "\nLOCATION:"
+ $output .= "\nLOCATION:"
. $event['locations']['name'] . ' - ';
if ( !$event['hide_address']['value'] ) {
if ( $event['locations']['address'] ) {
}
}
// contact info
- if ( $event['contact_name']
- || $event['contact_email']
- || $event['contact_phone']
+ if ( $event['contact_name']
+ || $event['contact_email']
+ || $event['contact_phone']
) {
- $output .= "\nCONTACT:" . $event['contact_email'] . '\;;'
+ $output .= "\nCONTACT:" . $event['contact_email'] . '\;;'
. $this->phoneFrmt( $event['contact_phone'] ) . '\;'
. $event['contact_name'];
}
$freq = 'FREQ=WEEKLY';
switch ( $dow ) {
case 'Sunday':
- $daysOfWeek[] = 'Sun';
+ $daysOfWeek[] = 'SU';
break;
case 'Monday':
- $daysOfWeek[] = 'Mon';
+ $daysOfWeek[] = 'MO';
break;
case 'Tuesday':
- $daysOfWeek[] = 'Tue';
+ $daysOfWeek[] = 'TU';
break;
case 'Wednesday':
- $daysOfWeek[] = 'Wed';
+ $daysOfWeek[] = 'WE';
break;
case 'Thursday':
- $daysOfWeek[] = 'Thu';
+ $daysOfWeek[] = 'TH';
break;
case 'Friday':
- $daysOfWeek[] = 'Fri';
+ $daysOfWeek[] = 'FR';
break;
case 'Saturday':
- $daysOfWeek[] = 'Sat';
+ $daysOfWeek[] = 'SA';
break;
}
}
}
}
$output .= $eventTemplateEnd;
- $output .= $icalFooter;
return $output;
}