From b0569de1660fba102e01856006175e1069624e28 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 14 Oct 2018 18:44:29 +0200 Subject: [PATCH] Work on multilang support --- htdocs/core/website.inc.php | 31 ++++ htdocs/langs/en_US/website.lang | 2 + htdocs/public/website/index.php | 158 +++++++++++---------- htdocs/website/class/websitepage.class.php | 3 + htdocs/website/index.php | 50 ++++++- 5 files changed, 165 insertions(+), 79 deletions(-) diff --git a/htdocs/core/website.inc.php b/htdocs/core/website.inc.php index ac4d6b35988..43c9116cea5 100644 --- a/htdocs/core/website.inc.php +++ b/htdocs/core/website.inc.php @@ -19,6 +19,7 @@ /** * \file htdocs/core/website.inc.php * \brief Common file loaded by all website pages (after master.inc.php). It set the new object $weblangs, using parameter 'l'. + * This file is included in top of all container pages. * The global variable $websitekey must be defined. */ @@ -34,6 +35,36 @@ if (! is_object($weblangs)) { $weblangs = dol_clone($langs); } + +// A lang was forced, so we change weblangs init if (GETPOST('l','aZ09')) $weblangs->setDefaultLang(GETPOST('l','aZ09')); +// A lang was forced, so we check to find if we must make a redirect on translation page +if (! defined('USEDOLIBARREDITOR')) +{ + if (GETPOST('l','aZ09')) + { + $sql ="SELECT wp.rowid, wp.lang, wp.pageurl, wp.fk_page"; + $sql.=" FROM ".MAIN_DB_PREFIX."website_page as wp, ".MAIN_DB_PREFIX."website as w"; + $sql.=" WHERE w.rowid = wp.fk_website AND w.ref = '".$db->escape($websitekey)."' AND fk_page = '".$db->escape($pageid)."' AND lang = '".$db->escape(GETPOST('l','aZ09'))."'"; + $resql = $db->query($sql); + if ($resql) + { + $obj = $db->fetch_object($resql); + if ($obj) + { + //$pageid = $obj->rowid; + //$pageref = $obj->pageurl; + if (! defined('USEDOLIBARRSERVER')) { + // TODO Redirect + } + else + { + // TODO Redirect + } + } + } + } +} + // Load websitepage class include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php'; diff --git a/htdocs/langs/en_US/website.lang b/htdocs/langs/en_US/website.lang index 55db08c3785..a14d05132cd 100644 --- a/htdocs/langs/en_US/website.lang +++ b/htdocs/langs/en_US/website.lang @@ -91,3 +91,5 @@ ExternalURLMustStartWithHttp=External URL must start with http:// or https:// ZipOfWebsitePackageToImport=Zip file of website package ShowSubcontainers=Show included containers InternalURLOfPage=Internal URL of page +ThisPageIsTranslationOf=This page/container is translation of +ThisPageHasTranslationPages=This page/container has translation \ No newline at end of file diff --git a/htdocs/public/website/index.php b/htdocs/public/website/index.php index 862d8ada71a..19abc48094b 100644 --- a/htdocs/public/website/index.php +++ b/htdocs/public/website/index.php @@ -18,8 +18,7 @@ /** * \file htdocs/public/website/index.php * \ingroup website - * \brief Page to output pages - * \author Laurent Destailleur + * \brief Wrapper to output pages when website is powered by Dolibarr instead of a native web server */ if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); // Disables token renewal @@ -59,88 +58,91 @@ $accessallowed = 1; $type=''; -/* - * View - */ +if (empty($pageid)) +{ + require_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php'; + require_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php'; + + $object=new Website($db); + $object->fetch(0, $websitekey); + + if (empty($object->id)) + { + if (empty($pageid)) + { + // Return header 404 + header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found", true, 404); + + include DOL_DOCUMENT_ROOT.'/public/error-404.php'; + exit; + } + } + + $objectpage=new WebsitePage($db); + + if ($pageref) + { + $result=$objectpage->fetch(0, $object->id, $pageref); + if ($result > 0) + { + $pageid = $objectpage->id; + } + elseif($result == 0) + { + // Page not found from ref=pageurl, we try using alternative alias + $result=$objectpage->fetch(0, $object->id, null, $pageref); + if ($result > 0) + { + $pageid = $objectpage->id; + } + } + } + else + { + if ($object->fk_default_home > 0) + { + $result=$objectpage->fetch($object->fk_default_home); + if ($result > 0) + { + $pageid = $objectpage->id; + } + } + + if (empty($pageid)) + { + $array=$objectpage->fetchAll($object->id); + if (is_array($array) && count($array) > 0) + { + $firstrep=reset($array); + $pageid=$firstrep->id; + } + } + } +} +if (empty($pageid)) +{ + // Return header 404 + header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found", true, 404); + + $langs->load("website"); + + if (! GETPOSTISSET('pageref')) print $langs->trans("PreviewOfSiteNotYetAvailable", $websitekey); + + include DOL_DOCUMENT_ROOT.'/public/error-404.php'; + exit; +} $appli=constant('DOL_APPLICATION_TITLE'); if (!empty($conf->global->MAIN_APPLICATION_TITLE)) $appli=$conf->global->MAIN_APPLICATION_TITLE; + + +/* + * View + */ + //print 'Directory with '.$appli.' websites.
'; -if (empty($pageid)) -{ - require_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php'; - require_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php'; - - $object=new Website($db); - $object->fetch(0, $websitekey); - - if (empty($object->id)) - { - if (empty($pageid)) - { - // Return header 404 - header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found", true, 404); - - include DOL_DOCUMENT_ROOT.'/public/error-404.php'; - exit; - } - } - - $objectpage=new WebsitePage($db); - - if ($pageref) - { - $result=$objectpage->fetch(0, $object->id, $pageref); - if ($result > 0) - { - $pageid = $objectpage->id; - } - elseif($result == 0) - { - // Page not found from ref=pageurl, we try using alternative alias - $result=$objectpage->fetch(0, $object->id, null, $pageref); - if ($result > 0) - { - $pageid = $objectpage->id; - } - } - } - else - { - if ($object->fk_default_home > 0) - { - $result=$objectpage->fetch($object->fk_default_home); - if ($result > 0) - { - $pageid = $objectpage->id; - } - } - - if (empty($pageid)) - { - $array=$objectpage->fetchAll($object->id); - if (is_array($array) && count($array) > 0) - { - $firstrep=reset($array); - $pageid=$firstrep->id; - } - } - } -} -if (empty($pageid)) -{ - // Return header 404 - header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found", true, 404); - - $langs->load("website"); - - if (! GETPOSTISSET('pageref')) print $langs->trans("PreviewOfSiteNotYetAvailable", $websitekey); - - include DOL_DOCUMENT_ROOT.'/public/error-404.php'; - exit; -} // Security: Delete string ../ into $original_file global $dolibarr_main_data_root; diff --git a/htdocs/website/class/websitepage.class.php b/htdocs/website/class/websitepage.class.php index 4277a03167d..79ff3bc789d 100644 --- a/htdocs/website/class/websitepage.class.php +++ b/htdocs/website/class/websitepage.class.php @@ -193,8 +193,11 @@ class WebsitePage extends CommonObject $this->fk_website = $obj->fk_website; $this->type_container = $obj->type_container; + $this->pageurl = $obj->pageurl; + $this->ref = $obj->pageurl; $this->aliasalt = preg_replace('/,+$/', '', preg_replace('/^,+/', '', $obj->aliasalt)); + $this->title = $obj->title; $this->description = $obj->description; $this->keywords = $obj->keywords; diff --git a/htdocs/website/index.php b/htdocs/website/index.php index 65a17be6281..e9e14c4f888 100644 --- a/htdocs/website/index.php +++ b/htdocs/website/index.php @@ -1926,10 +1926,11 @@ if (count($object->records) > 0) // There is at least one web site // Create an array for form $preselectedlanguage = GETPOST('newlang', 'az09') ? GETPOST('newlang', 'az09') : ($objectpage->lang ? $objectpage->lang : $langs->defaultlang); $formquestion = array( - array('type' => 'text', 'tdclass'=>'maxwidth200', 'name' => 'pageurl', 'label'=> $langs->trans("WEBSITE_PAGENAME"), 'value'=> 'copy_of_'.$objectpage->pageurl), + array('type' => 'hidden', 'name' => 'sourcepageurl', 'value'=> $objectpage->pageurl), array('type' => 'checkbox', 'tdclass'=>'maxwidth200', 'name' => 'is_a_translation', 'label' => $langs->trans("PageIsANewTranslation"), 'value' => 0), array('type' => 'other','name' => 'newlang', 'label' => $langs->trans("Language"), 'value' => $formadmin->select_language($preselectedlanguage, 'newlang', 0, null, 1, 0, 0, 'minwidth200', 0, 1)), array('type' => 'other','name' => 'newwebsite', 'label' => $langs->trans("WebSite"), 'value' => $formwebsite->selectWebsite($object->id, 'newwebsite', 0)), + array('type' => 'text', 'tdclass'=>'maxwidth200 fieldrequired', 'name' => 'pageurl', 'label'=> $langs->trans("WEBSITE_PAGENAME"), 'value'=> 'copy_of_'.$objectpage->pageurl), ); $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?website='.$object->ref.'&pageid=' . $pageid, $langs->trans('ClonePage'), '', 'confirm_createpagefromclone', $formquestion, 0, 1, 300, 550); @@ -2518,6 +2519,53 @@ if ($action == 'editmeta' || $action == 'createcontainer') print $formadmin->select_language($pagelang?$pagelang:$langs->defaultlang, 'WEBSITE_LANG', 0, null, '1'); print ''; + if ($action != 'createcontainer') + { + // Translation of + if ($objectpage->fk_page > 0) + { + print ''; + print $langs->trans('ThisPageIsTranslationOf'); + print ''; + $sourcepage=new WebsitePage($db); + $result = $sourcepage->fetch($objectpage->fk_page); + if ($result == 0) // not found, we can reset value + { + + } + elseif ($result > 0) + { + print $sourcepage->getNomUrl(1); + } + print ''; + } + + // Has translation pages + $sql='SELECT rowid, lang from '.MAIN_DB_PREFIX.'website_page where fk_page = '.$objectpage->id; + $resql = $db->query($sql); + if ($resql) + { + $num_rows = $db->num_rows($resql); + if ($num_rows > 0) + { + print ''; + print $langs->trans('ThisPageHasTranslationPages'); + print ''; + $i=0; + while ($obj = $db->fetch_object($resql)) + { + $tmppage=new WebsitePage($db); + $tmppage->fetch($obj->rowid); + if ($i > 0) print ' - '; + print $tmppage->getNomUrl(1).' ('.$tmppage->lang.')'; + $i++; + } + print ''; + } + } + else dol_print_error($db); + } + print ''; $htmlhelp=$langs->trans("WEBSITE_ALIASALTDesc"); print $form->textwithpicto($langs->trans('WEBSITE_ALIASALT'), $htmlhelp, 1, 'help', '', 0, 2, 'htmlheadertooltip');