function vevent($datestart, $dateend, $address, $summary, $description) { print "BEGIN:VEVENT\n"; print "DTEND:" . dateToCal($dateend) . "\n"; print "UID:" . uniqid() . "\n"; print "DTSAMP:" . dateToCal(time()) . "\n"; print "LOCATION:" . escapeString($address) . "\n"; print "DESCRIPTION:" . escapeString($description) . "\n"; print "SUMMARY:" . escapeString($summary) . "\n"; print "DTSTART:" . dateToCal($datestart) . "\n"; print "END:VEVENT\n"; }
?> UID:<?php echo uniqidICS($bug_id); ?> DTSTAMP:<?php echo dateToCal(time()); ?> LOCATION:<?php echo escapeString($address); ?> DESCRIPTION:<?php echo escapeString($description); ?> SUMMARY:<?php echo escapeString($summary); ?> DTSTART:<?php echo dateToCal($datestart); ?> END:VEVENT END:VCALENDAR
// the file. The filename param sets the name of the file, so you could set // it as "my-event-name.ics" or something similar. // // - Read up on RFC 5545, the iCalendar specification. There is a lot of helpful // info in there, such as formatting rules. There are also many more options // to set, including alarms, invitees, busy status, etc. // // https://www.ietf.org/rfc/rfc5545.txt // 1. Set the correct headers for this file header('Content-type: text/calendar; charset=utf-8'); header('Content-Disposition: attachment; filename=' . $filename . '.ics'); // 2. Define helper functions // Converts a unix timestamp to an ics-friendly format // NOTE: "Z" means that this timestamp is a UTC timestamp. If you need // to set a locale, remove the "\Z" and modify DTEND, DTSTAMP and DTSTART // with TZID properties (see RFC 5545 section 3.3.5 for info) // // Also note that we are using "H" instead of "g" because iCalendar's Time format // requires 24-hour time (see RFC 5545 section 3.3.12 for info). function dateToCal($timestamp) { return date('Ymd\\THis\\Z', $timestamp); } // Escapes a string of characters function escapeString($string) { return preg_replace('/([\\,;])/', '\\\\$1', $string); } // 3. Echo out the ics file's contents echo "BEGIN:VCALENDAR\n" . "VERSION:2.0\n" . "METHOD:PUBLISH\n" . "PRODID:-//hacksw/handcal//NONSGML v1.0//EN\n" . "CALSCALE:GREGORIAN\n" . "BEGIN:VEVENT\n" . "DTEND:" . dateToCal($endDate) . "\n" . "UID:" . uniqid() . "\n" . "DTSTAMP:" . dateToCal(time()) . "\n" . "LOCATION:" . escapeString($location) . "\n" . "TRANSP: OPAQUE\n" . "SEQUENCE:0\n" . "DESCRIPTION:" . escapeString($desc) . "\n" . "URL;VALUE=URI:" . escapeString($link) . "\n" . "CLASS:PUBLIC\n" . "SUMMARY:" . escapeString($title) . "\n" . "DTSTART:" . dateToCal($startDate) . "\n" . "END:VEVENT\n" . "END:VCALENDAR\n";
function qem_ics() { global $post; $display = event_get_stored_display(); $summary = $post->post_title; $eventstart = get_post_meta($post->ID, 'event_date', true); if (!$eventstart) { $eventstart = time(); } $start = get_post_meta($post->ID, 'event_start', true); $date = date('Ymd\\T', $eventstart); $time = qem_time($start); $time = date('His', $time); $datestart = $date . $time; $dateend = get_post_meta($post->ID, 'event_end_date', true); $address = get_post_meta($post->ID, 'event_address', true); $url = get_permalink(); $description = get_post_meta($post->ID, 'event_desc', true); $filename = $post->post_title . '.ics'; if (!$dateend) { $dateend = $eventstart; $finish = get_post_meta($post->ID, 'event_finish', true); $date = date('Ymd\\T', $eventstart); $time = qem_time($finish); $time = date('His', $time); $dateend = $date . $time; } else { $finish = get_post_meta($post->ID, 'event_finish', true); $date = date('Ymd\\T', $dateend); $time = qem_time($finish); $time = date('His', $time); $dateend = $date . $time; } $ics = 'BEGIN:VCALENDAR VERSION:2.0 PRODID:-//hacksw/handcal//NONSGML v1.0//EN CALSCALE:GREGORIAN BEGIN:VEVENT UID:' . uniqid() . ' DTSTAMP:' . dateToCal(time()) . ' DTSTART:' . $datestart . ' DTEND:' . $dateend . ' LOCATION:' . $address . ' DESCRIPTION:' . $description . ' URL;VALUE=URI:' . $url . ' SUMMARY:' . $summary . ' END:VEVENT END:VCALENDAR'; qem_generate_csv(); $content = '<form method="post" action=""> <input type="hidden" name="qem_ics" value="' . $ics . '"> <input type="hidden" name="qem_filename" value="' . $filename . '"> <input type="submit" name="qem_create_ics" class="qem-register" id="submit" value="' . $display['useicsbutton'] . '" /></form>'; return $content; }
// PHP equiv format: Ymd\This // The Function function dateToCal($time) { return date('Ymd\\This', $time) . 'Z'; } // Build the ics file $ical = 'BEGIN:VCALENDAR VERSION:2.0 PRODID:-//hacksw/handcal//NONSGML v1.0//EN CALSCALE:GREGORIAN BEGIN:VEVENT DTEND:' . dateToCal($event['dateend']) . ' UID:' . md5($event['title']) . ' DTSTAMP:' . time() . ' LOCATION:' . addslashes($event['address']) . ' DESCRIPTION:' . addslashes($event['description']) . ' URL;VALUE=URI:http://mohawkaustin.com/events/' . $event['id'] . ' SUMMARY:' . addslashes($event['title']) . ' DTSTART:' . dateToCal($event['datestart']) . ' END:VEVENT END:VCALENDAR'; //set correct content-type-header if ($event['id']) { header('Content-type: text/calendar; charset=utf-8'); header('Content-Disposition: attachment; filename=mohawk-event.ics'); echo $ical; } else { // If $id isn't set, then kick the user back to home. Do not pass go, and do not collect $200. header('Location: /'); }
if ($evid != null) { /* PROCESS */ $dates = $modx->newQuery('GcCalendarDates'); // $dates->limit($limit,$offset); $dates->where(array('evid:=' => $evid)); $dates->sortby('start', 'ASC'); $dateArr = $modx->getIterator('GcCalendarDates', $dates); $event = $modx->getObject('GcCalendarEvents', $evid); header('Content-type: text/calendar; charset=utf-8'); header('Content-Disposition: attachment; filename=' . $event->get('title') . '.ics'); $output = 'BEGIN:VCALENDAR' . PHP_EOL; $output .= 'VERSION:2.0' . PHP_EOL; $output .= 'PRODID:-//gcCalendar//IdeaBank Marketing//EN_US' . PHP_EOL; $output .= 'METHOD:PUBLISH' . PHP_EOL; $output .= 'CALSCALE:GREGORIA' . PHP_EOL; foreach ($dateArr as $dArr) { $output .= 'BEGIN:VEVENT' . PHP_EOL; $output .= 'DTEND;TZID=America/Chicago:' . dateToCal($dArr->get('end')) . PHP_EOL; $output .= 'UID:' . $dArr->get('id') . PHP_EOL; $output .= 'DTSTAMP:' . dateToCal(time()) . PHP_EOL; $output .= 'LOCATION:' . $event->get('locationname') . ' ' . $event->get('locationaddr') . ' ' . $event->get('locationcity') . ', ' . $event->get('locationstate') . ' ' . $event->get('locationzip') . PHP_EOL; $output .= 'DESCRIPTION:' . strip_tags($event->get('notes')) . PHP_EOL; $output .= 'URL;VALUE=URI:' . $event->get('link') . PHP_EOL; $output .= 'SUMMARY:' . $event->get('title') . PHP_EOL; $output .= 'DTSTART;TZID=America/Chicago:' . dateToCal($dArr->get('start')) . PHP_EOL; $output .= 'END:VEVENT' . PHP_EOL; } $output .= 'END:VCALENDAR'; } else { echo "Please Enter a Valid ID"; }
LOCATION:<?php echo escapeString('Rift'); ?> ; CATEGORIES:<?php echo escapeString('Crimson Crusade Alliance - Raid'); ?> ; TRANSP:OPAQUE; SEQUENCE:0; UID:<?php echo uniqid(); ?> ; DTSTAMP:<?php echo dateToCal(time()); ?> ; DESCRIPTION:<?php echo escapeString($description); ?> ; PRIORITY:9; SUMMARY:<?php echo escapeString($summary); ?> ; DTSTART:<?php echo $datestart; ?> ;
function createVCard($events) { $v = "BEGIN:VCALENDAR\r\n"; $v .= "VERSION:2.0\r\n"; $v .= "PRODID:-//hacksw/handcal//NONSGML v1.0//EN\r\n"; $v .= "CALSCALE:GREGORIAN\r\n"; foreach ($events as $event) { $v .= "BEGIN:VEVENT\r\n"; $v .= "DTEND:" . dateToCal($event["ende"]) . "\r\n"; $v .= "UID:" . uniqid() . "\r\n"; $v .= "DTSTAMP:" . dateToCal(time()) . "\r\n"; $v .= "SUMMARY:" . escapeString($event["title"]) . "\r\n"; $v .= "DTSTART:" . dateToCal($event["start"]) . "\r\n"; $v .= "END:VEVENT\r\n"; } $v .= "END:VCALENDAR\r\n"; return $v; }
function dateToCal2($timestamp) { // Pour tenir compte du décalage horaire et de l'heure d'été $annee_courante = strftime("%Y", $timestamp); $mois_courant = strftime("%m", $timestamp); $jour_courant = strftime("%d", $timestamp); if ($mois_courant > 10 || $mois_courant < 3) { $decalage_horaire = 1 * 3600; } elseif ($mois_courant > 3 && $mois_courant < 10) { $decalage_horaire = 2 * 3600; } elseif ($mois_courant == 3) { if (!isset($num_dernier_dimanche[$annee_courante][$mois_courant])) { $num_dernier_dimanche[$annee_courante][$mois_courant] = get_dernier_dimanche_du_mois2($mois_courant, $annee_courante); } if ($jour_courant >= $num_dernier_dimanche[$annee_courante][$mois_courant]) { $decalage_horaire = 2 * 3600; } else { $decalage_horaire = 1 * 3600; } } elseif ($mois_courant == 10) { if (!isset($num_dernier_dimanche[$annee_courante][$mois_courant])) { $num_dernier_dimanche[$annee_courante][$mois_courant] = get_dernier_dimanche_du_mois2($mois_courant, $annee_courante); } if ($jour_courant >= $num_dernier_dimanche[$annee_courante][$mois_courant]) { $decalage_horaire = 1 * 3600; } else { $decalage_horaire = 2 * 3600; } } return dateToCal($timestamp - $decalage_horaire); }
<?php $dstart = $_GET['dstart']; $dend = $_GET['dend']; $dob = $_GET['dob']; $dod = $_GET['dod']; $dsum = $_GET['dsum']; $url = $_GET['url']; $country = $_GET['country']; $description = 'According to your birthday ' . $dob . ' and the life expectancy in ' . $country . ' you will die on ' . $dod . '. http://population.io'; function dateToCal($timestamp) { return date('Ymd', strtotime($timestamp)); } // Build the ics file $ical = 'BEGIN:VCALENDAR VERSION:2.0 BEGIN:VEVENT CLASS:PUBLIC DESCRIPTION:' . addslashes($description) . ' DTSTART;VALUE=DATE:' . dateToCal($dstart) . ' DTEND;VALUE=DATE:' . dateToCal($dend) . ' LOCATION: SUMMARY;LANGUAGE=en-us:' . addslashes($dsum) . ' TRANSP:TRANSP END:VEVENT END:VCALENDAR'; //set correct content-type-header header('Content-type: text/calendar; charset=utf-8'); header('Content-Disposition: attachment; filename=calendar.ics'); echo $ical;
} // 3. Echo out the ics file's contents ?> BEGIN:VCALENDAR PRODID:-//Events Calendar//iCal4j 1.0//EN VERSION:2.0 CALSCALE:GREGORIAN BEGIN:VEVENT DTSTART:<?php echo dateToCal($_POST['book_date_start']) . "\n"; ?> DTEND:<?php echo dateToCal($_POST['book_date_end']) . "\n"; ?> DTSTAMP:<?php echo dateToCal($_POST['current_time']) . "\n"; ?> UID:<?php echo uniqid() . "\n"; ?> LOCATION:<?php echo escapeString('Mumbai') . "\n"; ?> DESCRIPTION:<?php echo escapeString($_POST['book_name']) . "\n"; ?> SUMMARY:<?php echo escapeString($_POST['book_name']) . "\n"; ?> END:VEVENT END:VCALENDAR