35 function build_calfile($format, $title, $desc, $events_array, $outputfile)
39 dol_syslog(
"xcal.lib.php::build_calfile Build cal file ".$outputfile.
" to format ".$format);
41 if (empty($outputfile))
48 $calfileh = fopen($outputfile,
"w");
52 include_once DOL_DOCUMENT_ROOT.
"/core/lib/date.lib.php";
57 if ($format ===
"vcal")
59 $encoding =
"ENCODING=QUOTED-PRINTABLE:";
63 fwrite($calfileh,
"BEGIN:VCALENDAR\n");
66 fwrite($calfileh,
"VERSION:2.0\n");
68 fwrite($calfileh,
"METHOD:PUBLISH\n");
69 fwrite($calfileh,
"PRODID:-//DOLIBARR ".DOL_VERSION.
"\n");
70 fwrite($calfileh,
"CALSCALE:GREGORIAN\n");
71 fwrite($calfileh,
"X-WR-CALNAME:".$encoding.format_cal($format, $title).
"\n");
72 fwrite($calfileh,
"X-WR-CALDESC:".$encoding.format_cal($format, $desc).
"\n");
75 if (!empty($conf->global->MAIN_AGENDA_EXPORT_CACHE) && $conf->global->MAIN_AGENDA_EXPORT_CACHE > 60)
81 fwrite($calfileh,
"X-PUBLISHED-TTL: P".$hh.
"H".$mm.
"M".$ss.
"S\n");
84 foreach ($events_array as $key => $event)
92 $type = $event[
"type"];
93 $startdate = $event[
"startdate"];
94 $duration = $event[
"duration"];
95 $enddate = $event[
"enddate"];
96 $summary = $event[
"summary"];
97 $category = $event[
"category"];
98 $priority = $event[
"priority"];
99 $fulldayevent = $event[
"fulldayevent"];
100 $location = $event[
"location"];
101 $email = $event[
"email"];
102 $url = $event[
"url"];
103 $transparency = $event[
"transparency"];
105 $created = $event[
"created"];
106 $modified = $event[
"modified"];
107 $assignedUsers = $event[
"assignedUsers"];
111 $description =
format_cal($format, $description);
150 if ($type ===
"event")
152 fwrite($calfileh,
"BEGIN:VEVENT\n");
153 fwrite($calfileh,
"UID:".$uid.
"\n");
157 fwrite($calfileh,
"ORGANIZER:MAILTO:".$email.
"\n");
158 fwrite($calfileh,
"CONTACT:MAILTO:".$email.
"\n");
163 fwrite($calfileh,
"URL:".$url.
"\n");
166 if (is_array($assignedUsers))
168 foreach ($assignedUsers as $assignedUser)
170 if ($assignedUser->email === $email)
175 fwrite($calfileh,
"ATTENDEE;RSVP=TRUE:mailto:".$assignedUser->email.
"\n");
181 fwrite($calfileh,
"CREATED:".
dol_print_date($created,
"dayhourxcard",
true).
"\n");
186 fwrite($calfileh,
"LAST-MODIFIED:".
dol_print_date($modified,
"dayhourxcard",
true).
"\n");
189 fwrite($calfileh,
"SUMMARY:".$encoding.$summary.
"\n");
190 fwrite($calfileh,
"DESCRIPTION:".$encoding.$description.
"\n");
192 if (!empty($location))
194 fwrite($calfileh,
"LOCATION:".$encoding.$location.
"\n");
199 fwrite($calfileh,
"X-FUNAMBOL-ALLDAY:1\n");
205 fwrite($calfileh,
"X-MICROSOFT-CDO-ALLDAYEVENT:TRUE\n");
210 fwrite($calfileh,
"DTSTAMP:".
dol_print_date($now,
"dayhourxcard",
true).
"\n");
219 $prefix =
";VALUE=DATE";
223 fwrite($calfileh,
"DTSTART".$prefix.
":".$startdatef.
"\n");
235 $enddate = $startdate + $duration;
244 $prefix =
";VALUE=DATE";
251 fwrite($calfileh,
"DTEND".$prefix.
":".$enddatef.
"\n");
252 fwrite($calfileh,
"STATUS:CONFIRMED\n");
254 if (!empty($transparency))
256 fwrite($calfileh,
"TRANSP:".$transparency.
"\n");
259 if (!empty($category))
261 fwrite($calfileh,
"CATEGORIES:".$encoding.$category.
"\n");
264 fwrite($calfileh,
"END:VEVENT\n");
268 if ($type ===
"journal")
270 fwrite($calfileh,
"BEGIN:VJOURNAL\n");
271 fwrite($calfileh,
"UID:".$uid.
"\n");
275 fwrite($calfileh,
"ORGANIZER:MAILTO:".$email.
"\n");
276 fwrite($calfileh,
"CONTACT:MAILTO:".$email.
"\n");
281 fwrite($calfileh,
"URL:".$url.
"\n");
286 fwrite($calfileh,
"CREATED:".
dol_print_date($created,
"dayhourxcard",
true).
"\n");
291 fwrite($calfileh,
"LAST-MODIFIED:".
dol_print_date($modified,
"dayhourxcard",
true).
"\n");
294 fwrite($calfileh,
"SUMMARY:".$encoding.$summary.
"\n");
295 fwrite($calfileh,
"DESCRIPTION:".$encoding.$description.
"\n");
296 fwrite($calfileh,
"STATUS:CONFIRMED\n");
297 fwrite($calfileh,
"CATEGORIES:".$category.
"\n");
298 fwrite($calfileh,
"LOCATION:".$location.
"\n");
299 fwrite($calfileh,
"TRANSP:OPAQUE\n");
300 fwrite($calfileh,
"CLASS:CONFIDENTIAL\n");
301 fwrite($calfileh,
"DTSTAMP:".
dol_print_date($startdatef,
"dayhourxcard",
true).
"\n");
303 fwrite($calfileh,
"END:VJOURNAL\n");
308 fwrite($calfileh,
"END:VCALENDAR");
312 if (!empty($conf->global->MAIN_UMASK))
314 @chmod($outputfile, octdec($conf->global->MAIN_UMASK));
317 dol_syslog(
"xcal.lib.php::build_calfile Failed to open file ".$outputfile.
" for writing");
336 function build_rssfile($format, $title, $desc, $events_array, $outputfile, $filter =
'', $url =
'', $langcode =
'')
338 global $user, $conf, $langs;
339 global $dolibarr_main_url_root;
341 dol_syslog(
"xcal.lib.php::build_rssfile Build rss file ".$outputfile.
" to format ".$format);
343 if (empty($outputfile))
349 $fichier = fopen($outputfile,
"w");
356 fwrite($fichier,
'<?xml version="1.0" encoding="'.$langs->charset_output.
'"?>');
357 fwrite($fichier,
"\n");
359 fwrite($fichier,
'<rss version="2.0">');
360 fwrite($fichier,
"\n");
362 fwrite($fichier,
"<channel>\n");
363 fwrite($fichier,
"<title>".$title.
"</title>\n");
364 if ($langcode) fwrite($fichier,
"<language>".$langcode.
"</language>\n");
376 $urlwithouturlroot = preg_replace(
"/".preg_quote(DOL_URL_ROOT,
"/").
"$/i",
"", trim($dolibarr_main_url_root));
377 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
380 $url = $urlwithroot.
"/public/agenda/agendaexport.php?format=rss&exportkey=".urlencode($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY);
383 fwrite($fichier,
"<link><![CDATA[".$url.
"]]></link>\n");
385 foreach ($events_array as $key => $event)
387 $eventqualified =
true;
393 $eventqualified =
false;
398 if (is_object($event) && get_class($event) ==
'WebsitePage') {
401 $tmpevent[
'uid'] = $event->id;
402 $tmpevent[
'startdate'] = $event->date_creation;
403 $tmpevent[
'summary'] = $event->title;
404 $tmpevent[
'url'] = $event->fullpageurl ? $event->fullpageurl : $event->pageurl.
'.php';
405 $tmpevent[
'author'] = $event->author_alias ? $event->author_alias :
'unknown';
407 $tmpevent[
'desc'] = $event->description;
412 $uid = $event[
"uid"];
413 $startdate = $event[
"startdate"];
414 $summary = $event[
"summary"];
415 $url = $event[
"url"];
416 $author = $event[
"author"];
417 $category = $event[
"category"];
428 fwrite($fichier,
"<item>\n");
429 fwrite($fichier,
"<title><![CDATA[".$summary.
"]]></title>\n");
430 fwrite($fichier,
"<link><![CDATA[".$url.
"]]></link>\n");
431 fwrite($fichier,
"<author><![CDATA[".$author.
"]]></author>\n");
432 fwrite($fichier,
"<category><![CDATA[".$category.
"]]></category>\n");
433 fwrite($fichier,
"<description><![CDATA[");
436 fwrite($fichier, $description);
440 fwrite($fichier,
"]]></description>\n");
441 fwrite($fichier,
"<pubDate>".date(
"r", $startdate).
"</pubDate>\n");
442 fwrite($fichier,
"<guid isPermaLink=\"true\"><![CDATA[".$uid.
"]]></guid>\n");
443 fwrite($fichier,
"<source><![CDATA[Dolibarr]]></source>\n");
444 fwrite($fichier,
"</item>\n");
448 fwrite($fichier,
"</channel>");
449 fwrite($fichier,
"\n");
450 fwrite($fichier,
"</rss>");
454 if (!empty($conf->global->MAIN_UMASK))
456 @chmod($outputfile, octdec($conf->global->MAIN_UMASK));
472 $newstring = $string;
474 if ($format ===
"vcal")
479 if ($format ===
"ical")
482 $newstring = preg_replace(
"/\r\n/i",
"\\n", $newstring);
483 $newstring = preg_replace(
"/\n\r/i",
"\\n", $newstring);
484 $newstring = preg_replace(
"/\n/i",
"\\n", $newstring);
506 if (function_exists(
"mb_strlen"))
508 $strlength = mb_strlen($line,
"UTF-8");
510 for ($j = 0; $j < $strlength; $j++)
513 $char = mb_substr($line, $j, 1,
"UTF-8");
515 if ((mb_strlen($newpara,
"UTF-8") + mb_strlen($char,
"UTF-8")) >= 75)
518 $out .= $newpara.
"\r\n ";
530 for ($j = 0; $j < $strlength; $j++)
533 $char = substr($line, $j, 1);
538 $out .= $newpara.
"\r\n ";
562 $lines = preg_split(
"/\r\n/", $str);
565 foreach ($lines as $line)
570 $strlength = strlen($line);
572 for ($j = 0; $j < $strlength; $j++)
574 $char = substr($line, $j, 1);
577 if ($ascii < 32 || $ascii === 61 || $ascii > 126)
579 $char =
"=".strtoupper(sprintf(
"%02X", $ascii));
583 if ((strlen($newpara) + strlen($char)) >= 76)
586 $out .= $newpara.
"=\r\n";
611 return trim(quoted_printable_decode(preg_replace(
"/=\r?\n/",
"", $str)));
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto= 'UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
quotedPrintEncode($str, $forcal=0)
Encode into vcal format.
dol_now($mode= 'auto')
Return date for now.
build_calfile($format, $title, $desc, $events_array, $outputfile)
Build a file from an array of events All input params and data must be encoded in $conf->charset_outp...
quotedPrintDecode($str)
Decode vcal format.
build_rssfile($format, $title, $desc, $events_array, $outputfile, $filter= '', $url= '', $langcode= '')
Build a file from an array of events.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
calEncode($line)
Cut string after 75 chars.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
format_cal($format, $string)
Encode for cal export.
dol_time_plus_duree($time, $duration_value, $duration_unit)
Add a delay to a date.
convertSecondToTime($iSecond, $format= 'all', $lengthOfDay=86400, $lengthOfWeek=7)
Return, in clear text, value of a number of seconds in days, hours and minutes.