diff --git a/htdocs/core/lib/website.lib.php b/htdocs/core/lib/website.lib.php index 354da07c6f2..a60be612e2d 100644 --- a/htdocs/core/lib/website.lib.php +++ b/htdocs/core/lib/website.lib.php @@ -33,14 +33,16 @@ function dolWebsiteOutput($content) global $db, $langs, $conf, $user; global $dolibarr_main_url_root, $dolibarr_main_data_root; - dol_syslog("dolWebsiteOutput start"); + dol_syslog("dolWebsiteOutput start (mode=".(defined('USEDOLIBARRSERVER')?'USEDOLIBARRSERVER':'').')'); // Define $urlwithroot $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current - if (! defined('USEDOLIBARRSERVER')) + // Note: This seems never called when page is output inside the website editor (search 'REPLACEMENT OF LINKS When page called by website editor') + + if (! defined('USEDOLIBARRSERVER')) // REPLACEMENT OF LINKS When page called from virtual host { $symlinktomediaexists=1; @@ -52,6 +54,7 @@ function dolWebsiteOutput($content) if (! $symlinktomediaexists) { $content=preg_replace('/()/', '\1'.$urlwithroot.'/viewimage.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep); + $content=preg_replace('/(url\(["\']?)[^\)]*viewimage\.php([^\)]*)modulepart=medias([^\)]*)file=([^\)]*)(["\']?\))/', '\1'.$urlwithroot.'/viewimage.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep); } else { @@ -59,14 +62,22 @@ function dolWebsiteOutput($content) $content=preg_replace('/(url\(["\']?)[^\)]*viewimage\.php([^\)]*)modulepart=medias([^\)]*)file=([^\)]*)(["\']?\))/', '\1medias/\4\5', $content, -1, $nbrep); } } - else + else // REPLACEMENT OF LINKS When page called from dolibarr server { global $website; - // Replace relative link / with dolibarr URL + // Replace relative link / with dolibarr URL: ...href="/"... $content=preg_replace('/(href=")\/\"/', '\1'.DOL_URL_ROOT.'/public/websites/index.php?website='.$website->ref.'&pageid='.$website->fk_default_home.'"', $content, -1, $nbrep); - // Replace relative link /xxx.php with dolibarr URL + // Replace relative link /xxx.php with dolibarr URL: ...href="....php" $content=preg_replace('/(href=")\/?([^\"]*)(\.php\")/', '\1'.DOL_URL_ROOT.'/public/websites/index.php?website='.$website->ref.'&pageref=\2"', $content, -1, $nbrep); + + // Fix relative link /document.php with correct URL after the DOL_URL_ROOT: ...href="/document.php?modulepart=" + $content=preg_replace('/(href=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3"', $content, -1, $nbrep); + // Fix relative link /viewimage.php with correct URL after the DOL_URL_ROOT: ...href="/viewimage.php?modulepart=" + $content=preg_replace('/(href=")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3"', $content, -1, $nbrep); + + // Fix relative link into medias with correct URL after the DOL_URL_ROOT: ../url("medias/ + $content=preg_replace('/url\((["\']?)medias\//', 'url(\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); } dol_syslog("dolWebsiteOutput end"); diff --git a/htdocs/langs/en_US/website.lang b/htdocs/langs/en_US/website.lang index 3e2d99d1503..9e0ded40602 100644 --- a/htdocs/langs/en_US/website.lang +++ b/htdocs/langs/en_US/website.lang @@ -33,13 +33,14 @@ PreviewSiteServedByWebServer=Preview %s in a new tab.

The %s will be serv PreviewSiteServedByDolibarr=Preview %s in a new tab.

The %s will be served by Dolibarr server so it does not need any extra web server (like Apache, Nginx, IIS) to be installed.
The inconvenient is that URL of pages are not user friendly and start with path of your Dolibarr.
URL served by Dolibarr:
%s

To use your own external web server to serve this web site, create a virtual host on your web server that point on directory
%s
then enter the name of this virtual server and click on the other preview button. VirtualHostUrlNotDefined=URL of the virtual host served by external web server not defined NoPageYet=No pages yet -SyntaxHelp=Help on code syntax +SyntaxHelp=Help on specific syntax tips YouCanEditHtmlSourceckeditor=You can edit HTML source code using the "Source" button in editor. -YouCanEditHtmlSource=You can include PHP code into this source using tags <?php ?>. The following global variables are available: $conf, $langs, $db, $mysoc, $user, $website.

You can also include content of another Page/Container with the following syntax: <?php dolIncludeHtmlContent($websitekey.'/contentaliastoinclude.php'); ?>

To include a link to download a file stored into the documents/medias directory, use syntax:
<a href="/document.php?modulepart=medias&file=filename.ext">. +YouCanEditHtmlSource=You can include PHP code into this source using tags <?php ?>. The following global variables are available: $conf, $langs, $db, $mysoc, $user, $website.

You can also include content of another Page/Container with the following syntax: <?php dolIncludeHtmlContent($websitekey.'/contentaliastoinclude.php'); ?>

To include a link to download a file stored into the documents directory, use the document.php wrapper:
Example, for a file into documents/ecm (need to be logged), syntax is:
<a href="/document.php?modulepart=ecm&file=reldir/filename.ext">.
for a file into documents/media (open access), syntax is:
<a href="/document.php?modulepart=medias&file=reldir/filename.ext">.

To include an image stored into the documents directory, use the viewimage.php wrapper:
Example, for an image into documents/media (open access), syntax is:
<a href="/viewimage.php?modulepart=medias&file=filename.ext">. ClonePage=Clone page/container CloneSite=Clone site ConfirmClonePage=Please enter code/alias of new page and if it is a translation of the cloned page. PageIsANewTranslation=The new page is a translation of the current page ? LanguageMustNotBeSameThanClonedPage=You clone a page as a translation. The language of the new page must be different than language of source page. ParentPageId=Parent page ID -WebsiteId=Website ID \ No newline at end of file +WebsiteId=Website ID + diff --git a/htdocs/public/websites/index.php b/htdocs/public/websites/index.php index 84e0a72f9fd..81b5f985186 100644 --- a/htdocs/public/websites/index.php +++ b/htdocs/public/websites/index.php @@ -190,7 +190,7 @@ if (! file_exists($original_file_osencoded)) // Output page content define('USEDOLIBARRSERVER', 1); -print ''."\n"; +print ''."\n"; include_once $original_file_osencoded; diff --git a/htdocs/public/websites/styles.css.php b/htdocs/public/websites/styles.css.php index 14014577cea..7fe80f9b66e 100644 --- a/htdocs/public/websites/styles.css.php +++ b/htdocs/public/websites/styles.css.php @@ -139,6 +139,8 @@ if (! file_exists($original_file_osencoded)) // Output page content +define('USEDOLIBARRSERVER', 1); +print '/* Page content '.$original_file.' : CSS content that was saved into tpl dir */'."\n"; require_once $original_file_osencoded; diff --git a/htdocs/websites/index.php b/htdocs/websites/index.php index 712a5a2dabb..3c64c0f287d 100644 --- a/htdocs/websites/index.php +++ b/htdocs/websites/index.php @@ -1304,31 +1304,24 @@ if ($action == 'preview' || $action == 'createpagefromclone') { // Ouput page under the Dolibarr top menu $objectpage->fetch($pageid); + $csscontent = @file_get_contents($filecss); $out = ''."\n"; $out.='
'."\n"; - $csscontent = @file_get_contents($filecss); + // REPLACEMENT OF LINKS When page called by website editor $out.=''."\n"; $out.='
'."\n"; - // Replace php code. Note $objectpage->content come from database and does not contains body tags. - $content = preg_replace('/<\?php[^\?]+\?>\n*/ims', '...php...', $objectpage->content); - - // Replace relative link / with dolibarr URL - $content = preg_replace('/(href=")\/\"/', '\1'.DOL_URL_ROOT.'/websites/index.php?website='.$object->ref.'&pageid='.$object->fk_default_home.'"', $content, -1, $nbrep); - // Replace relative link /xxx.php with dolibarr URL - $content = preg_replace('/(href=")\/?([^\"]*)(\.php\")/', '\1'.DOL_URL_ROOT.'/websites/index.php?website='.$object->ref.'&pageref=\2"', $content, -1, $nbrep); - - - $out.=$content."\n"; + $out.=dolWebsiteReplacementOfLinks($objectpage->content)."\n"; $out.='
'; + $out.='
'; $out.= "\n".''."\n\n"; @@ -1371,6 +1364,26 @@ $db->close(); +/** + * Save content of a page on disk + * + * @param string $content Content to replace + * @return boolean True if OK + */ +function dolWebsiteReplacementOfLinks($content) +{ + // Replace php code. Note $objectpage->content come from database and does not contains body tags. + $content = preg_replace('/<\?php[^\?]+\?>\n*/ims', '...php...', $content); + + // Replace relative link / with dolibarr URL + $content = preg_replace('/(href=")\/\"/', '\1'.DOL_URL_ROOT.'/websites/index.php?website='.$object->ref.'&pageid='.$object->fk_default_home.'"', $content, -1, $nbrep); + // Replace relative link /xxx.php with dolibarr URL + $content = preg_replace('/(href=")\/?([^\"]*)(\.php\")/', '\1'.DOL_URL_ROOT.'/websites/index.php?website='.$object->ref.'&pageref=\2"', $content, -1, $nbrep); + + $content = preg_replace('/url\((["\']?)medias\//', 'url(\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); + + return $content; +} /** * Save content of a page on disk @@ -1389,7 +1402,6 @@ function dolSavePageContent($filetpl, $object, $objectpage) dol_delete_file($filetpl); - // TODO Same code than into updatemeta $shortlangcode = ''; if ($objectpage->lang) $shortlangcode=preg_replace('/[_-].*$/', '', $objectpage->lang); // en_US or en-US -> en @@ -1433,4 +1445,4 @@ function dolSavePageContent($filetpl, $object, $objectpage) @chmod($filetpl, octdec($conf->global->MAIN_UMASK)); return $result; -} \ No newline at end of file +}