diff --git a/htdocs/websites/index.php b/htdocs/websites/index.php
index 15fed80ebf7..712a5a2dabb 100644
--- a/htdocs/websites/index.php
+++ b/htdocs/websites/index.php
@@ -529,52 +529,8 @@ if ($action == 'updatemeta')
if (! $result) setEventMessages('Failed to write file '.$filealias, null, 'errors');
-
- // Now create the .tpl file (duplicate code with actions updatesource or updatecontent but we need this to save new header)
- dol_syslog("We regenerate the tpl page filetpl=".$filetpl);
-
- dol_delete_file($filetpl);
-
- // TODO Same code than into updatesource updatecontent
- $tplcontent ='';
- $tplcontent.= "\n";
- $tplcontent.= ''."\n";
- $tplcontent.= '
'."\n";
- $tplcontent.= ''.dol_string_nohtmltag($objectpage->title, 0, 'UTF-8').''."\n";
- $tplcontent.= ''."\n";
- $tplcontent.= ''."\n";
- $tplcontent.= ''."\n";
- $tplcontent.= ''."\n";
- $tplcontent.= ''."\n";
- $tplcontent.= ''."\n";
- $tplcontent.= ''."\n";
- $tplcontent.= ''."\n";
- $tplcontent.= ''."\n";
- $tplcontent.= ''."\n";
- $tplcontent.= ''."\n";
- $tplcontent.= ''."\n";
- $tplcontent.= 'ref.'/htmlheader.html"); ?>'."\n";
- $tplcontent.= ''."\n";
-
- $tplcontent.= ''."\n";
- $tplcontent.= ''."\n";
- $tplcontent.= $objectpage->content."\n";
- $tplcontent.= ''."\n";
-
- $tplcontent.= '"."\n";
-
- //var_dump($filetpl);exit;
- $result = file_put_contents($filetpl, $tplcontent);
- if (! empty($conf->global->MAIN_UMASK))
- @chmod($filetpl, octdec($conf->global->MAIN_UMASK));
+ // Save page of content
+ $result=dolSavePageContent($filetpl, $object, $objectpage);
if ($result)
{
@@ -582,7 +538,12 @@ if ($action == 'updatemeta')
//header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website.'&pageid='.$pageid);
//exit;
}
- else setEventMessages('Failed to write file '.$filetpl, null, 'errors');
+ else
+ {
+ setEventMessages('Failed to write file '.$filetpl, null, 'errors');
+ //header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website.'&pageid='.$pageid);
+ //exit;
+ }
$action='preview';
}
@@ -730,48 +691,8 @@ if (($action == 'updatesource' || $action == 'updatecontent' || $action == 'conf
if (! $result) setEventMessages('Failed to write file '.$filealias, null, 'errors');
- // Now create the .tpl file with code to be able to make dynamic changes
- dol_delete_file($filetpl);
-
- // TODO Same code than into updatemeta
- $tplcontent ='';
- $tplcontent.= "\n";
- $tplcontent.= ''."\n";
- $tplcontent.= ''."\n";
- $tplcontent.= ''.dol_string_nohtmltag($objectpage->title, 0, 'UTF-8').''."\n";
- $tplcontent.= ''."\n";
- $tplcontent.= ''."\n";
- $tplcontent.= ''."\n";
- $tplcontent.= ''."\n";
- $tplcontent.= ''."\n";
- $tplcontent.= ''."\n";
- $tplcontent.= ''."\n";
- $tplcontent.= ''."\n";
- $tplcontent.= ''."\n";
- $tplcontent.= ''."\n";
- $tplcontent.= ''."\n";
- $tplcontent.= 'ref.'/htmlheader.html"); ?>'."\n";
- $tplcontent.= ''."\n";
-
- $tplcontent.= ''."\n";
- $tplcontent.= ''."\n";
- $tplcontent.= $objectpage->content."\n";
- $tplcontent.= ''."\n";
-
- $tplcontent.= '"."\n";
-
- //var_dump($filetpl);exit;
- $result = file_put_contents($filetpl, $tplcontent);
- if (! empty($conf->global->MAIN_UMASK))
- @chmod($filetpl, octdec($conf->global->MAIN_UMASK));
+ // Save page content
+ $result=dolSavePageContent($filetpl, $object, $objectpage);
if ($result)
{
@@ -1447,3 +1368,69 @@ if ($action == 'preview' || $action == 'createpagefromclone')
llxFooter();
$db->close();
+
+
+
+
+/**
+ * Save content of a page on disk
+ *
+ * @param string $filetpl Full path of filename to generate
+ * @param Website $object Object website
+ * @param WebsitePage $objectpage Object websitepage
+ * @return boolean True if OK
+ */
+function dolSavePageContent($filetpl, $object, $objectpage)
+{
+ global $conf;
+
+ // Now create the .tpl file (duplicate code with actions updatesource or updatecontent but we need this to save new header)
+ dol_syslog("We regenerate the tpl page filetpl=".$filetpl);
+
+ dol_delete_file($filetpl);
+
+ // TODO Same code than into updatemeta
+ $shortlangcode = '';
+ if ($objectpage->lang) $shortlangcode=preg_replace('/[_-].*$/', '', $objectpage->lang); // en_US or en-US -> en
+
+ $tplcontent ='';
+ $tplcontent.= "\n";
+ $tplcontent.= ''."\n";
+ $tplcontent.= ''."\n";
+ $tplcontent.= ''.dol_string_nohtmltag($objectpage->title, 0, 'UTF-8').''."\n";
+ $tplcontent.= ''."\n";
+ $tplcontent.= ''."\n";
+ $tplcontent.= ''."\n";
+ $tplcontent.= ''."\n";
+ $tplcontent.= ''."\n";
+ $tplcontent.= ''."\n";
+ $tplcontent.= ''."\n";
+ $tplcontent.= ''."\n";
+ $tplcontent.= ''."\n";
+ $tplcontent.= ''."\n";
+ $tplcontent.= ''."\n";
+ $tplcontent.= 'ref.'/htmlheader.html"); ?>'."\n";
+ $tplcontent.= ''."\n";
+
+ $tplcontent.= ''."\n";
+ $tplcontent.= ''."\n";
+ $tplcontent.= $objectpage->content."\n";
+ $tplcontent.= ''."\n";
+
+ $tplcontent.= '"."\n";
+
+ //var_dump($filetpl);exit;
+ $result = file_put_contents($filetpl, $tplcontent);
+ if (! empty($conf->global->MAIN_UMASK))
+ @chmod($filetpl, octdec($conf->global->MAIN_UMASK));
+
+ return $result;
+}
\ No newline at end of file