dolibarr 19.0.3
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
32function 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 $parts = preg_split('/'.preg_quote('<?php', '/').'/i', $str);
41
42 if (!empty($parts)) {
43 $i = 0;
44 foreach ($parts as $part) {
45 if ($i == 0) { // The first part is never php code
46 $i++;
47 $newstr .= $part;
48 continue;
49 }
50 // The second part is the php code. We split on closing tag
51 $partlings = explode('?>', $part);
52 if (!empty($partlings)) {
53 //$phppart = $partlings[0];
54 //remove content before closing tag
55 if (count($partlings) > 1) {
56 $partlings[0] = ''; // Todo why a count > 1 and not >= 1 ?
57 }
58 //append to out string
59 //$newstr .= '<span class="phptag" class="tooltip" title="'.dol_escape_htmltag(dolGetFirstLineOfText($phppart).'...').'">'.$replacewith.'<!-- '.$phppart.' --></span>'.implode('', $partlings);
60 //$newstr .= '<span>'.$replacewith.'<!-- '.$phppart.' --></span>'.implode('', $partlings);
61 $newstr .= '<span phptag>'.$replacewith.'</span>'.implode('', $partlings);
62 //$newstr .= $replacewith.implode('', $partlings);
63 }
64 }
65 }
66 return $newstr;
67}
68
76function dolKeepOnlyPhpCode($str)
77{
78 $str = str_replace('<?=', '<?php', $str);
79 $str = str_replace('<?php', '__LTINTPHP__', $str);
80 $str = str_replace('<?', '<?php', $str); // replace the short_open_tag. It is recommended to set this is Off in php.ini
81 $str = str_replace('__LTINTPHP__', '<?php', $str);
82
83 $newstr = '';
84
85 // Split on each opening tag
86 //$parts = explode('<?php', $str);
87 $parts = preg_split('/'.preg_quote('<?php', '/').'/i', $str);
88
89 if (!empty($parts)) {
90 $i = 0;
91 foreach ($parts as $part) {
92 if ($i == 0) { // The first part is never php code
93 $i++;
94 continue;
95 }
96 $newstr .= '<?php';
97 //split on closing tag
98 $partlings = explode('?>', $part, 2);
99 if (!empty($partlings)) {
100 $newstr .= $partlings[0].'?>';
101 } else {
102 $newstr .= $part.'?>';
103 }
104 }
105 }
106 return $newstr;
107}
108
121function dolWebsiteReplacementOfLinks($website, $content, $removephppart = 0, $contenttype = 'html', $containerid = '')
122{
123 $nbrep = 0;
124
125 dol_syslog('dolWebsiteReplacementOfLinks start (contenttype='.$contenttype." containerid=".$containerid." USEDOLIBARREDITOR=".(defined('USEDOLIBARREDITOR') ? '1' : '')." USEDOLIBARRSERVER=".(defined('USEDOLIBARRSERVER') ? '1' : '').')', LOG_DEBUG);
126 //if ($contenttype == 'html') { print $content;exit; }
127
128 // Replace php code. Note $content may come from database and does not contain body tags.
129 $replacewith = '...php...';
130 if ($removephppart) {
131 $replacewith = '';
132 }
133 $content = preg_replace('/value="<\?php((?!\?>).)*\?>\n*/ims', 'value="'.$replacewith.'"', $content);
134
135 $replacewith = '"callto=#';
136 if ($removephppart) {
137 $replacewith = '';
138 }
139 $content = preg_replace('/"callto:<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content);
140
141 $replacewith = '"mailto=#';
142 if ($removephppart) {
143 $replacewith = '';
144 }
145 $content = preg_replace('/"mailto:<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content);
146
147 $replacewith = 'src="php';
148 if ($removephppart) {
149 $replacewith = '';
150 }
151 $content = preg_replace('/src="<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content);
152
153 $replacewith = 'href="php';
154 if ($removephppart) {
155 $replacewith = '';
156 }
157 $content = preg_replace('/href="<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content);
158
159 //$replacewith='<span class="phptag">...php...</span>';
160 $replacewith = '...php...';
161 if ($removephppart) {
162 $replacewith = '';
163 }
164 //$content = preg_replace('/<\?php((?!\?toremove>).)*\?toremove>\n*/ims', $replacewith, $content);
165 /*if ($content === null) {
166 if (preg_last_error() == PREG_JIT_STACKLIMIT_ERROR) $content = 'preg_replace error (when removing php tags) PREG_JIT_STACKLIMIT_ERROR';
167 }*/
168 $content = dolStripPhpCode($content, $replacewith);
169
170 // Protect the link styles.css.php to any replacement that we make after.
171 $content = str_replace('href="styles.css.php', 'href="!~!~!~styles.css.php', $content);
172 $content = str_replace('src="javascript.js.php', 'src="!~!~!~javascript.js.php', $content);
173 $content = str_replace('href="http', 'href="!~!~!~http', $content);
174 $content = str_replace('xlink:href="', 'xlink:href="!~!~!~', $content);
175 $content = str_replace('href="//', 'href="!~!~!~//', $content);
176 $content = str_replace('src="//', 'src="!~!~!~//', $content);
177 $content = str_replace('src="viewimage.php', 'src="!~!~!~/viewimage.php', $content);
178 $content = str_replace('src="/viewimage.php', 'src="!~!~!~/viewimage.php', $content);
179 $content = str_replace('src="'.DOL_URL_ROOT.'/viewimage.php', 'src="!~!~!~'.DOL_URL_ROOT.'/viewimage.php', $content);
180 $content = str_replace('href="document.php', 'href="!~!~!~/document.php', $content);
181 $content = str_replace('href="/document.php', 'href="!~!~!~/document.php', $content);
182 $content = str_replace('href="'.DOL_URL_ROOT.'/document.php', 'href="!~!~!~'.DOL_URL_ROOT.'/document.php', $content);
183
184 // Replace relative link '/' with dolibarr URL
185 $content = preg_replace('/(href=")\/(#[^\"<>]*)?\"/', '\1!~!~!~'.DOL_URL_ROOT.'/website/index.php?website='.$website->ref.'&pageid='.$website->fk_default_home.'\2"', $content, -1, $nbrep);
186 // Replace relative link /xxx.php#aaa or /xxx.php with dolibarr URL (we discard param ?...)
187 $content = preg_replace('/(href=")\/?([^:\"\!]*)\.php(#[^\"<>]*)?\"/', '\1!~!~!~'.DOL_URL_ROOT.'/website/index.php?website='.$website->ref.'&pageref=\2\3"', $content, -1, $nbrep);
188 // Replace relative link /xxx.php?a=b&c=d#aaa or /xxx.php?a=b&c=d with dolibarr URL
189 $content = preg_replace('/(href=")\/?([^:\"\!]*)\.php\?([^#\"<>]*)(#[^\"<>]*)?\"/', '\1!~!~!~'.DOL_URL_ROOT.'/website/index.php?website='.$website->ref.'&pageref=\2&\3\4"', $content, -1, $nbrep);
190
191 // Fix relative link into medias with correct URL after the DOL_URL_ROOT: ../url("medias/
192 $content = preg_replace('/url\‍((["\']?)\/?medias\//', 'url(\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
193 $content = preg_replace('/data-slide-bg=(["\']?)\/?medias\//', 'data-slide-bg=\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
194
195 // <img src="medias/...image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png...
196 // <img src="...image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png...
197 $content = preg_replace('/(<img[^>]*src=")\/?medias\//', '\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
198 // <img src="image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png...
199 $content = preg_replace('/(<img[^>]*src=")\/?([^:\"\!]+)\"/', '\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=\2"', $content, -1, $nbrep);
200 // <img src="viewimage.php/modulepart=medias&file=image.png" => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png"
201 $content = preg_replace('/(<img[^>]*src=")(\/?viewimage\.php)/', '\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php', $content, -1, $nbrep);
202
203 // action="newpage.php" => action="dolibarr/website/index.php?website=...&pageref=newpage
204 $content = preg_replace('/(action=")\/?([^:\"]*)(\.php\")/', '\1!~!~!~'.DOL_URL_ROOT.'/website/index.php?website='.$website->ref.'&pageref=\2"', $content, -1, $nbrep);
205
206 // Fix relative link /document.php with correct URL after the DOL_URL_ROOT: ...href="/document.php?modulepart="
207 $content = preg_replace('/(href=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1!~!~!~'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
208 $content = preg_replace('/(src=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1!~!~!~'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
209
210 // Fix relative link /viewimage.php with correct URL after the DOL_URL_ROOT: ...href="/viewimage.php?modulepart="
211 $content = preg_replace('/(url\‍(")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1!~!~!~'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
212
213 // Fix relative URL
214 $content = str_replace('src="!~!~!~/viewimage.php', 'src="!~!~!~'.DOL_URL_ROOT.'/viewimage.php', $content);
215 $content = str_replace('href="!~!~!~/document.php', 'href="!~!~!~'.DOL_URL_ROOT.'/document.php', $content);
216 // Remove the protection tag !~!~!~
217 $content = str_replace('!~!~!~', '', $content);
218
219 dol_syslog('dolWebsiteReplacementOfLinks end', LOG_DEBUG);
220 //if ($contenttype == 'html') { print $content;exit; }
221
222 return $content;
223}
224
232{
233 $map = array(
234 ":face_with_tears_of_joy:" => "\xF0\x9F\x98\x82",
235 ":grinning_face_with_smiling_eyes:" => "\xF0\x9F\x98\x81",
236 ":smiling_face_with_open_mouth:" => "\xF0\x9F\x98\x83",
237 ":smiling_face_with_open_mouth_and_cold_sweat:" => "\xF0\x9F\x98\x85",
238 ":smiling_face_with_open_mouth_and_tightly_closed_eyes:" => "\xF0\x9F\x98\x86",
239 ":winking_face:" => "\xF0\x9F\x98\x89",
240 ":smiling_face_with_smiling_eyes:" => "\xF0\x9F\x98\x8A",
241 ":face_savouring_delicious_food:" => "\xF0\x9F\x98\x8B",
242 ":relieved_face:" => "\xF0\x9F\x98\x8C",
243 ":smiling_face_with_heart_shaped_eyes:" => "\xF0\x9F\x98\x8D",
244 ":smiling_face_with_sunglasses:" => "\xF0\x9F\x98\x8E",
245 ":smirking_face:" => "\xF0\x9F\x98\x8F",
246 ":neutral_face:" => "\xF0\x9F\x98\x90",
247 ":expressionless_face:" => "\xF0\x9F\x98\x91",
248 ":unamused_face:" => "\xF0\x9F\x98\x92",
249 ":face_with_cold_sweat:" => "\xF0\x9F\x98\x93",
250 ":pensive_face:" => "\xF0\x9F\x98\x94",
251 ":confused_face:" => "\xF0\x9F\x98\x95",
252 ":confounded_face:" => "\xF0\x9F\x98\x96",
253 ":kissing_face:" => "\xF0\x9F\x98\x97",
254 ":face_throwing_a_kiss:" => "\xF0\x9F\x98\x98",
255 ":kissing_face_with_smiling_eyes:" => "\xF0\x9F\x98\x99",
256 ":kissing_face_with_closed_eyes:" => "\xF0\x9F\x98\x9A",
257 ":face_with_stuck_out_tongue:" => "\xF0\x9F\x98\x9B",
258 ":face_with_stuck_out_tongue_and_winking_eye:" => "\xF0\x9F\x98\x9C",
259 ":face_with_stuck_out_tongue_and_tightly_closed_eyes:" => "\xF0\x9F\x98\x9D",
260 ":disappointed_face:" => "\xF0\x9F\x98\x9E",
261 ":worried_face:" => "\xF0\x9F\x98\x9F",
262 ":angry_face:" => "\xF0\x9F\x98\xA0",
263 ":face_with_symbols_on_mouth:" => "\xF0\x9F\x98\xA1",
264 );
265 foreach ($map as $key => $value) {
266 $content = str_replace($key, $value, $content);
267 }
268 return $content;
269}
270
271
282function dolWebsiteOutput($content, $contenttype = 'html', $containerid = '')
283{
284 global $db, $langs, $conf, $user;
285 global $dolibarr_main_url_root, $dolibarr_main_data_root;
286 global $website;
287 global $includehtmlcontentopened;
288
289 $nbrep = 0;
290
291 dol_syslog("dolWebsiteOutput start - contenttype=".$contenttype." containerid=".$containerid." USEDOLIBARREDITOR=".(defined('USEDOLIBARREDITOR') ? '1' : '')." USEDOLIBARRSERVER=".(defined('USEDOLIBARRSERVER') ? '1' : '').' includehtmlcontentopened='.$includehtmlcontentopened);
292
293 //print $containerid.' '.$content;
294
295 // Define $urlwithroot
296 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
297 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
298 //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
299
300 if (defined('USEDOLIBARREDITOR')) { // REPLACEMENT OF LINKS When page called from Dolibarr editor
301 // We remove the <head> part of content
302 if ($contenttype == 'html') {
303 $content = preg_replace('/<head>.*<\/head>/ims', '', $content);
304 $content = preg_replace('/^.*<body(\s[^>]*)*>/ims', '', $content);
305 $content = preg_replace('/<\/body(\s[^>]*)*>.*$/ims', '', $content);
306 }
307 } elseif (defined('USEDOLIBARRSERVER')) { // REPLACEMENT OF LINKS When page called from Dolibarr server
308 $content = str_replace('<link rel="stylesheet" href="/styles.css', '<link rel="stylesheet" href="styles.css', $content);
309 $content = str_replace(' async src="/javascript.js', ' async src="javascript.js', $content);
310
311 // Protect the link styles.css.php to any replacement that we make after.
312 $content = str_replace('href="styles.css.php', 'href="!~!~!~styles.css.php', $content);
313 $content = str_replace('src="javascript.css.php', 'src="!~!~!~javascript.css.php', $content);
314 $content = str_replace('href="http', 'href="!~!~!~http', $content);
315 $content = str_replace('xlink:href="', 'xlink:href="!~!~!~', $content);
316 $content = str_replace('href="//', 'href="!~!~!~//', $content);
317 $content = str_replace('src="//', 'src="!~!~!~//', $content);
318 $content = str_replace(array('src="viewimage.php', 'src="/viewimage.php'), 'src="!~!~!~/viewimage.php', $content);
319 $content = str_replace('src="'.DOL_URL_ROOT.'/viewimage.php', 'src="!~!~!~'.DOL_URL_ROOT.'/viewimage.php', $content);
320 $content = str_replace(array('href="document.php', 'href="/document.php'), 'href="!~!~!~/document.php', $content);
321 $content = str_replace('href="'.DOL_URL_ROOT.'/document.php', 'href="!~!~!~'.DOL_URL_ROOT.'/document.php', $content);
322
323 // Replace relative link / with dolibarr URL: ...href="/"...
324 $content = preg_replace('/(href=")\/\"/', '\1!~!~!~'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'"', $content, -1, $nbrep);
325 // Replace relative link /xxx.php#aaa or /xxx.php with dolibarr URL: ...href="....php" (we discard param ?...)
326 $content = preg_replace('/(href=")\/?([^:\"\!]*)\.php(#[^\"<>]*)?\"/', '\1!~!~!~'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2\3"', $content, -1, $nbrep);
327 // Replace relative link /xxx.php?a=b&c=d#aaa or /xxx.php?a=b&c=d with dolibarr URL
328 // Warning: we may replace twice if href="..." was inside an include (dolWebsiteOutput called by include and the by final page), that's why
329 // at end we replace the '!~!~!~' only if we are in final parent page.
330 $content = preg_replace('/(href=")\/?([^:\"\!]*)\.php\?([^#\"<>]*)(#[^\"<>]*)?\"/', '\1!~!~!~'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2&\3\4"', $content, -1, $nbrep);
331 // Replace relative link without .php like /xxx#aaa or /xxx with dolibarr URL: ...href="....php"
332 $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);
333
334 // Fix relative link /document.php with correct URL after the DOL_URL_ROOT: href="/document.php?modulepart=" => href="/dolibarr/document.php?modulepart="
335 $content = preg_replace('/(href=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1!~!~!~'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
336 $content = preg_replace('/(src=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1!~!~!~'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
337
338 // Fix relative link /viewimage.php with correct URL after the DOL_URL_ROOT: href="/viewimage.php?modulepart=" => href="/dolibarr/viewimage.php?modulepart="
339 $content = preg_replace('/(href=")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1!~!~!~'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
340 $content = preg_replace('/(src=")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1!~!~!~'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
341 $content = preg_replace('/(url\‍(")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1!~!~!~'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
342
343 // Fix relative link into medias with correct URL after the DOL_URL_ROOT: ../url("medias/
344 $content = preg_replace('/url\‍((["\']?)\/?medias\//', 'url(\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
345 $content = preg_replace('/data-slide-bg=(["\']?)\/?medias\//', 'data-slide-bg=\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
346
347 // <img src="medias/...image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png...
348 // <img src="...image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png...
349 $content = preg_replace('/(<img[^>]*src=")\/?medias\//', '\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
350 // <img src="image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png...
351 $content = preg_replace('/(<img[^>]*src=")\/?([^:\"\!]+)\"/', '\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=\2"', $content, -1, $nbrep);
352 // <img src="viewimage.php/modulepart=medias&file=image.png" => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png"
353 $content = preg_replace('/(<img[^>]*src=")(\/?viewimage\.php)/', '\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php', $content, -1, $nbrep);
354
355 // action="newpage.php" => action="dolibarr/website/index.php?website=...&pageref=newpage
356 $content = preg_replace('/(action=")\/?([^:\"]*)(\.php\")/', '\1!~!~!~'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2"', $content, -1, $nbrep);
357
358 // Fix relative URL
359 $content = str_replace('src="!~!~!~/viewimage.php', 'src="!~!~!~'.DOL_URL_ROOT.'/viewimage.php', $content);
360 $content = str_replace('href="!~!~!~/document.php', 'href="!~!~!~'.DOL_URL_ROOT.'/document.php', $content);
361
362 // Remove the protection tag !~!~!~, but only if this is the parent page and not an include
363 if (empty($includehtmlcontentopened)) {
364 $content = str_replace('!~!~!~', '', $content);
365 }
366 } else { // REPLACEMENT OF LINKS When page called from virtual host web server
367 $symlinktomediaexists = 1;
368 if ($website->virtualhost) {
369 $content = preg_replace('/^(<link[^>]*rel="canonical" href=")\//m', '\1'.$website->virtualhost.'/', $content, -1, $nbrep);
370 }
371 //print 'rrrrrrrrr'.$website->virtualhost.$content;
372
373
374 // Make a change into HTML code to allow to include images from medias directory correct with direct link for virtual server
375 // <img alt="" src="/dolibarr_dev/htdocs/viewimage.php?modulepart=medias&amp;entity=1&amp;file=image/ldestailleur_166x166.jpg" style="height:166px; width:166px" />
376 // become
377 // <img alt="" src="'.$urlwithroot.'/medias/image/ldestailleur_166x166.jpg" style="height:166px; width:166px" />
378 if (!$symlinktomediaexists) {
379 // <img src="image.png... => <img src="medias/image.png...
380 $content = preg_replace('/(<img[^>]*src=")\/?image\//', '\1/wrapper.php?modulepart=medias&file=medias/image/', $content, -1, $nbrep);
381 $content = preg_replace('/(url\‍(["\']?)\/?image\//', '\1/wrapper.php?modulepart=medias&file=medias/image/', $content, -1, $nbrep);
382
383 $content = preg_replace('/(<script[^>]*src=")[^\"]*document\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep);
384 $content = preg_replace('/(<a[^>]*href=")[^\"]*document\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep);
385
386 $content = preg_replace('/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep);
387 $content = preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep);
388 $content = preg_replace('/(url\‍(["\']?)[^\‍)]*viewimage\.php([^\‍)]*)modulepart=medias([^\‍)]*)file=([^\‍)]*)(["\']?\‍))/', '\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep);
389
390 $content = preg_replace('/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep);
391 $content = preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep);
392 $content = preg_replace('/(url\‍(["\']?)[^\‍)]*viewimage\.php([^\‍)]*)hashp=([^\‍)]*)(["\']?\‍))/', '\1/wrapper.php\2hashp\3\4', $content, -1, $nbrep);
393
394 $content = preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=mycompany([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=mycompany\3file=\4\5', $content, -1, $nbrep);
395
396 // If some links to documents or viewimage remains, we replace with wrapper
397 $content = preg_replace('/(<img[^>]*src=")\/?viewimage\.php/', '\1/wrapper.php', $content, -1, $nbrep);
398 $content = preg_replace('/(<a[^>]*href=")\/?documents\.php/', '\1/wrapper.php', $content, -1, $nbrep);
399 } else {
400 // <img src="image.png... => <img src="medias/image.png...
401 $content = preg_replace('/(<img[^>]*src=")\/?image\//', '\1/medias/image/', $content, -1, $nbrep);
402 $content = preg_replace('/(url\‍(["\']?)\/?image\//', '\1/medias/image/', $content, -1, $nbrep);
403
404 $content = preg_replace('/(<script[^>]*src=")[^\"]*document\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/medias/\4\5', $content, -1, $nbrep);
405 $content = preg_replace('/(<a[^>]*href=")[^\"]*document\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/medias/\4\5', $content, -1, $nbrep);
406
407 $content = preg_replace('/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/medias/\4\5', $content, -1, $nbrep);
408 $content = preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/medias/\4\5', $content, -1, $nbrep);
409 $content = preg_replace('/(url\‍(["\']?)[^\‍)]*viewimage\.php([^\‍)]*)modulepart=medias([^\‍)]*)file=([^\‍)]*)(["\']?\‍))/', '\1/medias/\4\5', $content, -1, $nbrep);
410
411 $content = preg_replace('/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep);
412 $content = preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep);
413 $content = preg_replace('/(url\‍(["\']?)[^\‍)]*viewimage\.php([^\‍)]*)hashp=([^\‍)]*)(["\']?\‍))/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep);
414
415 $content = preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=mycompany([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=mycompany\3file=\4\5', $content, -1, $nbrep);
416
417 // If some links to documents or viewimage remains, we replace with wrapper
418 $content = preg_replace('/(<img[^>]*src=")\/?viewimage\.php/', '\1/wrapper.php', $content, -1, $nbrep);
419 $content = preg_replace('/(<a[^>]*href=")\/?document\.php/', '\1/wrapper.php', $content, -1, $nbrep);
420 }
421 }
422
423 if (!defined('USEDOLIBARREDITOR')) {
424 $content = str_replace(' contenteditable="true"', ' contenteditable="false"', $content);
425 }
426
427 if (getDolGlobalString('WEBSITE_ADD_CSS_TO_BODY')) {
428 $content = str_replace('<body id="bodywebsite" class="bodywebsite', '<body id="bodywebsite" class="bodywebsite ' . getDolGlobalString('WEBSITE_ADD_CSS_TO_BODY'), $content);
429 }
430
431 $content = dolReplaceSmileyCodeWithUTF8($content);
432
433 dol_syslog("dolWebsiteOutput end");
434
435 print $content;
436}
437
446function dolWebsiteIncrementCounter($websiteid, $websitepagetype, $websitepageid)
447{
448 if (!getDolGlobalInt('WEBSITE_PERF_DISABLE_COUNTERS')) {
449 //dol_syslog("dolWebsiteIncrementCounter websiteid=".$websiteid." websitepagetype=".$websitepagetype." websitepageid=".$websitepageid);
450 if (in_array($websitepagetype, array('blogpost', 'page'))) {
451 global $db;
452
453 $tmpnow = dol_getdate(dol_now('gmt'), true, 'gmt');
454
455 $sql = "UPDATE ".$db->prefix()."website SET ";
456 $sql .= " pageviews_total = pageviews_total + 1,";
457 $sql .= " pageviews_month = pageviews_month + 1,";
458 // if last access was done during previous month, we save pageview_month into pageviews_previous_month
459 $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').",";
460 $sql .= " lastaccess = '".$db->idate(dol_now('gmt'), 'gmt')."'";
461 $sql .= " WHERE rowid = ".((int) $websiteid);
462 $resql = $db->query($sql);
463 if (! $resql) {
464 return -1;
465 }
466 }
467 }
468
469 return 1;
470}
471
472
480/*
481function dolWebsiteSaveContent($content)
482{
483 global $db, $langs, $conf, $user;
484 global $dolibarr_main_url_root, $dolibarr_main_data_root;
485
486 //dol_syslog("dolWebsiteSaveContent start (mode=".(defined('USEDOLIBARRSERVER')?'USEDOLIBARRSERVER':'').')');
487
488 // Define $urlwithroot
489 $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
490 $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
491 //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
492
493 //$content = preg_replace('/(<img.*src=")(?!(http|'.preg_quote(DOL_URL_ROOT,'/').'\/viewimage))/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
494
495 return $content;
496}
497*/
498
499
509function redirectToContainer($containerref, $containeraliasalt = '', $containerid = 0, $permanent = 0)
510{
511 global $db, $website;
512
513 $newurl = '';
514 $result = 0;
515
516 // We make redirect using the alternative alias, we must find the real $containerref
517 if ($containeraliasalt) {
518 include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
519 $tmpwebsitepage = new WebsitePage($db);
520 $result = $tmpwebsitepage->fetch(0, $website->id, '', $containeraliasalt);
521 if ($result > 0) {
522 $containerref = $tmpwebsitepage->pageurl;
523 } else {
524 print "Error, page contains a redirect to the alternative alias '".$containeraliasalt."' that does not exists in web site (".$website->id." / ".$website->ref.")";
525 exit;
526 }
527 }
528
529 if (defined('USEDOLIBARREDITOR')) {
530 /*print '<div class="margintoponly marginleftonly">';
531 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.";
532 print '</div>';*/
533 $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.";
534 setEventMessages($text, null, 'warnings', 'WEBSITEREDIRECTDISABLED'.$containerref);
535 return;
536 }
537
538 if (defined('USEDOLIBARRSERVER')) { // When page called from Dolibarr server
539 // Check new container exists
540 if (!$containeraliasalt) { // If containeraliasalt set, we already did the test
541 include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
542 $tmpwebsitepage = new WebsitePage($db);
543 $result = $tmpwebsitepage->fetch(0, $website->id, $containerref);
544 unset($tmpwebsitepage);
545 }
546 if ($result > 0) {
547 $currenturi = $_SERVER["REQUEST_URI"]; // Example: /public/website/index.php?website=mywebsite.com&pageref=mywebsite-home&nocache=1708177483
548 $regtmp = array();
549 if (preg_match('/&pageref=([^&]+)/', $currenturi, $regtmp)) {
550 if ($regtmp[0] == $containerref) {
551 print "Error, page with uri '.$currenturi.' try a redirect to the same alias page '".$containerref."' in web site '".$website->ref."'";
552 exit;
553 } else {
554 $newurl = preg_replace('/&pageref=([^&]+)/', '&pageref='.$containerref, $currenturi);
555 }
556 } else {
557 $newurl = $currenturi.'&pageref='.urlencode($containerref);
558 }
559 }
560 } else { // When page called from virtual host server
561 $newurl = '/'.$containerref.'.php';
562 $newurl = $newurl.(empty($_SERVER["QUERY_STRING"]) ? '' : '?'.$_SERVER["QUERY_STRING"]);
563 }
564
565 if ($newurl) {
566 if ($permanent) {
567 header("Status: 301 Moved Permanently", false, 301);
568 }
569 header("Location: ".$newurl);
570 exit;
571 } else {
572 print "Error, page contains a redirect to the alias page '".$containerref."' that does not exists in web site (".$website->id." / ".$website->ref.")";
573 exit;
574 }
575}
576
577
585function includeContainer($containerref)
586{
587 global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs; // Very important. Required to have var available when running included containers.
588 global $includehtmlcontentopened;
589 global $websitekey, $websitepagefile;
590
591 $MAXLEVEL = 20;
592
593 if (!preg_match('/\.php$/i', $containerref)) {
594 $containerref .= '.php';
595 }
596
597 $fullpathfile = DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$websitekey.'/'.$containerref;
598
599 if (empty($includehtmlcontentopened)) {
600 $includehtmlcontentopened = 0;
601 }
602 $includehtmlcontentopened++;
603 if ($includehtmlcontentopened > $MAXLEVEL) {
604 print 'ERROR: RECURSIVE CONTENT LEVEL. Depth of recursive call is more than the limit of '.((int) $MAXLEVEL).".\n";
605 return;
606 }
607
608 //dol_syslog("Include container ".$containerref.' includehtmlcontentopened='.$includehtmlcontentopened);
609
610 // file_get_contents is not possible. We must execute code with include
611 //$content = file_get_contents($fullpathfile);
612 //print preg_replace(array('/^.*<body[^>]*>/ims','/<\/body>.*$/ims'), array('', ''), $content);*/
613
614 ob_start();
615 $res = include $fullpathfile; // Include because we want to execute code content
616 $tmpoutput = ob_get_contents();
617 ob_end_clean();
618
619 print "\n".'<!-- include '.$websitekey.'/'.$containerref.(is_object($websitepage) ? ' parent id='.$websitepage->id : '').' level = '.$includehtmlcontentopened.' -->'."\n";
620 print preg_replace(array('/^.*<body[^>]*>/ims', '/<\/body>.*$/ims'), array('', ''), $tmpoutput);
621
622 if (!$res) {
623 print 'ERROR: FAILED TO INCLUDE PAGE '.$containerref.".\n";
624 }
625
626 $includehtmlcontentopened--;
627}
628
639function getStructuredData($type, $data = array())
640{
641 global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs, $pagelangs; // Very important. Required to have var available when running inluded containers.
642
643 $type = strtolower($type);
644
645 if ($type == 'software') {
646 $ret = '<!-- Add structured data for entry in a software annuary -->'."\n";
647 $ret .= '<script nonce="'.getNonce().'" type="application/ld+json">'."\n";
648 $ret .= '{
649 "@context": "https://schema.org",
650 "@type": "SoftwareApplication",
651 "name": "'.dol_escape_json($data['name']).'",
652 "operatingSystem": "'.dol_escape_json($data['os']).'",
653 "applicationCategory": "https://schema.org/'.dol_escape_json($data['applicationCategory']).'",';
654 if (!empty($data['ratingcount'])) {
655 $ret .= '
656 "aggregateRating": {
657 "@type": "AggregateRating",
658 "ratingValue": "'.dol_escape_json($data['ratingvalue']).'",
659 "ratingCount": "'.dol_escape_json($data['ratingcount']).'"
660 },';
661 }
662 $ret .= '
663 "offers": {
664 "@type": "Offer",
665 "price": "'.dol_escape_json($data['price']).'",
666 "priceCurrency": "'.dol_escape_json($data['currency'] ? $data['currency'] : $conf->currency).'"
667 }
668 }'."\n";
669 $ret .= '</script>'."\n";
670 } elseif ($type == 'organization') {
671 $companyname = $mysoc->name;
672 $url = $mysoc->url;
673
674 $ret = '<!-- Add structured data for organization -->'."\n";
675 $ret .= '<script nonce="'.getNonce().'" type="application/ld+json">'."\n";
676 $ret .= '{
677 "@context": "https://schema.org",
678 "@type": "Organization",
679 "name": "'.dol_escape_json(!empty($data['name']) ? $data['name'] : $companyname).'",
680 "url": "'.dol_escape_json(!empty($data['url']) ? $data['url'] : $url).'",
681 "logo": "'.($data['logo'] ? dol_escape_json($data['logo']) : '/wrapper.php?modulepart=mycompany&file=logos%2F'.urlencode($mysoc->logo)).'",
682 "contactPoint": {
683 "@type": "ContactPoint",
684 "contactType": "Contact",
685 "email": "'.dol_escape_json(!empty($data['email']) ? $data['email'] : $mysoc->email).'"
686 }'."\n";
687 if (is_array($mysoc->socialnetworks) && count($mysoc->socialnetworks) > 0) {
688 $ret .= ",\n";
689 $ret .= '"sameAs": [';
690 $i = 0;
691 foreach ($mysoc->socialnetworks as $key => $value) {
692 if ($key == 'linkedin') {
693 $ret .= '"https://www.'.$key.'.com/company/'.dol_escape_json($value).'"';
694 } elseif ($key == 'youtube') {
695 $ret .= '"https://www.'.$key.'.com/user/'.dol_escape_json($value).'"';
696 } else {
697 $ret .= '"https://www.'.$key.'.com/'.dol_escape_json($value).'"';
698 }
699 $i++;
700 if ($i < count($mysoc->socialnetworks)) {
701 $ret .= ', ';
702 }
703 }
704 $ret .= ']'."\n";
705 }
706 $ret .= '}'."\n";
707 $ret .= '</script>'."\n";
708 } elseif ($type == 'blogpost') {
709 if (!empty($websitepage->author_alias)) {
710 //include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
711 //$tmpuser = new User($db);
712 //$restmpuser = $tmpuser->fetch($websitepage->fk_user_creat);
713
714 $pageurl = $websitepage->pageurl;
715 $title = $websitepage->title;
716 $image = $websitepage->image;
717 $companyname = $mysoc->name;
718 $description = $websitepage->description;
719
720 $pageurl = str_replace('__WEBSITE_KEY__', $website->ref, $pageurl);
721 $title = str_replace('__WEBSITE_KEY__', $website->ref, $title);
722 $image = '/medias'.(preg_match('/^\//', $image) ? '' : '/').str_replace('__WEBSITE_KEY__', $website->ref, $image);
723 $companyname = str_replace('__WEBSITE_KEY__', $website->ref, $companyname);
724 $description = str_replace('__WEBSITE_KEY__', $website->ref, $description);
725
726 $ret = '<!-- Add structured data for blog post -->'."\n";
727 $ret .= '<script nonce="'.getNonce().'" type="application/ld+json">'."\n";
728 $ret .= '{
729 "@context": "https://schema.org",
730 "@type": "NewsArticle",
731 "mainEntityOfPage": {
732 "@type": "WebPage",
733 "@id": "'.dol_escape_json($pageurl).'"
734 },
735 "headline": "'.dol_escape_json($title).'",
736 "image": [
737 "'.dol_escape_json($image).'"
738 ],
739 "dateCreated": "'.dol_print_date($websitepage->date_creation, 'dayhourrfc').'",
740 "datePublished": "'.dol_print_date($websitepage->date_creation, 'dayhourrfc').'",
741 "dateModified": "'.dol_print_date($websitepage->date_modification, 'dayhourrfc').'",
742 "author": {
743 "@type": "Person",
744 "name": "'.dol_escape_json($websitepage->author_alias).'"
745 },
746 "publisher": {
747 "@type": "Organization",
748 "name": "'.dol_escape_json($companyname).'",
749 "logo": {
750 "@type": "ImageObject",
751 "url": "/wrapper.php?modulepart=mycompany&file=logos%2F'.urlencode($mysoc->logo).'"
752 }
753 },'."\n";
754 if ($websitepage->keywords) {
755 $ret .= '"keywords": [';
756 $i = 0;
757 $arrayofkeywords = explode(',', $websitepage->keywords);
758 foreach ($arrayofkeywords as $keyword) {
759 $ret .= '"'.dol_escape_json($keyword).'"';
760 $i++;
761 if ($i < count($arrayofkeywords)) {
762 $ret .= ', ';
763 }
764 }
765 $ret .= '],'."\n";
766 }
767 $ret .= '"description": "'.dol_escape_json($description).'"';
768 $ret .= "\n".'}'."\n";
769 $ret .= '</script>'."\n";
770 } else {
771 $ret = '<!-- no structured data inserted inline inside blogpost because no author_alias defined -->'."\n";
772 }
773 } elseif ($type == 'product') {
774 $ret = '<!-- Add structured data for product -->'."\n";
775 $ret .= '<script nonce="'.getNonce().'" type="application/ld+json">'."\n";
776 $ret .= '{
777 "@context": "https://schema.org/",
778 "@type": "Product",
779 "name": "'.dol_escape_json($data['label']).'",
780 "image": [
781 "'.dol_escape_json($data['image']).'",
782 ],
783 "description": "'.dol_escape_json($data['description']).'",
784 "sku": "'.dol_escape_json($data['ref']).'",
785 "brand": {
786 "@type": "Thing",
787 "name": "'.dol_escape_json($data['brand']).'"
788 },
789 "author": {
790 "@type": "Person",
791 "name": "'.dol_escape_json($data['author']).'"
792 }
793 },
794 "offers": {
795 "@type": "Offer",
796 "url": "https://example.com/anvil",
797 "priceCurrency": "'.dol_escape_json($data['currency'] ? $data['currency'] : $conf->currency).'",
798 "price": "'.dol_escape_json($data['price']).'",
799 "itemCondition": "https://schema.org/UsedCondition",
800 "availability": "https://schema.org/InStock",
801 "seller": {
802 "@type": "Organization",
803 "name": "'.dol_escape_json($mysoc->name).'"
804 }
805 }
806 }'."\n";
807 $ret .= '</script>'."\n";
808 } elseif ($type == 'qa') {
809 $ret = '<!-- Add structured data for QA -->'."\n";
810 $ret .= '<script nonce="'.getNonce().'" type="application/ld+json">'."\n";
811 $ret .= '{
812 "@context": "https://schema.org/",
813 "@type": "QAPage",
814 "mainEntity": {
815 "@type": "Question",
816 "name": "'.dol_escape_json($data['name']).'",
817 "text": "'.dol_escape_json($data['name']).'",
818 "answerCount": 1,
819 "author": {
820 "@type": "Person",
821 "name": "'.dol_escape_json($data['author']).'"
822 }
823 "acceptedAnswer": {
824 "@type": "Answer",
825 "text": "'.dol_escape_json(dol_string_nohtmltag(dolStripPhpCode($data['description']))).'",
826 "author": {
827 "@type": "Person",
828 "name": "'.dol_escape_json($data['author']).'"
829 }
830 }
831 }
832 }'."\n";
833 $ret .= '</script>'."\n";
834 }
835 return $ret;
836}
837
844function getSocialNetworkHeaderCards($params = null)
845{
846 global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs; // Very important. Required to have var available when running inluded containers.
847
848 $out = '';
849
850 if ($website->virtualhost) {
851 $pageurl = $websitepage->pageurl;
852 $title = $websitepage->title;
853 $image = $websitepage->image;
854 $companyname = $mysoc->name;
855 $description = $websitepage->description;
856
857 $pageurl = str_replace('__WEBSITE_KEY__', $website->ref, $pageurl);
858 $title = str_replace('__WEBSITE_KEY__', $website->ref, $title);
859 $image = '/medias'.(preg_match('/^\//', $image) ? '' : '/').str_replace('__WEBSITE_KEY__', $website->ref, $image);
860 $companyname = str_replace('__WEBSITE_KEY__', $website->ref, $companyname);
861 $description = str_replace('__WEBSITE_KEY__', $website->ref, $description);
862
863 $shortlangcode = '';
864 if ($websitepage->lang) {
865 $shortlangcode = substr($websitepage->lang, 0, 2); // en_US or en-US -> en
866 }
867 if (empty($shortlangcode)) {
868 $shortlangcode = substr($website->lang, 0, 2); // en_US or en-US -> en
869 }
870
871 $fullurl = $website->virtualhost.'/'.$websitepage->pageurl.'.php';
872 $canonicalurl = $website->virtualhost.(($websitepage->id == $website->fk_default_home) ? '/' : (($shortlangcode != substr($website->lang, 0, 2) ? '/'.$shortlangcode : '').'/'.$websitepage->pageurl.'.php'));
873 $hashtags = trim(join(' #', array_map('trim', explode(',', $websitepage->keywords))));
874
875 // Open Graph
876 $out .= '<meta name="og:type" content="website">'."\n"; // TODO If blogpost, use type article
877 $out .= '<meta name="og:title" content="'.$websitepage->title.'">'."\n";
878 if ($websitepage->image) {
879 $out .= '<meta name="og:image" content="'.$website->virtualhost.$image.'">'."\n";
880 }
881 $out .= '<meta name="og:url" content="'.$canonicalurl.'">'."\n";
882
883 // Twitter
884 $out .= '<meta name="twitter:card" content="summary">'."\n";
885 if (!empty($params) && !empty($params['twitter_account'])) {
886 $out .= '<meta name="twitter:site" content="@'.$params['twitter_account'].'">'."\n";
887 $out .= '<meta name="twitter:creator" content="@'.$params['twitter_account'].'">'."\n";
888 }
889 $out .= '<meta name="twitter:title" content="'.$websitepage->title.'">'."\n";
890 if ($websitepage->description) {
891 $out .= '<meta name="twitter:description" content="'.$websitepage->description.'">'."\n";
892 }
893 if ($websitepage->image) {
894 $out .= '<meta name="twitter:image" content="'.$website->virtualhost.$image.'">'."\n";
895 }
896 //$out .= '<meta name="twitter:domain" content="'.getDomainFromURL($website->virtualhost, 1).'">';
897 /*
898 $out .= '<meta name="twitter:app:name:iphone" content="">';
899 $out .= '<meta name="twitter:app:name:ipad" content="">';
900 $out .= '<meta name="twitter:app:name:googleplay" content="">';
901 $out .= '<meta name="twitter:app:url:iphone" content="">';
902 $out .= '<meta name="twitter:app:url:ipad" content="">';
903 $out .= '<meta name="twitter:app:url:googleplay" content="">';
904 $out .= '<meta name="twitter:app:id:iphone" content="">';
905 $out .= '<meta name="twitter:app:id:ipad" content="">';
906 $out .= '<meta name="twitter:app:id:googleplay" content="">';
907 */
908 }
909
910 return $out;
911}
912
919{
920 global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs; // Very important. Required to have var available when running inluded containers.
921
922 $out = '<!-- section for social network sharing of page -->'."\n";
923
924 if ($website->virtualhost) {
925 $fullurl = $website->virtualhost.'/'.$websitepage->pageurl.'.php';
926 $hashtags = trim(join(' #', array_map('trim', explode(',', $websitepage->keywords))));
927
928 $out .= '<div class="dol-social-share">'."\n";
929
930 // Twitter
931 $out .= '<div class="dol-social-share-tw">'."\n";
932 $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>';
933 $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>';
934 $out .= '</div>'."\n";
935
936 // Reddit
937 $out .= '<div class="dol-social-share-reddit">'."\n";
938 $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">';
939 $out .= '<span class="dol-social-share-reddit-span">Reddit</span>';
940 $out .= '</a>';
941 $out .= '</div>'."\n";
942
943 // Facebook
944 $out .= '<div class="dol-social-share-fbl">'."\n";
945 $out .= '<div id="fb-root"></div>'."\n";
946 $out .= '<script nonce="'.getNonce().'">(function(d, s, id) {
947 var js, fjs = d.getElementsByTagName(s)[0];
948 if (d.getElementById(id)) return;
949 js = d.createElement(s); js.id = id;
950 js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.0&amp;appId=dolibarr.org";
951 fjs.parentNode.insertBefore(js, fjs);
952 }(document, \'script\', \'facebook-jssdk\'));</script>
953 <fb:like
954 href="'.$fullurl.'"
955 layout="button_count"
956 show_faces="false"
957 width="90"
958 colorscheme="light"
959 share="1"
960 action="like" ></fb:like>'."\n";
961 $out .= '</div>'."\n";
962
963 $out .= "\n</div>\n";
964 } else {
965 $out .= '<!-- virtual host not defined in CMS. No way to add sharing buttons -->'."\n";
966 }
967 $out .= '<!-- section end for social network sharing of page -->'."\n";
968
969 return $out;
970}
971
987function getPagesFromSearchCriterias($type, $algo, $searchstring, $max = 25, $sortfield = 'date_creation', $sortorder = 'DESC', $langcode = '', $otherfilters = 'null', $status = 1)
988{
989 global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs; // Very important. Required to have var available when running inluded containers.
990
991 $error = 0;
992 $arrayresult = array('code'=>'', 'list'=>array());
993
994 if (!is_object($weblangs)) {
995 $weblangs = $langs;
996 }
997
998 if (empty($searchstring) && empty($type) && empty($langcode) && empty($otherfilters)) {
999 $error++;
1000 $arrayresult['code'] = 'KO';
1001 $arrayresult['message'] = $weblangs->trans("EmptySearchString");
1002 } elseif ($searchstring && dol_strlen($searchstring) < 2) {
1003 $weblangs->load("errors");
1004 $error++;
1005 $arrayresult['code'] = 'KO';
1006 $arrayresult['message'] = $weblangs->trans("ErrorSearchCriteriaTooSmall");
1007 } else {
1008 $tmparrayoftype = explode(',', $type);
1009 /*foreach ($tmparrayoftype as $tmptype) {
1010 if (!in_array($tmptype, array('', 'page', 'blogpost'))) {
1011 $error++;
1012 $arrayresult['code'] = 'KO';
1013 $arrayresult['message'] = 'Bad value for parameter type';
1014 break;
1015 }
1016 }*/
1017 }
1018
1019 $searchdone = 0;
1020 $found = 0;
1021
1022 if (!$error && (empty($max) || ($found < $max)) && (preg_match('/meta/', $algo) || preg_match('/content/', $algo))) {
1023 include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
1024
1025 $sql = 'SELECT wp.rowid FROM '.MAIN_DB_PREFIX.'website_page as wp';
1026 if (is_array($otherfilters) && !empty($otherfilters['category'])) {
1027 $sql .= ', '.MAIN_DB_PREFIX.'categorie_website_page as cwp';
1028 }
1029 $sql .= " WHERE wp.fk_website = ".((int) $website->id);
1030 if ($status >= 0) {
1031 $sql .= " AND wp.status = ".((int) $status);
1032 }
1033 if ($langcode) {
1034 $sql .= " AND wp.lang = '".$db->escape($langcode)."'";
1035 }
1036 if ($type) {
1037 $tmparrayoftype = explode(',', $type);
1038 $typestring = '';
1039 foreach ($tmparrayoftype as $tmptype) {
1040 $typestring .= ($typestring ? ", " : "")."'".$db->escape(trim($tmptype))."'";
1041 }
1042 $sql .= " AND wp.type_container IN (".$db->sanitize($typestring, 1).")";
1043 }
1044 $sql .= " AND (";
1045 $searchalgo = '';
1046 if (preg_match('/meta/', $algo)) {
1047 $searchalgo .= ($searchalgo ? ' OR ' : '')."wp.title LIKE '%".$db->escape($db->escapeforlike($searchstring))."%' OR wp.description LIKE '%".$db->escape($db->escapeforlike($searchstring))."%'";
1048 $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
1049 }
1050 if (preg_match('/content/', $algo)) {
1051 $searchalgo .= ($searchalgo ? ' OR ' : '')."wp.content LIKE '%".$db->escape($db->escapeforlike($searchstring))."%'";
1052 }
1053 $sql .= $searchalgo;
1054 if (is_array($otherfilters) && !empty($otherfilters['category'])) {
1055 $sql .= ' AND cwp.fk_website_page = wp.rowid AND cwp.fk_categorie = '.((int) $otherfilters['category']);
1056 }
1057 $sql .= ")";
1058 $sql .= $db->order($sortfield, $sortorder);
1059 $sql .= $db->plimit($max);
1060 //print $sql;
1061
1062 $resql = $db->query($sql);
1063
1064 if ($resql) {
1065 $i = 0;
1066 while (($obj = $db->fetch_object($resql)) && ($i < $max || $max == 0)) {
1067 if ($obj->rowid > 0) {
1068 $tmpwebsitepage = new WebsitePage($db);
1069 $tmpwebsitepage->fetch($obj->rowid);
1070 if ($tmpwebsitepage->id > 0) {
1071 $arrayresult['list'][$obj->rowid] = $tmpwebsitepage;
1072 }
1073 $found++;
1074 }
1075 $i++;
1076 }
1077 } else {
1078 $error++;
1079 $arrayresult['code'] = $db->lasterrno();
1080 $arrayresult['message'] = $db->lasterror();
1081 }
1082
1083 $searchdone = 1;
1084 }
1085
1086 if (!$error && (empty($max) || ($found < $max)) && (preg_match('/sitefiles/', $algo))) {
1087 global $dolibarr_main_data_root;
1088
1089 $pathofwebsite = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$website->ref;
1090 $filehtmlheader = $pathofwebsite.'/htmlheader.html';
1091 $filecss = $pathofwebsite.'/styles.css.php';
1092 $filejs = $pathofwebsite.'/javascript.js.php';
1093 $filerobot = $pathofwebsite.'/robots.txt';
1094 $filehtaccess = $pathofwebsite.'/.htaccess';
1095 $filemanifestjson = $pathofwebsite.'/manifest.json.php';
1096 $filereadme = $pathofwebsite.'/README.md';
1097
1098 $filecontent = file_get_contents($filehtmlheader);
1099 if ((empty($max) || ($found < $max)) && preg_match('/'.preg_quote($searchstring, '/').'/', $filecontent)) {
1100 $arrayresult['list'][] = array('type'=>'website_htmlheadercontent');
1101 }
1102
1103 $filecontent = file_get_contents($filecss);
1104 if ((empty($max) || ($found < $max)) && preg_match('/'.preg_quote($searchstring, '/').'/', $filecontent)) {
1105 $arrayresult['list'][] = array('type'=>'website_csscontent');
1106 }
1107
1108 $filecontent = file_get_contents($filejs);
1109 if ((empty($max) || ($found < $max)) && preg_match('/'.preg_quote($searchstring, '/').'/', $filecontent)) {
1110 $arrayresult['list'][] = array('type'=>'website_jscontent');
1111 }
1112
1113 $filerobot = file_get_contents($filerobot);
1114 if ((empty($max) || ($found < $max)) && preg_match('/'.preg_quote($searchstring, '/').'/', $filecontent)) {
1115 $arrayresult['list'][] = array('type'=>'website_robotcontent');
1116 }
1117
1118 $searchdone = 1;
1119 }
1120
1121 if (!$error) {
1122 if ($searchdone) {
1123 $arrayresult['code'] = 'OK';
1124 if (empty($arrayresult['list'])) {
1125 $arrayresult['code'] = 'KO';
1126 $arrayresult['message'] = $weblangs->trans("NoRecordFound");
1127 }
1128 } else {
1129 $error++;
1130 $arrayresult['code'] = 'KO';
1131 $arrayresult['message'] = 'No supported algorithm found';
1132 }
1133 }
1134
1135 return $arrayresult;
1136}
1137
1152function getAllImages($object, $objectpage, $urltograb, &$tmp, &$action, $modifylinks = 0, $grabimages = 1, $grabimagesinto = 'subpage')
1153{
1154 global $conf;
1155
1156 $error = 0;
1157
1158 dol_syslog("Call getAllImages with grabimagesinto=".$grabimagesinto);
1159
1160 $alreadygrabbed = array();
1161
1162 if (preg_match('/\/$/', $urltograb)) {
1163 $urltograb .= '.';
1164 }
1165 $urltograb = dirname($urltograb); // So urltograb is now http://www.nltechno.com or http://www.nltechno.com/dir1
1166
1167 // Search X in "img...src=X"
1168 $regs = array();
1169 preg_match_all('/<img([^\.\/]+)src="([^>"]+)"([^>]*)>/i', $tmp, $regs);
1170
1171 foreach ($regs[0] as $key => $val) {
1172 if (preg_match('/^data:image/i', $regs[2][$key])) {
1173 continue; // We do nothing for such images
1174 }
1175
1176 if (preg_match('/^\//', $regs[2][$key])) {
1177 $urltograbdirrootwithoutslash = getRootURLFromURL($urltograb);
1178 $urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key]; // We use dirroot
1179 } else {
1180 $urltograbbis = $urltograb.'/'.$regs[2][$key]; // We use dir of grabbed file
1181 }
1182
1183 $linkwithoutdomain = $regs[2][$key];
1184 $dirforimages = '/'.$objectpage->pageurl;
1185 if ($grabimagesinto == 'root') {
1186 $dirforimages = '';
1187 }
1188
1189 // Define $filetosave and $filename
1190 $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $regs[2][$key]) ? '' : '/').$regs[2][$key];
1191 if (preg_match('/^http/', $regs[2][$key])) {
1192 $urltograbbis = $regs[2][$key];
1193 $linkwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\//i', '', $regs[2][$key]);
1194 $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain) ? '' : '/').$linkwithoutdomain;
1195 }
1196 $filename = 'image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain) ? '' : '/').$linkwithoutdomain;
1197
1198 // Clean the aa/bb/../cc into aa/cc
1199 $filetosave = preg_replace('/\/[^\/]+\/\.\./', '', $filetosave);
1200 $filename = preg_replace('/\/[^\/]+\/\.\./', '', $filename);
1201
1202 //var_dump($filetosave);
1203 //var_dump($filename);
1204 //exit;
1205
1206 if (empty($alreadygrabbed[$urltograbbis])) {
1207 if ($grabimages) {
1208 $tmpgeturl = getURLContent($urltograbbis, 'GET', '', 1, array(), array('http', 'https'), 0);
1209 if ($tmpgeturl['curl_error_no']) {
1210 $error++;
1211 setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['curl_error_msg'], null, 'errors');
1212 $action = 'create';
1213 } elseif ($tmpgeturl['http_code'] != '200') {
1214 $error++;
1215 setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['http_code'], null, 'errors');
1216 $action = 'create';
1217 } else {
1218 $alreadygrabbed[$urltograbbis] = 1; // Track that file was alreay grabbed.
1219
1220 dol_mkdir(dirname($filetosave));
1221
1222 $fp = fopen($filetosave, "w");
1223 fputs($fp, $tmpgeturl['content']);
1224 fclose($fp);
1225 dolChmod($filetosave);
1226 }
1227 }
1228 }
1229
1230 if ($modifylinks) {
1231 $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);
1232 }
1233 }
1234
1235 // Search X in "background...url(X)"
1236 preg_match_all('/background([^\.\/\‍(;]+)url\‍([\"\']?([^\‍)\"\']*)[\"\']?\‍)/i', $tmp, $regs);
1237
1238 foreach ($regs[0] as $key => $val) {
1239 if (preg_match('/^data:image/i', $regs[2][$key])) {
1240 continue; // We do nothing for such images
1241 }
1242
1243 if (preg_match('/^\//', $regs[2][$key])) {
1244 $urltograbdirrootwithoutslash = getRootURLFromURL($urltograb);
1245 $urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key]; // We use dirroot
1246 } else {
1247 $urltograbbis = $urltograb.'/'.$regs[2][$key]; // We use dir of grabbed file
1248 }
1249
1250 $linkwithoutdomain = $regs[2][$key];
1251
1252 $dirforimages = '/'.$objectpage->pageurl;
1253 if ($grabimagesinto == 'root') {
1254 $dirforimages = '';
1255 }
1256
1257 $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $regs[2][$key]) ? '' : '/').$regs[2][$key];
1258
1259 if (preg_match('/^http/', $regs[2][$key])) {
1260 $urltograbbis = $regs[2][$key];
1261 $linkwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\//i', '', $regs[2][$key]);
1262 $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain) ? '' : '/').$linkwithoutdomain;
1263 }
1264
1265 $filename = 'image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain) ? '' : '/').$linkwithoutdomain;
1266
1267 // Clean the aa/bb/../cc into aa/cc
1268 $filetosave = preg_replace('/\/[^\/]+\/\.\./', '', $filetosave);
1269 $filename = preg_replace('/\/[^\/]+\/\.\./', '', $filename);
1270
1271 //var_dump($filetosave);
1272 //var_dump($filename);
1273 //exit;
1274
1275 if (empty($alreadygrabbed[$urltograbbis])) {
1276 if ($grabimages) {
1277 $tmpgeturl = getURLContent($urltograbbis, 'GET', '', 1, array(), array('http', 'https'), 0);
1278 if ($tmpgeturl['curl_error_no']) {
1279 $error++;
1280 setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['curl_error_msg'], null, 'errors');
1281 $action = 'create';
1282 } elseif ($tmpgeturl['http_code'] != '200') {
1283 $error++;
1284 setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['http_code'], null, 'errors');
1285 $action = 'create';
1286 } else {
1287 $alreadygrabbed[$urltograbbis] = 1; // Track that file was alreay grabbed.
1288
1289 dol_mkdir(dirname($filetosave));
1290
1291 $fp = fopen($filetosave, "w");
1292 fputs($fp, $tmpgeturl['content']);
1293 fclose($fp);
1294 dolChmod($filetosave);
1295 }
1296 }
1297 }
1298
1299 if ($modifylinks) {
1300 $tmp = preg_replace('/'.preg_quote($regs[0][$key], '/').'/i', 'background'.$regs[1][$key].'url("'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file='.$filename.'")', $tmp);
1301 }
1302 }
1303}
Class Websitepage.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dolChmod($filepath, $newmask='')
Change mod of a file.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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....
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).
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.
getStructuredData($type, $data=array())
Return HTML content to add structured data for an article, news or Blog Post.
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.
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.