'A' => $dateTime->format('A')
);
}
+function phoneFrmt($number)
+{
+ $num = preg_replace('%[^0-9]%', '', trim($number));
+ if (strlen($num) == 10) {
+ preg_match('%(\d{3})(\d{3})(\d{4})%', $num, $part);
+ return '('. $part[1] . ') ' . $part[2] . '-' . $part[3];
+ } else if (strlen($num) == 7) {
+ preg_match('%(\d{3})(\d{4})%', $num, $part);
+ return $part[1] . '-' . $part[2];
+ } else {
+ return $num;
+
+ }
+}
+
+if (!$dbh) {
+ $dbh = Toolkit_Database::getInstance();
+}
$icalHeader = <<<EOD
BEGIN:VCALENDAR
+PRODID:-//Gaslight Media Inc//Gaslight Events Calendar v2.0/EN
VERSION:2.0
-PRODID:~//Gaslight Media Inc//Gaslight Events Calendar v2.0/EN
+CALSCALE:GREGORIAN
+METHOD:PUBLISH
EOD;
$icalFooter = <<<EOD
DTSTAMP:%s
DTSTART:%s
DTEND:%s
-DESCRIPTION:%s
+%s
SUMMARY:%s
STATUS:CONFIRMED
EOD;
$sql = "
SELECT *
FROM event
+ WHERE edate >= '01/01/2014'::DATE
+ AND visable = true
ORDER BY bdate,edate";
$stmt = $dbh->query($sql);
$events = $stmt->fetchAll(PDO::FETCH_ASSOC);
array(1 => 'SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA');
foreach ($events as $event) {
// clean description
- $description = str_replace("\n", '\n', strip_tags($event['descr']));
+ $description = 'DESCRIPTION:' . str_replace("\n", "\\n", strip_tags($event['descr']));
$description = str_replace("\r", '', $description);
+ //$description = wordwrap($description, 75, "\\n");
$eventDataStart = sprintf($eventTemplateStart,
$event['id'],
'emmetcounty.org',
$event['header']
);
$output .= $eventDataStart;
+ // If event has Location data
+ if ($event['lat'] || $event['lon']) {
+ $output .= "\nGEO:" . $event['lat'] . ';' . $event['lon'];
+ }
+ $hasLocation = ($event['loc']
+ || $event['address']
+ || $event['city']
+ || $event['state']
+ || $event['zip']
+ );
+ if ($hasLocation) {
+ $output .= "\nLOCATION:" . $event['loc'].' - ';
+ if ($event['address']) {
+ $output .= "{$event['address']}";
+ }
+ if ($event['city']) {
+ $output .= "\,{$event['city']}";
+ }
+ if ($event['state']) {
+ $output .= "\,{$event['state']}";
+ }
+ if ($event['zip']) {
+ $output .= "\,{$event['zip']}";
+ }
+ }
// if event has contact data
if ( $event['contact'] || $event['email'] || $event['phone']) {
- $output .= "\nCONTACT:" . $event['contact'] . '\,' .$event['email'] .'\,'.$event['phone'];
+ $output .= "\nCONTACT:" . $event['email'] . '\;;' . phoneFrmt($event['phone']) . '\;'.$event['contact'];
+ }
+ if ($event['topicid']) {
+ $getTopic->bindParam(':id', $event['topicid'], PDO::PARAM_INT);
+ $getTopic->execute();
+ $categoryName = $getTopic->fetchColumn();
+ $output .= "\nCATEGORIES:" . $categoryName;
+ }
+ if ($event['cost']) {
+ $output .= "\nX-COST:" . $event['cost'];
+ }
+ if ($event['url']) {
+ if (!preg_match('%http://|https://%', $event['url'])) {
+ $event['url'] = 'http://' . $event['url'];
+ }
+ $output .= "\nX-TICKETS-URL:" . $event['url'];
}
// if event is recur
if ($event['reacur']) {
if (!empty($eventDays)) {
$daysInWeek = implode(',', $eventDays);
}
- if ($event['topicid']) {
- $getTopic->bindParam(':id', $event['topicid'], PDO::PARAM_INT);
- $getTopic->execute();
- $categoryName = $getTopic->fetchColumn();
- $output .= "\nCATEGORIES:" . $categoryName;
- }
$output .= "\nRRULE:" .$freq . ';BYDAY=' . $daysInWeek . ';UNTIL=' . icalDateFormat($event['edate'], getHourArrayFromTime($event['etime']));
}
}