dolibarr/htdocs/core/website.inc.php

141 lines
5.0 KiB
PHP
Raw Normal View History

<?php
/* Copyright (C) 2017-2019 Laurent Destailleur <eldy@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* or see https://www.gnu.org/
*/
/**
* \file htdocs/core/website.inc.php
2018-10-03 19:53:33 +02:00
* \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 and is run only when a web page is called.
2018-09-25 16:35:59 +02:00
* The global variable $websitekey must be defined.
*/
2018-10-03 20:58:45 +02:00
// Load website class
2017-10-20 23:48:42 +02:00
include_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php';
include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
// Detection browser (copy of code from main.inc.php)
if (isset($_SERVER["HTTP_USER_AGENT"]) && is_object($conf) && empty($conf->browser->name))
{
$tmp = getBrowserInfo($_SERVER["HTTP_USER_AGENT"]);
$conf->browser->name = $tmp['browsername'];
$conf->browser->os = $tmp['browseros'];
$conf->browser->version = $tmp['browserversion'];
$conf->browser->layout = $tmp['layout']; // 'classic', 'phone', 'tablet'
//var_dump($conf->browser);
if ($conf->browser->layout == 'phone') $conf->dol_no_mouse_hover = 1;
}
2018-10-16 01:39:04 +02:00
// Define $website
if (!is_object($website))
2018-10-03 20:58:45 +02:00
{
$website = new Website($db);
$website->fetch(0, $websitekey);
2018-10-03 20:58:45 +02:00
}
2018-10-16 01:39:04 +02:00
// Define $websitepage if we have $websitepagefile defined
if (!$pageid && !empty($websitepagefile))
2018-10-16 01:39:04 +02:00
{
$pageid = str_replace(array('.tpl.php', 'page'), array('', ''), basename($websitepagefile));
if ($pageid == 'index.php') $pageid = $website->fk_default_home;
}
if (!is_object($websitepage))
{
$websitepage = new WebsitePage($db);
2018-10-16 01:39:04 +02:00
}
// Define $weblangs
if (!is_object($weblangs))
{
2020-05-08 14:35:03 +02:00
$weblangs = new Translate('', $conf);
}
if (!is_object($pagelangs))
{
$pagelangs = new Translate('', $conf);
}
2018-10-16 01:39:04 +02:00
if ($pageid > 0)
{
$websitepage->fetch($pageid);
2020-05-16 16:27:23 +02:00
$weblangs->setDefaultLang(GETPOSTISSET('lang') ? GETPOST('lang', 'aZ09') : (empty($_COOKIE['weblangs-shortcode']) ? 'auto' : $_COOKIE['weblangs-shortcode']));
$pagelangs->setDefaultLang($websitepage->lang ? $websitepage->lang : $weblangs->shortlang);
if (!defined('USEDOLIBARREDITOR') && in_array($websitepage->type_container, array('menu', 'other')))
{
$weblangs->load("website");
http_response_code(404);
print '<center><br><br>'.$weblangs->trans("YouTryToAccessToAFileThatIsNotAWebsitePage").'</center>';
exit;
}
2018-10-16 01:39:04 +02:00
}
2018-10-14 18:44:29 +02:00
if (!defined('USEDOLIBARRSERVER') && !defined('USEDOLIBARREDITOR')) {
header("X-Content-Type-Options: nosniff");
2019-12-07 15:46:14 +01:00
/* TODO Manage allow_frames flag on websitepage.
if (empty($websitepage->allow_frames) && empty($conf->global->WEBSITE_ALLOW_FRAMES_ON_ALL_PAGES)) {
header("X-Frame-Options: SAMEORIGIN");
}
*/
}
2018-10-14 18:44:29 +02:00
// A lang was forced, so we change weblangs init
if (GETPOST('l', 'aZ09')) $weblangs->setDefaultLang(GETPOST('l', 'aZ09'));
2018-10-14 18:44:29 +02:00
// A lang was forced, so we check to find if we must make a redirect on translation page
2018-10-14 20:04:25 +02:00
if ($_SERVER['PHP_SELF'] != DOL_URL_ROOT.'/website/index.php') // If we browsing page using Dolibarr server or a Native web server
2018-10-14 18:44:29 +02:00
{
2018-10-14 20:04:25 +02:00
//print_r(get_defined_constants(true));exit;
if (GETPOST('l', 'aZ09'))
2018-10-14 18:44:29 +02:00
{
$sql = "SELECT wp.rowid, wp.lang, wp.pageurl, wp.fk_page";
$sql .= " FROM ".MAIN_DB_PREFIX."website_page as wp";
$sql .= " WHERE wp.fk_website = ".$website->id;
$sql .= " AND (wp.fk_page = ".$pageid." OR wp.rowid = ".$pageid;
if (is_object($websitepage) && $websitepage->fk_page > 0) $sql .= " OR wp.fk_page = ".$websitepage->fk_page." OR wp.rowid = ".$websitepage->fk_page;
$sql .= ")";
$sql .= " AND wp.lang = '".$db->escape(GETPOST('l', 'aZ09'))."'";
2018-10-14 23:26:57 +02:00
2018-10-16 01:39:04 +02:00
$resql = $db->query($sql);
if ($resql)
{
$obj = $db->fetch_object($resql);
if ($obj)
2018-10-14 18:44:29 +02:00
{
2018-10-16 01:39:04 +02:00
$newpageid = $obj->rowid;
if ($newpageid != $pageid) // To avoid to make a redirect on same page (infinite loop)
2018-10-14 18:44:29 +02:00
{
2018-10-16 01:39:04 +02:00
if (defined('USEDOLIBARRSERVER')) {
header("Location: ".DOL_URL_ROOT.'/public/website/index.php?website='.$websitekey.'&pageid='.$newpageid.'&l='.GETPOST('l', 'aZ09'));
2018-10-16 01:39:04 +02:00
exit;
}
else
2018-10-14 20:04:25 +02:00
{
2018-10-16 01:39:04 +02:00
$newpageref = $obj->pageurl;
2020-06-06 20:37:17 +02:00
header("Location: ".(($obj->lang && $obj->lang != $website->lang) ? '/'.$obj->lang.'/' : '/').$newpageref.'.php?l='.GETPOST('l', 'aZ09'));
2018-10-16 01:39:04 +02:00
exit;
2018-10-14 20:04:25 +02:00
}
2018-10-14 18:44:29 +02:00
}
}
}
}
}
// Show off line message
if (!defined('USEDOLIBARREDITOR') && empty($website->status))
{
$weblangs->load("website");
http_response_code(503);
print '<center><br><br>'.$weblangs->trans("SorryWebsiteIsCurrentlyOffLine").'</center>';
exit;
}