-
Notifications
You must be signed in to change notification settings - Fork 10
/
comments-rss.php
79 lines (70 loc) · 2.68 KB
/
comments-rss.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
<?php
require('utils.php');
// ----------------------------------------------------------------------------
function feed($title, $link, $description) {
connect();
$feed = '<?xml version="1.0"?>';
$feed .= '<rss version="2.0">';
$feed .= '<channel>';
$feed .= "<title>$title</title>";
$feed .= "<link>$link</link>";
$feed .= "<image>";
$feed .= "<url>http://terminal.jcubic.pl/css/images/logo.png</url>";
$feed .= "<title>$title</title>";
$feed .= "<link>http://terminal.jcubic.pl/#comments</link>";
$feed .= "</image>";
$feed .= "<copyright>Jakub Jankiewicz</copyright>";
$feed .= "<generator>php script</generator>";
$feed .= "<webMaster>jcubic@onet.pl</webMaster>";
$query = "SELECT strftime('%s', date), nick, email, www, comment FROM jq_comments order by date DESC LIMIT 10";
$comments = sqlite_query("comments.db", $query);
$feed .= "<pubDate>" . date("D, d M Y H:i:s T", $comments[0]["strftime('%s', date)"]) . "</pubDate>";
$feed .= "<description>$description</description>";
foreach ($comments as $item) {
if (!preg_match('/http:\/\//', $item['www'])) {
if (preg_match('/.*\..*/', $item['www'])) {
$url = "http://" . $item['www'];
} else {
$url = null;
}
} else {
$url = $item['www'];
}
$date = date("D, d M Y H:i:s T", $item["strftime('%s', date)"]);
$comment = htmlspecialchars($item['comment']);
$nick = strcmp($item['nick'], '') == 0 ? 'Anonymous' : $item['nick'];
$feed .= item($nick, $nick, $url, $comment, $date);
}
$feed .= "</channel>";
$feed .= "</rss>";
return $feed;
}
// ----------------------------------------------------------------------------
function item($title, $email, $link, $description, $date) {
$item = "<item>";
$item .= "<author>" . clean($email) . "</author>";
$item .= "<title><![CDATA[" . clean($title) . "]]></title>";
if ($link) {
$item .= "<link>$link</link>";
}
$item .= "<description><![CDATA[\n" . clean($description) . "\n]]></description>";
$item .= "<pubDate>$date</pubDate>";
$item .= "</item>";
return $item;
}
function clean($string) {
return iconv("UTF-8", "UTF-8//IGNORE", $string);
}
try {
$description = "Comments left by users.";
$url = "http://terminal.jcubic.pl/comments-rss.php";
$feed = feed("JQuery Terminal Comments", $url, $description);
header('Content-Type: application/xml; charset=utf-8');
//echo pretty_xml($feed);
echo $feed;
} catch (Exception $e) {
header("HTTP/1.1 500 Internal Server Error");
echo "Server Error: " . $e->getMessage();
exit(1);
}
?>