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");
289 dol_syslog(
"xcal.lib.php::build_calfile Failed to open file ".$outputfile.
" for writing");
308 function build_rssfile($format, $title, $desc, $events_array, $outputfile, $filter =
'', $url =
'', $langcode =
'')
310 global $user, $conf, $langs, $mysoc;
311 global $dolibarr_main_url_root;
313 dol_syslog(
"xcal.lib.php::build_rssfile Build rss file ".$outputfile.
" to format ".$format);
315 if (empty($outputfile)) {
320 $fichier = fopen($outputfile,
"w");
324 fwrite($fichier,
'<?xml version="1.0" encoding="'.$langs->charset_output.
'"?>');
325 fwrite($fichier,
"\n");
327 fwrite($fichier,
'<rss version="2.0">');
328 fwrite($fichier,
"\n");
330 fwrite($fichier,
"<channel>\n");
331 fwrite($fichier,
"<title>".$title.
"</title>\n");
333 fwrite($fichier,
"<language>".$langcode.
"</language>\n");
337 $urlwithouturlroot = preg_replace(
"/".preg_quote(DOL_URL_ROOT,
"/").
"$/i",
"", trim($dolibarr_main_url_root));
338 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
343 $url = $urlwithroot.
"/public/agenda/agendaexport.php?format=rss&exportkey=".urlencode($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY);
345 fwrite($fichier,
"<link><![CDATA[".$url.
"]]></link>\n");
348 if (!empty($mysoc->logo_squarred_small)) {
349 $urlimage = $urlwithroot.
'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode($mysoc->logo_squarred_small);
351 fwrite($fichier,
"<image><url><![CDATA[".$urlimage.
"]]></url><title>'.$title.</title></image>\n");
355 foreach ($events_array as $key => $event) {
356 $eventqualified =
true;
361 $eventqualified =
false;
364 if ($eventqualified) {
365 if (is_object($event) && get_class($event) ==
'WebsitePage') {
368 $tmpevent[
'uid'] = $event->id;
369 $tmpevent[
'startdate'] = $event->date_creation;
370 $tmpevent[
'summary'] = $event->title;
371 $tmpevent[
'url'] = $event->fullpageurl ? $event->fullpageurl : $event->pageurl.
'.php';
372 $tmpevent[
'author'] = $event->author_alias ? $event->author_alias :
'unknown';
374 $tmpevent[
'desc'] = $event->description;
375 $tmpevent[
'image'] = $GLOBALS[
'website']->virtualhost.
'/medias/'.$event->image;
379 $uid = $event[
"uid"];
380 $startdate = $event[
"startdate"];
381 $summary = $event[
"summary"];
382 $url = $event[
"url"];
383 $author = $event[
"author"];
384 $category = $event[
"category"];
385 if (!empty($event[
"image"])) {
386 $image = $event[
"image"];
397 fwrite($fichier,
"<item>\n");
398 fwrite($fichier,
"<title><![CDATA[".$summary.
"]]></title>\n");
399 fwrite($fichier,
"<link><![CDATA[".$url.
"]]></link>\n");
400 fwrite($fichier,
"<author><![CDATA[".$author.
"]]></author>\n");
401 fwrite($fichier,
"<category><![CDATA[".$category.
"]]></category>\n");
402 fwrite($fichier,
"<description><![CDATA[");
404 if (!empty($image)) {
405 fwrite($fichier,
'<p><img class="center" src="'.$image.
'"/></p>');
409 fwrite($fichier, $description);
414 fwrite($fichier,
"]]></description>\n");
415 fwrite($fichier,
"<pubDate>".date(
"r", $startdate).
"</pubDate>\n");
416 fwrite($fichier,
"<guid isPermaLink=\"true\"><![CDATA[".$uid.
"]]></guid>\n");
417 fwrite($fichier,
"<source><![CDATA[Dolibarr]]></source>\n");
418 fwrite($fichier,
"</item>\n");
422 fwrite($fichier,
"</channel>");
423 fwrite($fichier,
"\n");
424 fwrite($fichier,
"</rss>");
442 $newstring = $string;
444 if ($format ===
"vcal") {
448 if ($format ===
"ical") {
450 $newstring = preg_replace(
"/\r\n/i",
"\\n", $newstring);
451 $newstring = preg_replace(
"/\n\r/i",
"\\n", $newstring);
452 $newstring = preg_replace(
"/\n/i",
"\\n", $newstring);
474 if (function_exists(
"mb_strlen")) {
475 $strlength = mb_strlen($line,
"UTF-8");
477 for ($j = 0; $j < $strlength; $j++) {
479 $char = mb_substr($line, $j, 1,
"UTF-8");
481 if ((mb_strlen($newpara,
"UTF-8") + mb_strlen($char,
"UTF-8")) >= 75) {
483 $out .= $newpara.
"\r\n ";
495 for ($j = 0; $j < $strlength; $j++) {
497 $char = substr($line, $j, 1);
501 $out .= $newpara.
"\r\n ";
525 $lines = preg_split(
"/\r\n/", $str);
528 foreach ($lines as $line) {
532 $strlength = strlen($line);
534 for ($j = 0; $j < $strlength; $j++) {
535 $char = substr($line, $j, 1);
538 if ($ascii < 32 || $ascii === 61 || $ascii > 126) {
539 $char =
"=".strtoupper(sprintf(
"%02X", $ascii));
543 if ((strlen($newpara) + strlen($char)) >= 76) {
545 $out .= $newpara.
"=\r\n";
571 return trim(quoted_printable_decode(preg_replace(
"/=\r?\n/",
"", $str)));