فهرست منبع

reset_browser_cache()

Signed-off-by: Suki <[email protected]>
Suki 10 سال پیش
والد
کامیت
b03abfcb6c
2فایلهای تغییر یافته به همراه22 افزوده شده و 5 حذف شده
  1. 3 3
      Sources/Load.php
  2. 19 2
      Sources/Subs.php

+ 3 - 3
Sources/Load.php

@@ -2095,13 +2095,13 @@ function loadCSSFile($filename, $params = array(), $id = '')
  *  - ['validate'] (true/false): if true script will validate the local file exists
  *  - ['seed'] (true/false/string): if true or null, use cache stale, false do not, or used a supplied string
  *
- * @param string $id An ID to stik on the end of the filename
+ * @param string $id An ID to stick on the end of the filename
  */
 function loadJavascriptFile($filename, $params = array(), $id = '')
 {
-	global $settings, $context;
+	global $settings, $context, reset_browser_cache;
 
-	$params['seed'] = (!isset($params['seed']) || $params['seed'] === true) ? '?alph21' : (is_string($params['seed']) ? ($params['seed'] = $params['seed'][0] === '?' ? $params['seed'] : '?' . $params['seed']) : '');
+	$params['seed'] = (!isset($params['seed']) || $params['seed'] === true) ? $modSettings['browser_cache'] : (is_string($params['seed']) ? ($params['seed'] = $params['seed'][0] === '?' ? $params['seed'] : '?' . $params['seed']) : '');
 	$params['force_current'] = !empty($params['force_current']) ? $params['force_current'] : false;
 	$theme = !empty($params['default_theme']) ? 'default_theme' : 'theme';
 

+ 19 - 2
Sources/Subs.php

@@ -3324,7 +3324,7 @@ function template_css()
 		// Try to keep only what's useful.
 		$repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => '');
 		foreach ($context['css_files'] as $file)
-			$context['debug']['sheets'][] = strtr($file['filename'], $repl); 
+			$context['debug']['sheets'][] = strtr($file['filename'], $repl);
 	}
 
 	if (!empty($context['css_header']))
@@ -3692,7 +3692,7 @@ function setupMenuContext()
 	if (!isset($context['allow_calendar_event']))
 	{
 		$context['allow_calendar_event'] = $context['allow_calendar'] && allowedTo('calendar_post');
-		
+
 		// If you don't allow events not linked to posts and you're not an admin, we have more work to do...
 		if ($context['allow_calendar'] && $context['allow_calendar_event'] && empty($modSettings['cal_allow_unlinked']) && !$user_info['is_admin'])
 		{
@@ -3967,6 +3967,23 @@ function smf_seed_generator()
 	updateSettings(array('rand_seed' => mt_rand()));
 }
 
+/**
+ * Force browsers to grab a new copy of css / js files by changing ?bit
+ */
+function reset_browser_cache($set = '')
+{
+	global $modSettings;
+
+	if(empty($modSettings['browser_cache']) || empty($set) || preg_match('~^[a-z0-9]{1,4}$~i', $set) === false)
+		$modSettings['browser_cache'] = substr(sha1(microtime()), 0, 4);
+
+	else
+		$modSettings['browser_cache'] = $set;
+
+	// Save it
+	updateSettings(array('browser_cache' => $modSettings['browser_cache']));
+}
+
 /**
  * Process functions of an integration hook.
  * calls all functions of the given hook.