Debug module website

This commit is contained in:
Laurent Destailleur 2017-07-21 02:30:02 +02:00
parent 1fd3ab56a8
commit 28254655e9
5 changed files with 114 additions and 58 deletions

View File

@ -31,17 +31,17 @@
function dolWebsiteOutput($content) function dolWebsiteOutput($content)
{ {
global $db, $langs, $conf, $user; global $db, $langs, $conf, $user;
global $dolibarr_main_url_root; global $dolibarr_main_url_root, $dolibarr_main_data_root;
dol_syslog("dolWebsiteOutput start"); dol_syslog("dolWebsiteOutput start");
// 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')) if (! defined('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
$symlinktomediaexists=1; $symlinktomediaexists=1;
// Make a change into HTML code to allow to include images from medias directory correct with direct link for virtual server // Make a change into HTML code to allow to include images from medias directory correct with direct link for virtual server
@ -55,9 +55,17 @@ function dolWebsiteOutput($content)
} }
else else
{ {
$content=preg_replace('/(<img.*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^\/]*\/>)/', '\1medias/\4\5', $content, -1, $nbrep); $content=preg_replace('/(<img.*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^\/]*\/>)/', '\1medias/\4\5', $content, -1, $nbrep);
} }
} }
else
{
global $website;
// Replace relative link with dolibarr URL
$content=preg_replace('/(href=")\/\"/', '\1'.DOL_URL_ROOT.'/public/websites/index.php?website='.$website->ref.'&pageid='.$website->fk_default_home.'"', $content, -1, $nbrep);
$content=preg_replace('/(href=")\/?([^\"]*)(\.php\")/', '\1'.DOL_URL_ROOT.'/public/websites/index.php?website='.$website->ref.'&pageref=\2"', $content, -1, $nbrep);
}
dol_syslog("dolWebsiteOutput end"); dol_syslog("dolWebsiteOutput end");

View File

@ -33,4 +33,4 @@ PreviewSiteServedByDolibarr=Preview %s in a new tab.<br><br>The %s will be serve
VirtualHostUrlNotDefined=URL of the virtual host served by external web server not defined VirtualHostUrlNotDefined=URL of the virtual host served by external web server not defined
NoPageYet=No pages yet NoPageYet=No pages yet
SyntaxHelp=Help on code syntax SyntaxHelp=Help on code syntax
YouCanEditHtmlSource=You can edit HTML source code using the "Source" button in editor. You can also include PHP code into this source using tags <strong>&lt;?php ?&gt;</strong>. The following global variables are available: $conf, $langs, $db, $mysoc, $user, $website.<br>You can also include content of another Page/Content with the following syntax: <strong>&lt;?php dolIncludeHtmlContent($websitekey.'/contentaliastoinclude.php'); ?&gt;</strong> YouCanEditHtmlSource=You can edit HTML source code using the "Source" button in editor. You can also include PHP code into this source using tags <strong>&lt;?php ?&gt;</strong>. The following global variables are available: $conf, $langs, $db, $mysoc, $user, $website.<br><br>You can also include content of another Page/Content with the following syntax: <strong>&lt;?php dolIncludeHtmlContent($websitekey.'/contentaliastoinclude.php'); ?&gt;</strong><br><br>To include a link to download a file stored into the documents/medias directory, use syntax:<br><strong>&lt;a href="/document.php?modulepart=medias&file=filename.ext"&gt;</strong>.

View File

@ -49,6 +49,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$error=0; $error=0;
$websitekey=GETPOST('website', 'alpha'); $websitekey=GETPOST('website', 'alpha');
$pageid=GETPOST('page', 'alpha')?GETPOST('page', 'alpha'):GETPOST('pageid', 'alpha'); $pageid=GETPOST('page', 'alpha')?GETPOST('page', 'alpha'):GETPOST('pageid', 'alpha');
$pageref=GETPOST('pageref', 'aZ09')?GETPOST('pageref', 'aZ09'):'';
$accessallowed = 1; $accessallowed = 1;
$type=''; $type='';
@ -70,7 +71,8 @@ if (empty($pageid))
$object=new Website($db); $object=new Website($db);
$object->fetch(0, $websitekey); $object->fetch(0, $websitekey);
if (empty($object->id))
if (empty($object->id))
{ {
if (empty($pageid)) if (empty($pageid))
{ {
@ -84,23 +86,34 @@ if (empty($pageid))
$objectpage=new WebsitePage($db); $objectpage=new WebsitePage($db);
if ($object->fk_default_home > 0) if ($pageref)
{ {
$result=$objectpage->fetch($object->fk_default_home); $result=$objectpage->fetch(0, $object->id, $pageref);
if ($result > 0) if ($result > 0)
{ {
$pageid = $objectpage->id; $pageid = $objectpage->id;
} }
} }
else
if (empty($pageid))
{ {
$array=$objectpage->fetchAll($object->id); if ($object->fk_default_home > 0)
if (is_array($array) && count($array) > 0) {
{ $result=$objectpage->fetch($object->fk_default_home);
$firstrep=reset($array); if ($result > 0)
$pageid=$firstrep->id; {
} $pageid = $objectpage->id;
}
}
if (empty($pageid))
{
$array=$objectpage->fetchAll($object->id);
if (is_array($array) && count($array) > 0)
{
$firstrep=reset($array);
$pageid=$firstrep->id;
}
}
} }
} }
if (empty($pageid)) if (empty($pageid))
@ -177,7 +190,7 @@ if (! file_exists($original_file_osencoded))
// Output page content // Output page content
define('USEDOLIBARRSERVER', 1); define('USEDOLIBARRSERVER', 1);
print "\n".'<!-- Page content '.$original_file.' : Html with CSS link + Body was saved into tpl -->'."\n"; print '<!-- Page content '.$original_file.' : Html with CSS link and html header + Body that was saved into tpl -->'."\n";
include_once $original_file_osencoded; include_once $original_file_osencoded;

View File

@ -181,9 +181,9 @@ class WebsitePage extends CommonObject
/** /**
* Load object in memory from the database * Load object in memory from the database
* *
* @param int $id Id object. If this is 0, the default page of website_id will be used, if not defined, the first one. found * @param int $id Id object. If this is 0, the default page of website_id will be used, if not defined, the first one found.
* @param string $website_id Web site id * @param string $website_id Web site id (page name must also be filled if this parameter is used)
* @param string $page Page name * @param string $page Page name (website id must also be filled if this parameter is used)
* *
* @return int <0 if KO, 0 if not found, >0 if OK * @return int <0 if KO, 0 if not found, >0 if OK
*/ */
@ -205,12 +205,17 @@ class WebsitePage extends CommonObject
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
//$sql .= ' WHERE entity IN ('.getEntity('website').')'; // entity is on website level //$sql .= ' WHERE entity IN ('.getEntity('website').')'; // entity is on website level
$sql .= ' WHERE 1 = 1'; $sql .= ' WHERE 1 = 1';
if (null !== $website_id) { if ($id > 0)
$sql .= " AND t.fk_website = '" . $this->db->escape($website_id) . "'"; {
if ($page) $sql .= " AND t.pageurl = '" . $this->db->escape($page) . "'";
} else {
$sql .= ' AND t.rowid = ' . $id; $sql .= ' AND t.rowid = ' . $id;
} }
else
{
if (null !== $website_id) {
$sql .= " AND t.fk_website = '" . $this->db->escape($website_id) . "'";
if ($page) $sql .= " AND t.pageurl = '" . $this->db->escape($page) . "'";
}
}
$sql .= $this->db->plimit(1); $sql .= $this->db->plimit(1);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);

View File

@ -48,7 +48,7 @@ function llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0,
// html header // html header
top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss); top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
print '<body id="websitebody" class="websitebody">'; print '<body id="mainbody">';
// top menu and left menu area // top menu and left menu area
if (empty($conf->dol_hide_topmenu)) if (empty($conf->dol_hide_topmenu))
@ -89,6 +89,7 @@ $error=0;
$website=GETPOST('website', 'alpha'); $website=GETPOST('website', 'alpha');
$page=GETPOST('page', 'alpha'); $page=GETPOST('page', 'alpha');
$pageid=GETPOST('pageid', 'int'); $pageid=GETPOST('pageid', 'int');
$pageref=GETPOST('pageref', 'aZ09');
$action=GETPOST('action','alpha'); $action=GETPOST('action','alpha');
if (GETPOST('delete')) { $action='delete'; } if (GETPOST('delete')) { $action='delete'; }
@ -123,9 +124,10 @@ if ($website)
} }
if ($pageid < 0) $pageid = 0; if ($pageid < 0) $pageid = 0;
if ($pageid > 0 && $action != 'add') if (($pageid > 0 || $pageref) && $action != 'add')
{ {
$res = $objectpage->fetch($pageid); $res = $objectpage->fetch($pageid, ($object->id > 0 ? $object->id : null), $pageref);
$pageid = $objectpage->id;
} }
global $dolibarr_main_data_root; global $dolibarr_main_data_root;
@ -167,6 +169,11 @@ if ($action == 'add')
$error++; $error++;
$action='create'; $action='create';
} }
else if (! preg_match('/^[a-z0-9]+$/i', $objectpage->pageurl))
{
$error++;
setEventMessages($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities('WEBSITE_PAGENAME')), null, 'errors');
}
if (empty($objectpage->title)) if (empty($objectpage->title))
{ {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_TITLE")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_TITLE")), null, 'errors');
@ -250,13 +257,16 @@ if ($action == 'updatecss')
$res = $object->fetch(0, $website); $res = $object->fetch(0, $website);
// Html header file // Html header file
$htmlheadercontent ='';
/* Not required. htmlheader.html is never call as a standalone page
$htmlheadercontent.= '<?php '."\n"; $htmlheadercontent.= '<?php '."\n";
$htmlheadercontent.= "header('Content-type: text/html');\n"; $htmlheadercontent.= "header('Content-type: text/html');\n";
$htmlheadercontent.= "?>"."\n"; $htmlheadercontent.= "?>"."\n";
$htmlheadercontent = '<!-- BEGIN DOLIBARR-WEBSITE-HTML-ADDED-HEADER -->'."\n"; */
$htmlheadercontent.= '<!-- File generated to save common html header - YOU CAN MODIFY DIRECTLY THIS FILE. Change affects all pages of website. -->'."\n"; $htmlheadercontent.= '<!-- BEGIN DOLIBARR-WEBSITE-HTML-ADDED-HEADER -->'."\n";
$htmlheadercontent.= '<!-- File generated to save common html header - YOU CAN MODIFY DIRECTLY THE FILE htmlheader.html. Change affects all pages of website. -->'."\n";
$htmlheadercontent.= '<!-- END -->'."\n"; $htmlheadercontent.= '<!-- END -->'."\n";
$htmlheadercontent.= preg_replace(array('/<html>/','/<\/html>/'),array('',''),GETPOST('WEBSITE_HTML_HEADER')); $htmlheadercontent.= preg_replace(array('/<html>\n*/ims','/<\/html>\n*/ims'),array('',''),GETPOST('WEBSITE_HTML_HEADER'));
dol_syslog("Save file css into ".$filehtmlheader); dol_syslog("Save file css into ".$filehtmlheader);
@ -272,11 +282,12 @@ if ($action == 'updatecss')
} }
// Css file // Css file
$csscontent ='';
$csscontent.= '<?php '."\n"; $csscontent.= '<?php '."\n";
$csscontent.= "header('Content-type: text/css');\n"; $csscontent.= "header('Content-type: text/css');\n";
$csscontent.= "?>"."\n"; $csscontent.= "?>"."\n";
$csscontent = '/* BEGIN DOLIBARR-WEBSITE-CSS-ADDED-HEADER */'."\n"; $csscontent.= '/* BEGIN DOLIBARR-WEBSITE-CSS-ADDED-HEADER */'."\n";
$csscontent.= '/* File generated to wrap the css file - YOU CAN MODIFY DIRECTLY THIS FILE. Change affects all pages of website. */'."\n"; $csscontent.= '/* File generated to wrap the css file - YOU CAN MODIFY DIRECTLY THE FILE styles.css.php. Change affects all pages of website. */'."\n";
$csscontent.= '/* END */'."\n"; $csscontent.= '/* END */'."\n";
$csscontent.= GETPOST('WEBSITE_CSS_INLINE'); $csscontent.= GETPOST('WEBSITE_CSS_INLINE');
@ -353,8 +364,22 @@ if ($action == 'updatemeta')
$objectpage->fk_website = $object->id; $objectpage->fk_website = $object->id;
// Check parameters
if (! preg_match('/^[a-z0-9\-\_]+$/i', $objectpage->pageurl))
{
$error++;
setEventMessages($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities('WEBSITE_PAGENAME')), null, 'errors');
$action='editmeta';
}
$res = $objectpage->fetch($pageid, $object->fk_website); $res = $objectpage->fetch($pageid, $object->fk_website);
if ($res > 0) if ($res <= 0)
{
$error++;
dol_print_error($db, 'Page not found');
}
if (! $error)
{ {
$objectpage->old_object = clone $objectpage; $objectpage->old_object = clone $objectpage;
@ -388,7 +413,8 @@ if ($action == 'updatemeta')
$mastercontent = '<?php'."\n"; $mastercontent = '<?php'."\n";
$mastercontent.= '// File generated to link to the master file - DO NOT MODIFY - It is just an include'."\n"; $mastercontent.= '// File generated to link to the master file - DO NOT MODIFY - It is just an include'."\n";
$mastercontent.= "if (! defined('USEDOLIBARRSERVER')) require '".DOL_DOCUMENT_ROOT."/master.inc.php';\n"; $mastercontent.= "if (! defined('USEDOLIBARRSERVER')) require '".DOL_DOCUMENT_ROOT."/master.inc.php';\n";
$mastercontent.= '$website = new WebSite($db)'."\n"; //$mastercontent.= "include_once DOL_DOCUMENT_ROOT.'/websites/class/website.class.php';"."\n";
//$mastercontent.= '$website = new WebSite($db)'."\n";
$mastercontent.= '?>'."\n"; $mastercontent.= '?>'."\n";
$result = file_put_contents($filemaster, $mastercontent); $result = file_put_contents($filemaster, $mastercontent);
if (! empty($conf->global->MAIN_UMASK)) if (! empty($conf->global->MAIN_UMASK))
@ -435,7 +461,7 @@ if ($action == 'updatemeta')
$tplcontent.= '<meta name="generator" content="'.DOL_APPLICATION_TITLE.'" />'."\n"; $tplcontent.= '<meta name="generator" content="'.DOL_APPLICATION_TITLE.'" />'."\n";
$tplcontent.= '<!-- Include link to CSS file -->'."\n"; $tplcontent.= '<!-- Include link to CSS file -->'."\n";
$tplcontent.= '<link rel="stylesheet" href="styles.css.php?websiteid='.$object->id.'" type="text/css" />'."\n"; $tplcontent.= '<link rel="stylesheet" href="styles.css.php?websiteid='.$object->id.'" type="text/css" />'."\n";
$tplcontent.= '<!-- Include common page header file -->'."\n"; $tplcontent.= '<!-- Include common HTML header file -->'."\n";
$tplcontent.= '<?php print file_get_contents(DOL_DATA_ROOT."/websites/'.$object->ref.'/htmlheader.html"); ?>'."\n"; $tplcontent.= '<?php print file_get_contents(DOL_DATA_ROOT."/websites/'.$object->ref.'/htmlheader.html"); ?>'."\n";
$tplcontent.= '</header>'."\n"; $tplcontent.= '</header>'."\n";
@ -462,10 +488,6 @@ if ($action == 'updatemeta')
$db->rollback(); $db->rollback();
} }
} }
else
{
dol_print_error($db, 'Page not found');
}
} }
// Update page // Update page
@ -594,7 +616,7 @@ if ($action == 'updatecontent' || ($action == 'preview' && (GETPOST('refreshsite
$tplcontent.= '<meta name="generator" content="'.DOL_APPLICATION_TITLE.'" />'."\n"; $tplcontent.= '<meta name="generator" content="'.DOL_APPLICATION_TITLE.'" />'."\n";
$tplcontent.= '<!-- Include link to CSS file -->'."\n"; $tplcontent.= '<!-- Include link to CSS file -->'."\n";
$tplcontent.= '<link rel="stylesheet" href="styles.css.php?websiteid='.$object->id.'" type="text/css" />'."\n"; $tplcontent.= '<link rel="stylesheet" href="styles.css.php?websiteid='.$object->id.'" type="text/css" />'."\n";
$tplcontent.= '<!-- Include common page header file -->'."\n"; $tplcontent.= '<!-- Include common HTML header file -->'."\n";
$tplcontent.= '<?php print file_get_contents(DOL_DATA_ROOT."/websites/'.$object->ref.'/htmlheader.html"); ?>'."\n"; $tplcontent.= '<?php print file_get_contents(DOL_DATA_ROOT."/websites/'.$object->ref.'/htmlheader.html"); ?>'."\n";
$tplcontent.= '</header>'."\n"; $tplcontent.= '</header>'."\n";
@ -803,7 +825,7 @@ if (count($object->records) > 0)
if ($action != 'add') if ($action != 'add')
{ {
$out=''; $out='';
$out.='<select name="pageid" id="pageid" class="minwidth200">'; $out.='<select name="pageid" id="pageid" class="minwidth200 maxwidth300">';
if ($atleastonepage) if ($atleastonepage)
{ {
if (empty($pageid) && $action != 'create') // Page id is not defined, we try to take one if (empty($pageid) && $action != 'create') // Page id is not defined, we try to take one
@ -822,7 +844,7 @@ if (count($object->records) > 0)
$out.='<option value="'.$key.'"'; $out.='<option value="'.$key.'"';
if ($pageid > 0 && $pageid == $key) $out.=' selected'; // To preselect a value if ($pageid > 0 && $pageid == $key) $out.=' selected'; // To preselect a value
$out.='>'; $out.='>';
$out.=$valpage->title; $out.=$valpage->pageurl.' - '.$valpage->title;
if ($object->fk_default_home && $key == $object->fk_default_home) $out.=' ('.$langs->trans("HomePage").')'; if ($object->fk_default_home && $key == $object->fk_default_home) $out.=' ('.$langs->trans("HomePage").')';
$out.='</option>'; $out.='</option>';
} }
@ -848,8 +870,8 @@ if (count($object->records) > 0)
{ {
print ' &nbsp; '; print ' &nbsp; ';
print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditPageMeta")).'" name="editmeta">';
print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditPageContent")).'" name="editcontent">'; print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditPageContent")).'" name="editcontent">';
print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditPageMeta")).'" name="editmeta">';
if ($object->fk_default_home > 0 && $pageid == $object->fk_default_home) print '<input type="submit" class="button" disabled="disabled" value="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'" name="setashome">'; if ($object->fk_default_home > 0 && $pageid == $object->fk_default_home) print '<input type="submit" class="button" disabled="disabled" value="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'" name="setashome">';
else print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'" name="setashome">'; else print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'" name="setashome">';
print '<input type="submit" class="buttonDelete" name="delete" value="'.$langs->trans("Delete").'"'.($atleastonepage?'':' disabled="disabled"').'>'; print '<input type="submit" class="buttonDelete" name="delete" value="'.$langs->trans("Delete").'"'.($atleastonepage?'':' disabled="disabled"').'>';
@ -865,7 +887,7 @@ if (count($object->records) > 0)
$websitepage = new WebSitePage($db); $websitepage = new WebSitePage($db);
$websitepage->fetch($pageid); $websitepage->fetch($pageid);
$realpage=$urlwithroot.'/public/websites/index.php?website='.$website.'&page='.$pageid; $realpage=$urlwithroot.'/public/websites/index.php?website='.$website.'&pageref='.$websitepage->pageurl;
$pagealias = $websitepage->pageurl; $pagealias = $websitepage->pageurl;
print '<div class="websiteinputurl" id="websiteinputpage">'; print '<div class="websiteinputurl" id="websiteinputpage">';
@ -876,7 +898,7 @@ if (count($object->records) > 0)
$urlext=$virtualurl.'/'.$pagealias.'.php'; $urlext=$virtualurl.'/'.$pagealias.'.php';
$urlint=$urlwithroot.'/public/websites/index.php?website='.$website; $urlint=$urlwithroot.'/public/websites/index.php?website='.$website;
print '<a class="websitebuttonsitepreview'.($virtualurl?'':' websitebuttonsitepreviewdisabled cursornotallowed').'" id="previewpageext" href="'.$urlext.'ext" target="tab'.$website.'" alt="'.dol_escape_htmltag($langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $urlext)).'">'; print '<a class="websitebuttonsitepreview'.($virtualurl?'':' websitebuttonsitepreviewdisabled cursornotallowed').'" id="previewpageext" href="'.$urlext.'" target="tab'.$website.'ext" alt="'.dol_escape_htmltag($langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $urlext)).'">';
print $form->textwithpicto('', $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $virtualurl?$urlext:'<span class="error">'.$langs->trans("VirtualHostUrlNotDefined").'</span>'), 1, 'preview_ext'); print $form->textwithpicto('', $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $virtualurl?$urlext:'<span class="error">'.$langs->trans("VirtualHostUrlNotDefined").'</span>'), 1, 'preview_ext');
print '</a>'; print '</a>';
@ -972,18 +994,18 @@ if ($action == 'editcss')
$csscontent = @file_get_contents($filecss); $csscontent = @file_get_contents($filecss);
// Clean the php css file to remove php code and get only css part // Clean the php css file to remove php code and get only css part
$csscontent = preg_replace('/^<\?php[^\?]+\?>/ims', '', $csscontent); $csscontent = preg_replace('/^<\?php[^\?]+\?>\n*/ims', '', $csscontent);
$csscontent = preg_replace('/\/\* BEGIN DOLIBARR.*END \*\/\n*/ims', '', $csscontent); $csscontent = preg_replace('/\/\* BEGIN DOLIBARR.*END \*\/\n*/ims', '', $csscontent);
if (! trim($csscontent)) $csscontent='/* CSS content (all website) */'."\n".'body { margin: 0; }'; if (! trim($csscontent)) $csscontent='/* CSS content (all pages) */'."\n".'body.bodywebsite { margin: 0; }';
$htmlheader = @file_get_contents($filehtmlheader); $htmlheader = @file_get_contents($filehtmlheader);
// Clean the php htmlheader file to remove php code and get only html part // Clean the php htmlheader file to remove php code and get only html part
$htmlheader = preg_replace('/^<\?php[^\?]+\?>/ims', '', $htmlheader); $htmlheader = preg_replace('/^<\?php[^\?]+\?>\n*/ims', '', $htmlheader);
$htmlheader = preg_replace('/<!-- BEGIN DOLIBARR.*END -->\n*/ims', '', $htmlheader); $htmlheader = preg_replace('/<!-- BEGIN DOLIBARR.*END -->\n*/ims', '', $htmlheader);
if (! trim($htmlheader)) $htmlheader='<html><!-- HTML header content (all website) --></html>'; if (! trim($htmlheader)) $htmlheader='<html><!-- HTML header content (all pages) --></html>';
else $htmlheader='<html>'.$htmlheader.'</html>'; else $htmlheader='<html>'.$htmlheader.'</html>';
dol_fiche_head(); dol_fiche_head();
@ -1136,11 +1158,12 @@ if ($action == 'preview')
{ {
if ($pageid > 0) if ($pageid > 0)
{ {
// Ouput page under the Dolibarr top menu
$objectpage->fetch($pageid); $objectpage->fetch($pageid);
$out = "\n".'<!-- Page content '.$filetpl.' : Div with (CSS + Page content from database) -->'."\n"; $out = '<!-- Page content '.$filetpl.' : Div with (CSS + Page content from database) -->'."\n";
$out.='<div id="websitecontent" class="websitecontent">'."\n"; $out.='<div id="websitecontentundertopmenu" class="websitecontentundertopmenu">'."\n";
$csscontent = @file_get_contents($filecss); $csscontent = @file_get_contents($filecss);
@ -1148,11 +1171,18 @@ if ($action == 'preview')
$out.=$csscontent; $out.=$csscontent;
$out.='</style>'."\n"; $out.='</style>'."\n";
// Replace php code $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.*\?>/ims', '<span style="background: #ddd; border: 1px solid #ccc; border-radius: 4px;">...php...</span>', $objectpage->content); $content = preg_replace('/<\?php.*\?>/ims', '<span style="background: #ddd; border: 1px solid #ccc; border-radius: 4px;">...php...</span>', $objectpage->content);
// Replace internal relative links with Dolibarr links
// TODO
$out.=$content."\n"; $out.=$content."\n";
$out.='</div>';
$out.='</div>'; $out.='</div>';
$out.= "\n".'<!-- End page content '.$filetpl.' -->'."\n\n"; $out.= "\n".'<!-- End page content '.$filetpl.' -->'."\n\n";