PageRenderTime 274ms CodeModel.GetById 151ms app.highlight 4ms RepoModel.GetById 117ms 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 
 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
21$query = sprintf("SELECT type, title, UNIX_TIMESTAMP(start) as s, UNIX_TIMESTAMP(end) as e, resource_url as link FROM event
22	WHERE INSTR('%s', url_prefix) = 1
23	ORDER BY start DESC",
24	mysql_real_escape_string($_GET['url'])
25);
26
27$result = mysql_query($query);
28
29if (!$result) {
30        error_log(mysql_error());
31}
32
33$data = array();
34
35header('Content-type: text/xml');
36if (array_key_exists('ver', $_GET)) {
37	header('Expires: '.date('r', time() + 315569260));
38	header('Cace-control: max-age=315569260');
39}
40$xml = new SimpleXMLElement('<data/>');
41
42while ($row = mysql_fetch_assoc($result)) {
43	$event = $xml->addChild('event');
44	$event->addAttribute('start', date('r', $row['s']));
45	$event->addAttribute('latestStart', date('r', $row['s']));
46	$event->addAttribute('title', ($row['type'] ? $row['type'].': ' : '').$row['title']);
47
48	$end = $row['e'];
49
50	if (!$row['e'])
51	{
52		$end = $row['s'];
53	}
54
55	$event->addAttribute('end', date('r', $end));
56	$event->addAttribute('earliestEnd', date('r', $end));
57
58	if ($row['link'])
59	{
60		$event->addAttribute('link', $row['link']);
61	}
62}
63mysql_free_result($result);
64
65echo $xml->asXML();