diff --git a/htdocs/core/lib/website.lib.php b/htdocs/core/lib/website.lib.php
index b4c542edf9c..82e9a98d43f 100644
--- a/htdocs/core/lib/website.lib.php
+++ b/htdocs/core/lib/website.lib.php
@@ -165,47 +165,70 @@ function dolWebsiteSaveContent($content)
/**
- * Make a redirect to another container
+ * Make a redirect to another container.
*
- * @param string $containeralias Path to file to include (must be a page from website root. Example: 'mypage.php' means 'mywebsite/mypage.php')
+ * @param string $containerref Ref of container to redirect to (must be a page from website root. Example: 'mypage.php' means 'mywebsite/mypage.php').
+ * @param string $containeraliasalt Ref of alternative aliases to redirect to.
+ * @param int $containerid Id of container.
* @return void
*/
-function redirectToContainer($containeralias)
+function redirectToContainer($containerref, $containeraliasalt='',$containerid=0)
{
global $db, $website;
$newurl = '';
+ // We make redirect using the alternative alias, we must find the real $containerref
+ if ($containeraliasalt)
+ {
+ include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
+ $tmpwebsitepage=new WebsitePage($db);
+ $result = $tmpwebsitepage->fetch(0, $website->id, '', $containeraliasalt);
+ if ($result > 0)
+ {
+ $containerref = $tmpwebsitepage->pageurl;
+ }
+ else
+ {
+ print "Error, page contains a redirect to the alternative alias '".$containeraliasalt."' that does not exists in web site (".$website->id." / ".$website->ref.")";
+ exit;
+ }
+ }
+
if (defined('USEDOLIBARRSERVER')) // When page called from Dolibarr server
{
// Check new container exists
- $tmpwebsitepage=new WebsitePage($db);
- $result = $tmpwebsitepage->fetch(0, $website->id, $containeralias);
- unset($tmpwebsitepage);
+ if (! $containeraliasalt) // If containeraliasalt set, we already did the test
+ {
+ include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
+ $tmpwebsitepage=new WebsitePage($db);
+ $result = $tmpwebsitepage->fetch(0, $website->id, $containerref);
+ unset($tmpwebsitepage);
+ }
if ($result > 0)
{
$currenturi = $_SERVER["REQUEST_URI"];
if (preg_match('/&pageref=([^&]+)/', $currenturi, $regtmp))
{
- if ($regtmp[0] == $containeralias)
+ if ($regtmp[0] == $containerref)
{
- print "Error, page with uri '.$currenturi.' try a redirect to the same alias page '".$containeralias."' in web site '".$website->ref."'";
+ print "Error, page with uri '.$currenturi.' try a redirect to the same alias page '".$containerref."' in web site '".$website->ref."'";
exit;
}
else
{
- $newurl = preg_replace('/&pageref=([^&]+)/', '&pageref='.$containeralias, $currenturi);
+ $newurl = preg_replace('/&pageref=([^&]+)/', '&pageref='.$containerref, $currenturi);
}
}
else
{
- $newurl = $currenturi.'&pageref='.urlencode($containeralias);
+ $newurl = $currenturi.'&pageref='.urlencode($containerref);
}
}
}
else // When page called from virtual host server
{
- $newurl = '/'.$containeralias.'.php';
+ $newurl = '/'.$containerref.'.php';
}
if ($newurl)
@@ -215,7 +238,7 @@ function redirectToContainer($containeralias)
}
else
{
- print "Error, page contains a redirect to the alias page '".$containeralias."' that does not exists in web site '".$website->ref."'";
+ print "Error, page contains a redirect to the alias page '".$containerref."' that does not exists in web site (".$website->id." / ".$website->ref.")";
exit;
}
}
@@ -225,10 +248,10 @@ function redirectToContainer($containeralias)
* Clean an HTML page to report only content, so we can include it into another page.
* It outputs content of file sanitized from html and body part.
*
- * @param string $containeralias Path to file to include (must be a page from website root. Example: 'mypage.php' means 'mywebsite/mypage.php')
+ * @param string $containerref Path to file to include (must be a page from website root. Example: 'mypage.php' means 'mywebsite/mypage.php')
* @return void
*/
-function includeContainer($containeralias)
+function includeContainer($containerref)
{
global $conf, $db, $langs, $mysoc, $user, $website;
global $includehtmlcontentopened;
@@ -236,9 +259,9 @@ function includeContainer($containeralias)
$MAXLEVEL=20;
- if (! preg_match('/\.php$/i', $containeralias)) $containeralias.='.php';
+ if (! preg_match('/\.php$/i', $containerref)) $containerref.='.php';
- $fullpathfile=DOL_DATA_ROOT.'/website/'.$websitekey.'/'.$containeralias;
+ $fullpathfile=DOL_DATA_ROOT.'/website/'.$websitekey.'/'.$containerref;
if (empty($includehtmlcontentopened)) $includehtmlcontentopened=0;
$includehtmlcontentopened++;
@@ -261,7 +284,7 @@ function includeContainer($containeralias)
if (! $res)
{
- print 'ERROR: FAILED TO INCLUDE PAGE '.$containeralias.".\n";
+ print 'ERROR: FAILED TO INCLUDE PAGE '.$containerref.".\n";
}
$includehtmlcontentopened--;
@@ -550,6 +573,42 @@ function dolSavePageContent($filetpl, $object, $objectpage)
}
+/**
+ * Save content of the index.php page
+ *
+ * @param string $pathofwebsite Path of website root
+ * @param string $fileindex Full path of file index.php
+ * @param string $filetpl File tpl to index.php page redirect to
+ * @return boolean True if OK
+ */
+function dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl)
+{
+ global $conf;
+
+ $result=0;
+
+ dol_mkdir($pathofwebsite);
+ dol_delete_file($fileindex);
+
+ $indexcontent = ''."\n";
+ $result = file_put_contents($fileindex, $indexcontent);
+ if (! empty($conf->global->MAIN_UMASK))
+ @chmod($fileindex, octdec($conf->global->MAIN_UMASK));
+
+ return $result;
+}
+
+
/**
* Save content of a page on disk
*
diff --git a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql
index 79148c6887d..2acaae0aadb 100644
--- a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql
+++ b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql
@@ -58,4 +58,5 @@ insert into llx_c_type_container (code,label,module,active) values ('other',
ALTER TABLE llx_expensereport_det ADD COLUMN docnumber varchar(128) after fk_expensereport;
+ALTER TABLE llx_website_page ADD COLUMN aliasalt varchar(255) after pageurl;
diff --git a/htdocs/install/mysql/tables/llx_website_page.sql b/htdocs/install/mysql/tables/llx_website_page.sql
index 5393177a3bb..7cb9705bcba 100644
--- a/htdocs/install/mysql/tables/llx_website_page.sql
+++ b/htdocs/install/mysql/tables/llx_website_page.sql
@@ -22,6 +22,7 @@ CREATE TABLE llx_website_page
rowid integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
fk_website integer NOT NULL,
pageurl varchar(255) NOT NULL,
+ aliasalt varchar(255),
title varchar(255),
description varchar(255),
keywords varchar(255),
diff --git a/htdocs/langs/en_US/website.lang b/htdocs/langs/en_US/website.lang
index a4c7d9e0211..2da76863d41 100644
--- a/htdocs/langs/en_US/website.lang
+++ b/htdocs/langs/en_US/website.lang
@@ -6,6 +6,7 @@ ConfirmDeleteWebsite=Are you sure you want to delete this web site. All its page
WEBSITE_TYPE_CONTAINER=Type of page/container
WEBSITE_PAGE_EXAMPLE=Web page to use as example
WEBSITE_PAGENAME=Page name/alias
+WEBSITE_ALIASALT=Alternative page names/aliases
WEBSITE_CSS_URL=URL of external CSS file
WEBSITE_CSS_INLINE=CSS file content (common to all pages)
WEBSITE_JS_INLINE=Javascript file content (common to all pages)
@@ -36,6 +37,7 @@ SetAsHomePage=Set as Home page
RealURL=Real URL
ViewWebsiteInProduction=View web site using home URLs
SetHereVirtualHost=If you can create, on your web server (Apache, Nginx, ...), a dedicated Virtual Host with PHP enabled and a Root directory on
%s
then enter here the virtual hostname you have created, so the preview can be done also using this dedicated web server access instead of only using Dolibarr server.
+YouCanAlsoTestWithPHPS=On develop environment, you may prefer to test the site with the PHP embedded web server (PHP 5.5 required) by running
php -S 0.0.0.0:8080 -t %s
CheckVirtualHostPerms=Check also that virtual host has %s on files into
%s
ReadPerm=Read permission
WritePerm=Write permission
diff --git a/htdocs/website/class/website.class.php b/htdocs/website/class/website.class.php
index 432851b4bd4..3574c95e470 100644
--- a/htdocs/website/class/website.class.php
+++ b/htdocs/website/class/website.class.php
@@ -612,17 +612,11 @@ class Website extends CommonObject
if (! $error)
{
- dol_delete_file($fileindex);
-
$filetpl=$pathofwebsitenew.'/page'.$newidforhome.'.tpl.php';
- $indexcontent = ''."\n";
- $result = file_put_contents($fileindex, $indexcontent);
- if (! empty($conf->global->MAIN_UMASK))
- @chmod($fileindex, octdec($conf->global->MAIN_UMASK));
+ // Generate the index.php page to be the home page
+ //-------------------------------------------------
+ $result = dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl);
}
}
diff --git a/htdocs/website/class/websitepage.class.php b/htdocs/website/class/websitepage.class.php
index f4848c70c91..c0b6aaa7ab9 100644
--- a/htdocs/website/class/websitepage.class.php
+++ b/htdocs/website/class/websitepage.class.php
@@ -53,6 +53,7 @@ class WebsitePage extends CommonObject
public $fk_website;
public $pageurl;
+ public $aliasalt;
public $type_container;
public $title;
public $description;
@@ -71,8 +72,9 @@ class WebsitePage extends CommonObject
*/
public $fields=array(
'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'),
- 'pageurl' =>array('type'=>'varchar(16)', 'label'=>'WEBSITE_PAGENAME', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Alias of page'),
- 'type_container' =>array('type'=>'varchar(16)', 'label'=>'Type', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'index'=>0, 'position'=>11, 'comment'=>'Type of container'),
+ 'pageurl' =>array('type'=>'varchar(16)', 'label'=>'WEBSITE_PAGENAME', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Ref/alias of page'),
+ 'aliasalt' =>array('type'=>'varchar(255)', 'label'=>'AliasAlt', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'index'=>0, 'position'=>11, 'searchall'=>0, 'comment'=>'Alias alternative of page'),
+ 'type_container' =>array('type'=>'varchar(16)', 'label'=>'Type', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'index'=>0, 'position'=>12, 'comment'=>'Type of container'),
'title' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1),
'description' =>array('type'=>'varchar(255)', 'label'=>'Description', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1),
'keywords' =>array('type'=>'varchar(255)', 'label'=>'Keywords', 'enabled'=>1, 'visible'=>1, 'position'=>45, 'searchall'=>0),
@@ -115,6 +117,7 @@ class WebsitePage extends CommonObject
{
$this->description = dol_trunc($this->description, 255, 'right', 'utf-8', 1);
$this->keywords = dol_trunc($this->keywords, 255, 'right', 'utf-8', 1);
+ if ($this->aliasalt) $this->aliasalt = ','.preg_replace('/,+$/', '', preg_replace('/^,+/', '', $this->aliasalt)).','; // content in database must be ',xxx,...,yyy,'
return $this->createCommon($user, $notrigger);
}
@@ -122,13 +125,14 @@ class WebsitePage extends CommonObject
/**
* Load object in memory from the database
*
- * @param int $id Id object. If this is 0, the value into $page will be used. If not found of $page not defined, the default page of website_id will be used or the first page found if not set.
- * @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)
+ * @param int $id Id object. If this is 0, the value into $page will be used. If not found of $page not defined, the default page of website_id will be used or the first page found if not set.
+ * @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)
+ * @param string $aliasalt Alternative alias to search page (slow)
*
* @return int <0 if KO, 0 if not found, >0 if OK
*/
- public function fetch($id, $website_id = null, $page = null)
+ public function fetch($id, $website_id = null, $page = null, $aliasalt = null)
{
dol_syslog(__METHOD__, LOG_DEBUG);
@@ -137,6 +141,7 @@ class WebsitePage extends CommonObject
$sql .= " t.fk_website,";
$sql .= ' t.type_container,';
$sql .= " t.pageurl,";
+ $sql .= " t.aliasalt,";
$sql .= " t.title,";
$sql .= " t.description,";
$sql .= " t.keywords,";
@@ -159,7 +164,8 @@ class WebsitePage extends CommonObject
{
if (null !== $website_id) {
$sql .= " AND t.fk_website = '" . $this->db->escape($website_id) . "'";
- if ($page) $sql .= " AND t.pageurl = '" . $this->db->escape($page) . "'";
+ if ($page) $sql .= " AND t.pageurl = '" . $this->db->escape($page) . "'";
+ if ($aliasalt) $sql .= " AND t.aliasalt LIKE '%," . $this->db->escape($aliasalt) . ",%'";
}
}
$sql .= $this->db->plimit(1);
@@ -175,6 +181,7 @@ class WebsitePage extends CommonObject
$this->fk_website = $obj->fk_website;
$this->type_container = $obj->type_container;
$this->pageurl = $obj->pageurl;
+ $this->aliasalt = preg_replace('/,+$/', '', preg_replace('/^,+/', '', $obj->aliasalt));
$this->title = $obj->title;
$this->description = $obj->description;
$this->keywords = $obj->keywords;
@@ -225,6 +232,7 @@ class WebsitePage extends CommonObject
$sql .= " t.fk_website,";
$sql .= " t.type_container,";
$sql .= " t.pageurl,";
+ $sql .= " t.aliasalt,";
$sql .= " t.title,";
$sql .= " t.description,";
$sql .= " t.keywords,";
@@ -272,6 +280,7 @@ class WebsitePage extends CommonObject
$record->fk_website = $obj->fk_website;
$record->type_container = $obj->type_container;
$record->pageurl = $obj->pageurl;
+ $record->aliasalt = preg_replace('/,+$/', '', preg_replace('/^,+/', '', $obj->aliasalt));
$record->title = $obj->title;
$record->description = $obj->description;
$record->keywords = $obj->keywords;
@@ -306,6 +315,10 @@ class WebsitePage extends CommonObject
*/
public function update(User $user, $notrigger = false)
{
+ $this->description = dol_trunc($this->description, 255, 'right', 'utf-8', 1);
+ $this->keywords = dol_trunc($this->keywords, 255, 'right', 'utf-8', 1);
+ if ($this->aliasalt) $this->aliasalt = ','.preg_replace('/,+$/', '', preg_replace('/^,+/', '', $this->aliasalt)).','; // content in database must be ',xxx,...,yyy,'
+
return $this->updateCommon($user, $notrigger);
}
@@ -371,6 +384,7 @@ class WebsitePage extends CommonObject
// Clear fields
$object->ref = $newref;
$object->pageurl = $newref;
+ $object->aliasalt = '';
$object->title = $langs->trans("CopyOf").' '.$object->title;
if (! empty($newlang)) $object->lang=$newlang;
if ($istranslation) $object->fk_page = $fromid;
@@ -510,6 +524,7 @@ class WebsitePage extends CommonObject
$this->fk_website = '';
$this->type_container = 'page';
$this->pageurl = 'specimen';
+ $this->aliasalt = 'specimenalt';
$this->title = 'My Page';
$this->description = 'This is my page';
$this->keywords = 'keyword1, keyword2';
diff --git a/htdocs/website/index.php b/htdocs/website/index.php
index 084ef28c2d0..6cd9705ae21 100644
--- a/htdocs/website/index.php
+++ b/htdocs/website/index.php
@@ -35,9 +35,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
require_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php';
require_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
-$langs->load("admin");
-$langs->load("other");
-$langs->load("website");
+$langs->loadLangs(array("admin","other","website"));
if (! $user->admin) accessforbidden();
@@ -60,18 +58,18 @@ $type_container=GETPOST('WEBSITE_TYPE_CONTAINER', 'alpha');
$section_dir = GETPOST('section_dir', 'alpha');
$file_manager = GETPOST('file_manager', 'alpha');
-if (GETPOST('delete')) { $action='delete'; }
-if (GETPOST('preview')) $action='preview';
-if (GETPOST('createsite')) { $action='createsite'; }
-if (GETPOST('createcontainer')) { $action='createcontainer'; }
-if (GETPOST('editcss')) { $action='editcss'; }
-if (GETPOST('editmenu')) { $action='editmenu'; }
-if (GETPOST('setashome')) { $action='setashome'; }
-if (GETPOST('editmeta')) { $action='editmeta'; }
-if (GETPOST('editsource')) { $action='editsource'; }
-if (GETPOST('editcontent')) { $action='editcontent'; }
-if (GETPOST('createfromclone')) { $action='createfromclone'; }
-if (GETPOST('createpagefromclone')) { $action='createpagefromclone'; }
+if (GETPOST('delete','alpha')) { $action='delete'; }
+if (GETPOST('preview','alpha')) $action='preview';
+if (GETPOST('createsite','alpha')) { $action='createsite'; }
+if (GETPOST('createcontainer','alpha')) { $action='createcontainer'; }
+if (GETPOST('editcss','alpha')) { $action='editcss'; }
+if (GETPOST('editmenu','alpha')) { $action='editmenu'; }
+if (GETPOST('setashome','alpha')) { $action='setashome'; }
+if (GETPOST('editmeta','alpha')) { $action='editmeta'; }
+if (GETPOST('editsource','alpha')) { $action='editsource'; }
+if (GETPOST('editcontent','alpha')) { $action='editcontent'; }
+if (GETPOST('createfromclone','alpha')) { $action='createfromclone'; }
+if (GETPOST('createpagefromclone','alpha')) { $action='createpagefromclone'; }
if (empty($action) && $file_manager) $action='file_manager';
// Load variable for pagination
@@ -331,6 +329,9 @@ if ($action == 'addcontainer')
$objectpage->pageurl=$tmpdomain.'-home';
}
+ $objectpage->aliasalt = '';
+ if (preg_match('/^(\d+)\-/', basename($pageurl), $reg)) $objectpage->aliasalt = $reg[0];
+
if (preg_match('/