2016-01-24 21:17:11 +01:00
< ? php
2017-02-24 21:13:40 +01:00
/* Copyright ( C ) 2016 - 2017 Laurent Destailleur < eldy @ users . sourceforge . net >
2025-02-12 00:52:24 +01:00
* Copyright ( C ) 2024 - 2025 MDW < mdeweerd @ users . noreply . github . com >
2024-07-09 19:28:09 +02:00
* Copyright ( C ) 2024 Frédéric France < frederic . france @ free . fr >
2016-01-24 21:17:11 +01:00
*
* 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 />.
2020-02-21 11:36:16 +01:00
*
* Note about $_SERVER :
* REQUEST_URI : / test / before_rewrite / script . php / path / info ? q = helloword
* PHP_SELF : / test / after_rewrite / script . php / path / info
* QUERY_STRING : q = helloword
* SCRIPT_NAME : / test / after_rewrite / script . php
* PATH_INFO : / path / info
* SCRIPT_FILENAME : / var / www / test / php / script . php
* __FILE__ : / var / www / test / php / script_included . php
2016-01-24 21:17:11 +01:00
*/
/**
2017-10-20 23:48:42 +02:00
* \file htdocs / public / website / index . php
2016-08-08 14:21:43 +02:00
* \ingroup website
2018-10-14 18:44:29 +02:00
* \brief Wrapper to output pages when website is powered by Dolibarr instead of a native web server
2016-01-24 21:17:11 +01:00
*/
2021-02-26 18:58:34 +01:00
if ( ! defined ( 'NOTOKENRENEWAL' )) {
define ( 'NOTOKENRENEWAL' , 1 ); // Disables token renewal
}
if ( ! defined ( 'NOLOGIN' )) {
define ( " NOLOGIN " , 1 );
}
if ( ! defined ( 'NOCSRFCHECK' )) {
define ( " NOCSRFCHECK " , 1 ); // We accept to go on this page from external web site.
}
if ( ! defined ( 'NOREQUIREMENU' )) {
define ( 'NOREQUIREMENU' , '1' );
}
if ( ! defined ( 'NOREQUIREHTML' )) {
define ( 'NOREQUIREHTML' , '1' );
}
if ( ! defined ( 'NOREQUIREAJAX' )) {
define ( 'NOREQUIREAJAX' , '1' );
}
if ( ! defined ( 'NOIPCHECK' )) {
define ( 'NOIPCHECK' , '1' ); // Do not check IP defined into conf $dolibarr_main_restrict_ip
}
if ( ! defined ( 'NOBROWSERNOTIF' )) {
define ( 'NOBROWSERNOTIF' , '1' );
}
2016-05-01 16:34:50 +02:00
/**
* Header empty
*
2025-02-12 00:52:24 +01:00
* Note : also called by functions . lib : recordNotFound
*
2024-07-09 19:28:09 +02:00
* @ param string $head Optional head lines
* @ param string $title HTML title
* @ param string $help_url Url links to help page
* Syntax is : For a wiki page : EN : EnglishPage | FR : FrenchPage | ES : SpanishPage | DE : GermanPage
* For other external page : http :// server / url
* @ param string $target Target to use on links
2025-02-12 00:52:24 +01:00
* @ param int < 0 , 1 > $disablejs More content into html header
* @ param int < 0 , 1 > $disablehead More content into html header
2024-10-27 00:35:14 +02:00
* @ param string [] | string $arrayofjs Array of complementary js files
* @ param string [] | string $arrayofcss Array of complementary css files
2024-07-09 19:28:09 +02:00
* @ param string $morequerystring Query string to add to the link " print " to get same parameters ( use only if autodetect fails )
* @ param string $morecssonbody More CSS on body tag . For example 'classforhorizontalscrolloftabs' .
* @ param string $replacemainareaby Replace call to main_area () by a print of this string
2025-02-12 00:52:24 +01:00
* @ param int < 0 , 1 > $disablenofollow Disable the " nofollow " on meta robot header
* @ param int < 0 , 1 > $disablenoindex Disable the " noindex " on meta robot header
2016-05-01 16:34:50 +02:00
* @ return void
*/
2025-02-12 00:52:24 +01:00
function llxHeader ( $head = '' , $title = '' , $help_url = '' , $target = '' , $disablejs = 0 , $disablehead = 0 , $arrayofjs = '' , $arrayofcss = '' , $morequerystring = '' , $morecssonbody = '' , $replacemainareaby = '' , $disablenofollow = 0 , $disablenoindex = 0 ) // @phan-suppress-current-line PhanRedefineFunction
2018-08-15 14:28:34 +02:00
{
}
2016-05-01 16:34:50 +02:00
/**
* Footer empty
*
2025-02-12 00:52:24 +01:00
* Note : also called by functions . lib : recordNotFound
*
* @ param string $comment A text to add as HTML comment into HTML generated page
* @ param 'private' | 'public' $zone 'private' ( for private pages ) or 'public' ( for public pages )
* @ param int < 0 , 1 > $disabledoutputofmessages Clear all messages stored into session without displaying them
2016-05-01 16:34:50 +02:00
* @ return void
*/
2025-02-12 00:52:24 +01:00
function llxFooter ( $comment = '' , $zone = 'private' , $disabledoutputofmessages = 0 ) // @phan-suppress-current-line PhanRedefineFunction
2018-08-15 14:28:34 +02:00
{
}
2016-05-01 16:34:50 +02:00
2016-01-24 21:17:11 +01:00
require '../../master.inc.php' ;
2016-05-01 16:34:50 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2020-04-10 10:59:32 +02:00
$error = 0 ;
$websitekey = GETPOST ( 'website' , 'alpha' );
2023-12-04 13:49:31 +01:00
$pageid = GETPOST ( 'page' , 'alpha' ) ? GETPOST ( 'page' , 'alpha' ) : GETPOST ( 'pageid' , 'alpha' );
$pageref = GETPOST ( 'pageref' , 'alphanohtml' ) ? GETPOST ( 'pageref' , 'alphanohtml' ) : '' ;
2024-03-29 23:59:23 +01:00
// If page is xx/pagename, xx is a language, we set $pageref to pagename
$reg = array ();
if ( preg_match ( '/^(\w\w)\/(.*)$/' , $pageref , $reg )) {
$pageref = $reg [ 2 ];
}
2016-05-01 16:34:50 +02:00
$accessallowed = 1 ;
2020-04-10 10:59:32 +02:00
$type = '' ;
2016-05-01 16:34:50 +02:00
2021-02-26 18:58:34 +01:00
if ( empty ( $pageid )) {
2018-10-14 18:44:29 +02:00
require_once DOL_DOCUMENT_ROOT . '/website/class/website.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/website/class/websitepage.class.php' ;
2017-07-03 02:09:14 +02:00
2020-04-10 10:59:32 +02:00
$object = new Website ( $db );
2018-10-14 18:44:29 +02:00
$object -> fetch ( 0 , $websitekey );
2017-07-21 02:30:02 +02:00
2021-02-26 18:58:34 +01:00
if ( empty ( $object -> id )) {
if ( empty ( $pageid )) {
2018-10-14 18:44:29 +02:00
// Return header 404
header ( $_SERVER [ " SERVER_PROTOCOL " ] . " 404 Not Found " , true , 404 );
include DOL_DOCUMENT_ROOT . '/public/error-404.php' ;
exit ;
}
}
2020-04-10 10:59:32 +02:00
$objectpage = new WebsitePage ( $db );
2018-10-14 18:44:29 +02:00
2021-02-26 18:58:34 +01:00
if ( $pageref ) {
2024-03-07 20:16:48 +01:00
// @phan-suppress-next-line PhanPluginSuspiciousParamPosition
2025-02-12 00:52:24 +01:00
$result = $objectpage -> fetch ( 0 , ( string ) $object -> id , $pageref );
2021-02-26 18:58:34 +01:00
if ( $result > 0 ) {
2018-10-14 18:44:29 +02:00
$pageid = $objectpage -> id ;
2021-02-26 18:58:34 +01:00
} elseif ( $result == 0 ) {
2018-10-14 18:44:29 +02:00
// Page not found from ref=pageurl, we try using alternative alias
2024-03-07 20:16:48 +01:00
// @phan-suppress-next-line PhanPluginSuspiciousParamPosition
2025-02-12 00:52:24 +01:00
$result = $objectpage -> fetch ( 0 , ( string ) $object -> id , null , $pageref );
2021-02-26 18:58:34 +01:00
if ( $result > 0 ) {
2018-10-14 18:44:29 +02:00
$pageid = $objectpage -> id ;
}
}
2020-05-21 15:05:19 +02:00
} else {
2021-02-26 18:58:34 +01:00
if ( $object -> fk_default_home > 0 ) {
2020-04-10 10:59:32 +02:00
$result = $objectpage -> fetch ( $object -> fk_default_home );
2021-02-26 18:58:34 +01:00
if ( $result > 0 ) {
2018-10-14 18:44:29 +02:00
$pageid = $objectpage -> id ;
}
}
2021-02-26 18:58:34 +01:00
if ( empty ( $pageid )) {
2020-04-10 10:59:32 +02:00
$array = $objectpage -> fetchAll ( $object -> id ); // TODO Can filter on container of type pages only ?
2021-02-26 18:58:34 +01:00
if ( is_array ( $array ) && count ( $array ) > 0 ) {
2020-04-10 10:59:32 +02:00
$firstrep = reset ( $array );
$pageid = $firstrep -> id ;
2018-10-14 18:44:29 +02:00
}
}
}
2016-05-01 21:19:29 +02:00
}
2021-02-26 18:58:34 +01:00
if ( empty ( $pageid )) {
2018-10-14 18:44:29 +02:00
// Return header 404
header ( $_SERVER [ " SERVER_PROTOCOL " ] . " 404 Not Found " , true , 404 );
2017-07-03 02:09:14 +02:00
2018-10-14 18:44:29 +02:00
$langs -> load ( " website " );
2018-07-20 15:01:50 +02:00
2021-02-26 18:58:34 +01:00
if ( ! GETPOSTISSET ( 'pageref' )) {
print $langs -> trans ( " PreviewOfSiteNotYetAvailable " , $websitekey );
}
2017-07-03 02:09:14 +02:00
2018-10-14 18:44:29 +02:00
include DOL_DOCUMENT_ROOT . '/public/error-404.php' ;
exit ;
2016-05-07 16:38:32 +02:00
}
2024-05-21 20:13:39 +02:00
if ( empty ( $pageref )) {
$objectpage = new WebsitePage ( $db );
$result = $objectpage -> fetch ( $pageid );
if ( $result > 0 ) {
$pageref = $objectpage -> ref ;
}
}
if ( preg_match ( '/^_(library|service)_page_/' , $pageref )) {
$originalcontentonly = 1 ;
}
2016-05-01 16:34:50 +02:00
2020-04-10 10:59:32 +02:00
$appli = constant ( 'DOL_APPLICATION_TITLE' );
2023-11-27 11:56:32 +01:00
if ( getDolGlobalString ( 'MAIN_APPLICATION_TITLE' )) {
2024-01-05 04:18:53 +01:00
$appli = getDolGlobalString ( 'MAIN_APPLICATION_TITLE' );
2021-02-26 18:58:34 +01:00
}
2018-10-14 18:44:29 +02:00
/*
* View
*/
//print 'Directory with '.$appli.' websites.<br>';
2016-05-01 16:34:50 +02:00
// Security: Delete string ../ into $original_file
global $dolibarr_main_data_root ;
2021-02-26 18:58:34 +01:00
if ( $pageid == 'css' ) { // No more used ?
2020-03-23 15:54:02 +01:00
header ( 'Content-type: text/css' );
// Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access.
//if (empty($dolibarr_nocache)) header('Cache-Control: max-age=3600, public, must-revalidate');
//else
header ( 'Cache-Control: no-cache' );
2022-04-25 10:14:30 +02:00
$original_file = $dolibarr_main_data_root . ( $conf -> entity > 1 ? '/' . $conf -> entity : '' ) . '/website/' . $websitekey . '/styles.css.php' ;
2020-05-21 15:05:19 +02:00
} else {
2022-04-25 10:14:30 +02:00
$original_file = $dolibarr_main_data_root . ( $conf -> entity > 1 ? '/' . $conf -> entity : '' ) . '/website/' . $websitekey . '/page' . $pageid . '.tpl.php' ;
2016-05-01 16:34:50 +02:00
}
// Find the subdirectory name as the reference
2020-04-10 10:59:32 +02:00
$refname = basename ( dirname ( $original_file ) . " / " );
2016-05-01 16:34:50 +02:00
// Security:
2024-01-12 17:55:52 +01:00
// Limit access if permissions are insufficient
2021-02-26 18:58:34 +01:00
if ( ! $accessallowed ) {
2020-03-23 15:54:02 +01:00
accessforbidden ();
2016-05-01 16:34:50 +02:00
}
// Security:
// On interdit les remontees de repertoire ainsi que les pipe dans
// les noms de fichiers.
2021-02-26 18:58:34 +01:00
if ( preg_match ( '/\.\./' , $original_file ) || preg_match ( '/[<>|]/' , $original_file )) {
2020-03-23 15:54:02 +01:00
dol_syslog ( " Refused to deliver file " . $original_file );
2020-04-10 10:59:32 +02:00
$file = basename ( $original_file ); // Do no show plain path of original_file in shown error message
2024-03-26 12:51:04 +01:00
dol_print_error ( null , $langs -> trans ( " ErrorFileNameInvalid " , $file ));
2020-03-23 15:54:02 +01:00
exit ;
2016-05-01 16:34:50 +02:00
}
clearstatcache ();
$filename = basename ( $original_file );
// Output file on browser
dol_syslog ( " index.php include $original_file $filename content-type= $type " );
2020-04-10 10:59:32 +02:00
$original_file_osencoded = dol_osencode ( $original_file ); // New file name encoded in OS encoding charset
2016-05-01 16:34:50 +02:00
// This test if file exists should be useless. We keep it to find bug more easily
2021-02-26 18:58:34 +01:00
if ( ! file_exists ( $original_file_osencoded )) {
2020-03-23 15:54:02 +01:00
// Return header 404
header ( $_SERVER [ " SERVER_PROTOCOL " ] . " 404 Not Found " , true , 404 );
2017-07-03 02:09:14 +02:00
2020-03-23 15:54:02 +01:00
$langs -> load ( " website " );
print $langs -> trans ( " RequestedPageHasNoContentYet " , $pageid );
2017-07-03 02:09:14 +02:00
2020-03-23 15:54:02 +01:00
include DOL_DOCUMENT_ROOT . '/public/error-404.php' ;
exit ;
2016-05-01 16:34:50 +02:00
}
2016-08-08 14:21:43 +02:00
// Output page content
2016-09-16 01:00:24 +02:00
define ( 'USEDOLIBARRSERVER' , 1 );
2024-05-21 20:13:39 +02:00
if ( ! isset ( $originalcontentonly )) {
print '<!-- Page content ' . $original_file . ' rendered with DOLIBARR SERVER : Html with CSS link and html header + Body that was saved into tpl dir -->' . " \n " ;
}
2020-04-10 10:59:32 +02:00
include_once $original_file_osencoded ; // Note: The pageXXX.tpl.php showed here contains a formatage with dolWebsiteOutput() at end of page.
2016-08-08 14:21:43 +02:00
2021-02-26 18:58:34 +01:00
if ( is_object ( $db )) {
$db -> close ();
}