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");
352 fwrite($fichier,
"<language>".
dol_escape_xml($langcode).
"</language>\n");
356 $urlwithouturlroot = preg_replace(
"/".preg_quote(DOL_URL_ROOT,
"/").
"$/i",
"", trim($dolibarr_main_url_root));
357 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
362 $url = $urlwithroot.
"/public/agenda/agendaexport.php?format=rss&exportkey=".urlencode($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY);
364 fwrite($fichier,
"<link><![CDATA[".$url.
"]]></link>\n");
367 if (!empty($mysoc->logo_squarred_small)) {
368 $urlimage = $urlwithroot.
'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode(
'logos/thumbs/'.$mysoc->logo_squarred_small);
370 fwrite($fichier,
"<image><url><![CDATA[".$urlimage.
"]]></url><title>'.$title.</title></image>\n");
374 foreach ($events_array as $key => $event) {
375 $eventqualified =
true;
380 $eventqualified =
false;
383 if ($eventqualified) {
386 if (is_object($event) && get_class($event) ==
'WebsitePage') {
389 $tmpevent[
'uid'] = $event->id;
390 $tmpevent[
'startdate'] = $event->date_creation;
391 $tmpevent[
'summary'] = $event->title;
392 $tmpevent[
'url'] = $event->fullpageurl ? $event->fullpageurl : $event->pageurl.
'.php';
393 $tmpevent[
'author'] = $event->author_alias ? $event->author_alias :
'unknown';
395 $tmpevent[
'desc'] = $event->description;
396 $tmpevent[
'image'] = $GLOBALS[
'website']->virtualhost.
'/medias/'.$event->image;
400 $uid = $event[
"uid"];
401 $startdate = $event[
"startdate"];
402 $summary = $event[
"summary"];
403 $url = $event[
"url"];
404 $author = $event[
"author"];
405 $category = empty($event[
"category"]) ? null : $event[
"category"];
406 if (!empty($event[
"image"])) {
407 $image = $event[
"image"];
418 fwrite($fichier,
"<item>\n");
419 fwrite($fichier,
"<title><![CDATA[".$summary.
"]]></title>\n");
420 fwrite($fichier,
"<link><![CDATA[".$url.
"]]></link>\n");
421 fwrite($fichier,
"<author><![CDATA[".$author.
"]]></author>\n");
422 if (!empty($category)) {
423 fwrite($fichier,
"<category><![CDATA[".$category.
"]]></category>\n");
425 fwrite($fichier,
"<description><![CDATA[");
426 if (!empty($image)) {
427 fwrite($fichier,
'<p><img class="center" src="'.$image.
'"/></p>');
431 fwrite($fichier, $description);
436 fwrite($fichier,
"]]></description>\n");
437 fwrite($fichier,
"<pubDate>".date(
"r", $startdate).
"</pubDate>\n");
438 fwrite($fichier,
"<guid isPermaLink=\"true\"><![CDATA[".$uid.
"]]></guid>\n");
439 fwrite($fichier,
"<source><![CDATA[Dolibarr]]></source>\n");
440 fwrite($fichier,
"</item>\n");
444 fwrite($fichier,
"</channel>");
445 fwrite($fichier,
"\n");
446 fwrite($fichier,
"</rss>");
464 $newstring = $string;
466 if ($format ===
"vcal") {
470 if ($format ===
"ical") {
472 $newstring = preg_replace(
"/\r\n/i",
"\\n", $newstring);
473 $newstring = preg_replace(
"/\n\r/i",
"\\n", $newstring);
474 $newstring = preg_replace(
"/\n/i",
"\\n", $newstring);
496 if (function_exists(
"mb_strlen")) {
497 $strlength = mb_strlen($line,
"UTF-8");
499 for ($j = 0; $j < $strlength; $j++) {
503 if ((mb_strlen($newpara,
"UTF-8") + mb_strlen($char,
"UTF-8")) >= 75) {
505 $out .= $newpara.
"\r\n ";
517 for ($j = 0; $j < $strlength; $j++) {
519 $char = substr($line, $j, 1);
523 $out .= $newpara.
"\r\n ";
547 $lines = preg_split(
"/\r\n/", $str);
550 foreach ($lines as $line) {
554 $strlength = strlen($line);
556 for ($j = 0; $j < $strlength; $j++) {
557 $char = substr($line, $j, 1);
560 if ($ascii < 32 || $ascii === 61 || $ascii > 126) {
561 $char =
"=".strtoupper(sprintf(
"%02X", $ascii));
565 if ((strlen($newpara) + strlen($char)) >= 76) {
567 $out .= $newpara.
"=\r\n";
593 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).
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_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 dolibarr global constant string value.
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.