PageRenderTime 84ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/details/data_metric.php

http://showslow.googlecode.com/
PHP | 67 lines | 53 code | 14 blank | 0 comment | 9 complexity | 82c6a258028c5575bc804a7d2e8e8173 MD5 | raw file
  1. <?php
  2. require_once(dirname(dirname(__FILE__)).'/global.php');
  3. if (!array_key_exists('url', $_GET) || filter_var($_GET['url'], FILTER_VALIDATE_URL) === false
  4. || !array_key_exists('metric', $_GET) || !array_key_exists($_GET['metric'], $metrics)) {
  5. header('HTTP/1.0 400 Bad Request');
  6. ?><html>
  7. <head>
  8. <title>Bad Request: no valid url specified</title>
  9. </head>
  10. <body>
  11. <h1>Bad Request: no valid url specified</h1>
  12. <p>You must pass valid URL as 'url' parameter</p>
  13. </body></html>
  14. <?php
  15. exit;
  16. }
  17. $query = sprintf("SELECT id FROM urls WHERE urls.url = '%s'", mysql_real_escape_string($_GET['url']));
  18. $result = mysql_query($query);
  19. if (!$result) {
  20. error_log(mysql_error());
  21. }
  22. $row = mysql_fetch_assoc($result);
  23. $urlid = $row['id'];
  24. mysql_free_result($result);
  25. $query = sprintf("SELECT UNIX_TIMESTAMP(timestamp) AS t, value
  26. FROM metric WHERE url_id = %d AND metric_id = %d AND timestamp > DATE_SUB(now(), INTERVAL 3 MONTH)
  27. ORDER BY timestamp DESC",
  28. mysql_real_escape_string($urlid),
  29. mysql_real_escape_string($metrics[$_GET['metric']]['id'])
  30. );
  31. $result = mysql_query($query);
  32. if (!$result) {
  33. error_log(mysql_error());
  34. }
  35. $data = array();
  36. header('Content-type: text/plain');
  37. if (array_key_exists('ver', $_GET)) {
  38. header('Expires: '.date('r', time() + 315569260));
  39. header('Cache-control: max-age=315569260');
  40. }
  41. echo '# Timestamp, '.$metrics[$_GET['metric']]['title'].' for '.$_GET['url']."\n";
  42. $rows = array();
  43. while ($row = mysql_fetch_assoc($result)) {
  44. $rows[] = $row;
  45. }
  46. mysql_free_result($result);
  47. if (array_key_exists('smooth', $_REQUEST)) {
  48. require_once(dirname(__FILE__).'/smooth.php');
  49. smooth($rows, array('value'));
  50. }
  51. foreach ($rows as $row) {
  52. echo date('c', $row['t']).','.$row['value']."\n";
  53. }