34 $str = str_replace(
'<?=',
'<?php', $str);
40 $parts = preg_split(
'/'.preg_quote(
'<?php',
'/').
'/i', $str);
44 foreach ($parts as $part) {
51 $partlings = explode(
'?>', $part);
52 if (!empty($partlings)) {
55 if (count($partlings) > 1) {
61 $newstr .=
'<span phptag>'.$replacewith.
'</span>'.implode(
'', $partlings);
78 $str = str_replace(
'<?=',
'<?php', $str);
84 $parts = preg_split(
'/'.preg_quote(
'<?php',
'/').
'/i', $str);
88 foreach ($parts as $part) {
95 $partlings = explode(
'?>', $part, 2);
96 if (!empty($partlings)) {
97 $newstr .= $partlings[0].
'?>';
99 $newstr .= $part.
'?>';
122 dol_syslog(
'dolWebsiteReplacementOfLinks start (contenttype='.$contenttype.
" containerid=".$containerid.
" USEDOLIBARREDITOR=".(defined(
'USEDOLIBARREDITOR') ?
'1' :
'').
" USEDOLIBARRSERVER=".(defined(
'USEDOLIBARRSERVER') ?
'1' :
'').
')', LOG_DEBUG);
126 $replacewith =
'...php...';
127 if ($removephppart) {
130 $content = preg_replace(
'/value="<\?php((?!\?>).)*\?>\n*/ims',
'value="'.$replacewith.
'"', $content);
132 $replacewith =
'"callto=#';
133 if ($removephppart) {
136 $content = preg_replace(
'/"callto:<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content);
138 $replacewith =
'"mailto=#';
139 if ($removephppart) {
142 $content = preg_replace(
'/"mailto:<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content);
144 $replacewith =
'src="php';
145 if ($removephppart) {
148 $content = preg_replace(
'/src="<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content);
150 $replacewith =
'href="php';
151 if ($removephppart) {
154 $content = preg_replace(
'/href="<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content);
157 $replacewith =
'...php...';
158 if ($removephppart) {
169 $content = str_replace(
'href="styles.css.php',
'href="!~!~!~styles.css.php', $content);
170 $content = str_replace(
'href="http',
'href="!~!~!~http', $content);
171 $content = str_replace(
'href="//',
'href="!~!~!~//', $content);
172 $content = str_replace(
'src="viewimage.php',
'src="!~!~!~/viewimage.php', $content);
173 $content = str_replace(
'src="/viewimage.php',
'src="!~!~!~/viewimage.php', $content);
174 $content = str_replace(
'src="'.DOL_URL_ROOT.
'/viewimage.php',
'src="!~!~!~'.DOL_URL_ROOT.
'/viewimage.php', $content);
175 $content = str_replace(
'href="document.php',
'href="!~!~!~/document.php', $content);
176 $content = str_replace(
'href="/document.php',
'href="!~!~!~/document.php', $content);
177 $content = str_replace(
'href="'.DOL_URL_ROOT.
'/document.php',
'href="!~!~!~'.DOL_URL_ROOT.
'/document.php', $content);
180 $content = preg_replace(
'/(href=")\/(#[^\"<>]*)?\"/',
'\1!~!~!~'.DOL_URL_ROOT.
'/website/index.php?website='.$website->ref.
'&pageid='.$website->fk_default_home.
'\2"', $content, -1, $nbrep);
182 $content = preg_replace(
'/(href=")\/?([^:\"\!]*)\.php(#[^\"<>]*)?\"/',
'\1!~!~!~'.DOL_URL_ROOT.
'/website/index.php?website='.$website->ref.
'&pageref=\2\3"', $content, -1, $nbrep);
184 $content = preg_replace(
'/(href=")\/?([^:\"\!]*)\.php\?([^#\"<>]*)(#[^\"<>]*)?\"/',
'\1!~!~!~'.DOL_URL_ROOT.
'/website/index.php?website='.$website->ref.
'&pageref=\2&\3\4"', $content, -1, $nbrep);
187 $content = preg_replace(
'/url\((["\']?)\/?medias\//',
'url(\1!~!~!~'.DOL_URL_ROOT.
'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
188 $content = preg_replace(
'/data-slide-bg=(["\']?)\/?medias\//',
'data-slide-bg=\1!~!~!~'.DOL_URL_ROOT.
'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
192 $content = preg_replace(
'/(<img[^>]*src=")\/?medias\//',
'\1!~!~!~'.DOL_URL_ROOT.
'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
194 $content = preg_replace(
'/(<img[^>]*src=")\/?([^:\"\!]+)\"/',
'\1!~!~!~'.DOL_URL_ROOT.
'/viewimage.php?modulepart=medias&file=\2"', $content, -1, $nbrep);
196 $content = preg_replace(
'/(<img[^>]*src=")(\/?viewimage\.php)/',
'\1!~!~!~'.DOL_URL_ROOT.
'/viewimage.php', $content, -1, $nbrep);
199 $content = preg_replace(
'/(action=")\/?([^:\"]*)(\.php\")/',
'\1!~!~!~'.DOL_URL_ROOT.
'/website/index.php?website='.$website->ref.
'&pageref=\2"', $content, -1, $nbrep);
202 $content = preg_replace(
'/(href=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/',
'\1!~!~!~'.DOL_URL_ROOT.
'\2\3', $content, -1, $nbrep);
203 $content = preg_replace(
'/(src=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/',
'\1!~!~!~'.DOL_URL_ROOT.
'\2\3', $content, -1, $nbrep);
206 $content = preg_replace(
'/(url\(")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/',
'\1!~!~!~'.DOL_URL_ROOT.
'\2\3', $content, -1, $nbrep);
209 $content = str_replace(
'src="!~!~!~/viewimage.php',
'src="!~!~!~'.DOL_URL_ROOT.
'/viewimage.php', $content);
210 $content = str_replace(
'href="!~!~!~/document.php',
'href="!~!~!~'.DOL_URL_ROOT.
'/document.php', $content);
212 $content = str_replace(
'!~!~!~',
'', $content);
214 dol_syslog(
'dolWebsiteReplacementOfLinks end', LOG_DEBUG);
232 global $db, $langs, $conf, $user;
233 global $dolibarr_main_url_root, $dolibarr_main_data_root;
235 global $includehtmlcontentopened;
239 dol_syslog(
"dolWebsiteOutput start - contenttype=".$contenttype.
" containerid=".$containerid.
" USEDOLIBARREDITOR=".(defined(
'USEDOLIBARREDITOR') ?
'1' :
'').
" USEDOLIBARRSERVER=".(defined(
'USEDOLIBARRSERVER') ?
'1' :
'').
' includehtmlcontentopened='.$includehtmlcontentopened);
244 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
245 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
248 if (defined(
'USEDOLIBARREDITOR')) {
250 if ($contenttype ==
'html') {
251 $content = preg_replace(
'/<head>.*<\/head>/ims',
'', $content);
252 $content = preg_replace(
'/^.*<body(\s[^>]*)*>/ims',
'', $content);
253 $content = preg_replace(
'/<\/body(\s[^>]*)*>.*$/ims',
'', $content);
255 } elseif (defined(
'USEDOLIBARRSERVER')) {
256 $content = str_replace(
'<link rel="stylesheet" href="/styles.css',
'<link rel="stylesheet" href="styles.css', $content);
259 $content = str_replace(
'href="styles.css.php',
'href="!~!~!~styles.css.php', $content);
260 $content = str_replace(
'href="http',
'href="!~!~!~http', $content);
261 $content = str_replace(
'href="//',
'href="!~!~!~//', $content);
262 $content = str_replace(array(
'src="viewimage.php',
'src="/viewimage.php'),
'src="!~!~!~/viewimage.php', $content);
263 $content = str_replace(
'src="'.DOL_URL_ROOT.
'/viewimage.php',
'src="!~!~!~'.DOL_URL_ROOT.
'/viewimage.php', $content);
264 $content = str_replace(array(
'href="document.php',
'href="/document.php'),
'href="!~!~!~/document.php', $content);
265 $content = str_replace(
'href="'.DOL_URL_ROOT.
'/document.php',
'href="!~!~!~'.DOL_URL_ROOT.
'/document.php', $content);
268 $content = preg_replace(
'/(href=")\/\"/',
'\1!~!~!~'.DOL_URL_ROOT.
'/public/website/index.php?website='.$website->ref.
'"', $content, -1, $nbrep);
270 $content = preg_replace(
'/(href=")\/?([^:\"\!]*)\.php(#[^\"<>]*)?\"/',
'\1!~!~!~'.DOL_URL_ROOT.
'/public/website/index.php?website='.$website->ref.
'&pageref=\2\3"', $content, -1, $nbrep);
274 $content = preg_replace(
'/(href=")\/?([^:\"\!]*)\.php\?([^#\"<>]*)(#[^\"<>]*)?\"/',
'\1!~!~!~'.DOL_URL_ROOT.
'/public/website/index.php?website='.$website->ref.
'&pageref=\2&\3\4"', $content, -1, $nbrep);
276 $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);
279 $content = preg_replace(
'/(href=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/',
'\1!~!~!~'.DOL_URL_ROOT.
'\2\3', $content, -1, $nbrep);
280 $content = preg_replace(
'/(src=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/',
'\1!~!~!~'.DOL_URL_ROOT.
'\2\3', $content, -1, $nbrep);
283 $content = preg_replace(
'/(href=")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/',
'\1!~!~!~'.DOL_URL_ROOT.
'\2\3', $content, -1, $nbrep);
284 $content = preg_replace(
'/(src=")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/',
'\1!~!~!~'.DOL_URL_ROOT.
'\2\3', $content, -1, $nbrep);
285 $content = preg_replace(
'/(url\(")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/',
'\1!~!~!~'.DOL_URL_ROOT.
'\2\3', $content, -1, $nbrep);
288 $content = preg_replace(
'/url\((["\']?)\/?medias\//',
'url(\1!~!~!~'.DOL_URL_ROOT.
'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
289 $content = preg_replace(
'/data-slide-bg=(["\']?)\/?medias\//',
'data-slide-bg=\1!~!~!~'.DOL_URL_ROOT.
'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
293 $content = preg_replace(
'/(<img[^>]*src=")\/?medias\//',
'\1!~!~!~'.DOL_URL_ROOT.
'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
295 $content = preg_replace(
'/(<img[^>]*src=")\/?([^:\"\!]+)\"/',
'\1!~!~!~'.DOL_URL_ROOT.
'/viewimage.php?modulepart=medias&file=\2"', $content, -1, $nbrep);
297 $content = preg_replace(
'/(<img[^>]*src=")(\/?viewimage\.php)/',
'\1!~!~!~'.DOL_URL_ROOT.
'/viewimage.php', $content, -1, $nbrep);
300 $content = preg_replace(
'/(action=")\/?([^:\"]*)(\.php\")/',
'\1!~!~!~'.DOL_URL_ROOT.
'/public/website/index.php?website='.$website->ref.
'&pageref=\2"', $content, -1, $nbrep);
303 $content = str_replace(
'src="!~!~!~/viewimage.php',
'src="!~!~!~'.DOL_URL_ROOT.
'/viewimage.php', $content);
304 $content = str_replace(
'href="!~!~!~/document.php',
'href="!~!~!~'.DOL_URL_ROOT.
'/document.php', $content);
307 if (empty($includehtmlcontentopened)) {
308 $content = str_replace(
'!~!~!~',
'', $content);
312 $symlinktomediaexists = 1;
313 if ($website->virtualhost) {
314 $content = preg_replace(
'/^(<link[^>]*rel="canonical" href=")\//m',
'\1'.$website->virtualhost.
'/', $content, -1, $nbrep);
323 if (!$symlinktomediaexists) {
325 $content = preg_replace(
'/(<img[^>]*src=")\/?image\//',
'\1/wrapper.php?modulepart=medias&file=medias/image/', $content, -1, $nbrep);
326 $content = preg_replace(
'/(url\(["\']?)\/?image\//',
'\1/wrapper.php?modulepart=medias&file=medias/image/', $content, -1, $nbrep);
328 $content = preg_replace(
'/(<script[^>]*src=")[^\"]*document\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/',
'\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep);
329 $content = preg_replace(
'/(<a[^>]*href=")[^\"]*document\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/',
'\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep);
331 $content = preg_replace(
'/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/',
'\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep);
332 $content = preg_replace(
'/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/',
'\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep);
333 $content = preg_replace(
'/(url\(["\']?)[^\)]*viewimage\.php([^\)]*)modulepart=medias([^\)]*)file=([^\)]*)(["\']?\))/',
'\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep);
335 $content = preg_replace(
'/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/',
'\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep);
336 $content = preg_replace(
'/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/',
'\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep);
337 $content = preg_replace(
'/(url\(["\']?)[^\)]*viewimage\.php([^\)]*)hashp=([^\)]*)(["\']?\))/',
'\1/wrapper.php\2hashp\3\4', $content, -1, $nbrep);
339 $content = preg_replace(
'/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=mycompany([^\"]*)file=([^\"]*)("[^>]*>)/',
'\1/wrapper.php\2modulepart=mycompany\3file=\4\5', $content, -1, $nbrep);
342 $content = preg_replace(
'/(<img[^>]*src=")\/?viewimage\.php/',
'\1/wrapper.php', $content, -1, $nbrep);
343 $content = preg_replace(
'/(<a[^>]*href=")\/?documents\.php/',
'\1/wrapper.php', $content, -1, $nbrep);
346 $content = preg_replace(
'/(<img[^>]*src=")\/?image\//',
'\1/medias/image/', $content, -1, $nbrep);
347 $content = preg_replace(
'/(url\(["\']?)\/?image\//',
'\1/medias/image/', $content, -1, $nbrep);
349 $content = preg_replace(
'/(<script[^>]*src=")[^\"]*document\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/',
'\1/medias/\4\5', $content, -1, $nbrep);
350 $content = preg_replace(
'/(<a[^>]*href=")[^\"]*document\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/',
'\1/medias/\4\5', $content, -1, $nbrep);
352 $content = preg_replace(
'/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/',
'\1/medias/\4\5', $content, -1, $nbrep);
353 $content = preg_replace(
'/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/',
'\1/medias/\4\5', $content, -1, $nbrep);
354 $content = preg_replace(
'/(url\(["\']?)[^\)]*viewimage\.php([^\)]*)modulepart=medias([^\)]*)file=([^\)]*)(["\']?\))/',
'\1/medias/\4\5', $content, -1, $nbrep);
356 $content = preg_replace(
'/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/',
'\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep);
357 $content = preg_replace(
'/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/',
'\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep);
358 $content = preg_replace(
'/(url\(["\']?)[^\)]*viewimage\.php([^\)]*)hashp=([^\)]*)(["\']?\))/',
'\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep);
360 $content = preg_replace(
'/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=mycompany([^\"]*)file=([^\"]*)("[^>]*>)/',
'\1/wrapper.php\2modulepart=mycompany\3file=\4\5', $content, -1, $nbrep);
363 $content = preg_replace(
'/(<img[^>]*src=")\/?viewimage\.php/',
'\1/wrapper.php', $content, -1, $nbrep);
364 $content = preg_replace(
'/(<a[^>]*href=")\/?document\.php/',
'\1/wrapper.php', $content, -1, $nbrep);
368 if (!defined(
'USEDOLIBARREDITOR')) {
369 $content = str_replace(
' contenteditable="true"',
' contenteditable="false"', $content);
372 if (!empty($conf->global->WEBSITE_ADD_CSS_TO_BODY)) {
373 $content = str_replace(
'<body id="bodywebsite" class="bodywebsite',
'<body id="bodywebsite" class="bodywebsite '.$conf->global->WEBSITE_ADD_CSS_TO_BODY, $content);
420 global $db, $website;
426 if ($containeraliasalt) {
427 include_once DOL_DOCUMENT_ROOT.
'/website/class/websitepage.class.php';
429 $result = $tmpwebsitepage->fetch(0, $website->id,
'', $containeraliasalt);
431 $containerref = $tmpwebsitepage->pageurl;
433 print
"Error, page contains a redirect to the alternative alias '".$containeraliasalt.
"' that does not exists in web site (".$website->id.
" / ".$website->ref.
")";
438 if (defined(
'USEDOLIBARREDITOR')) {
442 $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.";
443 setEventMessages($text,
null,
'warnings',
'WEBSITEREDIRECTDISABLED'.$containerref);
447 if (defined(
'USEDOLIBARRSERVER')) {
449 if (!$containeraliasalt) {
450 include_once DOL_DOCUMENT_ROOT.
'/website/class/websitepage.class.php';
452 $result = $tmpwebsitepage->fetch(0, $website->id, $containerref);
453 unset($tmpwebsitepage);
456 $currenturi = $_SERVER[
"REQUEST_URI"];
458 if (preg_match(
'/&pageref=([^&]+)/', $currenturi, $regtmp)) {
459 if ($regtmp[0] == $containerref) {
460 print
"Error, page with uri '.$currenturi.' try a redirect to the same alias page '".$containerref.
"' in web site '".$website->ref.
"'";
463 $newurl = preg_replace(
'/&pageref=([^&]+)/',
'&pageref='.$containerref, $currenturi);
466 $newurl = $currenturi.
'&pageref='.urlencode($containerref);
471 $newurl =
'/'.$containerref.
'.php';
476 header(
"Status: 301 Moved Permanently",
false, 301);
478 header(
"Location: ".$newurl.(empty($_SERVER[
"QUERY_STRING"]) ?
'' :
'?'.$_SERVER[
"QUERY_STRING"]));
481 print
"Error, page contains a redirect to the alias page '".$containerref.
"' that does not exists in web site (".$website->id.
" / ".$website->ref.
")";
496 global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs;
497 global $includehtmlcontentopened;
498 global $websitekey, $websitepagefile;
502 if (!preg_match(
'/\.php$/i', $containerref)) {
503 $containerref .=
'.php';
506 $fullpathfile = DOL_DATA_ROOT.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.$websitekey.
'/'.$containerref;
508 if (empty($includehtmlcontentopened)) {
509 $includehtmlcontentopened = 0;
511 $includehtmlcontentopened++;
512 if ($includehtmlcontentopened > $MAXLEVEL) {
513 print
'ERROR: RECURSIVE CONTENT LEVEL. Depth of recursive call is more than the limit of '.((int) $MAXLEVEL).
".\n";
524 $res = include $fullpathfile;
525 $tmpoutput = ob_get_contents();
528 print
"\n".
'<!-- include '.$websitekey.
'/'.$containerref.(is_object($websitepage) ?
' parent id='.$websitepage->id :
'').
' level = '.$includehtmlcontentopened.
' -->'.
"\n";
529 print preg_replace(array(
'/^.*<body[^>]*>/ims',
'/<\/body>.*$/ims'), array(
'',
''), $tmpoutput);
532 print
'ERROR: FAILED TO INCLUDE PAGE '.$containerref.
".\n";
535 $includehtmlcontentopened--;
550 global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs, $pagelangs;
552 $type = strtolower($type);
554 if ($type ==
'software') {
555 $ret =
'<!-- Add structured data for entry in a software annuary -->'.
"\n";
556 $ret .=
'<script type="application/ld+json">'.
"\n";
558 "@context": "https://schema.org",
559 "@type": "SoftwareApplication",
560 "name": "'.dol_escape_json($data[
'name']).
'",
562 "applicationCategory": "https://schema.org/'.
dol_escape_json($data[
'applicationCategory']).
'",';
563 if (!empty($data[
'ratingcount'])) {
566 "@type": "AggregateRating",
567 "ratingValue": "'.dol_escape_json($data[
'ratingvalue']).
'",
574 "price": "'.dol_escape_json($data[
'price']).
'",
575 "priceCurrency": "'.
dol_escape_json($data[
'currency'] ? $data[
'currency'] : $conf->currency).
'"
578 $ret .=
'</script>'.
"\n";
579 } elseif ($type ==
'organization') {
580 $companyname = $mysoc->name;
583 $ret =
'<!-- Add structured data for organization -->'.
"\n";
584 $ret .=
'<script type="application/ld+json">'.
"\n";
586 "@context": "https://schema.org",
587 "@type": "Organization",
588 "name": "'.dol_escape_json($data[
'name'] ? $data[
'name'] : $companyname).
'",
590 "logo": "'.($data[
'logo'] ?
dol_escape_json($data[
'logo']) :
'/wrapper.php?modulepart=mycompany&file=logos%2F'.urlencode($mysoc->logo)).
'",
592 "@type": "ContactPoint",
593 "contactType": "Contact",
594 "email": "'.
dol_escape_json($data[
'email'] ? $data[
'email'] : $mysoc->email).
'"
596 if (is_array($mysoc->socialnetworks) && count($mysoc->socialnetworks) > 0) {
598 $ret .=
'"sameAs": [';
600 foreach ($mysoc->socialnetworks as $key => $value) {
601 if ($key ==
'linkedin') {
602 $ret .=
'"https://www.'.$key.
'.com/company/'.
dol_escape_json($value).
'"';
603 } elseif ($key ==
'youtube') {
609 if ($i < count($mysoc->socialnetworks)) {
616 $ret .=
'</script>'.
"\n";
617 } elseif ($type ==
'blogpost') {
618 if (!empty($websitepage->author_alias)) {
623 $pageurl = $websitepage->pageurl;
624 $title = $websitepage->title;
625 $image = $websitepage->image;
626 $companyname = $mysoc->name;
627 $description = $websitepage->description;
629 $pageurl = str_replace(
'__WEBSITE_KEY__', $website->ref, $pageurl);
630 $title = str_replace(
'__WEBSITE_KEY__', $website->ref, $title);
631 $image =
'/medias'.(preg_match(
'/^\//', $image) ?
'' :
'/').str_replace(
'__WEBSITE_KEY__', $website->ref, $image);
632 $companyname = str_replace(
'__WEBSITE_KEY__', $website->ref, $companyname);
633 $description = str_replace(
'__WEBSITE_KEY__', $website->ref, $description);
635 $ret =
'<!-- Add structured data for blog post -->'.
"\n";
636 $ret .=
'<script type="application/ld+json">'.
"\n";
638 "@context": "https://schema.org",
639 "@type": "NewsArticle",
640 "mainEntityOfPage": {
642 "@id": "'.dol_escape_json($pageurl).
'"
648 "dateCreated": "'.
dol_print_date($websitepage->date_creation,
'dayhourrfc').
'",
649 "datePublished": "'.
dol_print_date($websitepage->date_creation,
'dayhourrfc').
'",
650 "dateModified": "'.
dol_print_date($websitepage->date_modification,
'dayhourrfc').
'",
656 "@type": "Organization",
659 "@type": "ImageObject",
660 "url": "/wrapper.php?modulepart=mycompany&file=logos%2F'.urlencode($mysoc->logo).
'"
663 if ($websitepage->keywords) {
664 $ret .=
'"keywords": [';
666 $arrayofkeywords = explode(
',', $websitepage->keywords);
667 foreach ($arrayofkeywords as $keyword) {
668 $ret .=
'"'.dol_escape_json($keyword).
'"';
670 if ($i < count($arrayofkeywords)) {
676 $ret .=
'"description": "'.dol_escape_json($description).
'"';
677 $ret .=
"\n".
'}'.
"\n";
678 $ret .=
'</script>'.
"\n";
680 $ret .=
'<!-- no structured data inserted inline inside blogpost because no author_alias defined -->'.
"\n";
682 } elseif ($type ==
'product') {
683 $ret =
'<!-- Add structured data for product -->'.
"\n";
684 $ret .=
'<script type="application/ld+json">'.
"\n";
686 "@context": "https://schema.org/",
688 "name": "'.dol_escape_json($data[
'label']).
'",
705 "url": "https://example.com/anvil",
706 "priceCurrency": "'.
dol_escape_json($data[
'currency'] ? $data[
'currency'] : $conf->currency).
'",
708 "itemCondition": "https://schema.org/UsedCondition",
709 "availability": "https://schema.org/InStock",
711 "@type": "Organization",
716 $ret .=
'</script>'.
"\n";
717 } elseif ($type ==
'qa') {
718 $ret =
'<!-- Add structured data for QA -->'.
"\n";
719 $ret .=
'<script type="application/ld+json">'.
"\n";
721 "@context": "https://schema.org/",
725 "name": "'.dol_escape_json($data[
'name']).
'",
742 $ret .=
'</script>'.
"\n";
755 global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs;
759 if ($website->virtualhost) {
760 $pageurl = $websitepage->pageurl;
761 $title = $websitepage->title;
762 $image = $websitepage->image;
763 $companyname = $mysoc->name;
764 $description = $websitepage->description;
766 $pageurl = str_replace(
'__WEBSITE_KEY__', $website->ref, $pageurl);
767 $title = str_replace(
'__WEBSITE_KEY__', $website->ref, $title);
768 $image =
'/medias'.(preg_match(
'/^\//', $image) ?
'' :
'/').str_replace(
'__WEBSITE_KEY__', $website->ref, $image);
769 $companyname = str_replace(
'__WEBSITE_KEY__', $website->ref, $companyname);
770 $description = str_replace(
'__WEBSITE_KEY__', $website->ref, $description);
773 if ($websitepage->lang) {
774 $shortlangcode = substr($websitepage->lang, 0, 2);
776 if (empty($shortlangcode)) {
777 $shortlangcode = substr($website->lang, 0, 2);
780 $fullurl = $website->virtualhost.
'/'.$websitepage->pageurl.
'.php';
781 $canonicalurl = $website->virtualhost.(($websitepage->id == $website->fk_default_home) ?
'/' : (($shortlangcode != substr($website->lang, 0, 2) ?
'/'.$shortlangcode :
'').
'/'.$websitepage->pageurl.
'.php'));
782 $hashtags = trim(join(
' #', array_map(
'trim', explode(
',', $websitepage->keywords))));
785 $out .=
'<meta name="og:type" content="website">'.
"\n";
786 $out .=
'<meta name="og:title" content="'.$websitepage->title.
'">'.
"\n";
787 if ($websitepage->image) {
788 $out .=
'<meta name="og:image" content="'.$website->virtualhost.$image.
'">'.
"\n";
790 $out .=
'<meta name="og:url" content="'.$canonicalurl.
'">'.
"\n";
793 $out .=
'<meta name="twitter:card" content="summary">'.
"\n";
794 if (!empty($params) && !empty($params[
'twitter_account'])) {
795 $out .=
'<meta name="twitter:site" content="@'.$params[
'twitter_account'].
'">'.
"\n";
796 $out .=
'<meta name="twitter:creator" content="@'.$params[
'twitter_account'].
'">'.
"\n";
798 $out .=
'<meta name="twitter:title" content="'.$websitepage->title.
'">'.
"\n";
799 if ($websitepage->description) {
800 $out .=
'<meta name="twitter:description" content="'.$websitepage->description.
'">'.
"\n";
802 if ($websitepage->image) {
803 $out .=
'<meta name="twitter:image" content="'.$website->virtualhost.$image.
'">'.
"\n";
829 global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs;
831 $out =
'<!-- section for social network sharing of page -->'.
"\n";
833 if ($website->virtualhost) {
834 $fullurl = $website->virtualhost.
'/'.$websitepage->pageurl.
'.php';
835 $hashtags = trim(join(
' #', array_map(
'trim', explode(
',', $websitepage->keywords))));
837 $out .=
'<div class="dol-social-share">'.
"\n";
840 $out .=
'<div class="dol-social-share-tw">'.
"\n";
841 $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>';
842 $out .=
'<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?\'http\':\'https\';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+\'://platform.twitter.com/widgets.js\';fjs.parentNode.insertBefore(js,fjs);}}(document, \'script\', \'twitter-wjs\');</script>';
843 $out .=
'</div>'.
"\n";
846 $out .=
'<div class="dol-social-share-reddit">'.
"\n";
847 $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">';
848 $out .= '<span class="dol-social-share-reddit-span
">Reddit</span>';
850 $out .= '</div>'."\n
";
853 $out .= '<div class="dol-social-share-fbl
">'."\n
";
854 $out .= '<div id="fb-root
"></div>'."\n
";
855 $out .= '<script>(function(d, s, id) {
856 var js, fjs = d.getElementsByTagName(s)[0];
857 if (d.getElementById(id)) return;
858 js = d.createElement(s); js.id = id;
860 fjs.parentNode.insertBefore(js, fjs);
861 }(document, \
'script\', \'facebook-jssdk\'));</script>
864 layout="button_count"
869 action="like" ></fb:like>'.
"\n";
870 $out .=
'</div>'.
"\n";
872 $out .=
"\n</div>\n";
874 $out .=
'<!-- virtual host not defined in CMS. No way to add sharing buttons -->'.
"\n";
876 $out .=
'<!-- section end for social network sharing of page -->'.
"\n";
896 function getPagesFromSearchCriterias($type, $algo, $searchstring, $max = 25, $sortfield =
'date_creation', $sortorder =
'DESC', $langcode =
'', $otherfilters =
'null', $status = 1)
898 global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs;
901 $arrayresult = array(
'code'=>
'',
'list'=>array());
903 if (!is_object($weblangs)) {
907 if (empty($searchstring) && empty($type) && empty($langcode) && empty($otherfilters)) {
909 $arrayresult[
'code'] =
'KO';
910 $arrayresult[
'message'] = $weblangs->trans(
"EmptySearchString");
911 } elseif ($searchstring &&
dol_strlen($searchstring) < 2) {
912 $weblangs->load(
"errors");
914 $arrayresult[
'code'] =
'KO';
915 $arrayresult[
'message'] = $weblangs->trans(
"ErrorSearchCriteriaTooSmall");
917 $tmparrayoftype = explode(
',', $type);
931 if (!$error && (empty($max) || ($found < $max)) && (preg_match(
'/meta/', $algo) || preg_match(
'/content/', $algo))) {
932 include_once DOL_DOCUMENT_ROOT.
'/website/class/websitepage.class.php';
934 $sql =
'SELECT wp.rowid FROM '.MAIN_DB_PREFIX.
'website_page as wp';
935 if (is_array($otherfilters) && !empty($otherfilters[
'category'])) {
936 $sql .=
', '.MAIN_DB_PREFIX.
'categorie_website_page as cwp';
938 $sql .=
" WHERE wp.fk_website = ".((int) $website->id);
940 $sql .=
" AND wp.status = ".((int) $status);
943 $sql .=
" AND wp.lang = '".$db->escape($langcode).
"'";
946 $tmparrayoftype = explode(
',', $type);
948 foreach ($tmparrayoftype as $tmptype) {
949 $typestring .= ($typestring ?
", " :
"").
"'".$db->escape(trim($tmptype)).
"'";
951 $sql .=
" AND wp.type_container IN (".$db->sanitize($typestring, 1).
")";
955 if (preg_match(
'/meta/', $algo)) {
956 $searchalgo .= ($searchalgo ?
' OR ' :
'').
"wp.title LIKE '%".$db->escape($db->escapeforlike($searchstring)).
"%' OR wp.description LIKE '%".$db->escape($db->escapeforlike($searchstring)).
"%'";
957 $searchalgo .= ($searchalgo ?
' OR ' :
'').
"wp.keywords LIKE '".$db->escape($db->escapeforlike($searchstring)).
",%' OR wp.keywords LIKE '% ".$db->escape($db->escapeforlike($searchstring)).
"%'";
959 if (preg_match(
'/content/', $algo)) {
960 $searchalgo .= ($searchalgo ?
' OR ' :
'').
"wp.content LIKE '%".$db->escape($db->escapeforlike($searchstring)).
"%'";
963 if (is_array($otherfilters) && !empty($otherfilters[
'category'])) {
964 $sql .=
' AND cwp.fk_website_page = wp.rowid AND cwp.fk_categorie = '.((int) $otherfilters[
'category']);
967 $sql .= $db->order($sortfield, $sortorder);
968 $sql .= $db->plimit($max);
971 $resql = $db->query($sql);
975 while (($obj = $db->fetch_object(
$resql)) && ($i < $max || $max == 0)) {
976 if ($obj->rowid > 0) {
978 $tmpwebsitepage->fetch($obj->rowid);
979 if ($tmpwebsitepage->id > 0) {
980 $arrayresult[
'list'][$obj->rowid] = $tmpwebsitepage;
988 $arrayresult[
'code'] = $db->lasterrno();
989 $arrayresult[
'message'] = $db->lasterror();
995 if (!$error && (empty($max) || ($found < $max)) && (preg_match(
'/sitefiles/', $algo))) {
996 global $dolibarr_main_data_root;
998 $pathofwebsite = $dolibarr_main_data_root.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.$website->ref;
999 $filehtmlheader = $pathofwebsite.
'/htmlheader.html';
1000 $filecss = $pathofwebsite.
'/styles.css.php';
1001 $filejs = $pathofwebsite.
'/javascript.js.php';
1002 $filerobot = $pathofwebsite.
'/robots.txt';
1003 $filehtaccess = $pathofwebsite.
'/.htaccess';
1004 $filemanifestjson = $pathofwebsite.
'/manifest.json.php';
1005 $filereadme = $pathofwebsite.
'/README.md';
1007 $filecontent = file_get_contents($filehtmlheader);
1008 if ((empty($max) || ($found < $max)) && preg_match(
'/'.preg_quote($searchstring,
'/').
'/', $filecontent)) {
1009 $arrayresult[
'list'][] = array(
'type'=>
'website_htmlheadercontent');
1012 $filecontent = file_get_contents($filecss);
1013 if ((empty($max) || ($found < $max)) && preg_match(
'/'.preg_quote($searchstring,
'/').
'/', $filecontent)) {
1014 $arrayresult[
'list'][] = array(
'type'=>
'website_csscontent');
1017 $filecontent = file_get_contents($filejs);
1018 if ((empty($max) || ($found < $max)) && preg_match(
'/'.preg_quote($searchstring,
'/').
'/', $filecontent)) {
1019 $arrayresult[
'list'][] = array(
'type'=>
'website_jscontent');
1022 $filerobot = file_get_contents($filerobot);
1023 if ((empty($max) || ($found < $max)) && preg_match(
'/'.preg_quote($searchstring,
'/').
'/', $filecontent)) {
1024 $arrayresult[
'list'][] = array(
'type'=>
'website_robotcontent');
1032 $arrayresult[
'code'] =
'OK';
1033 if (empty($arrayresult[
'list'])) {
1034 $arrayresult[
'code'] =
'KO';
1035 $arrayresult[
'message'] = $weblangs->trans(
"NoRecordFound");
1039 $arrayresult[
'code'] =
'KO';
1040 $arrayresult[
'message'] =
'No supported algorithm found';
1044 return $arrayresult;
1061 function getAllImages($object, $objectpage, $urltograb, &$tmp, &$action, $modifylinks = 0, $grabimages = 1, $grabimagesinto =
'subpage')
1067 dol_syslog(
"Call getAllImages with grabimagesinto=".$grabimagesinto);
1069 $alreadygrabbed = array();
1071 if (preg_match(
'/\/$/', $urltograb)) {
1074 $urltograb = dirname($urltograb);
1078 preg_match_all(
'/<img([^\.\/]+)src="([^>"]+)"([^>]*)>/i', $tmp, $regs);
1080 foreach ($regs[0] as $key => $val) {
1081 if (preg_match(
'/^data:image/i', $regs[2][$key])) {
1085 if (preg_match(
'/^\//', $regs[2][$key])) {
1087 $urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key];
1089 $urltograbbis = $urltograb.
'/'.$regs[2][$key];
1092 $linkwithoutdomain = $regs[2][$key];
1093 $dirforimages =
'/'.$objectpage->pageurl;
1094 if ($grabimagesinto ==
'root') {
1099 $filetosave = $conf->medias->multidir_output[$conf->entity].
'/image/'.$object->ref.$dirforimages.(preg_match(
'/^\//', $regs[2][$key]) ?
'' :
'/').$regs[2][$key];
1100 if (preg_match(
'/^http/', $regs[2][$key])) {
1101 $urltograbbis = $regs[2][$key];
1102 $linkwithoutdomain = preg_replace(
'/^https?:\/\/[^\/]+\//i',
'', $regs[2][$key]);
1103 $filetosave = $conf->medias->multidir_output[$conf->entity].
'/image/'.$object->ref.$dirforimages.(preg_match(
'/^\//', $linkwithoutdomain) ?
'' :
'/').$linkwithoutdomain;
1105 $filename =
'image/'.$object->ref.$dirforimages.(preg_match(
'/^\//', $linkwithoutdomain) ?
'' :
'/').$linkwithoutdomain;
1108 $filetosave = preg_replace(
'/\/[^\/]+\/\.\./',
'', $filetosave);
1109 $filename = preg_replace(
'/\/[^\/]+\/\.\./',
'', $filename);
1115 if (empty($alreadygrabbed[$urltograbbis])) {
1117 $tmpgeturl =
getURLContent($urltograbbis,
'GET',
'', 1, array(), array(
'http',
'https'), 0);
1118 if ($tmpgeturl[
'curl_error_no']) {
1120 setEventMessages(
'Error getting '.$urltograbbis.
': '.$tmpgeturl[
'curl_error_msg'],
null,
'errors');
1122 } elseif ($tmpgeturl[
'http_code'] !=
'200') {
1124 setEventMessages(
'Error getting '.$urltograbbis.
': '.$tmpgeturl[
'http_code'],
null,
'errors');
1127 $alreadygrabbed[$urltograbbis] = 1;
1131 $fp = fopen($filetosave,
"w");
1132 fputs($fp, $tmpgeturl[
'content']);
1134 if (!empty($conf->global->MAIN_UMASK)) {
1135 @chmod($filetosave, octdec($conf->global->MAIN_UMASK));
1142 $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);
1147 preg_match_all(
'/background([^\.\/\(;]+)url\([\"\']?([^\)\"\']*)[\"\']?\)/i', $tmp, $regs);
1149 foreach ($regs[0] as $key => $val) {
1150 if (preg_match(
'/^data:image/i', $regs[2][$key])) {
1154 if (preg_match(
'/^\//', $regs[2][$key])) {
1156 $urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key];
1158 $urltograbbis = $urltograb.
'/'.$regs[2][$key];
1161 $linkwithoutdomain = $regs[2][$key];
1163 $dirforimages =
'/'.$objectpage->pageurl;
1164 if ($grabimagesinto ==
'root') {
1168 $filetosave = $conf->medias->multidir_output[$conf->entity].
'/image/'.$object->ref.$dirforimages.(preg_match(
'/^\//', $regs[2][$key]) ?
'' :
'/').$regs[2][$key];
1170 if (preg_match(
'/^http/', $regs[2][$key])) {
1171 $urltograbbis = $regs[2][$key];
1172 $linkwithoutdomain = preg_replace(
'/^https?:\/\/[^\/]+\//i',
'', $regs[2][$key]);
1173 $filetosave = $conf->medias->multidir_output[$conf->entity].
'/image/'.$object->ref.$dirforimages.(preg_match(
'/^\//', $linkwithoutdomain) ?
'' :
'/').$linkwithoutdomain;
1176 $filename =
'image/'.$object->ref.$dirforimages.(preg_match(
'/^\//', $linkwithoutdomain) ?
'' :
'/').$linkwithoutdomain;
1179 $filetosave = preg_replace(
'/\/[^\/]+\/\.\./',
'', $filetosave);
1180 $filename = preg_replace(
'/\/[^\/]+\/\.\./',
'', $filename);
1186 if (empty($alreadygrabbed[$urltograbbis])) {
1188 $tmpgeturl =
getURLContent($urltograbbis,
'GET',
'', 1, array(), array(
'http',
'https'), 0);
1189 if ($tmpgeturl[
'curl_error_no']) {
1191 setEventMessages(
'Error getting '.$urltograbbis.
': '.$tmpgeturl[
'curl_error_msg'],
null,
'errors');
1193 } elseif ($tmpgeturl[
'http_code'] !=
'200') {
1195 setEventMessages(
'Error getting '.$urltograbbis.
': '.$tmpgeturl[
'http_code'],
null,
'errors');
1198 $alreadygrabbed[$urltograbbis] = 1;
1202 $fp = fopen($filetosave,
"w");
1203 fputs($fp, $tmpgeturl[
'content']);
1205 if (!empty($conf->global->MAIN_UMASK)) {
1206 @chmod($filetosave, octdec($conf->global->MAIN_UMASK));
1213 $tmp = preg_replace(
'/'.preg_quote($regs[0][$key],
'/').
'/i',
'background'.$regs[1][$key].
'url("'.DOL_URL_ROOT.
'/viewimage.php?modulepart=medias&file='.$filename.
'")', $tmp);