-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
98 lines (72 loc) · 2.19 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
ini_set('display_errors','on');
ini_set('memory_limit', '32M');
$NUM_PER_FEED = 25;
function make_key_from_date($ts) {
$ts -= ($ts % (60 * 60 * 6));
return gmdate('r', $ts);
}
include('simplepie.inc');
header('Content-type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8" ?>';
$feed_items = array();
$now = time();
$newest_time = $now - ($now % (60 * 60 * 6)); // start of the latest 6 hour block
$oldest_time = $newest_time - (60 * 60 * 24); // start of the latest 6 hour block 12 hours ago
$item_time = $newest_time;
$feed_index = 0;
while ($item_time > $oldest_time) {
$feed = new SimplePie("http://ffffound.com/feed?offset={$feed_index}", './cache');
$feed->handle_content_type();
foreach ($feed->get_items() as $item) {
$item_time = $item->get_date('U');
if ($item_time < $newest_time && $item_time > $oldest_time) {
$feed_items[make_key_from_date($item_time)][] = $item;
}
}
$feed_index += $NUM_PER_FEED;
}
$date = date('r');
$this_url = htmlentities('http://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF']);
echo <<<END_OF_HTML
<rss version="2.0">
<channel>
<title><![CDATA[FFFFound.com Daily Digest]]></title>
<link>{$this_url}</link>
<description><![CDATA[FFFFound.com Daily Digest]]></description>
<language>en-us</language>
<lastBuildDate>{$date}</lastBuildDate>
END_OF_HTML;
foreach ($feed_items as $key => $block) {
echo <<<END_OF_HTML
<item>
<title><![CDATA[FFFFound! Digest for {$key}]]></title>
<link>http://ffffound.com/</link>
<guid isPermaLink="false">fffound_digest:$key</guid>
<pubDate>$key</pubDate>
<description><![CDATA[
<table cellpadding=8 border=1>
END_OF_HTML;
$offset = 0;
foreach ($block as $item) {
if (($offset % 4) == 0) {
echo "<tr>";
}
$desc = $item->get_description();
$enc = $item->get_enclosure();
$thumb = $item->get_item_tags('http://search.yahoo.com/mrss/', 'thumbnail');
$thumb = $thumb[0]['attribs']['']['url'];
$link = $item->get_link();
echo <<<END_OF_HTML
<td>
<a href="$link"><img src="$thumb"/></a>
</td>
END_OF_HTML;
if (($offset % 4) == 3) {
echo "</tr>";
}
$offset++;
}
echo '</table>]]></description></item>';
}
echo '</channel></rss>';