28require_once DOL_DOCUMENT_ROOT.
'/core/lib/xcal.lib.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
65 public $freebusy_count;
100 if ($tmpresult[
'http_code'] != 200) {
102 $this->error =
'Error: '.$tmpresult[
'http_code'].
' '.$tmpresult[
'content'];
104 $file_text = preg_replace(
"/[\r\n]{1,} /",
"", $tmpresult[
'content']);
120 return $this->event_count;
132 return $this->todo_count;
143 public function parse($uri, $usecachefile =
'', $delaycache = 3600)
145 $this->cal = array();
147 $this->event_count = -1;
148 $this->file_text =
'';
152 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
156 if ($datefile && $datefile > ($now - $delaycache)) {
158 $this->file_text = file_get_contents($usecachefile);
163 if (empty($this->file_text)) {
164 $this->file_text = $this->
read_file($uri);
166 if ($usecachefile && !is_null($this->file_text)) {
168 file_put_contents($usecachefile, $this->file_text, LOCK_EX);
173 $file_text_array = preg_split(
"[\n]", $this->file_text);
176 if (!stristr($file_text_array[0],
'BEGIN:VCALENDAR')) {
177 return 'error not VCALENDAR';
184 foreach ($file_text_array as $text) {
193 $this->todo_count += 1;
198 $this->event_count += 1;
202 case "BEGIN:VFREEBUSY":
203 $this->freebusy_count += 1;
207 case "BEGIN:VCALENDAR":
208 case "BEGIN:DAYLIGHT":
209 case "BEGIN:VTIMEZONE":
210 case "BEGIN:STANDARD":
216 case "END:VFREEBUSY":
217 case "END:VCALENDAR":
219 case "END:VTIMEZONE":
235 if (!preg_match(
'/=$/', $text)) {
237 $value =
quotedPrintDecode(preg_replace(
'/^ENCODING=QUOTED-PRINTABLE:/i',
'', $tmpvalue));
241 } elseif (preg_match(
'/^ENCODING=QUOTED-PRINTABLE:/i', $value)) {
242 if (preg_match(
'/=$/', $value)) {
244 $tmpvalue .= preg_replace(
'/=$/',
"", $value);
246 $value =
quotedPrintDecode(preg_replace(
'/^ENCODING=QUOTED-PRINTABLE:/i',
'', $tmpvalue.$value));
249 if (!$insidealarm && !$tmpkey) {
277 $key = $this->last_key;
281 $value = $this->cal[$type][$this->event_count][$key].$value;
285 $value = $this->cal[$type][$this->freebusy_count][$key].$value;
289 $value = $this->cal[$type][$this->todo_count][$key].$value;
294 if (($key ==
"DTSTAMP") || ($key ==
"LAST-MODIFIED") || ($key ==
"CREATED")) {
299 if (stristr($key,
"DTSTART") || stristr($key,
"DTEND") || stristr($key,
"DTSTART;VALUE=DATE") || stristr($key,
"DTEND;VALUE=DATE")) {
300 if (stristr($key,
"DTSTART;VALUE=DATE") || stristr($key,
"DTEND;VALUE=DATE")) {
301 list($key, $value) = array($key, $value);
310 $this->cal[$type][$this->todo_count][$key] = $value;
315 $this->cal[$type][$this->event_count][$key] = $value;
320 $this->cal[$type][$this->freebusy_count][$key] = $value;
325 $this->cal[$type][$key] = $value;
328 $this->last_key = $key;
353 return explode(
':', $text, 2);
367 $rrule = explode(
';', $value);
368 foreach ($rrule as $line) {
369 $rcontent = explode(
'=', $line);
370 $result[$rcontent[0]] = $rcontent[1];
385 $ical_date = str_replace(
'T',
'', $ical_date);
386 $ical_date = str_replace(
'Z',
'', $ical_date);
391 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)) {
392 $ntime =
dol_mktime((
int) $date[4], (
int) $date[5], (
int) $date[6], (
int) $date[2], (
int) $date[3], (
int) $date[1],
true);
411 $return_value = array();
414 $temp = explode(
";", $key);
416 if (empty($temp[1])) {
418 return array($key, $value);
421 $value = str_replace(
'T',
'', $value);
424 $temp = explode(
"=", $temp[1]);
425 $return_value[$temp[0]] = $temp[1];
426 $return_value[
'unixtime'] = $value;
428 return array($key, $return_value);
442 usort($temp, array($this,
"ical_dtstart_compare"));
460 return strnatcasecmp($a[
'DTSTART'][
'unixtime'], $b[
'DTSTART'][
'unixtime']);
472 return (empty($this->cal[
'VEVENT']) ? array() : $this->cal[
'VEVENT']);
484 return (empty($this->cal[
'VFREEBUSY']) ? array() : $this->cal[
'VFREEBUSY']);
496 return $this->cal[
'VTODO'];
508 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 format (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 information (by default a local PHP server timestamp) Rep...
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.