Debug module website
This commit is contained in:
parent
fcf04c122f
commit
89a62103ca
@ -26,6 +26,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php';
|
||||
@ -116,6 +117,11 @@ $tabfieldcheck[1] = array();
|
||||
$elementList = array();
|
||||
$sourceList=array();
|
||||
|
||||
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
|
||||
// Actions add or modify a website
|
||||
if (GETPOST('actionadd','alpha') || GETPOST('actionmodify','alpha'))
|
||||
{
|
||||
@ -128,19 +134,20 @@ if (GETPOST('actionadd','alpha') || GETPOST('actionmodify','alpha'))
|
||||
$ok=1;
|
||||
foreach ($listfield as $f => $value)
|
||||
{
|
||||
if ((! isset($_POST[$value]) || $_POST[$value]=='')
|
||||
&& (! in_array($listfield[$f], array('virtualhost')))) // Fields that are not mandatory
|
||||
{
|
||||
$ok=0;
|
||||
$fieldnamekey=$listfield[$f];
|
||||
setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)), null, 'errors');
|
||||
}
|
||||
if ($value == 'ref' && ! preg_match('/^[a-z0-9_\-\.]+$/i', $_POST[$value]))
|
||||
{
|
||||
if ($value == 'ref' && (! isset($_POST[$value]) || $_POST[$value]==''))
|
||||
{
|
||||
$ok=0;
|
||||
$fieldnamekey=$listfield[$f];
|
||||
setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)), null, 'errors');
|
||||
break;
|
||||
}
|
||||
elseif ($value == 'ref' && ! preg_match('/^[a-z0-9_\-\.]+$/i', $_POST[$value]))
|
||||
{
|
||||
$ok=0;
|
||||
$fieldnamekey=$listfield[$f];
|
||||
$fieldnamekey=$listfield[$f];
|
||||
setEventMessages($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities($fieldnamekey)), null, 'errors');
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Clean parameters
|
||||
@ -206,29 +213,6 @@ if (GETPOST('actionadd','alpha') || GETPOST('actionmodify','alpha'))
|
||||
$result = $db->query($sql);
|
||||
if ($result) // Add is ok
|
||||
{
|
||||
global $dolibarr_main_data_root;
|
||||
$pathofwebsite=$dolibarr_main_data_root.'/website/'.$websitekey;
|
||||
$filehtmlheader=$pathofwebsite.'/htmlheader.html';
|
||||
$filecss=$pathofwebsite.'/styles.css.php';
|
||||
$filetpl=$pathofwebsite.'/page'.$pageid.'.tpl.php';
|
||||
$fileindex=$pathofwebsite.'/index.php';
|
||||
|
||||
// Css file
|
||||
$csscontent = '<!-- BEGIN DOLIBARR-WEBSITE-ADDED-HEADER -->'."\n";
|
||||
$csscontent.= '<!-- File generated to wrap the css file - YOU CAN MODIFY DIRECTLY THE FILE styles.css.php. Change affects all pages of website. -->'."\n";
|
||||
$csscontent.= '<?php '."\n";
|
||||
$csscontent.= "header('Content-type: text/css');\n";
|
||||
$csscontent.= "?>"."\n";
|
||||
$csscontent.= '<!-- END -->'."\n";
|
||||
$csscontent.= 'body { margin: 0; }'."\n";
|
||||
|
||||
dol_syslog("Save file css into ".$filecss);
|
||||
|
||||
dol_mkdir($pathofwebsite);
|
||||
$result = file_put_contents($filecss, $csscontent);
|
||||
if (! empty($conf->global->MAIN_UMASK))
|
||||
@chmod($filecss, octdec($conf->global->MAIN_UMASK));
|
||||
|
||||
setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
|
||||
unset($_POST); // Clean $_POST array, we keep only
|
||||
}
|
||||
@ -335,21 +319,36 @@ if ($action == 'confirm_delete' && $confirm == 'yes') // delete
|
||||
if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
|
||||
else { $rowidcol="rowid"; }
|
||||
|
||||
$sql = "DELETE from ".MAIN_DB_PREFIX."website_page WHERE fk_website ='".$rowid."'";
|
||||
$result = $db->query($sql);
|
||||
$website = new Website($db);
|
||||
$website->fetch($rowid);
|
||||
|
||||
$sql = "DELETE from ".MAIN_DB_PREFIX."website WHERE rowid ='".$rowid."'";
|
||||
$result = $db->query($sql);
|
||||
if (! $result)
|
||||
if ($website->id > 0)
|
||||
{
|
||||
if ($db->errno() == 'DB_ERROR_CHILD_EXISTS')
|
||||
{
|
||||
setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db);
|
||||
}
|
||||
$sql = "DELETE from ".MAIN_DB_PREFIX."website_page WHERE fk_website ='".$rowid."'";
|
||||
$result = $db->query($sql);
|
||||
|
||||
$sql = "DELETE from ".MAIN_DB_PREFIX."website WHERE rowid ='".$rowid."'";
|
||||
$result = $db->query($sql);
|
||||
if (! $result)
|
||||
{
|
||||
if ($db->errno() == 'DB_ERROR_CHILD_EXISTS')
|
||||
{
|
||||
setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db);
|
||||
}
|
||||
}
|
||||
|
||||
if ($website->ref)
|
||||
{
|
||||
dol_delete_dir_recursive($conf->website->dir_output.'/'.$website->ref);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db, 'Failed to load website with id '.$rowid);
|
||||
}
|
||||
}
|
||||
|
||||
@ -618,7 +617,8 @@ if ($id)
|
||||
}
|
||||
|
||||
// Can an entry be erased or disabled ?
|
||||
$iserasable=1;$isdisable=1; // true by default
|
||||
$iserasable=1; $isdisable=1; // true by default
|
||||
if ($obj->status) $iserasable=0; // We can't delete a website on. Disable it first.
|
||||
|
||||
$url = $_SERVER["PHP_SELF"].'?'.($page?'page='.$page.'&':'').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.(! empty($obj->rowid)?$obj->rowid:(! empty($obj->code)?$obj->code:'')).'&code='.(! empty($obj->code)?urlencode($obj->code):'').'&';
|
||||
|
||||
@ -628,12 +628,11 @@ if ($id)
|
||||
print "</td>";
|
||||
|
||||
// Modify link
|
||||
if ($iserasable) print '<td align="center"><a class="reposition" href="'.$url.'action=edit">'.img_edit().'</a></td>';
|
||||
else print '<td> </td>';
|
||||
print '<td align="center"><a class="reposition" href="'.$url.'action=edit">'.img_edit().'</a></td>';
|
||||
|
||||
// Delete link
|
||||
if ($iserasable) print '<td align="center"><a href="'.$url.'action=delete">'.img_delete().'</a></td>';
|
||||
else print '<td> </td>';
|
||||
else print '<td align="center">'.img_delete($langs->trans("DisableSiteFirst"), 'class="opacitymedium"').'</td>';
|
||||
|
||||
print "</tr>\n";
|
||||
}
|
||||
|
||||
@ -368,6 +368,238 @@ function getAllImages($object, $objectpage, $urltograb, &$tmp, &$action, $modify
|
||||
$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 $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";
|
||||
$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.= "<?php // BEGIN PHP\n";
|
||||
$tplcontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
|
||||
$tplcontent.= "if (! defined('USEDOLIBARRSERVER')) { require_once './master.inc.php'; } // Not already loaded"."\n";
|
||||
$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";
|
||||
$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.'" />'."\n";
|
||||
$tplcontent.= '<!-- Include link to CSS file -->'."\n";
|
||||
$tplcontent.= '<link rel="stylesheet" href="styles.css.php?websiteid='.$object->id.'" type="text/css" />'."\n";
|
||||
$tplcontent.= '<!-- Include HTML header from common file -->'."\n";
|
||||
$tplcontent.= '<?php print file_get_contents(DOL_DATA_ROOT."/website/'.$object->ref.'/htmlheader.html"); ?>'."\n";
|
||||
$tplcontent.= '<!-- Include HTML header from page inline block -->'."\n";
|
||||
$tplcontent.= $objectpage->htmlheader."\n";
|
||||
$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";
|
||||
$tplcontent.= "// END PHP ?>"."\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 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -5,14 +5,15 @@ DeleteWebsite=Delete website
|
||||
ConfirmDeleteWebsite=Are you sure you want to delete this web site. All its pages and content will also be removed.
|
||||
WEBSITE_TYPE_CONTAINER=Type of page/container
|
||||
WEBSITE_PAGENAME=Page name/alias
|
||||
HtmlHeaderPage=HTML specific header for page
|
||||
WEBSITE_CSS_URL=URL of external CSS file
|
||||
WEBSITE_CSS_INLINE=CSS file content (common to all pages)
|
||||
WEBSITE_JS_INLINE=Javascript file content (common to all pages)
|
||||
WEBSITE_HTML_HEADER=Addition at bottom of HTML Header (common to all pages)
|
||||
WEBSITE_ROBOT=Robot file (robots.txt)
|
||||
WEBSITE_HTACCESS=Web site .htaccess file
|
||||
PageNameAliasHelp=Name or alias of the page.<br>This alias is also used to forge a SEO URL when website is ran from a Virtual host of a Web server (like Apacke, Nginx, ...). Use the button "<strong>%s</strong>" to edit this alias.
|
||||
HtmlHeaderPage=HTML header (specific to this page only)
|
||||
PageNameAliasHelp=Name or alias of the page.<br>This alias is also used to forge a SEO URL when website is ran from a Virtual host of a Web server (like Apacke, Nginx, ...). Use the button "<strong>%s</strong>" to edit this alias.
|
||||
EditTheWebSiteForACommonHeader=Note: If you want to define a personalized header for all pages, edit the header on the site level instead of on the page/container.
|
||||
MediaFiles=Media library
|
||||
EditCss=Edit Style/CSS or HTML header
|
||||
EditMenu=Edit menu
|
||||
@ -59,4 +60,5 @@ BlogPost=Blog post
|
||||
WebsiteAccount=Web site account
|
||||
WebsiteAccounts=Web site accounts
|
||||
AddWebsiteAccount=Create web site account
|
||||
BackToListOfThirdParty=Back to list for Third Party
|
||||
BackToListOfThirdParty=Back to list for Third Party
|
||||
DisableSiteFirst=Disable website first
|
||||
@ -107,6 +107,8 @@ class Website extends CommonObject
|
||||
*/
|
||||
public function create(User $user, $notrigger = false)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||
|
||||
$error = 0;
|
||||
@ -129,7 +131,7 @@ class Website extends CommonObject
|
||||
if (empty($this->date_modification)) $this->date_modification = $now;
|
||||
|
||||
// Check parameters
|
||||
// Put here code to add control on parameters values
|
||||
if (empty($this->entity)) { $this->entity = $conf->entity; }
|
||||
|
||||
// Insert request
|
||||
$sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '(';
|
||||
|
||||
@ -605,7 +605,7 @@ if ($action == 'addcontainer')
|
||||
|
||||
if (! dol_is_file($filehtmlheader))
|
||||
{
|
||||
$htmlheadercontent = "<!-- HTML header content (common for all pages) -->";
|
||||
$htmlheadercontent = "<html>\n<!-- HTML header content (common for all pages) -->\n</html>";
|
||||
$result=dolSaveHtmlHeader($filehtmlheader, $htmlheadercontent);
|
||||
}
|
||||
|
||||
@ -1616,7 +1616,7 @@ $head = array();
|
||||
|
||||
|
||||
/*
|
||||
* Edit mode
|
||||
* Edit Site HTML header of CSS
|
||||
*/
|
||||
|
||||
if ($action == 'editcss')
|
||||
@ -1624,28 +1624,53 @@ if ($action == 'editcss')
|
||||
print '<div class="fiche">';
|
||||
|
||||
print '<br>';
|
||||
|
||||
$csscontent = @file_get_contents($filecss);
|
||||
// Clean the php css file to remove php code and get only css part
|
||||
$csscontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $csscontent);
|
||||
$csscontent.= GETPOST('WEBSITE_CSS_INLINE');
|
||||
if (GETPOST('editcss','alpha') || GETPOST('refreshpage','alpha'))
|
||||
{
|
||||
$csscontent = @file_get_contents($filecss);
|
||||
// Clean the php css file to remove php code and get only css part
|
||||
$csscontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $csscontent);
|
||||
}
|
||||
else
|
||||
{
|
||||
$csscontent = GETPOST('WEBSITE_CSS_INLINE');
|
||||
}
|
||||
if (! trim($csscontent)) $csscontent='/* CSS content (all pages) */'."\n".'body.bodywebsite { margin: 0; }';
|
||||
|
||||
$jscontent = @file_get_contents($filejs);
|
||||
// Clean the php js file to remove php code and get only js part
|
||||
$jscontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $jscontent);
|
||||
$jscontent.= GETPOST('WEBSITE_JS_INLINE');
|
||||
if (GETPOST('editcss','alpha') || GETPOST('refreshpage','alpha'))
|
||||
{
|
||||
$jscontent = @file_get_contents($filejs);
|
||||
// Clean the php js file to remove php code and get only js part
|
||||
$jscontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $jscontent);
|
||||
}
|
||||
else
|
||||
{
|
||||
$jscontent = GETPOST('WEBSITE_JS_INLINE');
|
||||
}
|
||||
if (! trim($jscontent)) $jscontent='/* JS content (all pages) */'."\n";
|
||||
|
||||
$htmlheader = @file_get_contents($filehtmlheader);
|
||||
// Clean the php htmlheader file to remove php code and get only html part
|
||||
$htmlheader = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $htmlheader);
|
||||
if (! trim($htmlheader)) $htmlheader='<!-- HTML header content (common for all pages) -->';
|
||||
if (GETPOST('editcss','alpha') || GETPOST('refreshpage','alpha'))
|
||||
{
|
||||
$htmlheader = @file_get_contents($filehtmlheader);
|
||||
// Clean the php htmlheader file to remove php code and get only html part
|
||||
$htmlheader = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $htmlheader);
|
||||
}
|
||||
else
|
||||
{
|
||||
$htmlheader = GETPOST('WEBSITE_HTML_HEADER');
|
||||
}
|
||||
if (! trim($htmlheader)) $htmlheader="<html>\n<!-- HTML header content (common for all pages) -->\n</html>";
|
||||
else $htmlheader='<html>'."\n".trim($htmlheader)."\n".'</html>';
|
||||
|
||||
$robotcontent = @file_get_contents($filerobot);
|
||||
// Clean the php htmlheader file to remove php code and get only html part
|
||||
$robotcontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $robotcontent);
|
||||
if (GETPOST('editcss','alpha') || GETPOST('refreshpage','alpha'))
|
||||
{
|
||||
$robotcontent = @file_get_contents($filerobot);
|
||||
// Clean the php htmlheader file to remove php code and get only html part
|
||||
$robotcontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $robotcontent);
|
||||
}
|
||||
else
|
||||
{
|
||||
$robotcontent = GETPOST('WEBSITE_ROBOT');
|
||||
}
|
||||
if (! trim($robotcontent))
|
||||
{
|
||||
$robotcontent.="# Robot file. Generated with ".DOL_APPLICATION_TITLE."\n";
|
||||
@ -1654,9 +1679,16 @@ if ($action == 'editcss')
|
||||
$robotcontent.="Disallow: /administrator/\n";
|
||||
}
|
||||
|
||||
$htaccesscontent = @file_get_contents($filehtaccess);
|
||||
// Clean the php htaccesscontent file to remove php code and get only html part
|
||||
$htaccesscontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $htaccesscontent);
|
||||
if (GETPOST('editcss','alpha') || GETPOST('refreshpage','alpha'))
|
||||
{
|
||||
$htaccesscontent = @file_get_contents($filehtaccess);
|
||||
// Clean the php htaccesscontent file to remove php code and get only html part
|
||||
$htaccesscontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $htaccesscontent);
|
||||
}
|
||||
else
|
||||
{
|
||||
$htaccesscontent = GETPOST('WEBSITE_HTACCESS');
|
||||
}
|
||||
if (! trim($htaccesscontent))
|
||||
{
|
||||
$htaccesscontent.="# Order allow,deny\n";
|
||||
@ -1926,7 +1958,12 @@ if ($action == 'editmeta' || $action == 'createcontainer')
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td class="tdhtmlheader tdtop">';
|
||||
print $langs->trans('HtmlHeaderPage');
|
||||
$htmlhelp=$langs->trans("EditTheWebSiteForACommonHeader").'<br><br>';
|
||||
$htmlhelp.=$langs->trans("Example").' :<br>';
|
||||
$htmlhelp.='<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous" ></script><br>';
|
||||
$htmlhelp.='<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js" integrity="sha256-T0Vest3yCU7pafRw9r+settMBX6JkKN06dqBnpQ8d30=" crossorigin="anonymous" ></script><br>';
|
||||
$htmlhelp.='<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" /><br>';
|
||||
print $form->textwithpicto($langs->trans('HtmlHeaderPage'), $htmlhelp, 1, 'help', '', 0, 2, 'htmlheadertooltip');
|
||||
print '</td><td>';
|
||||
$doleditor=new DolEditor('htmlheader', $pagehtmlheader, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '');
|
||||
print $doleditor->Create(1, '', true, 'HTML Header', 'html');
|
||||
@ -2101,237 +2138,3 @@ if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpa
|
||||
llxFooter();
|
||||
|
||||
$db->close();
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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";
|
||||
$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.= "<?php // BEGIN PHP\n";
|
||||
$tplcontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
|
||||
$tplcontent.= "if (! defined('USEDOLIBARRSERVER')) { require_once './master.inc.php'; } // Not already loaded"."\n";
|
||||
$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";
|
||||
$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.'" />'."\n";
|
||||
$tplcontent.= '<!-- Include link to CSS file -->'."\n";
|
||||
$tplcontent.= '<link rel="stylesheet" href="styles.css.php?websiteid='.$object->id.'" type="text/css" />'."\n";
|
||||
$tplcontent.= '<!-- Include HTML header from common file -->'."\n";
|
||||
$tplcontent.= '<?php print file_get_contents(DOL_DATA_ROOT."/website/'.$object->ref.'/htmlheader.html"); ?>'."\n";
|
||||
$tplcontent.= '<!-- Include HTML header from page inline block -->'."\n";
|
||||
$tplcontent.= $objectpage->htmlheader."\n";
|
||||
$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";
|
||||
$tplcontent.= "// END PHP ?>"."\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 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 html header 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 html header 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 html header 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 html header 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;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user