36function build_calfile($format, $title, $desc, $events_array, $outputfile)
40 dol_syslog(
"xcal.lib.php::build_calfile Build cal file ".$outputfile.
" to format ".$format);
42 if (empty($outputfile)) {
50 $calfileh = fopen($outputfile,
"w");
53 include_once DOL_DOCUMENT_ROOT.
"/core/lib/date.lib.php";
58 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");
80 fwrite($calfileh,
"X-PUBLISHED-TTL: P".$hh.
"H".$mm.
"M".$ss.
"S\n");
83 foreach ($events_array as $key => $event) {
90 $type = $event[
"type"];
91 $startdate = $event[
"startdate"];
92 $duration = $event[
"duration"];
93 $enddate = $event[
"enddate"];
94 $summary = $event[
"summary"];
95 $category = $event[
"category"];
96 $priority = $event[
"priority"];
97 $fulldayevent = $event[
"fulldayevent"];
98 $location = $event[
"location"];
99 $email = $event[
"email"];
100 $url = $event[
"url"];
101 $transparency = $event[
"transparency"];
103 $created = $event[
"created"];
104 $modified = $event[
"modified"];
105 $assignedUsers = $event[
"assignedUsers"];
110 $description =
format_cal($format, $description);
149 if ($type ===
"event") {
152 fwrite($calfileh,
"BEGIN:VEVENT\n");
153 fwrite($calfileh,
"UID:".$uid.
"\n");
155 if (!empty($email)) {
156 fwrite($calfileh,
"ORGANIZER:MAILTO:".$email.
"\n");
157 fwrite($calfileh,
"CONTACT:MAILTO:".$email.
"\n");
161 fwrite($calfileh,
"URL:".$url.
"\n");
164 if (is_array($assignedUsers)) {
165 foreach ($assignedUsers as $assignedUser) {
166 if ($assignedUser->email === $email) {
170 fwrite($calfileh,
"ATTENDEE;RSVP=TRUE:mailto:".$assignedUser->email.
"\n");
175 fwrite($calfileh,
"CREATED:".
dol_print_date($created,
"dayhourxcard",
true).
"\n");
179 fwrite($calfileh,
"LAST-MODIFIED:".
dol_print_date($modified,
"dayhourxcard",
true).
"\n");
182 fwrite($calfileh,
"SUMMARY:".$encoding.$summary.
"\n");
183 fwrite($calfileh,
"DESCRIPTION:".$encoding.$description.
"\n");
185 if (!empty($location)) {
186 fwrite($calfileh,
"LOCATION:".$encoding.$location.
"\n");
190 fwrite($calfileh,
"X-FUNAMBOL-ALLDAY:1\n");
195 fwrite($calfileh,
"X-MICROSOFT-CDO-ALLDAYEVENT:TRUE\n");
200 fwrite($calfileh,
"DTSTAMP:".
dol_print_date($now,
"dayhourxcard",
'gmt').
"\n");
213 $prefix =
";VALUE=DATE";
221 fwrite($calfileh,
"DTSTART".$prefix.
":".$startdatef.
"\n");
225 if (empty($enddate)) {
232 if (empty($enddate)) {
233 $enddate = $startdate + $duration;
241 $prefix =
";VALUE=DATE";
248 fwrite($calfileh,
"DTEND".$prefix.
":".$enddatef.
"\n");
249 fwrite($calfileh,
"STATUS:CONFIRMED\n");
251 if (!empty($transparency)) {
252 fwrite($calfileh,
"TRANSP:".$transparency.
"\n");
255 if (!empty($category)) {
256 fwrite($calfileh,
"CATEGORIES:".$encoding.$category.
"\n");
259 fwrite($calfileh,
"END:VEVENT\n");
263 if ($type ===
"journal") {
266 fwrite($calfileh,
"BEGIN:VJOURNAL\n");
267 fwrite($calfileh,
"UID:".$uid.
"\n");
269 if (!empty($email)) {
270 fwrite($calfileh,
"ORGANIZER:MAILTO:".$email.
"\n");
271 fwrite($calfileh,
"CONTACT:MAILTO:".$email.
"\n");
275 fwrite($calfileh,
"URL:".$url.
"\n");
279 fwrite($calfileh,
"CREATED:".
dol_print_date($created,
"dayhourxcard",
'gmt').
"\n");
283 fwrite($calfileh,
"LAST-MODIFIED:".
dol_print_date($modified,
"dayhourxcard",
'gmt').
"\n");
286 fwrite($calfileh,
"SUMMARY:".$encoding.$summary.
"\n");
287 fwrite($calfileh,
"DESCRIPTION:".$encoding.$description.
"\n");
288 fwrite($calfileh,
"STATUS:CONFIRMED\n");
289 fwrite($calfileh,
"CATEGORIES:".$category.
"\n");
290 fwrite($calfileh,
"LOCATION:".$location.
"\n");
291 fwrite($calfileh,
"TRANSP:OPAQUE\n");
292 fwrite($calfileh,
"CLASS:CONFIDENTIAL\n");
293 fwrite($calfileh,
"DTSTAMP:".
dol_print_date($startdate,
"dayhourxcard",
'gmt').
"\n");
295 fwrite($calfileh,
"END:VJOURNAL\n");
300 fwrite($calfileh,
"END:VCALENDAR");
305 dol_syslog(
"xcal.lib.php::build_calfile Failed to open file ".$outputfile.
" for writing");
326function build_rssfile($format, $title, $desc, $events_array, $outputfile, $filter =
'', $url =
'', $langcode =
'')
328 global $user,
$conf, $langs, $mysoc;
329 global $dolibarr_main_url_root;
331 dol_syslog(
"xcal.lib.php::build_rssfile Build rss file ".$outputfile.
" to format ".$format);
333 if (empty($outputfile)) {
340 $fichier = fopen($outputfile,
"w");
344 fwrite($fichier,
'<?xml version="1.0" encoding="'.$langs->charset_output.
'"?>');
345 fwrite($fichier,
"\n");
347 fwrite($fichier,
'<rss version="2.0">');
348 fwrite($fichier,
"\n");
350 fwrite($fichier,
"<channel>\n");
352 fwrite($fichier,
"<description>".
dol_escape_xml($title).
"</description>\n");
354 fwrite($fichier,
"<language>".
dol_escape_xml($langcode).
"</language>\n");
358 $urlwithouturlroot = preg_replace(
"/".preg_quote(DOL_URL_ROOT,
"/").
"$/i",
"", trim($dolibarr_main_url_root));
359 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
364 $url = $urlwithroot.
"/public/agenda/agendaexport.php?format=rss&exportkey=".urlencode(
getDolGlobalString(
'MAIN_AGENDA_XCAL_EXPORTKEY'));
366 fwrite($fichier,
"<link><![CDATA[".$url.
"]]></link>\n");
369 if (!empty($mysoc->logo_squarred_small)) {
370 $urlimage = $urlwithroot.
'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode(
'logos/thumbs/'.$mysoc->logo_squarred_small);
372 if ($urlimage && (empty($GLOBALS[
'website']) || preg_match(
'/'.preg_quote($GLOBALS[
'website']->virtualhost,
'/').
'/', $urlwithroot))) {
373 fwrite($fichier,
"<image><url><![CDATA[".$urlimage.
"]]></url><title>".htmlspecialchars($title).
"</title><link><![CDATA[".$url.
"]]></link></image>\n");
377 foreach ($events_array as $key => $event) {
378 $eventqualified =
true;
383 $eventqualified =
false;
386 if ($eventqualified) {
389 if (is_object($event) && get_class($event) ==
'WebsitePage') {
392 $tmpevent[
'uid'] = (string) $event->id;
393 $tmpevent[
'startdate'] = $event->date_creation;
394 $tmpevent[
'summary'] = $event->title;
395 $tmpevent[
'url'] = $event->fullpageurl ? $event->fullpageurl : $event->pageurl.
'.php';
396 $tmpevent[
'author'] = $event->author_alias ? $event->author_alias :
'unknown';
398 $tmpevent[
'desc'] = $event->description;
399 if (!empty($event->image)) {
400 $tmpevent[
'image'] = $GLOBALS[
'website']->virtualhost.
'/medias/'.$event->image;
402 include_once DOL_DOCUMENT_ROOT.
'/core/lib/website.lib.php';
405 if (strpos($tmpimage,
'/') === 0) {
406 $tmpevent[
'image'] = $GLOBALS[
'website']->virtualhost.$tmpimage;
407 } elseif (stripos($tmpimage,
'http') === 0) {
408 $tmpevent[
'image'] = $tmpimage;
410 $tmpevent[
'image'] = $GLOBALS[
'website']->virtualhost.
'/medias/'.$tmpimage;
414 $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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.