FIX Add log and type of content in dolWebsiteOutput and

dolWebsiteReplacementOfLinks
This commit is contained in:
Laurent Destailleur 2019-08-13 06:37:06 +02:00
parent 172271c98a
commit 277a693c16
3 changed files with 19 additions and 10 deletions

View File

@ -36,6 +36,8 @@ function dolWebsiteReplacementOfLinks($website, $content, $removephppart = 0)
{ {
$nbrep = 0; $nbrep = 0;
dol_syslog('dolWebsiteReplacementOfLinks start', LOG_DEBUG);
// Replace php code. Note $content may come from database and does not contains body tags. // Replace php code. Note $content may come from database and does not contains body tags.
$replacewith='...php...'; $replacewith='...php...';
if ($removephppart) $replacewith=''; 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('/(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); $content=preg_replace('/(src=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
dol_syslog('dolWebsiteReplacementOfLinks end', LOG_DEBUG);
return $content; return $content;
} }
@ -177,15 +181,16 @@ function dolKeepOnlyPhpCode($str)
* Used to ouput the page when viewed from server (Dolibarr or Apache). * 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 * @return void
* @see dolWebsiteReplacementOfLinks() for function used to replace content in the backoffice context when USEDOLIBARREDITOR is not on * @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 $db, $langs, $conf, $user;
global $dolibarr_main_url_root, $dolibarr_main_data_root; 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 // Define $urlwithroot
$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
@ -195,10 +200,13 @@ function dolWebsiteOutput($content)
if (defined('USEDOLIBARREDITOR')) // REPLACEMENT OF LINKS When page called from Dolibarr editor if (defined('USEDOLIBARREDITOR')) // REPLACEMENT OF LINKS When page called from Dolibarr editor
{ {
// We remove the <head> part of content // We remove the <head> part of content
if ($contenttype == 'html')
{
$content = preg_replace('/<head>.*<\/head>/ims', '', $content); $content = preg_replace('/<head>.*<\/head>/ims', '', $content);
$content = preg_replace('/^.*<body(\s[^>]*)*>/ims', '', $content); $content = preg_replace('/^.*<body(\s[^>]*)*>/ims', '', $content);
$content = preg_replace('/<\/body(\s[^>]*)*>.*$/ims', '', $content); $content = preg_replace('/<\/body(\s[^>]*)*>.*$/ims', '', $content);
} }
}
elseif (defined('USEDOLIBARRSERVER')) // REPLACEMENT OF LINKS When page called from Dolibarr server elseif (defined('USEDOLIBARRSERVER')) // REPLACEMENT OF LINKS When page called from Dolibarr server
{ {
global $website; global $website;

View File

@ -98,6 +98,7 @@ if ($_SERVER['PHP_SELF'] != DOL_URL_ROOT.'/website/index.php') // If we browsing
if (! defined('USEDOLIBARREDITOR') && empty($website->status)) if (! defined('USEDOLIBARREDITOR') && empty($website->status))
{ {
$weblangs->load("website"); $weblangs->load("website");
http_response_code(503);
print '<center><br><br>'.$weblangs->trans("SorryWebsiteIsCurrentlyOffLine").'</center>'; print '<center><br><br>'.$weblangs->trans("SorryWebsiteIsCurrentlyOffLine").'</center>';
exit; exit;
} }

View File

@ -1031,7 +1031,7 @@ if ($action == 'updatecss')
$csscontent.= GETPOST('WEBSITE_CSS_INLINE', 'none'); $csscontent.= GETPOST('WEBSITE_CSS_INLINE', 'none');
$csscontent.= "\n".'<?php // BEGIN PHP'."\n"; $csscontent.= "\n".'<?php // BEGIN PHP'."\n";
$csscontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp);'."\n"; $csscontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "css");'."\n";
$csscontent.= "// END PHP ?>"."\n"; $csscontent.= "// END PHP ?>"."\n";
dol_syslog("Save css content into ".$filecss); dol_syslog("Save css content into ".$filecss);
@ -1064,7 +1064,7 @@ if ($action == 'updatecss')
$jscontent.= GETPOST('WEBSITE_JS_INLINE', 'none'); $jscontent.= GETPOST('WEBSITE_JS_INLINE', 'none');
$jscontent.= "\n".'<?php // BEGIN PHP'."\n"; $jscontent.= "\n".'<?php // BEGIN PHP'."\n";
$jscontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp);'."\n"; $jscontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "js");'."\n";
$jscontent.= "// END PHP ?>"."\n"; $jscontent.= "// END PHP ?>"."\n";
dol_syslog("Save js content into ".$filejs); dol_syslog("Save js content into ".$filejs);
@ -1097,7 +1097,7 @@ if ($action == 'updatecss')
$robotcontent.= GETPOST('WEBSITE_ROBOT', 'none'); $robotcontent.= GETPOST('WEBSITE_ROBOT', 'none');
/*$robotcontent.= "\n".'<?php // BEGIN PHP'."\n"; /*$robotcontent.= "\n".'<?php // BEGIN PHP'."\n";
$robotcontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp);'."\n"; $robotcontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "robot");'."\n";
$robotcontent.= "// END PHP ?>"."\n";*/ $robotcontent.= "// END PHP ?>"."\n";*/
dol_syslog("Save file robot into ".$filerobot); dol_syslog("Save file robot into ".$filerobot);
@ -1147,7 +1147,7 @@ if ($action == 'updatecss')
$manifestjsoncontent.= GETPOST('WEBSITE_MANIFEST_JSON', 'none'); $manifestjsoncontent.= GETPOST('WEBSITE_MANIFEST_JSON', 'none');
$manifestjsoncontent.= "\n".'<?php // BEGIN PHP'."\n"; $manifestjsoncontent.= "\n".'<?php // BEGIN PHP'."\n";
$manifestjsoncontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp);'."\n"; $manifestjsoncontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "manifest");'."\n";
$manifestjsoncontent.= "// END PHP ?>"."\n"; $manifestjsoncontent.= "// END PHP ?>"."\n";
dol_syslog("Save file manifest.json.php into ".$manifestjsoncontent); dol_syslog("Save file manifest.json.php into ".$manifestjsoncontent);