forked from Kliqqi-CMS/Kliqqi-CMS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstoryrss.php
141 lines (119 loc) · 4.89 KB
/
storyrss.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
//
// Story RSS feed
// Usage:
// storyrss.php?id=story_id&rows=10&time=3600
// or
// storyrss.php?title=Story_title&rows=100&time=86600
//
include_once('internal/Smarty.class.php');
$main_smarty = new Smarty;
include('config.php');
include(mnminclude.'html1.php');
include(mnminclude.'link.php');
include(mnminclude.'smartyvariables.php');
include_once(mnminclude.'user.php');
$requestID = isset($_GET['id']) && is_numeric($_GET['id']) ? $_GET['id'] : 0;
if(isset($_GET['title']) && sanitize($_GET['title'], 3) != ''){$requestTitle = sanitize(sanitize($_GET['title'], 3),4);}
if(isset($requestTitle)){$requestID = $db->get_var($sql = "SELECT link_id FROM " . table_links . " WHERE `link_title_url` = '".$db->escape($requestTitle)."';"); }
$rows = isset($_GET['rows']) && is_numeric($_GET['rows']) ? $_GET['rows'] : 40;
$time = isset($_GET['time']) && is_numeric($_GET['time']) ? $_GET['time'] : 0;
if(is_numeric($requestID)) {
$id = $requestID;
$link = new Link;
$link->id=$requestID;
if(!$link->read() || ($link->status=='spam' && !checklevel('admin') && !checklevel('moderator'))){
// check for redirects
include(mnminclude.'redirector.php');
$x = new redirector($_SERVER['REQUEST_URI']);
header("Location: $my_pligg_base/error_404.php");
// $main_smarty->assign('tpl_center', 'error_404_center');
// $main_smarty->display($the_template . '/pligg.tpl');
die();
}
do_rss_header($link);
// get all parent comments
$sql = "SELECT * FROM " . table_comments . "
LEFT JOIN " . table_users . " ON comment_user_id=user_id
WHERE comment_status='published' AND comment_link_id=$link->id";
if($time > 0) {
$from = time()-$time;
$sql .= " AND comment_date > FROM_UNIXTIME($from)";
}
$sql .= " ORDER BY comment_date DESC ";
if($rows > 0) {
$sql .= " LIMIT 0,$rows";
}
$comments = $db->get_results($sql);
if ($comments) {
require_once(mnminclude.'comment.php');
$comment = new Comment;
foreach($comments as $dbcomment) {
$comment->id=$dbcomment->comment_id;
$cached_comments[$dbcomment->comment_id] = $dbcomment;
$comment->read();
echo "<item>\n";
echo " <title><![CDATA[".$main_smarty->get_config_vars('PLIGG_MiscWords_Comment')." #".$comment->id."]]></title>\n";
echo " <link>".getmyFullurl("storyURL", $link->category_safe_names($link->category), urlencode($link->title_url), $link->id)."#c".$comment->id."</link>\n";
$vars = array('link' => $link);
check_actions('rss_add_data', $vars);
echo ' <source url="'.getmyFullurl("storyURL", $link->category_safe_names($link->category), $link->title_url, $link->id).'"><![CDATA['. $link->title .']]></source>';
echo "\n <description><![CDATA[" . $comment->content . "]]></description>\n";
if (!empty($comment->date))
echo " <pubDate>".date('D, d M Y H:i:s T', $comment->date-misc_timezone*3600)."</pubDate>\n";
else
echo " <pubDate>".date('D, d M Y H:i:s T', time()-misc_timezone*3600)."</pubDate>\n";
echo " <author>" . $dbcomment->user_login . "</author>\n";
echo " <votes>".$comment->votes."</votes>\n";
echo " <guid isPermaLink='false'>".$comment->id."</guid>\n";
// module system hook
$vars = array('item' => $comment);
check_actions('comment_rss_item', $vars);
echo "</item>\n\n";
}
}
do_rss_footer();
} else {
// check for redirects
include(mnminclude.'redirector.php');
$x = new redirector($_SERVER['REQUEST_URI']);
header("Location: $my_pligg_base/error_404.php");
// header("Location: error_404.php");
// $main_smarty->assign('tpl_center', 'error_404_center');
// $main_smarty->display($the_template . '/pligg.tpl');
die();
}
function do_rss_header($link) {
global $last_modified, $dblang, $main_smarty;
# header('Content-type: text/xml; charset=utf-8', true);
echo '<?xml version="1.0" encoding="utf-8"?'.'>' . "\n";
echo '<rss version="2.0" '."\n";
echo 'xmlns:content="http://purl.org/rss/1.0/modules/content/"'."\n";
echo 'xmlns:wfw="http://wellformedweb.org/CommentAPI/"'."\n";
echo 'xmlns:dc="http://purl.org/dc/elements/1.1/"'."\n";
echo '>'. "\n";
echo '<channel>'."\n";
echo '<title>'.htmlspecialchars($main_smarty->get_config_vars("PLIGG_Visual_Name"))." - ".$link->title.'</title>'."\n";
echo "<link>".getmyFullurl("storyURL", $link->category_safe_names($link->category), urlencode($link->title_url), $link->id)."</link>\n";
echo '<description>'.strip_tags($link->truncate_content()).'</description>'."\n";
if (!empty($link->date))
echo '<pubDate>'.date('D, d M Y H:i:s T', $link->date-misc_timezone*3600).'</pubDate>'."\n";
else
echo "<pubDate>".date('D, d M Y H:i:s T', time()-misc_timezone*3600)."</pubDate>\n";
echo '<language>'.$dblang.'</language>'."\n";
}
function do_rss_footer() {
echo "</channel>\n</rss>\n";
}
function onlyreadables($string) {
for ($i=0;$i<strlen($string);$i++) {
$chr = $string{$i};
$ord = ord($chr);
if ($ord<32 or $ord>126) {
$chr = "~";
$string{$i} = $chr;
}
}
return str_replace("~", "", $string);
}
?>