Example #1
0
/**
 * Retrieve a venue's location suitable for an iCal feed.
 *
 * @since 1.0.0
 *
 * @param int|object $post Venue post ID or object.
 * @return string Venue iCal vCard.
 */
function get_audiotheme_venue_location_ical($venue = null)
{
    $venue = get_audiotheme_venue($venue);
    $output = $venue->name;
    $address = array();
    if (!empty($venue->address)) {
        $address[] = $venue->address;
    }
    $locality = empty($venue->city) ? '' : $venue->city;
    $locality .= empty($locality) && empty($venue->state) ? '' : ', ';
    $locality .= empty($venue->state) ? '' : $venue->state;
    if (!empty($locality)) {
        $address[] = $locality;
    }
    if (!empty($venue->country)) {
        $address[] = $venue->country;
    }
    if (!empty($venue->postal_code)) {
        $address[] = $venue->postal_code;
    }
    if (!empty($address)) {
        $output .= ', ' . join($address, ', ');
    }
    return escape_ical_text($output);
}
Example #2
0
header('Content-type: text/calendar');
header('Content-Disposition: attachment; filename="audiotheme-gigs.ics"');
?>
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//AudioTheme <?php 
echo AUDIOTHEME_VERSION;
?>

<?php 
foreach ($wp_query->posts as $post) {
    $post = get_audiotheme_gig($post);
    echo "BEGIN:VEVENT\n";
    echo 'UID:' . get_the_guid($post->ID) . "\n";
    echo 'URL:' . get_permalink($post->ID) . "\n";
    $date = get_audiotheme_gig_time('Ymd', '', true);
    $time = get_audiotheme_gig_time('', 'His', true);
    $dtstart = sprintf("DTSTART%s%s%s\n", empty($time) ? ';VALUE=DATE:' : ';TZID=GMT:', $date, empty($time) ? '' : 'T' . $time);
    echo $dtstart;
    echo 'SUMMARY:' . get_audiotheme_gig_title() . "\n";
    if (!empty($post->post_excerpt)) {
        echo 'DESCRIPTION:' . escape_ical_text($post->post_excerpt) . "\n";
    }
    if (!empty($post->venue)) {
        $location = get_audiotheme_venue_location_ical($post->venue->ID);
        echo empty($location) ? '' : 'LOCATION:' . $location . "\n";
    }
    echo "END:VEVENT\n";
}
?>
END:VCALENDAR