27require_once DOL_DOCUMENT_ROOT.
'/core/lib/xcal.lib.php';
28require_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
41 public $freebusy_count;
67 if ($tmpresult[
'http_code'] != 200) {
69 $this->error =
'Error: '.$tmpresult[
'http_code'].
' '.$tmpresult[
'content'];
71 $file_text = preg_replace(
"/[\r\n]{1,} /",
"", $tmpresult[
'content']);
87 return $this->event_count;
99 return $this->todo_count;
110 public function parse($uri, $usecachefile =
'', $delaycache = 3600)
112 $this->cal = array();
114 $this->event_count = -1;
115 $this->file_text =
null;
119 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
123 if ($datefile && $datefile > ($now - $delaycache)) {
125 $this->file_text = file_get_contents($usecachefile);
130 if (is_null($this->file_text)) {
131 $this->file_text = $this->
read_file($uri);
133 if ($usecachefile && !is_null($this->file_text)) {
135 file_put_contents($usecachefile, $this->file_text, LOCK_EX);
140 $this->file_text = preg_split(
"[\n]", $this->file_text);
143 if (!stristr($this->file_text[0],
'BEGIN:VCALENDAR')) {
144 return 'error not VCALENDAR';
148 $tmpkey =
''; $tmpvalue =
''; $type =
'';
149 foreach ($this->file_text as $text) {
158 $this->todo_count = $this->todo_count + 1;
163 $this->event_count = $this->event_count + 1;
167 case "BEGIN:VFREEBUSY":
168 $this->freebusy_count = $this->freebusy_count + 1;
172 case "BEGIN:VCALENDAR":
173 case "BEGIN:DAYLIGHT":
174 case "BEGIN:VTIMEZONE":
175 case "BEGIN:STANDARD":
181 case "END:VFREEBUSY":
182 case "END:VCALENDAR":
184 case "END:VTIMEZONE":
200 if (!preg_match(
'/=$/', $text)) {
202 $value =
quotedPrintDecode(preg_replace(
'/^ENCODING=QUOTED-PRINTABLE:/i',
'', $tmpvalue));
206 } elseif (preg_match(
'/^ENCODING=QUOTED-PRINTABLE:/i', $value)) {
207 if (preg_match(
'/=$/', $value)) {
209 $tmpvalue = $tmpvalue.preg_replace(
'/=$/',
"", $value);
211 $value =
quotedPrintDecode(preg_replace(
'/^ENCODING=QUOTED-PRINTABLE:/i',
'', $tmpvalue.$value));
214 if (!$insidealarm && !$tmpkey) {
242 $key = $this->last_key;
245 $value = $this->cal[$type][$this->event_count][$key].$value;
248 $value = $this->cal[$type][$this->freebusy_count][$key].$value;
251 $value = $this->cal[$type][$this->todo_count][$key].$value;
256 if (($key ==
"DTSTAMP") || ($key ==
"LAST-MODIFIED") || ($key ==
"CREATED")) {
261 if (stristr($key,
"DTSTART") || stristr($key,
"DTEND") || stristr($key,
"DTSTART;VALUE=DATE") || stristr($key,
"DTEND;VALUE=DATE")) {
262 if (stristr($key,
"DTSTART;VALUE=DATE") || stristr($key,
"DTEND;VALUE=DATE")) {
263 list($key, $value) = array($key, $value);
271 $this->cal[$type][$this->todo_count][$key] = $value;
275 $this->cal[$type][$this->event_count][$key] = $value;
279 $this->cal[$type][$this->freebusy_count][$key] = $value;
283 $this->cal[$type][$key] = $value;
286 $this->last_key = $key;
311 return explode(
':', $text, 2);
325 $rrule = explode(
';', $value);
326 foreach ($rrule as $line) {
327 $rcontent = explode(
'=', $line);
328 $result[$rcontent[0]] = $rcontent[1];
343 $ical_date = str_replace(
'T',
'', $ical_date);
344 $ical_date = str_replace(
'Z',
'', $ical_date);
348 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)) {
349 $ntime =
dol_mktime($date[4], $date[5], $date[6], $date[2], $date[3], $date[1],
true);
368 $return_value = array();
372 $temp = explode(
";", $key);
374 if (empty($temp[1])) {
375 $value = str_replace(
'T',
'', $value);
376 return array($key, $value);
380 $temp = explode(
"=", $temp[1]);
381 $return_value[$temp[0]] = $temp[1];
382 $return_value[
'unixtime'] = $value;
384 return array($key, $return_value);
398 usort($temp, array(&$this,
"ical_dtstart_compare"));
416 return strnatcasecmp($a[
'DTSTART'][
'unixtime'], $b[
'DTSTART'][
'unixtime']);
428 return (empty($this->cal[
'VEVENT']) ? array() : $this->cal[
'VEVENT']);
440 return (empty($this->cal[
'VFREEBUSY']) ? array() : $this->cal[
'VFREEBUSY']);
452 return $this->cal[
'VTODO'];
464 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.