36function build_calfile($format, $title, $desc, $events_array, $outputfile)
38 dol_syslog(
"xcal.lib.php::build_calfile Build cal file ".$outputfile.
" to format ".$format);
40 if (empty($outputfile)) {
48 $calfileh = fopen($outputfile,
"w");
51 include_once DOL_DOCUMENT_ROOT.
"/core/lib/date.lib.php";
59 $writeline =
function ($line) use ($calfileh, $format) {
60 if ($format ===
"ical") {
61 $line =
calFoldLine((
string) preg_replace(
'/[\x00-\x08\x0A-\x1F\x7F]+/',
' ', $line));
63 fwrite($calfileh, $line.
"\r\n");
66 if ($format ===
"vcal") {
67 $encoding =
"ENCODING=QUOTED-PRINTABLE:";
71 $writeline(
"BEGIN:VCALENDAR");
74 $writeline(
"VERSION:2.0");
76 $writeline(
"METHOD:PUBLISH");
77 $writeline(
"PRODID:-//DOLIBARR ".DOL_VERSION);
78 $writeline(
"CALSCALE:GREGORIAN");
79 $writeline(
"X-WR-CALNAME:".$encoding.format_cal($format, $title));
80 $writeline(
"X-WR-CALDESC:".$encoding.format_cal($format, $desc));
86 $writeline(
"X-PUBLISHED-TTL:PT".intdiv($ttl, 3600).
"H".intdiv($ttl % 3600, 60).
"M".($ttl % 60).
"S");
89 foreach ($events_array as $key => $event) {
96 $type = $event[
"type"];
97 $startdate = $event[
"startdate"];
98 $duration = $event[
"duration"];
99 $enddate = $event[
"enddate"];
100 $summary = $event[
"summary"];
101 $category = $event[
"category"];
102 $priority = $event[
"priority"];
103 $fulldayevent = $event[
"fulldayevent"];
104 $location = $event[
"location"];
105 $email = $event[
"email"];
106 $url = $event[
"url"];
107 $transparency = $event[
"transparency"];
109 $created = $event[
"created"];
110 $modified = $event[
"modified"];
111 $assignedUsers = $event[
"assignedUsers"] ?? array();
116 $description =
format_cal($format, $description);
117 $category =
format_cal($format, (
string) $category);
118 $location =
format_cal($format, (
string) $location);
155 if ($type ===
"event") {
158 $writeline(
"BEGIN:VEVENT");
159 $writeline(
"UID:".$uid);
161 if (!empty($email)) {
162 $writeline(
"ORGANIZER:MAILTO:".$email);
163 $writeline(
"CONTACT:MAILTO:".$email);
167 $writeline(
"URL:".$url);
170 if (is_array($assignedUsers)) {
171 foreach ($assignedUsers as $assignedUser) {
172 if (empty($assignedUser->email) || $assignedUser->email === $email) {
176 $writeline(
"ATTENDEE;RSVP=TRUE:mailto:".$assignedUser->email);
181 $writeline(
"CREATED:".
dol_print_date($created,
"dayhourxcard",
true));
185 $writeline(
"LAST-MODIFIED:".
dol_print_date($modified,
"dayhourxcard",
true));
188 $writeline(
"SUMMARY:".$encoding.$summary);
189 $writeline(
"DESCRIPTION:".$encoding.$description);
191 if (!empty($location)) {
192 $writeline(
"LOCATION:".$encoding.$location);
196 $writeline(
"X-FUNAMBOL-ALLDAY:1");
201 $writeline(
"X-MICROSOFT-CDO-ALLDAYEVENT:TRUE");
206 $writeline(
"DTSTAMP:".
dol_print_date($now,
"dayhourxcard",
'gmt'));
219 $prefix =
";VALUE=DATE";
227 $writeline(
"DTSTART".$prefix.
":".$startdatef);
231 if (empty($enddate)) {
238 if (empty($enddate)) {
239 $enddate = $startdate + $duration;
247 $prefix =
";VALUE=DATE";
254 $writeline(
"DTEND".$prefix.
":".$enddatef);
255 $writeline(
"STATUS:CONFIRMED");
257 if (!empty($transparency)) {
258 $writeline(
"TRANSP:".$transparency);
261 if (!empty($category)) {
262 $writeline(
"CATEGORIES:".$encoding.$category);
265 $writeline(
"END:VEVENT");
269 if ($type ===
"journal") {
272 $writeline(
"BEGIN:VJOURNAL");
273 $writeline(
"UID:".$uid);
275 if (!empty($email)) {
276 $writeline(
"ORGANIZER:MAILTO:".$email);
277 $writeline(
"CONTACT:MAILTO:".$email);
281 $writeline(
"URL:".$url);
285 $writeline(
"CREATED:".
dol_print_date($created,
"dayhourxcard",
'gmt'));
289 $writeline(
"LAST-MODIFIED:".
dol_print_date($modified,
"dayhourxcard",
'gmt'));
292 $writeline(
"SUMMARY:".$encoding.$summary);
293 $writeline(
"DESCRIPTION:".$encoding.$description);
294 $writeline(
"STATUS:CONFIRMED");
295 if (!empty($category)) {
296 $writeline(
"CATEGORIES:".$encoding.$category);
298 if (!empty($location)) {
299 $writeline(
"LOCATION:".$encoding.$location);
301 $writeline(
"TRANSP:OPAQUE");
302 $writeline(
"CLASS:CONFIDENTIAL");
303 $writeline(
"DTSTAMP:".
dol_print_date($now,
"dayhourxcard",
'gmt'));
305 $writeline(
"END:VJOURNAL");
310 $writeline(
"END:VCALENDAR");
315 dol_syslog(
"xcal.lib.php::build_calfile Failed to open file ".$outputfile.
" for writing");
337function build_rssfile($format, $title, $desc, $events_array, $outputfile, $filter =
'', $url =
'', $langcode =
'', $useurlforguid =
false)
342 dol_syslog(
"xcal.lib.php::build_rssfile Build rss file ".$outputfile.
" to format ".$format);
344 if (empty($outputfile)) {
351 $fichier = fopen($outputfile,
"w");
355 fwrite($fichier,
'<?xml version="1.0" encoding="'.$langs->charset_output.
'"?>'.
"\n");
358 fwrite($fichier,
'<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">'.
"\n");
360 fwrite($fichier,
"<channel>\n");
362 fwrite($fichier,
"<description>".
dol_escape_xml($title).
"</description>\n");
364 fwrite($fichier,
"<language>".
dol_escape_xml($langcode).
"</language>\n");
369 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
374 $url = $urlwithroot.
"/public/agenda/agendaexport.php?format=rss&exportkey=".urlencode(
getDolGlobalString(
'MAIN_AGENDA_XCAL_EXPORTKEY'));
377 include_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
381 if (!empty(
$mysoc->logo_squarred_small)) {
382 $urlimage = $urlwithroot.
'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode(
'logos/thumbs/'.
$mysoc->logo_squarred_small);
384 if ($urlimage && (empty($GLOBALS[
'website']) || preg_match(
'/'.preg_quote($GLOBALS[
'website']->virtualhost,
'/').
'/', $urlwithroot))) {
391 fwrite($fichier,
'<atom:link href="'.
rssUrl($url).
'" rel="self" type="application/rss+xml"/>'.
"\n");
393 foreach ($events_array as $key => $event) {
394 $eventqualified =
true;
399 $eventqualified =
false;
402 if ($eventqualified) {
405 if (is_object($event) && get_class($event) ==
'WebsitePage') {
408 $tmpevent[
'uid'] = (string) $event->id;
409 $tmpevent[
'startdate'] = $event->date_creation;
410 $tmpevent[
'summary'] = $event->title;
411 $tmpevent[
'url'] = $event->fullpageurl ? $event->fullpageurl : $event->pageurl.
'.php';
412 $tmpevent[
'author'] = $event->author_alias ? $event->author_alias :
'unknown';
414 $tmpevent[
'desc'] = $event->description;
415 if (!empty($event->image)) {
416 $tmpevent[
'image'] = $GLOBALS[
'website']->virtualhost.
'/medias/'.$event->image;
418 include_once DOL_DOCUMENT_ROOT.
'/core/lib/website.lib.php';
421 if (strpos($tmpimage,
'/') === 0) {
422 $tmpevent[
'image'] = $GLOBALS[
'website']->virtualhost.$tmpimage;
423 } elseif (stripos($tmpimage,
'http') === 0) {
424 $tmpevent[
'image'] = $tmpimage;
426 $tmpevent[
'image'] = $GLOBALS[
'website']->virtualhost.
'/medias/'.$tmpimage;
430 $tmpevent[
'content'] = $event->content;
434 $uid = $event[
"uid"];
435 $startdate = $event[
"startdate"];
436 $summary = $event[
"summary"];
437 $description = $event[
"desc"];
438 $url = empty($event[
"url"]) ?
'' : $event[
"url"];
439 $author = $event[
"author"];
440 $category = empty($event[
"category"]) ? null : $event[
"category"];
442 if (!empty($event[
"image"])) {
443 $image = $event[
"image"];
447 if (!empty($event[
"content"]) && preg_match(
'/<img\s*(?:alt="[^"]*"\s*)?(?:class="[^"]*"\s*)?src="([^"]+)"/m', $event[
"content"], $reg)) {
448 if (!empty($reg[0])) {
452 if (!empty($GLOBALS[
'website']->virtualhost)) {
453 if (preg_match(
'/^\/medias\//', $image)) {
454 $image = $GLOBALS[
'website']->virtualhost.$image;
455 } elseif (preg_match(
'/^\/viewimage\.php\?modulepart=medias&[^"]*file=([^&"]+)/', $image, $reg)) {
456 $image = $GLOBALS[
'website']->virtualhost.
'/medias/'.$reg[1];
472 fwrite($fichier,
"<item>\n");
473 fwrite($fichier,
"<title>".
rssCdata($summary).
"</title>\n");
475 fwrite($fichier,
"<link>".
rssUrl($url).
"</link>\n");
478 if (!empty($category)) {
479 fwrite($fichier,
"<category>".
rssCdata($category).
"</category>\n");
482 $descriptionhtml =
'';
483 if (!empty($image)) {
484 $descriptionhtml .=
'<p><img class="center" src="'.htmlspecialchars($image, ENT_QUOTES).
'"/></p>';
487 $descriptionhtml .= $description;
489 fwrite($fichier,
"<description>".
rssCdata($descriptionhtml).
"</description>\n");
492 fwrite($fichier,
"<pubDate>".
date(
"r", $startdate).
"</pubDate>\n");
493 if ($useurlforguid) {
494 fwrite($fichier,
'<guid isPermaLink="true">'.
rssUrl($url).
'</guid>'.
"\n");
496 fwrite($fichier,
'<guid isPermaLink="false">'.
rssCdata(str_pad($uid, 10,
"0", STR_PAD_LEFT)).
'</guid>'.
"\n");
498 fwrite($fichier,
'<source url="'.
rssUrl($url).
'"><![CDATA[Dolibarr]]></source>'.
"\n");
499 fwrite($fichier,
"</item>\n");
503 fwrite($fichier,
"</channel>");
504 fwrite($fichier,
"\n");
505 fwrite($fichier,
"</rss>");
524 $string = (string) preg_replace(
'/[\x00-\x08\x0B\x0C\x0E-\x1F]/',
'', $string);
526 return '<![CDATA['.str_replace(
']]>',
']]]]><![CDATA[>', $string).
']]>';
538 $url = (string) preg_replace(
'/[\x00-\x1F\x7F]/',
'', $url);
539 $url = (string) preg_replace(
'/&(?!amp;|lt;|gt;|quot;|apos;)/',
'&', $url);
541 return str_replace(array(
'"',
"'",
'<',
'>'), array(
'"',
''',
'<',
'>'), $url);
553 $newstring = $string;
555 if ($format ===
"vcal") {
559 if ($format ===
"ical") {
562 $newstring = str_replace(array(
"\\",
";",
",",
"\r\n",
"\n\r",
"\r",
"\n"), array(
"\\\\",
"\\;",
"\\,",
"\\n",
"\\n",
"\\n",
"\\n"), $newstring);
578 while (strlen($line) > 75) {
580 while ($cut > 0 && (ord($line[$cut]) & 0xC0) == 0x80) {
583 $out .= substr($line, 0, $cut).
"\r\n";
584 $line =
" ".substr($line, $cut);
604 if (function_exists(
"mb_strlen")) {
605 $strlength = mb_strlen($line,
"UTF-8");
607 for ($j = 0; $j < $strlength; $j++) {
611 if ((mb_strlen($newpara,
"UTF-8") + mb_strlen($char,
"UTF-8")) >= 75) {
613 $out .= $newpara.
"\r\n ";
625 for ($j = 0; $j < $strlength; $j++) {
627 $char = substr($line, $j, 1);
631 $out .= $newpara.
"\r\n ";
655 $lines = preg_split(
"/\r\n/", $str);
658 foreach ($lines as $line) {
662 $strlength = strlen($line);
664 for ($j = 0; $j < $strlength; $j++) {
665 $char = substr($line, $j, 1);
668 if ($ascii < 32 || $ascii === 61 || $ascii > 126) {
669 $char =
"=".strtoupper(sprintf(
"%02X", $ascii));
673 if ((strlen($newpara) + strlen($char)) >= 76) {
675 $out .= $newpara.
"=\r\n";
701 return trim(quoted_printable_decode(preg_replace(
"/=\r?\n/",
"", $str)));
global $dolibarr_main_url_root
getImageFromHtmlContent($htmlContent, $imageNumber=1)
Return the URL of an image found into a HTML content.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0, $tz='')
Add a delay to a date.
dol_now($mode='gmt')
Return date for now.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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.
getRootURLFromURL($url)
Function root url from a long url For example: https://www.abc.mydomain.com/dir/page....
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
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...
build_rssfile($format, $title, $desc, $events_array, $outputfile, $filter='', $url='', $langcode='', $useurlforguid=false)
Build a file from an array of events.
rssUrl($url)
Return an URL ready to be written in a XML file, as a text or as an attribute value.
calFoldLine($line)
Fold a line of an iCal file as RFC 5545 section 3.1 asks: no more than 75 octets per line,...
format_cal($format, $string)
Encode for cal export.
calEncode($line)
Cut string after 75 chars.
rssCdata($string)
Return a text as a CDATA section of a XML file.
quotedPrintDecode($str)
Decode vcal format.