From 277a693c1667d14ebe7f5ef65afa0583f754c08d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Aug 2019 06:37:06 +0200 Subject: [PATCH] FIX Add log and type of content in dolWebsiteOutput and dolWebsiteReplacementOfLinks --- htdocs/core/lib/website.lib.php | 20 ++++++++++++++------ htdocs/core/website.inc.php | 1 + htdocs/website/index.php | 8 ++++---- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/htdocs/core/lib/website.lib.php b/htdocs/core/lib/website.lib.php index 405a0687eae..c1070ce325c 100644 --- a/htdocs/core/lib/website.lib.php +++ b/htdocs/core/lib/website.lib.php @@ -36,6 +36,8 @@ function dolWebsiteReplacementOfLinks($website, $content, $removephppart = 0) { $nbrep = 0; + dol_syslog('dolWebsiteReplacementOfLinks start', LOG_DEBUG); + // Replace php code. Note $content may come from database and does not contains body tags. $replacewith='...php...'; if ($removephppart) $replacewith=''; @@ -90,6 +92,8 @@ function dolWebsiteReplacementOfLinks($website, $content, $removephppart = 0) $content=preg_replace('/(href=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep); $content=preg_replace('/(src=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep); + dol_syslog('dolWebsiteReplacementOfLinks end', LOG_DEBUG); + return $content; } @@ -176,16 +180,17 @@ function dolKeepOnlyPhpCode($str) * Render a string of an HTML content and output it. * Used to ouput the page when viewed from server (Dolibarr or Apache). * - * @param string $content Content string + * @param string $content Content string + * @param string $contenttype Content type * @return void * @see dolWebsiteReplacementOfLinks() for function used to replace content in the backoffice context when USEDOLIBARREDITOR is not on */ -function dolWebsiteOutput($content) +function dolWebsiteOutput($content, $contenttype='html') { global $db, $langs, $conf, $user; global $dolibarr_main_url_root, $dolibarr_main_data_root; - dol_syslog("dolWebsiteOutput start (USEDOLIBARRSERVER=".(defined('USEDOLIBARRSERVER')?'1':'')." USEDOLIBARREDITOR=".(defined('USEDOLIBARREDITOR')?'1':'').')'); + dol_syslog("dolWebsiteOutput start (contenttype=".$contenttype." USEDOLIBARRSERVER=".(defined('USEDOLIBARRSERVER')?'1':'')." USEDOLIBARREDITOR=".(defined('USEDOLIBARREDITOR')?'1':'').')'); // Define $urlwithroot $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); @@ -195,9 +200,12 @@ function dolWebsiteOutput($content) if (defined('USEDOLIBARREDITOR')) // REPLACEMENT OF LINKS When page called from Dolibarr editor { // We remove the part of content - $content = preg_replace('/.*<\/head>/ims', '', $content); - $content = preg_replace('/^.*]*)*>/ims', '', $content); - $content = preg_replace('/<\/body(\s[^>]*)*>.*$/ims', '', $content); + if ($contenttype == 'html') + { + $content = preg_replace('/.*<\/head>/ims', '', $content); + $content = preg_replace('/^.*]*)*>/ims', '', $content); + $content = preg_replace('/<\/body(\s[^>]*)*>.*$/ims', '', $content); + } } elseif (defined('USEDOLIBARRSERVER')) // REPLACEMENT OF LINKS When page called from Dolibarr server { diff --git a/htdocs/core/website.inc.php b/htdocs/core/website.inc.php index 44c5d89097a..cf9b76a7be1 100644 --- a/htdocs/core/website.inc.php +++ b/htdocs/core/website.inc.php @@ -98,6 +98,7 @@ if ($_SERVER['PHP_SELF'] != DOL_URL_ROOT.'/website/index.php') // If we browsing if (! defined('USEDOLIBARREDITOR') && empty($website->status)) { $weblangs->load("website"); + http_response_code(503); print '


'.$weblangs->trans("SorryWebsiteIsCurrentlyOffLine").'
'; exit; } diff --git a/htdocs/website/index.php b/htdocs/website/index.php index 9017e7b4464..7caf5a8aac4 100644 --- a/htdocs/website/index.php +++ b/htdocs/website/index.php @@ -1031,7 +1031,7 @@ if ($action == 'updatecss') $csscontent.= GETPOST('WEBSITE_CSS_INLINE', 'none'); $csscontent.= "\n".'"."\n"; dol_syslog("Save css content into ".$filecss); @@ -1064,7 +1064,7 @@ if ($action == 'updatecss') $jscontent.= GETPOST('WEBSITE_JS_INLINE', 'none'); $jscontent.= "\n".'"."\n"; dol_syslog("Save js content into ".$filejs); @@ -1097,7 +1097,7 @@ if ($action == 'updatecss') $robotcontent.= GETPOST('WEBSITE_ROBOT', 'none'); /*$robotcontent.= "\n".'"."\n";*/ dol_syslog("Save file robot into ".$filerobot); @@ -1147,7 +1147,7 @@ if ($action == 'updatecss') $manifestjsoncontent.= GETPOST('WEBSITE_MANIFEST_JSON', 'none'); $manifestjsoncontent.= "\n".'"."\n"; dol_syslog("Save file manifest.json.php into ".$manifestjsoncontent);