PageRenderTime 31ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/details/events.php

http://showslow.googlecode.com/
PHP | 65 lines | 51 code | 14 blank | 0 comment | 7 complexity | 8c8c713edeedfa1cdcb7df252ce58176 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. header('HTTP/1.0 400 Bad Request');
  5. ?><html>
  6. <head>
  7. <title>Bad Request: no valid url specified</title>
  8. </head>
  9. <body>
  10. <h1>Bad Request: no valid url specified</h1>
  11. <p>You must pass valid URL as 'url' parameter</p>
  12. </body></html>
  13. <?php
  14. exit;
  15. }
  16. $all = true;
  17. $query = sprintf("SELECT type, title, UNIX_TIMESTAMP(start) as s, UNIX_TIMESTAMP(end) as e, resource_url as link FROM event
  18. WHERE INSTR('%s', url_prefix) = 1
  19. ORDER BY start DESC",
  20. mysql_real_escape_string($_GET['url'])
  21. );
  22. $result = mysql_query($query);
  23. if (!$result) {
  24. error_log(mysql_error());
  25. }
  26. $data = array();
  27. header('Content-type: text/xml');
  28. if (array_key_exists('ver', $_GET)) {
  29. header('Expires: '.date('r', time() + 315569260));
  30. header('Cace-control: max-age=315569260');
  31. }
  32. $xml = new SimpleXMLElement('<data/>');
  33. while ($row = mysql_fetch_assoc($result)) {
  34. $event = $xml->addChild('event');
  35. $event->addAttribute('start', date('r', $row['s']));
  36. $event->addAttribute('latestStart', date('r', $row['s']));
  37. $event->addAttribute('title', ($row['type'] ? $row['type'].': ' : '').$row['title']);
  38. $end = $row['e'];
  39. if (!$row['e'])
  40. {
  41. $end = $row['s'];
  42. }
  43. $event->addAttribute('end', date('r', $end));
  44. $event->addAttribute('earliestEnd', date('r', $end));
  45. if ($row['link'])
  46. {
  47. $event->addAttribute('link', $row['link']);
  48. }
  49. }
  50. mysql_free_result($result);
  51. echo $xml->asXML();