dolibarr  16.0.5
website.inc.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2017-2019 Laurent Destailleur <eldy@users.sourceforge.net>
3  *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 * or see https://www.gnu.org/
17 */
18 
26 // Load website class
27 include_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php';
28 include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
29 
30 $website = null;
31 $websitepage = null;
32 $weblangs = null;
33 $pagelangs = null;
34 
35 // Detection browser (copy of code from main.inc.php)
36 if (isset($_SERVER["HTTP_USER_AGENT"]) && is_object($conf) && empty($conf->browser->name)) {
37  $tmp = getBrowserInfo($_SERVER["HTTP_USER_AGENT"]);
38  $conf->browser->name = $tmp['browsername'];
39  $conf->browser->os = $tmp['browseros'];
40  $conf->browser->version = $tmp['browserversion'];
41  $conf->browser->layout = $tmp['layout']; // 'classic', 'phone', 'tablet'
42  //var_dump($conf->browser);
43 
44  if ($conf->browser->layout == 'phone') {
45  $conf->dol_no_mouse_hover = 1;
46  }
47 }
48 // Define $website
49 if (!is_object($website)) {
50  $website = new Website($db);
51  $website->fetch(0, $websitekey);
52 }
53 // Define $websitepage if we have $websitepagefile defined
54 if (!$pageid && !empty($websitepagefile)) {
55  $pageid = str_replace(array('.tpl.php', 'page'), array('', ''), basename($websitepagefile));
56  if ($pageid == 'index.php') {
57  $pageid = $website->fk_default_home;
58  }
59 }
60 if (!is_object($websitepage)) {
61  $websitepage = new WebsitePage($db);
62 }
63 // Define $weblangs
64 if (!is_object($weblangs)) {
65  $weblangs = new Translate('', $conf);
66 }
67 if (!is_object($pagelangs)) {
68  $pagelangs = new Translate('', $conf);
69 }
70 if ($pageid > 0) {
71  $websitepage->fetch($pageid);
72 
73  $weblangs->setDefaultLang(GETPOSTISSET('lang') ? GETPOST('lang', 'aZ09') : (empty($_COOKIE['weblangs-shortcode']) ? 'auto' : preg_replace('/[^a-zA-Z0-9_\-]/', '', $_COOKIE['weblangs-shortcode'])));
74  $pagelangs->setDefaultLang($websitepage->lang ? $websitepage->lang : $weblangs->shortlang);
75 
76  if (!defined('USEDOLIBARREDITOR') && (in_array($websitepage->type_container, array('menu', 'other')) || empty($websitepage->status) && !defined('USEDOLIBARRSERVER'))) {
77  $weblangs->load("website");
78  http_response_code(404);
79  print '<center><br><br>'.$weblangs->trans("YouTryToAccessToAFileThatIsNotAWebsitePage", $websitepage->pageurl, $websitepage->type_container, $websitepage->status).'</center>';
80  exit;
81  }
82 }
83 
84 if (!defined('USEDOLIBARRSERVER') && !defined('USEDOLIBARREDITOR')) {
85  header("X-Content-Type-Options: nosniff");
86  if (empty($websitepage->allowed_in_frames) && empty($conf->global->WEBSITE_ALLOW_FRAMES_ON_ALL_PAGES)) {
87  header("X-Frame-Options: SAMEORIGIN");
88  }
89 }
90 
91 // A lang was forced, so we change weblangs init
92 if (GETPOST('l', 'aZ09')) {
93  $weblangs->setDefaultLang(GETPOST('l', 'aZ09'));
94 }
95 // A lang was forced, so we check to find if we must make a redirect on translation page
96 if ($_SERVER['PHP_SELF'] != DOL_URL_ROOT.'/website/index.php') { // If we browsing page using Dolibarr server or a Native web server
97  //print_r(get_defined_constants(true));exit;
98  if (GETPOST('l', 'aZ09')) {
99  $sql = "SELECT wp.rowid, wp.lang, wp.pageurl, wp.fk_page";
100  $sql .= " FROM ".MAIN_DB_PREFIX."website_page as wp";
101  $sql .= " WHERE wp.fk_website = ".((int) $website->id);
102  $sql .= " AND (wp.fk_page = ".((int) $pageid)." OR wp.rowid = ".((int) $pageid);
103  if (is_object($websitepage) && $websitepage->fk_page > 0) {
104  $sql .= " OR wp.fk_page = ".((int) $websitepage->fk_page)." OR wp.rowid = ".((int) $websitepage->fk_page);
105  }
106  $sql .= ")";
107  $sql .= " AND wp.lang = '".$db->escape(GETPOST('l', 'aZ09'))."'";
108 
109  $resql = $db->query($sql);
110  if ($resql) {
111  $obj = $db->fetch_object($resql);
112  if ($obj) {
113  $newpageid = $obj->rowid;
114  if ($newpageid != $pageid) { // To avoid to make a redirect on same page (infinite loop)
115  if (defined('USEDOLIBARRSERVER')) {
116  header("Location: ".DOL_URL_ROOT.'/public/website/index.php?website='.$websitekey.'&pageid='.$newpageid.'&l='.GETPOST('l', 'aZ09'));
117  exit;
118  } else {
119  $newpageref = $obj->pageurl;
120  header("Location: ".(($obj->lang && $obj->lang != $website->lang) ? '/'.$obj->lang.'/' : '/').$newpageref.'.php?l='.GETPOST('l', 'aZ09'));
121  exit;
122  }
123  }
124  }
125  }
126  }
127 }
128 
129 // Show off line message
130 if (!defined('USEDOLIBARREDITOR') && empty($website->status)) {
131  $weblangs->load("website");
132  http_response_code(503);
133  print '<center><br><br>'.$weblangs->trans("SorryWebsiteIsCurrentlyOffLine").'</center>';
134  exit;
135 }
WebsitePage
Class Websitepage.
Definition: websitepage.class.php:36
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
Translate
Class to manage translations.
Definition: translate.class.php:30
getBrowserInfo
getBrowserInfo($user_agent)
Return information about user browser.
Definition: functions.lib.php:260
Website
Class Website.
Definition: website.class.php:36
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742