27require_once DOL_DOCUMENT_ROOT.
'/core/lib/xcal.lib.php';
28require_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
46 public $freebusy_count;
72 if ($tmpresult[
'http_code'] != 200) {
74 $this->error =
'Error: '.$tmpresult[
'http_code'].
' '.$tmpresult[
'content'];
76 $file_text = preg_replace(
"/[\r\n]{1,} /",
"", $tmpresult[
'content']);
92 return $this->event_count;
104 return $this->todo_count;
115 public function parse($uri, $usecachefile =
'', $delaycache = 3600)
117 $this->cal = array();
119 $this->event_count = -1;
120 $this->file_text =
null;
124 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
128 if ($datefile && $datefile > ($now - $delaycache)) {
130 $this->file_text = file_get_contents($usecachefile);
135 if (is_null($this->file_text)) {
136 $this->file_text = $this->
read_file($uri);
138 if ($usecachefile && !is_null($this->file_text)) {
140 file_put_contents($usecachefile, $this->file_text, LOCK_EX);
145 $this->file_text = preg_split(
"[\n]", $this->file_text);
148 if (!stristr($this->file_text[0],
'BEGIN:VCALENDAR')) {
149 return 'error not VCALENDAR';
156 foreach ($this->file_text as $text) {
165 $this->todo_count = $this->todo_count + 1;
170 $this->event_count = $this->event_count + 1;
174 case "BEGIN:VFREEBUSY":
175 $this->freebusy_count = $this->freebusy_count + 1;
179 case "BEGIN:VCALENDAR":
180 case "BEGIN:DAYLIGHT":
181 case "BEGIN:VTIMEZONE":
182 case "BEGIN:STANDARD":
188 case "END:VFREEBUSY":
189 case "END:VCALENDAR":
191 case "END:VTIMEZONE":
207 if (!preg_match(
'/=$/', $text)) {
209 $value =
quotedPrintDecode(preg_replace(
'/^ENCODING=QUOTED-PRINTABLE:/i',
'', $tmpvalue));
213 } elseif (preg_match(
'/^ENCODING=QUOTED-PRINTABLE:/i', $value)) {
214 if (preg_match(
'/=$/', $value)) {
216 $tmpvalue = $tmpvalue.preg_replace(
'/=$/',
"", $value);
218 $value =
quotedPrintDecode(preg_replace(
'/^ENCODING=QUOTED-PRINTABLE:/i',
'', $tmpvalue.$value));
221 if (!$insidealarm && !$tmpkey) {
249 $key = $this->last_key;
252 $value = $this->cal[$type][$this->event_count][$key].$value;
255 $value = $this->cal[$type][$this->freebusy_count][$key].$value;
258 $value = $this->cal[$type][$this->todo_count][$key].$value;
263 if (($key ==
"DTSTAMP") || ($key ==
"LAST-MODIFIED") || ($key ==
"CREATED")) {
268 if (stristr($key,
"DTSTART") || stristr($key,
"DTEND") || stristr($key,
"DTSTART;VALUE=DATE") || stristr($key,
"DTEND;VALUE=DATE")) {
269 if (stristr($key,
"DTSTART;VALUE=DATE") || stristr($key,
"DTEND;VALUE=DATE")) {
270 list($key, $value) = array($key, $value);
278 $this->cal[$type][$this->todo_count][$key] = $value;
282 $this->cal[$type][$this->event_count][$key] = $value;
286 $this->cal[$type][$this->freebusy_count][$key] = $value;
290 $this->cal[$type][$key] = $value;
293 $this->last_key = $key;
318 return explode(
':', $text, 2);
332 $rrule = explode(
';', $value);
333 foreach ($rrule as $line) {
334 $rcontent = explode(
'=', $line);
335 $result[$rcontent[0]] = $rcontent[1];
350 $ical_date = str_replace(
'T',
'', $ical_date);
351 $ical_date = str_replace(
'Z',
'', $ical_date);
355 if (preg_match(
'/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{0,2})([0-9]{0,2})([0-9]{0,2})/', $ical_date, $date)) {
356 $ntime =
dol_mktime($date[4], $date[5], $date[6], $date[2], $date[3], $date[1],
true);
375 $return_value = array();
379 $temp = explode(
";", $key);
381 if (empty($temp[1])) {
382 $value = str_replace(
'T',
'', $value);
383 return array($key, $value);
387 $temp = explode(
"=", $temp[1]);
388 $return_value[$temp[0]] = $temp[1];
389 $return_value[
'unixtime'] = $value;
391 return array($key, $return_value);
405 usort($temp, array(&$this,
"ical_dtstart_compare"));
423 return strnatcasecmp($a[
'DTSTART'][
'unixtime'], $b[
'DTSTART'][
'unixtime']);
435 return (empty($this->cal[
'VEVENT']) ? array() : $this->cal[
'VEVENT']);
447 return (empty($this->cal[
'VFREEBUSY']) ? array() : $this->cal[
'VFREEBUSY']);
459 return $this->cal[
'VTODO'];
471 return $this->cal[
'VCALENDAR'];
Class to read/parse ICal calendars.
get_all_data()
Return array with all data.
get_event_list()
Return eventlist array (not sorted eventlist array)
parse($uri, $usecachefile='', $delaycache=3600)
Translate Calendar.
ical_dt_date($key, $value)
Return unix date from iCal date format.
ical_rrule($value)
Parse RRULE return array.
retun_key_value($text)
Parse text "XXXX:value text some with : " and return array($key = "XXXX", $value="value");.
get_todo_count()
Returns the number of to do.
ical_dtstart_compare($a, $b)
Compare two unix timestamp.
get_event_count()
Returns the number of calendar events.
__construct()
Constructor.
add_to_array($type, $key, $value)
Add to $this->ical array one value and key.
read_file($file)
Read text file, icalender text file.
get_sort_event_list()
Return sorted eventlist as array or false if calendar is empty.
get_freebusy_list()
Return freebusy array (not sort eventlist array)
get_todo_list()
Return to do array (not sorted todo array)
get_calender_data()
Return base calendar data.
ical_date_to_unix($ical_date)
Return Unix time from ical date time fomrat (YYYYMMDD[T]HHMMSS[Z] or YYYYMMDD[T]HHMMSS)
dol_filemtime($pathoffile)
Return time of a file.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dolChmod($filepath, $newmask='')
Change mod of a file.
dol_now($mode='auto')
Return date for now.
getURLContent($url, $postorget='GET', $param='', $followlocation=1, $addheaders=array(), $allowedschemes=array('http', 'https'), $localurl=0, $ssl_verifypeer=-1)
Function to get a content from an URL (use proxy if proxy defined).
quotedPrintDecode($str)
Decode vcal format.