diff --git a/htdocs/core/lib/website.lib.php b/htdocs/core/lib/website.lib.php index a60be612e2d..2de1bfb4ecd 100644 --- a/htdocs/core/lib/website.lib.php +++ b/htdocs/core/lib/website.lib.php @@ -27,6 +27,7 @@ * * @param string $content Content string * @return void + * @see dolWebsiteSaveContent */ function dolWebsiteOutput($content) { @@ -87,7 +88,61 @@ function dolWebsiteOutput($content) /** - * Clean an HTML page to report only content, so we can include it into another page + * Convert a page content to have correct links into a new html content. + * Used to ouput the page on the Preview. + * + * @param Website $website Web site object + * @param string $content Content to replace + * @return boolean True if OK + */ +function dolWebsiteReplacementOfLinks($website, $content) +{ + // Replace php code. Note $content may 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='.$website->ref.'&pageid='.$website->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='.$website->ref.'&pageref=\2"', $content, -1, $nbrep); + + $content = preg_replace('/url\((["\']?)medias\//', 'url(\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); + + // ]*>/ims','/<\/body>.*$/ims'), array('', ''), $content);*/ if (empty($includehtmlcontentopened)) $includehtmlcontentopened=0; $includehtmlcontentopened++; @@ -111,6 +164,9 @@ function dolIncludeHtmlContent($contentfile) print 'ERROR: RECURSIVE CONTENT LEVEL. Depth of recursive call is more than the limit of '.$MAXLEVEL.".\n"; return; } + // TODO Remove body and html if included + //$content = file_get_contents($fullpathfile); + //print preg_replace(array('/^.*]*>/ims','/<\/body>.*$/ims'), array('', ''), $content);*/ $res = include $fullpathfile; // Include because we want to execute code content if (! $res) { diff --git a/htdocs/websites/index.php b/htdocs/websites/index.php index 9561a50c7a3..1982d08af01 100644 --- a/htdocs/websites/index.php +++ b/htdocs/websites/index.php @@ -69,6 +69,7 @@ function llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formwebsite.class.php'; @@ -702,6 +703,7 @@ if (($action == 'updatesource' || $action == 'updatecontent' || $action == 'conf $objectpage->content = preg_replace('/.*<\/head>/s', '', $objectpage->content); /* $objectpage->content = preg_replace('//s', '', $objectpage->content); */ + $res = $objectpage->update($user); if ($res < 0) { @@ -1413,6 +1415,8 @@ if ($action == 'editcontent') $contentforedit.=''."\n";*/ $contentforedit .= $objectpage->content; + $contentforedit = preg_replace('/(Create(0, '', false); @@ -1488,30 +1492,6 @@ $db->close(); -/** - * Save content of a page on disk - * - * @param Website $website Web site object - * @param string $content Content to replace - * @return boolean True if OK - */ -function dolWebsiteReplacementOfLinks($website, $content) -{ - // Replace php code. Note $content may 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='.$website->ref.'&pageid='.$website->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='.$website->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