From: Steve Sutton Date: Tue, 29 Sep 2015 18:19:24 +0000 (-0400) Subject: Update for feed X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fdevelop;p=prog%2FeventIcal.git Update for feed correcting category part format of phone number correction in description line breaks --- diff --git a/index.php b/index.php index e1a5e40..20883de 100644 --- a/index.php +++ b/index.php @@ -33,10 +33,30 @@ function getHourArrayFromTime($time) '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 = <<query($sql); $events = $stmt->fetchAll(PDO::FETCH_ASSOC); @@ -88,8 +110,9 @@ $weekdays = 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', @@ -103,9 +126,49 @@ foreach ($events as $event) { $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']) { @@ -150,12 +213,6 @@ foreach ($events as $event) { 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'])); } }