/
news.php
67 lines (58 loc) · 1.67 KB
/
news.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
<?
$cat_mapping = array(
"Head of the Hudson" => 4,
"Learn to Row" => 5,
);
$base = "http://www.albanyrowingcenter.org/";
$base .= "wpblog/";
$url = $base . "?feed=rss2";
$cat = $_GET['cat'];
#php is such a joke...
if(array_key_exists($cat, $cat_mapping)){
$url .= "&cat=" . $cat_mapping[$cat];
}
function cat_link($c)
{
return sprintf('<a href="news.php?cat=%s">%s</a>', $c, $c);
}
function cat_links($cs)
{
$links = array();
foreach($cs as $c){
array_push($links, cat_link($c));
}
return join(", ", $links);
}
function get_feed($url)
{
$doc = new DOMDocument();
$doc->load($url);
$news_feed = array();
foreach ($doc->getElementsByTagName('item') as $node) {
$categories = array();
foreach($node->getElementsByTagName('category') as $c)
array_push($categories, $c->nodeValue);
$itemRSS = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'content' => $node->getElementsByTagName('encoded')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
'categories' => $categories
);
array_push($news_feed, $itemRSS);
}
return $news_feed;
}
$feed = get_feed($url);
$title = "News";
include("header.inc");
?>
<div id="main">
<h1> <?= $title ?> </h1>
<? foreach ($feed as $item){ ?>
<h2><?= $item['title'] ?></h2>
<small>Posted on <?= $item['date'] ?> in <?= cat_links($item['categories']) ?> </small>
<?= $item['content'] ?>
<? } ?>
</div>
<? include("footer.inc"); ?>