27 require_once DOL_DOCUMENT_ROOT.
'/core/lib/xcal.lib.php';
28 require_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 $this->cal = array();
112 $this->event_count = -1;
115 $this->file_text = $this->
read_file($uri);
117 $this->file_text = preg_split(
"[\n]", $this->file_text);
120 if (!stristr($this->file_text[0],
'BEGIN:VCALENDAR')) {
121 return 'error not VCALENDAR';
125 $tmpkey =
''; $tmpvalue =
''; $type =
'';
126 foreach ($this->file_text as $text) {
135 $this->todo_count = $this->todo_count + 1;
140 $this->event_count = $this->event_count + 1;
144 case "BEGIN:VFREEBUSY":
145 $this->freebusy_count = $this->freebusy_count + 1;
149 case "BEGIN:VCALENDAR":
150 case "BEGIN:DAYLIGHT":
151 case "BEGIN:VTIMEZONE":
152 case "BEGIN:STANDARD":
158 case "END:VFREEBUSY":
159 case "END:VCALENDAR":
161 case "END:VTIMEZONE":
177 if (!preg_match(
'/=$/', $text)) {
179 $value =
quotedPrintDecode(preg_replace(
'/^ENCODING=QUOTED-PRINTABLE:/i',
'', $tmpvalue));
183 } elseif (preg_match(
'/^ENCODING=QUOTED-PRINTABLE:/i', $value)) {
184 if (preg_match(
'/=$/', $value)) {
186 $tmpvalue = $tmpvalue.preg_replace(
'/=$/',
"", $value);
188 $value =
quotedPrintDecode(preg_replace(
'/^ENCODING=QUOTED-PRINTABLE:/i',
'', $tmpvalue.$value));
191 if (!$insidealarm && !$tmpkey) {
219 $key = $this->last_key;
222 $value = $this->cal[$type][$this->event_count][$key].$value;
225 $value = $this->cal[$type][$this->freebusy_count][$key].$value;
228 $value = $this->cal[$type][$this->todo_count][$key].$value;
233 if (($key ==
"DTSTAMP") || ($key ==
"LAST-MODIFIED") || ($key ==
"CREATED")) {
238 if (stristr($key,
"DTSTART") || stristr($key,
"DTEND") || stristr($key,
"DTSTART;VALUE=DATE") || stristr($key,
"DTEND;VALUE=DATE")) {
239 if (stristr($key,
"DTSTART;VALUE=DATE") || stristr($key,
"DTEND;VALUE=DATE")) {
240 list($key, $value) = array($key, $value);
248 $this->cal[$type][$this->todo_count][$key] = $value;
252 $this->cal[$type][$this->event_count][$key] = $value;
256 $this->cal[$type][$this->freebusy_count][$key] = $value;
260 $this->cal[$type][$key] = $value;
263 $this->last_key = $key;
288 return explode(
':', $text, 2);
302 $rrule = explode(
';', $value);
303 foreach ($rrule as $line) {
304 $rcontent = explode(
'=', $line);
305 $result[$rcontent[0]] = $rcontent[1];
320 $ical_date = str_replace(
'T',
'', $ical_date);
321 $ical_date = str_replace(
'Z',
'', $ical_date);
325 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)) {
326 $ntime =
dol_mktime($date[4], $date[5], $date[6], $date[2], $date[3], $date[1],
true);
345 $return_value = array();
349 $temp = explode(
";", $key);
351 if (empty($temp[1])) {
352 $value = str_replace(
'T',
'', $value);
353 return array($key, $value);
357 $temp = explode(
"=", $temp[1]);
358 $return_value[$temp[0]] = $temp[1];
359 $return_value[
'unixtime'] = $value;
361 return array($key, $return_value);
375 usort($temp, array(&$this,
"ical_dtstart_compare"));
393 return strnatcasecmp($a[
'DTSTART'][
'unixtime'], $b[
'DTSTART'][
'unixtime']);
405 return (empty($this->cal[
'VEVENT']) ? array() : $this->cal[
'VEVENT']);
417 return (empty($this->cal[
'VFREEBUSY']) ? array() : $this->cal[
'VFREEBUSY']);
429 return $this->cal[
'VTODO'];
441 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)
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.
parse($uri)
Translate Calendar.
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_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...
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.