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)) {
47 $calfileh = fopen($outputfile,
"w");
50 include_once DOL_DOCUMENT_ROOT.
"/core/lib/date.lib.php";
55 if ($format ===
"vcal") {
56 $encoding =
"ENCODING=QUOTED-PRINTABLE:";
60 fwrite($calfileh,
"BEGIN:VCALENDAR\n");
63 fwrite($calfileh,
"VERSION:2.0\n");
65 fwrite($calfileh,
"METHOD:PUBLISH\n");
66 fwrite($calfileh,
"PRODID:-//DOLIBARR ".DOL_VERSION.
"\n");
67 fwrite($calfileh,
"CALSCALE:GREGORIAN\n");
68 fwrite($calfileh,
"X-WR-CALNAME:".$encoding.format_cal($format, $title).
"\n");
69 fwrite($calfileh,
"X-WR-CALDESC:".$encoding.format_cal($format, $desc).
"\n");
72 if (!empty($conf->global->MAIN_AGENDA_EXPORT_CACHE) && $conf->global->MAIN_AGENDA_EXPORT_CACHE > 60) {
77 fwrite($calfileh,
"X-PUBLISHED-TTL: P".$hh.
"H".$mm.
"M".$ss.
"S\n");
80 foreach ($events_array as $key => $event) {
87 $type = $event[
"type"];
88 $startdate = $event[
"startdate"];
89 $duration = $event[
"duration"];
90 $enddate = $event[
"enddate"];
91 $summary = $event[
"summary"];
92 $category = $event[
"category"];
93 $priority = $event[
"priority"];
94 $fulldayevent = $event[
"fulldayevent"];
95 $location = $event[
"location"];
96 $email = $event[
"email"];
98 $transparency = $event[
"transparency"];
100 $created = $event[
"created"];
101 $modified = $event[
"modified"];
102 $assignedUsers = $event[
"assignedUsers"];
107 $description =
format_cal($format, $description);
146 if ($type ===
"event") {
147 fwrite($calfileh,
"BEGIN:VEVENT\n");
148 fwrite($calfileh,
"UID:".$uid.
"\n");
150 if (!empty($email)) {
151 fwrite($calfileh,
"ORGANIZER:MAILTO:".$email.
"\n");
152 fwrite($calfileh,
"CONTACT:MAILTO:".$email.
"\n");
156 fwrite($calfileh,
"URL:".$url.
"\n");
159 if (is_array($assignedUsers)) {
160 foreach ($assignedUsers as $assignedUser) {
161 if ($assignedUser->email === $email) {
165 fwrite($calfileh,
"ATTENDEE;RSVP=TRUE:mailto:".$assignedUser->email.
"\n");
170 fwrite($calfileh,
"CREATED:".
dol_print_date($created,
"dayhourxcard",
true).
"\n");
174 fwrite($calfileh,
"LAST-MODIFIED:".
dol_print_date($modified,
"dayhourxcard",
true).
"\n");
177 fwrite($calfileh,
"SUMMARY:".$encoding.$summary.
"\n");
178 fwrite($calfileh,
"DESCRIPTION:".$encoding.$description.
"\n");
180 if (!empty($location)) {
181 fwrite($calfileh,
"LOCATION:".$encoding.$location.
"\n");
185 fwrite($calfileh,
"X-FUNAMBOL-ALLDAY:1\n");
190 fwrite($calfileh,
"X-MICROSOFT-CDO-ALLDAYEVENT:TRUE\n");
195 fwrite($calfileh,
"DTSTAMP:".
dol_print_date($now,
"dayhourxcard",
'gmt').
"\n");
203 $prefix =
";VALUE=DATE";
207 fwrite($calfileh,
"DTSTART".$prefix.
":".$startdatef.
"\n");
211 if (empty($enddate)) {
218 if (empty($enddate)) {
219 $enddate = $startdate + $duration;
227 $prefix =
";VALUE=DATE";
234 fwrite($calfileh,
"DTEND".$prefix.
":".$enddatef.
"\n");
235 fwrite($calfileh,
"STATUS:CONFIRMED\n");
237 if (!empty($transparency)) {
238 fwrite($calfileh,
"TRANSP:".$transparency.
"\n");
241 if (!empty($category)) {
242 fwrite($calfileh,
"CATEGORIES:".$encoding.$category.
"\n");
245 fwrite($calfileh,
"END:VEVENT\n");
249 if ($type ===
"journal") {
250 fwrite($calfileh,
"BEGIN:VJOURNAL\n");
251 fwrite($calfileh,
"UID:".$uid.
"\n");
253 if (!empty($email)) {
254 fwrite($calfileh,
"ORGANIZER:MAILTO:".$email.
"\n");
255 fwrite($calfileh,
"CONTACT:MAILTO:".$email.
"\n");
259 fwrite($calfileh,
"URL:".$url.
"\n");
263 fwrite($calfileh,
"CREATED:".
dol_print_date($created,
"dayhourxcard",
'gmt').
"\n");
267 fwrite($calfileh,
"LAST-MODIFIED:".
dol_print_date($modified,
"dayhourxcard",
'gmt').
"\n");
270 fwrite($calfileh,
"SUMMARY:".$encoding.$summary.
"\n");
271 fwrite($calfileh,
"DESCRIPTION:".$encoding.$description.
"\n");
272 fwrite($calfileh,
"STATUS:CONFIRMED\n");
273 fwrite($calfileh,
"CATEGORIES:".$category.
"\n");
274 fwrite($calfileh,
"LOCATION:".$location.
"\n");
275 fwrite($calfileh,
"TRANSP:OPAQUE\n");
276 fwrite($calfileh,
"CLASS:CONFIDENTIAL\n");
277 fwrite($calfileh,
"DTSTAMP:".
dol_print_date($startdatef,
"dayhourxcard",
'gmt').
"\n");
279 fwrite($calfileh,
"END:VJOURNAL\n");
284 fwrite($calfileh,
"END:VCALENDAR");
288 if (!empty($conf->global->MAIN_UMASK)) {
289 @chmod($outputfile, octdec($conf->global->MAIN_UMASK));
292 dol_syslog(
"xcal.lib.php::build_calfile Failed to open file ".$outputfile.
" for writing");
311 function build_rssfile($format, $title, $desc, $events_array, $outputfile, $filter =
'', $url =
'', $langcode =
'')
313 global $user, $conf, $langs;
314 global $dolibarr_main_url_root;
316 dol_syslog(
"xcal.lib.php::build_rssfile Build rss file ".$outputfile.
" to format ".$format);
318 if (empty($outputfile)) {
323 $fichier = fopen($outputfile,
"w");
329 fwrite($fichier,
'<?xml version="1.0" encoding="'.$langs->charset_output.
'"?>');
330 fwrite($fichier,
"\n");
332 fwrite($fichier,
'<rss version="2.0">');
333 fwrite($fichier,
"\n");
335 fwrite($fichier,
"<channel>\n");
336 fwrite($fichier,
"<title>".$title.
"</title>\n");
338 fwrite($fichier,
"<language>".$langcode.
"</language>\n");
351 $urlwithouturlroot = preg_replace(
"/".preg_quote(DOL_URL_ROOT,
"/").
"$/i",
"", trim($dolibarr_main_url_root));
352 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
355 $url = $urlwithroot.
"/public/agenda/agendaexport.php?format=rss&exportkey=".urlencode($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY);
358 fwrite($fichier,
"<link><![CDATA[".$url.
"]]></link>\n");
360 foreach ($events_array as $key => $event) {
361 $eventqualified =
true;
366 $eventqualified =
false;
369 if ($eventqualified) {
370 if (is_object($event) && get_class($event) ==
'WebsitePage') {
373 $tmpevent[
'uid'] = $event->id;
374 $tmpevent[
'startdate'] = $event->date_creation;
375 $tmpevent[
'summary'] = $event->title;
376 $tmpevent[
'url'] = $event->fullpageurl ? $event->fullpageurl : $event->pageurl.
'.php';
377 $tmpevent[
'author'] = $event->author_alias ? $event->author_alias :
'unknown';
379 $tmpevent[
'desc'] = $event->description;
380 $tmpevent[
'image'] = $GLOBALS[
'website']->virtualhost.
'/medias/'.$event->image;
384 $uid = $event[
"uid"];
385 $startdate = $event[
"startdate"];
386 $summary = $event[
"summary"];
387 $url = $event[
"url"];
388 $author = $event[
"author"];
389 $category = $event[
"category"];
390 if (!empty($event[
"image"])) {
391 $image = $event[
"image"];
402 fwrite($fichier,
"<item>\n");
403 fwrite($fichier,
"<title><![CDATA[".$summary.
"]]></title>\n");
404 fwrite($fichier,
"<link><![CDATA[".$url.
"]]></link>\n");
405 fwrite($fichier,
"<author><![CDATA[".$author.
"]]></author>\n");
406 fwrite($fichier,
"<category><![CDATA[".$category.
"]]></category>\n");
407 fwrite($fichier,
"<description><![CDATA[");
409 if (!empty($image)) {
410 fwrite($fichier,
'<p><img class="center" src="'.$image.
'"/></p>');
414 fwrite($fichier, $description);
419 fwrite($fichier,
"]]></description>\n");
420 fwrite($fichier,
"<pubDate>".date(
"r", $startdate).
"</pubDate>\n");
421 fwrite($fichier,
"<guid isPermaLink=\"true\"><![CDATA[".$uid.
"]]></guid>\n");
422 fwrite($fichier,
"<source><![CDATA[Dolibarr]]></source>\n");
423 fwrite($fichier,
"</item>\n");
427 fwrite($fichier,
"</channel>");
428 fwrite($fichier,
"\n");
429 fwrite($fichier,
"</rss>");
433 if (!empty($conf->global->MAIN_UMASK)) {
434 @chmod($outputfile, octdec($conf->global->MAIN_UMASK));
450 $newstring = $string;
452 if ($format ===
"vcal") {
456 if ($format ===
"ical") {
458 $newstring = preg_replace(
"/\r\n/i",
"\\n", $newstring);
459 $newstring = preg_replace(
"/\n\r/i",
"\\n", $newstring);
460 $newstring = preg_replace(
"/\n/i",
"\\n", $newstring);
482 if (function_exists(
"mb_strlen")) {
483 $strlength = mb_strlen($line,
"UTF-8");
485 for ($j = 0; $j < $strlength; $j++) {
487 $char = mb_substr($line, $j, 1,
"UTF-8");
489 if ((mb_strlen($newpara,
"UTF-8") + mb_strlen($char,
"UTF-8")) >= 75) {
491 $out .= $newpara.
"\r\n ";
503 for ($j = 0; $j < $strlength; $j++) {
505 $char = substr($line, $j, 1);
509 $out .= $newpara.
"\r\n ";
533 $lines = preg_split(
"/\r\n/", $str);
536 foreach ($lines as $line) {
540 $strlength = strlen($line);
542 for ($j = 0; $j < $strlength; $j++) {
543 $char = substr($line, $j, 1);
546 if ($ascii < 32 || $ascii === 61 || $ascii > 126) {
547 $char =
"=".strtoupper(sprintf(
"%02X", $ascii));
551 if ((strlen($newpara) + strlen($char)) >= 76) {
553 $out .= $newpara.
"=\r\n";
579 return trim(quoted_printable_decode(preg_replace(
"/=\r?\n/",
"", $str)));
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
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.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
quotedPrintEncode($str, $forcal=0)
Encode into vcal format.
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...
format_cal($format, $string)
Encode for cal export.
build_rssfile($format, $title, $desc, $events_array, $outputfile, $filter='', $url='', $langcode='')
Build a file from an array of events.
calEncode($line)
Cut string after 75 chars.
quotedPrintDecode($str)
Decode vcal format.