dolibarr 21.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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
34function dolStripPhpCode($str, $replacewith = '')
35{
36 $str = str_replace('<?=', '<?php echo', $str); // replace a bad practive
37
38 $newstr = '';
39
40 // Split on each opening tag
41 //$parts = explode('<?php', $str);
42 $parts = preg_split('/'.preg_quote('<?php', '/').'/i', $str);
43
44 if (!empty($parts)) {
45 $i = 0;
46 foreach ($parts as $part) {
47 if ($i == 0) { // The first part is never php code
48 $i++;
49 $newstr .= $part;
50 continue;
51 }
52 // The second part is the php code. We split on closing tag
53 $partlings = explode('?>', $part);
54 if (!empty($partlings)) {
55 //$phppart = $partlings[0];
56 //remove content before closing tag
57 if (count($partlings) > 1) {
58 $partlings[0] = ''; // Todo why a count > 1 and not >= 1 ?
59 }
60 //append to out string
61 //$newstr .= '<span class="phptag" class="tooltip" title="'.dol_escape_htmltag(dolGetFirstLineOfText($phppart).'...').'">'.$replacewith.'<!-- '.$phppart.' --></span>'.implode('', $partlings);
62 //$newstr .= '<span>'.$replacewith.'<!-- '.$phppart.' --></span>'.implode('', $partlings);
63 $newstr .= '<span phptag>'.$replacewith.'</span>'.implode('', $partlings);
64 //$newstr .= $replacewith.implode('', $partlings);
65 }
66 }
67 }
68 return $newstr;
69}
70
78function dolKeepOnlyPhpCode($str)
79{
80 $str = str_replace('<?=', '<?php echo', $str);
81 $str = str_replace('<?php', '__LTINTPHP__', $str);
82 $str = str_replace('<?', '<?php', $str); // replace the short_open_tag. It is recommended to set this to Off in php.ini
83 $str = str_replace('__LTINTPHP__', '<?php', $str);
84
85 $newstr = '';
86
87 // Split on each opening tag
88 //$parts = explode('<?php', $str);
89 $parts = preg_split('/'.preg_quote('<?php', '/').'/i', $str);
90
91 if (!empty($parts)) {
92 $i = 0;
93 foreach ($parts as $part) {
94 if ($i == 0) { // The first part is never php code
95 $i++;
96 continue;
97 }
98 $newstr .= '<?php';
99 //split on closing tag
100 $partlings = explode('?>', $part, 2);
101 if (!empty($partlings)) {
102 $newstr .= $partlings[0].'?>';
103 } else {
104 $newstr .= $part.'?>';
105 }
106 }
107 }
108 return $newstr;
109}
110
123function dolWebsiteReplacementOfLinks($website, $content, $removephppart = 0, $contenttype = 'html', $containerid = 0)
124{
125 $nbrep = 0;
126
127 dol_syslog('dolWebsiteReplacementOfLinks start (contenttype='.$contenttype." containerid=".$containerid." USEDOLIBARREDITOR=".(defined('USEDOLIBARREDITOR') ? '1' : '')." USEDOLIBARRSERVER=".(defined('USEDOLIBARRSERVER') ? '1' : '').')', LOG_DEBUG);
128 //if ($contenttype == 'html') { print $content;exit; }
129
130 // Replace php code. Note $content may come from database and does not contain body tags.
131 $replacewith = '...php...';
132 if ($removephppart) {
133 $replacewith = '';
134 }
135 $content = preg_replace('/value="<\?php((?!\?>).)*\?>\n*/ims', 'value="'.$replacewith.'"', $content);
136
137 $replacewith = '"callto=#';
138 if ($removephppart) {
139 $replacewith = '';
140 }
141 $content = preg_replace('/"callto:<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content);
142
143 $replacewith = '"mailto=#';
144 if ($removephppart) {
145 $replacewith = '';
146 }
147 $content = preg_replace('/"mailto:<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content);
148
149 $replacewith = 'src="php';
150 if ($removephppart) {
151 $replacewith = '';
152 }
153 $content = preg_replace('/src="<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content);
154
155 $replacewith = 'href="php';
156 if ($removephppart) {
157 $replacewith = '';
158 }
159 $content = preg_replace('/href="<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content);
160
161 //$replacewith='<span class="phptag">...php...</span>';
162 $replacewith = '...php...';
163 if ($removephppart) {
164 $replacewith = '';
165 }
166 //$content = preg_replace('/<\?php((?!\?toremove>).)*\?toremove>\n*/ims', $replacewith, $content);
167 /*if ($content === null) {
168 if (preg_last_error() == PREG_JIT_STACKLIMIT_ERROR) $content = 'preg_replace error (when removing php tags) PREG_JIT_STACKLIMIT_ERROR';
169 }*/
170 $content = dolStripPhpCode($content, $replacewith);
171
172 // Protect the link styles.css.php to any replacement that we make after.
173 $content = str_replace('href="styles.css.php', 'href="!~!~!~styles.css.php', $content);
174 $content = str_replace('src="javascript.js.php', 'src="!~!~!~javascript.js.php', $content);
175 $content = str_replace('href="http', 'href="!~!~!~http', $content);
176 $content = str_replace('xlink:href="', 'xlink:href="!~!~!~', $content);
177 $content = str_replace('href="//', 'href="!~!~!~//', $content);
178 $content = str_replace('src="//', 'src="!~!~!~//', $content);
179 $content = str_replace('src="viewimage.php', 'src="!~!~!~/viewimage.php', $content);
180 $content = str_replace('src="/viewimage.php', 'src="!~!~!~/viewimage.php', $content);
181 $content = str_replace('src="'.DOL_URL_ROOT.'/viewimage.php', 'src="!~!~!~'.DOL_URL_ROOT.'/viewimage.php', $content);
182 $content = str_replace('href="document.php', 'href="!~!~!~/document.php', $content);
183 $content = str_replace('href="/document.php', 'href="!~!~!~/document.php', $content);
184 $content = str_replace('href="'.DOL_URL_ROOT.'/document.php', 'href="!~!~!~'.DOL_URL_ROOT.'/document.php', $content);
185
186 // Replace relative link '/' with dolibarr URL
187 $content = preg_replace('/(href=")\/(#[^\"<>]*)?\"/', '\1!~!~!~'.DOL_URL_ROOT.'/website/index.php?website='.$website->ref.'&pageid='.$website->fk_default_home.'\2"', $content, -1, $nbrep);
188 // Replace relative link /xxx.php#aaa or /xxx.php with dolibarr URL (we discard param ?...)
189 $content = preg_replace('/(href=")\/?([^:\"\!]*)\.php(#[^\"<>]*)?\"/', '\1!~!~!~'.DOL_URL_ROOT.'/website/index.php?website='.$website->ref.'&pageref=\2\3"', $content, -1, $nbrep);
190 // Replace relative link /xxx.php?a=b&c=d#aaa or /xxx.php?a=b&c=d with dolibarr URL
191 $content = preg_replace('/(href=")\/?([^:\"\!]*)\.php\?([^#\"<>]*)(#[^\"<>]*)?\"/', '\1!~!~!~'.DOL_URL_ROOT.'/website/index.php?website='.$website->ref.'&pageref=\2&\3\4"', $content, -1, $nbrep);
192
193 // Fix relative link into medias with correct URL after the DOL_URL_ROOT: ../url("medias/
194 $content = preg_replace('/url\‍((["\']?)\/?medias\//', 'url(\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
195 $content = preg_replace('/data-slide-bg=(["\']?)\/?medias\//', 'data-slide-bg=\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
196
197 // <img src="medias/...image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png...
198 // <img src="...image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png...
199 $content = preg_replace('/(<img[^>]*src=")\/?medias\//', '\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
200 // <img src="image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png...
201 $content = preg_replace('/(<img[^>]*src=")\/?([^:\"\!]+)\"/', '\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=\2"', $content, -1, $nbrep);
202 // <img src="viewimage.php/modulepart=medias&file=image.png" => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png"
203 $content = preg_replace('/(<img[^>]*src=")(\/?viewimage\.php)/', '\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php', $content, -1, $nbrep);
204
205 // action="newpage.php" => action="dolibarr/website/index.php?website=...&pageref=newpage
206 $content = preg_replace('/(action=")\/?([^:\"]*)(\.php\")/', '\1!~!~!~'.DOL_URL_ROOT.'/website/index.php?website='.$website->ref.'&pageref=\2"', $content, -1, $nbrep);
207
208 // Fix relative link /document.php with correct URL after the DOL_URL_ROOT: ...href="/document.php?modulepart="
209 $content = preg_replace('/(href=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1!~!~!~'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
210 $content = preg_replace('/(src=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1!~!~!~'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
211
212 // Fix relative link /viewimage.php with correct URL after the DOL_URL_ROOT: ...href="/viewimage.php?modulepart="
213 $content = preg_replace('/(url\‍(")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1!~!~!~'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
214
215 // Fix relative URL
216 $content = str_replace('src="!~!~!~/viewimage.php', 'src="!~!~!~'.DOL_URL_ROOT.'/viewimage.php', $content);
217 $content = str_replace('href="!~!~!~/document.php', 'href="!~!~!~'.DOL_URL_ROOT.'/document.php', $content);
218 // Remove the protection tag !~!~!~
219 $content = str_replace('!~!~!~', '', $content);
220
221 dol_syslog('dolWebsiteReplacementOfLinks end', LOG_DEBUG);
222 //if ($contenttype == 'html') { print $content;exit; }
223
224 return $content;
225}
226
234{
235 $map = array(
236 ":face_with_tears_of_joy:" => "\xF0\x9F\x98\x82",
237 ":grinning_face_with_smiling_eyes:" => "\xF0\x9F\x98\x81",
238 ":smiling_face_with_open_mouth:" => "\xF0\x9F\x98\x83",
239 ":smiling_face_with_open_mouth_and_cold_sweat:" => "\xF0\x9F\x98\x85",
240 ":smiling_face_with_open_mouth_and_tightly_closed_eyes:" => "\xF0\x9F\x98\x86",
241 ":winking_face:" => "\xF0\x9F\x98\x89",
242 ":smiling_face_with_smiling_eyes:" => "\xF0\x9F\x98\x8A",
243 ":face_savouring_delicious_food:" => "\xF0\x9F\x98\x8B",
244 ":relieved_face:" => "\xF0\x9F\x98\x8C",
245 ":smiling_face_with_heart_shaped_eyes:" => "\xF0\x9F\x98\x8D",
246 ":smiling_face_with_sunglasses:" => "\xF0\x9F\x98\x8E",
247 ":smirking_face:" => "\xF0\x9F\x98\x8F",
248 ":neutral_face:" => "\xF0\x9F\x98\x90",
249 ":expressionless_face:" => "\xF0\x9F\x98\x91",
250 ":unamused_face:" => "\xF0\x9F\x98\x92",
251 ":face_with_cold_sweat:" => "\xF0\x9F\x98\x93",
252 ":pensive_face:" => "\xF0\x9F\x98\x94",
253 ":confused_face:" => "\xF0\x9F\x98\x95",
254 ":confounded_face:" => "\xF0\x9F\x98\x96",
255 ":kissing_face:" => "\xF0\x9F\x98\x97",
256 ":face_throwing_a_kiss:" => "\xF0\x9F\x98\x98",
257 ":kissing_face_with_smiling_eyes:" => "\xF0\x9F\x98\x99",
258 ":kissing_face_with_closed_eyes:" => "\xF0\x9F\x98\x9A",
259 ":face_with_stuck_out_tongue:" => "\xF0\x9F\x98\x9B",
260 ":face_with_stuck_out_tongue_and_winking_eye:" => "\xF0\x9F\x98\x9C",
261 ":face_with_stuck_out_tongue_and_tightly_closed_eyes:" => "\xF0\x9F\x98\x9D",
262 ":disappointed_face:" => "\xF0\x9F\x98\x9E",
263 ":worried_face:" => "\xF0\x9F\x98\x9F",
264 ":angry_face:" => "\xF0\x9F\x98\xA0",
265 ":face_with_symbols_on_mouth:" => "\xF0\x9F\x98\xA1",
266 );
267 foreach ($map as $key => $value) {
268 $content = str_replace($key, $value, $content);
269 }
270 return $content;
271}
272
273
284function dolWebsiteOutput($content, $contenttype = 'html', $containerid = 0)
285{
286 global $db, $langs, $conf, $user;
287 global $dolibarr_main_url_root, $dolibarr_main_data_root;
288 global $website;
289 global $includehtmlcontentopened; // $includehtmlcontentopened is the level of includes (start at 0 for main page, 1 for first level include, ...)
290 '@phan-var-force Website $website';
291
292 $nbrep = 0;
293
294 dol_syslog("dolWebsiteOutput start - contenttype=".$contenttype." containerid=".$containerid.(defined('USEDOLIBARREDITOR') ? ' USEDOLIBARREDITOR=1' : '').(defined('USEDOLIBARRSERVER') ? ' USEDOLIBARRSERVER=1' : '').' includehtmlcontentopened='.$includehtmlcontentopened);
295
296 //print $containerid.' '.$content;
297
298 // Define $urlwithroot
299 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
300 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
301 //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
302
303 if (defined('USEDOLIBARREDITOR')) { // REPLACEMENT OF LINKS When page called from Dolibarr editor
304 // We remove the <head> part of content
305 if ($contenttype == 'html') {
306 $content = preg_replace('/<head>.*<\/head>/ims', '', $content);
307 $content = preg_replace('/^.*<body(\s[^>]*)*>/ims', '', $content);
308 $content = preg_replace('/<\/body(\s[^>]*)*>.*$/ims', '', $content);
309 }
310 } elseif (defined('USEDOLIBARRSERVER')) { // REPLACEMENT OF LINKS When page called from Dolibarr server
311 $content = str_replace('<link rel="stylesheet" href="/styles.css', '<link rel="stylesheet" href="styles.css', $content);
312 $content = str_replace(' async src="/javascript.js', ' async src="javascript.js', $content);
313
314 // Protect the link styles.css.php to any replacement that we make after.
315 $content = str_replace('href="styles.css.php', 'href="!~!~!~styles.css.php', $content);
316 $content = str_replace('src="javascript.css.php', 'src="!~!~!~javascript.css.php', $content);
317 $content = str_replace('href="http', 'href="!~!~!~http', $content);
318 $content = str_replace('xlink:href="', 'xlink:href="!~!~!~', $content);
319 $content = str_replace('href="//', 'href="!~!~!~//', $content);
320 $content = str_replace('src="//', 'src="!~!~!~//', $content);
321 $content = str_replace(array('src="viewimage.php', 'src="/viewimage.php'), 'src="!~!~!~/viewimage.php', $content);
322 $content = str_replace('src="'.DOL_URL_ROOT.'/viewimage.php', 'src="!~!~!~'.DOL_URL_ROOT.'/viewimage.php', $content);
323 $content = str_replace(array('href="document.php', 'href="/document.php'), 'href="!~!~!~/document.php', $content);
324 $content = str_replace('href="'.DOL_URL_ROOT.'/document.php', 'href="!~!~!~'.DOL_URL_ROOT.'/document.php', $content);
325
326 // Replace relative link / with dolibarr URL: ...href="/"...
327 $content = preg_replace('/(href=")\/\"/', '\1!~!~!~'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'"', $content, -1, $nbrep);
328 // Replace relative link /xxx.php#aaa or /xxx.php with dolibarr URL: ...href="....php" (we discard param ?...)
329 $content = preg_replace('/(href=")\/?([^:\"\!]*)\.php(#[^\"<>]*)?\"/', '\1!~!~!~'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2\3"', $content, -1, $nbrep);
330 // Replace relative link /xxx.php?a=b&c=d#aaa or /xxx.php?a=b&c=d with dolibarr URL
331 // Warning: we may replace twice if href="..." was inside an include (dolWebsiteOutput called by include and the by final page), that's why
332 // at end we replace the '!~!~!~' only if we are in final parent page.
333 $content = preg_replace('/(href=")\/?([^:\"\!]*)\.php\?([^#\"<>]*)(#[^\"<>]*)?\"/', '\1!~!~!~'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2&\3\4"', $content, -1, $nbrep);
334 // Replace occurrence like _service_XXX.php with dolibarr URL
335 $content = preg_replace('/([\'"])_service_([^\'"]+)\.php\1/', '\1!~!~!~' . DOL_URL_ROOT . '/public/website/index.php?website=' . $website->ref . '&pageref=_service_\2\1', $content, -1, $nbrep);
336 // Replace occurrence like _library_XXX.php with dolibarr URL
337 $content = preg_replace('/([\'"])_library_([^\'"]+)\.php\1/', '\1!~!~!~' . DOL_URL_ROOT . '/public/website/index.php?website=' . $website->ref . '&pageref=_library_\2\1', $content, -1, $nbrep);
338 // Replace relative link without .php like /xxx#aaa or /xxx with dolibarr URL: ...href="....php"
339 $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);
340
341 // Fix relative link /document.php with correct URL after the DOL_URL_ROOT: href="/document.php?modulepart=" => href="/dolibarr/document.php?modulepart="
342 $content = preg_replace('/(href=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1!~!~!~'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
343 $content = preg_replace('/(src=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1!~!~!~'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
344
345 // Fix relative link /viewimage.php with correct URL after the DOL_URL_ROOT: href="/viewimage.php?modulepart=" => href="/dolibarr/viewimage.php?modulepart="
346 $content = preg_replace('/(href=")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1!~!~!~'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
347 $content = preg_replace('/(src=")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1!~!~!~'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
348 $content = preg_replace('/(url\‍(")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1!~!~!~'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
349
350 // Fix relative link into medias with correct URL after the DOL_URL_ROOT: ../url("medias/
351 $content = preg_replace('/url\‍((["\']?)\/?medias\//', 'url(\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
352 $content = preg_replace('/data-slide-bg=(["\']?)\/?medias\//', 'data-slide-bg=\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
353
354 // <img src="medias/...image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png...
355 // <img src="...image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png...
356 $content = preg_replace('/(<img[^>]*src=")\/?medias\//', '\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
357 // <img src="image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png...
358 $content = preg_replace('/(<img[^>]*src=")\/?([^:\"\!]+)\"/', '\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=\2"', $content, -1, $nbrep);
359 // <img src="viewimage.php/modulepart=medias&file=image.png" => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png"
360 $content = preg_replace('/(<img[^>]*src=")(\/?viewimage\.php)/', '\1!~!~!~'.DOL_URL_ROOT.'/viewimage.php', $content, -1, $nbrep);
361
362 // action="newpage.php" => action="dolibarr/website/index.php?website=...&pageref=newpage
363 $content = preg_replace('/(action=")\/?([^:\"]*)(\.php\")/', '\1!~!~!~'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2"', $content, -1, $nbrep);
364
365 // Fix relative URL
366 $content = str_replace('src="!~!~!~/viewimage.php', 'src="!~!~!~'.DOL_URL_ROOT.'/viewimage.php', $content);
367 $content = str_replace('href="!~!~!~/document.php', 'href="!~!~!~'.DOL_URL_ROOT.'/document.php', $content);
368
369 // Remove the protection tag !~!~!~, but only if this is the parent page and not an include
370 if (empty($includehtmlcontentopened)) {
371 $content = str_replace('!~!~!~', '', $content);
372 }
373 } else { // REPLACEMENT OF LINKS When page called from virtual host web server
374 $symlinktomediaexists = 1;
375 if ($website->virtualhost) {
376 $content = preg_replace('/^(<link[^>]*rel="canonical" href=")\//m', '\1'.$website->virtualhost.'/', $content, -1, $nbrep);
377 }
378 //print 'rrrrrrrrr'.$website->virtualhost.$content;
379
380
381 // Make a change into HTML code to allow to include images from medias directory correct with direct link for virtual server
382 // <img alt="" src="/dolibarr_dev/htdocs/viewimage.php?modulepart=medias&amp;entity=1&amp;file=image/ldestailleur_166x166.jpg" style="height:166px; width:166px" />
383 // become
384 // <img alt="" src="'.$urlwithroot.'/medias/image/ldestailleur_166x166.jpg" style="height:166px; width:166px" />
385 if (!$symlinktomediaexists) {
386 // <img src="image.png... => <img src="medias/image.png...
387 $content = preg_replace('/(<img[^>]*src=")\/?image\//', '\1/wrapper.php?modulepart=medias&file=medias/image/', $content, -1, $nbrep);
388 $content = preg_replace('/(url\‍(["\']?)\/?image\//', '\1/wrapper.php?modulepart=medias&file=medias/image/', $content, -1, $nbrep);
389
390 $content = preg_replace('/(<script[^>]*src=")[^\"]*document\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep);
391 $content = preg_replace('/(<a[^>]*href=")[^\"]*document\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep);
392
393 $content = preg_replace('/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep);
394 $content = preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep);
395 $content = preg_replace('/(url\‍(["\']?)[^\‍)]*viewimage\.php([^\‍)]*)modulepart=medias([^\‍)]*)file=([^\‍)]*)(["\']?\‍))/', '\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep);
396
397 $content = preg_replace('/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep);
398 $content = preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep);
399 $content = preg_replace('/(url\‍(["\']?)[^\‍)]*viewimage\.php([^\‍)]*)hashp=([^\‍)]*)(["\']?\‍))/', '\1/wrapper.php\2hashp\3\4', $content, -1, $nbrep);
400
401 $content = preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=mycompany([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=mycompany\3file=\4\5', $content, -1, $nbrep);
402
403 // If some links to documents or viewimage remains, we replace with wrapper
404 $content = preg_replace('/(<img[^>]*src=")\/?viewimage\.php/', '\1/wrapper.php', $content, -1, $nbrep);
405 $content = preg_replace('/(<a[^>]*href=")\/?documents\.php/', '\1/wrapper.php', $content, -1, $nbrep);
406 } else {
407 // <img src="image.png... => <img src="medias/image.png...
408 $content = preg_replace('/(<img[^>]*src=")\/?image\//', '\1/medias/image/', $content, -1, $nbrep);
409 $content = preg_replace('/(url\‍(["\']?)\/?image\//', '\1/medias/image/', $content, -1, $nbrep);
410
411 $content = preg_replace('/(<script[^>]*src=")[^\"]*document\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/medias/\4\5', $content, -1, $nbrep);
412 $content = preg_replace('/(<a[^>]*href=")[^\"]*document\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/medias/\4\5', $content, -1, $nbrep);
413
414 $content = preg_replace('/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/medias/\4\5', $content, -1, $nbrep);
415 $content = preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/medias/\4\5', $content, -1, $nbrep);
416 $content = preg_replace('/(url\‍(["\']?)[^\‍)]*viewimage\.php([^\‍)]*)modulepart=medias([^\‍)]*)file=([^\‍)]*)(["\']?\‍))/', '\1/medias/\4\5', $content, -1, $nbrep);
417
418 $content = preg_replace('/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep);
419 $content = preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep);
420 $content = preg_replace('/(url\‍(["\']?)[^\‍)]*viewimage\.php([^\‍)]*)hashp=([^\‍)]*)(["\']?\‍))/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep);
421
422 $content = preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=mycompany([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=mycompany\3file=\4\5', $content, -1, $nbrep);
423
424 // If some links to documents or viewimage remains, we replace with wrapper
425 $content = preg_replace('/(<img[^>]*src=")\/?viewimage\.php/', '\1/wrapper.php', $content, -1, $nbrep);
426 $content = preg_replace('/(<a[^>]*href=")\/?document\.php/', '\1/wrapper.php', $content, -1, $nbrep);
427 }
428 }
429
430 if (!defined('USEDOLIBARREDITOR')) {
431 $content = str_replace(' contenteditable="true"', ' contenteditable="false"', $content);
432 }
433
434 if (getDolGlobalString('WEBSITE_ADD_CSS_TO_BODY')) {
435 $content = str_replace('<body id="bodywebsite" class="bodywebsite', '<body id="bodywebsite" class="bodywebsite ' . getDolGlobalString('WEBSITE_ADD_CSS_TO_BODY'), $content);
436 }
437
438 $content = dolReplaceSmileyCodeWithUTF8($content);
439
440 dol_syslog("dolWebsiteOutput end");
441
442 print $content;
443}
444
453function dolWebsiteIncrementCounter($websiteid, $websitepagetype, $websitepageid)
454{
455 if (!getDolGlobalInt('WEBSITE_PERF_DISABLE_COUNTERS')) {
456 //dol_syslog("dolWebsiteIncrementCounter websiteid=".$websiteid." websitepagetype=".$websitepagetype." websitepageid=".$websitepageid);
457 if (in_array($websitepagetype, array('blogpost', 'page'))) {
458 global $db;
459
460 $tmpnow = dol_getdate(dol_now('gmt'), true, 'gmt');
461
462 $sql = "UPDATE ".$db->prefix()."website SET ";
463 $sql .= " pageviews_total = pageviews_total + 1,";
464 $sql .= " pageviews_month = pageviews_month + 1,";
465 // if last access was done during previous month, we save pageview_month into pageviews_previous_month
466 $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').",";
467 $sql .= " lastaccess = '".$db->idate(dol_now('gmt'), 'gmt')."',";
468 $sql .= " lastpageid = ".((int) $websitepageid);
469 $sql .= " WHERE rowid = ".((int) $websiteid);
470
471 $resql = $db->query($sql);
472 if (! $resql) {
473 return -1;
474 }
475 }
476 }
477
478 return 1;
479}
480
481
489/*
490function dolWebsiteSaveContent($content)
491{
492 global $db, $langs, $conf, $user;
493 global $dolibarr_main_url_root, $dolibarr_main_data_root;
494
495 //dol_syslog("dolWebsiteSaveContent start (mode=".(defined('USEDOLIBARRSERVER')?'USEDOLIBARRSERVER':'').')');
496
497 // Define $urlwithroot
498 $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
499 $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
500 //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
501
502 //$content = preg_replace('/(<img.*src=")(?!(http|'.preg_quote(DOL_URL_ROOT,'/').'\/viewimage))/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
503
504 return $content;
505}
506*/
507
508
520function redirectToContainer($containerref, $containeraliasalt = '', $containerid = 0, $permanent = 0, $parameters = array(), $parampropagation = 1)
521{
522 global $db, $website;
523 '@phan-var-force Website $website';
524
525 $newurl = '';
526 $result = 0;
527
528 // We make redirect using the alternative alias, we must find the real $containerref
529 if ($containeraliasalt) {
530 include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
531 $tmpwebsitepage = new WebsitePage($db);
532 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
533 $result = $tmpwebsitepage->fetch(0, $website->id, '', $containeraliasalt);
534 if ($result > 0) {
535 $containerref = $tmpwebsitepage->pageurl;
536 } else {
537 print "Error, page contains a redirect to the alternative alias '".$containeraliasalt."' that does not exists in web site (".$website->id." / ".$website->ref.")";
538 exit;
539 }
540 }
541
542 if (defined('USEDOLIBARREDITOR')) {
543 /*print '<div class="margintoponly marginleftonly">';
544 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.";
545 print '</div>';*/
546 $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.";
547 setEventMessages($text, null, 'warnings', 'WEBSITEREDIRECTDISABLED'.$containerref);
548 return;
549 }
550
551 if (defined('USEDOLIBARRSERVER')) { // When page called from Dolibarr server
552 // Check new container exists
553 if (!$containeraliasalt) { // If containeraliasalt set, we already did the test
554 include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
555 $tmpwebsitepage = new WebsitePage($db);
556 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
557 $result = $tmpwebsitepage->fetch(0, $website->id, $containerref);
558 unset($tmpwebsitepage);
559 }
560 if ($result > 0) {
561 $currenturi = $_SERVER["REQUEST_URI"]; // Example: /public/website/index.php?website=mywebsite.com&pageref=mywebsite-home&cache=3600
562 $regtmp = array();
563 if (preg_match('/&pageref=([^&]+)/', $currenturi, $regtmp)) {
564 if ($regtmp[0] == $containerref) {
565 print "Error, page with uri '.$currenturi.' try a redirect to the same alias page '".$containerref."' in web site '".$website->ref."'";
566 exit;
567 } else {
568 $newurl = preg_replace('/&pageref=([^&]+)/', '&pageref='.$containerref, $currenturi);
569 }
570 } else {
571 $newurl = $currenturi.'&pageref='.urlencode($containerref);
572 }
573 }
574 } else { // When page called from virtual host server
575 $newurl = '/'.$containerref.'.php';
576 if ($parampropagation) {
577 $newurl .= (empty($_SERVER["QUERY_STRING"]) ? '' : '?'.$_SERVER["QUERY_STRING"]);
578 }
579 }
580
581 if ($newurl) {
582 if (!empty($parameters)) {
583 $separator = (parse_url($newurl, PHP_URL_QUERY) == null) ? '?' : '&';
584 $newurl = $newurl . $separator . http_build_query($parameters);
585 }
586 if ($permanent) {
587 header("Status: 301 Moved Permanently", false, 301);
588 }
589 header("Location: ".$newurl);
590 exit;
591 } else {
592 print "Error, page contains a redirect to the alias page '".$containerref."' that does not exists in web site (".$website->id." / ".$website->ref.")";
593 exit;
594 }
595}
596
597
608function includeContainer($containerref, $once = 0, $cachedelay = 0, $cachekey = '')
609{
610 global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs; // Very important. Required to have var available when running included containers.
611 global $includehtmlcontentopened;
612 global $websitekey, $websitepagefile;
613 '@phan-var-force Website $website';
614
615 $MAXLEVEL = 20;
616
617 if (!preg_match('/\.php$/i', $containerref)) {
618 $containerref .= '.php';
619 }
620
621 $fullpathfile = DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$websitekey.'/'.$containerref;
622 $fullpathcache = '';
623 // If we ask to use the cache delay
624 if ($cachedelay > 0 && !getDolGlobalString("WEBSITE_DISABLE_CACHE_OF_CONTAINERS")) {
625 $fullpathcache = DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/temp/'.$websitekey.'-'.$websitepage->id.'-'.$containerref.($cachekey ? '-'.$cachekey: '').'.cache';
626 }
627
628 if (empty($includehtmlcontentopened)) {
629 $includehtmlcontentopened = 0;
630 }
631 $includehtmlcontentopened++;
632 if ($includehtmlcontentopened > $MAXLEVEL) {
633 print 'ERROR: RECURSIVE CONTENT LEVEL. Depth of recursive call is more than the limit of '.((int) $MAXLEVEL).".\n";
634 return;
635 }
636
637 //dol_syslog("Include container ".$containerref.' includehtmlcontentopened='.$includehtmlcontentopened);
638
639 // We don't print info messages for pages of type library or service
640 if (!empty($websitepage->type_container) && !in_array($websitepage->type_container, array('library', 'service'))) {
641 print "\n".'<!-- include '.$websitekey.'/'.$containerref.($cachekey ? ' '.$cachekey: '').(is_object($websitepage) ? ' parent id='.$websitepage->id : '').' level='.$includehtmlcontentopened.' -->'."\n";
642 }
643
644 $tmpoutput = '';
645
646 if ($cachedelay > 0 && $fullpathcache) {
647 if (is_file($fullpathcache)) {
648 // Get the last modification time of the file
649 $lastModifiedTime = filemtime($fullpathcache);
650
651 // Get the current time
652 $currentTime = time();
653
654 // Check if the file is not older than X seconds
655 if (($currentTime - $lastModifiedTime) <= $cachedelay) {
656 // The file is too recent
657 $tmpoutput = file_get_contents($fullpathcache);
658 }
659 }
660 }
661
662 if (empty($tmpoutput)) {
663 // file_get_contents is not possible because we must execute code with include
664 //$content = file_get_contents($fullpathfile);
665 //print preg_replace(array('/^.*<body[^>]*>/ims','/<\/body>.*$/ims'), array('', ''), $content);*/
666
667 ob_start();
668 if ($once) {
669 $res = @include_once $fullpathfile;
670 } else {
671 $res = @include $fullpathfile;
672 }
673 $tmpoutput = ob_get_contents();
674 ob_end_clean();
675
676 if (!$res) {
677 print 'ERROR: FAILED TO INCLUDE PAGE '.$containerref."(once=".$once.")\n";
678 } else {
679 $tmpoutput = preg_replace(array('/^.*<body[^>]*>/ims', '/<\/body>.*$/ims'), array('', ''), $tmpoutput);
680
681 // Save the content into cache file if content is lower than 10M
682 if ($fullpathcache && strlen($tmpoutput) < 10000000) {
683 file_put_contents($fullpathcache, $tmpoutput);
684 dolChmod($fullpathcache);
685 }
686 }
687 }
688
689 print $tmpoutput;
690
691 $includehtmlcontentopened--;
692}
693
704function getStructuredData($type, $data = array())
705{
706 global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs, $pagelangs; // Very important. Required to have var available when running included containers.
707 '@phan-var-force Website $website';
708
709 $type = strtolower($type);
710
711 if ($type == 'software') {
712 $ret = '<!-- Add structured data for entry in a software annuary -->'."\n";
713 $ret .= '<script nonce="'.getNonce().'" type="application/ld+json">'."\n";
714 $ret .= '{
715 "@context": "https://schema.org",
716 "@type": "SoftwareApplication",
717 "name": "'.dol_escape_json($data['name']).'",
718 "operatingSystem": "'.dol_escape_json($data['os']).'",
719 "applicationCategory": "https://schema.org/'.dol_escape_json($data['applicationCategory']).'",';
720 if (!empty($data['ratingcount'])) {
721 $ret .= '
722 "aggregateRating": {
723 "@type": "AggregateRating",
724 "ratingValue": "'.dol_escape_json($data['ratingvalue']).'",
725 "ratingCount": "'.dol_escape_json($data['ratingcount']).'"
726 },';
727 }
728 $ret .= '
729 "offers": {
730 "@type": "Offer",
731 "price": "'.dol_escape_json($data['price']).'",
732 "priceCurrency": "'.dol_escape_json($data['currency'] ? $data['currency'] : $conf->currency).'"
733 }
734 }'."\n";
735 $ret .= '</script>'."\n";
736 } elseif ($type == 'organization') {
737 $companyname = $mysoc->name;
738 $url = $mysoc->url;
739
740 $ret = '<!-- Add structured data for organization -->'."\n";
741 $ret .= '<script nonce="'.getNonce().'" type="application/ld+json">'."\n";
742 $ret .= '{
743 "@context": "https://schema.org",
744 "@type": "Organization",
745 "name": "'.dol_escape_json(!empty($data['name']) ? $data['name'] : $companyname).'",
746 "url": "'.dol_escape_json(!empty($data['url']) ? $data['url'] : $url).'",
747 "logo": "'.($data['logo'] ? dol_escape_json($data['logo']) : '/wrapper.php?modulepart=mycompany&file=logos%2F'.urlencode($mysoc->logo)).'",
748 "contactPoint": {
749 "@type": "ContactPoint",
750 "contactType": "Contact",
751 "email": "'.dol_escape_json(!empty($data['email']) ? $data['email'] : $mysoc->email).'"
752 }'."\n";
753 if (is_array($mysoc->socialnetworks) && count($mysoc->socialnetworks) > 0) {
754 $ret .= ",\n";
755 $ret .= '"sameAs": [';
756 $i = 0;
757 foreach ($mysoc->socialnetworks as $key => $value) {
758 if ($key == 'linkedin') {
759 $ret .= '"https://www.'.$key.'.com/company/'.dol_escape_json($value).'"';
760 } elseif ($key == 'youtube') {
761 $ret .= '"https://www.'.$key.'.com/user/'.dol_escape_json($value).'"';
762 } else {
763 $ret .= '"https://www.'.$key.'.com/'.dol_escape_json($value).'"';
764 }
765 $i++;
766 if ($i < count($mysoc->socialnetworks)) {
767 $ret .= ', ';
768 }
769 }
770 $ret .= ']'."\n";
771 }
772 $ret .= '}'."\n";
773 $ret .= '</script>'."\n";
774 } elseif ($type == 'blogpost') {
775 if (!empty($websitepage->author_alias)) {
776 //include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
777 //$tmpuser = new User($db);
778 //$restmpuser = $tmpuser->fetch($websitepage->fk_user_creat);
779
780 $pageurl = $websitepage->pageurl;
781 $title = $websitepage->title;
782 $image = getImageFromHtmlContent($websitepage->content);
783 $companyname = $mysoc->name;
784 $description = $websitepage->description;
785
786 $pageurl = str_replace('__WEBSITE_KEY__', $website->ref, $pageurl);
787 $title = str_replace('__WEBSITE_KEY__', $website->ref, $title);
788 $imagepath = '/medias'.(preg_match('/^\//', $image) ? '' : '/').str_replace('__WEBSITE_KEY__', $website->ref, $image);
789 $companyname = str_replace('__WEBSITE_KEY__', $website->ref, $companyname);
790 $description = str_replace('__WEBSITE_KEY__', $website->ref, $description);
791
792 $ret = '<!-- Add structured data for blog post -->'."\n";
793 $ret .= '<script nonce="'.getNonce().'" type="application/ld+json">'."\n";
794 $ret .= '{
795 "@context": "https://schema.org",
796 "@type": "NewsArticle",
797 "mainEntityOfPage": {
798 "@type": "WebPage",
799 "@id": "'.dol_escape_json($pageurl).'"
800 },
801 "headline": "'.dol_escape_json($title).'",';
802 if ($image) {
803 $ret .= '
804 "image": [
805 "'.dol_escape_json($imagepath).'"
806 ],';
807 }
808 $ret .= '
809 "dateCreated": "'.dol_print_date($websitepage->date_creation, 'dayhourrfc').'",
810 "datePublished": "'.dol_print_date($websitepage->date_creation, 'dayhourrfc').'",
811 "dateModified": "'.dol_print_date($websitepage->date_modification, 'dayhourrfc').'",
812 "author": {
813 "@type": "Person",
814 "name": "'.dol_escape_json($websitepage->author_alias).'"
815 },
816 "publisher": {
817 "@type": "Organization",
818 "name": "'.dol_escape_json($companyname).'",
819 "logo": {
820 "@type": "ImageObject",
821 "url": "/wrapper.php?modulepart=mycompany&file='.urlencode('logos/'.$mysoc->logo).'"
822 }
823 },'."\n";
824 if ($websitepage->keywords) {
825 $ret .= '"keywords": [';
826 $i = 0;
827 $arrayofkeywords = explode(',', $websitepage->keywords);
828 foreach ($arrayofkeywords as $keyword) {
829 $ret .= '"'.dol_escape_json($keyword).'"';
830 $i++;
831 if ($i < count($arrayofkeywords)) {
832 $ret .= ', ';
833 }
834 }
835 $ret .= '],'."\n";
836 }
837 $ret .= '"description": "'.dol_escape_json($description).'"';
838 $ret .= "\n".'}'."\n";
839 $ret .= '</script>'."\n";
840 } else {
841 $ret = '<!-- no structured data inserted inline inside blogpost because no author_alias defined -->'."\n";
842 }
843 } elseif ($type == 'product') {
844 $ret = '<!-- Add structured data for product -->'."\n";
845 $ret .= '<script nonce="'.getNonce().'" type="application/ld+json">'."\n";
846 $ret .= '{
847 "@context": "https://schema.org/",
848 "@type": "Product",
849 "name": "'.dol_escape_json($data['label']).'",
850 "image": [
851 "'.dol_escape_json($data['image']).'",
852 ],
853 "description": "'.dol_escape_json($data['description']).'",
854 "sku": "'.dol_escape_json($data['ref']).'",
855 "brand": {
856 "@type": "Thing",
857 "name": "'.dol_escape_json($data['brand']).'"
858 },
859 "author": {
860 "@type": "Person",
861 "name": "'.dol_escape_json($data['author']).'"
862 }
863 },
864 "offers": {
865 "@type": "Offer",
866 "url": "https://example.com/anvil",
867 "priceCurrency": "'.dol_escape_json($data['currency'] ? $data['currency'] : $conf->currency).'",
868 "price": "'.dol_escape_json($data['price']).'",
869 "itemCondition": "https://schema.org/UsedCondition",
870 "availability": "https://schema.org/InStock",
871 "seller": {
872 "@type": "Organization",
873 "name": "'.dol_escape_json($mysoc->name).'"
874 }
875 }
876 }'."\n";
877 $ret .= '</script>'."\n";
878 } elseif ($type == 'qa') {
879 $ret = '<!-- Add structured data for QA -->'."\n";
880 $ret .= '<script nonce="'.getNonce().'" type="application/ld+json">'."\n";
881 $ret .= '{
882 "@context": "https://schema.org/",
883 "@type": "QAPage",
884 "mainEntity": {
885 "@type": "Question",
886 "name": "'.dol_escape_json($data['name']).'",
887 "text": "'.dol_escape_json($data['name']).'",
888 "answerCount": 1,
889 "author": {
890 "@type": "Person",
891 "name": "'.dol_escape_json($data['author']).'"
892 }
893 "acceptedAnswer": {
894 "@type": "Answer",
895 "text": "'.dol_escape_json(dol_string_nohtmltag(dolStripPhpCode($data['description']))).'",
896 "author": {
897 "@type": "Person",
898 "name": "'.dol_escape_json($data['author']).'"
899 }
900 }
901 }
902 }'."\n";
903 $ret .= '</script>'."\n";
904 } else {
905 $ret = '';
906 }
907 return $ret;
908}
909
916function getSocialNetworkHeaderCards($params = null)
917{
918 global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs; // Very important. Required to have var available when running included containers.
919 '@phan-var-force Website $website';
920
921 $out = '';
922
923 if ($website->virtualhost) {
924 $pageurl = $websitepage->pageurl;
925 $title = $websitepage->title;
926 $image = $websitepage->image;
927 $companyname = $mysoc->name;
928 $description = $websitepage->description;
929
930 $pageurl = str_replace('__WEBSITE_KEY__', $website->ref, $pageurl);
931 $title = str_replace('__WEBSITE_KEY__', $website->ref, $title);
932 $image = '/medias'.(preg_match('/^\//', $image) ? '' : '/').str_replace('__WEBSITE_KEY__', $website->ref, $image);
933 $companyname = str_replace('__WEBSITE_KEY__', $website->ref, $companyname);
934 $description = str_replace('__WEBSITE_KEY__', $website->ref, $description);
935
936 $shortlangcode = '';
937 if ($websitepage->lang) {
938 $shortlangcode = substr($websitepage->lang, 0, 2); // en_US or en-US -> en
939 }
940 if (empty($shortlangcode)) {
941 $shortlangcode = substr($website->lang, 0, 2); // en_US or en-US -> en
942 }
943
944 $fullurl = $website->virtualhost.'/'.$websitepage->pageurl.'.php';
945 $canonicalurl = $website->virtualhost.(($websitepage->id == $website->fk_default_home) ? '/' : (($shortlangcode != substr($website->lang, 0, 2) ? '/'.$shortlangcode : '').'/'.$websitepage->pageurl.'.php'));
946 $hashtags = trim(implode(' #', array_map('trim', explode(',', $websitepage->keywords))));
947
948 // Open Graph
949 $out .= '<meta name="og:type" content="website">'."\n"; // TODO If blogpost, use type article
950 $out .= '<meta name="og:title" content="'.$websitepage->title.'">'."\n";
951 if ($websitepage->image) {
952 $out .= '<meta name="og:image" content="'.$website->virtualhost.$image.'">'."\n";
953 }
954 $out .= '<meta name="og:url" content="'.$canonicalurl.'">'."\n";
955
956 // Twitter
957 $out .= '<meta name="twitter:card" content="summary">'."\n";
958 if (!empty($params) && !empty($params['twitter_account'])) {
959 $out .= '<meta name="twitter:site" content="@'.$params['twitter_account'].'">'."\n";
960 $out .= '<meta name="twitter:creator" content="@'.$params['twitter_account'].'">'."\n";
961 }
962 $out .= '<meta name="twitter:title" content="'.$websitepage->title.'">'."\n";
963 if ($websitepage->description) {
964 $out .= '<meta name="twitter:description" content="'.$websitepage->description.'">'."\n";
965 }
966 if ($websitepage->image) {
967 $out .= '<meta name="twitter:image" content="'.$website->virtualhost.$image.'">'."\n";
968 }
969 //$out .= '<meta name="twitter:domain" content="'.getDomainFromURL($website->virtualhost, 1).'">';
970 /*
971 $out .= '<meta name="twitter:app:name:iphone" content="">';
972 $out .= '<meta name="twitter:app:name:ipad" content="">';
973 $out .= '<meta name="twitter:app:name:googleplay" content="">';
974 $out .= '<meta name="twitter:app:url:iphone" content="">';
975 $out .= '<meta name="twitter:app:url:ipad" content="">';
976 $out .= '<meta name="twitter:app:url:googleplay" content="">';
977 $out .= '<meta name="twitter:app:id:iphone" content="">';
978 $out .= '<meta name="twitter:app:id:ipad" content="">';
979 $out .= '<meta name="twitter:app:id:googleplay" content="">';
980 */
981 }
982
983 return $out;
984}
985
992function getSocialNetworkSharingLinks($socialnetworks = '')
993{
994 global $website, $websitepage; // Very important. Required to have var available when running included containers.
995 '@phan-var-force Website $website';
996
997 $out = '<!-- section for social network sharing of page -->'."\n";
998
999 if ($website->virtualhost) {
1000 $fullurl = $website->virtualhost.'/'.$websitepage->pageurl.'.php';
1001 $hashtags = trim(implode(' #', array_map('trim', explode(',', $websitepage->keywords))));
1002
1003 $out .= '<div class="dol-social-share">'."\n";
1004
1005 // Twitter
1006 if (empty($socialnetworks) || preg_match('/twitter/', $socialnetworks)) {
1007 $out .= '<div class="dol-social-share-tw">'."\n";
1008 $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>';
1009 $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>';
1010 $out .= '</div>'."\n";
1011 }
1012
1013 // Reddit
1014 if (empty($socialnetworks) || preg_match('/reddit/', $socialnetworks)) {
1015 $out .= '<div class="dol-social-share-reddit">'."\n";
1016 $out .= '<a href="https://www.reddit.com/submit" target="_blank" rel="noopener noreferrer external" onclick="window.location = \'https://www.reddit.com/submit?url='.urlencode($fullurl).'\'; return false">';
1017 $out .= '<span class="dol-social-share-reddit-span">Reddit</span>';
1018 $out .= '</a>';
1019 $out .= '</div>'."\n";
1020 }
1021
1022 // Facebook
1023 if (empty($socialnetworks) || preg_match('/facebook/', $socialnetworks)) {
1024 $out .= '<div class="dol-social-share-fbl">'."\n";
1025 $out .= '<a href="https://www.facebook.com/sharer/sharer.php?u='.urlencode($fullurl).'">';
1026 $out .= '<span class="dol-social-share-fbl-span">Facebook</span>';
1027 $out .= '</a>';
1028 $out .= '</div>';
1029 }
1030
1031 $out .= "\n</div>\n";
1032 } else {
1033 $out .= '<!-- virtual host not defined in CMS. No way to add sharing buttons -->'."\n";
1034 }
1035 $out .= '<!-- section end for social network sharing of page -->'."\n";
1036
1037 return $out;
1038}
1039
1040
1049{
1050 global $db;
1051
1052 $nb = 0;
1053
1054 include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
1055 $regexforimg = getListOfPossibleImageExt(0);
1056 $regexforimg = '('.$regexforimg.')$';
1057
1058 $sql = "SELECT COUNT(rowid) as nb";
1059 $sql .= " FROM ".MAIN_DB_PREFIX."ecm_files";
1060 $sql .= " WHERE entity IN (".getEntity($object->element).")";
1061 $sql .= " AND src_object_type = '".$db->escape($object->element)."' AND src_object_id = ".((int) $object->id); // Filter on object
1062 $sql .= " AND ".$db->regexpsql('filename', $regexforimg, 1);
1063 $sql .= " AND share IS NOT NULL"; // Only image that are public
1064
1065 $resql = $db->query($sql);
1066 if ($resql) {
1067 $obj = $db->fetch_object($resql);
1068 if ($obj) {
1069 $nb = $obj->nb;
1070 }
1071 }
1072
1073 return $nb;
1074}
1075
1087function getImagePublicURLOfObject($object, $no = 1, $extName = '', $cover = 1)
1088{
1089 global $db;
1090
1091 $image_path = '';
1092
1093 include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
1094 $regexforimg = getListOfPossibleImageExt(0);
1095 $regexforimg = '('.$regexforimg.')$';
1096
1097 $sql = "SELECT rowid, ref, share, filename, cover, position";
1098 $sql .= " FROM ".MAIN_DB_PREFIX."ecm_files";
1099 $sql .= " WHERE entity IN (".getEntity($object->element).")";
1100 $sql .= " AND src_object_type = '".$db->escape($object->element)."' AND src_object_id = ".((int) $object->id); // Filter on object
1101 $sql .= " AND ".$db->regexpsql('filename', $regexforimg, 1);
1102 $sql .= ($cover ? "" : " AND cover <> 1");
1103 if ($cover == 1) {
1104 $sql .= $db->order("cover,position,rowid", "ASC,ASC,ASC");
1105 } else {
1106 $sql .= $db->order("cover,position,rowid", "DESC,ASC,ASC");
1107 }
1108
1109 $resql = $db->query($sql);
1110 if ($resql) {
1111 $num = $db->num_rows($resql);
1112 $i = 0;
1113 $found = 0;
1114 $foundnotshared = 0;
1115 while ($i < $num) {
1116 $obj = $db->fetch_object($resql);
1117 if ($obj) {
1118 if (empty($obj->share)) {
1119 $foundnotshared++;
1120 } else {
1121 $found++;
1122
1123 if (defined('USEDOLIBARRSERVER') || defined('USEDOLIBARREDITOR')) {
1124 $image_path = DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($obj->share);
1125 } else {
1126 $image_path = '/wrapper.php?hashp='.urlencode($obj->share);
1127 }
1128
1129 if ($extName) {
1130 $image_path .= '&extname='.urlencode($extName);
1131 }
1132 }
1133 }
1134 if ($found >= $no) {
1135 break;
1136 }
1137 $i++;
1138 }
1139 if (!$found && $foundnotshared) {
1140 if (defined('USEDOLIBARRSERVER') || defined('USEDOLIBARREDITOR')) {
1141 $image_path = DOL_URL_ROOT.'/viewimage.php?modulepart=common&file=nophotopublic.png';
1142 } else {
1143 $image_path = '/wrapper.php?modulepart=common&file=nophotopublic.png';
1144 }
1145 }
1146 }
1147
1148 if (empty($image_path)) {
1149 if (defined('USEDOLIBARRSERVER') || defined('USEDOLIBARREDITOR')) {
1150 $image_path = DOL_URL_ROOT.'/viewimage.php?modulepart=common&file=nophoto.png';
1151 } else {
1152 $image_path = '/wrapper.php?modulepart=common&file=nophoto.png';
1153 }
1154 }
1155
1156 return $image_path;
1157}
1158
1167{
1168 global $db;
1169
1170 $files = array();
1171
1172 include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
1173 $regexforimg = getListOfPossibleImageExt(0);
1174 $regexforimg = '/('.$regexforimg.')$/i';
1175
1176 $sql = "SELECT rowid, ref, share, filename, cover, position";
1177 $sql .= " FROM ".MAIN_DB_PREFIX."ecm_files";
1178 $sql .= " WHERE entity IN (".getEntity($object->element).")";
1179 $sql .= " AND src_object_type = '".$db->escape($object->element)."' AND src_object_id = ".((int) $object->id);
1180 $sql .= $db->order("cover,position,rowid", "ASC,ASC,ASC");
1181
1182 $resql = $db->query($sql);
1183 if ($resql) {
1184 $num = $db->num_rows($resql);
1185 $i = 0;
1186 while ($i < $num) {
1187 $obj = $db->fetch_object($resql);
1188 if ($obj) {
1189 if (!empty($obj->share)) {
1190 $files[$obj->rowid]['filename'] = $obj->filename;
1191 $files[$obj->rowid]['position'] = $obj->position;
1192 if (defined('USEDOLIBARRSERVER') || defined('USEDOLIBARREDITOR')) {
1193 if (preg_match($regexforimg, $obj->filename)) {
1194 $files[$obj->rowid]['url'] = DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($obj->share);
1195 } else {
1196 $files[$obj->rowid]['url'] = DOL_URL_ROOT.'/document.php?hashp='.urlencode($obj->share);
1197 }
1198 } else {
1199 $files[$obj->rowid]['url'] = '/wrapper.php?hashp='.urlencode($obj->share);
1200 }
1201 }
1202 }
1203 $i++;
1204 }
1205 }
1206
1207 return $files;
1208}
1209
1210
1226function getPagesFromSearchCriterias($type, $algo, $searchstring, $max = 25, $sortfield = 'date_creation', $sortorder = 'DESC', $langcode = '', $otherfilters = [], $status = 1)
1227{
1228 global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs; // Very important. Required to have var available when running included containers.
1229 '@phan-var-force Website $website';
1230
1231 $error = 0;
1232 $arrayresult = array('code' => '', 'list' => array());
1233
1234 // Clean parameters
1235 if (!is_object($weblangs)) {
1236 $weblangs = $langs;
1237 }
1238 if (empty($algo)) {
1239 $algo = 'content';
1240 }
1241
1242 /*
1243 if (empty($searchstring) && empty($type) && empty($langcode) && empty($otherfilters)) {
1244 $error++;
1245 $arrayresult['code'] = 'KO';
1246 $arrayresult['message'] = $weblangs->trans("EmptySearchString");
1247 } elseif ($searchstring && dol_strlen($searchstring) < 2) {
1248 $weblangs->load("errors");
1249 $error++;
1250 $arrayresult['code'] = 'KO';
1251 $arrayresult['message'] = $weblangs->trans("ErrorSearchCriteriaTooSmall");
1252 } else {
1253 */
1254 $tmparrayoftype = explode(',', $type);
1255 /*foreach ($tmparrayoftype as $tmptype) {
1256 if (!in_array($tmptype, array('', 'page', 'blogpost'))) {
1257 $error++;
1258 $arrayresult['code'] = 'KO';
1259 $arrayresult['message'] = 'Bad value for parameter type';
1260 break;
1261 }
1262 }*/
1263 //}
1264
1265 $searchdone = 0;
1266 $found = 0;
1267
1268 if (!$error && (empty($max) || ($found < $max)) && (preg_match('/meta/', $algo) || preg_match('/content/', $algo))) {
1269 include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
1270
1271 $sql = 'SELECT wp.rowid FROM '.MAIN_DB_PREFIX.'website_page as wp';
1272 if (is_array($otherfilters) && !empty($otherfilters['category'])) {
1273 $sql .= ', '.MAIN_DB_PREFIX.'categorie_website_page as cwp';
1274 }
1275 $sql .= " WHERE wp.fk_website = ".((int) $website->id);
1276 if ($status >= 0) {
1277 $sql .= " AND wp.status = ".((int) $status);
1278 }
1279 if ($langcode) {
1280 $sql .= " AND wp.lang = '".$db->escape($langcode)."'";
1281 }
1282 if ($type) {
1283 $tmparrayoftype = explode(',', $type);
1284 $typestring = '';
1285 foreach ($tmparrayoftype as $tmptype) {
1286 $typestring .= ($typestring ? ", " : "")."'".$db->escape(trim($tmptype))."'";
1287 }
1288 $sql .= " AND wp.type_container IN (".$db->sanitize($typestring, 1).")";
1289 }
1290 $sql .= " AND (";
1291 $searchalgo = '';
1292 if (preg_match('/meta/', $algo)) {
1293 $searchalgo .= ($searchalgo ? ' OR ' : '')."wp.title LIKE '%".$db->escape($db->escapeforlike($searchstring))."%' OR wp.description LIKE '%".$db->escape($db->escapeforlike($searchstring))."%'";
1294 $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
1295 }
1296 if (preg_match('/content/', $algo)) {
1297 $searchalgo .= ($searchalgo ? ' OR ' : '')."wp.content LIKE '%".$db->escape($db->escapeforlike($searchstring))."%'";
1298 }
1299 $sql .= $searchalgo;
1300 if (is_array($otherfilters) && !empty($otherfilters['category'])) {
1301 $sql .= ' AND cwp.fk_website_page = wp.rowid AND cwp.fk_categorie = '.((int) $otherfilters['category']);
1302 }
1303 $sql .= ")";
1304 $sql .= $db->order($sortfield, $sortorder);
1305 $sql .= $db->plimit($max);
1306 //print $sql;
1307
1308 $resql = $db->query($sql);
1309
1310 if ($resql) {
1311 $i = 0;
1312 while (($obj = $db->fetch_object($resql)) && ($i < $max || $max == 0)) {
1313 if ($obj->rowid > 0) {
1314 $tmpwebsitepage = new WebsitePage($db);
1315 $tmpwebsitepage->fetch($obj->rowid);
1316 if ($tmpwebsitepage->id > 0) {
1317 $arrayresult['list'][$obj->rowid] = $tmpwebsitepage;
1318 }
1319 $found++;
1320 }
1321 $i++;
1322 }
1323 } else {
1324 $error++;
1325 $arrayresult['code'] = $db->lasterrno();
1326 $arrayresult['message'] = $db->lasterror();
1327 }
1328
1329 $searchdone = 1;
1330 }
1331
1332 if (!$error && (empty($max) || ($found < $max)) && (preg_match('/sitefiles/', $algo))) {
1333 global $dolibarr_main_data_root;
1334
1335 $pathofwebsite = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$website->ref;
1336 $filehtmlheader = $pathofwebsite.'/htmlheader.html';
1337 $filecss = $pathofwebsite.'/styles.css.php';
1338 $filejs = $pathofwebsite.'/javascript.js.php';
1339 $filerobot = $pathofwebsite.'/robots.txt';
1340 $filehtaccess = $pathofwebsite.'/.htaccess';
1341 $filemanifestjson = $pathofwebsite.'/manifest.json.php';
1342 $filereadme = $pathofwebsite.'/README.md';
1343
1344 $filecontent = file_get_contents($filehtmlheader);
1345 if ((empty($max) || ($found < $max)) && preg_match('/'.preg_quote($searchstring, '/').'/', $filecontent)) {
1346 $arrayresult['list'][] = array('type' => 'website_htmlheadercontent');
1347 }
1348
1349 $filecontent = file_get_contents($filecss);
1350 if ((empty($max) || ($found < $max)) && preg_match('/'.preg_quote($searchstring, '/').'/', $filecontent)) {
1351 $arrayresult['list'][] = array('type' => 'website_csscontent');
1352 }
1353
1354 $filecontent = file_get_contents($filejs);
1355 if ((empty($max) || ($found < $max)) && preg_match('/'.preg_quote($searchstring, '/').'/', $filecontent)) {
1356 $arrayresult['list'][] = array('type' => 'website_jscontent');
1357 }
1358
1359 $filerobot = file_get_contents($filerobot);
1360 if ((empty($max) || ($found < $max)) && preg_match('/'.preg_quote($searchstring, '/').'/', $filecontent)) {
1361 $arrayresult['list'][] = array('type' => 'website_robotcontent');
1362 }
1363
1364 $searchdone = 1;
1365 }
1366
1367 if (!$error) {
1368 if ($searchdone) {
1369 $arrayresult['code'] = 'OK';
1370 if (empty($arrayresult['list'])) {
1371 $arrayresult['code'] = 'KO';
1372 $arrayresult['message'] = $weblangs->trans("NoRecordFound");
1373 }
1374 } else {
1375 $error++;
1376 $arrayresult['code'] = 'KO';
1377 $arrayresult['message'] = 'No supported algorithm found';
1378 }
1379 }
1380
1381 return $arrayresult;
1382}
1383
1393function getImageFromHtmlContent($htmlContent, $imageNumber = 1)
1394{
1395 $dom = new DOMDocument();
1396
1397 libxml_use_internal_errors(false); // Avoid to fill memory with xml errors
1398 if (LIBXML_VERSION < 20900) {
1399 // Avoid load of external entities (security problem).
1400 // Required only if LIBXML_VERSION < 20900
1401 // @phan-suppress-next-line PhanDeprecatedFunctionInternal
1402 libxml_disable_entity_loader(true);
1403 }
1404
1405 // Load HTML content into object
1406 // We add the @ to avoid verbose warnings logsin the error.log file. For example:
1407 // "PHP message: PHP Warning: DOMDocument::loadHTML(): Tag section invalid in Entity, line: ...", etc.
1408 @$dom->loadHTML($htmlContent);
1409
1410 // Re-enable HTML load errors
1411 libxml_clear_errors();
1412
1413 // Load all img tags
1414 $images = $dom->getElementsByTagName('img');
1415
1416 // Check if nb of image is valid
1417 if ($imageNumber > 0 && $imageNumber <= $images->length) {
1418 // Récupère l'image correspondante (index - 1 car $imageNumber est 1-based)
1419 $img = $images->item($imageNumber - 1);
1420 if ($img instanceof DOMElement) {
1421 return $img->getAttribute('src');
1422 }
1423 }
1424
1425 return '';
1426}
1427
1444function getAllImages($object, $objectpage, $urltograb, &$tmp, &$action, $modifylinks = 0, $grabimages = 1, $grabimagesinto = 'subpage')
1445{
1446 global $conf;
1447
1448 $error = 0;
1449
1450 dol_syslog("Call getAllImages with grabimagesinto=".$grabimagesinto);
1451
1452 $alreadygrabbed = array();
1453
1454 if (preg_match('/\/$/', $urltograb)) {
1455 $urltograb .= '.';
1456 }
1457 $urltograb = dirname($urltograb); // So urltograb is now http://www.nltechno.com or http://www.nltechno.com/dir1
1458
1459 // Search X in "img...src=X"
1460 $regs = array();
1461 preg_match_all('/<img([^\.\/]+)src="([^>"]+)"([^>]*)>/i', $tmp, $regs);
1462
1463 foreach ($regs[0] as $key => $val) {
1464 if (preg_match('/^data:image/i', $regs[2][$key])) {
1465 continue; // We do nothing for such images
1466 }
1467
1468 if (preg_match('/^\//', $regs[2][$key])) {
1469 $urltograbdirrootwithoutslash = getRootURLFromURL($urltograb);
1470 $urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key]; // We use dirroot
1471 } else {
1472 $urltograbbis = $urltograb.'/'.$regs[2][$key]; // We use dir of grabbed file
1473 }
1474
1475 $linkwithoutdomain = $regs[2][$key];
1476 $dirforimages = '/'.$objectpage->pageurl;
1477 if ($grabimagesinto == 'root') {
1478 $dirforimages = '';
1479 }
1480
1481 // Define $filetosave and $filename
1482 $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $regs[2][$key]) ? '' : '/').$regs[2][$key];
1483 if (preg_match('/^http/', $regs[2][$key])) {
1484 $urltograbbis = $regs[2][$key];
1485 $linkwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\//i', '', $regs[2][$key]);
1486 $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain) ? '' : '/').$linkwithoutdomain;
1487 }
1488 $filename = 'image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain) ? '' : '/').$linkwithoutdomain;
1489
1490 // Clean the aa/bb/../cc into aa/cc
1491 $filetosave = preg_replace('/\/[^\/]+\/\.\./', '', $filetosave);
1492 $filename = preg_replace('/\/[^\/]+\/\.\./', '', $filename);
1493
1494 if (empty($alreadygrabbed[$urltograbbis])) {
1495 if ($grabimages) {
1496 $tmpgeturl = getURLContent($urltograbbis, 'GET', '', 1, array(), array('http', 'https'), 0);
1497 if ($tmpgeturl['curl_error_no']) {
1498 $error++;
1499 setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['curl_error_msg'], null, 'errors');
1500 $action = 'create';
1501 } elseif ($tmpgeturl['http_code'] != '200') {
1502 $error++;
1503 setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['http_code'], null, 'errors');
1504 $action = 'create';
1505 } else {
1506 $alreadygrabbed[$urltograbbis] = 1; // Track that file was already grabbed.
1507
1508 dol_mkdir(dirname($filetosave));
1509
1510 $fp = fopen($filetosave, "w");
1511 fwrite($fp, $tmpgeturl['content']);
1512 fclose($fp);
1513 dolChmod($filetosave);
1514 }
1515 }
1516 }
1517
1518 if ($modifylinks) {
1519 $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);
1520 }
1521 }
1522
1523 // Search X in "background...url(X)"
1524 preg_match_all('/background([^\.\/\‍(;]+)url\‍([\"\']?([^\‍)\"\']*)[\"\']?\‍)/i', $tmp, $regs);
1525
1526 foreach ($regs[0] as $key => $val) {
1527 if (preg_match('/^data:image/i', $regs[2][$key])) {
1528 continue; // We do nothing for such images
1529 }
1530
1531 if (preg_match('/^\//', $regs[2][$key])) {
1532 $urltograbdirrootwithoutslash = getRootURLFromURL($urltograb);
1533 $urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key]; // We use dirroot
1534 } else {
1535 $urltograbbis = $urltograb.'/'.$regs[2][$key]; // We use dir of grabbed file
1536 }
1537
1538 $linkwithoutdomain = $regs[2][$key];
1539
1540 $dirforimages = '/'.$objectpage->pageurl;
1541 if ($grabimagesinto == 'root') {
1542 $dirforimages = '';
1543 }
1544
1545 $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $regs[2][$key]) ? '' : '/').$regs[2][$key];
1546
1547 if (preg_match('/^http/', $regs[2][$key])) {
1548 $urltograbbis = $regs[2][$key];
1549 $linkwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\//i', '', $regs[2][$key]);
1550 $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain) ? '' : '/').$linkwithoutdomain;
1551 }
1552
1553 $filename = 'image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain) ? '' : '/').$linkwithoutdomain;
1554
1555 // Clean the aa/bb/../cc into aa/cc
1556 $filetosave = preg_replace('/\/[^\/]+\/\.\./', '', $filetosave);
1557 $filename = preg_replace('/\/[^\/]+\/\.\./', '', $filename);
1558
1559 if (empty($alreadygrabbed[$urltograbbis])) {
1560 if ($grabimages) {
1561 $tmpgeturl = getURLContent($urltograbbis, 'GET', '', 1, array(), array('http', 'https'), 0);
1562 if ($tmpgeturl['curl_error_no']) {
1563 $error++;
1564 setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['curl_error_msg'], null, 'errors');
1565 $action = 'create';
1566 } elseif ($tmpgeturl['http_code'] != '200') {
1567 $error++;
1568 setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['http_code'], null, 'errors');
1569 $action = 'create';
1570 } else {
1571 $alreadygrabbed[$urltograbbis] = 1; // Track that file was already grabbed.
1572
1573 dol_mkdir(dirname($filetosave));
1574
1575 $fp = fopen($filetosave, "w");
1576 if ($fp) {
1577 fwrite($fp, $tmpgeturl['content']);
1578 fclose($fp);
1579 dolChmod($filetosave);
1580 } else {
1581 $error++;
1582 setEventMessages('Error failed to open file '.$filetosave.' for writing', null, 'errors');
1583 $action = 'create';
1584 }
1585 }
1586 }
1587 }
1588
1589 if ($modifylinks) {
1590 $tmp = preg_replace('/'.preg_quote($regs[0][$key], '/').'/i', 'background'.$regs[1][$key].'url("'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file='.$filename.'")', $tmp);
1591 }
1592 }
1593}
1594
1601function getNewsDetailsById($postId)
1602{
1603 global $db;
1604
1605 if (empty($postId)) {
1606 return -1;
1607 }
1608
1609 $sql = "SELECT p.title, p.description, p.date_creation, p.image
1610 FROM ".MAIN_DB_PREFIX."website_page as p
1611 WHERE p.rowid = ".(intval($postId));
1612
1613 $resql = $db->query($sql);
1614 if ($resql) {
1615 return $db->fetch_array($resql);
1616 } else {
1617 return -1;
1618 }
1619}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
Class Websitepage.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dolChmod($filepath, $newmask='')
Change mod of a file.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_escape_json($stringtoescape)
Returns text escaped for inclusion into javascript code.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
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).
getListOfPossibleImageExt($acceptsvg=0)
Return if a filename is file name of a supported image format.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
getAllImages($object, $objectpage, $urltograb, &$tmp, &$action, $modifylinks=0, $grabimages=1, $grabimagesinto='subpage')
Download all images found into an external URL.
includeContainer($containerref, $once=0, $cachedelay=0, $cachekey='')
Execute content of a php page and report result to be included into another page.
getPublicFilesOfObject($object)
Return array with list of all public files of a given object.
getImageFromHtmlContent($htmlContent, $imageNumber=1)
Return the URL of an image found into a HTML content.
getImagePublicURLOfObject($object, $no=1, $extName='', $cover=1)
Return the public image URL of an object.
dolStripPhpCode($str, $replacewith='')
Remove PHP code part from a string.
getNbOfImagePublicURLOfObject($object)
Return nb of images known into inde files for an object;.
getStructuredData($type, $data=array())
Return HTML content to add structured data for an article, news or Blog Post.
dolWebsiteReplacementOfLinks($website, $content, $removephppart=0, $contenttype='html', $containerid=0)
Convert a page content to have correct links (based on DOL_URL_ROOT) into an html content.
getPagesFromSearchCriterias($type, $algo, $searchstring, $max=25, $sortfield='date_creation', $sortorder='DESC', $langcode='', $otherfilters=[], $status=1)
Return list of containers object that match a criteria.
dolWebsiteIncrementCounter($websiteid, $websitepagetype, $websitepageid)
Increase the website counter of page access.
getNewsDetailsById($postId)
Retrieves the details of a news post by its ID.
dolReplaceSmileyCodeWithUTF8($content)
Converts smiley string into the utf8 sequence.
dolKeepOnlyPhpCode($str)
Keep only PHP code part from a HTML string page.
dolWebsiteOutput($content, $contenttype='html', $containerid=0)
Render a string of an HTML content and output it.
redirectToContainer($containerref, $containeraliasalt='', $containerid=0, $permanent=0, $parameters=array(), $parampropagation=1)
Format img tags to introduce viewimage on img src.
getSocialNetworkHeaderCards($params=null)
Return HTML content to add as header card for an article, news or Blog Post or home page.
getSocialNetworkSharingLinks($socialnetworks='')
Return HTML content to add structured data for an article, news or Blog Post.