PageRenderTime 152ms CodeModel.GetById 71ms app.highlight 3ms RepoModel.GetById 77ms app.codeStats 0ms

/details/har.php

http://showslow.googlecode.com/
PHP | 79 lines | 66 code | 13 blank | 0 comment | 14 complexity | 73ff7ac1b94f2ffc0acb287338ad475e MD5 | raw file
 1<?php 
 2require_once(dirname(dirname(__FILE__)).'/global.php');
 3
 4if (!array_key_exists('id', $_GET) && (!array_key_exists('url', $_GET) || filter_var($_GET['url'], FILTER_VALIDATE_URL) === false)) {
 5	header('HTTP/1.0 400 Bad Request');
 6
 7	?><html>
 8<head>
 9<title>Bad Request: no valid url or har id specified</title>
10</head>
11<body>
12<h1>Bad Request: no valid url or har id specified</h1>
13<p>You must pass valid URL as 'url' parameter or HAR file ID as 'id' parameter</p>
14</body></html>
15<?php 
16	exit;
17}
18
19
20if (array_key_exists('id', $_GET)) {
21	$query = sprintf("SELECT har, compressed FROM har WHERE id = '%d'",
22		mysql_real_escape_string($_GET['id'])
23	);
24}
25else
26{
27	$query = sprintf("SELECT UNIX_TIMESTAMP(timestamp) as t, har, compressed
28		FROM har, urls WHERE urls.url = '%s' AND har.url_id = urls.id ORDER BY timestamp DESC LIMIT 1",
29		mysql_real_escape_string($_GET['url'])
30	);
31}
32
33$result = mysql_query($query);
34
35if (!$result) {
36        error_log(mysql_error());
37}
38
39$harp = false;
40if (array_key_exists('callback', $_GET)) {
41	$harp = $_GET['callback'];
42
43	if (!preg_match('/^[a-z]([a-z0-9\.]*[a-z0-9])?$/i', $harp)) {
44		$harp = false;
45	}
46}
47
48if ($row = mysql_fetch_assoc($result)) {
49	header('Content-type: text/plain');
50	if (array_key_exists('id', $_GET)) {
51		header('Expires: '.date('r', time() + 315569260));
52		header('Cache-control: max-age=315569260');
53	}
54
55	if ($harp) {
56		echo $harp.'(';
57	}
58
59	echo $row['compressed'] ? gzuncompress($row['har']) : $row['har'];
60 
61	if ($harp) {
62		echo ');';
63	}
64}
65else
66{
67	header('HTTP/1.0 404 No HAR(P) found');
68
69	?><html>
70<head>
71<title>404 No HAR<?php if ($harp) {?>P<?php } ?> found</title>
72</head>
73<body>
74<h1>404 No HAR<?php if ($harp) {?>P<?php } ?> found</h1>
75<p>No HAR<?php if ($harp) {?>P<?php } ?> data found</p>
76</body></html>
77<?php 
78	exit;
79}