2019-08-12 22:19:24 +02: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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2019-08-12 22:19:24 +02:00
*/
/**
* \file htdocs / core / lib / website2 . lib . php
* \ingroup website
* \brief Library for website module ( rare functions not required for execution of website )
*/
/**
* 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 " ;
2019-11-13 19:35:02 +01:00
$mastercontent .= '// File generated to link to the master file - DO NOT MODIFY - It is just an include' . " \n " ;
2020-05-06 04:32:48 +02:00
$mastercontent .= " if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { \n " ;
$mastercontent .= " if (! defined('USEEXTERNALSERVER')) define('USEEXTERNALSERVER', 1); \n " ;
$mastercontent .= " require_once ' " . DOL_DOCUMENT_ROOT . " /master.inc.php'; \n " ;
$mastercontent .= " } \n " ;
2019-11-13 19:35:02 +01:00
$mastercontent .= '?>' . " \n " ;
2019-08-12 22:19:24 +02:00
$result = file_put_contents ( $filemaster , $mastercontent );
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_UMASK )) {
2019-08-12 22:19:24 +02:00
@ chmod ( $filemaster , octdec ( $conf -> global -> MAIN_UMASK ));
2021-02-23 22:03:23 +01:00
}
2019-08-12 22:19:24 +02:00
return $result ;
}
/**
2021-01-24 13:27:52 +01:00
* Save an alias page on disk ( A page that include the reference page ) .
* It saves file into the root directory but also into language subdirectory .
2019-08-12 22:19:24 +02:00
*
* @ param string $filealias Full path of filename to generate
* @ param Website $object Object website
* @ param WebsitePage $objectpage Object websitepage
* @ return boolean True if OK
2020-02-21 11:36:16 +01:00
* @ see dolSavePageContent ()
2019-08-12 22:19:24 +02:00
*/
function dolSavePageAlias ( $filealias , $object , $objectpage )
{
global $conf ;
2021-04-01 19:48:15 +02:00
// Now create the .tpl file
2019-08-16 02:31:06 +02:00
dol_syslog ( " dolSavePageAlias We regenerate the alias page filealias= " . $filealias );
2019-08-12 22:19:24 +02:00
$aliascontent = '<?php' . " \n " ;
2019-11-13 19:35:02 +01:00
$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 " ;
$aliascontent .= '?>' . " \n " ;
2019-08-12 22:19:24 +02:00
$result = file_put_contents ( $filealias , $aliascontent );
2020-04-11 16:34:59 +02:00
if ( $result === false ) {
dol_syslog ( " Failed to write file " . $filealias , LOG_WARNING );
}
2019-11-13 19:35:02 +01:00
if ( ! empty ( $conf -> global -> MAIN_UMASK )) {
2019-08-12 22:19:24 +02:00
@ chmod ( $filealias , octdec ( $conf -> global -> MAIN_UMASK ));
}
2021-01-24 13:27:52 +01:00
// Save also alias into language subdirectory if it is not a main language
2020-02-21 11:36:16 +01:00
if ( $objectpage -> lang && in_array ( $objectpage -> lang , explode ( ',' , $object -> otherlang ))) {
$dirname = dirname ( $filealias );
$filename = basename ( $filealias );
2021-01-26 13:38:41 +01:00
$filealiassub = $dirname . '/' . $objectpage -> lang . '/' . $filename ;
2020-02-21 11:36:16 +01:00
$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 " ;
$aliascontent .= '?>' . " \n " ;
2021-01-26 13:38:41 +01:00
$result = file_put_contents ( $filealiassub , $aliascontent );
2020-04-11 16:34:59 +02:00
if ( $result === false ) {
2021-01-26 13:38:41 +01:00
dol_syslog ( " Failed to write file " . $filealiassub , LOG_WARNING );
2020-04-11 16:34:59 +02:00
}
2020-02-21 11:36:16 +01:00
if ( ! empty ( $conf -> global -> MAIN_UMASK )) {
2021-01-26 13:38:41 +01:00
@ chmod ( $filealiassub , octdec ( $conf -> global -> MAIN_UMASK ));
2020-02-21 11:36:16 +01:00
}
2021-03-01 20:37:16 +01:00
} elseif ( empty ( $objectpage -> lang ) || ! in_array ( $objectpage -> lang , explode ( ',' , $object -> otherlang ))) {
// Save also alias into all language subdirectories if it is a main language
2021-04-09 12:48:06 +02:00
if ( empty ( $conf -> global -> WEBSITE_DISABLE_MAIN_LANGUAGE_INTO_LANGSUBDIR ) && ! empty ( $object -> otherlang )) {
2021-01-24 14:31:29 +01:00
$dirname = dirname ( $filealias );
$filename = basename ( $filealias );
foreach ( explode ( ',' , $object -> otherlang ) as $sublang ) {
2021-04-10 00:31:20 +02:00
// Avoid to erase main alias file if $sublang is empty string
2021-04-07 09:29:40 +02:00
if ( empty ( trim ( $sublang ))) continue ;
2021-01-26 13:38:41 +01:00
$filealiassub = $dirname . '/' . $sublang . '/' . $filename ;
2021-01-24 14:31:29 +01:00
$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 " ;
$aliascontent .= '?>' . " \n " ;
2021-01-26 13:38:41 +01:00
$result = file_put_contents ( $filealiassub , $aliascontent );
2021-01-24 14:31:29 +01:00
if ( $result === false ) {
2021-01-26 13:38:41 +01:00
dol_syslog ( " Failed to write file " . $filealiassub , LOG_WARNING );
2021-01-24 14:31:29 +01:00
}
if ( ! empty ( $conf -> global -> MAIN_UMASK )) {
2021-01-26 13:38:41 +01:00
@ chmod ( $filealiassub , octdec ( $conf -> global -> MAIN_UMASK ));
2021-01-24 14:31:29 +01:00
}
}
}
}
2021-01-24 13:27:52 +01:00
2019-11-13 19:35:02 +01:00
return ( $result ? true : false );
2019-08-12 22:19:24 +02:00
}
/**
2021-01-24 13:27:52 +01:00
* Save content of a page on disk ( page name is generally ID_of_page . php ) .
* Page contents are always saved into " root " directory . Only aliases pages saved with dolSavePageAlias () can be in root or language subdir .
2019-08-12 22:19:24 +02:00
*
* @ param string $filetpl Full path of filename to generate
* @ param Website $object Object website
* @ param WebsitePage $objectpage Object websitepage
2021-04-01 19:48:15 +02:00
* @ param int $backupold 1 = Make a backup of old page
2019-08-12 22:19:24 +02:00
* @ return boolean True if OK
2020-02-21 11:36:16 +01:00
* @ see dolSavePageAlias ()
2019-08-12 22:19:24 +02:00
*/
2021-04-01 19:48:15 +02:00
function dolSavePageContent ( $filetpl , Website $object , WebsitePage $objectpage , $backupold = 0 )
2019-08-12 22:19:24 +02:00
{
2019-12-07 13:19:12 +01:00
global $conf , $db ;
2019-08-12 22:19:24 +02:00
// 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 );
2020-03-20 16:30:45 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2021-04-01 19:48:15 +02:00
if ( $backupold ) {
dol_delete_file ( $filetpl . '.old' );
$result = dol_move ( $filetpl , $filetpl . '.old' , 0 , 1 , 0 , 0 );
if ( ! $result ) {
return false ;
}
} else {
dol_delete_file ( $filetpl );
}
2019-08-12 22:19:24 +02:00
$shortlangcode = '' ;
2021-02-23 22:03:23 +01:00
if ( $objectpage -> lang ) {
$shortlangcode = substr ( $objectpage -> lang , 0 , 2 ); // en_US or en-US -> en
}
if ( empty ( $shortlangcode )) {
$shortlangcode = substr ( $object -> lang , 0 , 2 ); // en_US or en-US -> en
}
2019-11-13 19:35:02 +01:00
$tplcontent = '' ;
$tplcontent .= " <?php // BEGIN PHP \n " ;
$tplcontent .= '$websitekey=basename(__DIR__); if (empty($websitepagefile)) $websitepagefile=__FILE__;' . " \n " ;
2020-02-21 11:36:16 +01:00
$tplcontent .= " if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { \n " ;
$tplcontent .= ' $pathdepth = count(explode(\'/\', $_SERVER[\'SCRIPT_NAME\'])) - 2;' . " \n " ;
$tplcontent .= ' require_once ($pathdepth ? str_repeat(\'../\', $pathdepth) : \'./\').\'master.inc.php\';' . " \n " ;
2020-04-26 23:06:52 +02:00
$tplcontent .= " } // Not already loaded \n " ;
2019-11-13 19:35:02 +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 " ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> WEBSITE_FORCE_DOCTYPE_HTML5 )) {
2019-11-13 19:35:02 +01:00
$tplcontent .= " <!DOCTYPE html> \n " ;
2019-08-12 22:19:24 +02:00
}
2019-11-13 19:35:02 +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 " ;
$tplcontent .= '<meta name="generator" content="' . DOL_APPLICATION_TITLE . ' ' . DOL_VERSION . ' (https://www.dolibarr.org)" />' . " \n " ;
$tplcontent .= '<meta name="dolibarr:pageid" content="' . dol_string_nohtmltag ( $objectpage -> id ) . '" />' . " \n " ;
2020-05-23 15:33:04 +02:00
// Add canonical reference
if ( $object -> virtualhost ) {
$tplcontent .= '<link rel="canonical" href="' . (( $objectpage -> id == $object -> fk_default_home ) ? '/' : (( $shortlangcode != substr ( $object -> lang , 0 , 2 ) ? '/' . $shortlangcode : '' ) . '/' . $objectpage -> pageurl . '.php' )) . '" />' . " \n " ;
}
2019-12-07 13:09:55 +01:00
// Add translation reference (main language)
2019-12-07 15:46:14 +01:00
if ( $object -> isMultiLang ()) {
2019-12-07 16:59:35 +01:00
// Add page "translation of"
2019-12-07 15:46:14 +01:00
$translationof = $objectpage -> fk_page ;
if ( $translationof ) {
$tmppage = new WebsitePage ( $db );
$tmppage -> fetch ( $translationof );
if ( $tmppage -> id > 0 ) {
$tmpshortlangcode = '' ;
2021-02-23 22:03:23 +01:00
if ( $tmppage -> lang ) {
$tmpshortlangcode = preg_replace ( '/[_-].*$/' , '' , $tmppage -> lang ); // en_US or en-US -> en
}
if ( empty ( $tmpshortlangcode )) {
$tmpshortlangcode = preg_replace ( '/[_-].*$/' , '' , $object -> lang ); // en_US or en-US -> en
}
2019-12-07 16:59:35 +01:00
if ( $tmpshortlangcode != $shortlangcode ) {
2020-05-23 17:01:22 +02:00
$tplcontent .= '<link rel="alternate" hreflang="' . $tmpshortlangcode . '" href="' . ( $object -> fk_default_home == $tmppage -> id ? '/' : (( $tmpshortlangcode != substr ( $object -> lang , 0 , 2 )) ? '/' . $tmpshortlangcode : '' ) . '/' . $tmppage -> pageurl . '.php' ) . '" />' . " \n " ;
2019-12-07 16:59:35 +01:00
}
2019-12-07 15:46:14 +01:00
}
2019-12-07 13:09:55 +01:00
}
2021-04-18 13:45:46 +02:00
2019-12-07 16:59:35 +01:00
// Add "has translation pages"
2021-03-22 12:00:41 +01:00
$sql = 'SELECT rowid as id, lang, pageurl from ' . MAIN_DB_PREFIX . 'website_page where fk_page IN (' . $db -> sanitize ( $objectpage -> id . ( $translationof ? ', ' . $translationof : '' )) . " ) " ;
2019-12-07 16:59:35 +01:00
$resql = $db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) {
2019-12-07 16:59:35 +01:00
$num_rows = $db -> num_rows ( $resql );
2021-02-23 22:03:23 +01:00
if ( $num_rows > 0 ) {
while ( $obj = $db -> fetch_object ( $resql )) {
2019-12-07 16:59:35 +01:00
$tmpshortlangcode = '' ;
2021-02-23 22:03:23 +01:00
if ( $obj -> lang ) {
$tmpshortlangcode = preg_replace ( '/[_-].*$/' , '' , $obj -> lang ); // en_US or en-US -> en
}
2019-12-07 16:59:35 +01:00
if ( $tmpshortlangcode != $shortlangcode ) {
2020-03-13 10:14:26 +01:00
$tplcontent .= '<link rel="alternate" hreflang="' . $tmpshortlangcode . '" href="' . ( $object -> fk_default_home == $obj -> id ? '/' : (( $tmpshortlangcode != substr ( $object -> lang , 0 , 2 ) ? '/' . $tmpshortlangcode : '' )) . '/' . $obj -> pageurl . '.php' ) . '" />' . " \n " ;
2019-12-07 16:59:35 +01:00
}
}
}
2020-05-23 18:54:33 +02:00
} else {
dol_print_error ( $db );
2019-12-07 16:59:35 +01:00
}
2021-04-18 13:45:46 +02:00
// Add myself
$tplcontent .= '<?php if ($_SERVER["PHP_SELF"] == "' . (( $object -> fk_default_home == $objectpage -> id ) ? '/' : (( $shortlangcode != substr ( $object -> lang , 0 , 2 )) ? '/' . $shortlangcode : '' )) . '/' . $objectpage -> pageurl . '.php") { ?>' . " \n " ;
$tplcontent .= '<link rel="alternate" hreflang="' . $shortlangcode . '" href="' . (( $object -> fk_default_home == $objectpage -> id ) ? '/' : (( $shortlangcode != substr ( $object -> lang , 0 , 2 )) ? '/' . $shortlangcode : '' ) . '/' . $objectpage -> pageurl . '.php' ) . '" />' . " \n " ;
2020-05-23 15:33:04 +02:00
$tplcontent .= '<?php } ?>' . " \n " ;
2020-05-19 00:50:30 +02:00
}
2020-06-09 22:07:06 +02:00
// Add manifest.json. Do we have to add it only on home page ?
2019-12-07 13:09:55 +01:00
$tplcontent .= '<?php if ($website->use_manifest) { print \'<link rel="manifest" href="/manifest.json.php" />\'."\n"; } ?>' . " \n " ;
2019-11-13 19:35:02 +01:00
$tplcontent .= '<!-- Include link to CSS file -->' . " \n " ;
2020-06-09 22:07:06 +02:00
// Add js
2020-02-21 11:36:16 +01:00
$tplcontent .= '<link rel="stylesheet" href="/styles.css.php?website=<?php echo $websitekey; ?>" type="text/css" />' . " \n " ;
2020-06-03 00:46:09 +02:00
$tplcontent .= '<!-- Include link to JS file -->' . " \n " ;
2021-04-03 13:24:34 +02:00
$tplcontent .= '<script async src="/javascript.js.php"></script>' . " \n " ;
2020-06-09 22:07:06 +02:00
// Add headers
2019-11-13 19:35:02 +01:00
$tplcontent .= '<!-- Include HTML header from common file -->' . " \n " ;
2020-06-09 22:07:06 +02:00
$tplcontent .= '<?php if (file_exists(DOL_DATA_ROOT."/website/".$websitekey."/htmlheader.html")) include DOL_DATA_ROOT."/website/".$websitekey."/htmlheader.html"; ?>' . " \n " ;
2019-11-13 19:35:02 +01:00
$tplcontent .= '<!-- Include HTML header from page header block -->' . " \n " ;
$tplcontent .= preg_replace ( '/<\/?html>/ims' , '' , $objectpage -> htmlheader ) . " \n " ;
$tplcontent .= '</head>' . " \n " ;
$tplcontent .= '<!-- File generated by Dolibarr website module editor -->' . " \n " ;
$tplcontent .= '<body id="bodywebsite" class="bodywebsite bodywebpage-' . $objectpage -> ref . '">' . " \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, "html", ' . $objectpage -> id . ');' . " \n " ;
2020-04-26 23:06:52 +02:00
$tplcontent .= " // END PHP ?> \n " ;
2019-08-12 22:19:24 +02:00
//var_dump($filetpl);exit;
$result = file_put_contents ( $filetpl , $tplcontent );
2021-01-24 13:27:52 +01:00
if ( ! empty ( $conf -> global -> MAIN_UMASK )) {
2019-08-12 22:19:24 +02:00
@ chmod ( $filetpl , octdec ( $conf -> global -> MAIN_UMASK ));
2021-01-24 13:27:52 +01:00
}
2019-08-12 22:19:24 +02:00
2021-01-24 13:27:52 +01:00
return $result ;
2019-08-12 22:19:24 +02:00
}
/**
2021-05-20 10:34:49 +02:00
* Save content of the index . php and / or the wrapper . php page
2019-08-12 22:19:24 +02:00
*
* @ param string $pathofwebsite Path of website root
* @ param string $fileindex Full path of file index . php
2021-05-20 10:34:49 +02:00
* @ param string $filetpl File tpl the index . php page redirect to ( used only if $fileindex is provided )
2019-08-12 22:19:24 +02:00
* @ param string $filewrapper Full path of file wrapper . php
* @ return boolean True if OK
*/
function dolSaveIndexPage ( $pathofwebsite , $fileindex , $filetpl , $filewrapper )
{
global $conf ;
2019-11-13 19:35:02 +01:00
$result1 = false ;
$result2 = false ;
2019-08-12 22:19:24 +02:00
dol_mkdir ( $pathofwebsite );
2020-05-23 13:10:33 +02:00
if ( $fileindex ) {
dol_delete_file ( $fileindex );
$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 " ;
$indexcontent .= '$websitekey=basename(__DIR__); if (empty($websitepagefile)) $websitepagefile=__FILE__;' . " \n " ;
$indexcontent .= " if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Load master if not already loaded \n " ;
$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 " ;
$indexcontent .= '// END PHP ?>' . " \n " ;
$result1 = file_put_contents ( $fileindex , $indexcontent );
if ( ! empty ( $conf -> global -> MAIN_UMASK )) {
@ chmod ( $fileindex , octdec ( $conf -> global -> MAIN_UMASK ));
}
2020-05-23 21:07:47 +02:00
} else {
2020-05-23 13:10:33 +02:00
$result1 = true ;
2020-03-21 19:37:09 +01:00
}
2019-08-12 22:19:24 +02:00
2020-05-23 13:10:33 +02:00
if ( $filewrapper ) {
dol_delete_file ( $filewrapper );
$wrappercontent = file_get_contents ( DOL_DOCUMENT_ROOT . '/website/samples/wrapper.php' );
2019-08-12 22:19:24 +02:00
2020-05-23 13:10:33 +02:00
$result2 = file_put_contents ( $filewrapper , $wrappercontent );
if ( ! empty ( $conf -> global -> MAIN_UMASK )) {
@ chmod ( $filewrapper , octdec ( $conf -> global -> MAIN_UMASK ));
}
} else {
$result2 = true ;
2020-03-21 19:37:09 +01:00
}
2019-08-12 22:19:24 +02:00
2020-03-21 19:37:09 +01:00
return ( $result1 && $result2 );
2019-08-12 22:19:24 +02: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 );
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_UMASK )) {
2019-08-12 22:19:24 +02:00
@ chmod ( $filehtmlheader , octdec ( $conf -> global -> MAIN_UMASK ));
2021-02-23 22:03:23 +01:00
}
2019-08-12 22:19:24 +02:00
2019-08-14 16:28:41 +02:00
return $result ;
2019-08-12 22:19:24 +02:00
}
/**
* 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 );
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_UMASK )) {
2019-08-12 22:19:24 +02:00
@ chmod ( $filecss , octdec ( $conf -> global -> MAIN_UMASK ));
2021-02-23 22:03:23 +01:00
}
2019-08-12 22:19:24 +02:00
2019-08-14 16:28:41 +02:00
return $result ;
2019-08-12 22:19:24 +02:00
}
/**
2020-06-03 00:46:09 +02:00
* Save content of a page on disk . For example into documents / website / mywebsite / javascript . js . php file .
2019-08-12 22:19:24 +02:00
*
* @ 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 );
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_UMASK )) {
2019-08-12 22:19:24 +02:00
@ chmod ( $filejs , octdec ( $conf -> global -> MAIN_UMASK ));
2021-02-23 22:03:23 +01:00
}
2019-08-12 22:19:24 +02:00
2019-08-14 16:28:41 +02:00
return $result ;
2019-08-12 22:19:24 +02:00
}
/**
* 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 );
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_UMASK )) {
2019-08-12 22:19:24 +02:00
@ chmod ( $filerobot , octdec ( $conf -> global -> MAIN_UMASK ));
2021-02-23 22:03:23 +01:00
}
2019-08-12 22:19:24 +02:00
2019-08-14 16:28:41 +02:00
return $result ;
2019-08-12 22:19:24 +02:00
}
/**
* 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 );
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_UMASK )) {
2019-08-12 22:19:24 +02:00
@ chmod ( $filehtaccess , octdec ( $conf -> global -> MAIN_UMASK ));
2021-02-23 22:03:23 +01:00
}
2019-08-12 22:19:24 +02:00
2019-08-14 16:28:41 +02:00
return $result ;
2019-08-13 04:43:50 +02:00
}
/**
* Save content of a page on disk
*
* @ param string $file Full path of filename to generate
* @ param string $content Content of file
* @ return boolean True if OK
*/
function dolSaveManifestJson ( $file , $content )
{
global $conf , $pathofwebsite ;
dol_syslog ( " Save manifest.js.php file into " . $file );
dol_mkdir ( $pathofwebsite );
$result = file_put_contents ( $file , $content );
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_UMASK )) {
2019-08-13 04:43:50 +02:00
@ chmod ( $file , octdec ( $conf -> global -> MAIN_UMASK ));
2021-02-23 22:03:23 +01:00
}
2019-08-13 04:43:50 +02:00
2019-08-14 16:28:41 +02:00
return $result ;
2019-08-12 22:19:24 +02:00
}
2019-08-15 00:55:47 +02:00
/**
* Save content of a page on disk
*
* @ param string $file Full path of filename to generate
* @ param string $content Content of file
* @ return boolean True if OK
*/
function dolSaveReadme ( $file , $content )
{
global $conf , $pathofwebsite ;
dol_syslog ( " Save README.md file into " . $file );
dol_mkdir ( $pathofwebsite );
$result = file_put_contents ( $file , $content );
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_UMASK )) {
2019-08-15 00:55:47 +02:00
@ chmod ( $file , octdec ( $conf -> global -> MAIN_UMASK ));
2021-02-23 22:03:23 +01:00
}
2019-08-15 00:55:47 +02:00
return $result ;
}
2019-08-12 22:19:24 +02:00
/**
2019-08-15 01:58:22 +02:00
* Show list of themes . Show all thumbs of themes / skins
2019-08-12 22:19:24 +02:00
*
2020-12-05 15:35:52 +01:00
* @ param Website $website Object website to load the template into
2019-08-12 22:19:24 +02:00
* @ return void
*/
function showWebsiteTemplates ( Website $website )
{
2019-11-13 19:35:02 +01:00
global $conf , $langs , $db , $form ;
2019-08-12 22:19:24 +02:00
2019-11-13 19:35:02 +01:00
$dirthemes = array ( '/doctemplates/websites' );
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> modules_parts [ 'websitetemplates' ])) { // Using this feature slow down application
foreach ( $conf -> modules_parts [ 'websitetemplates' ] as $reldir ) {
2019-11-13 19:35:02 +01:00
$dirthemes = array_merge ( $dirthemes , ( array ) ( $reldir . 'doctemplates/websites' ));
2019-08-12 22:19:24 +02:00
}
}
2019-11-13 19:35:02 +01:00
$dirthemes = array_unique ( $dirthemes );
2019-08-12 22:19:24 +02:00
// Now dir_themes=array('/themes') or dir_themes=array('/theme','/mymodule/theme')
2019-11-13 19:35:02 +01:00
$colspan = 2 ;
2019-08-12 22:19:24 +02:00
2020-06-19 10:36:19 +02:00
print '<!-- For website template import -->' . " \n " ;
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2019-08-12 22:19:24 +02:00
// Title
2020-04-13 22:52:34 +02:00
print '<tr class="liste_titre"><th class="titlefield">' ;
print $form -> textwithpicto ( $langs -> trans ( " Templates " ), $langs -> trans ( " ThemeDir " ) . ' : ' . join ( " , " , $dirthemes ));
print '</th>' ;
2019-08-12 22:19:24 +02:00
print '<th class="right">' ;
2019-11-13 19:35:02 +01:00
$url = 'https://www.dolistore.com/43-web-site-templates' ;
2019-08-12 22:19:24 +02:00
print '<a href="' . $url . '" target="_blank">' ;
print $langs -> trans ( 'DownloadMoreSkins' );
print '</a>' ;
print '</th></tr>' ;
print '<tr><td colspan="' . $colspan . '">' ;
print '<table class="nobordernopadding" width="100%"><tr><td><div class="center">' ;
2020-04-13 22:52:34 +02:00
if ( count ( $dirthemes )) {
$i = 0 ;
2021-02-23 22:03:23 +01:00
foreach ( $dirthemes as $dir ) {
2020-04-13 22:52:34 +02:00
//print $dirroot.$dir;exit;
$dirtheme = DOL_DATA_ROOT . $dir ; // This include loop on $conf->file->dol_document_root
2021-02-23 22:03:23 +01:00
if ( is_dir ( $dirtheme )) {
2020-04-13 22:52:34 +02:00
$handle = opendir ( $dirtheme );
2021-02-23 22:03:23 +01:00
if ( is_resource ( $handle )) {
while (( $subdir = readdir ( $handle )) !== false ) {
2020-04-13 22:52:34 +02:00
if ( is_file ( $dirtheme . " / " . $subdir ) && substr ( $subdir , 0 , 1 ) <> '.'
2021-02-23 22:03:23 +01:00
&& substr ( $subdir , 0 , 3 ) <> 'CVS' && preg_match ( '/\.zip$/i' , $subdir )) {
2020-04-13 22:52:34 +02:00
$subdirwithoutzip = preg_replace ( '/\.zip$/i' , '' , $subdir );
// Disable not stable themes (dir ends with _exp or _dev)
2021-02-23 22:03:23 +01:00
if ( $conf -> global -> MAIN_FEATURES_LEVEL < 2 && preg_match ( '/_dev$/i' , $subdir )) {
continue ;
}
if ( $conf -> global -> MAIN_FEATURES_LEVEL < 1 && preg_match ( '/_exp$/i' , $subdir )) {
continue ;
}
2020-04-13 22:52:34 +02:00
print '<div class="inline-block" style="margin-top: 10px; margin-bottom: 10px; margin-right: 20px; margin-left: 20px;">' ;
$file = $dirtheme . " / " . $subdirwithoutzip . " .jpg " ;
$url = DOL_URL_ROOT . '/viewimage.php?modulepart=doctemplateswebsite&file=' . $subdirwithoutzip . " .jpg " ;
2021-02-23 22:03:23 +01:00
if ( ! file_exists ( $file )) {
$url = DOL_URL_ROOT . '/public/theme/common/nophoto.png' ;
}
2020-04-13 22:52:34 +02:00
$originalfile = basename ( $file );
$entity = $conf -> entity ;
$modulepart = 'doctemplateswebsite' ;
$cache = '' ;
$title = $file ;
$ret = '' ;
$urladvanced = getAdvancedPreviewUrl ( $modulepart , $originalfile , 1 , '&entity=' . $entity );
2021-02-23 22:03:23 +01:00
if ( ! empty ( $urladvanced )) {
$ret .= '<a class="' . $urladvanced [ 'css' ] . '" target="' . $urladvanced [ 'target' ] . '" mime="' . $urladvanced [ 'mime' ] . '" href="' . $urladvanced [ 'url' ] . '">' ;
} else {
$ret .= '<a href="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&entity=' . $entity . '&file=' . urlencode ( $originalfile ) . '&cache=' . $cache . '">' ;
}
2020-04-13 22:52:34 +02:00
print $ret ;
print '<img class="img-skinthumb shadow" src="' . $url . '" border="0" alt="' . $title . '" title="' . $title . '" style="margin-bottom: 5px;">' ;
print '</a>' ;
print '<br>' ;
print $subdir . ' (' . dol_print_size ( dol_filesize ( $dirtheme . " / " . $subdir ), 1 , 1 ) . ')' ;
print '<br><a href="' . $_SERVER [ " PHP_SELF " ] . '?action=importsiteconfirm&website=' . $website -> ref . '&templateuserfile=' . $subdir . '" class="button">' . $langs -> trans ( " Load " ) . '</a>' ;
print '</div>' ;
$i ++ ;
}
2019-08-12 22:19:24 +02:00
}
}
}
}
2020-05-21 15:05:19 +02:00
} else {
2020-04-13 22:52:34 +02:00
print '<span class="opacitymedium">' . $langs -> trans ( " None " ) . '</span>' ;
}
2019-08-12 22:19:24 +02:00
print '</div></td></tr></table>' ;
print '</td></tr>' ;
print '</table>' ;
}