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 = $this->todo_count + 1;
198 $this->event_count = $this->event_count + 1;
202 case "BEGIN:VFREEBUSY":
203 $this->freebusy_count = $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 = $tmpvalue.preg_replace(
'/=$/',
"", $value);
246 $value =
quotedPrintDecode(preg_replace(
'/^ENCODING=QUOTED-PRINTABLE:/i',
'', $tmpvalue.$value));
249 if (!$insidealarm && !$tmpkey) {
277 $key = $this->last_key;
280 $value = $this->cal[$type][$this->event_count][$key].$value;
283 $value = $this->cal[$type][$this->freebusy_count][$key].$value;
286 $value = $this->cal[$type][$this->todo_count][$key].$value;
291 if (($key ==
"DTSTAMP") || ($key ==
"LAST-MODIFIED") || ($key ==
"CREATED")) {
296 if (stristr($key,
"DTSTART") || stristr($key,
"DTEND") || stristr($key,
"DTSTART;VALUE=DATE") || stristr($key,
"DTEND;VALUE=DATE")) {
297 if (stristr($key,
"DTSTART;VALUE=DATE") || stristr($key,
"DTEND;VALUE=DATE")) {
298 list($key, $value) = array($key, $value);
306 $this->cal[$type][$this->todo_count][$key] = $value;
310 $this->cal[$type][$this->event_count][$key] = $value;
314 $this->cal[$type][$this->freebusy_count][$key] = $value;
318 $this->cal[$type][$key] = $value;
321 $this->last_key = $key;
346 return explode(
':', $text, 2);
360 $rrule = explode(
';', $value);
361 foreach ($rrule as $line) {
362 $rcontent = explode(
'=', $line);
363 $result[$rcontent[0]] = $rcontent[1];
378 $ical_date = str_replace(
'T',
'', $ical_date);
379 $ical_date = str_replace(
'Z',
'', $ical_date);
384 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)) {
385 $ntime =
dol_mktime($date[4], $date[5], $date[6], $date[2], $date[3], $date[1],
true);
404 $return_value = array();
407 $temp = explode(
";", $key);
409 if (empty($temp[1])) {
411 return array($key, $value);
414 $value = str_replace(
'T',
'', $value);
417 $temp = explode(
"=", $temp[1]);
418 $return_value[$temp[0]] = $temp[1];
419 $return_value[
'unixtime'] = $value;
421 return array($key, $return_value);
435 usort($temp, array(&$this,
"ical_dtstart_compare"));
453 return strnatcasecmp($a[
'DTSTART'][
'unixtime'], $b[
'DTSTART'][
'unixtime']);
465 return (empty($this->cal[
'VEVENT']) ? array() : $this->cal[
'VEVENT']);
477 return (empty($this->cal[
'VFREEBUSY']) ? array() : $this->cal[
'VFREEBUSY']);
489 return $this->cal[
'VTODO'];
501 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.