Example #1
0
 $description .= $permalink;
 //$description.= ' ['.sprintf(__('by: %s'),get_the_author_nickname()).']';
 ec3_ical_echo('DESCRIPTION:' . ec3_ical_quote($description));
 if ($entry->allday) {
     $dt_start = mysql2date('Ymd', $entry->start);
     $dt_end = date('Ymd', mysql2date('U', $entry->end) + 3600 * 24);
     ec3_ical_echo("TRANSP:TRANSPARENT");
     // for availability.
     ec3_ical_echo("DTSTART;VALUE=DATE:{$dt_start}");
     ec3_ical_echo("DTEND;VALUE=DATE:{$dt_end}");
 } else {
     ec3_ical_echo('TRANSP:OPAQUE');
     // for availability.
     // Convert timestamps to UTC
     ec3_ical_echo('DTSTART;VALUE=DATE-TIME:' . ec3_to_utc($entry->start));
     ec3_ical_echo('DTEND;VALUE=DATE-TIME:' . ec3_to_utc($entry->end));
 }
 // Location
 $location = get_post_meta($entry->post_id, 'location', true);
 $location = apply_filters('ical_location', $location);
 if (!empty($location)) {
     ec3_ical_echo('LOCATION:' . ec3_ical_quote($location));
 }
 // GEO
 $geo = get_post_meta($entry->post_id, 'geo', true);
 $geo = apply_filters('ical_geo', $geo);
 if (!empty($geo)) {
     ec3_ical_echo('GEO:' . ec3_ical_quote($geo));
 }
 do_action('ical_item');
 ec3_ical_echo('END:VEVENT');
Example #2
0
/** If the parameter ec3_ical is set, then brutally hijack the page and replace
 *  it with iCalendar data.
 * (Includes fixes contributed by Matthias Tarasiewicz & Marc Schumann.)*/
function ec3_filter_query_vars_ical($wpvarstoreset = NULL)
{
    //
    // Generate the iCalendar
    $name = preg_replace('/([\\,;])/', '\\\\$1', get_bloginfo_rss('name'));
    $filename = preg_replace('/[^0-9a-zA-Z]/', '', $name) . '.ics';
    header("Content-Type: text/calendar");
    header("Content-Disposition: inline; filename={$filename}");
    header('Expires: Wed, 11 Jan 1984 05:00:00 GMT');
    header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
    header('Cache-Control: no-cache, must-revalidate, max-age=0');
    header('Pragma: no-cache');
    echo "BEGIN:VCALENDAR\r\n";
    echo "VERSION:2.0\r\n";
    echo "X-WR-CALNAME:{$name}\r\n";
    global $ec3, $wpdb;
    $calendar_entries = $wpdb->get_results("SELECT\n         post_id,\n         sched_id,\n         post_title,\n         post_excerpt,\n         DATE_FORMAT(start,IF(allday,'%Y%m%d','%Y-%m-%d %H:%i')) AS dt_start,\n         IF( allday,\n             DATE_FORMAT(DATE_ADD(end, INTERVAL 1 DAY),'%Y%m%d'),\n             DATE_FORMAT(end,'%Y-%m-%d %H:%i')\n           ) AS dt_end,\n         {$ec3->wp_user_nicename} AS user_nicename,\n         IF(allday,'TRANSPARENT','OPAQUE') AS transp,\n         allday\n       FROM {$wpdb->posts} p\n       LEFT  JOIN {$wpdb->users}   u ON p.post_author=u.ID\n       INNER JOIN {$ec3->schedule} s ON p.id=s.post_id\n       WHERE post_status='publish'\n       ORDER BY start");
    if ($calendar_entries) {
        foreach ($calendar_entries as $entry) {
            // ?? Should add line folding at 75 octets at some time as per RFC 2445.
            $summary = preg_replace('/([\\,;])/', '\\\\$1', $entry->post_title);
            $permalink = get_permalink($entry->post_id);
            echo "BEGIN:VEVENT\r\n";
            echo "SUMMARY:{$summary}\r\n";
            echo "URL;VALUE=URI:{$permalink}\r\n";
            echo "UID:{$entry->sched_id}-{$permalink}\r\n";
            $description = '';
            if (strlen($entry->post_excerpt) > 0) {
                // I can't get iCal to understand iCalendar encoding.
                // So just strip out newlines here:
                $description = preg_replace('/[ \\r\\n]+/', ' ', $entry->post_excerpt . ' ');
                $description = preg_replace('/([\\,;])/', '\\\\$1', $description);
            }
            $description .= '[' . sprintf(__('by: %s'), $entry->user_nicename) . ']';
            echo "DESCRIPTION:{$description}\r\n";
            echo "TRANSP:{$entry->transp}\r\n";
            // for availability.
            if ($entry->allday) {
                echo "DTSTART;VALUE=DATE:{$entry->dt_start}\r\n";
                echo "DTEND;VALUE=DATE:{$entry->dt_end}\r\n";
            } else {
                // Convert timestamps to UTC
                echo sprintf("DTSTART;VALUE=DATE-TIME:%s\r\n", ec3_to_utc($entry->dt_start));
                echo sprintf("DTEND;VALUE=DATE-TIME:%s\r\n", ec3_to_utc($entry->dt_end));
            }
            echo "END:VEVENT\r\n";
        }
    }
    echo "END:VCALENDAR\r\n";
    exit(0);
}