mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
Add support of language in website module
This commit is contained in:
parent
854a6ca3d5
commit
437d620fe4
|
|
@ -29,5 +29,6 @@ ALTER TABLE llx_facture_fourn ADD COLUMN date_pointoftax date DEFAULT NULL;
|
|||
ALTER TABLE llx_facture_fourn ADD COLUMN date_valid date;
|
||||
|
||||
ALTER TABLE llx_website_page MODIFY COLUMN pageurl varchar(255);
|
||||
|
||||
ALTER TABLE llx_website_page ADD COLUMN lang varchar(6);
|
||||
ALTER TABLE llx_website_page ADD COLUMN fk_page integer;
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ CREATE TABLE llx_website_page
|
|||
title varchar(255),
|
||||
description varchar(255),
|
||||
keywords varchar(255),
|
||||
lang varchar(6),
|
||||
fk_page integer,
|
||||
content mediumtext, -- text is not enough in size
|
||||
status integer,
|
||||
fk_user_create integer,
|
||||
|
|
|
|||
|
|
@ -35,4 +35,7 @@ NoPageYet=No pages yet
|
|||
SyntaxHelp=Help on code syntax
|
||||
YouCanEditHtmlSource=You can edit HTML source code using the "Source" button in editor. You can also include PHP code into this source using tags <strong><?php ?></strong>. The following global variables are available: $conf, $langs, $db, $mysoc, $user, $website.<br><br>You can also include content of another Page/Container with the following syntax: <strong><?php dolIncludeHtmlContent($websitekey.'/contentaliastoinclude.php'); ?></strong><br><br>To include a link to download a file stored into the documents/medias directory, use syntax:<br><strong><a href="/document.php?modulepart=medias&file=filename.ext"></strong>.
|
||||
ClonePage=Clone page/container
|
||||
CloneSite=Clone site
|
||||
CloneSite=Clone site
|
||||
ConfirmClonePage=Please enter code/alias of new page and if it is a translation of the cloned page.
|
||||
PageIsANewTranslation=The new page is a translation of the current page ?
|
||||
LanguageMustNotBeSameThanClonedPage=You clone a page as a translation. The language of the new page must be different than language of source page.
|
||||
|
|
@ -127,6 +127,8 @@ class WebsitePage extends CommonObject
|
|||
$sql.= 'description,';
|
||||
$sql.= 'keywords,';
|
||||
$sql.= 'content,';
|
||||
$sql.= 'lang,';
|
||||
$sql.= 'fk_page,';
|
||||
$sql.= 'status,';
|
||||
$sql.= 'date_creation,';
|
||||
$sql.= 'tms';
|
||||
|
|
@ -137,6 +139,8 @@ class WebsitePage extends CommonObject
|
|||
$sql .= ' '.(! isset($this->description)?'NULL':"'".$this->db->escape($this->description)."'").',';
|
||||
$sql .= ' '.(! isset($this->keywords)?'NULL':"'".$this->db->escape($this->keywords)."'").',';
|
||||
$sql .= ' '.(! isset($this->content)?'NULL':"'".$this->db->escape($this->content)."'").',';
|
||||
$sql .= ' '.(! isset($this->lang)?'NULL':"'".$this->db->escape($this->lang)."'").',';
|
||||
$sql .= ' '.(empty($this->fk_page)?'NULL':$this->db->escape($this->fk_page)).',';
|
||||
$sql .= ' '.(! isset($this->status)?'NULL':$this->status).',';
|
||||
$sql .= ' '.(! isset($this->date_creation) || dol_strlen($this->date_creation)==0?'NULL':"'".$this->db->idate($this->date_creation)."'").',';
|
||||
$sql .= ' '.(! isset($this->date_modification) || dol_strlen($this->date_modification)==0?'NULL':"'".$this->db->idate($this->date_modification)."'");
|
||||
|
|
@ -199,6 +203,8 @@ class WebsitePage extends CommonObject
|
|||
$sql .= " t.description,";
|
||||
$sql .= " t.keywords,";
|
||||
$sql .= " t.content,";
|
||||
$sql .= " t.lang,";
|
||||
$sql .= " t.fk_page,";
|
||||
$sql .= " t.status,";
|
||||
$sql .= " t.date_creation,";
|
||||
$sql .= " t.tms as date_modification";
|
||||
|
|
@ -232,6 +238,8 @@ class WebsitePage extends CommonObject
|
|||
$this->description = $obj->description;
|
||||
$this->keywords = $obj->keywords;
|
||||
$this->content = $obj->content;
|
||||
$this->lang = $obj->lang;
|
||||
$this->fk_page = $obj->fk_page;
|
||||
$this->status = $obj->status;
|
||||
$this->date_creation = $this->db->jdate($obj->date_creation);
|
||||
$this->date_modification = $this->db->jdate($obj->date_modification);
|
||||
|
|
@ -277,6 +285,8 @@ class WebsitePage extends CommonObject
|
|||
$sql .= " t.description,";
|
||||
$sql .= " t.keywords,";
|
||||
$sql .= " t.content,";
|
||||
$sql .= " t.lang,";
|
||||
$sql .= " t.fk_page,";
|
||||
$sql .= " t.status,";
|
||||
$sql .= " t.date_creation,";
|
||||
$sql .= " t.tms as date_modification";
|
||||
|
|
@ -319,6 +329,8 @@ class WebsitePage extends CommonObject
|
|||
$record->description = $obj->description;
|
||||
$record->keywords = $obj->keywords;
|
||||
$record->content = $obj->content;
|
||||
$record->lang = $obj->lang;
|
||||
$record->fk_page = $obj->fk_page;
|
||||
$record->status = $obj->status;
|
||||
$record->date_creation = $this->db->jdate($obj->date_creation);
|
||||
$record->date_modification = $this->db->jdate($obj->date_modification);
|
||||
|
|
@ -385,6 +397,8 @@ class WebsitePage extends CommonObject
|
|||
$sql .= ' description = '.(isset($this->description)?"'".$this->db->escape($this->description)."'":"null").',';
|
||||
$sql .= ' keywords = '.(isset($this->keywords)?"'".$this->db->escape($this->keywords)."'":"null").',';
|
||||
$sql .= ' content = '.(isset($this->content)?"'".$this->db->escape($this->content)."'":"null").',';
|
||||
$sql .= ' lang = '.(isset($this->lang)?"'".$this->db->escape($this->lang)."'":"null").',';
|
||||
$sql .= ' fk_page = '.(empty($this->fk_page)?"null":$this->db->escape($this->fk_page)).',';
|
||||
$sql .= ' status = '.(isset($this->status)?$this->status:"null").',';
|
||||
$sql .= ' date_creation = '.(! isset($this->date_creation) || dol_strlen($this->date_creation) != 0 ? "'".$this->db->idate($this->date_creation)."'" : 'null');
|
||||
$sql .= ', tms = '.(dol_strlen($this->date_modification) != 0 ? "'".$this->db->idate($this->date_modification)."'" : "'".$this->db->idate(dol_now())."'");
|
||||
|
|
@ -482,10 +496,13 @@ class WebsitePage extends CommonObject
|
|||
/**
|
||||
* Load an object from its id and create a new one in database
|
||||
*
|
||||
* @param int $fromid Id of object to clone
|
||||
* @return int New id of clone
|
||||
* @param int $fromid Id of object to clone
|
||||
* @param string $newref New ref/alias of page
|
||||
* @param string $newlang New language
|
||||
* @param int $istranslation 1=New page is a translation of the cloned page.
|
||||
* @return int New id of clone
|
||||
*/
|
||||
public function createFromClone($fromid)
|
||||
public function createFromClone($fromid, $newref, $newlang='', $istranslation=0)
|
||||
{
|
||||
global $user, $langs;
|
||||
|
||||
|
|
@ -502,9 +519,12 @@ class WebsitePage extends CommonObject
|
|||
$object->id = 0;
|
||||
|
||||
// Clear fields
|
||||
$object->ref = 'copy_of_'.$object->ref;
|
||||
$object->pageurl = 'copy_of_'.$object->pageurl;
|
||||
$object->ref = $newref;
|
||||
$object->pageurl = $newref;
|
||||
$object->title = $langs->trans("CopyOf").' '.$object->title;
|
||||
if (! empty($newlang)) $object->lang=$newlang;
|
||||
if ($istranslation) $object->fk_page = $fromid;
|
||||
else $object->fk_page = 0;
|
||||
|
||||
// Create clone
|
||||
$result = $object->create($user);
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ require '../main.inc.php';
|
|||
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/websites/class/website.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/websites/class/websitepage.class.php';
|
||||
|
||||
|
|
@ -163,7 +164,8 @@ if ($action == 'add')
|
|||
$objectpage->title = GETPOST('WEBSITE_TITLE');
|
||||
$objectpage->pageurl = GETPOST('WEBSITE_PAGENAME');
|
||||
$objectpage->description = GETPOST('WEBSITE_DESCRIPTION');
|
||||
$objectpage->keywords = GETPOST('WEBSITE_KEYWORD');
|
||||
$objectpage->keywords = GETPOST('WEBSITE_KEYWORDS');
|
||||
$objectpage->lang = GETPOST('WEBSITE_LANG');
|
||||
|
||||
if (empty($objectpage->pageurl))
|
||||
{
|
||||
|
|
@ -404,6 +406,7 @@ if ($action == 'updatemeta')
|
|||
$objectpage->title = GETPOST('WEBSITE_TITLE');
|
||||
$objectpage->description = GETPOST('WEBSITE_DESCRIPTION');
|
||||
$objectpage->keywords = GETPOST('WEBSITE_KEYWORDS');
|
||||
$objectpage->lang = GETPOST('WEBSITE_LANG');
|
||||
|
||||
$res = $objectpage->update($user);
|
||||
if (! $res > 0)
|
||||
|
|
@ -524,58 +527,78 @@ if ($action == 'updatemeta')
|
|||
}
|
||||
|
||||
// Update page
|
||||
if (($action == 'updatecontent' || $action == 'createpagefromclone')
|
||||
if (($action == 'updatecontent' || $action == 'confirm_createpagefromclone')
|
||||
|| ($action == 'preview' && (GETPOST('refreshsite') || GETPOST('refreshpage') || GETPOST('preview'))))
|
||||
{
|
||||
$object->fetch(0, $website);
|
||||
|
||||
if ($action == 'createpagefromclone')
|
||||
if ($action == 'confirm_createpagefromclone')
|
||||
{
|
||||
$objectpage = new WebsitePage($db);
|
||||
$result = $objectpage->createFromClone($pageid);
|
||||
if ($result < 0)
|
||||
$istranslation=(GETPOST('is_a_translation','aZ09')=='on'?1:0);
|
||||
if ($istranslation)
|
||||
{
|
||||
setEventMessages($objectpage->error, $objectpage->errors, 'errors');
|
||||
$action='preview';
|
||||
if (GETPOST('newlang','aZ09') == $objectpage->lang)
|
||||
{
|
||||
$error++;
|
||||
setEventMessages($langs->trans("LanguageMustNotBeSameThanClonedPage"), null, 'errors');
|
||||
$action='preview';
|
||||
}
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$objectpage = new WebsitePage($db);
|
||||
$result = $objectpage->createFromClone($pageid, GETPOST('pageurl','aZ09'), (GETPOST('newlang','aZ09')?GETPOST('newlang','aZ09'):''), $istranslation);
|
||||
if ($result < 0)
|
||||
{
|
||||
$error++;
|
||||
setEventMessages($objectpage->error, $objectpage->errors, 'errors');
|
||||
$action='createpagefromclone';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check symlink to medias and restore it if ko
|
||||
$pathtomedias=DOL_DATA_ROOT.'/medias';
|
||||
$pathtomediasinwebsite=$pathofwebsite.'/medias';
|
||||
if (! is_link(dol_osencode($pathtomediasinwebsite)))
|
||||
$res = 0;
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite);
|
||||
dol_mkdir(dirname($pathtomediasinwebsite)); // To be sure dir for website exists
|
||||
$result = symlink($pathtomedias, $pathtomediasinwebsite);
|
||||
// Check symlink to medias and restore it if ko
|
||||
$pathtomedias=DOL_DATA_ROOT.'/medias';
|
||||
$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
|
||||
$result = symlink($pathtomedias, $pathtomediasinwebsite);
|
||||
}
|
||||
|
||||
/*if (GETPOST('savevirtualhost') && $object->virtualhost != GETPOST('previewsite'))
|
||||
{
|
||||
$object->virtualhost = GETPOST('previewsite', 'alpha');
|
||||
$object->update($user);
|
||||
}*/
|
||||
|
||||
$objectpage->fk_website = $object->id;
|
||||
|
||||
if ($pageid > 0)
|
||||
{
|
||||
$res = $objectpage->fetch($pageid);
|
||||
}
|
||||
else
|
||||
{
|
||||
$res=0;
|
||||
if ($object->fk_default_home > 0)
|
||||
{
|
||||
$res = $objectpage->fetch($object->fk_default_home);
|
||||
}
|
||||
if (! ($res > 0))
|
||||
{
|
||||
$res = $objectpage->fetch(0, $object->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*if (GETPOST('savevirtualhost') && $object->virtualhost != GETPOST('previewsite'))
|
||||
{
|
||||
$object->virtualhost = GETPOST('previewsite', 'alpha');
|
||||
$object->update($user);
|
||||
}*/
|
||||
|
||||
$objectpage->fk_website = $object->id;
|
||||
|
||||
if ($pageid > 0)
|
||||
{
|
||||
$res = $objectpage->fetch($pageid);
|
||||
}
|
||||
else
|
||||
{
|
||||
$res=0;
|
||||
if ($object->fk_default_home > 0)
|
||||
{
|
||||
$res = $objectpage->fetch($object->fk_default_home);
|
||||
}
|
||||
if (! ($res > 0))
|
||||
{
|
||||
$res = $objectpage->fetch(0, $object->id);
|
||||
}
|
||||
}
|
||||
|
||||
if ($res > 0)
|
||||
if (! $error && $res > 0)
|
||||
{
|
||||
if ($action == 'updatecontent')
|
||||
{
|
||||
|
|
@ -709,7 +732,7 @@ if (($action == 'updatecontent' || $action == 'createpagefromclone')
|
|||
}
|
||||
else
|
||||
{
|
||||
setEventMessages($langs->trans("NoPageYet"), null, 'warnings');
|
||||
if (! $error) setEventMessages($langs->trans("NoPageYet"), null, 'warnings');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -720,6 +743,7 @@ if (($action == 'updatecontent' || $action == 'createpagefromclone')
|
|||
*/
|
||||
|
||||
$form = new Form($db);
|
||||
$formadmin = new FormAdmin($db);
|
||||
|
||||
$help_url='';
|
||||
|
||||
|
|
@ -916,13 +940,26 @@ if (count($object->records) > 0)
|
|||
|
||||
print '<input type="submit" class="button" name="refreshpage" value="'.$langs->trans("Load").'"'.($atleastonepage?'':' disabled="disabled"').'>';
|
||||
|
||||
if ($action == 'preview')
|
||||
if ($action == 'preview' || $action == 'createpagefromclone')
|
||||
{
|
||||
$disabled='';
|
||||
if (empty($user->rights->websites->write)) $disabled=' disabled="disabled"';
|
||||
|
||||
if ($pageid > 0)
|
||||
{
|
||||
// Confirmation to delete
|
||||
if ($action == 'createpagefromclone') {
|
||||
// Create an array for form
|
||||
$formquestion = array(
|
||||
array('type' => 'text', 'name' => 'pageurl', 'label'=> $langs->trans("WEBSITE_PAGENAME") ,'value'=> 'copy_of_'.$objectpage->pageurl),
|
||||
array('type' => 'checkbox', 'name' => 'is_a_translation', 'label' => $langs->trans("PageIsANewTranslation"), 'value' => 0),
|
||||
array('type' => 'other','name' => 'newlang','label' => $langs->trans("Language"), 'value' => $formadmin->select_language(GETPOST('newlang', 'az09')?GETPOST('newlang', 'az09'):$langs->defaultlang, 'newlang', 0, null, '', 0, 0, 'minwidth200')));
|
||||
|
||||
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?pageid=' . $pageid, $langs->trans('ClonePage'), '', 'confirm_createpagefromclone', $formquestion, 0, 1, 250);
|
||||
|
||||
print $formconfirm;
|
||||
}
|
||||
|
||||
print ' ';
|
||||
|
||||
print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditPageContent")).'" name="editcontent">';
|
||||
|
|
@ -938,7 +975,7 @@ if (count($object->records) > 0)
|
|||
|
||||
print '<div class="websitetools">';
|
||||
|
||||
if ($website && $pageid > 0 && $action == 'preview')
|
||||
if ($website && $pageid > 0 && ($action == 'preview' || $action == 'createpagefromclone'))
|
||||
{
|
||||
$websitepage = new WebSitePage($db);
|
||||
$websitepage->fetch($pageid);
|
||||
|
|
@ -965,7 +1002,7 @@ if (count($object->records) > 0)
|
|||
|
||||
// TODO Add js to save alias like we save virtual host name and use dynamic virtual host for url of id=previewpageext
|
||||
}
|
||||
if (! in_array($action, array('editcss','editmenu','create')))
|
||||
if (! in_array($action, array('editcss','editmenu','create','createpagefromclone')))
|
||||
{
|
||||
if (preg_match('/^create/',$action)) print '<input type="submit" id="savefile" class="button" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
|
||||
if (preg_match('/^edit/',$action)) print '<input type="submit" id="savefile" class="button" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
|
||||
|
|
@ -984,7 +1021,7 @@ if (count($object->records) > 0)
|
|||
|
||||
|
||||
|
||||
if ($action == 'preview')
|
||||
if ($action == 'preview' || $action == 'createpagefromclone')
|
||||
{
|
||||
// Adding jquery code to change on the fly url of preview ext
|
||||
if (! empty($conf->use_javascript_ajax))
|
||||
|
|
@ -1126,38 +1163,46 @@ if ($action == 'editmeta' || $action == 'create')
|
|||
print '</td><td>';
|
||||
print '/public/websites/index.php?website='.urlencode($website).'&pageid='.urlencode($pageid);
|
||||
print '</td></tr>';
|
||||
$pageurl=dol_escape_htmltag($objectpage->pageurl);
|
||||
$pagetitle=dol_escape_htmltag($objectpage->title);
|
||||
$pagedescription=dol_escape_htmltag($objectpage->description);
|
||||
$pagekeywords=dol_escape_htmltag($objectpage->keywords);
|
||||
$pageurl=$objectpage->pageurl;
|
||||
$pagetitle=$objectpage->title;
|
||||
$pagedescription=$objectpage->description;
|
||||
$pagekeywords=$objectpage->keywords;
|
||||
$pagelang=$objectpage->lang;
|
||||
}
|
||||
if (GETPOST('WEBSITE_PAGENAME')) $pageurl=GETPOST('WEBSITE_PAGENAME');
|
||||
if (GETPOST('WEBSITE_TITLE')) $pagetitle=GETPOST('WEBSITE_TITLE');
|
||||
if (GETPOST('WEBSITE_DESCRIPTION')) $pagedescription=GETPOST('WEBSITE_DESCRIPTION');
|
||||
if (GETPOST('WEBSITE_KEYWORDS')) $pagekeywords=GETPOST('WEBSITE_KEYWORDS');
|
||||
if (GETPOST('WEBSITE_PAGENAME')) $pageurl=GETPOST('WEBSITE_PAGENAME','alpha');
|
||||
if (GETPOST('WEBSITE_TITLE')) $pagetitle=GETPOST('WEBSITE_TITLE','alpha');
|
||||
if (GETPOST('WEBSITE_DESCRIPTION')) $pagedescription=GETPOST('WEBSITE_DESCRIPTION','alpha');
|
||||
if (GETPOST('WEBSITE_KEYWORDS')) $pagekeywords=GETPOST('WEBSITE_KEYWORDS','alpha');
|
||||
if (GETPOST('WEBSITE_LANG')) $pagelang=GETPOST('WEBSITE_LANG','aZ09');
|
||||
|
||||
print '<tr><td class="titlefieldcreate fieldrequired">';
|
||||
print $langs->trans('WEBSITE_PAGENAME');
|
||||
print '</td><td>';
|
||||
print '<input type="text" class="flat" size="96" name="WEBSITE_PAGENAME" value="'.$pageurl.'">';
|
||||
print '<input type="text" class="flat" size="96" name="WEBSITE_PAGENAME" value="'.dol_escape_htmltag($pageurl).'">';
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td class="fieldrequired">';
|
||||
print $langs->trans('WEBSITE_TITLE');
|
||||
print '</td><td>';
|
||||
print '<input type="text" class="flat" size="96" name="WEBSITE_TITLE" value="'.$pagetitle.'">';
|
||||
print '<input type="text" class="flat" size="96" name="WEBSITE_TITLE" value="'.dol_escape_htmltag($pagetitle).'">';
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td>';
|
||||
print $langs->trans('WEBSITE_DESCRIPTION');
|
||||
print '</td><td>';
|
||||
print '<input type="text" class="flat" size="96" name="WEBSITE_DESCRIPTION" value="'.$pagedescription.'">';
|
||||
print '<input type="text" class="flat" size="96" name="WEBSITE_DESCRIPTION" value="'.dol_escape_htmltag($pagedescription).'">';
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td>';
|
||||
print $langs->trans('WEBSITE_KEYWORDS');
|
||||
print '</td><td>';
|
||||
print '<input type="text" class="flat" size="128" name="WEBSITE_KEYWORDS" value="'.$pagekeywords.'">';
|
||||
print '<input type="text" class="flat" size="128" name="WEBSITE_KEYWORDS" value="'.dol_escape_htmltag($pagekeywords).'">';
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td>';
|
||||
print $langs->trans('Language');
|
||||
print '</td><td>';
|
||||
print $formadmin->select_language($pagelang?$pagelang:$langs->defaultlang, 'WEBSITE_LANG');
|
||||
print '</td></tr>';
|
||||
|
||||
print '</table>';
|
||||
|
|
@ -1204,7 +1249,7 @@ print "</div>\n</form>\n";
|
|||
|
||||
|
||||
|
||||
if ($action == 'preview')
|
||||
if ($action == 'preview' || $action == 'createpagefromclone')
|
||||
{
|
||||
if ($pageid > 0)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user