Enhance image replacement
This commit is contained in:
parent
8bba9fa149
commit
b0e62f9d24
@ -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('/(<img.*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^\/]*\/>)/', '\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");
|
||||
|
||||
@ -33,13 +33,14 @@ PreviewSiteServedByWebServer=Preview %s in a new tab.<br><br>The %s will be serv
|
||||
PreviewSiteServedByDolibarr=Preview %s in a new tab.<br><br>The %s will be served by Dolibarr server so it does not need any extra web server (like Apache, Nginx, IIS) to be installed.<br>The inconvenient is that URL of pages are not user friendly and start with path of your Dolibarr.<br>URL served by Dolibarr:<br><strong>%s</strong><br><br>To use your own external web server to serve this web site, create a virtual host on your web server that point on directory<br><strong>%s</strong><br>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 <strong><?php ?></strong>. The following global variables are available: $conf, $langs, $db, $mysoc, $user, $website.<br><br>You can also include content of another Page/Container with the following syntax: <strong><?php dolIncludeHtmlContent($websitekey.'/contentaliastoinclude.php'); ?></strong><br><br>To include a link to download a file stored into the documents/medias directory, use syntax:<br><strong><a href="/document.php?modulepart=medias&file=filename.ext"></strong>.
|
||||
YouCanEditHtmlSource=You can include PHP code into this source using tags <strong><?php ?></strong>. The following global variables are available: $conf, $langs, $db, $mysoc, $user, $website.<br><br>You can also include content of another Page/Container with the following syntax: <strong><?php dolIncludeHtmlContent($websitekey.'/contentaliastoinclude.php'); ?></strong><br><br>To include a link to download a file stored into the <strong>documents</strong> directory, use the <strong>document.php</strong> wrapper:<br>Example, for a file into documents/ecm (need to be logged), syntax is:<br><strong><a href="/document.php?modulepart=ecm&file=reldir/filename.ext"></strong>.<br>for a file into documents/media (open access), syntax is:<br><strong><a href="/document.php?modulepart=medias&file=reldir/filename.ext"></strong>.<br><br>To include an image stored into the <strong>documents</strong> directory, use the <strong>viewimage.php</strong> wrapper:<br>Example, for an image into documents/media (open access), syntax is:<br><strong><a href="/viewimage.php?modulepart=medias&file=filename.ext"></strong>.
|
||||
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
|
||||
WebsiteId=Website ID
|
||||
|
||||
|
||||
@ -190,7 +190,7 @@ if (! file_exists($original_file_osencoded))
|
||||
|
||||
// Output page content
|
||||
define('USEDOLIBARRSERVER', 1);
|
||||
print '<!-- Page content '.$original_file.' : Html with CSS link and html header + Body that was saved into tpl -->'."\n";
|
||||
print '<!-- Page content '.$original_file.' : Html with CSS link and html header + Body that was saved into tpl dir -->'."\n";
|
||||
include_once $original_file_osencoded;
|
||||
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
|
||||
@ -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 = '<!-- Page content '.$filetpl.' : Div with (CSS + Page content from database) -->'."\n";
|
||||
|
||||
$out.='<div id="websitecontentundertopmenu" class="websitecontentundertopmenu">'."\n";
|
||||
|
||||
$csscontent = @file_get_contents($filecss);
|
||||
// REPLACEMENT OF LINKS When page called by website editor
|
||||
|
||||
$out.='<style scoped>'."\n"; // "scoped" means "apply to parent element only". Not yet supported by browsers
|
||||
$out.=$csscontent;
|
||||
$out.=dolWebsiteReplacementOfLinks($csscontent);
|
||||
$out.='</style>'."\n";
|
||||
|
||||
$out.='<div id="bodywebsite" class="bodywebsite">'."\n";
|
||||
|
||||
// Replace php code. Note $objectpage->content come from database and does not contains body tags.
|
||||
$content = preg_replace('/<\?php[^\?]+\?>\n*/ims', '<span style="background: #ddd; border: 1px solid #ccc; border-radius: 4px;">...php...</span>', $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.='</div>';
|
||||
|
||||
$out.='</div>';
|
||||
|
||||
$out.= "\n".'<!-- End page content '.$filetpl.' -->'."\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', '<span style="background: #ddd; border: 1px solid #ccc; border-radius: 4px;">...php...</span>', $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;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user