Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrobocoder <anthon.pang@gmail.com>2009-12-26 02:45:34 +0300
committerrobocoder <anthon.pang@gmail.com>2009-12-26 02:45:34 +0300
commitdb7db47e293e8f386cce769712c1e1d40eb48b13 (patch)
tree682fe65aa2f44f4f2b8bc2483d2db3db55cb4c99 /js/index.php
parent9a48fc60d1cce8a344ec7e09293e3d958099486d (diff)
support manually gzip'd piwik.js for sites that don't support on-the-fly compression
git-svn-id: http://dev.piwik.org/svn/trunk@1733 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'js/index.php')
-rw-r--r--js/index.php43
1 files changed, 27 insertions, 16 deletions
diff --git a/js/index.php b/js/index.php
index 483e5fbabe..3fc633f3a6 100644
--- a/js/index.php
+++ b/js/index.php
@@ -9,7 +9,7 @@
$file = '../piwik.js';
-if (file_exists($file)) {
+if (file_exists($file) && function_exists('readfile')) {
// conditional GET
$modifiedSince = '';
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
@@ -20,30 +20,41 @@ if (file_exists($file)) {
// optional compression
$compressed = false;
$encoding = '';
- if (extension_loaded('zlib') && function_exists('file_get_contents') && function_exists('file_put_contents') && isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
+ if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
$acceptEncoding = $_SERVER['HTTP_ACCEPT_ENCODING'];
- if (preg_match('/(?:^|, ?)(deflate)(?:,|$)/', $acceptEncoding, $matches)) {
- $encoding = $matches[1];
- } else if (preg_match('/(?:^|, ?)((x-)?gzip)(?:,|$)/', $acceptEncoding, $matches)) {
- $encoding = $matches[1];
- }
+ if (extension_loaded('zlib') && function_exists('file_get_contents') && function_exists('file_put_contents')) {
+ if (preg_match('/(?:^|, ?)(deflate)(?:,|$)/', $acceptEncoding, $matches)) {
+ $encoding = 'deflate';
+ $filegz = '../piwik.js.deflate';
+ } else if (preg_match('/(?:^|, ?)((x-)?gzip)(?:,|$)/', $acceptEncoding, $matches)) {
+ $encoding = $matches[1];
+ $filegz = '../piwik.js.gz';
+ }
- if (!empty($encoding)) {
- $filegz = '../piwik.js.' . $encoding;
+ if (!empty($encoding)) {
+ // compress-on-demand and use cache
+ if(!file_exists($filegz) || (filemtime($file) > filemtime($filegz))) {
+ $data = file_get_contents($file);
- if(!file_exists($filegz) || (filemtime($file) > filemtime($filegz))) {
- $data = file_get_contents($file);
+ if ($encoding == 'deflate') {
+ $data = gzcompress($data, 9);
+ } else if ($encoding == 'gzip' || $encoding == 'x-gzip') {
+ $data = gzencode($data, 9);
+ }
- if ($encoding == 'deflate') {
- $data = gzcompress($data, 9);
- } else if ($encoding == 'gzip' || $encoding == 'x-gzip') {
- $data = gzencode($data, 9);
+ file_put_contents($filegz, $data);
+ $file = $filegz;
}
- file_put_contents($filegz, $data);
$compressed = true;
$file = $filegz;
}
+ } else {
+ // manually compressed
+ $filegz = '../piwik.js.gz';
+ if (preg_match('/(?:^|, ?)((x-)?gzip)(?:,|$)/', $acceptEncoding, $matches) && file_exists($filegz) && (filemtime($file) < filemtime($filegz))) {
+ $file = $filegz;
+ }
}
}