29require_once DOL_DOCUMENT_ROOT.
'/core/lib/xcal.lib.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
66 public $freebusy_count;
109 $tmpresult =
getURLContent($file,
'GET',
'', 1, [], [
'http',
'https'], $localip, $sslverify);
110 if ($tmpresult[
'http_code'] != 200) {
112 $this->error =
'Error: '.$tmpresult[
'http_code'].
' '.$tmpresult[
'content'];
114 $file_text = preg_replace(
"/[\r\n]{1,} /",
"", $tmpresult[
'content']);
130 return $this->event_count;
142 return $this->todo_count;
153 public function parse($uri, $usecachefile =
'', $delaycache = 3600)
155 $this->cal = array();
157 $this->event_count = -1;
158 $this->file_text =
'';
162 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
166 if ($datefile && $datefile > ($now - $delaycache)) {
168 $this->file_text = file_get_contents($usecachefile);
173 if (empty($this->file_text)) {
174 $this->file_text = $this->
read_file($uri);
176 if ($usecachefile && !is_null($this->file_text)) {
178 file_put_contents($usecachefile, $this->file_text, LOCK_EX);
183 $file_text_array = preg_split(
"[\n]", $this->file_text);
186 if (!stristr($file_text_array[0],
'BEGIN:VCALENDAR')) {
187 return 'error not VCALENDAR';
194 foreach ($file_text_array as $text) {
203 $this->todo_count += 1;
208 $this->event_count += 1;
212 case "BEGIN:VFREEBUSY":
213 $this->freebusy_count += 1;
217 case "BEGIN:VCALENDAR":
218 case "BEGIN:DAYLIGHT":
219 case "BEGIN:VTIMEZONE":
220 case "BEGIN:STANDARD":
226 case "END:VFREEBUSY":
227 case "END:VCALENDAR":
229 case "END:VTIMEZONE":
245 if (!preg_match(
'/=$/', $text)) {
247 $value =
quotedPrintDecode(preg_replace(
'/^ENCODING=QUOTED-PRINTABLE:/i',
'', $tmpvalue));
251 } elseif (preg_match(
'/^ENCODING=QUOTED-PRINTABLE:/i', $value)) {
252 if (preg_match(
'/=$/', $value)) {
254 $tmpvalue .= preg_replace(
'/=$/',
"", $value);
256 $value =
quotedPrintDecode(preg_replace(
'/^ENCODING=QUOTED-PRINTABLE:/i',
'', $tmpvalue.$value));
259 if (!$insidealarm && !$tmpkey) {
287 $key = $this->last_key;
291 $value = $this->cal[$type][$this->event_count][$key].$value;
295 $value = $this->cal[$type][$this->freebusy_count][$key].$value;
299 $value = $this->cal[$type][$this->todo_count][$key].$value;
304 if (($key ==
"DTSTAMP") || ($key ==
"LAST-MODIFIED") || ($key ==
"CREATED")) {
309 if (stristr($key,
"DTSTART") || stristr($key,
"DTEND") || stristr($key,
"DTSTART;VALUE=DATE") || stristr($key,
"DTEND;VALUE=DATE")) {
310 if (stristr($key,
"DTSTART;VALUE=DATE") || stristr($key,
"DTEND;VALUE=DATE")) {
311 list($key, $value) = array($key, $value);
320 $this->cal[$type][$this->todo_count][$key] = $value;
325 $this->cal[$type][$this->event_count][$key] = $value;
330 $this->cal[$type][$this->freebusy_count][$key] = $value;
335 $this->cal[$type][$key] = $value;
338 $this->last_key = $key;
363 return explode(
':', $text, 2);
377 $rrule = explode(
';', $value);
378 foreach ($rrule as $line) {
379 $rcontent = explode(
'=', $line);
380 $result[$rcontent[0]] = $rcontent[1];
395 $ical_date = str_replace(
'T',
'', $ical_date);
396 $ical_date = str_replace(
'Z',
'', $ical_date);
401 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)) {
402 $ntime =
dol_mktime((
int) $date[4], (
int) $date[5], (
int) $date[6], (
int) $date[2], (
int) $date[3], (
int) $date[1],
true);
421 $return_value = array();
424 $temp = explode(
";", $key);
426 if (empty($temp[1])) {
428 return array($key, $value);
431 $value = str_replace(
'T',
'', $value);
434 $temp = explode(
"=", $temp[1]);
435 $return_value[$temp[0]] = $temp[1];
436 $return_value[
'unixtime'] = $value;
438 return array($key, $return_value);
452 usort($temp, array($this,
"ical_dtstart_compare"));
470 return strnatcasecmp($a[
'DTSTART'][
'unixtime'], $b[
'DTSTART'][
'unixtime']);
482 return (empty($this->cal[
'VEVENT']) ? array() : $this->cal[
'VEVENT']);
494 return (empty($this->cal[
'VFREEBUSY']) ? array() : $this->cal[
'VFREEBUSY']);
506 return $this->cal[
'VTODO'];
518 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_now($mode='gmt')
Return date for now.
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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
getURLContent($url, $postorget='GET', $param='', $followlocation=1, $addheaders=array(), $allowedschemes=array('http', 'https'), $localurl=0, $ssl_verifypeer=-1, $timeoutconnect=0, $timeoutresponse=0, $otherCurlOptions=array())
Function to get a content from an URL (use proxy if proxy defined).
quotedPrintDecode($str)
Decode vcal format.