From bf9d90c0821df2c226822c4691ef5e8ec633490d Mon Sep 17 00:00:00 2001 From: Vincent Zanotti Date: Sun, 8 Nov 2009 22:20:58 +0100 Subject: [PATCH] Serves javascript file from a per-version directory, to prevent cross-version caching issues. Also normalizes the javascript inclusion, moving the common ones to PlPage implementations (prepares the upcoming javascript minimization). Signed-off-by: Vincent Zanotti --- classes/plpage.php | 6 ++---- include/platal.inc.php | 16 ++++++++++++++++ plugins/compiler.checkpasswd.php | 2 +- plugins/compiler.javascript.php | 14 ++++---------- templates/plpage.header.tpl | 6 ++++-- 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/classes/plpage.php b/classes/plpage.php index f444708..15c81bf 100644 --- a/classes/plpage.php +++ b/classes/plpage.php @@ -60,7 +60,6 @@ abstract class PlPage extends Smarty . " actuellement désactivée, en particulier aucune donnée ne sera sauvegardée"); } $this->register_prefilter('at_to_globals'); - $this->addJsLink('jquery.js'); } // }}} @@ -153,7 +152,6 @@ abstract class PlPage extends Smarty if (S::i('auth') <= AUTH_PUBLIC) { $this->register_outputfilter('hide_emails'); } - $this->addJsLink('wiki.js'); header("Accept-Charset: utf-8"); if (Env::v('forceXml')) { pl_content_headers("text/xml"); @@ -291,9 +289,9 @@ abstract class PlPage extends Smarty // }}} // {{{ function addJsLink - public function addJsLink($path) + public function addJsLink($filename) { - $this->append('pl_js', $path); + $this->append('pl_js', pl_static_content_path("javascript/", $filename)); } // }}} diff --git a/include/platal.inc.php b/include/platal.inc.php index ef02627..badaef5 100644 --- a/include/platal.inc.php +++ b/include/platal.inc.php @@ -177,6 +177,21 @@ function pl_entity_decode($text, $mode = ENT_COMPAT) } /** + * Returns the path of a static content, including, when appropriate, the + * version number. This is used to avoid cross-version cache issues, by ensuiring + * that all static resources are served on a unique path. + */ +function pl_static_content_path($path, $filename) +{ + global $globals; + if (isset($globals) && isset($globals->version)) { + return $path . $globals->version . '/' . $filename; + } else { + return $path . $filename; + } +} + +/** * Adds content type headers; by default the encoding used is utf-8. */ function pl_content_headers($content_type, $encoding = 'utf-8') @@ -200,6 +215,7 @@ function pl_cached_content_headers($content_type, $encoding = null, $cache_durat header("Cache-Control: max-age=$cache_duration"); header("Expires: " . gmdate('D, d M Y H:i:s', time() + $cache_duration) . " GMT"); + header("Pragma: "); pl_content_headers($content_type, $encoding); } diff --git a/plugins/compiler.checkpasswd.php b/plugins/compiler.checkpasswd.php index de984a5..8fe3c44 100644 --- a/plugins/compiler.checkpasswd.php +++ b/plugins/compiler.checkpasswd.php @@ -35,7 +35,7 @@ function smarty_compiler_checkpasswd($tag_attrs, &$compiler) $text = "'Changer'"; } - return '?> + return '?> \n diff --git a/templates/plpage.header.tpl b/templates/plpage.header.tpl index a007e2b..33a5c49 100644 --- a/templates/plpage.header.tpl +++ b/templates/plpage.header.tpl @@ -42,7 +42,7 @@ {if t($pl_js)} {foreach from=$pl_js item=js} - + {/foreach} {/if} {if t($pl_rss)} @@ -51,6 +51,8 @@ {if t($pl_extra_header)} {$pl_extra_header|smarty:nodefaults} {/if} -{if t($pl_title)}{$pl_title}{/if} +{if t($pl_title)} +{$pl_title} +{/if} {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} -- 2.1.4