-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
45 lines (42 loc) · 1.42 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
require('tweetcache.php');
try {
$config = parse_ini_file("tweetcache.ini", true);
$username = '';
$format = 'xml';
$bad = array();
if (isset($_GET['username'])) {
$username = $_GET['username'];
if (!preg_match('/^\w+$/', $username))
$bad[] = "Twitter username not accepted.";
} else
$bad[] = 'No twitter username given.';
if (isset($_GET['format']))
$format = $_GET['format'];
if (!in_array($format, array('atom', 'xml', 'rss')))
$bad[] = "Format not accepted.";
if (count($bad)) {
header("Status: 400 Bad Request");
echo "<ul>\n\t<li>" . join("</li>\n\t<li>", $bad) . "</li>\n</ul>\n";
} else {
if (isset($config['cache']['timezone']))
date_default_timezone_set($config['cache']['timezone']);
$tweets = new TweetCache($config, $username, $format);
$tweets->load();
$now = time();
$max_age = $config['cache']['max_age'];
header('Content-type: ' . $tweets->mimetype() . '; charset=utf-8');
header('Last-Modified: ' . gmstrftime("%A %d-%b-%y %T %Z", $tweets->modified()));
header('Expires: ' . gmstrftime("%A %d-%b-%y %T %Z", $now + $max_age));
header('Cache-control: public,max-age=' . $max_age);
if ($format != 'json') {
echo '<' . '?xml version="1.0" encoding="utf-8" ?' . ">\n";
echo "<!--\n\t" . $tweets->getLog("\n\t") . "\n-->\n";
}
echo $tweets->toString() . "\n";
}
} catch(Exception $ex) {
header('Status: 500 Internal Server Error');
echo $ex->getMessage() . "\n";
}
?>