35function 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)) {
49 $calfileh = fopen($outputfile,
"w");
52 include_once DOL_DOCUMENT_ROOT.
"/core/lib/date.lib.php";
57 if ($format ===
"vcal") {
58 $encoding =
"ENCODING=QUOTED-PRINTABLE:";
62 fwrite($calfileh,
"BEGIN:VCALENDAR\n");
65 fwrite($calfileh,
"VERSION:2.0\n");
67 fwrite($calfileh,
"METHOD:PUBLISH\n");
68 fwrite($calfileh,
"PRODID:-//DOLIBARR ".DOL_VERSION.
"\n");
69 fwrite($calfileh,
"CALSCALE:GREGORIAN\n");
70 fwrite($calfileh,
"X-WR-CALNAME:".$encoding.format_cal($format, $title).
"\n");
71 fwrite($calfileh,
"X-WR-CALDESC:".$encoding.format_cal($format, $desc).
"\n");
79 fwrite($calfileh,
"X-PUBLISHED-TTL: P".$hh.
"H".$mm.
"M".$ss.
"S\n");
82 foreach ($events_array as $key => $event) {
89 $type = $event[
"type"];
90 $startdate = $event[
"startdate"];
91 $duration = $event[
"duration"];
92 $enddate = $event[
"enddate"];
93 $summary = $event[
"summary"];
94 $category = $event[
"category"];
95 $priority = $event[
"priority"];
96 $fulldayevent = $event[
"fulldayevent"];
97 $location = $event[
"location"];
98 $email = $event[
"email"];
100 $transparency = $event[
"transparency"];
102 $created = $event[
"created"];
103 $modified = $event[
"modified"];
104 $assignedUsers = $event[
"assignedUsers"];
109 $description =
format_cal($format, $description);
148 if ($type ===
"event") {
151 fwrite($calfileh,
"BEGIN:VEVENT\n");
152 fwrite($calfileh,
"UID:".$uid.
"\n");
154 if (!empty($email)) {
155 fwrite($calfileh,
"ORGANIZER:MAILTO:".$email.
"\n");
156 fwrite($calfileh,
"CONTACT:MAILTO:".$email.
"\n");
160 fwrite($calfileh,
"URL:".$url.
"\n");
163 if (is_array($assignedUsers)) {
164 foreach ($assignedUsers as $assignedUser) {
165 if ($assignedUser->email === $email) {
169 fwrite($calfileh,
"ATTENDEE;RSVP=TRUE:mailto:".$assignedUser->email.
"\n");
174 fwrite($calfileh,
"CREATED:".
dol_print_date($created,
"dayhourxcard",
true).
"\n");
178 fwrite($calfileh,
"LAST-MODIFIED:".
dol_print_date($modified,
"dayhourxcard",
true).
"\n");
181 fwrite($calfileh,
"SUMMARY:".$encoding.$summary.
"\n");
182 fwrite($calfileh,
"DESCRIPTION:".$encoding.$description.
"\n");
184 if (!empty($location)) {
185 fwrite($calfileh,
"LOCATION:".$encoding.$location.
"\n");
189 fwrite($calfileh,
"X-FUNAMBOL-ALLDAY:1\n");
194 fwrite($calfileh,
"X-MICROSOFT-CDO-ALLDAYEVENT:TRUE\n");
199 fwrite($calfileh,
"DTSTAMP:".
dol_print_date($now,
"dayhourxcard",
'gmt').
"\n");
212 $prefix =
";VALUE=DATE";
220 fwrite($calfileh,
"DTSTART".$prefix.
":".$startdatef.
"\n");
224 if (empty($enddate)) {
231 if (empty($enddate)) {
232 $enddate = $startdate + $duration;
240 $prefix =
";VALUE=DATE";
247 fwrite($calfileh,
"DTEND".$prefix.
":".$enddatef.
"\n");
248 fwrite($calfileh,
"STATUS:CONFIRMED\n");
250 if (!empty($transparency)) {
251 fwrite($calfileh,
"TRANSP:".$transparency.
"\n");
254 if (!empty($category)) {
255 fwrite($calfileh,
"CATEGORIES:".$encoding.$category.
"\n");
258 fwrite($calfileh,
"END:VEVENT\n");
262 if ($type ===
"journal") {
265 fwrite($calfileh,
"BEGIN:VJOURNAL\n");
266 fwrite($calfileh,
"UID:".$uid.
"\n");
268 if (!empty($email)) {
269 fwrite($calfileh,
"ORGANIZER:MAILTO:".$email.
"\n");
270 fwrite($calfileh,
"CONTACT:MAILTO:".$email.
"\n");
274 fwrite($calfileh,
"URL:".$url.
"\n");
278 fwrite($calfileh,
"CREATED:".
dol_print_date($created,
"dayhourxcard",
'gmt').
"\n");
282 fwrite($calfileh,
"LAST-MODIFIED:".
dol_print_date($modified,
"dayhourxcard",
'gmt').
"\n");
285 fwrite($calfileh,
"SUMMARY:".$encoding.$summary.
"\n");
286 fwrite($calfileh,
"DESCRIPTION:".$encoding.$description.
"\n");
287 fwrite($calfileh,
"STATUS:CONFIRMED\n");
288 fwrite($calfileh,
"CATEGORIES:".$category.
"\n");
289 fwrite($calfileh,
"LOCATION:".$location.
"\n");
290 fwrite($calfileh,
"TRANSP:OPAQUE\n");
291 fwrite($calfileh,
"CLASS:CONFIDENTIAL\n");
292 fwrite($calfileh,
"DTSTAMP:".
dol_print_date($startdatef,
"dayhourxcard",
'gmt').
"\n");
294 fwrite($calfileh,
"END:VJOURNAL\n");
299 fwrite($calfileh,
"END:VCALENDAR");
304 dol_syslog(
"xcal.lib.php::build_calfile Failed to open file ".$outputfile.
" for writing");
325function build_rssfile($format, $title, $desc, $events_array, $outputfile, $filter =
'', $url =
'', $langcode =
'')
327 global $user, $conf, $langs, $mysoc;
328 global $dolibarr_main_url_root;
330 dol_syslog(
"xcal.lib.php::build_rssfile Build rss file ".$outputfile.
" to format ".$format);
332 if (empty($outputfile)) {
339 $fichier = fopen($outputfile,
"w");
343 fwrite($fichier,
'<?xml version="1.0" encoding="'.$langs->charset_output.
'"?>');
344 fwrite($fichier,
"\n");
346 fwrite($fichier,
'<rss version="2.0">');
347 fwrite($fichier,
"\n");
349 fwrite($fichier,
"<channel>\n");
351 fwrite($fichier,
"<description>".
dol_escape_xml($title).
"</description>\n");
353 fwrite($fichier,
"<language>".
dol_escape_xml($langcode).
"</language>\n");
357 $urlwithouturlroot = preg_replace(
"/".preg_quote(DOL_URL_ROOT,
"/").
"$/i",
"", trim($dolibarr_main_url_root));
358 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
363 $url = $urlwithroot.
"/public/agenda/agendaexport.php?format=rss&exportkey=".urlencode(
getDolGlobalString(
'MAIN_AGENDA_XCAL_EXPORTKEY'));
365 fwrite($fichier,
"<link><![CDATA[".$url.
"]]></link>\n");
368 if (!empty($mysoc->logo_squarred_small)) {
369 $urlimage = $urlwithroot.
'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode(
'logos/thumbs/'.$mysoc->logo_squarred_small);
371 if ($urlimage && (empty($GLOBALS[
'website']) || preg_match(
'/'.preg_quote($GLOBALS[
'website']->virtualhost,
'/').
'/', $urlwithroot))) {
372 fwrite($fichier,
"<image><url><![CDATA[".$urlimage.
"]]></url><title>".htmlspecialchars($title).
"</title><link><![CDATA[".$url.
"]]></link></image>\n");
376 foreach ($events_array as $key => $event) {
377 $eventqualified =
true;
382 $eventqualified =
false;
385 if ($eventqualified) {
388 if (is_object($event) && get_class($event) ==
'WebsitePage') {
391 $tmpevent[
'uid'] = (string) $event->id;
392 $tmpevent[
'startdate'] = $event->date_creation;
393 $tmpevent[
'summary'] = $event->title;
394 $tmpevent[
'url'] = $event->fullpageurl ? $event->fullpageurl : $event->pageurl.
'.php';
395 $tmpevent[
'author'] = $event->author_alias ? $event->author_alias :
'unknown';
397 $tmpevent[
'desc'] = $event->description;
398 if (!empty($event->image)) {
399 $tmpevent[
'image'] = $GLOBALS[
'website']->virtualhost.
'/medias/'.$event->image;
401 include_once DOL_DOCUMENT_ROOT.
'/core/lib/website.lib.php';
404 if (strpos($tmpimage,
'/') === 0) {
405 $tmpevent[
'image'] = $GLOBALS[
'website']->virtualhost.$tmpimage;
406 } elseif (stripos($tmpimage,
'http') === 0) {
407 $tmpevent[
'image'] = $tmpimage;
409 $tmpevent[
'image'] = $GLOBALS[
'website']->virtualhost.
'/medias/'.$tmpimage;
413 $tmpevent[
'content'] = $event->content;
418 $uid = $event[
"uid"];
419 $startdate = $event[
"startdate"];
420 $summary = $event[
"summary"];
421 $description = $event[
"desc"];
422 $url = empty($event[
"url"]) ?
'' : $event[
"url"];
423 $author = $event[
"author"];
424 $category = empty($event[
"category"]) ? null : $event[
"category"];
426 if (!empty($event[
"image"])) {
427 $image = $event[
"image"];
431 if (!empty($event[
"content"]) && preg_match(
'/<img\s*(?:alt="[^"]*"\s*)?(?:class="[^"]*"\s*)?src="([^"]+)"/m', $event[
"content"], $reg)) {
432 if (!empty($reg[0])) {
436 if (!empty($GLOBALS[
'website']->virtualhost)) {
437 if (preg_match(
'/^\/medias\//', $image)) {
438 $image = $GLOBALS[
'website']->virtualhost.$image;
439 } elseif (preg_match(
'/^\/viewimage\.php\?modulepart=medias&[^"]*file=([^&"]+)/', $image, $reg)) {
440 $image = $GLOBALS[
'website']->virtualhost.
'/medias/'.$reg[1];
456 fwrite($fichier,
"<item>\n");
457 fwrite($fichier,
"<title><![CDATA[".$summary.
"]]></title>\n");
458 fwrite($fichier,
"<link><![CDATA[".$url.
"]]></link>\n");
460 if (!empty($category)) {
461 fwrite($fichier,
"<category><![CDATA[".$category.
"]]></category>\n");
464 fwrite($fichier,
"<description><![CDATA[");
465 if (!empty($image)) {
466 fwrite($fichier,
'<p><img class="center" src="'.$image.
'"/></p>');
470 fwrite($fichier, $description);
475 fwrite($fichier,
"]]></description>\n");
476 fwrite($fichier,
"<pubDate>".date(
"r", $startdate).
"</pubDate>\n");
477 fwrite($fichier,
'<guid isPermaLink="false"><![CDATA['.str_pad($uid, 10,
"0", STR_PAD_LEFT).
']]></guid>'.
"\n");
478 fwrite($fichier,
'<source url="'.$url.
'"><![CDATA[Dolibarr]]></source>'.
"\n");
479 fwrite($fichier,
"</item>\n");
483 fwrite($fichier,
"</channel>");
484 fwrite($fichier,
"\n");
485 fwrite($fichier,
"</rss>");
503 $newstring = $string;
505 if ($format ===
"vcal") {
509 if ($format ===
"ical") {
511 $newstring = preg_replace(
"/\r\n/i",
"\\n", $newstring);
512 $newstring = preg_replace(
"/\n\r/i",
"\\n", $newstring);
513 $newstring = preg_replace(
"/\n/i",
"\\n", $newstring);
535 if (function_exists(
"mb_strlen")) {
536 $strlength = mb_strlen($line,
"UTF-8");
538 for ($j = 0; $j < $strlength; $j++) {
542 if ((mb_strlen($newpara,
"UTF-8") + mb_strlen($char,
"UTF-8")) >= 75) {
544 $out .= $newpara.
"\r\n ";
556 for ($j = 0; $j < $strlength; $j++) {
558 $char = substr($line, $j, 1);
562 $out .= $newpara.
"\r\n ";
586 $lines = preg_split(
"/\r\n/", $str);
589 foreach ($lines as $line) {
593 $strlength = strlen($line);
595 for ($j = 0; $j < $strlength; $j++) {
596 $char = substr($line, $j, 1);
599 if ($ascii < 32 || $ascii === 61 || $ascii > 126) {
600 $char =
"=".strtoupper(sprintf(
"%02X", $ascii));
604 if ((strlen($newpara) + strlen($char)) >= 76) {
606 $out .= $newpara.
"=\r\n";
632 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.
dolChmod($filepath, $newmask='')
Change mod of a file.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
dol_escape_xml($stringtoescape)
Returns text escaped for inclusion into a XML string.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getImageFromHtmlContent($htmlContent, $imageNumber=1)
Return the URL of an image found into a HTML content.
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.