예제 #1
0
<?php

include_once 'functions.php';
$vevent = urldecode($_GET['vevent']);
$output = "BEGIN:VCALENDAR\r\n";
$output .= "PRODID: -//Google Inc//Google Calendar 70.9054//EN" . "\r\n";
$output .= "VERSION:2.0\r\n";
$output .= "METHOD:PUBLISH" . "\r\n";
$output .= $vevent;
$output .= "END:VCALENDAR\r\n";
// Get the event parameters
$entry = parse_vevent($vevent);
// Make a filename
$filename = 'iCalendar_';
if ($entry['allday']) {
    if ($entry['startdate'] != $entry['enddate']) {
        $filename .= $entry['startdate'] . '_' . $entry['enddate'];
    } else {
        $filename .= $entry['startdate'];
    }
} else {
    if ($entry['startdate'] != $entry['enddate']) {
        $filename .= $entry['startdate'] . $entry['starttime'] . '_' . $entry['enddate'] . $entry['endtime'];
    } else {
        $filename .= $entry['startdate'] . '_' . $entry['starttime'] . '_' . $entry['endtime'];
    }
}
$filename .= '.ics';
$filename = str_replace(":", "", $filename);
// Output the file
header('Content-Type: text/Calendar');
예제 #2
0
 /**
  * Load the iCalendar file from 'url' and parse all
  * events that are within the range
  * from <= eventdate <= from+previewSec
  *
  * @param url HTTP URL of an *.ics file
  * @param from unix timestamp in seconds (may be null)
  * @param to unix timestamp in seconds (may be null)
  * @param previewDays Limit the entries to 30 days in the future	 
  * @param numberOfEntries Number of entries to display
  * @param $sort_descending	 
  * @return an array of entries sorted by their startdate
  */
 function _parseIcs($url, $from, $to, $previewDays, $numberOfEntries, $sort_descending)
 {
     global $conf;
     $http = new DokuHTTPClient();
     if (!$http->get($url)) {
         $this->error = "Could not get '{$url}': " . $http->status;
         return array();
     }
     $content = $http->resp_body;
     $entries = array();
     # If dateformat is set in plugin configuration ('dformat'), then use it.
     # Otherwise fall back to dokuwiki's default dformat from the global /conf/dokuwiki.php.
     $dateFormat = $this->getConf('dformat') ? $this->getConf('dformat') : $conf['dformat'];
     //$timeFormat = $this->getConf('tformat') ? $this->getConf('tformat') : $conf['tformat'];
     # regular expressions for items that we want to extract from the iCalendar file
     $regex_vevent = '/BEGIN:VEVENT(.*?)END:VEVENT/s';
     #split the whole content into VEVENTs
     preg_match_all($regex_vevent, $content, $matches, PREG_PATTERN_ORDER);
     if ($previewDays > 0) {
         $previewSec = $previewDays * 24 * 3600;
     } else {
         $previewSec = -1;
     }
     // loop over VEVENTs and parse out some itmes
     foreach ($matches[1] as $vevent) {
         $entry = parse_vevent($vevent, $dateFormat);
         // if entry is to old then filter it
         if ($from && $entry['endunixdate']) {
             if ($entry['endunixdate'] < $from) {
                 continue;
             }
             if ($previewSec > 0 && $entry['startunixdate'] > time() + $previewSec) {
                 continue;
             }
         }
         // if entry is to new then filter it
         if ($to && $entry['startunixdate']) {
             if ($entry['startunixdate'] > $to) {
                 continue;
             }
         }
         $entries[] = $entry;
     }
     if ($to && $from == null) {
         // sort entries by startunixdate
         usort($entries, 'compareByEndUnixDate');
     } else {
         if ($from) {
             // sort entries by startunixdate
             usort($entries, 'compareByStartUnixDate');
         } else {
             if ($sort_descending) {
                 $entries = array_reverse($entries, true);
             }
         }
     }
     // See if a maximum number of entries was set
     if ($numberOfEntries > 0) {
         $entries = array_slice($entries, 0, $numberOfEntries);
         // Reverse array?
         if ($from && $sort_descending) {
             $entries = array_reverse($entries, true);
         } else {
             if ($to && !$from && !$sort_descending) {
                 $entries = array_reverse($entries, true);
             }
         }
     }
     return $entries;
 }