dolibarr  20.0.0-beta
website.lib.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4  * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
34 function dolStripPhpCode($str, $replacewith = '')
35 {
36  $str = str_replace('<?=', '<?php', $str);
37 
38  $newstr = '';
39 
40  // Split on each opening tag
41  //$parts = explode('<?php', $str);
42  $parts = preg_split('/'.preg_quote('<?php', '/').'/i', $str);
43 
44  if (!empty($parts)) {
45  $i = 0;
46  foreach ($parts as $part) {
47  if ($i == 0) { // The first part is never php code
48  $i++;
49  $newstr .= $part;
50  continue;
51  }
52  // The second part is the php code. We split on closing tag
53  $partlings = explode('?>', $part);
54  if (!empty($partlings)) {
55  //$phppart = $partlings[0];
56  //remove content before closing tag
57  if (count($partlings) > 1) {
58  $partlings[0] = ''; // Todo why a count > 1 and not >= 1 ?
59  }
60  //append to out string
61  //$newstr .= '<span class="phptag" class="tooltip" title="'.dol_escape_htmltag(dolGetFirstLineOfText($phppart).'...').'">'.$replacewith.'<!-- '.$phppart.' --></span>'.implode('', $partlings);
62  //$newstr .= '<span>'.$replacewith.'<!-- '.$phppart.' --></span>'.implode('', $partlings);
63  $newstr .= '<span phptag>'.$replacewith.'</span>'.implode('', $partlings);
64  //$newstr .= $replacewith.implode('', $partlings);
65  }
66  }
67  }
68  return $newstr;
69 }
70 
78 function dolKeepOnlyPhpCode($str)
79 {
80  $str = str_replace('<?=', '<?php', $str);
81  $str = str_replace('<?php', '__LTINTPHP__', $str);
82  $str = str_replace('<?', '<?php', $str); // replace the short_open_tag. It is recommended to set this is Off in php.ini
83  $str = str_replace('__LTINTPHP__', '<?php', $str);
84 
85  $newstr = '';
86 
87  // Split on each opening tag
88  //$parts = explode('<?php', $str);
89  $parts = preg_split('/'.preg_quote('<?php', '/').'/i', $str);
90 
91  if (!empty($parts)) {
92  $i = 0;
93  foreach ($parts as $part) {
94  if ($i == 0) { // The first part is never php code
95  $i++;
96  continue;
97  }
98  $newstr .= '<?php';
99  //split on closing tag
100  $partlings = explode('?>', $part, 2);
101  if (!empty($partlings)) {
102  $newstr .= $partlings[0].'?>';
103  } else {
104  $newstr .= $part.'?>';
105  }
106  }
107  }
108  return $newstr;
109 }
110 
123 function dolWebsiteReplacementOfLinks($website, $content, $removephppart = 0, $contenttype = 'html', $containerid = 0)
124 {
125  $nbrep = 0;
126 
127  dol_syslog('dolWebsiteReplacementOfLinks start (contenttype='.$contenttype." containerid=".$containerid." USEDOLIBARREDITOR=".(defined('USEDOLIBARREDITOR') ? '1' : '')." USEDOLIBARRSERVER=".(defined('USEDOLIBARRSERVER') ? '1' : '').')', LOG_DEBUG);
128  //if ($contenttype == 'html') { print $content;exit; }
129 
130  // Replace php code. Note $content may come from database and does not contain body tags.
131  $replacewith = '...php...';
132  if ($removephppart) {
133  $replacewith = '';
134  }
135  $content = preg_replace('/value="<\?php((?!\?>).)*\?>\n*/ims', 'value="'.$replacewith.'"', $content);
136 
137  $replacewith = '"callto=#';
138  if ($removephppart) {
139  $replacewith = '';
140  }
141  $content = preg_replace('/"callto:<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content);
142 
143  $replacewith = '"mailto=#';
144  if ($removephppart) {
145  $replacewith = '';
146  }
147  $content = preg_replace('/"mailto:<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content);
148 
149  $replacewith = 'src="php';
150  if ($removephppart) {
151  $replacewith = '';
152  }
153  $content = preg_replace('/src="<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content);
154 
155  $replacewith = 'href="php';
156  if ($removephppart) {
157  $replacewith = '';
158  }
159  $content = preg_replace('/href="<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content);
160 
161  //$replacewith='<span class="phptag">...php...</span>';
162  $replacewith = '...php...';
163  if ($removephppart) {
164  $replacewith = '';
165  }
166  //$content = preg_replace('/<\?php((?!\?toremove>).)*\?toremove>\n*/ims', $replacewith, $content);
167  /*if ($content === null) {
168  if (preg_last_error() == PREG_JIT_STACKLIMIT_ERROR) $content = 'preg_replace error (when removing php tags) PREG_JIT_STACKLIMIT_ERROR';
169  }*/
170  $content = dolStripPhpCode($content, $replacewith);
171 
172  // Protect the link styles.css.php to any replacement that we make after.
173  $content = str_replace('href="styles.css.php', 'href="!~!~!~styles.css.php', $content);
174  $content = str_replace('src="javascript.js.php', 'src="!~!~!~javascript.js.php', $content);
175  $content = str_replace('href="http', 'href="!~!~!~http', $content);
176  $content = str_replace('xlink:href="', 'xlink:href="!~!~!~', $content);
177  $content = str_replace('href="//', 'href="!~!~!~//', $content);
178  $content = str_replace('src="//', 'src="!~!~!~//', $content);
179  $content = str_replace('src="viewimage.php', 'src="!~!~!~/viewimage.php', $content);
180  $content = str_replace('src="/viewimage.php', 'src="!~!~!~/viewimage.php', $content);
181  $content = str_replace('src="'.DOL_URL_ROOT.'/viewimage.php', 'src="!~!~!~'.DOL_URL_ROOT.'/viewimage.php', $content);
182  $content = str_replace('href="document.php', 'href="!~!~!~/document.php', $content);
183  $content = str_replace('href="/document.php', 'href="!~!~!~/document.php', $content);
184  $content = str_replace('href="'.DOL_URL_ROOT.'/document.php', 'href="!~!~!~'.DOL_URL_ROOT.'/document.php', $content);
185 
186  // Replace relative link '/' with dolibarr URL
187  $content = preg_replace('/(href=")\/(#[^\"<>]*)?\"/', '\1!~!~!~'.DOL_URL_ROOT.'/website/index.php?website='.$website->ref.'&pageid='.$website->fk_default_home.'\2"', $content, -1, $nbrep);
188  // Replace relative link /xxx.php#aaa or /xxx.php with dolibarr URL (we discard param ?...)
189  $content = preg_replace('/(href=")\/?([^:\"\!]*)\.php(#[^\"<>]*)?\"/', '\1!~!~!~'.DOL_URL_ROOT.'/website/index.php?website='.$website->ref.'&pageref=\2\3"', $content, -1, $nbrep);
190  // Replace relative link /xxx.php?a=b&c=d#aaa or /xxx.php?a=b&c=d with dolibarr URL
191  $content = preg_replace('/(href=")\/?([^:\"\!]*)\.php\?([^#\"<>]*)(#[^\"<>]*)?\"/', '\1!~!~!~'.DOL_URL_ROOT.'/website/index.php?website='.$website->ref.'&pageref=\2&\3\4"', $content, -1, $nbrep);
192 
193  // Fix relative link into medias with correct URL after the DOL_URL_ROOT: ../url("medias/
194  $content = preg_replace('/url\‍((["\']?)\/?medias\//', 'url(\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
195  $content = preg_replace('/data-slide-bg=(["\']?)\/?medias\//', 'data-slide-bg=\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
196 
197  // <img src="medias/...image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png...
198  // <img src="...image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png...
199  $content = preg_replace('/(<img[^>]*src=")\/?medias\//', '\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
200  // <img src="image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png...
201  $content = preg_replace('/(<img[^>]*src=")\/?([^:\"\!]+)\"/', '\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=\2"', $content, -1, $nbrep);
202  // <img src="viewimage.php/modulepart=medias&file=image.png" => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png"
203  $content = preg_replace('/(<img[^>]*src=")(\/?viewimage\.php)/', '\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php', $content, -1, $nbrep);
204 
205  // action="newpage.php" => action="dolibarr/website/index.php?website=...&pageref=newpage
206  $content = preg_replace('/(action=")\/?([^:\"]*)(\.php\")/', '\1!~!~!~'.DOL_URL_ROOT.'/website/index.php?website='.$website->ref.'&pageref=\2"', $content, -1, $nbrep);
207 
208  // Fix relative link /document.php with correct URL after the DOL_URL_ROOT: ...href="/document.php?modulepart="
209  $content = preg_replace('/(href=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1!~!~!~'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
210  $content = preg_replace('/(src=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1!~!~!~'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
211 
212  // Fix relative link /viewimage.php with correct URL after the DOL_URL_ROOT: ...href="/viewimage.php?modulepart="
213  $content = preg_replace('/(url\‍(")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1!~!~!~'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
214 
215  // Fix relative URL
216  $content = str_replace('src="!~!~!~/viewimage.php', 'src="!~!~!~'.DOL_URL_ROOT.'/viewimage.php', $content);
217  $content = str_replace('href="!~!~!~/document.php', 'href="!~!~!~'.DOL_URL_ROOT.'/document.php', $content);
218  // Remove the protection tag !~!~!~
219  $content = str_replace('!~!~!~', '', $content);
220 
221  dol_syslog('dolWebsiteReplacementOfLinks end', LOG_DEBUG);
222  //if ($contenttype == 'html') { print $content;exit; }
223 
224  return $content;
225 }
226 
234 {
235  $map = array(
236  ":face_with_tears_of_joy:" => "\xF0\x9F\x98\x82",
237  ":grinning_face_with_smiling_eyes:" => "\xF0\x9F\x98\x81",
238  ":smiling_face_with_open_mouth:" => "\xF0\x9F\x98\x83",
239  ":smiling_face_with_open_mouth_and_cold_sweat:" => "\xF0\x9F\x98\x85",
240  ":smiling_face_with_open_mouth_and_tightly_closed_eyes:" => "\xF0\x9F\x98\x86",
241  ":winking_face:" => "\xF0\x9F\x98\x89",
242  ":smiling_face_with_smiling_eyes:" => "\xF0\x9F\x98\x8A",
243  ":face_savouring_delicious_food:" => "\xF0\x9F\x98\x8B",
244  ":relieved_face:" => "\xF0\x9F\x98\x8C",
245  ":smiling_face_with_heart_shaped_eyes:" => "\xF0\x9F\x98\x8D",
246  ":smiling_face_with_sunglasses:" => "\xF0\x9F\x98\x8E",
247  ":smirking_face:" => "\xF0\x9F\x98\x8F",
248  ":neutral_face:" => "\xF0\x9F\x98\x90",
249  ":expressionless_face:" => "\xF0\x9F\x98\x91",
250  ":unamused_face:" => "\xF0\x9F\x98\x92",
251  ":face_with_cold_sweat:" => "\xF0\x9F\x98\x93",
252  ":pensive_face:" => "\xF0\x9F\x98\x94",
253  ":confused_face:" => "\xF0\x9F\x98\x95",
254  ":confounded_face:" => "\xF0\x9F\x98\x96",
255  ":kissing_face:" => "\xF0\x9F\x98\x97",
256  ":face_throwing_a_kiss:" => "\xF0\x9F\x98\x98",
257  ":kissing_face_with_smiling_eyes:" => "\xF0\x9F\x98\x99",
258  ":kissing_face_with_closed_eyes:" => "\xF0\x9F\x98\x9A",
259  ":face_with_stuck_out_tongue:" => "\xF0\x9F\x98\x9B",
260  ":face_with_stuck_out_tongue_and_winking_eye:" => "\xF0\x9F\x98\x9C",
261  ":face_with_stuck_out_tongue_and_tightly_closed_eyes:" => "\xF0\x9F\x98\x9D",
262  ":disappointed_face:" => "\xF0\x9F\x98\x9E",
263  ":worried_face:" => "\xF0\x9F\x98\x9F",
264  ":angry_face:" => "\xF0\x9F\x98\xA0",
265  ":face_with_symbols_on_mouth:" => "\xF0\x9F\x98\xA1",
266  );
267  foreach ($map as $key => $value) {
268  $content = str_replace($key, $value, $content);
269  }
270  return $content;
271 }
272 
273 
284 function dolWebsiteOutput($content, $contenttype = 'html', $containerid = 0)
285 {
286  global $db, $langs, $conf, $user;
287  global $dolibarr_main_url_root, $dolibarr_main_data_root;
288  global $website;
289  global $includehtmlcontentopened;
290 
291  $nbrep = 0;
292 
293  dol_syslog("dolWebsiteOutput start - contenttype=".$contenttype." containerid=".$containerid." USEDOLIBARREDITOR=".(defined('USEDOLIBARREDITOR') ? '1' : '')." USEDOLIBARRSERVER=".(defined('USEDOLIBARRSERVER') ? '1' : '').' includehtmlcontentopened='.$includehtmlcontentopened);
294 
295  //print $containerid.' '.$content;
296 
297  // Define $urlwithroot
298  $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
299  $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
300  //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
301 
302  if (defined('USEDOLIBARREDITOR')) { // REPLACEMENT OF LINKS When page called from Dolibarr editor
303  // We remove the <head> part of content
304  if ($contenttype == 'html') {
305  $content = preg_replace('/<head>.*<\/head>/ims', '', $content);
306  $content = preg_replace('/^.*<body(\s[^>]*)*>/ims', '', $content);
307  $content = preg_replace('/<\/body(\s[^>]*)*>.*$/ims', '', $content);
308  }
309  } elseif (defined('USEDOLIBARRSERVER')) { // REPLACEMENT OF LINKS When page called from Dolibarr server
310  $content = str_replace('<link rel="stylesheet" href="/styles.css', '<link rel="stylesheet" href="styles.css', $content);
311  $content = str_replace(' async src="/javascript.js', ' async src="javascript.js', $content);
312 
313  // Protect the link styles.css.php to any replacement that we make after.
314  $content = str_replace('href="styles.css.php', 'href="!~!~!~styles.css.php', $content);
315  $content = str_replace('src="javascript.css.php', 'src="!~!~!~javascript.css.php', $content);
316  $content = str_replace('href="http', 'href="!~!~!~http', $content);
317  $content = str_replace('xlink:href="', 'xlink:href="!~!~!~', $content);
318  $content = str_replace('href="//', 'href="!~!~!~//', $content);
319  $content = str_replace('src="//', 'src="!~!~!~//', $content);
320  $content = str_replace(array('src="viewimage.php', 'src="/viewimage.php'), 'src="!~!~!~/viewimage.php', $content);
321  $content = str_replace('src="'.DOL_URL_ROOT.'/viewimage.php', 'src="!~!~!~'.DOL_URL_ROOT.'/viewimage.php', $content);
322  $content = str_replace(array('href="document.php', 'href="/document.php'), 'href="!~!~!~/document.php', $content);
323  $content = str_replace('href="'.DOL_URL_ROOT.'/document.php', 'href="!~!~!~'.DOL_URL_ROOT.'/document.php', $content);
324 
325  // Replace relative link / with dolibarr URL: ...href="/"...
326  $content = preg_replace('/(href=")\/\"/', '\1!~!~!~'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'"', $content, -1, $nbrep);
327  // Replace relative link /xxx.php#aaa or /xxx.php with dolibarr URL: ...href="....php" (we discard param ?...)
328  $content = preg_replace('/(href=")\/?([^:\"\!]*)\.php(#[^\"<>]*)?\"/', '\1!~!~!~'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2\3"', $content, -1, $nbrep);
329  // Replace relative link /xxx.php?a=b&c=d#aaa or /xxx.php?a=b&c=d with dolibarr URL
330  // Warning: we may replace twice if href="..." was inside an include (dolWebsiteOutput called by include and the by final page), that's why
331  // at end we replace the '!~!~!~' only if we are in final parent page.
332  $content = preg_replace('/(href=")\/?([^:\"\!]*)\.php\?([^#\"<>]*)(#[^\"<>]*)?\"/', '\1!~!~!~'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2&\3\4"', $content, -1, $nbrep);
333  // Replace occurrence like _service_page_XXX.php with dolibarr URL
334  $content = preg_replace('/([\'"])_service_page_([^\'"]+)\.php\1/', '\1!~!~!~' . DOL_URL_ROOT . '/public/website/index.php?website=' . $website->ref . '&pageref=_service_page_\2\1', $content, -1, $nbrep);
335  // Replace occurrence like _library_page_XXX.php with dolibarr URL
336  $content = preg_replace('/([\'"])_library_page_([^\'"]+)\.php\1/', '\1!~!~!~' . DOL_URL_ROOT . '/public/website/index.php?website=' . $website->ref . '&pageref=_library_page_\2\1', $content, -1, $nbrep);
337  // Replace relative link without .php like /xxx#aaa or /xxx with dolibarr URL: ...href="....php"
338  $content = preg_replace('/(href=")\/?([a-zA-Z0-9\-_#]+)(\"|\?)/', '\1!~!~!~'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2\3', $content, -1, $nbrep);
339 
340  // Fix relative link /document.php with correct URL after the DOL_URL_ROOT: href="/document.php?modulepart=" => href="/dolibarr/document.php?modulepart="
341  $content = preg_replace('/(href=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1!~!~!~'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
342  $content = preg_replace('/(src=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1!~!~!~'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
343 
344  // Fix relative link /viewimage.php with correct URL after the DOL_URL_ROOT: href="/viewimage.php?modulepart=" => href="/dolibarr/viewimage.php?modulepart="
345  $content = preg_replace('/(href=")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1!~!~!~'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
346  $content = preg_replace('/(src=")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1!~!~!~'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
347  $content = preg_replace('/(url\‍(")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1!~!~!~'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
348 
349  // Fix relative link into medias with correct URL after the DOL_URL_ROOT: ../url("medias/
350  $content = preg_replace('/url\‍((["\']?)\/?medias\//', 'url(\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
351  $content = preg_replace('/data-slide-bg=(["\']?)\/?medias\//', 'data-slide-bg=\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
352 
353  // <img src="medias/...image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png...
354  // <img src="...image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png...
355  $content = preg_replace('/(<img[^>]*src=")\/?medias\//', '\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
356  // <img src="image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png...
357  $content = preg_replace('/(<img[^>]*src=")\/?([^:\"\!]+)\"/', '\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=\2"', $content, -1, $nbrep);
358  // <img src="viewimage.php/modulepart=medias&file=image.png" => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png"
359  $content = preg_replace('/(<img[^>]*src=")(\/?viewimage\.php)/', '\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php', $content, -1, $nbrep);
360 
361  // action="newpage.php" => action="dolibarr/website/index.php?website=...&pageref=newpage
362  $content = preg_replace('/(action=")\/?([^:\"]*)(\.php\")/', '\1!~!~!~'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2"', $content, -1, $nbrep);
363 
364  // Fix relative URL
365  $content = str_replace('src="!~!~!~/viewimage.php', 'src="!~!~!~'.DOL_URL_ROOT.'/viewimage.php', $content);
366  $content = str_replace('href="!~!~!~/document.php', 'href="!~!~!~'.DOL_URL_ROOT.'/document.php', $content);
367 
368  // Remove the protection tag !~!~!~, but only if this is the parent page and not an include
369  if (empty($includehtmlcontentopened)) {
370  $content = str_replace('!~!~!~', '', $content);
371  }
372  } else { // REPLACEMENT OF LINKS When page called from virtual host web server
373  $symlinktomediaexists = 1;
374  if ($website->virtualhost) {
375  $content = preg_replace('/^(<link[^>]*rel="canonical" href=")\//m', '\1'.$website->virtualhost.'/', $content, -1, $nbrep);
376  }
377  //print 'rrrrrrrrr'.$website->virtualhost.$content;
378 
379 
380  // Make a change into HTML code to allow to include images from medias directory correct with direct link for virtual server
381  // <img alt="" src="/dolibarr_dev/htdocs/viewimage.php?modulepart=medias&amp;entity=1&amp;file=image/ldestailleur_166x166.jpg" style="height:166px; width:166px" />
382  // become
383  // <img alt="" src="'.$urlwithroot.'/medias/image/ldestailleur_166x166.jpg" style="height:166px; width:166px" />
384  if (!$symlinktomediaexists) {
385  // <img src="image.png... => <img src="medias/image.png...
386  $content = preg_replace('/(<img[^>]*src=")\/?image\//', '\1/wrapper.php?modulepart=medias&file=medias/image/', $content, -1, $nbrep);
387  $content = preg_replace('/(url\‍(["\']?)\/?image\//', '\1/wrapper.php?modulepart=medias&file=medias/image/', $content, -1, $nbrep);
388 
389  $content = preg_replace('/(<script[^>]*src=")[^\"]*document\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep);
390  $content = preg_replace('/(<a[^>]*href=")[^\"]*document\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep);
391 
392  $content = preg_replace('/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep);
393  $content = preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep);
394  $content = preg_replace('/(url\‍(["\']?)[^\‍)]*viewimage\.php([^\‍)]*)modulepart=medias([^\‍)]*)file=([^\‍)]*)(["\']?\‍))/', '\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep);
395 
396  $content = preg_replace('/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep);
397  $content = preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep);
398  $content = preg_replace('/(url\‍(["\']?)[^\‍)]*viewimage\.php([^\‍)]*)hashp=([^\‍)]*)(["\']?\‍))/', '\1/wrapper.php\2hashp\3\4', $content, -1, $nbrep);
399 
400  $content = preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=mycompany([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=mycompany\3file=\4\5', $content, -1, $nbrep);
401 
402  // If some links to documents or viewimage remains, we replace with wrapper
403  $content = preg_replace('/(<img[^>]*src=")\/?viewimage\.php/', '\1/wrapper.php', $content, -1, $nbrep);
404  $content = preg_replace('/(<a[^>]*href=")\/?documents\.php/', '\1/wrapper.php', $content, -1, $nbrep);
405  } else {
406  // <img src="image.png... => <img src="medias/image.png...
407  $content = preg_replace('/(<img[^>]*src=")\/?image\//', '\1/medias/image/', $content, -1, $nbrep);
408  $content = preg_replace('/(url\‍(["\']?)\/?image\//', '\1/medias/image/', $content, -1, $nbrep);
409 
410  $content = preg_replace('/(<script[^>]*src=")[^\"]*document\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/medias/\4\5', $content, -1, $nbrep);
411  $content = preg_replace('/(<a[^>]*href=")[^\"]*document\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/medias/\4\5', $content, -1, $nbrep);
412 
413  $content = preg_replace('/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/medias/\4\5', $content, -1, $nbrep);
414  $content = preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/medias/\4\5', $content, -1, $nbrep);
415  $content = preg_replace('/(url\‍(["\']?)[^\‍)]*viewimage\.php([^\‍)]*)modulepart=medias([^\‍)]*)file=([^\‍)]*)(["\']?\‍))/', '\1/medias/\4\5', $content, -1, $nbrep);
416 
417  $content = preg_replace('/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep);
418  $content = preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep);
419  $content = preg_replace('/(url\‍(["\']?)[^\‍)]*viewimage\.php([^\‍)]*)hashp=([^\‍)]*)(["\']?\‍))/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep);
420 
421  $content = preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=mycompany([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=mycompany\3file=\4\5', $content, -1, $nbrep);
422 
423  // If some links to documents or viewimage remains, we replace with wrapper
424  $content = preg_replace('/(<img[^>]*src=")\/?viewimage\.php/', '\1/wrapper.php', $content, -1, $nbrep);
425  $content = preg_replace('/(<a[^>]*href=")\/?document\.php/', '\1/wrapper.php', $content, -1, $nbrep);
426  }
427  }
428 
429  if (!defined('USEDOLIBARREDITOR')) {
430  $content = str_replace(' contenteditable="true"', ' contenteditable="false"', $content);
431  }
432 
433  if (getDolGlobalString('WEBSITE_ADD_CSS_TO_BODY')) {
434  $content = str_replace('<body id="bodywebsite" class="bodywebsite', '<body id="bodywebsite" class="bodywebsite ' . getDolGlobalString('WEBSITE_ADD_CSS_TO_BODY'), $content);
435  }
436 
437  $content = dolReplaceSmileyCodeWithUTF8($content);
438 
439  dol_syslog("dolWebsiteOutput end");
440 
441  print $content;
442 }
443 
452 function dolWebsiteIncrementCounter($websiteid, $websitepagetype, $websitepageid)
453 {
454  if (!getDolGlobalInt('WEBSITE_PERF_DISABLE_COUNTERS')) {
455  //dol_syslog("dolWebsiteIncrementCounter websiteid=".$websiteid." websitepagetype=".$websitepagetype." websitepageid=".$websitepageid);
456  if (in_array($websitepagetype, array('blogpost', 'page'))) {
457  global $db;
458 
459  $tmpnow = dol_getdate(dol_now('gmt'), true, 'gmt');
460 
461  $sql = "UPDATE ".$db->prefix()."website SET ";
462  $sql .= " pageviews_total = pageviews_total + 1,";
463  $sql .= " pageviews_month = pageviews_month + 1,";
464  // if last access was done during previous month, we save pageview_month into pageviews_previous_month
465  $sql .= " pageviews_previous_month = ".$db->ifsql("lastaccess < '".$db->idate(dol_mktime(0, 0, 0, $tmpnow['mon'], 1, $tmpnow['year'], 'gmt', 0), 'gmt')."'", 'pageviews_month', 'pageviews_previous_month').",";
466  $sql .= " lastaccess = '".$db->idate(dol_now('gmt'), 'gmt')."',";
467  $sql .= " lastpageid = ".((int) $websitepageid);
468  $sql .= " WHERE rowid = ".((int) $websiteid);
469 
470  $resql = $db->query($sql);
471  if (! $resql) {
472  return -1;
473  }
474  }
475  }
476 
477  return 1;
478 }
479 
480 
488 /*
489 function dolWebsiteSaveContent($content)
490 {
491  global $db, $langs, $conf, $user;
492  global $dolibarr_main_url_root, $dolibarr_main_data_root;
493 
494  //dol_syslog("dolWebsiteSaveContent start (mode=".(defined('USEDOLIBARRSERVER')?'USEDOLIBARRSERVER':'').')');
495 
496  // Define $urlwithroot
497  $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
498  $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
499  //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
500 
501  //$content = preg_replace('/(<img.*src=")(?!(http|'.preg_quote(DOL_URL_ROOT,'/').'\/viewimage))/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
502 
503  return $content;
504 }
505 */
506 
507 
518 function redirectToContainer($containerref, $containeraliasalt = '', $containerid = 0, $permanent = 0, $parameters = array())
519 {
520  global $db, $website;
521 
522  $newurl = '';
523  $result = 0;
524 
525  // We make redirect using the alternative alias, we must find the real $containerref
526  if ($containeraliasalt) {
527  include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
528  $tmpwebsitepage = new WebsitePage($db);
529  // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
530  $result = $tmpwebsitepage->fetch(0, $website->id, '', $containeraliasalt);
531  if ($result > 0) {
532  $containerref = $tmpwebsitepage->pageurl;
533  } else {
534  print "Error, page contains a redirect to the alternative alias '".$containeraliasalt."' that does not exists in web site (".$website->id." / ".$website->ref.")";
535  exit;
536  }
537  }
538 
539  if (defined('USEDOLIBARREDITOR')) {
540  /*print '<div class="margintoponly marginleftonly">';
541  print "This page contains dynamic code that make a redirect to '".$containerref."' in your current context. Redirect has been canceled as it is not supported in edition mode.";
542  print '</div>';*/
543  $text = "This page contains dynamic code that make a redirect to '".$containerref."' in your current context. Redirect has been canceled as it is not supported in edition mode.";
544  setEventMessages($text, null, 'warnings', 'WEBSITEREDIRECTDISABLED'.$containerref);
545  return;
546  }
547 
548  if (defined('USEDOLIBARRSERVER')) { // When page called from Dolibarr server
549  // Check new container exists
550  if (!$containeraliasalt) { // If containeraliasalt set, we already did the test
551  include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
552  $tmpwebsitepage = new WebsitePage($db);
553  // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
554  $result = $tmpwebsitepage->fetch(0, $website->id, $containerref);
555  unset($tmpwebsitepage);
556  }
557  if ($result > 0) {
558  $currenturi = $_SERVER["REQUEST_URI"]; // Example: /public/website/index.php?website=mywebsite.com&pageref=mywebsite-home&nocache=1708177483
559  $regtmp = array();
560  if (preg_match('/&pageref=([^&]+)/', $currenturi, $regtmp)) {
561  if ($regtmp[0] == $containerref) {
562  print "Error, page with uri '.$currenturi.' try a redirect to the same alias page '".$containerref."' in web site '".$website->ref."'";
563  exit;
564  } else {
565  $newurl = preg_replace('/&pageref=([^&]+)/', '&pageref='.$containerref, $currenturi);
566  }
567  } else {
568  $newurl = $currenturi.'&pageref='.urlencode($containerref);
569  }
570  }
571  } else { // When page called from virtual host server
572  $newurl = '/'.$containerref.'.php';
573  $newurl = $newurl.(empty($_SERVER["QUERY_STRING"]) ? '' : '?'.$_SERVER["QUERY_STRING"]);
574  }
575 
576  if ($newurl) {
577  if (!empty($parameters)) {
578  $separator = (parse_url($newurl, PHP_URL_QUERY) == null) ? '?' : '&';
579  $newurl = $newurl . $separator . http_build_query($parameters);
580  }
581  if ($permanent) {
582  header("Status: 301 Moved Permanently", false, 301);
583  }
584  header("Location: ".$newurl);
585  exit;
586  } else {
587  print "Error, page contains a redirect to the alias page '".$containerref."' that does not exists in web site (".$website->id." / ".$website->ref.")";
588  exit;
589  }
590 }
591 
592 
600 function includeContainer($containerref)
601 {
602  global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs; // Very important. Required to have var available when running included containers.
603  global $includehtmlcontentopened;
604  global $websitekey, $websitepagefile;
605 
606  $MAXLEVEL = 20;
607 
608  if (!preg_match('/\.php$/i', $containerref)) {
609  $containerref .= '.php';
610  }
611 
612  $fullpathfile = DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$websitekey.'/'.$containerref;
613 
614  if (empty($includehtmlcontentopened)) {
615  $includehtmlcontentopened = 0;
616  }
617  $includehtmlcontentopened++;
618  if ($includehtmlcontentopened > $MAXLEVEL) {
619  print 'ERROR: RECURSIVE CONTENT LEVEL. Depth of recursive call is more than the limit of '.((int) $MAXLEVEL).".\n";
620  return;
621  }
622 
623  //dol_syslog("Include container ".$containerref.' includehtmlcontentopened='.$includehtmlcontentopened);
624 
625  // file_get_contents is not possible. We must execute code with include
626  //$content = file_get_contents($fullpathfile);
627  //print preg_replace(array('/^.*<body[^>]*>/ims','/<\/body>.*$/ims'), array('', ''), $content);*/
628 
629  ob_start();
630  $res = @include $fullpathfile; // Include because we want to execute code content
631  $tmpoutput = ob_get_contents();
632  ob_end_clean();
633 
634  print "\n".'<!-- include '.$websitekey.'/'.$containerref.(is_object($websitepage) ? ' parent id='.$websitepage->id : '').' level = '.$includehtmlcontentopened.' -->'."\n";
635  print preg_replace(array('/^.*<body[^>]*>/ims', '/<\/body>.*$/ims'), array('', ''), $tmpoutput);
636 
637  if (!$res) {
638  print 'ERROR: FAILED TO INCLUDE PAGE '.$containerref.".\n";
639  }
640 
641  $includehtmlcontentopened--;
642 }
643 
654 function getStructuredData($type, $data = array())
655 {
656  global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs, $pagelangs; // Very important. Required to have var available when running included containers.
657 
658  $type = strtolower($type);
659 
660  if ($type == 'software') {
661  $ret = '<!-- Add structured data for entry in a software annuary -->'."\n";
662  $ret .= '<script nonce="'.getNonce().'" type="application/ld+json">'."\n";
663  $ret .= '{
664  "@context": "https://schema.org",
665  "@type": "SoftwareApplication",
666  "name": "'.dol_escape_json($data['name']).'",
667  "operatingSystem": "'.dol_escape_json($data['os']).'",
668  "applicationCategory": "https://schema.org/'.dol_escape_json($data['applicationCategory']).'",';
669  if (!empty($data['ratingcount'])) {
670  $ret .= '
671  "aggregateRating": {
672  "@type": "AggregateRating",
673  "ratingValue": "'.dol_escape_json($data['ratingvalue']).'",
674  "ratingCount": "'.dol_escape_json($data['ratingcount']).'"
675  },';
676  }
677  $ret .= '
678  "offers": {
679  "@type": "Offer",
680  "price": "'.dol_escape_json($data['price']).'",
681  "priceCurrency": "'.dol_escape_json($data['currency'] ? $data['currency'] : $conf->currency).'"
682  }
683  }'."\n";
684  $ret .= '</script>'."\n";
685  } elseif ($type == 'organization') {
686  $companyname = $mysoc->name;
687  $url = $mysoc->url;
688 
689  $ret = '<!-- Add structured data for organization -->'."\n";
690  $ret .= '<script nonce="'.getNonce().'" type="application/ld+json">'."\n";
691  $ret .= '{
692  "@context": "https://schema.org",
693  "@type": "Organization",
694  "name": "'.dol_escape_json(!empty($data['name']) ? $data['name'] : $companyname).'",
695  "url": "'.dol_escape_json(!empty($data['url']) ? $data['url'] : $url).'",
696  "logo": "'.($data['logo'] ? dol_escape_json($data['logo']) : '/wrapper.php?modulepart=mycompany&file=logos%2F'.urlencode($mysoc->logo)).'",
697  "contactPoint": {
698  "@type": "ContactPoint",
699  "contactType": "Contact",
700  "email": "'.dol_escape_json(!empty($data['email']) ? $data['email'] : $mysoc->email).'"
701  }'."\n";
702  if (is_array($mysoc->socialnetworks) && count($mysoc->socialnetworks) > 0) {
703  $ret .= ",\n";
704  $ret .= '"sameAs": [';
705  $i = 0;
706  foreach ($mysoc->socialnetworks as $key => $value) {
707  if ($key == 'linkedin') {
708  $ret .= '"https://www.'.$key.'.com/company/'.dol_escape_json($value).'"';
709  } elseif ($key == 'youtube') {
710  $ret .= '"https://www.'.$key.'.com/user/'.dol_escape_json($value).'"';
711  } else {
712  $ret .= '"https://www.'.$key.'.com/'.dol_escape_json($value).'"';
713  }
714  $i++;
715  if ($i < count($mysoc->socialnetworks)) {
716  $ret .= ', ';
717  }
718  }
719  $ret .= ']'."\n";
720  }
721  $ret .= '}'."\n";
722  $ret .= '</script>'."\n";
723  } elseif ($type == 'blogpost') {
724  if (!empty($websitepage->author_alias)) {
725  //include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
726  //$tmpuser = new User($db);
727  //$restmpuser = $tmpuser->fetch($websitepage->fk_user_creat);
728 
729  $pageurl = $websitepage->pageurl;
730  $title = $websitepage->title;
731  $image = $websitepage->image;
732  $companyname = $mysoc->name;
733  $description = $websitepage->description;
734 
735  $pageurl = str_replace('__WEBSITE_KEY__', $website->ref, $pageurl);
736  $title = str_replace('__WEBSITE_KEY__', $website->ref, $title);
737  $image = '/medias'.(preg_match('/^\//', $image) ? '' : '/').str_replace('__WEBSITE_KEY__', $website->ref, $image);
738  $companyname = str_replace('__WEBSITE_KEY__', $website->ref, $companyname);
739  $description = str_replace('__WEBSITE_KEY__', $website->ref, $description);
740 
741  $ret = '<!-- Add structured data for blog post -->'."\n";
742  $ret .= '<script nonce="'.getNonce().'" type="application/ld+json">'."\n";
743  $ret .= '{
744  "@context": "https://schema.org",
745  "@type": "NewsArticle",
746  "mainEntityOfPage": {
747  "@type": "WebPage",
748  "@id": "'.dol_escape_json($pageurl).'"
749  },
750  "headline": "'.dol_escape_json($title).'",
751  "image": [
752  "'.dol_escape_json($image).'"
753  ],
754  "dateCreated": "'.dol_print_date($websitepage->date_creation, 'dayhourrfc').'",
755  "datePublished": "'.dol_print_date($websitepage->date_creation, 'dayhourrfc').'",
756  "dateModified": "'.dol_print_date($websitepage->date_modification, 'dayhourrfc').'",
757  "author": {
758  "@type": "Person",
759  "name": "'.dol_escape_json($websitepage->author_alias).'"
760  },
761  "publisher": {
762  "@type": "Organization",
763  "name": "'.dol_escape_json($companyname).'",
764  "logo": {
765  "@type": "ImageObject",
766  "url": "/wrapper.php?modulepart=mycompany&file=logos%2F'.urlencode($mysoc->logo).'"
767  }
768  },'."\n";
769  if ($websitepage->keywords) {
770  $ret .= '"keywords": [';
771  $i = 0;
772  $arrayofkeywords = explode(',', $websitepage->keywords);
773  foreach ($arrayofkeywords as $keyword) {
774  $ret .= '"'.dol_escape_json($keyword).'"';
775  $i++;
776  if ($i < count($arrayofkeywords)) {
777  $ret .= ', ';
778  }
779  }
780  $ret .= '],'."\n";
781  }
782  $ret .= '"description": "'.dol_escape_json($description).'"';
783  $ret .= "\n".'}'."\n";
784  $ret .= '</script>'."\n";
785  } else {
786  $ret = '<!-- no structured data inserted inline inside blogpost because no author_alias defined -->'."\n";
787  }
788  } elseif ($type == 'product') {
789  $ret = '<!-- Add structured data for product -->'."\n";
790  $ret .= '<script nonce="'.getNonce().'" type="application/ld+json">'."\n";
791  $ret .= '{
792  "@context": "https://schema.org/",
793  "@type": "Product",
794  "name": "'.dol_escape_json($data['label']).'",
795  "image": [
796  "'.dol_escape_json($data['image']).'",
797  ],
798  "description": "'.dol_escape_json($data['description']).'",
799  "sku": "'.dol_escape_json($data['ref']).'",
800  "brand": {
801  "@type": "Thing",
802  "name": "'.dol_escape_json($data['brand']).'"
803  },
804  "author": {
805  "@type": "Person",
806  "name": "'.dol_escape_json($data['author']).'"
807  }
808  },
809  "offers": {
810  "@type": "Offer",
811  "url": "https://example.com/anvil",
812  "priceCurrency": "'.dol_escape_json($data['currency'] ? $data['currency'] : $conf->currency).'",
813  "price": "'.dol_escape_json($data['price']).'",
814  "itemCondition": "https://schema.org/UsedCondition",
815  "availability": "https://schema.org/InStock",
816  "seller": {
817  "@type": "Organization",
818  "name": "'.dol_escape_json($mysoc->name).'"
819  }
820  }
821  }'."\n";
822  $ret .= '</script>'."\n";
823  } elseif ($type == 'qa') {
824  $ret = '<!-- Add structured data for QA -->'."\n";
825  $ret .= '<script nonce="'.getNonce().'" type="application/ld+json">'."\n";
826  $ret .= '{
827  "@context": "https://schema.org/",
828  "@type": "QAPage",
829  "mainEntity": {
830  "@type": "Question",
831  "name": "'.dol_escape_json($data['name']).'",
832  "text": "'.dol_escape_json($data['name']).'",
833  "answerCount": 1,
834  "author": {
835  "@type": "Person",
836  "name": "'.dol_escape_json($data['author']).'"
837  }
838  "acceptedAnswer": {
839  "@type": "Answer",
840  "text": "'.dol_escape_json(dol_string_nohtmltag(dolStripPhpCode($data['description']))).'",
841  "author": {
842  "@type": "Person",
843  "name": "'.dol_escape_json($data['author']).'"
844  }
845  }
846  }
847  }'."\n";
848  $ret .= '</script>'."\n";
849  } else {
850  $ret = '';
851  }
852  return $ret;
853 }
854 
861 function getSocialNetworkHeaderCards($params = null)
862 {
863  global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs; // Very important. Required to have var available when running included containers.
864 
865  $out = '';
866 
867  if ($website->virtualhost) {
868  $pageurl = $websitepage->pageurl;
869  $title = $websitepage->title;
870  $image = $websitepage->image;
871  $companyname = $mysoc->name;
872  $description = $websitepage->description;
873 
874  $pageurl = str_replace('__WEBSITE_KEY__', $website->ref, $pageurl);
875  $title = str_replace('__WEBSITE_KEY__', $website->ref, $title);
876  $image = '/medias'.(preg_match('/^\//', $image) ? '' : '/').str_replace('__WEBSITE_KEY__', $website->ref, $image);
877  $companyname = str_replace('__WEBSITE_KEY__', $website->ref, $companyname);
878  $description = str_replace('__WEBSITE_KEY__', $website->ref, $description);
879 
880  $shortlangcode = '';
881  if ($websitepage->lang) {
882  $shortlangcode = substr($websitepage->lang, 0, 2); // en_US or en-US -> en
883  }
884  if (empty($shortlangcode)) {
885  $shortlangcode = substr($website->lang, 0, 2); // en_US or en-US -> en
886  }
887 
888  $fullurl = $website->virtualhost.'/'.$websitepage->pageurl.'.php';
889  $canonicalurl = $website->virtualhost.(($websitepage->id == $website->fk_default_home) ? '/' : (($shortlangcode != substr($website->lang, 0, 2) ? '/'.$shortlangcode : '').'/'.$websitepage->pageurl.'.php'));
890  $hashtags = trim(implode(' #', array_map('trim', explode(',', $websitepage->keywords))));
891 
892  // Open Graph
893  $out .= '<meta name="og:type" content="website">'."\n"; // TODO If blogpost, use type article
894  $out .= '<meta name="og:title" content="'.$websitepage->title.'">'."\n";
895  if ($websitepage->image) {
896  $out .= '<meta name="og:image" content="'.$website->virtualhost.$image.'">'."\n";
897  }
898  $out .= '<meta name="og:url" content="'.$canonicalurl.'">'."\n";
899 
900  // Twitter
901  $out .= '<meta name="twitter:card" content="summary">'."\n";
902  if (!empty($params) && !empty($params['twitter_account'])) {
903  $out .= '<meta name="twitter:site" content="@'.$params['twitter_account'].'">'."\n";
904  $out .= '<meta name="twitter:creator" content="@'.$params['twitter_account'].'">'."\n";
905  }
906  $out .= '<meta name="twitter:title" content="'.$websitepage->title.'">'."\n";
907  if ($websitepage->description) {
908  $out .= '<meta name="twitter:description" content="'.$websitepage->description.'">'."\n";
909  }
910  if ($websitepage->image) {
911  $out .= '<meta name="twitter:image" content="'.$website->virtualhost.$image.'">'."\n";
912  }
913  //$out .= '<meta name="twitter:domain" content="'.getDomainFromURL($website->virtualhost, 1).'">';
914  /*
915  $out .= '<meta name="twitter:app:name:iphone" content="">';
916  $out .= '<meta name="twitter:app:name:ipad" content="">';
917  $out .= '<meta name="twitter:app:name:googleplay" content="">';
918  $out .= '<meta name="twitter:app:url:iphone" content="">';
919  $out .= '<meta name="twitter:app:url:ipad" content="">';
920  $out .= '<meta name="twitter:app:url:googleplay" content="">';
921  $out .= '<meta name="twitter:app:id:iphone" content="">';
922  $out .= '<meta name="twitter:app:id:ipad" content="">';
923  $out .= '<meta name="twitter:app:id:googleplay" content="">';
924  */
925  }
926 
927  return $out;
928 }
929 
936 {
937  global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs; // Very important. Required to have var available when running included containers.
938 
939  $out = '<!-- section for social network sharing of page -->'."\n";
940 
941  if ($website->virtualhost) {
942  $fullurl = $website->virtualhost.'/'.$websitepage->pageurl.'.php';
943  $hashtags = trim(implode(' #', array_map('trim', explode(',', $websitepage->keywords))));
944 
945  $out .= '<div class="dol-social-share">'."\n";
946 
947  // Twitter
948  $out .= '<div class="dol-social-share-tw">'."\n";
949  $out .= '<a href="https://twitter.com/share" class="twitter-share-button" data-url="'.$fullurl.'" data-text="'.dol_escape_htmltag($websitepage->description).'" data-lang="'.$websitepage->lang.'" data-size="small" data-related="" data-hashtags="'.preg_replace('/^#/', '', $hashtags).'" data-count="horizontal">Tweet</a>';
950  $out .= '<script nonce="'.getNonce().'">!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?\'http\':\'https\';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+\'://platform.twitter.com/widgets.js\';fjs.parentNode.insertBefore(js,fjs);}}(document, \'script\', \'twitter-wjs\');</script>';
951  $out .= '</div>'."\n";
952 
953  // Reddit
954  $out .= '<div class="dol-social-share-reddit">'."\n";
955  $out .= '<a href="https://www.reddit.com/submit" target="_blank" rel="noopener noreferrer external" onclick="window.location = \'https://www.reddit.com/submit?url='.$fullurl.'\'; return false">';
956  $out .= '<span class="dol-social-share-reddit-span">Reddit</span>';
957  $out .= '</a>';
958  $out .= '</div>'."\n";
959 
960  // Facebook
961  $out .= '<div class="dol-social-share-fbl">'."\n";
962  $out .= '<div id="fb-root"></div>'."\n";
963  $out .= '<script nonce="'.getNonce().'">(function(d, s, id) {
964  var js, fjs = d.getElementsByTagName(s)[0];
965  if (d.getElementById(id)) return;
966  js = d.createElement(s); js.id = id;
967  js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.0&amp;appId=dolibarr.org";
968  fjs.parentNode.insertBefore(js, fjs);
969  }(document, \'script\', \'facebook-jssdk\'));</script>
970  <fb:like
971  href="'.$fullurl.'"
972  layout="button_count"
973  show_faces="false"
974  width="90"
975  colorscheme="light"
976  share="1"
977  action="like" ></fb:like>'."\n";
978  $out .= '</div>'."\n";
979 
980  $out .= "\n</div>\n";
981  } else {
982  $out .= '<!-- virtual host not defined in CMS. No way to add sharing buttons -->'."\n";
983  }
984  $out .= '<!-- section end for social network sharing of page -->'."\n";
985 
986  return $out;
987 }
988 
989 
998 {
999  global $db;
1000 
1001  $nb = 0;
1002 
1003  include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
1004  $regexforimg = getListOfPossibleImageExt(0);
1005  $regexforimg = '('.$regexforimg.')$';
1006 
1007  $sql = "SELECT COUNT(rowid) as nb";
1008  $sql .= " FROM ".MAIN_DB_PREFIX."ecm_files";
1009  $sql .= " WHERE entity IN (".getEntity($object->element).")";
1010  $sql .= " AND src_object_type = '".$db->escape($object->element)."' AND src_object_id = ".((int) $object->id); // Filter on object
1011  $sql .= " AND ".$db->regexpsql('filename', $regexforimg, 1);
1012  $sql .= " AND share IS NOT NULL"; // Only image that are public
1013 
1014  $resql = $db->query($sql);
1015  if ($resql) {
1016  $obj = $db->fetch_object($resql);
1017  if ($obj) {
1018  $nb = $obj->nb;
1019  }
1020  }
1021 
1022  return $nb;
1023 }
1024 
1034 function getImagePublicURLOfObject($object, $no = 1, $extName = '')
1035 {
1036  global $db;
1037 
1038  $image_path = '';
1039 
1040  include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
1041  $regexforimg = getListOfPossibleImageExt(0);
1042  $regexforimg = '('.$regexforimg.')$';
1043 
1044  $sql = "SELECT rowid, ref, share, filename, cover, position";
1045  $sql .= " FROM ".MAIN_DB_PREFIX."ecm_files";
1046  $sql .= " WHERE entity IN (".getEntity($object->element).")";
1047  $sql .= " AND src_object_type = '".$db->escape($object->element)."' AND src_object_id = ".((int) $object->id); // Filter on object
1048  $sql .= " AND ".$db->regexpsql('filename', $regexforimg, 1);
1049  $sql .= $db->order("cover,position,rowid", "ASC,ASC,ASC");
1050 
1051  $resql = $db->query($sql);
1052  if ($resql) {
1053  $num = $db->num_rows($resql);
1054  $i = 0;
1055  $found = 0;
1056  $foundnotshared = 0;
1057  while ($i < $num) {
1058  $obj = $db->fetch_object($resql);
1059  if ($obj) {
1060  if (empty($obj->share)) {
1061  $foundnotshared++;
1062  } else {
1063  $found++;
1064 
1065  if (defined('USEDOLIBARRSERVER') || defined('USEDOLIBARREDITOR')) {
1066  $image_path = DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($obj->share);
1067  } else {
1068  $image_path = '/wrapper.php?hashp='.urlencode($obj->share);
1069  }
1070  if ($extName) {
1071  //getImageFileNameForSize($dir.$file, '_small')
1072  $image_path .= '&extname='.urlencode($extName);
1073  }
1074  }
1075  }
1076  if ($found >= $no) {
1077  break;
1078  }
1079  $i++;
1080  }
1081  if (!$found && $foundnotshared) {
1082  if (defined('USEDOLIBARRSERVER') || defined('USEDOLIBARREDITOR')) {
1083  $image_path = DOL_URL_ROOT.'/viewimage.php?modulepart=common&file=nophotopublic.png';
1084  } else {
1085  $image_path = '/wrapper.php?modulepart=common&file=nophotopublic.png';
1086  }
1087  }
1088  }
1089 
1090  if (empty($image_path)) {
1091  if (defined('USEDOLIBARRSERVER') || defined('USEDOLIBARREDITOR')) {
1092  $image_path = DOL_URL_ROOT.'/viewimage.php?modulepart=common&file=nophoto.png';
1093  } else {
1094  $image_path = '/wrapper.php?modulepart=common&file=nophoto.png';
1095  }
1096  }
1097 
1098  return $image_path;
1099 }
1100 
1101 
1117 function getPagesFromSearchCriterias($type, $algo, $searchstring, $max = 25, $sortfield = 'date_creation', $sortorder = 'DESC', $langcode = '', $otherfilters = [], $status = 1)
1118 {
1119  global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs; // Very important. Required to have var available when running included containers.
1120 
1121  $error = 0;
1122  $arrayresult = array('code' => '', 'list' => array());
1123 
1124  // Clean parameters
1125  if (!is_object($weblangs)) {
1126  $weblangs = $langs;
1127  }
1128  if (empty($algo)) {
1129  $algo = 'content';
1130  }
1131 
1132  /*
1133  if (empty($searchstring) && empty($type) && empty($langcode) && empty($otherfilters)) {
1134  $error++;
1135  $arrayresult['code'] = 'KO';
1136  $arrayresult['message'] = $weblangs->trans("EmptySearchString");
1137  } elseif ($searchstring && dol_strlen($searchstring) < 2) {
1138  $weblangs->load("errors");
1139  $error++;
1140  $arrayresult['code'] = 'KO';
1141  $arrayresult['message'] = $weblangs->trans("ErrorSearchCriteriaTooSmall");
1142  } else {
1143  */
1144  $tmparrayoftype = explode(',', $type);
1145  /*foreach ($tmparrayoftype as $tmptype) {
1146  if (!in_array($tmptype, array('', 'page', 'blogpost'))) {
1147  $error++;
1148  $arrayresult['code'] = 'KO';
1149  $arrayresult['message'] = 'Bad value for parameter type';
1150  break;
1151  }
1152  }*/
1153  //}
1154 
1155  $searchdone = 0;
1156  $found = 0;
1157 
1158  if (!$error && (empty($max) || ($found < $max)) && (preg_match('/meta/', $algo) || preg_match('/content/', $algo))) {
1159  include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
1160 
1161  $sql = 'SELECT wp.rowid FROM '.MAIN_DB_PREFIX.'website_page as wp';
1162  if (is_array($otherfilters) && !empty($otherfilters['category'])) {
1163  $sql .= ', '.MAIN_DB_PREFIX.'categorie_website_page as cwp';
1164  }
1165  $sql .= " WHERE wp.fk_website = ".((int) $website->id);
1166  if ($status >= 0) {
1167  $sql .= " AND wp.status = ".((int) $status);
1168  }
1169  if ($langcode) {
1170  $sql .= " AND wp.lang = '".$db->escape($langcode)."'";
1171  }
1172  if ($type) {
1173  $tmparrayoftype = explode(',', $type);
1174  $typestring = '';
1175  foreach ($tmparrayoftype as $tmptype) {
1176  $typestring .= ($typestring ? ", " : "")."'".$db->escape(trim($tmptype))."'";
1177  }
1178  $sql .= " AND wp.type_container IN (".$db->sanitize($typestring, 1).")";
1179  }
1180  $sql .= " AND (";
1181  $searchalgo = '';
1182  if (preg_match('/meta/', $algo)) {
1183  $searchalgo .= ($searchalgo ? ' OR ' : '')."wp.title LIKE '%".$db->escape($db->escapeforlike($searchstring))."%' OR wp.description LIKE '%".$db->escape($db->escapeforlike($searchstring))."%'";
1184  $searchalgo .= ($searchalgo ? ' OR ' : '')."wp.keywords LIKE '".$db->escape($db->escapeforlike($searchstring)).",%' OR wp.keywords LIKE '% ".$db->escape($db->escapeforlike($searchstring))."%'"; // TODO Use a better way to scan keywords
1185  }
1186  if (preg_match('/content/', $algo)) {
1187  $searchalgo .= ($searchalgo ? ' OR ' : '')."wp.content LIKE '%".$db->escape($db->escapeforlike($searchstring))."%'";
1188  }
1189  $sql .= $searchalgo;
1190  if (is_array($otherfilters) && !empty($otherfilters['category'])) {
1191  $sql .= ' AND cwp.fk_website_page = wp.rowid AND cwp.fk_categorie = '.((int) $otherfilters['category']);
1192  }
1193  $sql .= ")";
1194  $sql .= $db->order($sortfield, $sortorder);
1195  $sql .= $db->plimit($max);
1196  //print $sql;
1197 
1198  $resql = $db->query($sql);
1199 
1200  if ($resql) {
1201  $i = 0;
1202  while (($obj = $db->fetch_object($resql)) && ($i < $max || $max == 0)) {
1203  if ($obj->rowid > 0) {
1204  $tmpwebsitepage = new WebsitePage($db);
1205  $tmpwebsitepage->fetch($obj->rowid);
1206  if ($tmpwebsitepage->id > 0) {
1207  $arrayresult['list'][$obj->rowid] = $tmpwebsitepage;
1208  }
1209  $found++;
1210  }
1211  $i++;
1212  }
1213  } else {
1214  $error++;
1215  $arrayresult['code'] = $db->lasterrno();
1216  $arrayresult['message'] = $db->lasterror();
1217  }
1218 
1219  $searchdone = 1;
1220  }
1221 
1222  if (!$error && (empty($max) || ($found < $max)) && (preg_match('/sitefiles/', $algo))) {
1223  global $dolibarr_main_data_root;
1224 
1225  $pathofwebsite = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$website->ref;
1226  $filehtmlheader = $pathofwebsite.'/htmlheader.html';
1227  $filecss = $pathofwebsite.'/styles.css.php';
1228  $filejs = $pathofwebsite.'/javascript.js.php';
1229  $filerobot = $pathofwebsite.'/robots.txt';
1230  $filehtaccess = $pathofwebsite.'/.htaccess';
1231  $filemanifestjson = $pathofwebsite.'/manifest.json.php';
1232  $filereadme = $pathofwebsite.'/README.md';
1233 
1234  $filecontent = file_get_contents($filehtmlheader);
1235  if ((empty($max) || ($found < $max)) && preg_match('/'.preg_quote($searchstring, '/').'/', $filecontent)) {
1236  $arrayresult['list'][] = array('type' => 'website_htmlheadercontent');
1237  }
1238 
1239  $filecontent = file_get_contents($filecss);
1240  if ((empty($max) || ($found < $max)) && preg_match('/'.preg_quote($searchstring, '/').'/', $filecontent)) {
1241  $arrayresult['list'][] = array('type' => 'website_csscontent');
1242  }
1243 
1244  $filecontent = file_get_contents($filejs);
1245  if ((empty($max) || ($found < $max)) && preg_match('/'.preg_quote($searchstring, '/').'/', $filecontent)) {
1246  $arrayresult['list'][] = array('type' => 'website_jscontent');
1247  }
1248 
1249  $filerobot = file_get_contents($filerobot);
1250  if ((empty($max) || ($found < $max)) && preg_match('/'.preg_quote($searchstring, '/').'/', $filecontent)) {
1251  $arrayresult['list'][] = array('type' => 'website_robotcontent');
1252  }
1253 
1254  $searchdone = 1;
1255  }
1256 
1257  if (!$error) {
1258  if ($searchdone) {
1259  $arrayresult['code'] = 'OK';
1260  if (empty($arrayresult['list'])) {
1261  $arrayresult['code'] = 'KO';
1262  $arrayresult['message'] = $weblangs->trans("NoRecordFound");
1263  }
1264  } else {
1265  $error++;
1266  $arrayresult['code'] = 'KO';
1267  $arrayresult['message'] = 'No supported algorithm found';
1268  }
1269  }
1270 
1271  return $arrayresult;
1272 }
1273 
1288 function getAllImages($object, $objectpage, $urltograb, &$tmp, &$action, $modifylinks = 0, $grabimages = 1, $grabimagesinto = 'subpage')
1289 {
1290  global $conf;
1291 
1292  $error = 0;
1293 
1294  dol_syslog("Call getAllImages with grabimagesinto=".$grabimagesinto);
1295 
1296  $alreadygrabbed = array();
1297 
1298  if (preg_match('/\/$/', $urltograb)) {
1299  $urltograb .= '.';
1300  }
1301  $urltograb = dirname($urltograb); // So urltograb is now http://www.nltechno.com or http://www.nltechno.com/dir1
1302 
1303  // Search X in "img...src=X"
1304  $regs = array();
1305  preg_match_all('/<img([^\.\/]+)src="([^>"]+)"([^>]*)>/i', $tmp, $regs);
1306 
1307  foreach ($regs[0] as $key => $val) {
1308  if (preg_match('/^data:image/i', $regs[2][$key])) {
1309  continue; // We do nothing for such images
1310  }
1311 
1312  if (preg_match('/^\//', $regs[2][$key])) {
1313  $urltograbdirrootwithoutslash = getRootURLFromURL($urltograb);
1314  $urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key]; // We use dirroot
1315  } else {
1316  $urltograbbis = $urltograb.'/'.$regs[2][$key]; // We use dir of grabbed file
1317  }
1318 
1319  $linkwithoutdomain = $regs[2][$key];
1320  $dirforimages = '/'.$objectpage->pageurl;
1321  if ($grabimagesinto == 'root') {
1322  $dirforimages = '';
1323  }
1324 
1325  // Define $filetosave and $filename
1326  $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $regs[2][$key]) ? '' : '/').$regs[2][$key];
1327  if (preg_match('/^http/', $regs[2][$key])) {
1328  $urltograbbis = $regs[2][$key];
1329  $linkwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\//i', '', $regs[2][$key]);
1330  $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain) ? '' : '/').$linkwithoutdomain;
1331  }
1332  $filename = 'image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain) ? '' : '/').$linkwithoutdomain;
1333 
1334  // Clean the aa/bb/../cc into aa/cc
1335  $filetosave = preg_replace('/\/[^\/]+\/\.\./', '', $filetosave);
1336  $filename = preg_replace('/\/[^\/]+\/\.\./', '', $filename);
1337 
1338  if (empty($alreadygrabbed[$urltograbbis])) {
1339  if ($grabimages) {
1340  $tmpgeturl = getURLContent($urltograbbis, 'GET', '', 1, array(), array('http', 'https'), 0);
1341  if ($tmpgeturl['curl_error_no']) {
1342  $error++;
1343  setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['curl_error_msg'], null, 'errors');
1344  $action = 'create';
1345  } elseif ($tmpgeturl['http_code'] != '200') {
1346  $error++;
1347  setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['http_code'], null, 'errors');
1348  $action = 'create';
1349  } else {
1350  $alreadygrabbed[$urltograbbis] = 1; // Track that file was already grabbed.
1351 
1352  dol_mkdir(dirname($filetosave));
1353 
1354  $fp = fopen($filetosave, "w");
1355  fwrite($fp, $tmpgeturl['content']);
1356  fclose($fp);
1357  dolChmod($filetosave);
1358  }
1359  }
1360  }
1361 
1362  if ($modifylinks) {
1363  $tmp = preg_replace('/'.preg_quote($regs[0][$key], '/').'/i', '<img'.$regs[1][$key].'src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file='.$filename.'"'.$regs[3][$key].'>', $tmp);
1364  }
1365  }
1366 
1367  // Search X in "background...url(X)"
1368  preg_match_all('/background([^\.\/\‍(;]+)url\‍([\"\']?([^\‍)\"\']*)[\"\']?\‍)/i', $tmp, $regs);
1369 
1370  foreach ($regs[0] as $key => $val) {
1371  if (preg_match('/^data:image/i', $regs[2][$key])) {
1372  continue; // We do nothing for such images
1373  }
1374 
1375  if (preg_match('/^\//', $regs[2][$key])) {
1376  $urltograbdirrootwithoutslash = getRootURLFromURL($urltograb);
1377  $urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key]; // We use dirroot
1378  } else {
1379  $urltograbbis = $urltograb.'/'.$regs[2][$key]; // We use dir of grabbed file
1380  }
1381 
1382  $linkwithoutdomain = $regs[2][$key];
1383 
1384  $dirforimages = '/'.$objectpage->pageurl;
1385  if ($grabimagesinto == 'root') {
1386  $dirforimages = '';
1387  }
1388 
1389  $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $regs[2][$key]) ? '' : '/').$regs[2][$key];
1390 
1391  if (preg_match('/^http/', $regs[2][$key])) {
1392  $urltograbbis = $regs[2][$key];
1393  $linkwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\//i', '', $regs[2][$key]);
1394  $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain) ? '' : '/').$linkwithoutdomain;
1395  }
1396 
1397  $filename = 'image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain) ? '' : '/').$linkwithoutdomain;
1398 
1399  // Clean the aa/bb/../cc into aa/cc
1400  $filetosave = preg_replace('/\/[^\/]+\/\.\./', '', $filetosave);
1401  $filename = preg_replace('/\/[^\/]+\/\.\./', '', $filename);
1402 
1403  if (empty($alreadygrabbed[$urltograbbis])) {
1404  if ($grabimages) {
1405  $tmpgeturl = getURLContent($urltograbbis, 'GET', '', 1, array(), array('http', 'https'), 0);
1406  if ($tmpgeturl['curl_error_no']) {
1407  $error++;
1408  setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['curl_error_msg'], null, 'errors');
1409  $action = 'create';
1410  } elseif ($tmpgeturl['http_code'] != '200') {
1411  $error++;
1412  setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['http_code'], null, 'errors');
1413  $action = 'create';
1414  } else {
1415  $alreadygrabbed[$urltograbbis] = 1; // Track that file was already grabbed.
1416 
1417  dol_mkdir(dirname($filetosave));
1418 
1419  $fp = fopen($filetosave, "w");
1420  fwrite($fp, $tmpgeturl['content']);
1421  fclose($fp);
1422  dolChmod($filetosave);
1423  }
1424  }
1425  }
1426 
1427  if ($modifylinks) {
1428  $tmp = preg_replace('/'.preg_quote($regs[0][$key], '/').'/i', 'background'.$regs[1][$key].'url("'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file='.$filename.'")', $tmp);
1429  }
1430  }
1431 }
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
Class Websitepage.
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:745
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
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.
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).
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_escape_json($stringtoescape)
Returns text escaped for inclusion into javascript code.
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.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
getRootURLFromURL($url)
Function root url from a long url For example: https://www.abc.mydomain.com/dir/page....
Definition: geturl.lib.php:414
getURLContent($url, $postorget='GET', $param='', $followlocation=1, $addheaders=array(), $allowedschemes=array('http', 'https'), $localurl=0, $ssl_verifypeer=-1)
Function to get a content from an URL (use proxy if proxy defined).
Definition: geturl.lib.php:42
getListOfPossibleImageExt($acceptsvg=0)
Return if a filename is file name of a supported image format.
Definition: images.lib.php:67
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
getAllImages($object, $objectpage, $urltograb, &$tmp, &$action, $modifylinks=0, $grabimages=1, $grabimagesinto='subpage')
Download all images found into page content $tmp.
getImagePublicURLOfObject($object, $no=1, $extName='')
Return HTML content to add structured data for an article, news or Blog Post.
redirectToContainer($containerref, $containeraliasalt='', $containerid=0, $permanent=0, $parameters=array())
Format img tags to introduce viewimage on img src.
dolStripPhpCode($str, $replacewith='')
Remove PHP code part from a string.
Definition: website.lib.php:34
getNbOfImagePublicURLOfObject($object)
Return HTML content to add structured data for an article, news or Blog Post.
getStructuredData($type, $data=array())
Return HTML content to add structured data for an article, news or Blog Post.
dolWebsiteReplacementOfLinks($website, $content, $removephppart=0, $contenttype='html', $containerid=0)
Convert a page content to have correct links (based on DOL_URL_ROOT) into an html content.
getPagesFromSearchCriterias($type, $algo, $searchstring, $max=25, $sortfield='date_creation', $sortorder='DESC', $langcode='', $otherfilters=[], $status=1)
Return list of containers object that match a criteria.
dolWebsiteIncrementCounter($websiteid, $websitepagetype, $websitepageid)
Increase the website counter of page access.
dolReplaceSmileyCodeWithUTF8($content)
Converts smiley string into the utf8 sequence.
includeContainer($containerref)
Clean an HTML page to report only content, so we can include it into another page.
dolKeepOnlyPhpCode($str)
Keep only PHP code part from a HTML string page.
Definition: website.lib.php:78
getSocialNetworkSharingLinks()
Return HTML content to add structured data for an article, news or Blog Post.
dolWebsiteOutput($content, $contenttype='html', $containerid=0)
Render a string of an HTML content and output it.
getSocialNetworkHeaderCards($params=null)
Return HTML content to add as header card for an article, news or Blog Post or home page.