diff --git a/htdocs/core/lib/website.lib.php b/htdocs/core/lib/website.lib.php index 336a82b4697..d5d4f2d3826 100644 --- a/htdocs/core/lib/website.lib.php +++ b/htdocs/core/lib/website.lib.php @@ -31,17 +31,17 @@ function dolWebsiteOutput($content) { global $db, $langs, $conf, $user; - global $dolibarr_main_url_root; + global $dolibarr_main_url_root, $dolibarr_main_data_root; 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')) { - // 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; // 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 { - $content=preg_replace('/()/', '\1medias/\4\5', $content, -1, $nbrep); + $content=preg_replace('/()/', '\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"); diff --git a/htdocs/langs/en_US/website.lang b/htdocs/langs/en_US/website.lang index 07304f2a464..c9cf66fc6d1 100644 --- a/htdocs/langs/en_US/website.lang +++ b/htdocs/langs/en_US/website.lang @@ -33,4 +33,4 @@ PreviewSiteServedByDolibarr=Preview %s in a new tab.

The %s will be serve VirtualHostUrlNotDefined=URL of the virtual host served by external web server not defined NoPageYet=No pages yet 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 <?php ?>. The following global variables are available: $conf, $langs, $db, $mysoc, $user, $website.
You can also include content of another Page/Content with the following syntax: <?php dolIncludeHtmlContent($websitekey.'/contentaliastoinclude.php'); ?> +YouCanEditHtmlSource=You can edit HTML source code using the "Source" button in editor. You can also 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/Content 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">. diff --git a/htdocs/public/websites/index.php b/htdocs/public/websites/index.php index a2dcbfc3dc6..84e0a72f9fd 100644 --- a/htdocs/public/websites/index.php +++ b/htdocs/public/websites/index.php @@ -49,6 +49,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $error=0; $websitekey=GETPOST('website', 'alpha'); $pageid=GETPOST('page', 'alpha')?GETPOST('page', 'alpha'):GETPOST('pageid', 'alpha'); +$pageref=GETPOST('pageref', 'aZ09')?GETPOST('pageref', 'aZ09'):''; $accessallowed = 1; $type=''; @@ -70,7 +71,8 @@ if (empty($pageid)) $object=new Website($db); $object->fetch(0, $websitekey); - if (empty($object->id)) + + if (empty($object->id)) { if (empty($pageid)) { @@ -84,23 +86,34 @@ if (empty($pageid)) $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) - { - $pageid = $objectpage->id; - } + { + $pageid = $objectpage->id; + } } - - if (empty($pageid)) + else { - $array=$objectpage->fetchAll($object->id); - if (is_array($array) && count($array) > 0) - { - $firstrep=reset($array); - $pageid=$firstrep->id; - } + if ($object->fk_default_home > 0) + { + $result=$objectpage->fetch($object->fk_default_home); + if ($result > 0) + { + $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)) @@ -177,7 +190,7 @@ if (! file_exists($original_file_osencoded)) // Output page content define('USEDOLIBARRSERVER', 1); -print "\n".''."\n"; +print ''."\n"; include_once $original_file_osencoded; diff --git a/htdocs/websites/class/websitepage.class.php b/htdocs/websites/class/websitepage.class.php index 7d99678fcb6..60661a1af02 100644 --- a/htdocs/websites/class/websitepage.class.php +++ b/htdocs/websites/class/websitepage.class.php @@ -181,9 +181,9 @@ class WebsitePage extends CommonObject /** * 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 string $website_id Web site id - * @param string $page Page name + * @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 (page name must also be filled if this parameter is used) + * @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 */ @@ -205,12 +205,17 @@ class WebsitePage extends CommonObject $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; //$sql .= ' WHERE entity IN ('.getEntity('website').')'; // entity is on website level $sql .= ' WHERE 1 = 1'; - if (null !== $website_id) { - $sql .= " AND t.fk_website = '" . $this->db->escape($website_id) . "'"; - if ($page) $sql .= " AND t.pageurl = '" . $this->db->escape($page) . "'"; - } else { + if ($id > 0) + { $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); $resql = $this->db->query($sql); diff --git a/htdocs/websites/index.php b/htdocs/websites/index.php index d9ea42096c7..1130d760649 100644 --- a/htdocs/websites/index.php +++ b/htdocs/websites/index.php @@ -48,7 +48,7 @@ function llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, // html header top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss); - print ''; + print ''; // top menu and left menu area if (empty($conf->dol_hide_topmenu)) @@ -89,6 +89,7 @@ $error=0; $website=GETPOST('website', 'alpha'); $page=GETPOST('page', 'alpha'); $pageid=GETPOST('pageid', 'int'); +$pageref=GETPOST('pageref', 'aZ09'); $action=GETPOST('action','alpha'); if (GETPOST('delete')) { $action='delete'; } @@ -123,9 +124,10 @@ if ($website) } 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; @@ -167,6 +169,11 @@ if ($action == 'add') $error++; $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)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_TITLE")), null, 'errors'); @@ -250,13 +257,16 @@ if ($action == 'updatecss') $res = $object->fetch(0, $website); // Html header file + $htmlheadercontent =''; + /* Not required. htmlheader.html is never call as a standalone page $htmlheadercontent.= '"."\n"; - $htmlheadercontent = ''."\n"; - $htmlheadercontent.= ''."\n"; + */ + $htmlheadercontent.= ''."\n"; + $htmlheadercontent.= ''."\n"; $htmlheadercontent.= ''."\n"; - $htmlheadercontent.= preg_replace(array('//','/<\/html>/'),array('',''),GETPOST('WEBSITE_HTML_HEADER')); + $htmlheadercontent.= preg_replace(array('/\n*/ims','/<\/html>\n*/ims'),array('',''),GETPOST('WEBSITE_HTML_HEADER')); dol_syslog("Save file css into ".$filehtmlheader); @@ -272,11 +282,12 @@ if ($action == 'updatecss') } // Css file + $csscontent =''; $csscontent.= '"."\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.= '/* BEGIN DOLIBARR-WEBSITE-CSS-ADDED-HEADER */'."\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.= GETPOST('WEBSITE_CSS_INLINE'); @@ -353,8 +364,22 @@ if ($action == 'updatemeta') $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); - if ($res > 0) + if ($res <= 0) + { + $error++; + dol_print_error($db, 'Page not found'); + } + + if (! $error) { $objectpage->old_object = clone $objectpage; @@ -388,7 +413,8 @@ if ($action == 'updatemeta') $mastercontent = ''."\n"; $result = file_put_contents($filemaster, $mastercontent); if (! empty($conf->global->MAIN_UMASK)) @@ -435,7 +461,7 @@ if ($action == 'updatemeta') $tplcontent.= ''."\n"; $tplcontent.= ''."\n"; $tplcontent.= ''."\n"; - $tplcontent.= ''."\n"; + $tplcontent.= ''."\n"; $tplcontent.= 'ref.'/htmlheader.html"); ?>'."\n"; $tplcontent.= ''."\n"; @@ -462,10 +488,6 @@ if ($action == 'updatemeta') $db->rollback(); } } - else - { - dol_print_error($db, 'Page not found'); - } } // Update page @@ -594,7 +616,7 @@ if ($action == 'updatecontent' || ($action == 'preview' && (GETPOST('refreshsite $tplcontent.= ''."\n"; $tplcontent.= ''."\n"; $tplcontent.= ''."\n"; - $tplcontent.= ''."\n"; + $tplcontent.= ''."\n"; $tplcontent.= 'ref.'/htmlheader.html"); ?>'."\n"; $tplcontent.= ''."\n"; @@ -803,7 +825,7 @@ if (count($object->records) > 0) if ($action != 'add') { $out=''; - $out.=''; if ($atleastonepage) { 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.=''; } @@ -848,8 +870,8 @@ if (count($object->records) > 0) { print '   '; - print ''; print ''; + print ''; if ($object->fk_default_home > 0 && $pageid == $object->fk_default_home) print ''; else print ''; print ''; @@ -865,7 +887,7 @@ if (count($object->records) > 0) $websitepage = new WebSitePage($db); $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; print '
'; @@ -876,7 +898,7 @@ if (count($object->records) > 0) $urlext=$virtualurl.'/'.$pagealias.'.php'; $urlint=$urlwithroot.'/public/websites/index.php?website='.$website; - print 'transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $urlext)).'">'; + print 'transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $urlext)).'">'; print $form->textwithpicto('', $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $virtualurl?$urlext:''.$langs->trans("VirtualHostUrlNotDefined").''), 1, 'preview_ext'); print ''; @@ -972,18 +994,18 @@ if ($action == 'editcss') $csscontent = @file_get_contents($filecss); // 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); - 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); // 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('/\n*/ims', '', $htmlheader); - if (! trim($htmlheader)) $htmlheader=''; + if (! trim($htmlheader)) $htmlheader=''; else $htmlheader=''.$htmlheader.''; dol_fiche_head(); @@ -1136,11 +1158,12 @@ if ($action == 'preview') { if ($pageid > 0) { + // Ouput page under the Dolibarr top menu $objectpage->fetch($pageid); - $out = "\n".''."\n"; + $out = ''."\n"; - $out.='
'."\n"; + $out.='
'."\n"; $csscontent = @file_get_contents($filecss); @@ -1148,11 +1171,18 @@ if ($action == 'preview') $out.=$csscontent; $out.=''."\n"; - // Replace php code + $out.='
'."\n"; + + // Replace php code. Note $objectpage->content come from database and does not contains body tags. $content = preg_replace('/<\?php.*\?>/ims', '...php...', $objectpage->content); + // Replace internal relative links with Dolibarr links + // TODO + + $out.=$content."\n"; + $out.='
'; $out.='
'; $out.= "\n".''."\n\n";