Start to work on common js part.
This commit is contained in:
parent
4347bc06a2
commit
6a3be553f7
@ -7,7 +7,8 @@ WEBSITE_PAGENAME=Page name/alias
|
||||
WEBSITE_HTML_HEADER=HTML Header (common to all pages)
|
||||
HtmlHeaderPage=HTML specific header for ppage
|
||||
WEBSITE_CSS_URL=URL of external CSS file
|
||||
WEBSITE_CSS_INLINE=CSS content
|
||||
WEBSITE_CSS_INLINE=CSS file content (common to all pages)
|
||||
WEBSITE_JS_INLINE=Javascript file content (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.
|
||||
|
||||
@ -141,6 +141,7 @@ global $dolibarr_main_data_root;
|
||||
$pathofwebsite=$dolibarr_main_data_root.'/websites/'.$website;
|
||||
$filehtmlheader=$pathofwebsite.'/htmlheader.html';
|
||||
$filecss=$pathofwebsite.'/styles.css.php';
|
||||
$filejs=$pathofwebsite.'/javascript.js.php';
|
||||
$filerobot=$pathofwebsite.'/robots.txt';
|
||||
$filehtaccess=$pathofwebsite.'/.htaccess';
|
||||
$filetpl=$pathofwebsite.'/page'.$pageid.'.tpl.php';
|
||||
@ -497,10 +498,16 @@ if ($action == 'add')
|
||||
|
||||
if (! dol_is_file($filecss))
|
||||
{
|
||||
$csscontent = "/* CSS content (all pages) */\nbody.bodywebsite { margin: 0; }'";
|
||||
$csscontent = "/* CSS content (all pages) */\nbody.bodywebsite { margin: 0; }";
|
||||
$result=dolSaveCssFile($filecss, $csscontent);
|
||||
}
|
||||
|
||||
if (! dol_is_file($filejs))
|
||||
{
|
||||
$jscontent = "/* JS content (all pages) */\n";
|
||||
$result=dolSaveJsFile($filejs, $jscontent);
|
||||
}
|
||||
|
||||
if (! dol_is_file($filerobot))
|
||||
{
|
||||
$robotcontent = "# Robot file. Generated with Dolibarr\nUser-agent: *\nAllow: /public/\nDisallow: /administrator/";
|
||||
@ -621,7 +628,39 @@ if ($action == 'updatecss')
|
||||
}
|
||||
|
||||
|
||||
// Css file
|
||||
// Js file
|
||||
$jscontent ='';
|
||||
|
||||
$jscontent.= "<?php // BEGIN PHP\n";
|
||||
$jscontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
|
||||
$jscontent.= "if (! defined('USEDOLIBARRSERVER')) { require_once dirname(__FILE__).'/master.inc.php'; } // Not already loaded"."\n"; // For the css, we need to set path of master using the dirname of css file.
|
||||
$jscontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
|
||||
$jscontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
|
||||
$jscontent.= "ob_start();\n";
|
||||
$jscontent.= "header('Content-type: application/javascript');\n";
|
||||
$jscontent.= "// END PHP ?>\n";
|
||||
|
||||
$jscontent.= GETPOST('WEBSITE_JS_INLINE', 'none');
|
||||
|
||||
$jscontent.= "\n".'<?php // BEGIN PHP'."\n";
|
||||
$jscontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp);'."\n";
|
||||
$jscontent.= "// END PHP ?>"."\n";
|
||||
|
||||
dol_syslog("Save js content 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)
|
||||
{
|
||||
$error++;
|
||||
setEventMessages('Failed to write file '.$filejs, null, 'errors');
|
||||
}
|
||||
|
||||
|
||||
// Robot file
|
||||
$robotcontent ='';
|
||||
|
||||
/*$robotcontent.= "<?php // BEGIN PHP\n";
|
||||
@ -1424,6 +1463,12 @@ if ($action == 'editcss')
|
||||
$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 (! 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);
|
||||
@ -1473,6 +1518,16 @@ if ($action == 'editcss')
|
||||
|
||||
print '</td></tr>';
|
||||
|
||||
// JS file
|
||||
print '<tr><td class="tdtop">';
|
||||
print $langs->trans('WEBSITE_JS_INLINE');
|
||||
print '</td><td>';
|
||||
|
||||
$doleditor=new DolEditor('WEBSITE_JS_INLINE', $jscontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '');
|
||||
print $doleditor->Create(1, '', true, 'JS', 'javascript');
|
||||
|
||||
print '</td></tr>';
|
||||
|
||||
// Common HTML header
|
||||
print '<tr><td class="tdtop">';
|
||||
print $langs->trans('WEBSITE_HTML_HEADER');
|
||||
@ -1731,11 +1786,9 @@ if ($action == 'editmenu')
|
||||
if ($action == 'editsource')
|
||||
{
|
||||
/*
|
||||
* Editing global variables not related to a specific theme
|
||||
* Editing with source editor
|
||||
*/
|
||||
|
||||
//$csscontent = @file_get_contents($filecss);
|
||||
|
||||
$contentforedit = '';
|
||||
/*$contentforedit.='<style scoped>'."\n"; // "scoped" means "apply to parent element only". Not yet supported by browsers
|
||||
$contentforedit.=$csscontent;
|
||||
@ -1750,11 +1803,9 @@ if ($action == 'editsource')
|
||||
if ($action == 'editcontent')
|
||||
{
|
||||
/*
|
||||
* Editing global variables not related to a specific theme
|
||||
* Editing with default ckeditor
|
||||
*/
|
||||
|
||||
//$csscontent = @file_get_contents($filecss);
|
||||
|
||||
$contentforedit = '';
|
||||
/*$contentforedit.='<style scoped>'."\n"; // "scoped" means "apply to parent element only". Not yet supported by browsers
|
||||
$contentforedit.=$csscontent;
|
||||
@ -1779,6 +1830,7 @@ if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpa
|
||||
// Ouput page under the Dolibarr top menu
|
||||
$objectpage->fetch($pageid);
|
||||
$csscontent = @file_get_contents($filecss);
|
||||
$jscontent = @file_get_contents($filejs);
|
||||
|
||||
$out = '<!-- Page content '.$filetpl.' : Div with (CSS Of website from file + Style/htmlheader of page from database + Page content from database) -->'."\n";
|
||||
|
||||
@ -1991,6 +2043,33 @@ function dolSaveCssFile($filecss, $csscontent)
|
||||
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
|
||||
*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user