Can set main language and sublanguages of a website

This commit is contained in:
Laurent Destailleur 2020-02-19 18:32:04 +01:00
parent ace0c7f89d
commit c14daa2790
5 changed files with 107 additions and 7 deletions

View File

@ -44,6 +44,9 @@ ALTER TABLE llx_commande_fournisseur_dispatch_extrafields ADD INDEX idx_commande
-- For v12
ALTER TABLE llx_website ADD COLUMN lang varchar(8);
ALTER TABLE llx_website ADD COLUMN otherlang varchar(255);
ALTER TABLE llx_holiday_users DROP INDEX uk_holiday_users;
ALTER TABLE llx_holiday_users ADD UNIQUE INDEX uk_holiday_users(fk_user, fk_type);

View File

@ -26,6 +26,8 @@ CREATE TABLE llx_website
description varchar(255),
maincolor varchar(16),
maincolorbis varchar(16),
lang varchar(8),
otherlang varchar(255),
status integer DEFAULT 1,
fk_default_home integer,
use_manifest integer,

View File

@ -121,3 +121,6 @@ BackToHomePage=Back to home page...
TranslationLinks=Translation links
YouTryToAccessToAFileThatIsNotAWebsitePage=You try to access to a page that is not a website page
UseTextBetween5And70Chars=For good SEO practices, use a text between 5 and 70 characters
MainLanguage=Main language
OtherLanguages=Other languages
UseManifest=Provide a manifest.json file

View File

@ -70,6 +70,16 @@ class Website extends CommonObject
*/
public $description;
/**
* @var string Main language of web site
*/
public $lang;
/**
* @var string List of languages of web site ('fr', 'es_MX', ...)
*/
public $otherlang;
/**
* @var int Status
*/
@ -171,6 +181,8 @@ class Website extends CommonObject
$sql .= 'entity,';
$sql .= 'ref,';
$sql .= 'description,';
$sql .= 'lang,';
$sql .= 'otherlang,';
$sql .= 'status,';
$sql .= 'fk_default_home,';
$sql .= 'virtualhost,';
@ -181,6 +193,8 @@ class Website extends CommonObject
$sql .= ' '.((empty($this->entity) && $this->entity != '0') ? 'NULL' : $this->entity).',';
$sql .= ' '.(!isset($this->ref) ? 'NULL' : "'".$this->db->escape($this->ref)."'").',';
$sql .= ' '.(!isset($this->description) ? 'NULL' : "'".$this->db->escape($this->description)."'").',';
$sql .= ' '.(!isset($this->lang) ? 'NULL' : "'".$this->db->escape($this->lang)."'").',';
$sql .= ' '.(!isset($this->otherlang) ? 'NULL' : "'".$this->db->escape($this->otherlang)."'").',';
$sql .= ' '.(!isset($this->status) ? '1' : $this->status).',';
$sql .= ' '.(!isset($this->fk_default_home) ? 'NULL' : $this->fk_default_home).',';
$sql .= ' '.(!isset($this->virtualhost) ? 'NULL' : "'".$this->db->escape($this->virtualhost)."'").",";
@ -201,6 +215,16 @@ class Website extends CommonObject
if (!$error) {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
// Create subdirectory per language
$tmplangarray = explode(',', $this->otherlang);
if (is_array($tmplangarray)) {
dol_mkdir($conf->website->dir_output.'/'.$this->ref);
foreach($tmplangarray as $val) {
if (trim($val) == $this->lang) continue;
dol_mkdir($conf->website->dir_output.'/'.$this->ref.'/'.trim($val));
}
}
// Uncomment this and change MYOBJECT to your own tag if you
// want this action to call a trigger.
// if (!$notrigger) {
@ -240,6 +264,8 @@ class Website extends CommonObject
$sql .= " t.entity,";
$sql .= " t.ref,";
$sql .= " t.description,";
$sql .= " t.lang,";
$sql .= " t.otherlang,";
$sql .= " t.status,";
$sql .= " t.fk_default_home,";
$sql .= " t.use_manifest,";
@ -267,6 +293,8 @@ class Website extends CommonObject
$this->entity = $obj->entity;
$this->ref = $obj->ref;
$this->description = $obj->description;
$this->lang = $obj->lang;
$this->otherlang = $obj->otherlang;
$this->status = $obj->status;
$this->fk_default_home = $obj->fk_default_home;
$this->virtualhost = $obj->virtualhost;
@ -332,6 +360,8 @@ class Website extends CommonObject
$sql .= " t.entity,";
$sql .= " t.ref,";
$sql .= " t.description,";
$sql .= " t.lang,";
$sql .= " t.otherlang,";
$sql .= " t.status,";
$sql .= " t.fk_default_home,";
$sql .= " t.virtualhost,";
@ -372,6 +402,8 @@ class Website extends CommonObject
$line->entity = $obj->entity;
$line->ref = $obj->ref;
$line->description = $obj->description;
$line->lang = $obj->lang;
$line->otherlang = $obj->otherlang;
$line->status = $obj->status;
$line->fk_default_home = $obj->fk_default_home;
$line->virtualhost = $obj->virtualhost;
@ -403,6 +435,8 @@ class Website extends CommonObject
*/
public function update(User $user, $notrigger = false)
{
global $conf;
$error = 0;
dol_syslog(__METHOD__, LOG_DEBUG);
@ -430,6 +464,8 @@ class Website extends CommonObject
$sql .= ' entity = '.(isset($this->entity) ? $this->entity : "null").',';
$sql .= ' ref = '.(isset($this->ref) ? "'".$this->db->escape($this->ref)."'" : "null").',';
$sql .= ' description = '.(isset($this->description) ? "'".$this->db->escape($this->description)."'" : "null").',';
$sql .= ' lang = '.(isset($this->lang) ? "'".$this->db->escape($this->lang)."'" : "null").',';
$sql .= ' otherlang = '.(isset($this->otherlang) ? "'".$this->db->escape($this->otherlang)."'" : "null").',';
$sql .= ' status = '.(isset($this->status) ? $this->status : "null").',';
$sql .= ' fk_default_home = '.(($this->fk_default_home > 0) ? $this->fk_default_home : "null").',';
$sql .= ' use_manifest = '.((int) $this->use_manifest).',';
@ -452,6 +488,16 @@ class Website extends CommonObject
// Uncomment this and change MYOBJECT to your own tag if you
// want this action calls a trigger.
// Create subdirectory per language
$tmplangarray = explode(',', $this->otherlang);
if (is_array($tmplangarray)) {
dol_mkdir($conf->website->dir_output.'/'.$this->ref);
foreach($tmplangarray as $val) {
if (trim($val) == $this->lang) continue;
dol_mkdir($conf->website->dir_output.'/'.$this->ref.'/'.trim($val));
}
}
//// Call triggers
//$result=$this->call_trigger('MYOBJECT_MODIFY',$user);
//if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
@ -715,7 +761,8 @@ class Website extends CommonObject
$label = '<u>'.$langs->trans("WebSite").'</u>';
$label .= '<br>';
$label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
$label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref.'<br>';
$label .= '<b>'.$langs->trans('MainLanguage').':</b> '.$this->lang;
$linkstart = '<a href="'.DOL_URL_ROOT.'/website/card.php?id='.$this->id.'"';
$linkstart .= ($notooltip ? '' : ' title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip'.($morecss ? ' '.$morecss : '').'"');
@ -789,6 +836,8 @@ class Website extends CommonObject
$this->entity = 1;
$this->ref = 'myspecimenwebsite';
$this->description = 'A specimen website';
$this->lang = 'en';
$this->otherlang = 'fr,es_MX';
$this->status = '';
$this->fk_default_home = null;
$this->virtualhost = 'http://myvirtualhost';
@ -926,7 +975,7 @@ class Website extends CommonObject
fputs($fp, $line);
// Warning: We must keep llx_ here. It is a generic SQL.
$line = 'INSERT INTO llx_website_page(rowid, fk_page, fk_website, pageurl, aliasalt, title, description, image, keywords, status, date_creation, tms, lang, import_key, grabbed_from, type_container, htmlheader, content)';
$line = 'INSERT INTO llx_website_page(rowid, fk_page, fk_website, pageurl, aliasalt, title, description, lang, otherlang, image, keywords, status, date_creation, tms, lang, import_key, grabbed_from, type_container, htmlheader, content)';
$line .= " VALUES(";
$line .= $objectpageold->newid."__+MAX_llx_website_page__, ";
@ -936,6 +985,8 @@ class Website extends CommonObject
$line .= "'".$this->db->escape($objectpageold->aliasalt)."', ";
$line .= "'".$this->db->escape($objectpageold->title)."', ";
$line .= "'".$this->db->escape($objectpageold->description)."', ";
$line .= "'".$this->db->escape($objectpageold->lang)."', ";
$line .= "'".$this->db->escape($objectpageold->otherlang)."', ";
$line .= "'".$this->db->escape($objectpageold->image)."', ";
$line .= "'".$this->db->escape($objectpageold->keywords)."', ";
$line .= "'".$this->db->escape($objectpageold->status)."', ";

View File

@ -398,7 +398,9 @@ if ($action == 'addsite')
{
$tmpobject = new Website($db);
$tmpobject->ref = GETPOST('WEBSITE_REF', 'alpha');
$tmpobject->description = GETPOST('WEBSITE_DESCRIPTION', 'alpha');
$tmpobject->description = GETPOST('WEBSITE_DESCRIPTION', 'alphanohtml');
$tmpobject->lang = GETPOST('WEBSITE_LANG', 'aZ09');
$tmpobject->otherlang = GETPOST('WEBSITE_OTHERLANG', 'aZ09comma');
$tmpobject->virtualhost = GETPOST('virtualhost', 'alpha');
$result = $tmpobject->create($user);
@ -782,6 +784,8 @@ if ($action == 'addcontainer')
$objectpage->pageurl = GETPOST('WEBSITE_PAGENAME', 'alpha');
$objectpage->aliasalt = GETPOST('WEBSITE_ALIASALT', 'alpha');
$objectpage->description = GETPOST('WEBSITE_DESCRIPTION', 'alpha');
$objectpage->lang = GETPOST('WEBSITE_LANG', 'alpha');
$objectpage->otherlang = GETPOST('WEBSITE_OTHERLANG', 'alpha');
$objectpage->image = GETPOST('WEBSITE_IMAGE', 'alpha');
$objectpage->keywords = GETPOST('WEBSITE_KEYWORDS', 'alpha');
$objectpage->lang = GETPOST('WEBSITE_LANG', 'aZ09');
@ -1060,6 +1064,8 @@ if ($action == 'updatecss')
if (!$error)
{
$object->virtualhost = GETPOST('virtualhost', 'alpha');
$object->lang = GETPOST('WEBSITE_LANG', 'aZ09');
$object->otherlang = GETPOST('WEBSITE_OTHERLANG', 'aZ09comma');
$object->use_manifest = GETPOST('use_manifest', 'alpha');
$result = $object->update($user);
@ -1403,11 +1409,13 @@ if ($action == 'updatemeta')
{
$objectpage->old_object = clone $objectpage;
$objectpage->title = GETPOST('WEBSITE_TITLE', 'alpha');
$objectpage->type_container = GETPOST('WEBSITE_TYPE_CONTAINER', 'alpha');
$objectpage->title = GETPOST('WEBSITE_TITLE', 'alphanohtml');
$objectpage->type_container = GETPOST('WEBSITE_TYPE_CONTAINER', 'alphanohtml');
$objectpage->pageurl = GETPOST('WEBSITE_PAGENAME', 'alpha');
$objectpage->aliasalt = GETPOST('WEBSITE_ALIASALT', 'alpha');
$objectpage->description = GETPOST('WEBSITE_DESCRIPTION', 'alpha');
$objectpage->lang = GETPOST('WEBSITE_LANG', 'aZ09');
$objectpage->otherlang = GETPOST('WEBSITE_OTHERLANG', 'aZ09comma');
$objectpage->description = GETPOST('WEBSITE_DESCRIPTION', 'alphanohtml');
$objectpage->image = GETPOST('WEBSITE_IMAGE', 'alpha');
$objectpage->keywords = GETPOST('WEBSITE_KEYWORDS', 'alpha');
$objectpage->lang = GETPOST('WEBSITE_LANG', 'aZ09');
@ -2691,6 +2699,24 @@ if ($action == 'editcss')
print $websitekey;
print '</td></tr>';
// Main language
print '<tr><td class="tdtop">';
$htmltext='';
print $form->textwithpicto($langs->trans('MainLanguage'), $htmltext, 1, 'help', '', 0, 2, 'WEBSITE_LANG');
print '</td><td>';
print $formadmin->select_language((GETPOSTISSET('WEBSITE_LANG') ? GETPOST('WEBSITE_LANG', 'alpha') : ($object->lang ? $object->lang : $langs->defaultlang)), 'WEBSITE_LANG', 0, 0, 0, 0, 0, 'minwidth300', 2);
print '</td>';
print '</tr>';
// Other languages
print '<tr><td class="tdtop">';
$htmltext= '';
print $form->textwithpicto($langs->trans('OtherLanguages'), $htmltext, 1, 'help', '', 0, 2, 'WEBSITE_OTHERLANG');
print '</td><td>';
print '<input type="text" class="flat" value="'.(GETPOSTISSET('WEBSITE_OTHERLANG') ? GETPOST('WEBSITE_OTHERLANG', 'alpha') : $object->otherlang).'" name="WEBSITE_OTHERLANG">';
print '</td>';
print '</tr>';
// VirtualHost
print '<tr><td class="tdtop">';
@ -2816,8 +2842,11 @@ if ($action == 'createsite')
print '<table class="border centpercent">';
$siteref = $sitedesc = $sitelang = $siteotherlang = '';
if (GETPOST('WEBSITE_REF')) $siteref = GETPOST('WEBSITE_REF', 'alpha');
if (GETPOST('WEBSITE_DESCRIPTION')) $sitedesc = GETPOST('WEBSITE_DESCRIPTION', 'alpha');
if (GETPOST('WEBSITE_LANG')) $sitelang = GETPOST('WEBSITE_LANG', 'aZ09');
if (GETPOST('WEBSITE_OTHERLANG')) $siteotherlang = GETPOST('WEBSITE_OTHERLANG', 'aZ09comma');
print '<tr><td class="titlefieldcreate fieldrequired">';
print $langs->trans('Ref');
@ -2828,7 +2857,19 @@ if ($action == 'createsite')
print '<tr><td>';
print $langs->trans('Description');
print '</td><td>';
print '<input type="text" class="flat minwidth300" name="WEBSITE_DESCRIPTION" value="'.dol_escape_htmltag($sitedesc).'">';
print '<input type="text" class="flat minwidth500" name="WEBSITE_DESCRIPTION" value="'.dol_escape_htmltag($sitedesc).'">';
print '</td></tr>';
print '<tr><td>';
print $langs->trans('MainLanguage');
print '</td><td>';
print $formadmin->select_language((GETPOSTISSET('WEBSITE_LANG') ? GETPOST('WEBSITE_LANG', 'alpha') : $langs->defaultlang), 'WEBSITE_LANG', 0, 0, 0, 0, 0, 'minwidth300', 2);
print '</td></tr>';
print '<tr><td>';
print $langs->trans('OtherLanguages');
print '</td><td>';
print '<input type="text" class="flat minwidth300" name="WEBSITE_OTHERLANG" value="'.dol_escape_htmltag($siteotherlang).'">';
print '</td></tr>';
print '<tr><td>';