*
* 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 .
*/
/**
* \file htdocs/core/lib/website.lib.php
* \ingroup website
* \brief Library for website module
*/
/**
* Convert a page content to have correct links (based on DOL_URL_ROOT) into an html content.
* Used to ouput the page on the Preview from backoffice.
*
* @param Website $website Web site object
* @param string $content Content to replace
* @param int $removephppart 0=Replace PHP sections with a PHP badge. 1=Remove completely PHP sections.
* @return boolean True if OK
* @see dolWebsiteOutput() for function used to replace content in a web server context
*/
function dolWebsiteReplacementOfLinks($website, $content, $removephppart = 0)
{
$nbrep = 0;
// Replace php code. Note $content may come from database and does not contains body tags.
$replacewith='...php...';
if ($removephppart) $replacewith='';
$content = preg_replace('/value="<\?php((?!\?>).)*\?>\n*/ims', 'value="'.$replacewith.'"', $content);
$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);
$replacewith='src="php';
if ($removephppart) $replacewith='';
$content = preg_replace('/src="<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content);
$replacewith='href="php';
if ($removephppart) $replacewith='';
$content = preg_replace('/href="<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content);
//$replacewith='...php...';
$replacewith='...php...';
if ($removephppart) $replacewith='';
//$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);
// 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);
// 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);
$content = preg_replace('/data-slide-bg=(["\']?)medias\//', 'data-slide-bg=\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
// ]*src=")(medias\/)/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
// ]*src=")(?!(http|\/?viewimage|'.preg_quote(DOL_URL_ROOT, '/').'\/viewimage))/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
// ]*src=")(\/?viewimage\.php)/', '\1'.DOL_URL_ROOT.'/viewimage.php', $content, -1, $nbrep);
// 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);
// 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);
return $content;
}
/**
* 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
* @see dolKeepOnlyPhpCode()
*/
function dolStripPhpCode($str, $replacewith = '')
{
$newstr = '';
//split on each opening tag
$parts = explode('', $part);
if (!empty($partlings))
{
//remove content before closing tag
if (count($partlings) > 1) $partlings[0] = '';
//append to out string
$newstr .= $replacewith.implode('', $partlings);
}
}
}
return $newstr;
}
/**
* 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
$parts = explode('', $part, 2);
if (!empty($partlings))
{
$newstr .= $partlings[0].'?>';
}
else
{
$newstr .= $part.'?>';
}
}
}
return $newstr;
}
/**
* Render a string of an HTML content and output it.
* Used to ouput the page when viewed from server (Dolibarr or Apache).
*
* @param string $content Content string
* @return void
* @see dolWebsiteReplacementOfLinks() for function used to replace content in the backoffice context when USEDOLIBARREDITOR is not on
*/
function dolWebsiteOutput($content)
{
global $db, $langs, $conf, $user;
global $dolibarr_main_url_root, $dolibarr_main_data_root;
dol_syslog("dolWebsiteOutput start (USEDOLIBARRSERVER=".(defined('USEDOLIBARRSERVER')?'1':'')." USEDOLIBARREDITOR=".(defined('USEDOLIBARREDITOR')?'1':'').')');
// 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
if (defined('USEDOLIBARREDITOR')) // REPLACEMENT OF LINKS When page called from Dolibarr editor
{
// We remove the
part of content
$content = preg_replace('/.*<\/head>/ims', '', $content);
$content = preg_replace('/^.*]*)*>/ims', '', $content);
$content = preg_replace('/<\/body(\s[^>]*)*>.*$/ims', '', $content);
}
elseif (defined('USEDOLIBARRSERVER')) // REPLACEMENT OF LINKS When page called from Dolibarr server
{
global $website;
// Replace relative link / with dolibarr URL: ...href="/"...
$content=preg_replace('/(href=")\/\"/', '\1'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'"', $content, -1, $nbrep);
// 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);
// Replace relative link /xxx with dolibarr URL: ...href="....php"
$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);
// Fix relative link /document.php with correct URL after the DOL_URL_ROOT: href="/document.php?modulepart=" => href="/dolibarr/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);
// Fix relative link /viewimage.php with correct URL after the DOL_URL_ROOT: href="/viewimage.php?modulepart=" => href="/dolibarr/viewimage.php?modulepart="
$content=preg_replace('/(href=")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
$content=preg_replace('/(src=")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep);
// 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);
$content=preg_replace('/data-slide-bg=(["\']?)medias\//', 'data-slide-bg=\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
// ]*src=")(medias\/)/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
// ]*src=")(?!(http|\/?viewimage|'.preg_quote(DOL_URL_ROOT, '/').'\/viewimage))/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep);
// ]*src=")(\/?viewimage\.php)/', '\1'.DOL_URL_ROOT.'/viewimage.php', $content, -1, $nbrep);
// action="newpage.php" => action="dolibarr/website/index.php?website=...&pageref=newpage
$content = preg_replace('/(action=")\/?([^:\"]*)(\.php\")/', '\1'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2"', $content, -1, $nbrep);
}
else // REPLACEMENT OF LINKS When page called from virtual host
{
$symlinktomediaexists=1;
// Make a change into HTML code to allow to include images from medias directory correct with direct link for virtual server
//
// become
//
$nbrep=0;
if (! $symlinktomediaexists)
{
$content=preg_replace('/('."\n";
}
elseif ($type == 'blogpost')
{
if ($websitepage->fk_user_creat > 0)
{
include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
$tmpuser = new User($db);
$restmpuser = $tmpuser->fetch($websitepage->fk_user_creat);
if ($restmpuser > 0)
{
$ret = ''."\n";
$ret .= ''."\n";
}
}
}
elseif ($type == 'product')
{
$ret = ''."\n";
$ret.= ''."\n";
}
return $ret;
}
/**
* 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
* @param string $urltograb URL to grab (exemple: http://www.nltechno.com/ or http://www.nltechno.com/dir1/ or http://www.nltechno.com/dir1/mapage1)
* @param string $tmp Content to parse
* @param string $action Var $action
* @param string $modifylinks 0=Do not modify content, 1=Replace links with a link to viewimage
* @param int $grabimages 0=Do not grab images, 1=Grab images
* @param string $grabimagesinto 'root' or 'subpage'
* @return void
*/
function getAllImages($object, $objectpage, $urltograb, &$tmp, &$action, $modifylinks = 0, $grabimages = 1, $grabimagesinto = 'subpage')
{
global $conf;
$error=0;
dol_syslog("Call getAllImages with grabimagesinto=".$grabimagesinto);
$alreadygrabbed=array();
if (preg_match('/\/$/', $urltograb)) $urltograb.='.';
$urltograb = dirname($urltograb); // So urltograb is now http://www.nltechno.com or http://www.nltechno.com/dir1
// Search X in "img...src=X"
preg_match_all('/"]+)"([^>]*)>/i', $tmp, $regs);
foreach ($regs[0] as $key => $val)
{
if (preg_match('/^data:image/i', $regs[2][$key])) continue; // We do nothing for such images
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
}
$linkwithoutdomain = $regs[2][$key];
$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];
if (preg_match('/^http/', $regs[2][$key]))
{
$urltograbbis = $regs[2][$key];
$linkwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\//i', '', $regs[2][$key]);
$filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
}
$filename = 'image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
// 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]))
{
if ($grabimages)
{
$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));
}
}
}
if ($modifylinks)
{
$tmp = preg_replace('/'.preg_quote($regs[0][$key], '/').'/i', '', $tmp);
}
}
// Search X in "background...url(X)"
preg_match_all('/background([^\.\/\(;]+)url\([\"\']?([^\)\"\']*)[\"\']?\)/i', $tmp, $regs);
foreach ($regs[0] as $key => $val)
{
if (preg_match('/^data:image/i', $regs[2][$key])) continue; // We do nothing for such images
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
}
$linkwithoutdomain = $regs[2][$key];
$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];
if (preg_match('/^http/', $regs[2][$key]))
{
$urltograbbis = $regs[2][$key];
$linkwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\//i', '', $regs[2][$key]);
$filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
}
$filename = 'image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
// 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]))
{
if ($grabimages)
{
$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));
}
}
}
if ($modifylinks)
{
$tmp = preg_replace('/'.preg_quote($regs[0][$key], '/').'/i', 'background'.$regs[1][$key].'url("'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file='.$filename.'")', $tmp);
}
}
}
/**
* 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 = ''."\n";
$result = file_put_contents($filemaster, $mastercontent);
if (! empty($conf->global->MAIN_UMASK))
@chmod($filemaster, octdec($conf->global->MAIN_UMASK));
return $result;
}
/**
* 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 = 'id.'.tpl.php\'; ';
$aliascontent.= 'else require $dolibarr_main_data_root.\'/website/\'.$website->ref.\'/page'.$objectpage->id.'.tpl.php\';'."\n";
$aliascontent.= '?>'."\n";
$result = file_put_contents($filealias, $aliascontent);
if (! empty($conf->global->MAIN_UMASK)) {
@chmod($filealias, octdec($conf->global->MAIN_UMASK));
}
return ($result?true:false);
}
/**
* 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.= "\n";
if (! empty($conf->global->WEBSITE_FORCE_DOCTYPE_HTML5))
{
$tplcontent.= "\n";
}
$tplcontent.= ''."\n";
$tplcontent.= ''."\n";
$tplcontent.= ''.dol_string_nohtmltag($objectpage->title, 0, 'UTF-8').''."\n";
$tplcontent.= ''."\n";
$tplcontent.= ''."\n";
$tplcontent.= ''."\n";
$tplcontent.= ''."\n";
$tplcontent.= ''."\n";
$tplcontent.= ''."\n";
$tplcontent.= ''."\n";
$tplcontent.= ''."\n";
$tplcontent.= ''."\n";
$tplcontent.= ''."\n";
$tplcontent.= ''."\n";
$tplcontent.= ''."\n";
$tplcontent.= ''."\n";
$tplcontent.= '/ims\', \'\', file_get_contents(DOL_DATA_ROOT."/website/".$websitekey."/htmlheader.html")); ?>'."\n";
$tplcontent.= ''."\n";
$tplcontent.= preg_replace('/<\/?html>/ims', '', $objectpage->htmlheader)."\n";
$tplcontent.= ''."\n";
$tplcontent.= ''."\n";
$tplcontent.= ''."\n";
$tplcontent.= $objectpage->content."\n";
$tplcontent.= ''."\n";
$tplcontent.= ''."\n";
$tplcontent.= '"."\n";
//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;
}
/**
* Save content of the index.php and wrapper.php page
*
* @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
* @param string $filewrapper Full path of file wrapper.php
* @return boolean True if OK
*/
function dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper)
{
global $conf;
$result1=false;
$result2=false;
dol_mkdir($pathofwebsite);
dol_delete_file($fileindex);
$indexcontent = ''."\n";
$result1 = file_put_contents($fileindex, $indexcontent);
if (! empty($conf->global->MAIN_UMASK))
@chmod($fileindex, octdec($conf->global->MAIN_UMASK));
dol_delete_file($filewrapper);
$wrappercontent=file_get_contents(DOL_DOCUMENT_ROOT.'/website/samples/wrapper.html');
$result2 = file_put_contents($filewrapper, $wrappercontent);
if (! empty($conf->global->MAIN_UMASK))
@chmod($filewrapper, octdec($conf->global->MAIN_UMASK));
return ($result1 && $result2);
}
/**
* 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;
}