Clean code of lib_notification. Now use cache like other js.

This commit is contained in:
Laurent Destailleur
2021-07-08 23:19:43 +02:00
parent 4e69afb253
commit aa9d98a336
4 changed files with 140 additions and 111 deletions

View File

@@ -47,6 +47,11 @@ session_cache_limiter('public');
require_once '../../main.inc.php'; require_once '../../main.inc.php';
/*
* View
*/
// Define javascript type // Define javascript type
top_httphead('text/javascript; charset=UTF-8'); top_httphead('text/javascript; charset=UTF-8');
// Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access. // Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access.

View File

@@ -50,6 +50,11 @@ session_cache_limiter('public');
require_once '../../main.inc.php'; require_once '../../main.inc.php';
/*
* View
*/
// Define javascript type // Define javascript type
top_httphead('text/javascript; charset=UTF-8'); top_httphead('text/javascript; charset=UTF-8');
// Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access. // Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access.

View File

@@ -41,15 +41,28 @@ if (!defined('NOREQUIREHTML')) {
define('NOREQUIREHTML', 1); define('NOREQUIREHTML', 1);
} }
session_cache_limiter('public');
require_once '../../main.inc.php'; require_once '../../main.inc.php';
if (!($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root.'/' || $_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root.'/index.php'
|| preg_match('/getmenu_div\.php/', $_SERVER['HTTP_REFERER']))) { /*
global $langs, $conf; * View
*/
top_httphead('text/javascript; charset=UTF-8'); top_httphead('text/javascript; charset=UTF-8');
// Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access.
if (empty($dolibarr_nocache)) {
header('Cache-Control: max-age=10800, public, must-revalidate');
} else {
header('Cache-Control: no-cache');
}
print "jQuery(document).ready(function () {\n";
//print " console.log('referrer=".dol_escape_js($_SERVER['HTTP_REFERER'])."');\n";
print 'var login = \''.$_SESSION['dol_login'].'\';'."\n";
print ' var nowtime = Date.now();'; print ' var nowtime = Date.now();';
print ' var time_auto_update = '.$conf->global->MAIN_BROWSER_NOTIFICATION_FREQUENCY.';'."\n"; // Always defined print ' var time_auto_update = '.$conf->global->MAIN_BROWSER_NOTIFICATION_FREQUENCY.';'."\n"; // Always defined
print ' var time_js_next_test;'."\n"; print ' var time_js_next_test;'."\n";
@@ -62,14 +75,14 @@ if (!($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root.'/' || $_SERVER['HTTP
} }
/* Launch timer */ /* Launch timer */
// We set a delay before launching first test so next check will arrive after the time_auto_update compared to previous one. // We set a delay before launching first test so next check will arrive after the time_auto_update compared to previous one.
//var time_first_execution = (time_auto_update + (time_js_next_test - nowtime)) * 1000; //need milliseconds //var time_first_execution = (time_auto_update + (time_js_next_test - nowtime)) * 1000; //need milliseconds
var time_first_execution = <?php echo max(3, empty($conf->global->MAIN_BROWSER_NOTIFICATION_CHECK_FIRST_EXECUTION) ? 0 : $conf->global->MAIN_BROWSER_NOTIFICATION_CHECK_FIRST_EXECUTION); ?>; var time_first_execution = <?php echo max(3, empty($conf->global->MAIN_BROWSER_NOTIFICATION_CHECK_FIRST_EXECUTION) ? 0 : $conf->global->MAIN_BROWSER_NOTIFICATION_CHECK_FIRST_EXECUTION); ?>;
if (login != '') {
setTimeout(first_execution, time_first_execution * 1000); setTimeout(first_execution, time_first_execution * 1000);
time_js_next_test = nowtime + time_first_execution; time_js_next_test = nowtime + time_first_execution;
console.log("Launch browser notif check: setTimeout is set to launch 'first_execution' function after a wait of time_first_execution="+time_first_execution+". nowtime (time php page generation) = "+nowtime+" time_js_next_check = "+time_js_next_test); console.log("Launch browser notif check: setTimeout is set to launch 'first_execution' function after a wait of time_first_execution="+time_first_execution+". nowtime (time php page generation) = "+nowtime+" time_js_next_check = "+time_js_next_test);
} //first run auto check
function first_execution() { function first_execution() {
@@ -169,4 +182,6 @@ if (!($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root.'/' || $_SERVER['HTTP
} }
} }
<?php <?php
}
print "\n";
print '})'."\n";

View File

@@ -47,6 +47,10 @@ session_cache_limiter('public');
require_once '../../main.inc.php'; require_once '../../main.inc.php';
/*
* View
*/
// Define javascript type // Define javascript type
top_httphead('text/javascript; charset=UTF-8'); top_httphead('text/javascript; charset=UTF-8');
// Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access. // Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access.