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

index.php « js - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 483e5fbabe250e4d1c1fe7e46359b882bea883c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
 * Piwik - Open source web analytics
 * 
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html Gpl v3 or later
 * @version $Id$
 */

$file = '../piwik.js';

if (file_exists($file)) {
	// conditional GET
	$modifiedSince = '';
	if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
		$modifiedSince = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
	}
	$lastModified = gmdate('D, d M Y H:i:s', filemtime($file)) . ' GMT';

	// optional compression
	$compressed = false;
	$encoding = '';
	if (extension_loaded('zlib') && function_exists('file_get_contents') && function_exists('file_put_contents') && 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 (!empty($encoding)) {
			$filegz = '../piwik.js.' . $encoding;

			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);
				}

				file_put_contents($filegz, $data);
				$compressed = true;
				$file = $filegz;
			}
		}
	}

	// strip any trailing data appended to header
	if (false !== ($semicolon = strpos($modifiedSince, ';'))) {
		$modifiedSince = substr($modifiedSince, 0, $semicolon);
	}

	if ($modifiedSince == $lastModified) {
		header('HTTP/1.1 304 Not Modified');
	} else {
		header('Last-Modified: ' . $lastModified);
		header('Content-Length: ' . filesize($file));
		header('Content-Type: application/x-javascript; charset=UTF-8');

		if ($compressed) {
			header('Content-Encoding: ' . $encoding);
		}

		if (!readfile($file)) {
			header ('HTTP/1.0 505 Internal server error');
		}
	}
} else {
	header ('HTTP/1.0 404 Not Found');
}
exit;