dolibarr  x.y.z
website.lib.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
32 function dolStripPhpCode($str, $replacewith = '')
33 {
34  $str = str_replace('<?=', '<?php', $str);
35 
36  $newstr = '';
37 
38  //split on each opening tag
39  $parts = explode('<?php', $str);
40  if (!empty($parts)) {
41  $i = 0;
42  foreach ($parts as $part) {
43  if ($i == 0) { // The first part is never php code
44  $i++;
45  $newstr .= $part;
46  continue;
47  }
48  // The second part is the php code. We split on closing tag
49  $partlings = explode('?>', $part);
50  if (!empty($partlings)) {
51  //$phppart = $partlings[0];
52  //remove content before closing tag
53  if (count($partlings) > 1) {
54  $partlings[0] = ''; // Todo why a count > 1 and not >= 1 ?
55  }
56  //append to out string
57  //$newstr .= '<span class="phptag" class="tooltip" title="'.dol_escape_htmltag(dolGetFirstLineOfText($phppart).'...').'">'.$replacewith.'<!-- '.$phppart.' --></span>'.implode('', $partlings);
58  //$newstr .= '<span>'.$replacewith.'<!-- '.$phppart.' --></span>'.implode('', $partlings);
59  $newstr .= '<span phptag>'.$replacewith.'</span>'.implode('', $partlings);
60  //$newstr .= $replacewith.implode('', $partlings);
61  }
62  }
63  }
64  return $newstr;
65 }
66 
74 function dolKeepOnlyPhpCode($str)
75 {
76  $str = str_replace('<?=', '<?php', $str);
77 
78  $newstr = '';
79 
80  //split on each opening tag
81  $parts = explode('<?php', $str);
82  if (!empty($parts)) {
83  $i = 0;
84  foreach ($parts as $part) {
85  if ($i == 0) { // The first part is never php code
86  $i++;
87  continue;
88  }
89  $newstr .= '<?php';
90  //split on closing tag
91  $partlings = explode('?>', $part, 2);
92  if (!empty($partlings)) {
93  $newstr .= $partlings[0].'?>';
94  } else {
95  $newstr .= $part.'?>';
96  }
97  }
98  }
99  return $newstr;
100 }
101 
114 function dolWebsiteReplacementOfLinks($website, $content, $removephppart = 0, $contenttype = 'html', $containerid = '')
115 {
116  $nbrep = 0;
117 
118  dol_syslog('dolWebsiteReplacementOfLinks start (contenttype='.$contenttype." containerid=".$containerid." USEDOLIBARREDITOR=".(defined('USEDOLIBARREDITOR') ? '1' : '')." USEDOLIBARRSERVER=".(defined('USEDOLIBARRSERVER') ? '1' : '').')', LOG_DEBUG);
119  //if ($contenttype == 'html') { print $content;exit; }
120 
121  // Replace php code. Note $content may come from database and does not contains body tags.
122  $replacewith = '...php...';
123  if ($removephppart) {
124  $replacewith = '';
125  }
126  $content = preg_replace('/value="<\?php((?!\?>).)*\?>\n*/ims', 'value="'.$replacewith.'"', $content);
127 
128  $replacewith = '"callto=#';
129  if ($removephppart) {
130  $replacewith = '';
131  }
132  $content = preg_replace('/"callto:<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content);
133 
134  $replacewith = '"mailto=#';
135  if ($removephppart) {
136  $replacewith = '';
137  }
138  $content = preg_replace('/"mailto:<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content);
139 
140  $replacewith = 'src="php';
141  if ($removephppart) {
142  $replacewith = '';
143  }
144  $content = preg_replace('/src="<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content);
145 
146  $replacewith = 'href="php';
147  if ($removephppart) {
148  $replacewith = '';
149  }
150  $content = preg_replace('/href="<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content);
151 
152  //$replacewith='<span class="phptag">...php...</span>';
153  $replacewith = '...php...';
154  if ($removephppart) {
155  $replacewith = '';
156  }
157  //$content = preg_replace('/<\?php((?!\?toremove>).)*\?toremove>\n*/ims', $replacewith, $content);
158  /*if ($content === null) {
159  if (preg_last_error() == PREG_JIT_STACKLIMIT_ERROR) $content = 'preg_replace error (when removing php tags) PREG_JIT_STACKLIMIT_ERROR';
160  }*/
161  $content = dolStripPhpCode($content, $replacewith);
162  //var_dump($content);
163 
164  // Protect the link styles.css.php to any replacement that we make after.
165  $content = str_replace('href="styles.css.php', 'href="!~!~!~styles.css.php', $content);
166  $content = str_replace('href="http', 'href="!~!~!~http', $content);
167  $content = str_replace('href="//', 'href="!~!~!~//', $content);
168  $content = str_replace('src="viewimage.php', 'src="!~!~!~/viewimage.php', $content);
169  $content = str_replace('src="/viewimage.php', 'src="!~!~!~/viewimage.php', $content);
170  $content = str_replace('src="'.DOL_URL_ROOT.'/viewimage.php', 'src="!~!~!~'.DOL_URL_ROOT.'/viewimage.php', $content);
171  $content = str_replace('href="document.php', 'href="!~!~!~/document.php', $content);
172  $content = str_replace('href="/document.php', 'href="!~!~!~/document.php', $content);
173  $content = str_replace('href="'.DOL_URL_ROOT.'/document.php', 'href="!~!~!~'.DOL_URL_ROOT.'/document.php', $content);
174 
175  // Replace relative link '/' with dolibarr URL
176  $content = preg_replace('/(href=")\/(#[^\"<>]*)?\"/', '\1!~!~!~'.DOL_URL_ROOT.'/website/index.php?website='.$website->ref.'&pageid='.$website->fk_default_home.'\2"', $content, -1, $nbrep);
177  // Replace relative link /xxx.php#aaa or /xxx.php with dolibarr URL (we discard param ?...)
178  $content = preg_replace('/(href=")\/?([^:\"\!]*)\.php(#[^\"<>]*)?\"/', '\1!~!~!~'.DOL_URL_ROOT.'/website/index.php?website='.$website->ref.'&pageref=\2\3"', $content, -1, $nbrep);
179  // Replace relative link /xxx.php?a=b&c=d#aaa or /xxx.php?a=b&c=d with dolibarr URL
180  $content = preg_replace('/(href=")\/?([^:\"\!]*)\.php\?([^#\"<>]*)(#[^\"<>]*)?\"/', '\1!~!~!~'.DOL_URL_ROOT.'/website/index.php?website='.$website->ref.'&pageref=\2&\3\4"', $content, -1, $nbrep);
181 
182  // Fix relative link into medias with correct URL after the DOL_URL_ROOT: ../url("medias/
183  $content = preg_replace('/url\‍((["\']?)\/?medias\//', 'url(\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
184  $content = preg_replace('/data-slide-bg=(["\']?)\/?medias\//', 'data-slide-bg=\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
185 
186  // <img src="medias/...image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png...
187  // <img src="...image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png...
188  $content = preg_replace('/(<img[^>]*src=")\/?medias\//', '\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
189  // <img src="image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png...
190  $content = preg_replace('/(<img[^>]*src=")\/?([^:\"\!]+)\"/', '\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=\2"', $content, -1, $nbrep);
191  // <img src="viewimage.php/modulepart=medias&file=image.png" => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png"
192  $content = preg_replace('/(<img[^>]*src=")(\/?viewimage\.php)/', '\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php', $content, -1, $nbrep);
193 
194  // action="newpage.php" => action="dolibarr/website/index.php?website=...&pageref=newpage
195  $content = preg_replace('/(action=")\/?([^:\"]*)(\.php\")/', '\1!~!~!~'.DOL_URL_ROOT.'/website/index.php?website='.$website->ref.'&pageref=\2"', $content, -1, $nbrep);
196 
197  // Fix relative link /document.php with correct URL after the DOL_URL_ROOT: ...href="/document.php?modulepart="
198  $content = preg_replace('/(href=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1!~!~!~'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
199  $content = preg_replace('/(src=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1!~!~!~'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
200 
201  // Fix relative link /viewimage.php with correct URL after the DOL_URL_ROOT: ...href="/viewimage.php?modulepart="
202  $content = preg_replace('/(url\‍(")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1!~!~!~'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
203 
204  // Fix relative URL
205  $content = str_replace('src="!~!~!~/viewimage.php', 'src="!~!~!~'.DOL_URL_ROOT.'/viewimage.php', $content);
206  $content = str_replace('href="!~!~!~/document.php', 'href="!~!~!~'.DOL_URL_ROOT.'/document.php', $content);
207  // Remove the protection tag !~!~!~
208  $content = str_replace('!~!~!~', '', $content);
209 
210  dol_syslog('dolWebsiteReplacementOfLinks end', LOG_DEBUG);
211  //if ($contenttype == 'html') { print $content;exit; }
212 
213  return $content;
214 }
215 
223 {
224  $map = array(
225  ":face_with_tears_of_joy:" => "\xF0\x9F\x98\x82",
226  ":grinning_face_with_smiling_eyes:" => "\xF0\x9F\x98\x81",
227  ":smiling_face_with_open_mouth:" => "\xF0\x9F\x98\x83",
228  ":smiling_face_with_open_mouth_and_cold_sweat:" => "\xF0\x9F\x98\x85",
229  ":smiling_face_with_open_mouth_and_tightly_closed_eyes:" => "\xF0\x9F\x98\x86",
230  ":winking_face:" => "\xF0\x9F\x98\x89",
231  ":smiling_face_with_smiling_eyes:" => "\xF0\x9F\x98\x8A",
232  ":face_savouring_delicious_food:" => "\xF0\x9F\x98\x8B",
233  ":relieved_face:" => "\xF0\x9F\x98\x8C",
234  ":smiling_face_with_heart_shaped_eyes:" => "\xF0\x9F\x98\x8D",
235  ":smiling_face_with_sunglasses:" => "\xF0\x9F\x98\x8E",
236  ":smirking_face:" => "\xF0\x9F\x98\x8F",
237  ":neutral_face:" => "\xF0\x9F\x98\x90",
238  ":expressionless_face:" => "\xF0\x9F\x98\x91",
239  ":unamused_face:" => "\xF0\x9F\x98\x92",
240  ":face_with_cold_sweat:" => "\xF0\x9F\x98\x93",
241  ":pensive_face:" => "\xF0\x9F\x98\x94",
242  ":confused_face:" => "\xF0\x9F\x98\x95",
243  ":confounded_face:" => "\xF0\x9F\x98\x96",
244  ":kissing_face:" => "\xF0\x9F\x98\x97",
245  ":face_throwing_a_kiss:" => "\xF0\x9F\x98\x98",
246  ":kissing_face_with_smiling_eyes:" => "\xF0\x9F\x98\x99",
247  ":kissing_face_with_closed_eyes:" => "\xF0\x9F\x98\x9A",
248  ":face_with_stuck_out_tongue:" => "\xF0\x9F\x98\x9B",
249  ":face_with_stuck_out_tongue_and_winking_eye:" => "\xF0\x9F\x98\x9C",
250  ":face_with_stuck_out_tongue_and_tightly_closed_eyes:" => "\xF0\x9F\x98\x9D",
251  ":disappointed_face:" => "\xF0\x9F\x98\x9E",
252  ":worried_face:" => "\xF0\x9F\x98\x9F",
253  ":angry_face:" => "\xF0\x9F\x98\xA0",
254  ":face_with_symbols_on_mouth:" => "\xF0\x9F\x98\xA1",
255  );
256  foreach ($map as $key => $value) {
257  $content = str_replace($key, $value, $content);
258  }
259  return $content;
260 }
261 
262 
273 function dolWebsiteOutput($content, $contenttype = 'html', $containerid = '')
274 {
275  global $db, $langs, $conf, $user;
276  global $dolibarr_main_url_root, $dolibarr_main_data_root;
277  global $website;
278  global $includehtmlcontentopened;
279 
280  $nbrep = 0;
281 
282  dol_syslog("dolWebsiteOutput start - contenttype=".$contenttype." containerid=".$containerid." USEDOLIBARREDITOR=".(defined('USEDOLIBARREDITOR') ? '1' : '')." USEDOLIBARRSERVER=".(defined('USEDOLIBARRSERVER') ? '1' : '').' includehtmlcontentopened='.$includehtmlcontentopened);
283 
284  //print $containerid.' '.$content;
285 
286  // Define $urlwithroot
287  $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
288  $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
289  //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
290 
291  if (defined('USEDOLIBARREDITOR')) { // REPLACEMENT OF LINKS When page called from Dolibarr editor
292  // We remove the <head> part of content
293  if ($contenttype == 'html') {
294  $content = preg_replace('/<head>.*<\/head>/ims', '', $content);
295  $content = preg_replace('/^.*<body(\s[^>]*)*>/ims', '', $content);
296  $content = preg_replace('/<\/body(\s[^>]*)*>.*$/ims', '', $content);
297  }
298  } elseif (defined('USEDOLIBARRSERVER')) { // REPLACEMENT OF LINKS When page called from Dolibarr server
299  $content = str_replace('<link rel="stylesheet" href="/styles.css', '<link rel="stylesheet" href="styles.css', $content);
300 
301  // Protect the link styles.css.php to any replacement that we make after.
302  $content = str_replace('href="styles.css.php', 'href="!~!~!~styles.css.php', $content);
303  $content = str_replace('href="http', 'href="!~!~!~http', $content);
304  $content = str_replace('href="//', 'href="!~!~!~//', $content);
305  $content = str_replace(array('src="viewimage.php', 'src="/viewimage.php'), 'src="!~!~!~/viewimage.php', $content);
306  $content = str_replace('src="'.DOL_URL_ROOT.'/viewimage.php', 'src="!~!~!~'.DOL_URL_ROOT.'/viewimage.php', $content);
307  $content = str_replace(array('href="document.php', 'href="/document.php'), 'href="!~!~!~/document.php', $content);
308  $content = str_replace('href="'.DOL_URL_ROOT.'/document.php', 'href="!~!~!~'.DOL_URL_ROOT.'/document.php', $content);
309 
310  // Replace relative link / with dolibarr URL: ...href="/"...
311  $content = preg_replace('/(href=")\/\"/', '\1!~!~!~'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'"', $content, -1, $nbrep);
312  // Replace relative link /xxx.php#aaa or /xxx.php with dolibarr URL: ...href="....php" (we discard param ?...)
313  $content = preg_replace('/(href=")\/?([^:\"\!]*)\.php(#[^\"<>]*)?\"/', '\1!~!~!~'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2\3"', $content, -1, $nbrep);
314  // Replace relative link /xxx.php?a=b&c=d#aaa or /xxx.php?a=b&c=d with dolibarr URL
315  // Warning: we may replace twice if href="..." was inside an include (dolWebsiteOutput called by include and the by final page), that's why
316  // at end we replace the '!~!~!~' only if we are in final parent page.
317  $content = preg_replace('/(href=")\/?([^:\"\!]*)\.php\?([^#\"<>]*)(#[^\"<>]*)?\"/', '\1!~!~!~'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2&\3\4"', $content, -1, $nbrep);
318  // Replace relative link without .php like /xxx#aaa or /xxx with dolibarr URL: ...href="....php"
319  $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);
320 
321  // Fix relative link /document.php with correct URL after the DOL_URL_ROOT: href="/document.php?modulepart=" => href="/dolibarr/document.php?modulepart="
322  $content = preg_replace('/(href=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1!~!~!~'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
323  $content = preg_replace('/(src=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1!~!~!~'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
324 
325  // Fix relative link /viewimage.php with correct URL after the DOL_URL_ROOT: href="/viewimage.php?modulepart=" => href="/dolibarr/viewimage.php?modulepart="
326  $content = preg_replace('/(href=")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1!~!~!~'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
327  $content = preg_replace('/(src=")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1!~!~!~'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
328  $content = preg_replace('/(url\‍(")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1!~!~!~'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
329 
330  // Fix relative link into medias with correct URL after the DOL_URL_ROOT: ../url("medias/
331  $content = preg_replace('/url\‍((["\']?)\/?medias\//', 'url(\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
332  $content = preg_replace('/data-slide-bg=(["\']?)\/?medias\//', 'data-slide-bg=\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
333 
334  // <img src="medias/...image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png...
335  // <img src="...image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png...
336  $content = preg_replace('/(<img[^>]*src=")\/?medias\//', '\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
337  // <img src="image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png...
338  $content = preg_replace('/(<img[^>]*src=")\/?([^:\"\!]+)\"/', '\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=\2"', $content, -1, $nbrep);
339  // <img src="viewimage.php/modulepart=medias&file=image.png" => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png"
340  $content = preg_replace('/(<img[^>]*src=")(\/?viewimage\.php)/', '\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php', $content, -1, $nbrep);
341 
342  // action="newpage.php" => action="dolibarr/website/index.php?website=...&pageref=newpage
343  $content = preg_replace('/(action=")\/?([^:\"]*)(\.php\")/', '\1!~!~!~'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2"', $content, -1, $nbrep);
344 
345  // Fix relative URL
346  $content = str_replace('src="!~!~!~/viewimage.php', 'src="!~!~!~'.DOL_URL_ROOT.'/viewimage.php', $content);
347  $content = str_replace('href="!~!~!~/document.php', 'href="!~!~!~'.DOL_URL_ROOT.'/document.php', $content);
348 
349  // Remove the protection tag !~!~!~, but only if this is the parent page and not an include
350  if (empty($includehtmlcontentopened)) {
351  $content = str_replace('!~!~!~', '', $content);
352  }
353  } else // REPLACEMENT OF LINKS When page called from virtual host web server
354  {
355  $symlinktomediaexists = 1;
356  if ($website->virtualhost) {
357  $content = preg_replace('/^(<link[^>]*rel="canonical" href=")\//m', '\1'.$website->virtualhost.'/', $content, -1, $nbrep);
358  }
359  //print 'rrrrrrrrr'.$website->virtualhost.$content;
360 
361 
362  // Make a change into HTML code to allow to include images from medias directory correct with direct link for virtual server
363  // <img alt="" src="/dolibarr_dev/htdocs/viewimage.php?modulepart=medias&amp;entity=1&amp;file=image/ldestailleur_166x166.jpg" style="height:166px; width:166px" />
364  // become
365  // <img alt="" src="'.$urlwithroot.'/medias/image/ldestailleur_166x166.jpg" style="height:166px; width:166px" />
366  if (!$symlinktomediaexists) {
367  // <img src="image.png... => <img src="medias/image.png...
368  $content = preg_replace('/(<img[^>]*src=")\/?image\//', '\1/wrapper.php?modulepart=medias&file=medias/image/', $content, -1, $nbrep);
369  $content = preg_replace('/(url\‍(["\']?)\/?image\//', '\1/wrapper.php?modulepart=medias&file=medias/image/', $content, -1, $nbrep);
370 
371  $content = preg_replace('/(<script[^>]*src=")[^\"]*document\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep);
372  $content = preg_replace('/(<a[^>]*href=")[^\"]*document\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep);
373 
374  $content = preg_replace('/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep);
375  $content = preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep);
376  $content = preg_replace('/(url\‍(["\']?)[^\‍)]*viewimage\.php([^\‍)]*)modulepart=medias([^\‍)]*)file=([^\‍)]*)(["\']?\‍))/', '\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep);
377 
378  $content = preg_replace('/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep);
379  $content = preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep);
380  $content = preg_replace('/(url\‍(["\']?)[^\‍)]*viewimage\.php([^\‍)]*)hashp=([^\‍)]*)(["\']?\‍))/', '\1/wrapper.php\2hashp\3\4', $content, -1, $nbrep);
381 
382  $content = preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=mycompany([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=mycompany\3file=\4\5', $content, -1, $nbrep);
383 
384  // If some links to documents or viewimage remains, we replace with wrapper
385  $content = preg_replace('/(<img[^>]*src=")\/?viewimage\.php/', '\1/wrapper.php', $content, -1, $nbrep);
386  $content = preg_replace('/(<a[^>]*href=")\/?documents\.php/', '\1/wrapper.php', $content, -1, $nbrep);
387  } else {
388  // <img src="image.png... => <img src="medias/image.png...
389  $content = preg_replace('/(<img[^>]*src=")\/?image\//', '\1/medias/image/', $content, -1, $nbrep);
390  $content = preg_replace('/(url\‍(["\']?)\/?image\//', '\1/medias/image/', $content, -1, $nbrep);
391 
392  $content = preg_replace('/(<script[^>]*src=")[^\"]*document\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/medias/\4\5', $content, -1, $nbrep);
393  $content = preg_replace('/(<a[^>]*href=")[^\"]*document\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/medias/\4\5', $content, -1, $nbrep);
394 
395  $content = preg_replace('/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/medias/\4\5', $content, -1, $nbrep);
396  $content = preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/medias/\4\5', $content, -1, $nbrep);
397  $content = preg_replace('/(url\‍(["\']?)[^\‍)]*viewimage\.php([^\‍)]*)modulepart=medias([^\‍)]*)file=([^\‍)]*)(["\']?\‍))/', '\1/medias/\4\5', $content, -1, $nbrep);
398 
399  $content = preg_replace('/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep);
400  $content = preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep);
401  $content = preg_replace('/(url\‍(["\']?)[^\‍)]*viewimage\.php([^\‍)]*)hashp=([^\‍)]*)(["\']?\‍))/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep);
402 
403  $content = preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=mycompany([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=mycompany\3file=\4\5', $content, -1, $nbrep);
404 
405  // If some links to documents or viewimage remains, we replace with wrapper
406  $content = preg_replace('/(<img[^>]*src=")\/?viewimage\.php/', '\1/wrapper.php', $content, -1, $nbrep);
407  $content = preg_replace('/(<a[^>]*href=")\/?document\.php/', '\1/wrapper.php', $content, -1, $nbrep);
408  }
409  }
410 
411  if (!defined('USEDOLIBARREDITOR')) {
412  $content = str_replace(' contenteditable="true"', ' contenteditable="false"', $content);
413  }
414 
415  if (!empty($conf->global->WEBSITE_ADD_CSS_TO_BODY)) {
416  $content = str_replace('<body id="bodywebsite" class="bodywebsite', '<body id="bodywebsite" class="bodywebsite '.$conf->global->WEBSITE_ADD_CSS_TO_BODY, $content);
417  }
418 
419  $content = dolReplaceSmileyCodeWithUTF8($content);
420 
421  dol_syslog("dolWebsiteOutput end");
422 
423  print $content;
424 }
425 
426 
434 /*
435 function dolWebsiteSaveContent($content)
436 {
437  global $db, $langs, $conf, $user;
438  global $dolibarr_main_url_root, $dolibarr_main_data_root;
439 
440  //dol_syslog("dolWebsiteSaveContent start (mode=".(defined('USEDOLIBARRSERVER')?'USEDOLIBARRSERVER':'').')');
441 
442  // Define $urlwithroot
443  $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
444  $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
445  //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
446 
447  //$content = preg_replace('/(<img.*src=")(?!(http|'.preg_quote(DOL_URL_ROOT,'/').'\/viewimage))/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
448 
449  return $content;
450 }
451 */
452 
453 
463 function redirectToContainer($containerref, $containeraliasalt = '', $containerid = 0, $permanent = 0)
464 {
465  global $db, $website;
466 
467  $newurl = '';
468  $result = 0;
469 
470  // We make redirect using the alternative alias, we must find the real $containerref
471  if ($containeraliasalt) {
472  include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
473  $tmpwebsitepage = new WebsitePage($db);
474  $result = $tmpwebsitepage->fetch(0, $website->id, '', $containeraliasalt);
475  if ($result > 0) {
476  $containerref = $tmpwebsitepage->pageurl;
477  } else {
478  print "Error, page contains a redirect to the alternative alias '".$containeraliasalt."' that does not exists in web site (".$website->id." / ".$website->ref.")";
479  exit;
480  }
481  }
482 
483  if (defined('USEDOLIBARREDITOR')) {
484  /*print '<div class="margintoponly marginleftonly">';
485  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.";
486  print '</div>';*/
487  $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.";
488  setEventMessages($text, null, 'warnings', 'WEBSITEREDIRECTDISABLED'.$containerref);
489  return;
490  }
491 
492  if (defined('USEDOLIBARRSERVER')) { // When page called from Dolibarr server
493  // Check new container exists
494  if (!$containeraliasalt) { // If containeraliasalt set, we already did the test
495  include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
496  $tmpwebsitepage = new WebsitePage($db);
497  $result = $tmpwebsitepage->fetch(0, $website->id, $containerref);
498  unset($tmpwebsitepage);
499  }
500  if ($result > 0) {
501  $currenturi = $_SERVER["REQUEST_URI"];
502  $regtmp = array();
503  if (preg_match('/&pageref=([^&]+)/', $currenturi, $regtmp)) {
504  if ($regtmp[0] == $containerref) {
505  print "Error, page with uri '.$currenturi.' try a redirect to the same alias page '".$containerref."' in web site '".$website->ref."'";
506  exit;
507  } else {
508  $newurl = preg_replace('/&pageref=([^&]+)/', '&pageref='.$containerref, $currenturi);
509  }
510  } else {
511  $newurl = $currenturi.'&pageref='.urlencode($containerref);
512  }
513  }
514  } else // When page called from virtual host server
515  {
516  $newurl = '/'.$containerref.'.php';
517  }
518 
519  if ($newurl) {
520  if ($permanent) {
521  header("Status: 301 Moved Permanently", false, 301);
522  }
523  header("Location: ".$newurl.(empty($_SERVER["QUERY_STRING"]) ? '' : '?'.$_SERVER["QUERY_STRING"]));
524  exit;
525  } else {
526  print "Error, page contains a redirect to the alias page '".$containerref."' that does not exists in web site (".$website->id." / ".$website->ref.")";
527  exit;
528  }
529 }
530 
531 
539 function includeContainer($containerref)
540 {
541  global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs; // Very important. Required to have var available when running included containers.
542  global $includehtmlcontentopened;
543  global $websitekey, $websitepagefile;
544 
545  $MAXLEVEL = 20;
546 
547  if (!preg_match('/\.php$/i', $containerref)) {
548  $containerref .= '.php';
549  }
550 
551  $fullpathfile = DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$websitekey.'/'.$containerref;
552 
553  if (empty($includehtmlcontentopened)) {
554  $includehtmlcontentopened = 0;
555  }
556  $includehtmlcontentopened++;
557  if ($includehtmlcontentopened > $MAXLEVEL) {
558  print 'ERROR: RECURSIVE CONTENT LEVEL. Depth of recursive call is more than the limit of '.((int) $MAXLEVEL).".\n";
559  return;
560  }
561 
562  //dol_syslog("Include container ".$containerref.' includehtmlcontentopened='.$includehtmlcontentopened);
563 
564  // file_get_contents is not possible. We must execute code with include
565  //$content = file_get_contents($fullpathfile);
566  //print preg_replace(array('/^.*<body[^>]*>/ims','/<\/body>.*$/ims'), array('', ''), $content);*/
567 
568  ob_start();
569  $res = include $fullpathfile; // Include because we want to execute code content
570  $tmpoutput = ob_get_contents();
571  ob_end_clean();
572 
573  print "\n".'<!-- include '.$websitekey.'/'.$containerref.(is_object($websitepage) ? ' parent id='.$websitepage->id : '').' level = '.$includehtmlcontentopened.' -->'."\n";
574  print preg_replace(array('/^.*<body[^>]*>/ims', '/<\/body>.*$/ims'), array('', ''), $tmpoutput);
575 
576  if (!$res) {
577  print 'ERROR: FAILED TO INCLUDE PAGE '.$containerref.".\n";
578  }
579 
580  $includehtmlcontentopened--;
581 }
582 
593 function getStructuredData($type, $data = array())
594 {
595  global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs, $pagelangs; // Very important. Required to have var available when running inluded containers.
596 
597  $type = strtolower($type);
598 
599  if ($type == 'software') {
600  $ret = '<!-- Add structured data for entry in a software annuary -->'."\n";
601  $ret .= '<script type="application/ld+json">'."\n";
602  $ret .= '{
603  "@context": "https://schema.org",
604  "@type": "SoftwareApplication",
605  "name": "'.dol_escape_json($data['name']).'",
606  "operatingSystem": "'.dol_escape_json($data['os']).'",
607  "applicationCategory": "https://schema.org/'.dol_escape_json($data['applicationCategory']).'",';
608  if (!empty($data['ratingcount'])) {
609  $ret .= '
610  "aggregateRating": {
611  "@type": "AggregateRating",
612  "ratingValue": "'.dol_escape_json($data['ratingvalue']).'",
613  "ratingCount": "'.dol_escape_json($data['ratingcount']).'"
614  },';
615  }
616  $ret .= '
617  "offers": {
618  "@type": "Offer",
619  "price": "'.dol_escape_json($data['price']).'",
620  "priceCurrency": "'.dol_escape_json($data['currency'] ? $data['currency'] : $conf->currency).'"
621  }
622  }'."\n";
623  $ret .= '</script>'."\n";
624  } elseif ($type == 'organization') {
625  $companyname = $mysoc->name;
626  $url = $mysoc->url;
627 
628  $ret = '<!-- Add structured data for organization -->'."\n";
629  $ret .= '<script type="application/ld+json">'."\n";
630  $ret .= '{
631  "@context": "https://schema.org",
632  "@type": "Organization",
633  "name": "'.dol_escape_json($data['name'] ? $data['name'] : $companyname).'",
634  "url": "'.dol_escape_json($data['url'] ? $data['url'] : $url).'",
635  "logo": "'.($data['logo'] ? dol_escape_json($data['logo']) : '/wrapper.php?modulepart=mycompany&file=logos%2F'.urlencode($mysoc->logo)).'",
636  "contactPoint": {
637  "@type": "ContactPoint",
638  "contactType": "Contact",
639  "email": "'.dol_escape_json($data['email'] ? $data['email'] : $mysoc->email).'"
640  }'."\n";
641  if (is_array($mysoc->socialnetworks) && count($mysoc->socialnetworks) > 0) {
642  $ret .= ",\n";
643  $ret .= '"sameAs": [';
644  $i = 0;
645  foreach ($mysoc->socialnetworks as $key => $value) {
646  if ($key == 'linkedin') {
647  $ret .= '"https://www.'.$key.'.com/company/'.dol_escape_json($value).'"';
648  } elseif ($key == 'youtube') {
649  $ret .= '"https://www.'.$key.'.com/user/'.dol_escape_json($value).'"';
650  } else {
651  $ret .= '"https://www.'.$key.'.com/'.dol_escape_json($value).'"';
652  }
653  $i++;
654  if ($i < count($mysoc->socialnetworks)) {
655  $ret .= ', ';
656  }
657  }
658  $ret .= ']'."\n";
659  }
660  $ret .= '}'."\n";
661  $ret .= '</script>'."\n";
662  } elseif ($type == 'blogpost') {
663  if (!empty($websitepage->author_alias)) {
664  //include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
665  //$tmpuser = new User($db);
666  //$restmpuser = $tmpuser->fetch($websitepage->fk_user_creat);
667 
668  $pageurl = $websitepage->pageurl;
669  $title = $websitepage->title;
670  $image = $websitepage->image;
671  $companyname = $mysoc->name;
672  $description = $websitepage->description;
673 
674  $pageurl = str_replace('__WEBSITE_KEY__', $website->ref, $pageurl);
675  $title = str_replace('__WEBSITE_KEY__', $website->ref, $title);
676  $image = '/medias'.(preg_match('/^\//', $image) ? '' : '/').str_replace('__WEBSITE_KEY__', $website->ref, $image);
677  $companyname = str_replace('__WEBSITE_KEY__', $website->ref, $companyname);
678  $description = str_replace('__WEBSITE_KEY__', $website->ref, $description);
679 
680  $ret = '<!-- Add structured data for blog post -->'."\n";
681  $ret .= '<script type="application/ld+json">'."\n";
682  $ret .= '{
683  "@context": "https://schema.org",
684  "@type": "NewsArticle",
685  "mainEntityOfPage": {
686  "@type": "WebPage",
687  "@id": "'.dol_escape_json($pageurl).'"
688  },
689  "headline": "'.dol_escape_json($title).'",
690  "image": [
691  "'.dol_escape_json($image).'"
692  ],
693  "dateCreated": "'.dol_print_date($websitepage->date_creation, 'dayhourrfc').'",
694  "datePublished": "'.dol_print_date($websitepage->date_creation, 'dayhourrfc').'",
695  "dateModified": "'.dol_print_date($websitepage->date_modification, 'dayhourrfc').'",
696  "author": {
697  "@type": "Person",
698  "name": "'.dol_escape_json($websitepage->author_alias).'"
699  },
700  "publisher": {
701  "@type": "Organization",
702  "name": "'.dol_escape_json($companyname).'",
703  "logo": {
704  "@type": "ImageObject",
705  "url": "/wrapper.php?modulepart=mycompany&file=logos%2F'.urlencode($mysoc->logo).'"
706  }
707  },'."\n";
708  if ($websitepage->keywords) {
709  $ret .= '"keywords": [';
710  $i = 0;
711  $arrayofkeywords = explode(',', $websitepage->keywords);
712  foreach ($arrayofkeywords as $keyword) {
713  $ret .= '"'.dol_escape_json($keyword).'"';
714  $i++;
715  if ($i < count($arrayofkeywords)) {
716  $ret .= ', ';
717  }
718  }
719  $ret .= '],'."\n";
720  }
721  $ret .= '"description": "'.dol_escape_json($description).'"';
722  $ret .= "\n".'}'."\n";
723  $ret .= '</script>'."\n";
724  } else {
725  $ret .= '<!-- no structured data inserted inline inside blogpost because no author_alias defined -->'."\n";
726  }
727  } elseif ($type == 'product') {
728  $ret = '<!-- Add structured data for product -->'."\n";
729  $ret .= '<script type="application/ld+json">'."\n";
730  $ret .= '{
731  "@context": "https://schema.org/",
732  "@type": "Product",
733  "name": "'.dol_escape_json($data['label']).'",
734  "image": [
735  "'.dol_escape_json($data['image']).'",
736  ],
737  "description": "'.dol_escape_json($data['description']).'",
738  "sku": "'.dol_escape_json($data['ref']).'",
739  "brand": {
740  "@type": "Thing",
741  "name": "'.dol_escape_json($data['brand']).'"
742  },
743  "author": {
744  "@type": "Person",
745  "name": "'.dol_escape_json($data['author']).'"
746  }
747  },
748  "offers": {
749  "@type": "Offer",
750  "url": "https://example.com/anvil",
751  "priceCurrency": "'.dol_escape_json($data['currency'] ? $data['currency'] : $conf->currency).'",
752  "price": "'.dol_escape_json($data['price']).'",
753  "itemCondition": "https://schema.org/UsedCondition",
754  "availability": "https://schema.org/InStock",
755  "seller": {
756  "@type": "Organization",
757  "name": "'.dol_escape_json($mysoc->name).'"
758  }
759  }
760  }'."\n";
761  $ret .= '</script>'."\n";
762  } elseif ($type == 'qa') {
763  $ret = '<!-- Add structured data for QA -->'."\n";
764  $ret .= '<script type="application/ld+json">'."\n";
765  $ret .= '{
766  "@context": "https://schema.org/",
767  "@type": "QAPage",
768  "mainEntity": {
769  "@type": "Question",
770  "name": "'.dol_escape_json($data['name']).'",
771  "text": "'.dol_escape_json($data['name']).'",
772  "answerCount": 1,
773  "author": {
774  "@type": "Person",
775  "name": "'.dol_escape_json($data['author']).'"
776  }
777  "acceptedAnswer": {
778  "@type": "Answer",
779  "text": "'.dol_escape_json(dol_string_nohtmltag(dolStripPhpCode($data['description']))).'",
780  "author": {
781  "@type": "Person",
782  "name": "'.dol_escape_json($data['author']).'"
783  }
784  }
785  }
786  }'."\n";
787  $ret .= '</script>'."\n";
788  }
789  return $ret;
790 }
791 
798 function getSocialNetworkHeaderCards($params = null)
799 {
800  global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs; // Very important. Required to have var available when running inluded containers.
801 
802  $out = '';
803 
804  if ($website->virtualhost) {
805  $pageurl = $websitepage->pageurl;
806  $title = $websitepage->title;
807  $image = $websitepage->image;
808  $companyname = $mysoc->name;
809  $description = $websitepage->description;
810 
811  $pageurl = str_replace('__WEBSITE_KEY__', $website->ref, $pageurl);
812  $title = str_replace('__WEBSITE_KEY__', $website->ref, $title);
813  $image = '/medias'.(preg_match('/^\//', $image) ? '' : '/').str_replace('__WEBSITE_KEY__', $website->ref, $image);
814  $companyname = str_replace('__WEBSITE_KEY__', $website->ref, $companyname);
815  $description = str_replace('__WEBSITE_KEY__', $website->ref, $description);
816 
817  $shortlangcode = '';
818  if ($websitepage->lang) {
819  $shortlangcode = substr($websitepage->lang, 0, 2); // en_US or en-US -> en
820  }
821  if (empty($shortlangcode)) {
822  $shortlangcode = substr($website->lang, 0, 2); // en_US or en-US -> en
823  }
824 
825  $fullurl = $website->virtualhost.'/'.$websitepage->pageurl.'.php';
826  $canonicalurl = $website->virtualhost.(($websitepage->id == $website->fk_default_home) ? '/' : (($shortlangcode != substr($website->lang, 0, 2) ? '/'.$shortlangcode : '').'/'.$websitepage->pageurl.'.php'));
827  $hashtags = trim(join(' #', array_map('trim', explode(',', $websitepage->keywords))));
828 
829  // Open Graph
830  $out .= '<meta name="og:type" content="website">'."\n"; // TODO If blogpost, use type article
831  $out .= '<meta name="og:title" content="'.$websitepage->title.'">'."\n";
832  if ($websitepage->image) {
833  $out .= '<meta name="og:image" content="'.$website->virtualhost.$image.'">'."\n";
834  }
835  $out .= '<meta name="og:url" content="'.$canonicalurl.'">'."\n";
836 
837  // Twitter
838  $out .= '<meta name="twitter:card" content="summary">'."\n";
839  if (!empty($params) && !empty($params['twitter_account'])) {
840  $out .= '<meta name="twitter:site" content="@'.$params['twitter_account'].'">'."\n";
841  $out .= '<meta name="twitter:creator" content="@'.$params['twitter_account'].'">'."\n";
842  }
843  $out .= '<meta name="twitter:title" content="'.$websitepage->title.'">'."\n";
844  if ($websitepage->description) {
845  $out .= '<meta name="twitter:description" content="'.$websitepage->description.'">'."\n";
846  }
847  if ($websitepage->image) {
848  $out .= '<meta name="twitter:image" content="'.$website->virtualhost.$image.'">'."\n";
849  }
850  //$out .= '<meta name="twitter:domain" content="'.getDomainFromURL($website->virtualhost, 1).'">';
851  /*
852  $out .= '<meta name="twitter:app:name:iphone" content="">';
853  $out .= '<meta name="twitter:app:name:ipad" content="">';
854  $out .= '<meta name="twitter:app:name:googleplay" content="">';
855  $out .= '<meta name="twitter:app:url:iphone" content="">';
856  $out .= '<meta name="twitter:app:url:ipad" content="">';
857  $out .= '<meta name="twitter:app:url:googleplay" content="">';
858  $out .= '<meta name="twitter:app:id:iphone" content="">';
859  $out .= '<meta name="twitter:app:id:ipad" content="">';
860  $out .= '<meta name="twitter:app:id:googleplay" content="">';
861  */
862  }
863 
864  return $out;
865 }
866 
873 {
874  global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs; // Very important. Required to have var available when running inluded containers.
875 
876  $out = '<!-- section for social network sharing of page -->'."\n";
877 
878  if ($website->virtualhost) {
879  $fullurl = $website->virtualhost.'/'.$websitepage->pageurl.'.php';
880  $hashtags = trim(join(' #', array_map('trim', explode(',', $websitepage->keywords))));
881 
882  $out .= '<div class="dol-social-share">'."\n";
883 
884  // Twitter
885  $out .= '<div class="dol-social-share-tw">'."\n";
886  $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>';
887  $out .= '<script>!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>';
888  $out .= '</div>'."\n";
889 
890  // Reddit
891  $out .= '<div class="dol-social-share-reddit">'."\n";
892  $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">';
893  $out .= '<span class="dol-social-share-reddit-span">Reddit</span>';
894  $out .= '</a>';
895  $out .= '</div>'."\n";
896 
897  // Facebook
898  $out .= '<div class="dol-social-share-fbl">'."\n";
899  $out .= '<div id="fb-root"></div>'."\n";
900  $out .= '<script>(function(d, s, id) {
901  var js, fjs = d.getElementsByTagName(s)[0];
902  if (d.getElementById(id)) return;
903  js = d.createElement(s); js.id = id;
904  js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.0&amp;appId=dolibarr.org";
905  fjs.parentNode.insertBefore(js, fjs);
906  }(document, \'script\', \'facebook-jssdk\'));</script>
907  <fb:like
908  href="'.$fullurl.'"
909  layout="button_count"
910  show_faces="false"
911  width="90"
912  colorscheme="light"
913  share="1"
914  action="like" ></fb:like>'."\n";
915  $out .= '</div>'."\n";
916 
917  $out .= "\n</div>\n";
918  } else {
919  $out .= '<!-- virtual host not defined in CMS. No way to add sharing buttons -->'."\n";
920  }
921  $out .= '<!-- section end for social network sharing of page -->'."\n";
922 
923  return $out;
924 }
925 
941 function getPagesFromSearchCriterias($type, $algo, $searchstring, $max = 25, $sortfield = 'date_creation', $sortorder = 'DESC', $langcode = '', $otherfilters = 'null', $status = 1)
942 {
943  global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs; // Very important. Required to have var available when running inluded containers.
944 
945  $error = 0;
946  $arrayresult = array('code'=>'', 'list'=>array());
947 
948  if (!is_object($weblangs)) {
949  $weblangs = $langs;
950  }
951 
952  if (empty($searchstring) && empty($type) && empty($langcode) && empty($otherfilters)) {
953  $error++;
954  $arrayresult['code'] = 'KO';
955  $arrayresult['message'] = $weblangs->trans("EmptySearchString");
956  } elseif ($searchstring && dol_strlen($searchstring) < 2) {
957  $weblangs->load("errors");
958  $error++;
959  $arrayresult['code'] = 'KO';
960  $arrayresult['message'] = $weblangs->trans("ErrorSearchCriteriaTooSmall");
961  } else {
962  $tmparrayoftype = explode(',', $type);
963  /*foreach ($tmparrayoftype as $tmptype) {
964  if (!in_array($tmptype, array('', 'page', 'blogpost'))) {
965  $error++;
966  $arrayresult['code'] = 'KO';
967  $arrayresult['message'] = 'Bad value for parameter type';
968  break;
969  }
970  }*/
971  }
972 
973  $searchdone = 0;
974  $found = 0;
975 
976  if (!$error && (empty($max) || ($found < $max)) && (preg_match('/meta/', $algo) || preg_match('/content/', $algo))) {
977  include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
978 
979  $sql = 'SELECT wp.rowid FROM '.MAIN_DB_PREFIX.'website_page as wp';
980  if (is_array($otherfilters) && !empty($otherfilters['category'])) {
981  $sql .= ', '.MAIN_DB_PREFIX.'categorie_website_page as cwp';
982  }
983  $sql .= " WHERE wp.fk_website = ".((int) $website->id);
984  if ($status >= 0) {
985  $sql .= " AND wp.status = ".((int) $status);
986  }
987  if ($langcode) {
988  $sql .= " AND wp.lang = '".$db->escape($langcode)."'";
989  }
990  if ($type) {
991  $tmparrayoftype = explode(',', $type);
992  $typestring = '';
993  foreach ($tmparrayoftype as $tmptype) {
994  $typestring .= ($typestring ? ", " : "")."'".$db->escape(trim($tmptype))."'";
995  }
996  $sql .= " AND wp.type_container IN (".$db->sanitize($typestring, 1).")";
997  }
998  $sql .= " AND (";
999  $searchalgo = '';
1000  if (preg_match('/meta/', $algo)) {
1001  $searchalgo .= ($searchalgo ? ' OR ' : '')."wp.title LIKE '%".$db->escape($db->escapeforlike($searchstring))."%' OR wp.description LIKE '%".$db->escape($db->escapeforlike($searchstring))."%'";
1002  $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
1003  }
1004  if (preg_match('/content/', $algo)) {
1005  $searchalgo .= ($searchalgo ? ' OR ' : '')."wp.content LIKE '%".$db->escape($db->escapeforlike($searchstring))."%'";
1006  }
1007  $sql .= $searchalgo;
1008  if (is_array($otherfilters) && !empty($otherfilters['category'])) {
1009  $sql .= ' AND cwp.fk_website_page = wp.rowid AND cwp.fk_categorie = '.((int) $otherfilters['category']);
1010  }
1011  $sql .= ")";
1012  $sql .= $db->order($sortfield, $sortorder);
1013  $sql .= $db->plimit($max);
1014  //print $sql;
1015 
1016  $resql = $db->query($sql);
1017 
1018  if ($resql) {
1019  $i = 0;
1020  while (($obj = $db->fetch_object($resql)) && ($i < $max || $max == 0)) {
1021  if ($obj->rowid > 0) {
1022  $tmpwebsitepage = new WebsitePage($db);
1023  $tmpwebsitepage->fetch($obj->rowid);
1024  if ($tmpwebsitepage->id > 0) {
1025  $arrayresult['list'][$obj->rowid] = $tmpwebsitepage;
1026  }
1027  $found++;
1028  }
1029  $i++;
1030  }
1031  } else {
1032  $error++;
1033  $arrayresult['code'] = $db->lasterrno();
1034  $arrayresult['message'] = $db->lasterror();
1035  }
1036 
1037  $searchdone = 1;
1038  }
1039 
1040  if (!$error && (empty($max) || ($found < $max)) && (preg_match('/sitefiles/', $algo))) {
1041  global $dolibarr_main_data_root;
1042 
1043  $pathofwebsite = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$website->ref;
1044  $filehtmlheader = $pathofwebsite.'/htmlheader.html';
1045  $filecss = $pathofwebsite.'/styles.css.php';
1046  $filejs = $pathofwebsite.'/javascript.js.php';
1047  $filerobot = $pathofwebsite.'/robots.txt';
1048  $filehtaccess = $pathofwebsite.'/.htaccess';
1049  $filemanifestjson = $pathofwebsite.'/manifest.json.php';
1050  $filereadme = $pathofwebsite.'/README.md';
1051 
1052  $filecontent = file_get_contents($filehtmlheader);
1053  if ((empty($max) || ($found < $max)) && preg_match('/'.preg_quote($searchstring, '/').'/', $filecontent)) {
1054  $arrayresult['list'][] = array('type'=>'website_htmlheadercontent');
1055  }
1056 
1057  $filecontent = file_get_contents($filecss);
1058  if ((empty($max) || ($found < $max)) && preg_match('/'.preg_quote($searchstring, '/').'/', $filecontent)) {
1059  $arrayresult['list'][] = array('type'=>'website_csscontent');
1060  }
1061 
1062  $filecontent = file_get_contents($filejs);
1063  if ((empty($max) || ($found < $max)) && preg_match('/'.preg_quote($searchstring, '/').'/', $filecontent)) {
1064  $arrayresult['list'][] = array('type'=>'website_jscontent');
1065  }
1066 
1067  $filerobot = file_get_contents($filerobot);
1068  if ((empty($max) || ($found < $max)) && preg_match('/'.preg_quote($searchstring, '/').'/', $filecontent)) {
1069  $arrayresult['list'][] = array('type'=>'website_robotcontent');
1070  }
1071 
1072  $searchdone = 1;
1073  }
1074 
1075  if (!$error) {
1076  if ($searchdone) {
1077  $arrayresult['code'] = 'OK';
1078  if (empty($arrayresult['list'])) {
1079  $arrayresult['code'] = 'KO';
1080  $arrayresult['message'] = $weblangs->trans("NoRecordFound");
1081  }
1082  } else {
1083  $error++;
1084  $arrayresult['code'] = 'KO';
1085  $arrayresult['message'] = 'No supported algorithm found';
1086  }
1087  }
1088 
1089  return $arrayresult;
1090 }
1091 
1106 function getAllImages($object, $objectpage, $urltograb, &$tmp, &$action, $modifylinks = 0, $grabimages = 1, $grabimagesinto = 'subpage')
1107 {
1108  global $conf;
1109 
1110  $error = 0;
1111 
1112  dol_syslog("Call getAllImages with grabimagesinto=".$grabimagesinto);
1113 
1114  $alreadygrabbed = array();
1115 
1116  if (preg_match('/\/$/', $urltograb)) {
1117  $urltograb .= '.';
1118  }
1119  $urltograb = dirname($urltograb); // So urltograb is now http://www.nltechno.com or http://www.nltechno.com/dir1
1120 
1121  // Search X in "img...src=X"
1122  $regs = array();
1123  preg_match_all('/<img([^\.\/]+)src="([^>"]+)"([^>]*)>/i', $tmp, $regs);
1124 
1125  foreach ($regs[0] as $key => $val) {
1126  if (preg_match('/^data:image/i', $regs[2][$key])) {
1127  continue; // We do nothing for such images
1128  }
1129 
1130  if (preg_match('/^\//', $regs[2][$key])) {
1131  $urltograbdirrootwithoutslash = getRootURLFromURL($urltograb);
1132  $urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key]; // We use dirroot
1133  } else {
1134  $urltograbbis = $urltograb.'/'.$regs[2][$key]; // We use dir of grabbed file
1135  }
1136 
1137  $linkwithoutdomain = $regs[2][$key];
1138  $dirforimages = '/'.$objectpage->pageurl;
1139  if ($grabimagesinto == 'root') {
1140  $dirforimages = '';
1141  }
1142 
1143  // Define $filetosave and $filename
1144  $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $regs[2][$key]) ? '' : '/').$regs[2][$key];
1145  if (preg_match('/^http/', $regs[2][$key])) {
1146  $urltograbbis = $regs[2][$key];
1147  $linkwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\//i', '', $regs[2][$key]);
1148  $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain) ? '' : '/').$linkwithoutdomain;
1149  }
1150  $filename = 'image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain) ? '' : '/').$linkwithoutdomain;
1151 
1152  // Clean the aa/bb/../cc into aa/cc
1153  $filetosave = preg_replace('/\/[^\/]+\/\.\./', '', $filetosave);
1154  $filename = preg_replace('/\/[^\/]+\/\.\./', '', $filename);
1155 
1156  //var_dump($filetosave);
1157  //var_dump($filename);
1158  //exit;
1159 
1160  if (empty($alreadygrabbed[$urltograbbis])) {
1161  if ($grabimages) {
1162  $tmpgeturl = getURLContent($urltograbbis, 'GET', '', 1, array(), array('http', 'https'), 0);
1163  if ($tmpgeturl['curl_error_no']) {
1164  $error++;
1165  setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['curl_error_msg'], null, 'errors');
1166  $action = 'create';
1167  } elseif ($tmpgeturl['http_code'] != '200') {
1168  $error++;
1169  setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['http_code'], null, 'errors');
1170  $action = 'create';
1171  } else {
1172  $alreadygrabbed[$urltograbbis] = 1; // Track that file was alreay grabbed.
1173 
1174  dol_mkdir(dirname($filetosave));
1175 
1176  $fp = fopen($filetosave, "w");
1177  fputs($fp, $tmpgeturl['content']);
1178  fclose($fp);
1179  if (!empty($conf->global->MAIN_UMASK)) {
1180  @chmod($filetosave, octdec($conf->global->MAIN_UMASK));
1181  }
1182  }
1183  }
1184  }
1185 
1186  if ($modifylinks) {
1187  $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);
1188  }
1189  }
1190 
1191  // Search X in "background...url(X)"
1192  preg_match_all('/background([^\.\/\‍(;]+)url\‍([\"\']?([^\‍)\"\']*)[\"\']?\‍)/i', $tmp, $regs);
1193 
1194  foreach ($regs[0] as $key => $val) {
1195  if (preg_match('/^data:image/i', $regs[2][$key])) {
1196  continue; // We do nothing for such images
1197  }
1198 
1199  if (preg_match('/^\//', $regs[2][$key])) {
1200  $urltograbdirrootwithoutslash = getRootURLFromURL($urltograb);
1201  $urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key]; // We use dirroot
1202  } else {
1203  $urltograbbis = $urltograb.'/'.$regs[2][$key]; // We use dir of grabbed file
1204  }
1205 
1206  $linkwithoutdomain = $regs[2][$key];
1207 
1208  $dirforimages = '/'.$objectpage->pageurl;
1209  if ($grabimagesinto == 'root') {
1210  $dirforimages = '';
1211  }
1212 
1213  $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $regs[2][$key]) ? '' : '/').$regs[2][$key];
1214 
1215  if (preg_match('/^http/', $regs[2][$key])) {
1216  $urltograbbis = $regs[2][$key];
1217  $linkwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\//i', '', $regs[2][$key]);
1218  $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain) ? '' : '/').$linkwithoutdomain;
1219  }
1220 
1221  $filename = 'image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain) ? '' : '/').$linkwithoutdomain;
1222 
1223  // Clean the aa/bb/../cc into aa/cc
1224  $filetosave = preg_replace('/\/[^\/]+\/\.\./', '', $filetosave);
1225  $filename = preg_replace('/\/[^\/]+\/\.\./', '', $filename);
1226 
1227  //var_dump($filetosave);
1228  //var_dump($filename);
1229  //exit;
1230 
1231  if (empty($alreadygrabbed[$urltograbbis])) {
1232  if ($grabimages) {
1233  $tmpgeturl = getURLContent($urltograbbis, 'GET', '', 1, array(), array('http', 'https'), 0);
1234  if ($tmpgeturl['curl_error_no']) {
1235  $error++;
1236  setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['curl_error_msg'], null, 'errors');
1237  $action = 'create';
1238  } elseif ($tmpgeturl['http_code'] != '200') {
1239  $error++;
1240  setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['http_code'], null, 'errors');
1241  $action = 'create';
1242  } else {
1243  $alreadygrabbed[$urltograbbis] = 1; // Track that file was alreay grabbed.
1244 
1245  dol_mkdir(dirname($filetosave));
1246 
1247  $fp = fopen($filetosave, "w");
1248  fputs($fp, $tmpgeturl['content']);
1249  fclose($fp);
1250  if (!empty($conf->global->MAIN_UMASK)) {
1251  @chmod($filetosave, octdec($conf->global->MAIN_UMASK));
1252  }
1253  }
1254  }
1255  }
1256 
1257  if ($modifylinks) {
1258  $tmp = preg_replace('/'.preg_quote($regs[0][$key], '/').'/i', 'background'.$regs[1][$key].'url("'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file='.$filename.'")', $tmp);
1259  }
1260  }
1261 }
Class Websitepage.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
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).
dol_escape_json($stringtoescape)
Returns text escaped for inclusion into javascript code.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
getRootURLFromURL($url)
Function root url from a long url For example: https://www.abc.mydomain.com/dir/page....
Definition: geturl.lib.php:349
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:41
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.
getPagesFromSearchCriterias($type, $algo, $searchstring, $max=25, $sortfield='date_creation', $sortorder='DESC', $langcode='', $otherfilters='null', $status=1)
Return list of containers object that match a criteria.
dolWebsiteReplacementOfLinks($website, $content, $removephppart=0, $contenttype='html', $containerid='')
Convert a page content to have correct links (based on DOL_URL_ROOT) into an html content.
dolStripPhpCode($str, $replacewith='')
Remove PHP code part from a string.
Definition: website.lib.php:32
getStructuredData($type, $data=array())
Return HTML content to add structured data for an article, news or Blog Post.
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:74
getSocialNetworkSharingLinks()
Return HTML content to add structured data for an article, news or Blog Post.
redirectToContainer($containerref, $containeraliasalt='', $containerid=0, $permanent=0)
Format img tags to introduce viewimage on img src.
dolWebsiteOutput($content, $contenttype='html', $containerid='')
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.