/details/data.php
PHP | 158 lines | 138 code | 20 blank | 0 comment | 20 complexity | cfd818f317438ca56eca56e80bd89bc9 MD5 | raw file
1<?php 2require_once(dirname(dirname(__FILE__)).'/global.php'); 3 4if (!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 specified</title> 10</head> 11<body> 12<h1>Bad Request: no valid url specified</h1> 13<p>You must pass valid URL as 'url' parameter</p> 14</body></html> 15<?php 16 exit; 17} 18 19$all = true; 20 21if (array_key_exists('profile', $_GET) && $_GET['profile'] != '' ) { 22 $all = false; 23} 24 25$query = sprintf("SELECT id FROM urls WHERE urls.url = '%s'", mysql_real_escape_string($_GET['url'])); 26$result = mysql_query($query); 27 28if (!$result) { 29 error_log(mysql_error()); 30} 31 32$row = mysql_fetch_assoc($result); 33$urlid = $row['id']; 34mysql_free_result($result); 35 36if ($all) { 37 $query = sprintf("SELECT UNIX_TIMESTAMP(timestamp) as t, y.w, y.o, y.r, y.i, y.lt, 38 y.ynumreq, y.ycdn, y.yexpires, y.ycompress, y.ycsstop, 39 y.yjsbottom, y.yexpressions, y.yexternal, y.ydns, y.yminify, 40 y.yredirects, y.ydupes, y.yetags, y.yxhr, y.yxhrmethod, 41 y.ymindom, y.yno404, y.ymincookie, y.ycookiefree, y.ynofilter, 42 y.yimgnoscale, y.yfavicon 43 FROM yslow2 y WHERE y.url_id = %d AND timestamp > DATE_SUB(now(), INTERVAL 3 MONTH) 44 ORDER BY timestamp DESC", 45 mysql_real_escape_string($urlid) 46 ); 47} else { 48 $query = sprintf("SELECT UNIX_TIMESTAMP(timestamp) as t, y.w, y.o, y.r, y.i, y.lt, 49 y.ynumreq, y.ycdn, y.yexpires, y.ycompress, y.ycsstop, 50 y.yjsbottom, y.yexpressions, y.yexternal, y.ydns, y.yminify, 51 y.yredirects, y.ydupes, y.yetags, y.yxhr, y.yxhrmethod, 52 y.ymindom, y.yno404, y.ymincookie, y.ycookiefree, y.ynofilter, 53 y.yimgnoscale, y.yfavicon 54 FROM yslow2 y WHERE y.url_id = %d AND y.i = '%s' AND timestamp > DATE_SUB(now(),INTERVAL 3 MONTH) 55 ORDER BY timestamp DESC", 56 mysql_real_escape_string($urlid), mysql_real_escape_string($_GET['profile']) 57 ); 58} 59 60$result = mysql_query($query); 61 62if (!$result) { 63 error_log(mysql_error()); 64} 65 66$data = array(); 67 68header('Content-type: text/csv'); 69if (array_key_exists('ver', $_GET)) { 70 header('Expires: '.date('r', time() + 315569260)); 71 header('Cache-control: max-age=315569260'); 72} 73 74$rows = array(); 75while ($row = mysql_fetch_assoc($result)) { 76 $rows[] = $row; 77} 78 79mysql_free_result($result); 80 81if (array_key_exists('smooth', $_REQUEST)) { 82 require_once(dirname(__FILE__).'/smooth.php'); 83 smooth($rows, array('w', 'o', 'r', 'lt')); 84} 85 86if (!array_key_exists('subset', $_REQUEST) || !$_REQUEST['subset'] == 'graph') 87{ 88 header('Content-disposition: attachment;filename=yslow.csv'); 89 90 echo '# Measurement time, '; 91 echo 'Page size (in bytes), '; 92 echo 'YSlow grade, '; 93 echo 'Total number requests, '; 94 echo 'Page Load Time, '; 95 echo "YSlow profile used, "; 96 echo 'Make fewer HTTP requests, '; 97 echo 'Use a Content Delivery Network (CDN), '; 98 echo 'Add Expires headers, '; 99 echo 'Compress components with gzip, '; 100 echo 'Put CSS at top, '; 101 echo 'Put JavaScript at bottom, '; 102 echo 'Avoid CSS expressions, '; 103 echo 'Make JavaScript and CSS external, '; 104 echo 'Reduce DNS lookups, '; 105 echo 'Minify JavaScript and CSS, '; 106 echo 'Avoid URL redirects, '; 107 echo 'Remove duplicate JavaScript and CSS, '; 108 echo 'Configure entity tags (ETags), '; 109 echo 'Make AJAX cacheable, '; 110 echo 'Use GET for AJAX requests, '; 111 echo 'Reduce the number of DOM elements, '; 112 echo 'Avoid HTTP 404 (Not Found) error, '; 113 echo 'Reduce cookie size, '; 114 echo 'Use cookie-free domains, '; 115 echo 'Avoid AlphaImageLoader filter, '; 116 echo 'Do not scale images in HTML, '; 117 echo 'Make favicon small and cacheable'; 118 echo "\n"; 119} 120 121foreach ($rows as $row) { 122 echo date('c', $row['t']).','. 123 ($row['i'] == 'yslow1' ? $row['w'] * 1024 : $row['w']).','. 124 $row['o'].','. 125 $row['r'].','. 126 $row['lt'].','. 127 $row['i']; 128 129 if (array_key_exists('subset', $_REQUEST) && $_REQUEST['subset'] == 'graph') 130 { 131 echo "\n"; 132 } else { 133 echo ','.$row['ynumreq'].','. 134 $row['ycdn'].','. 135 $row['yexpires'].','. 136 $row['ycompress'].','. 137 $row['ycsstop'].','. 138 $row['yjsbottom'].','. 139 $row['yexpressions'].','. 140 $row['yexternal'].','. 141 $row['ydns'].','. 142 $row['yminify'].','. 143 $row['yredirects'].','. 144 $row['ydupes'].','. 145 $row['yetags'].','. 146 $row['yxhr'].','. 147 $row['yxhrmethod'].','. 148 $row['ymindom'].','. 149 $row['yno404'].','. 150 $row['ymincookie'].','. 151 $row['ycookiefree'].','. 152 $row['ynofilter'].','. 153 $row['yimgnoscale'].','. 154 $row['yfavicon']. 155 "\n"; 156 } 157} 158