diff --git a/htdocs/core/lib/website2.lib.php b/htdocs/core/lib/website2.lib.php
index fb11846a4fb..f882dc9faaf 100644
--- a/htdocs/core/lib/website2.lib.php
+++ b/htdocs/core/lib/website2.lib.php
@@ -49,7 +49,7 @@ function dolSaveMasterFile($filemaster)
@chmod($filemaster, octdec($conf->global->MAIN_UMASK));
}
- return $result;
+ return $result;
}
/**
@@ -291,9 +291,10 @@ function dolSavePageContent($filetpl, Website $object, WebsitePage $objectpage,
* @param string $fileindex Full path of file index.php
* @param string $filetpl File tpl the index.php page redirect to (used only if $fileindex is provided)
* @param string $filewrapper Full path of file wrapper.php
+ * @param Website $object Object website
* @return boolean True if OK
*/
-function dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper)
+function dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper, $object = null)
{
global $conf;
@@ -320,6 +321,44 @@ function dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper)
if (!empty($conf->global->MAIN_UMASK)) {
@chmod($fileindex, octdec($conf->global->MAIN_UMASK));
}
+
+ if ($object->fk_default_home > 0) {
+ $objectpage = new WebsitePage($db);
+ $objectpage->fetch($object->fk_default_home);
+
+ // Create a version for sublanguages
+ if (empty($objectpage->lang) || !in_array($objectpage->lang, explode(',', $object->otherlang))) {
+ if (empty($conf->global->WEBSITE_DISABLE_MAIN_LANGUAGE_INTO_LANGSUBDIR) && is_object($object) && !empty($object->otherlang)) {
+ $dirname = dirname($fileindex);
+ foreach (explode(',', $object->otherlang) as $sublang) {
+ // Avoid to erase main alias file if $sublang is empty string
+ if (empty(trim($sublang))) continue;
+ $fileindexsub = $dirname.'/'.$sublang.'/index.php';
+
+ // Same indexcontent than previously but with ../ instead of ./ for master and tpl file include/require_once.
+ $relpath = '..';
+ $indexcontent = ''."\n";
+ $result = file_put_contents($fileindexsub, $indexcontent);
+ if ($result === false) {
+ dol_syslog("Failed to write file ".$fileindexsub, LOG_WARNING);
+ }
+ if (!empty($conf->global->MAIN_UMASK)) {
+ @chmod($fileindexsub, octdec($conf->global->MAIN_UMASK));
+ }
+ }
+ }
+ }
+ }
} else {
$result1 = true;
}
@@ -491,7 +530,7 @@ function dolSaveReadme($file, $content)
@chmod($file, octdec($conf->global->MAIN_UMASK));
}
- return $result;
+ return $result;
}
@@ -545,9 +584,9 @@ function showWebsiteTemplates(Website $website)
while (($subdir = readdir($handle)) !== false) {
if (is_file($dirtheme."/".$subdir) && substr($subdir, 0, 1) <> '.'
&& substr($subdir, 0, 3) <> 'CVS' && preg_match('/\.zip$/i', $subdir)) {
- $subdirwithoutzip = preg_replace('/\.zip$/i', '', $subdir);
+ $subdirwithoutzip = preg_replace('/\.zip$/i', '', $subdir);
- // Disable not stable themes (dir ends with _exp or _dev)
+ // Disable not stable themes (dir ends with _exp or _dev)
if ($conf->global->MAIN_FEATURES_LEVEL < 2 && preg_match('/_dev$/i', $subdir)) {
continue;
}
@@ -555,38 +594,38 @@ function showWebsiteTemplates(Website $website)
continue;
}
- print '
';
+ print '
';
- $file = $dirtheme."/".$subdirwithoutzip.".jpg";
- $url = DOL_URL_ROOT.'/viewimage.php?modulepart=doctemplateswebsite&file='.$subdirwithoutzip.".jpg";
+ $file = $dirtheme."/".$subdirwithoutzip.".jpg";
+ $url = DOL_URL_ROOT.'/viewimage.php?modulepart=doctemplateswebsite&file='.$subdirwithoutzip.".jpg";
if (!file_exists($file)) {
$url = DOL_URL_ROOT.'/public/theme/common/nophoto.png';
}
- $originalfile = basename($file);
- $entity = $conf->entity;
- $modulepart = 'doctemplateswebsite';
- $cache = '';
- $title = $file;
+ $originalfile = basename($file);
+ $entity = $conf->entity;
+ $modulepart = 'doctemplateswebsite';
+ $cache = '';
+ $title = $file;
- $ret = '';
- $urladvanced = getAdvancedPreviewUrl($modulepart, $originalfile, 1, '&entity='.$entity);
+ $ret = '';
+ $urladvanced = getAdvancedPreviewUrl($modulepart, $originalfile, 1, '&entity='.$entity);
if (!empty($urladvanced)) {
$ret .= '
';
} else {
$ret .= '';
}
- print $ret;
- print '
';
- print '';
+ print $ret;
+ print '

';
+ print '';
- print '
';
- print $subdir.' ('.dol_print_size(dol_filesize($dirtheme."/".$subdir), 1, 1).')';
- print '
ref.'&templateuserfile='.$subdir.'" class="button">'.$langs->trans("Load").'';
- print '
';
+ print '
';
+ print $subdir.' ('.dol_print_size(dol_filesize($dirtheme."/".$subdir), 1, 1).')';
+ print '
ref.'&templateuserfile='.$subdir.'" class="button">'.$langs->trans("Load").'';
+ print '
';
- $i++;
+ $i++;
}
}
}
diff --git a/htdocs/website/class/website.class.php b/htdocs/website/class/website.class.php
index 80a48048151..031419e53fd 100644
--- a/htdocs/website/class/website.class.php
+++ b/htdocs/website/class/website.class.php
@@ -786,7 +786,7 @@ class Website extends CommonObject
// Re-generates the index.php page to be the home page, and re-generates the wrapper.php
//--------------------------------------------------------------------------------------
- $result = dolSaveIndexPage($pathofwebsitenew, $fileindex, $filetpl, $filewrapper);
+ $result = dolSaveIndexPage($pathofwebsitenew, $fileindex, $filetpl, $filewrapper, $object);
}
}
@@ -1275,7 +1275,7 @@ class Website extends CommonObject
// Regenerate index page to point to the new index page
$pathofwebsite = $conf->website->dir_output.'/'.$object->ref;
- dolSaveIndexPage($pathofwebsite, $pathofwebsite.'/index.php', $pathofwebsite.'/page'.$object->fk_default_home.'.tpl.php', $pathofwebsite.'/wrapper.php');
+ dolSaveIndexPage($pathofwebsite, $pathofwebsite.'/index.php', $pathofwebsite.'/page'.$object->fk_default_home.'.tpl.php', $pathofwebsite.'/wrapper.php', $object);
if ($error) {
$this->db->rollback();
@@ -1287,7 +1287,7 @@ class Website extends CommonObject
}
/**
- * Rebuild all files of a containers of a website. Rebuild also the wrapper.php file. TODO Add other files too.
+ * Rebuild all files of all the pages/containers of a website. Rebuild also the index and wrapper.php file.
* Note: Files are already regenerated during importWebSite so this function is useless when importing a website.
*
* @return int <0 if KO, >=0 if OK
@@ -1339,12 +1339,12 @@ class Website extends CommonObject
$aliasesarray[] = $objectpagestatic->pageurl;
}
- // Regenerate all aliases pages (pages with a natural name)
+ // Regenerate also all aliases pages (pages with a natural name) by calling dolSavePageAlias()
if (is_array($aliasesarray)) {
foreach ($aliasesarray as $aliasshortcuttocreate) {
if (trim($aliasshortcuttocreate)) {
$filealias = $conf->website->dir_output.'/'.$object->ref.'/'.trim($aliasshortcuttocreate).'.php';
- $result = dolSavePageAlias($filealias, $object, $objectpagestatic);
+ $result = dolSavePageAlias($filealias, $object, $objectpagestatic); // This includes also a copy into sublanguage directories.
if (!$result) {
$this->errors[] = 'Failed to write file '.basename($filealias);
$error++;
@@ -1357,10 +1357,15 @@ class Website extends CommonObject
}
if (!$error) {
- // Save wrapper.php
+ // Save index.php and wrapper.php
$pathofwebsite = $conf->website->dir_output.'/'.$object->ref;
+ $fileindex = $pathofwebsite.'/index.php';
+ $filetpl = '';
+ if ($object->fk_default_home) {
+ $filetpl = $pathofwebsite.'/page'.$object->fk_default_home.'.tpl.php';
+ }
$filewrapper = $pathofwebsite.'/wrapper.php';
- dolSaveIndexPage($pathofwebsite, '', '', $filewrapper);
+ dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper, $object); // This includes also a version of index.php into sublanguage directories
}
if ($error) {
diff --git a/htdocs/website/index.php b/htdocs/website/index.php
index 8ac4d612264..12292cf2fd8 100644
--- a/htdocs/website/index.php
+++ b/htdocs/website/index.php
@@ -1087,7 +1087,7 @@ if ($action == 'addcontainer' && $usercanedit) {
$filetpl = $pathofwebsite.'/page'.$pageid.'.tpl.php';
// Generate the index.php page (to be the home page) and the wrapper.php file
- $result = dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper);
+ $result = dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper, $object);
if ($result <= 0) {
setEventMessages('Failed to write file '.$fileindex, null, 'errors');
@@ -1580,7 +1580,7 @@ if ($action == 'updatecss' && $usercanedit) {
// Save wrapper.php
- $result = dolSaveIndexPage($pathofwebsite, '', '', $filewrapper);
+ $result = dolSaveIndexPage($pathofwebsite, '', '', $filewrapper, $object);
// Message if no error
@@ -1621,7 +1621,7 @@ if ($action == 'setashome' && $usercanedit) {
$filetpl = $pathofwebsite.'/page'.$pageid.'.tpl.php';
// Generate the index.php page to be the home page
- $result = dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper);
+ $result = dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper, $object);
if ($result) {
setEventMessages($langs->trans("Saved"), null, 'mesgs');
@@ -2181,7 +2181,7 @@ if ($action == 'regeneratesite' && $usercanedit) {
$pathtomediasinwebsite = $pathofwebsite.'/medias';
if (!is_link(dol_osencode($pathtomediasinwebsite))) {
dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite);
- dol_mkdir(dirname($pathtomediasinwebsite)); // To be sure dir for website exists
+ dol_mkdir(dirname($pathtomediasinwebsite)); // To be sure that the directory for website exists
$result = symlink($pathtomedias, $pathtomediasinwebsite);
if (!$result) {
setEventMessages($langs->trans("ErrorFieldToCreateSymLinkToMedias", $pathtomediasinwebsite, $pathtomedias), null, 'errors');