From 6a3be553f72d750c9f40d5cb64d8bc9c2cfa3a7d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 7 Oct 2017 03:08:01 +0200 Subject: [PATCH] Start to work on common js part. --- htdocs/langs/en_US/website.lang | 3 +- htdocs/websites/index.php | 95 ++++++++++++++++++++++++++++++--- 2 files changed, 89 insertions(+), 9 deletions(-) diff --git a/htdocs/langs/en_US/website.lang b/htdocs/langs/en_US/website.lang index c065dc7ca53..4352c480fc0 100644 --- a/htdocs/langs/en_US/website.lang +++ b/htdocs/langs/en_US/website.lang @@ -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.
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 "%s" to edit this alias. diff --git a/htdocs/websites/index.php b/htdocs/websites/index.php index 18941f20823..523e7b7e561 100644 --- a/htdocs/websites/index.php +++ b/htdocs/websites/index.php @@ -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.= "\n"; + + $jscontent.= GETPOST('WEBSITE_JS_INLINE', 'none'); + + $jscontent.= "\n".'"."\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.= "\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 ''; + // JS file + print ''; + print $langs->trans('WEBSITE_JS_INLINE'); + print ''; + + $doleditor=new DolEditor('WEBSITE_JS_INLINE', $jscontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', ''); + print $doleditor->Create(1, '', true, 'JS', 'javascript'); + + print ''; + // Common HTML header print ''; 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.='