2017-02-24 21:13:40 +01:00
< ? php
/* Copyright ( C ) 2017 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
* along with this program . If not , see < http :// www . gnu . org / licenses />.
*/
/**
* \file htdocs / core / lib / website . lib . php
* \ingroup website
* \brief Library for website module
*/
2017-10-27 17:58:38 +02:00
/**
* Convert a page content to have correct links ( based on DOL_URL_ROOT ) into an html content .
2018-01-07 20:32:59 +01:00
* Used to ouput the page on the Preview from backoffice .
2017-10-27 17:58:38 +02:00
*
* @ param Website $website Web site object
* @ param string $content Content to replace
2017-12-10 20:34:35 +01:00
* @ param int $removephppart 0 = Replace PHP sections with a PHP badge . 1 = Remove completely PHP sections .
2017-10-27 17:58:38 +02:00
* @ return boolean True if OK
2019-03-11 01:01:15 +01:00
* @ see dolWebsiteOutput () for function used to replace content in a web server context
2017-10-27 17:58:38 +02:00
*/
2019-01-27 15:20:16 +01:00
function dolWebsiteReplacementOfLinks ( $website , $content , $removephppart = 0 )
2017-10-27 17:58:38 +02:00
{
2018-11-27 16:20:31 +01:00
$nbrep = 0 ;
2017-10-27 17:58:38 +02:00
// Replace php code. Note $content may come from database and does not contains body tags.
2017-12-10 20:34:35 +01:00
$replacewith = '...php...' ;
if ( $removephppart ) $replacewith = '' ;
$content = preg_replace ( '/value="<\?php((?!\?>).)*\?>\n*/ims' , 'value="' . $replacewith . '"' , $content );
2017-11-05 03:57:26 +01:00
2018-07-23 14:08:20 +02:00
$replacewith = '"callto=#' ;
if ( $removephppart ) $replacewith = '' ;
$content = preg_replace ( '/"callto:<\?php((?!\?>).)*\?>\n*/ims' , $replacewith , $content );
$replacewith = '"mailto=#' ;
if ( $removephppart ) $replacewith = '' ;
$content = preg_replace ( '/"mailto:<\?php((?!\?>).)*\?>\n*/ims' , $replacewith , $content );
2018-07-24 01:10:38 +02:00
$replacewith = 'src="php' ;
if ( $removephppart ) $replacewith = '' ;
$content = preg_replace ( '/src="<\?php((?!\?>).)*\?>\n*/ims' , $replacewith , $content );
2018-09-26 15:20:37 +02:00
$replacewith = 'href="php' ;
if ( $removephppart ) $replacewith = '' ;
$content = preg_replace ( '/href="<\?php((?!\?>).)*\?>\n*/ims' , $replacewith , $content );
//$replacewith='<span class="phptag">...php...</span>';
2017-12-17 16:24:47 +01:00
$replacewith = '<span class="phptag">...php...</span>' ;
2017-12-10 20:34:35 +01:00
if ( $removephppart ) $replacewith = '' ;
2018-11-27 16:20:31 +01:00
//$content = preg_replace('/<\?php((?!\?toremove>).)*\?toremove>\n*/ims', $replacewith, $content);
/* if ( $content === null ) {
if ( preg_last_error () == PREG_JIT_STACKLIMIT_ERROR ) $content = 'preg_replace error (when removing php tags) PREG_JIT_STACKLIMIT_ERROR' ;
} */
$content = dolStripPhpCode ( $content , $replacewith );
//var_dump($content);
2017-10-27 17:58:38 +02:00
// Replace relative link / with dolibarr URL
$content = preg_replace ( '/(href=")\/\"/' , '\1' . DOL_URL_ROOT . '/website/index.php?website=' . $website -> ref . '&pageid=' . $website -> fk_default_home . '"' , $content , - 1 , $nbrep );
// Replace relative link /xxx.php with dolibarr URL
$content = preg_replace ( '/(href=")\/?([^:\"]*)(\.php\")/' , '\1' . DOL_URL_ROOT . '/website/index.php?website=' . $website -> ref . '&pageref=\2"' , $content , - 1 , $nbrep );
2018-07-19 21:35:21 +02:00
// Fix relative link into medias with correct URL after the DOL_URL_ROOT: ../url("medias/
2017-10-27 17:58:38 +02:00
$content = preg_replace ( '/url\((["\']?)medias\//' , 'url(\1' . DOL_URL_ROOT . '/viewimage.php?modulepart=medias&file=' , $content , - 1 , $nbrep );
2018-07-19 21:35:21 +02:00
$content = preg_replace ( '/data-slide-bg=(["\']?)medias\//' , 'data-slide-bg=\1' . DOL_URL_ROOT . '/viewimage.php?modulepart=medias&file=' , $content , - 1 , $nbrep );
2017-10-27 17:58:38 +02:00
2018-07-19 21:35:21 +02:00
// <img src="medias/image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png...
$content = preg_replace ( '/(<img[^>]*src=")(medias\/)/' , '\1' . DOL_URL_ROOT . '/viewimage.php?modulepart=medias&file=' , $content , - 1 , $nbrep );
2017-10-27 17:58:38 +02:00
// <img src="image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png...
2019-01-27 11:55:16 +01:00
$content = preg_replace ( '/(<img[^>]*src=")(?!(http|\/?viewimage|' . preg_quote ( DOL_URL_ROOT , '/' ) . '\/viewimage))/' , '\1' . DOL_URL_ROOT . '/viewimage.php?modulepart=medias&file=' , $content , - 1 , $nbrep );
2018-07-19 21:35:21 +02:00
// <img src="viewimage.php/modulepart=medias&file=image.png" => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png"
$content = preg_replace ( '/(<img[^>]*src=")(\/?viewimage\.php)/' , '\1' . DOL_URL_ROOT . '/viewimage.php' , $content , - 1 , $nbrep );
2017-10-27 17:58:38 +02:00
// action="newpage.php" => action="dolibarr/website/index.php?website=...&pageref=newpage
$content = preg_replace ( '/(action=")\/?([^:\"]*)(\.php\")/' , '\1' . DOL_URL_ROOT . '/website/index.php?website=' . $website -> ref . '&pageref=\2"' , $content , - 1 , $nbrep );
2018-07-19 16:06:06 +02:00
// Fix relative link /document.php with correct URL after the DOL_URL_ROOT: ...href="/document.php?modulepart="
$content = preg_replace ( '/(href=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/' , '\1' . DOL_URL_ROOT . '\2\3' , $content , - 1 , $nbrep );
$content = preg_replace ( '/(src=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/' , '\1' . DOL_URL_ROOT . '\2\3' , $content , - 1 , $nbrep );
2017-10-27 17:58:38 +02:00
return $content ;
}
2018-11-27 16:20:31 +01:00
/**
* Remove PHP code part from a string .
*
* @ param string $str String to clean
* @ param string $replacewith String to use as replacement
* @ return string Result string without php code
2019-04-25 23:21:25 +02:00
* @ see dolKeepOnlyPhpCode ()
2018-11-27 16:20:31 +01:00
*/
2019-01-27 15:20:16 +01:00
function dolStripPhpCode ( $str , $replacewith = '' )
2018-11-27 16:20:31 +01:00
{
$newstr = '' ;
//split on each opening tag
2019-01-27 11:55:16 +01:00
$parts = explode ( '<?php' , $str );
2018-11-27 16:20:31 +01:00
if ( ! empty ( $parts ))
{
$i = 0 ;
foreach ( $parts as $part )
{
if ( $i == 0 ) // The first part is never php code
{
$i ++ ;
$newstr .= $part ;
continue ;
}
//split on closing tag
$partlings = explode ( '?>' , $part );
if ( ! empty ( $partlings ))
{
//remove content before closing tag
if ( count ( $partlings ) > 1 ) $partlings [ 0 ] = '' ;
//append to out string
2019-01-27 11:55:16 +01:00
$newstr .= $replacewith . implode ( '' , $partlings );
2018-11-27 16:20:31 +01:00
}
}
}
return $newstr ;
}
2019-04-25 23:21:25 +02:00
/**
* Keep only PHP code part from a HTML string page .
*
* @ param string $str String to clean
* @ return string Result string with php code only
* @ see dolStripPhpCode ()
*/
function dolKeepOnlyPhpCode ( $str )
{
$newstr = '' ;
//split on each opening tag
2019-05-02 12:28:40 +02:00
$parts = explode ( '<?php' , $str );
2019-04-25 23:21:25 +02:00
if ( ! empty ( $parts ))
{
$i = 0 ;
foreach ( $parts as $part )
{
if ( $i == 0 ) // The first part is never php code
{
$i ++ ;
continue ;
}
$newstr .= '<?php' ;
//split on closing tag
$partlings = explode ( '?>' , $part , 2 );
if ( ! empty ( $partlings ))
{
$newstr .= $partlings [ 0 ] . '?>' ;
}
else
{
$newstr .= $part . '?>' ;
}
}
}
return $newstr ;
}
2018-11-27 16:20:31 +01:00
2017-02-24 21:13:40 +01:00
/**
* Render a string of an HTML content and output it .
2017-10-27 17:58:38 +02:00
* Used to ouput the page when viewed from server ( Dolibarr or Apache ) .
2017-02-24 21:13:40 +01:00
*
* @ param string $content Content string
* @ return void
2019-03-11 01:01:15 +01:00
* @ see dolWebsiteReplacementOfLinks () for function used to replace content in the backoffice context when USEDOLIBARREDITOR is not on
2017-02-24 21:13:40 +01:00
*/
function dolWebsiteOutput ( $content )
{
2017-10-07 13:09:31 +02:00
global $db , $langs , $conf , $user ;
global $dolibarr_main_url_root , $dolibarr_main_data_root ;
2017-02-24 21:13:40 +01:00
2018-09-24 17:12:51 +02:00
dol_syslog ( " dolWebsiteOutput start (USEDOLIBARRSERVER= " . ( defined ( 'USEDOLIBARRSERVER' ) ? '1' : '' ) . " (USEDOLIBARREDITOR= " . ( defined ( 'USEDOLIBARREDITOR' ) ? '1' : '' ) . ')' );
2017-07-03 02:09:14 +02:00
2017-10-07 13:09:31 +02:00
// Define $urlwithroot
2019-01-27 11:55:16 +01:00
$urlwithouturlroot = preg_replace ( '/' . preg_quote ( DOL_URL_ROOT , '/' ) . '$/i' , '' , trim ( $dolibarr_main_url_root ));
2017-10-07 13:09:31 +02:00
$urlwithroot = $urlwithouturlroot . DOL_URL_ROOT ; // This is to use external domain name found into config file
//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
2017-07-21 02:30:02 +02:00
2018-09-25 15:00:37 +02:00
if ( defined ( 'USEDOLIBARREDITOR' )) // REPLACEMENT OF LINKS When page called from Dolibarr editor
2018-09-24 17:12:51 +02:00
{
2018-09-25 15:00:37 +02:00
// We remove the <head> part of content
$content = preg_replace ( '/<head>.*<\/head>/ims' , '' , $content );
2018-09-25 16:35:59 +02:00
$content = preg_replace ( '/^.*<body(\s[^>]*)*>/ims' , '' , $content );
$content = preg_replace ( '/<\/body(\s[^>]*)*>.*$/ims' , '' , $content );
2018-09-24 17:12:51 +02:00
}
2018-09-25 15:00:37 +02:00
elseif ( defined ( 'USEDOLIBARRSERVER' )) // REPLACEMENT OF LINKS When page called from Dolibarr server
2017-10-27 17:58:38 +02:00
{
global $website ;
// Replace relative link / with dolibarr URL: ...href="/"...
2018-01-07 20:32:59 +01:00
$content = preg_replace ( '/(href=")\/\"/' , '\1' . DOL_URL_ROOT . '/public/website/index.php?website=' . $website -> ref . '"' , $content , - 1 , $nbrep );
2017-10-27 17:58:38 +02:00
// Replace relative link /xxx.php with dolibarr URL: ...href="....php"
$content = preg_replace ( '/(href=")\/?([^:\"]*)(\.php\")/' , '\1' . DOL_URL_ROOT . '/public/website/index.php?website=' . $website -> ref . '&pageref=\2"' , $content , - 1 , $nbrep );
2018-01-07 20:32:59 +01:00
// Replace relative link /xxx with dolibarr URL: ...href="....php"
2018-07-19 16:06:06 +02:00
$content = preg_replace ( '/(href=")\/?([a-zA-Z0-9\-]+)(\")/' , '\1' . DOL_URL_ROOT . '/public/website/index.php?website=' . $website -> ref . '&pageref=\2\3' , $content , - 1 , $nbrep );
$content = preg_replace ( '/(href=")\/?([a-zA-Z0-9\-]+)(\?)/' , '\1' . DOL_URL_ROOT . '/public/website/index.php?website=' . $website -> ref . '&pageref=\2\3' , $content , - 1 , $nbrep );
2017-10-27 17:58:38 +02:00
2018-07-19 21:35:21 +02:00
// Fix relative link /document.php with correct URL after the DOL_URL_ROOT: href="/document.php?modulepart=" => href="/dolibarr/document.php?modulepart="
2018-07-19 16:06:06 +02:00
$content = preg_replace ( '/(href=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/' , '\1' . DOL_URL_ROOT . '\2\3' , $content , - 1 , $nbrep );
$content = preg_replace ( '/(src=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/' , '\1' . DOL_URL_ROOT . '\2\3' , $content , - 1 , $nbrep );
2018-01-02 22:58:37 +01:00
2018-07-19 21:35:21 +02:00
// Fix relative link /viewimage.php with correct URL after the DOL_URL_ROOT: href="/viewimage.php?modulepart=" => href="/dolibarr/viewimage.php?modulepart="
2018-07-19 16:06:06 +02:00
$content = preg_replace ( '/(href=")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/' , '\1' . DOL_URL_ROOT . '\2\3' , $content , - 1 , $nbrep );
2018-07-19 21:35:21 +02:00
$content = preg_replace ( '/(src=")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/' , '\1' . DOL_URL_ROOT . '\2\3' , $content , - 1 , $nbrep );
2017-10-27 17:58:38 +02:00
// Fix relative link into medias with correct URL after the DOL_URL_ROOT: ../url("medias/
$content = preg_replace ( '/url\((["\']?)medias\//' , 'url(\1' . DOL_URL_ROOT . '/viewimage.php?modulepart=medias&file=' , $content , - 1 , $nbrep );
2018-07-19 21:35:21 +02:00
$content = preg_replace ( '/data-slide-bg=(["\']?)medias\//' , 'data-slide-bg=\1' . DOL_URL_ROOT . '/viewimage.php?modulepart=medias&file=' , $content , - 1 , $nbrep );
// <img src="medias/image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png...
$content = preg_replace ( '/(<img[^>]*src=")(medias\/)/' , '\1' . DOL_URL_ROOT . '/viewimage.php?modulepart=medias&file=' , $content , - 1 , $nbrep );
// <img src="image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png...
2019-01-27 11:55:16 +01:00
$content = preg_replace ( '/(<img[^>]*src=")(?!(http|\/?viewimage|' . preg_quote ( DOL_URL_ROOT , '/' ) . '\/viewimage))/' , '\1' . DOL_URL_ROOT . '/viewimage.php?modulepart=medias&file=' , $content , - 1 , $nbrep );
2018-07-19 21:35:21 +02:00
// <img src="viewimage.php/modulepart=medias&file=image.png" => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png"
$content = preg_replace ( '/(<img[^>]*src=")(\/?viewimage\.php)/' , '\1' . DOL_URL_ROOT . '/viewimage.php' , $content , - 1 , $nbrep );
2017-10-27 17:58:38 +02:00
// action="newpage.php" => action="dolibarr/website/index.php?website=...&pageref=newpage
2017-10-27 18:45:12 +02:00
$content = preg_replace ( '/(action=")\/?([^:\"]*)(\.php\")/' , '\1' . DOL_URL_ROOT . '/public/website/index.php?website=' . $website -> ref . '&pageref=\2"' , $content , - 1 , $nbrep );
2017-10-27 17:58:38 +02:00
}
2018-09-25 15:00:37 +02:00
else // REPLACEMENT OF LINKS When page called from virtual host
2017-10-07 13:09:31 +02:00
{
$symlinktomediaexists = 1 ;
2017-07-03 02:09:14 +02:00
// Make a change into HTML code to allow to include images from medias directory correct with direct link for virtual server
// <img alt="" src="/dolibarr_dev/htdocs/viewimage.php?modulepart=medias&entity=1&file=image/ldestailleur_166x166.jpg" style="height:166px; width:166px" />
// become
// <img alt="" src="'.$urlwithroot.'/medias/image/ldestailleur_166x166.jpg" style="height:166px; width:166px" />
2017-10-07 13:09:31 +02:00
$nbrep = 0 ;
if ( ! $symlinktomediaexists )
{
2018-09-09 14:05:23 +02:00
$content = preg_replace ( '/(<script[^>]*src=")[^\"]*document\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/' , '\wrapper.php\2modulepart=medias\3file=\4\5' , $content , - 1 , $nbrep );
2018-09-08 14:30:27 +02:00
2018-09-09 14:05:23 +02:00
$content = preg_replace ( '/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/' , '\1/wrapper.php\2modulepart=medias\3file=\4\5' , $content , - 1 , $nbrep );
$content = preg_replace ( '/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/' , '\1/wrapper.php\2modulepart=medias\3file=\4\5' , $content , - 1 , $nbrep );
2019-02-09 12:00:49 +01:00
$content = preg_replace ( '/(url\(["\']?)[^\)]*viewimage\.php([^\)]*)modulepart=medias([^\)]*)file=([^\)]*)(["\']?\))/' , '\1/wrapper.php\2modulepart=medias\3file=\4\5' , $content , - 1 , $nbrep );
2018-09-09 14:05:23 +02:00
2018-12-17 17:29:04 +01:00
$content = preg_replace ( '/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/' , '\1/wrapper.php\2hashp=\3\4' , $content , - 1 , $nbrep );
$content = preg_replace ( '/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/' , '\1/wrapper.php\2hashp=\3\4' , $content , - 1 , $nbrep );
2019-02-09 12:00:49 +01:00
$content = preg_replace ( '/(url\(["\']?)[^\)]*viewimage\.php([^\)]*)hashp=([^\)]*)(["\']?\))/' , '\1/wrapper.php\2hashp\3\4' , $content , - 1 , $nbrep );
2018-12-17 17:29:04 +01:00
2018-09-09 14:05:23 +02:00
$content = preg_replace ( '/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=mycompany([^\"]*)file=([^\"]*)("[^>]*>)/' , '\1/wrapper.php\2modulepart=mycompany\3file=\4\5' , $content , - 1 , $nbrep );
2017-10-07 13:09:31 +02:00
}
else
{
2018-01-08 01:37:10 +01:00
$content = preg_replace ( '/(<script[^>]*src=")[^\"]*document\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/' , '\1medias/\4\5' , $content , - 1 , $nbrep );
$content = preg_replace ( '/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/' , '\1medias/\4\5' , $content , - 1 , $nbrep );
$content = preg_replace ( '/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/' , '\1medias/\4\5' , $content , - 1 , $nbrep );
2017-10-07 13:09:31 +02:00
$content = preg_replace ( '/(url\(["\']?)[^\)]*viewimage\.php([^\)]*)modulepart=medias([^\)]*)file=([^\)]*)(["\']?\))/' , '\1medias/\4\5' , $content , - 1 , $nbrep );
2018-09-09 14:05:23 +02:00
2018-12-17 17:29:04 +01:00
$content = preg_replace ( '/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/' , '\1/wrapper.php\2hashp=\3\4' , $content , - 1 , $nbrep );
$content = preg_replace ( '/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/' , '\1/wrapper.php\2hashp=\3\4' , $content , - 1 , $nbrep );
$content = preg_replace ( '/(url\(["\']?)[^\)]*viewimage\.php([^\)]*)hashp=([^\)]*)(["\']?\))/' , '\1/wrapper.php\2hashp=\3\4' , $content , - 1 , $nbrep );
2018-09-09 14:05:23 +02:00
$content = preg_replace ( '/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=mycompany([^\"]*)file=([^\"]*)("[^>]*>)/' , '\1/wrapper.php\2modulepart=mycompany\3file=\4\5' , $content , - 1 , $nbrep );
2017-10-07 13:09:31 +02:00
}
}
2018-06-11 10:25:22 +02:00
$content = preg_replace ( '/ contenteditable="true"/' , ' contenteditable="false"' , $content , - 1 , $nbrep );
2018-06-11 10:19:42 +02:00
2017-10-07 13:09:31 +02:00
dol_syslog ( " dolWebsiteOutput end " );
print $content ;
2017-02-24 21:13:40 +01:00
}
2017-07-20 16:49:20 +02:00
2017-08-21 03:13:44 +02:00
/**
* Format img tags to introduce viewimage on img src .
*
* @ param string $content Content string
* @ return void
* @ see dolWebsiteOutput
*/
/*
function dolWebsiteSaveContent ( $content )
{
global $db , $langs , $conf , $user ;
global $dolibarr_main_url_root , $dolibarr_main_data_root ;
//dol_syslog("dolWebsiteSaveContent start (mode=".(defined('USEDOLIBARRSERVER')?'USEDOLIBARRSERVER':'').')');
// Define $urlwithroot
$urlwithouturlroot = preg_replace ( '/' . preg_quote ( DOL_URL_ROOT , '/' ) . '$/i' , '' , trim ( $dolibarr_main_url_root ));
$urlwithroot = $urlwithouturlroot . DOL_URL_ROOT ; // This is to use external domain name found into config file
//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
//$content = preg_replace('/(<img.*src=")(?!(http|'.preg_quote(DOL_URL_ROOT,'/').'\/viewimage))/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
return $content ;
}
*/
2018-02-19 16:46:29 +01:00
/**
2018-02-28 14:36:22 +01:00
* Make a redirect to another container .
2018-02-19 16:46:29 +01:00
*
2018-02-28 14:36:22 +01:00
* @ param string $containerref Ref of container to redirect to ( must be a page from website root . Example : 'mypage.php' means 'mywebsite/mypage.php' ) .
* @ param string $containeraliasalt Ref of alternative aliases to redirect to .
* @ param int $containerid Id of container .
2018-02-19 16:46:29 +01:00
* @ return void
*/
2019-01-27 15:20:16 +01:00
function redirectToContainer ( $containerref , $containeraliasalt = '' , $containerid = 0 )
2018-02-19 16:46:29 +01:00
{
global $db , $website ;
$newurl = '' ;
2018-03-04 11:09:53 +01:00
$result = 0 ;
2018-02-19 16:46:29 +01:00
2018-02-28 14:36:22 +01:00
// We make redirect using the alternative alias, we must find the real $containerref
if ( $containeraliasalt )
{
include_once DOL_DOCUMENT_ROOT . '/website/class/websitepage.class.php' ;
$tmpwebsitepage = new WebsitePage ( $db );
$result = $tmpwebsitepage -> fetch ( 0 , $website -> id , '' , $containeraliasalt );
if ( $result > 0 )
{
$containerref = $tmpwebsitepage -> pageurl ;
}
else
{
print " Error, page contains a redirect to the alternative alias ' " . $containeraliasalt . " ' that does not exists in web site ( " . $website -> id . " / " . $website -> ref . " ) " ;
exit ;
}
}
2018-02-19 16:46:29 +01:00
if ( defined ( 'USEDOLIBARRSERVER' )) // When page called from Dolibarr server
{
// Check new container exists
2018-02-28 14:36:22 +01:00
if ( ! $containeraliasalt ) // If containeraliasalt set, we already did the test
{
include_once DOL_DOCUMENT_ROOT . '/website/class/websitepage.class.php' ;
$tmpwebsitepage = new WebsitePage ( $db );
$result = $tmpwebsitepage -> fetch ( 0 , $website -> id , $containerref );
unset ( $tmpwebsitepage );
}
2018-02-19 16:46:29 +01:00
if ( $result > 0 )
{
2018-02-19 22:10:15 +01:00
$currenturi = $_SERVER [ " REQUEST_URI " ];
if ( preg_match ( '/&pageref=([^&]+)/' , $currenturi , $regtmp ))
{
2018-02-28 14:36:22 +01:00
if ( $regtmp [ 0 ] == $containerref )
2018-02-19 22:10:15 +01:00
{
2018-02-28 14:36:22 +01:00
print " Error, page with uri '. $currenturi .' try a redirect to the same alias page ' " . $containerref . " ' in web site ' " . $website -> ref . " ' " ;
2018-02-19 22:10:15 +01:00
exit ;
}
else
{
2018-02-28 14:36:22 +01:00
$newurl = preg_replace ( '/&pageref=([^&]+)/' , '&pageref=' . $containerref , $currenturi );
2018-02-19 22:10:15 +01:00
}
}
else
{
2018-02-28 14:36:22 +01:00
$newurl = $currenturi . '&pageref=' . urlencode ( $containerref );
2018-02-19 22:10:15 +01:00
}
2018-02-19 16:46:29 +01:00
}
}
else // When page called from virtual host server
{
2018-02-28 14:36:22 +01:00
$newurl = '/' . $containerref . '.php' ;
2018-02-19 16:46:29 +01:00
}
if ( $newurl )
{
header ( " Location: " . $newurl );
exit ;
}
else
{
2018-02-28 14:36:22 +01:00
print " Error, page contains a redirect to the alias page ' " . $containerref . " ' that does not exists in web site ( " . $website -> id . " / " . $website -> ref . " ) " ;
2018-02-19 16:46:29 +01:00
exit ;
}
}
2017-08-21 03:13:44 +02:00
/**
* Clean an HTML page to report only content , so we can include it into another page .
2017-07-20 16:49:20 +02:00
* It outputs content of file sanitized from html and body part .
*
2018-02-28 14:36:22 +01:00
* @ param string $containerref Path to file to include ( must be a page from website root . Example : 'mypage.php' means 'mywebsite/mypage.php' )
2017-07-20 16:49:20 +02:00
* @ return void
*/
2018-02-28 14:36:22 +01:00
function includeContainer ( $containerref )
2017-07-20 16:49:20 +02:00
{
2018-10-16 01:39:04 +02:00
global $conf , $db , $hookmanager , $langs , $mysoc , $user , $website , $websitepage , $weblangs ; // Very important. Required to have var available when running inluded containers.
2017-07-20 16:49:20 +02:00
global $includehtmlcontentopened ;
2018-10-14 20:04:25 +02:00
global $websitekey , $websitepagefile ;
2017-07-20 16:49:20 +02:00
$MAXLEVEL = 20 ;
2018-02-28 14:36:22 +01:00
if ( ! preg_match ( '/\.php$/i' , $containerref )) $containerref .= '.php' ;
2017-12-12 01:40:34 +01:00
2018-02-28 14:36:22 +01:00
$fullpathfile = DOL_DATA_ROOT . '/website/' . $websitekey . '/' . $containerref ;
2017-07-20 16:49:20 +02:00
if ( empty ( $includehtmlcontentopened )) $includehtmlcontentopened = 0 ;
$includehtmlcontentopened ++ ;
if ( $includehtmlcontentopened > $MAXLEVEL )
{
print 'ERROR: RECURSIVE CONTENT LEVEL. Depth of recursive call is more than the limit of ' . $MAXLEVEL . " . \n " ;
return ;
}
2017-08-22 15:44:28 +02:00
// file_get_contents is not possible. We must execute code with include
2017-08-21 03:13:44 +02:00
//$content = file_get_contents($fullpathfile);
//print preg_replace(array('/^.*<body[^>]*>/ims','/<\/body>.*$/ims'), array('', ''), $content);*/
2017-08-22 15:32:45 +02:00
2017-08-22 15:44:28 +02:00
ob_start ();
2017-07-20 16:49:20 +02:00
$res = include $fullpathfile ; // Include because we want to execute code content
2017-08-22 15:44:28 +02:00
$tmpoutput = ob_get_contents ();
ob_end_clean ();
print " \n " . '<!-- include ' . $fullpathfile . ' level = ' . $includehtmlcontentopened . ' -->' . " \n " ;
print preg_replace ( array ( '/^.*<body[^>]*>/ims' , '/<\/body>.*$/ims' ), array ( '' , '' ), $tmpoutput );
2017-07-20 16:49:20 +02:00
if ( ! $res )
{
2018-02-28 14:36:22 +01:00
print 'ERROR: FAILED TO INCLUDE PAGE ' . $containerref . " . \n " ;
2017-07-20 16:49:20 +02:00
}
$includehtmlcontentopened -- ;
}
2017-10-26 13:09:11 +02:00
2017-10-06 23:54:45 +02:00
/**
* Download all images found into page content $tmp .
* If $modifylinks is set , links to images will be replace with a link to viewimage wrapper .
*
* @ param Website $object Object website
* @ param WebsitePage $objectpage Object website page
2017-10-07 02:29:27 +02:00
* @ param string $urltograb URL to grab ( exemple : http :// www . nltechno . com / or http :// www . nltechno . com / dir1 / or http :// www . nltechno . com / dir1 / mapage1 )
2017-10-06 23:54:45 +02:00
* @ param string $tmp Content to parse
* @ param string $action Var $action
2017-10-07 02:29:27 +02:00
* @ param string $modifylinks 0 = Do not modify content , 1 = Replace links with a link to viewimage
2018-02-19 14:56:37 +01:00
* @ param int $grabimages 0 = Do not grab images , 1 = Grab images
* @ param string $grabimagesinto 'root' or 'subpage'
2017-10-06 23:54:45 +02:00
* @ return void
*/
2019-01-27 15:20:16 +01:00
function getAllImages ( $object , $objectpage , $urltograb , & $tmp , & $action , $modifylinks = 0 , $grabimages = 1 , $grabimagesinto = 'subpage' )
2017-10-06 23:54:45 +02:00
{
global $conf ;
2017-10-07 13:04:31 +02:00
$error = 0 ;
2018-02-20 00:04:43 +01:00
dol_syslog ( " Call getAllImages with grabimagesinto= " . $grabimagesinto );
2017-10-07 02:29:27 +02:00
$alreadygrabbed = array ();
if ( preg_match ( '/\/$/' , $urltograb )) $urltograb .= '.' ;
$urltograb = dirname ( $urltograb ); // So urltograb is now http://www.nltechno.com or http://www.nltechno.com/dir1
2018-02-20 00:04:43 +01:00
// Search X in "img...src=X"
2017-10-07 02:29:27 +02:00
preg_match_all ( '/<img([^\.\/]+)src="([^>"]+)"([^>]*)>/i' , $tmp , $regs );
2017-10-06 23:54:45 +02:00
foreach ( $regs [ 0 ] as $key => $val )
{
2017-10-07 02:40:03 +02:00
if ( preg_match ( '/^data:image/i' , $regs [ 2 ][ $key ])) continue ; // We do nothing for such images
2017-12-10 17:59:19 +01:00
if ( preg_match ( '/^\//' , $regs [ 2 ][ $key ]))
{
$urltograbdirrootwithoutslash = getRootURLFromURL ( $urltograb );
$urltograbbis = $urltograbdirrootwithoutslash . $regs [ 2 ][ $key ]; // We use dirroot
}
else
{
$urltograbbis = $urltograb . '/' . $regs [ 2 ][ $key ]; // We use dir of grabbed file
}
2017-10-06 23:54:45 +02:00
$linkwithoutdomain = $regs [ 2 ][ $key ];
2018-02-19 14:56:37 +01:00
$dirforimages = '/' . $objectpage -> pageurl ;
if ( $grabimagesinto == 'root' ) $dirforimages = '' ;
// Define $filetosave and $filename
$filetosave = $conf -> medias -> multidir_output [ $conf -> entity ] . '/image/' . $object -> ref . $dirforimages . ( preg_match ( '/^\//' , $regs [ 2 ][ $key ]) ? '' : '/' ) . $regs [ 2 ][ $key ];
2017-10-06 23:54:45 +02:00
if ( preg_match ( '/^http/' , $regs [ 2 ][ $key ]))
{
$urltograbbis = $regs [ 2 ][ $key ];
$linkwithoutdomain = preg_replace ( '/^https?:\/\/[^\/]+\//i' , '' , $regs [ 2 ][ $key ]);
2018-02-19 14:56:37 +01:00
$filetosave = $conf -> medias -> multidir_output [ $conf -> entity ] . '/image/' . $object -> ref . $dirforimages . ( preg_match ( '/^\//' , $linkwithoutdomain ) ? '' : '/' ) . $linkwithoutdomain ;
2017-10-06 23:54:45 +02:00
}
2018-02-19 14:56:37 +01:00
$filename = 'image/' . $object -> ref . $dirforimages . ( preg_match ( '/^\//' , $linkwithoutdomain ) ? '' : '/' ) . $linkwithoutdomain ;
2017-10-07 02:29:27 +02:00
// Clean the aa/bb/../cc into aa/cc
$filetosave = preg_replace ( '/\/[^\/]+\/\.\./' , '' , $filetosave );
$filename = preg_replace ( '/\/[^\/]+\/\.\./' , '' , $filename );
//var_dump($filetosave);
//var_dump($filename);
//exit;
if ( empty ( $alreadygrabbed [ $urltograbbis ]))
{
2018-02-19 14:56:37 +01:00
if ( $grabimages )
2017-10-07 02:29:27 +02:00
{
2018-02-19 14:56:37 +01:00
$tmpgeturl = getURLContent ( $urltograbbis );
if ( $tmpgeturl [ 'curl_error_no' ])
{
$error ++ ;
setEventMessages ( 'Error getting ' . $urltograbbis . ': ' . $tmpgeturl [ 'curl_error_msg' ], null , 'errors' );
$action = 'create' ;
}
elseif ( $tmpgeturl [ 'http_code' ] != '200' )
{
$error ++ ;
setEventMessages ( 'Error getting ' . $urltograbbis . ': ' . $tmpgeturl [ 'http_code' ], null , 'errors' );
$action = 'create' ;
}
else
{
$alreadygrabbed [ $urltograbbis ] = 1 ; // Track that file was alreay grabbed.
dol_mkdir ( dirname ( $filetosave ));
$fp = fopen ( $filetosave , " w " );
fputs ( $fp , $tmpgeturl [ 'content' ]);
fclose ( $fp );
if ( ! empty ( $conf -> global -> MAIN_UMASK ))
@ chmod ( $filetosave , octdec ( $conf -> global -> MAIN_UMASK ));
}
2017-10-07 02:29:27 +02:00
}
}
if ( $modifylinks )
{
2019-01-27 11:55:16 +01:00
$tmp = preg_replace ( '/' . preg_quote ( $regs [ 0 ][ $key ], '/' ) . '/i' , '<img' . $regs [ 1 ][ $key ] . 'src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=medias&file=' . $filename . '"' . $regs [ 3 ][ $key ] . '>' , $tmp );
2017-10-07 02:29:27 +02:00
}
}
// Search X in "background...url(X)"
preg_match_all ( '/background([^\.\/\(;]+)url\([\"\']?([^\)\"\']*)[\"\']?\)/i' , $tmp , $regs );
foreach ( $regs [ 0 ] as $key => $val )
{
2017-10-07 02:40:03 +02:00
if ( preg_match ( '/^data:image/i' , $regs [ 2 ][ $key ])) continue ; // We do nothing for such images
2017-12-10 17:59:19 +01:00
if ( preg_match ( '/^\//' , $regs [ 2 ][ $key ]))
{
$urltograbdirrootwithoutslash = getRootURLFromURL ( $urltograb );
$urltograbbis = $urltograbdirrootwithoutslash . $regs [ 2 ][ $key ]; // We use dirroot
}
else
{
$urltograbbis = $urltograb . '/' . $regs [ 2 ][ $key ]; // We use dir of grabbed file
}
2017-10-07 02:29:27 +02:00
$linkwithoutdomain = $regs [ 2 ][ $key ];
2018-02-20 00:04:43 +01:00
$dirforimages = '/' . $objectpage -> pageurl ;
if ( $grabimagesinto == 'root' ) $dirforimages = '' ;
$filetosave = $conf -> medias -> multidir_output [ $conf -> entity ] . '/image/' . $object -> ref . $dirforimages . ( preg_match ( '/^\//' , $regs [ 2 ][ $key ]) ? '' : '/' ) . $regs [ 2 ][ $key ];
2017-10-07 02:29:27 +02:00
if ( preg_match ( '/^http/' , $regs [ 2 ][ $key ]))
2017-10-06 23:54:45 +02:00
{
2017-10-07 02:29:27 +02:00
$urltograbbis = $regs [ 2 ][ $key ];
$linkwithoutdomain = preg_replace ( '/^https?:\/\/[^\/]+\//i' , '' , $regs [ 2 ][ $key ]);
2018-02-20 00:04:43 +01:00
$filetosave = $conf -> medias -> multidir_output [ $conf -> entity ] . '/image/' . $object -> ref . $dirforimages . ( preg_match ( '/^\//' , $linkwithoutdomain ) ? '' : '/' ) . $linkwithoutdomain ;
2017-10-06 23:54:45 +02:00
}
2017-10-07 02:29:27 +02:00
2018-02-20 00:04:43 +01:00
$filename = 'image/' . $object -> ref . $dirforimages . ( preg_match ( '/^\//' , $linkwithoutdomain ) ? '' : '/' ) . $linkwithoutdomain ;
2017-10-07 02:29:27 +02:00
// Clean the aa/bb/../cc into aa/cc
$filetosave = preg_replace ( '/\/[^\/]+\/\.\./' , '' , $filetosave );
$filename = preg_replace ( '/\/[^\/]+\/\.\./' , '' , $filename );
//var_dump($filetosave);
//var_dump($filename);
//exit;
if ( empty ( $alreadygrabbed [ $urltograbbis ]))
2017-10-06 23:54:45 +02:00
{
2018-02-19 14:56:37 +01:00
if ( $grabimages )
2017-12-10 17:59:19 +01:00
{
2018-02-19 14:56:37 +01:00
$tmpgeturl = getURLContent ( $urltograbbis );
if ( $tmpgeturl [ 'curl_error_no' ])
{
$error ++ ;
setEventMessages ( 'Error getting ' . $urltograbbis . ': ' . $tmpgeturl [ 'curl_error_msg' ], null , 'errors' );
$action = 'create' ;
}
elseif ( $tmpgeturl [ 'http_code' ] != '200' )
{
$error ++ ;
setEventMessages ( 'Error getting ' . $urltograbbis . ': ' . $tmpgeturl [ 'http_code' ], null , 'errors' );
$action = 'create' ;
}
else
{
$alreadygrabbed [ $urltograbbis ] = 1 ; // Track that file was alreay grabbed.
dol_mkdir ( dirname ( $filetosave ));
$fp = fopen ( $filetosave , " w " );
fputs ( $fp , $tmpgeturl [ 'content' ]);
fclose ( $fp );
if ( ! empty ( $conf -> global -> MAIN_UMASK ))
@ chmod ( $filetosave , octdec ( $conf -> global -> MAIN_UMASK ));
}
2017-10-07 02:29:27 +02:00
}
2017-10-06 23:54:45 +02:00
}
if ( $modifylinks )
{
2019-01-27 11:55:16 +01:00
$tmp = preg_replace ( '/' . preg_quote ( $regs [ 0 ][ $key ], '/' ) . '/i' , 'background' . $regs [ 1 ][ $key ] . 'url("' . DOL_URL_ROOT . '/viewimage.php?modulepart=medias&file=' . $filename . '")' , $tmp );
2017-10-06 23:54:45 +02:00
}
}
2017-12-19 11:40:29 +01:00
}
2018-09-10 22:58:34 +02:00
/**
* Save content of a page on disk
*
* @ param string $filemaster Full path of filename master . inc . php for website to generate
* @ return boolean True if OK
*/
function dolSaveMasterFile ( $filemaster )
{
global $conf ;
// Now generate the master.inc.php page
dol_syslog ( " We regenerate the master file " );
dol_delete_file ( $filemaster );
$mastercontent = '<?php' . " \n " ;
$mastercontent .= '// File generated to link to the master file - DO NOT MODIFY - It is just an include' . " \n " ;
2018-09-24 17:12:51 +02:00
$mastercontent .= " if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) require_once ' " . DOL_DOCUMENT_ROOT . " /master.inc.php'; \n " ;
2019-04-05 11:09:39 +02:00
$mastercontent .= '?>' . " \n " ;
2018-09-10 22:58:34 +02:00
$result = file_put_contents ( $filemaster , $mastercontent );
if ( ! empty ( $conf -> global -> MAIN_UMASK ))
@ chmod ( $filemaster , octdec ( $conf -> global -> MAIN_UMASK ));
2018-09-10 23:20:31 +02:00
return $result ;
2018-09-10 22:58:34 +02:00
}
2017-12-19 11:40:29 +01:00
/**
* Save content of a page on disk
*
* @ param string $filealias Full path of filename to generate
* @ param Website $object Object website
* @ param WebsitePage $objectpage Object websitepage
* @ return boolean True if OK
*/
function dolSavePageAlias ( $filealias , $object , $objectpage )
{
global $conf ;
// Now create the .tpl file (duplicate code with actions updatesource or updatecontent but we need this to save new header)
dol_syslog ( " We regenerate the alias page filealias= " . $filealias );
$aliascontent = '<?php' . " \n " ;
$aliascontent .= " // File generated to wrap the alias page - DO NOT MODIFY - It is just a wrapper to real page \n " ;
$aliascontent .= 'global $dolibarr_main_data_root;' . " \n " ;
$aliascontent .= 'if (empty($dolibarr_main_data_root)) require \'./page' . $objectpage -> id . '.tpl.php\'; ' ;
$aliascontent .= 'else require $dolibarr_main_data_root.\'/website/\'.$website->ref.\'/page' . $objectpage -> id . '.tpl.php\';' . " \n " ;
2019-04-05 11:09:39 +02:00
$aliascontent .= '?>' . " \n " ;
2017-12-19 11:40:29 +01:00
$result = file_put_contents ( $filealias , $aliascontent );
2018-09-09 14:47:33 +02:00
if ( ! empty ( $conf -> global -> MAIN_UMASK )) {
@ chmod ( $filealias , octdec ( $conf -> global -> MAIN_UMASK ));
}
2017-10-07 02:29:27 +02:00
2018-09-10 22:58:34 +02:00
return ( $result ? true : false );
2017-10-06 23:54:45 +02:00
}
2017-12-19 11:40:29 +01:00
/**
* Save content of a page on disk
*
* @ param string $filetpl Full path of filename to generate
* @ param Website $object Object website
* @ param WebsitePage $objectpage Object websitepage
* @ return boolean True if OK
*/
function dolSavePageContent ( $filetpl , $object , $objectpage )
{
global $conf ;
// Now create the .tpl file (duplicate code with actions updatesource or updatecontent but we need this to save new header)
dol_syslog ( " We regenerate the tpl page filetpl= " . $filetpl );
dol_delete_file ( $filetpl );
$shortlangcode = '' ;
if ( $objectpage -> lang ) $shortlangcode = preg_replace ( '/[_-].*$/' , '' , $objectpage -> lang ); // en_US or en-US -> en
$tplcontent = '' ;
$tplcontent .= " <?php // BEGIN PHP \n " ;
2019-03-06 14:33:05 +01:00
$tplcontent .= '$websitekey=basename(__DIR__); if (empty($websitepagefile)) $websitepagefile=__FILE__;' . " \n " ;
2018-09-24 17:12:51 +02:00
$tplcontent .= " if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Not already loaded " . " \n " ;
2017-12-19 11:40:29 +01:00
$tplcontent .= " require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php'; \n " ;
$tplcontent .= " require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php'; \n " ;
$tplcontent .= " ob_start(); \n " ;
$tplcontent .= " // END PHP ?> \n " ;
2019-02-07 19:38:36 +01:00
if ( ! empty ( $conf -> global -> WEBSITE_FORCE_DOCTYPE_HTML5 ))
{
2019-02-07 19:39:23 +01:00
$tplcontent .= " <!DOCTYPE html> \n " ;
2019-02-07 19:38:36 +01:00
}
2017-12-19 11:40:29 +01:00
$tplcontent .= '<html' . ( $shortlangcode ? ' lang="' . $shortlangcode . '"' : '' ) . '>' . " \n " ;
$tplcontent .= '<head>' . " \n " ;
$tplcontent .= '<title>' . dol_string_nohtmltag ( $objectpage -> title , 0 , 'UTF-8' ) . '</title>' . " \n " ;
$tplcontent .= '<meta charset="UTF-8">' . " \n " ;
$tplcontent .= '<meta http-equiv="content-type" content="text/html; charset=utf-8" />' . " \n " ;
$tplcontent .= '<meta name="robots" content="index, follow" />' . " \n " ;
$tplcontent .= '<meta name="viewport" content="width=device-width, initial-scale=1.0">' . " \n " ;
$tplcontent .= '<meta name="keywords" content="' . dol_string_nohtmltag ( $objectpage -> keywords ) . '" />' . " \n " ;
$tplcontent .= '<meta name="title" content="' . dol_string_nohtmltag ( $objectpage -> title , 0 , 'UTF-8' ) . '" />' . " \n " ;
$tplcontent .= '<meta name="description" content="' . dol_string_nohtmltag ( $objectpage -> description , 0 , 'UTF-8' ) . '" />' . " \n " ;
2018-02-19 23:19:54 +01:00
$tplcontent .= '<meta name="generator" content="' . DOL_APPLICATION_TITLE . ' ' . DOL_VERSION . ' (https://www.dolibarr.org)" />' . " \n " ;
2019-03-29 23:04:09 +01:00
$tplcontent .= '<meta name="dolibarr:pageid" content="' . dol_string_nohtmltag ( $objectpage -> id ) . '" />' . " \n " ;
2018-10-15 21:43:01 +02:00
$tplcontent .= '<link href="/' . (( $objectpage -> id == $object -> fk_default_home ) ? '' : ( $objectpage -> pageurl . '.php' )) . '" rel="canonical" />' . " \n " ;
2017-12-19 11:40:29 +01:00
$tplcontent .= '<!-- Include link to CSS file -->' . " \n " ;
2018-09-10 23:37:51 +02:00
$tplcontent .= '<link rel="stylesheet" href="styles.css.php?website=<?php echo $websitekey; ?>" type="text/css" />' . " \n " ;
2017-12-19 11:40:29 +01:00
$tplcontent .= '<!-- Include HTML header from common file -->' . " \n " ;
2018-09-10 23:20:31 +02:00
$tplcontent .= '<?php print preg_replace(\'/<\/?html>/ims\', \'\', file_get_contents(DOL_DATA_ROOT."/website/".$websitekey."/htmlheader.html")); ?>' . " \n " ;
2018-02-15 00:24:15 +01:00
$tplcontent .= '<!-- Include HTML header from page header block -->' . " \n " ;
2018-02-15 00:53:03 +01:00
$tplcontent .= preg_replace ( '/<\/?html>/ims' , '' , $objectpage -> htmlheader ) . " \n " ;
2017-12-19 11:40:29 +01:00
$tplcontent .= '</head>' . " \n " ;
$tplcontent .= '<!-- File generated by Dolibarr website module editor -->' . " \n " ;
$tplcontent .= '<body id="bodywebsite" class="bodywebsite">' . " \n " ;
$tplcontent .= $objectpage -> content . " \n " ;
$tplcontent .= '</body>' . " \n " ;
$tplcontent .= '</html>' . " \n " ;
$tplcontent .= '<?php // BEGIN PHP' . " \n " ;
$tplcontent .= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp);' . " \n " ;
2019-04-05 11:09:39 +02:00
$tplcontent .= " // END PHP ?> " . " \n " ;
2017-12-19 11:40:29 +01:00
//var_dump($filetpl);exit;
$result = file_put_contents ( $filetpl , $tplcontent );
if ( ! empty ( $conf -> global -> MAIN_UMASK ))
@ chmod ( $filetpl , octdec ( $conf -> global -> MAIN_UMASK ));
return $result ;
}
2018-02-28 14:36:22 +01:00
/**
2018-09-09 14:05:23 +02:00
* Save content of the index . php and wrapper . php page
2018-02-28 14:36:22 +01:00
*
* @ param string $pathofwebsite Path of website root
* @ param string $fileindex Full path of file index . php
* @ param string $filetpl File tpl to index . php page redirect to
2018-09-09 14:47:33 +02:00
* @ param string $filewrapper Full path of file wrapper . php
2018-02-28 14:36:22 +01:00
* @ return boolean True if OK
*/
2018-09-09 14:05:23 +02:00
function dolSaveIndexPage ( $pathofwebsite , $fileindex , $filetpl , $filewrapper )
2018-02-28 14:36:22 +01:00
{
global $conf ;
2018-09-09 14:05:23 +02:00
$result1 = false ;
$result2 = false ;
2018-02-28 14:36:22 +01:00
dol_mkdir ( $pathofwebsite );
2018-09-09 14:05:23 +02:00
dol_delete_file ( $fileindex );
2018-02-28 14:36:22 +01:00
$indexcontent = '<?php' . " \n " ;
$indexcontent .= " // BEGIN PHP File generated to provide an index.php as Home Page or alias redirector - DO NOT MODIFY - It is just a generated wrapper. \n " ;
2019-03-06 14:33:05 +01:00
$indexcontent .= '$websitekey=basename(__DIR__); if (empty($websitepagefile)) $websitepagefile=__FILE__;' . " \n " ;
2018-09-24 17:12:51 +02:00
$indexcontent .= " if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Load master if not already loaded \n " ;
2018-02-28 14:36:22 +01:00
$indexcontent .= 'if (! empty($_GET[\'pageref\']) || ! empty($_GET[\'pagealiasalt\']) || ! empty($_GET[\'pageid\'])) {' . " \n " ;
$indexcontent .= " require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php'; \n " ;
$indexcontent .= " require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php'; \n " ;
$indexcontent .= ' redirectToContainer($_GET[\'pageref\'], $_GET[\'pagealiasalt\'], $_GET[\'pageid\']);' . " \n " ;
$indexcontent .= " } \n " ;
$indexcontent .= " include_once './ " . basename ( $filetpl ) . " ' \n " ;
2019-04-05 11:09:39 +02:00
$indexcontent .= '// END PHP ?>' . " \n " ;
2018-09-09 14:05:23 +02:00
$result1 = file_put_contents ( $fileindex , $indexcontent );
2018-02-28 14:36:22 +01:00
if ( ! empty ( $conf -> global -> MAIN_UMASK ))
@ chmod ( $fileindex , octdec ( $conf -> global -> MAIN_UMASK ));
2018-09-09 14:05:23 +02:00
dol_delete_file ( $filewrapper );
2018-12-17 19:37:17 +01:00
$wrappercontent = file_get_contents ( DOL_DOCUMENT_ROOT . '/website/samples/wrapper.html' );
2018-09-09 14:05:23 +02:00
$result2 = file_put_contents ( $filewrapper , $wrappercontent );
if ( ! empty ( $conf -> global -> MAIN_UMASK ))
@ chmod ( $filewrapper , octdec ( $conf -> global -> MAIN_UMASK ));
return ( $result1 && $result2 );
2018-02-28 14:36:22 +01:00
}
2017-12-19 11:40:29 +01:00
/**
* Save content of a page on disk
*
* @ param string $filehtmlheader Full path of filename to generate
* @ param string $htmlheadercontent Content of file
* @ return boolean True if OK
*/
function dolSaveHtmlHeader ( $filehtmlheader , $htmlheadercontent )
{
global $conf , $pathofwebsite ;
dol_syslog ( " Save html header into " . $filehtmlheader );
dol_mkdir ( $pathofwebsite );
$result = file_put_contents ( $filehtmlheader , $htmlheadercontent );
if ( ! empty ( $conf -> global -> MAIN_UMASK ))
@ chmod ( $filehtmlheader , octdec ( $conf -> global -> MAIN_UMASK ));
if ( ! $result )
{
setEventMessages ( 'Failed to write file ' . $filehtmlheader , null , 'errors' );
return false ;
}
return true ;
}
/**
* Save content of a page on disk
*
* @ param string $filecss Full path of filename to generate
* @ param string $csscontent Content of file
* @ return boolean True if OK
*/
function dolSaveCssFile ( $filecss , $csscontent )
{
global $conf , $pathofwebsite ;
dol_syslog ( " Save css file into " . $filecss );
dol_mkdir ( $pathofwebsite );
$result = file_put_contents ( $filecss , $csscontent );
if ( ! empty ( $conf -> global -> MAIN_UMASK ))
@ chmod ( $filecss , octdec ( $conf -> global -> MAIN_UMASK ));
if ( ! $result )
{
setEventMessages ( 'Failed to write file ' . $filecss , null , 'errors' );
return false ;
}
return true ;
}
/**
* Save content of a page on disk
*
* @ param string $filejs Full path of filename to generate
* @ param string $jscontent Content of file
* @ return boolean True if OK
*/
function dolSaveJsFile ( $filejs , $jscontent )
{
global $conf , $pathofwebsite ;
dol_syslog ( " Save js file into " . $filejs );
dol_mkdir ( $pathofwebsite );
$result = file_put_contents ( $filejs , $jscontent );
if ( ! empty ( $conf -> global -> MAIN_UMASK ))
@ chmod ( $filejs , octdec ( $conf -> global -> MAIN_UMASK ));
if ( ! $result )
{
setEventMessages ( 'Failed to write file ' . $filejs , null , 'errors' );
return false ;
}
return true ;
}
/**
* Save content of a page on disk
*
* @ param string $filerobot Full path of filename to generate
* @ param string $robotcontent Content of file
* @ return boolean True if OK
*/
function dolSaveRobotFile ( $filerobot , $robotcontent )
{
global $conf , $pathofwebsite ;
dol_syslog ( " Save robot file into " . $filerobot );
dol_mkdir ( $pathofwebsite );
$result = file_put_contents ( $filerobot , $robotcontent );
if ( ! empty ( $conf -> global -> MAIN_UMASK ))
@ chmod ( $filerobot , octdec ( $conf -> global -> MAIN_UMASK ));
if ( ! $result )
{
setEventMessages ( 'Failed to write file ' . $filerobot , null , 'errors' );
return false ;
}
return true ;
}
/**
* Save content of a page on disk
*
* @ param string $filehtaccess Full path of filename to generate
* @ param string $htaccess Content of file
* @ return boolean True if OK
*/
function dolSaveHtaccessFile ( $filehtaccess , $htaccess )
{
global $conf , $pathofwebsite ;
dol_syslog ( " Save htaccess file into " . $filehtaccess );
dol_mkdir ( $pathofwebsite );
$result = file_put_contents ( $filehtaccess , $htaccess );
if ( ! empty ( $conf -> global -> MAIN_UMASK ))
@ chmod ( $filehtaccess , octdec ( $conf -> global -> MAIN_UMASK ));
if ( ! $result )
{
setEventMessages ( 'Failed to write file ' . $filehtaccess , null , 'errors' );
return false ;
}
return true ;
}