diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 0634d4c6746..d4f1a38fbbb 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -2775,7 +2775,7 @@ function dol_print_error($db='',$error='',$errors=null) foreach($errors as $msg) { - $msg=$langs->trans($msg); + if (empty($msg)) continue; if ($_SERVER['DOCUMENT_ROOT']) // Mode web { $out.="".$langs->trans("Message").": ".$msg."
\n" ; diff --git a/htdocs/langs/en_US/website.lang b/htdocs/langs/en_US/website.lang index d94ac13cd05..9ce7cfb09a3 100644 --- a/htdocs/langs/en_US/website.lang +++ b/htdocs/langs/en_US/website.lang @@ -16,7 +16,10 @@ Website=Web site AddPage=Add page Page=Page PreviewOfSiteNotYetAvailable=Preview of your website %s not yet available. You must first add a page. -PageDeleted=Page %s of website %s deleted +RequestedPageHasNoContentYet=Requested page with id %s has not content yet or cache file .tpl.php was removed. Edit content of page to solve this. +PageDeleted=Page '%s' of website %s deleted +PageAdded=Page '%s' added ViewSiteInNewTab=View site in new tab ViewPageInNewTab=View page in new tab -SetAsHomePage=Set as Home page \ No newline at end of file +SetAsHomePage=Set as Home page +RealURL=Real URL \ No newline at end of file diff --git a/htdocs/public/websites/index.php b/htdocs/public/websites/index.php index b54a69e90f9..4625bc1573a 100644 --- a/htdocs/public/websites/index.php +++ b/htdocs/public/websites/index.php @@ -48,8 +48,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $error=0; $website=GETPOST('website', 'alpha'); -$page=GETPOST('page', 'alpha'); -$pageid=GETPOST('pageid', 'alpha'); +$pageid=GETPOST('page', 'alpha')?GETPOST('page', 'alpha'):GETPOST('pageid', 'alpha'); $accessallowed = 1; $type=''; @@ -81,13 +80,23 @@ if (empty($pageid)) $pageid=$firstrep->id; } } - +if (empty($pageid)) +{ + $langs->load("website"); + print $langs->trans("PreviewOfSiteNotYetAvailable"); + exit; +} // Security: Delete string ../ into $original_file global $dolibarr_main_data_root; if ($pageid == 'css') { + header('Content-type: text/css'); + // Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access. + //if (empty($dolibarr_nocache)) header('Cache-Control: max-age=3600, public, must-revalidate'); + //else + header('Cache-Control: no-cache'); $original_file=$dolibarr_main_data_root.'/websites/'.$website.'/styles.css'; } else @@ -127,7 +136,9 @@ $original_file_osencoded=dol_osencode($original_file); // New file name encoded // This test if file exists should be useless. We keep it to find bug more easily if (! file_exists($original_file_osencoded)) { - dol_print_error(0,$langs->trans("ErrorFileDoesNotExists",$original_file)); + $langs->load("website"); + print $langs->trans("RequestedPageHasNoContentYet", $pageid); + //dol_print_error(0,$langs->trans("ErrorFileDoesNotExists",$original_file)); exit; } diff --git a/htdocs/websites/class/websitepage.class.php b/htdocs/websites/class/websitepage.class.php index aa0063f9a2b..65e56e030a1 100644 --- a/htdocs/websites/class/websitepage.class.php +++ b/htdocs/websites/class/websitepage.class.php @@ -253,15 +253,16 @@ class WebsitePage extends CommonObject /** * Load object in memory from the database * - * @param string $sortorder Sort Order - * @param string $sortfield Sort field - * @param int $limit limit - * @param int $offset Offset - * @param array $filter Filter array - * @param string $filtermode Filter mode (AND or OR) - * @return array|int int <0 if KO, array of pages if OK + * @param string $websiteid Web site + * @param string $sortorder Sort Order + * @param string $sortfield Sort field + * @param int $limit limit + * @param int $offset Offset + * @param array $filter Filter array + * @param string $filtermode Filter mode (AND or OR) + * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter = array(), $filtermode='AND') + public function fetchAll($websiteid, $sortorder='', $sortfield='', $limit=0, $offset=0, array $filter = array(), $filtermode='AND') { dol_syslog(__METHOD__, LOG_DEBUG); @@ -280,14 +281,15 @@ class WebsitePage extends CommonObject $sql .= " t.date_modification,"; $sql .= " t.tms"; $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t'; + $sql .= ' WHERE t.fk_website = '.$websiteid; // Manage filter $sqlwhere = array(); if (count($filter) > 0) { foreach ($filter as $key => $value) { if ($key=='t.rowid' || $key=='t.fk_website') { - $sqlwhere [] = $key . '='. $value; + $sqlwhere[] = $key . '='. $value; } else { - $sqlwhere [] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; + $sqlwhere[] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; } } } diff --git a/htdocs/websites/index.php b/htdocs/websites/index.php index 73581307c83..ae29dab196b 100644 --- a/htdocs/websites/index.php +++ b/htdocs/websites/index.php @@ -126,6 +126,11 @@ $pathofwebsite=$dolibarr_main_data_root.'/websites/'.$website; $filecss=$pathofwebsite.'/styles.css'; $filetpl=$pathofwebsite.'/page'.$pageid.'.tpl.php'; +// 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 + /* @@ -162,7 +167,7 @@ if ($action == 'add') if (! $error) { $db->commit(); - setEventMessages($langs->trans("PageAdded"), null, 'mesgs'); + setEventMessages($langs->trans("PageAdded", $objectpage->pageurl), null, 'mesgs'); $action=''; } else @@ -475,6 +480,9 @@ if (count($object->records) > 0) if ($website) { + print ' - '.$langs->trans("RealURL").' '; + $realurl=$urlwithroot.'/public/websites/index.php?website='.$website; + print ' '; print ''.$langs->trans("ViewSiteInNewTab").''; } print ''; @@ -508,8 +516,10 @@ if (count($object->records) > 0) { print ''; - $array=$objectpage->fetchAll('','',0,0,array('t.fk_website'=>$object->id)); - + $array=$objectpage->fetchAll($object->id); + if (! is_array($array) && $array < 0) dol_print_error('', $objectpage->error, $objectpage->errors); + $atleastonepage=(is_array($array) && count($array) > 0); + print '
'; print '
'; print $langs->trans("Page").': '; @@ -517,30 +527,33 @@ if (count($object->records) > 0) print '
'; $out=''; $out.=''; print $out; - print ''; - print ''; + print ''; + print ''; //print $form->selectarray('page', $array); if ($website && $pageid > 0) { - print ''.$langs->trans("ViewPageInNewTab").''; + print ' - '.$langs->trans("RealURL").' '; + $realurl=$urlwithroot.'/public/websites/index.php?website='.$website.'&page='.$pageid; + print ' '; + print ''.$langs->trans("ViewPageInNewTab").''; } print '
';