-
Notifications
You must be signed in to change notification settings - Fork 0
/
rss.php
219 lines (191 loc) · 7.82 KB
/
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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?php
include_once('internal/Smarty.class.php');
$main_smarty = new Smarty;
include('config.php');
include(mnminclude.'link.php');
include(mnminclude.'html1.php');
include(mnminclude.'search.php');
include(mnminclude.'user.php');
include_once(mnminclude.'smartyvariables.php');
// pagename
define('pagename', 'rss');
$main_smarty->assign('pagename', pagename);
$rows = isset($_GET['rows']) && is_numeric($_GET['rows']) ? $_GET['rows'] : 20;
$status = sanitize($_GET['status'], 3) != '' ? sanitize($_GET['status'], 3) : 'published';
$time = isset($_GET['time']) && is_numeric($_GET['time']) ? $_GET['time'] : 0;
if($time > 0) {
// Prepare for times
$sql = "SELECT link_id, count(*) as votes FROM " . table_votes . ", " . table_links . " WHERE ";
if ($time > 0) {
$from = time()-$time;
$sql .= "vote_date > FROM_UNIXTIME($from) AND ";
}
$sql .= "vote_link_id=link_id AND (link_status='published' OR link_status='new') GROUP BY vote_link_id ORDER BY votes DESC LIMIT $rows";
$last_modified = time();
$title = $main_smarty->get_config_vars('PLIGG_Visual_RSS_Recent') . ' ' . txt_time_diff($from);
$link_date = "";
} else {
// All the others
$tmpsearch = new Search;
$tmpsearch->searchTerm = isset($_GET['search']) && sanitize($_GET['search'], 3) != '' ? sanitize($_GET['search'], 3) : '';
$search = $tmpsearch->get_search_clause();
if ($search) $status='all';
switch ($status) {
case 'published':
$order_field = 'link_date';
$link_date = 'date';
$title = " | " . $main_smarty->get_config_vars("PLIGG_Visual_Published_News");
break;
case 'new':
case 'new':
$title = " | " . $main_smarty->get_config_vars("PLIGG_Visual_Pligg_Queued");
$order_field = 'link_date';
$link_date = "date";
$status = 'new';
break;
case 'shared':
$order_field = 'link_date';
$link_date = 'date';
$title = " | " . $main_smarty->get_config_vars("PLIGG_Visual_Group_Shared");
break;
case 'all':
$title = "";
$order_field = 'link_date';
$link_date = "date";
break;
default:
header("Location: $my_pligg_base/error_404.php");
die();
break;
}
$from = "FROM " . table_links .
" LEFT JOIN " . table_groups . " ON group_id=link_group_id ";
# " LEFT JOIN " . table_categories . " ON category_id=link_category ".
# " LEFT JOIN " . table_users . " ON link_author=user_id ";
if($status == 'shared') {
$from .= " LEFT JOIN " . table_group_shared . " ON share_link_id=link_id ";
}
$where = " WHERE (ISNULL(group_privacy) OR group_privacy!='private') ";
if($status == 'all') {
$where .= " AND (link_status='published' OR link_status='new') ";
} elseif($status == 'shared') {
$where .= " AND !ISNULL(share_link_id) AND (link_status='published' OR link_status='new') ";
} else {
$where .= " AND link_status='$status' ";
}
if($_REQUEST['category']){
if(!($cat=check_integer('category'))) {
$thecat = get_cached_category_data('category_safe_name', sanitize($_REQUEST['category'], 1));
$cat = $thecat->category_id;
if (!$cat)
{
header("Location: $my_pligg_base/storyrss.php?title=".urlencode($_REQUEST['category']));
die();
}
}
$where .= " AND link_category IN (SELECT category_ID from ". table_categories ." where category_id=$cat OR category_parent=$cat )";
$category_name = $db->get_var("SELECT category_name FROM " . table_categories . " WHERE category_id = $cat AND category_lang='$dblang'");
$title .= " | " . htmlspecialchars($category_name);
}
if(isset($_REQUEST['group'])){
if(!($group=check_integer('group')))
$group = $db->get_var("SELECT group_id FROM " . table_groups . " WHERE group_safename = '".$db->escape(strip_tags($_REQUEST['group']))."';");
$group_name = $db->get_var("SELECT group_name FROM " . table_groups . " WHERE group_id = '$group'");
if ($group_name)
{
$title .= " | " . $group_name;
$where .= " AND link_group_id = '$group' ";
}
}
// This doesn't seem to work -kb
if($search) {
$where .= $search;
$title = htmlspecialchars(sanitize($_GET['search'], 3));
}
$order_by = " ORDER BY $order_field DESC ";
$last_modified = $db->get_var($sql="SELECT UNIX_TIMESTAMP(max($order_field)) $from $where");
$sql = "SELECT * $from $where $order_by LIMIT $rows";
}
do_rss_header($title);
// module system hook
$vars = '';
check_actions('rss_start_data', $vars);
$link = new Link;
$links = $db->get_results($sql);
if ($links) {
foreach($links as $dblink) {
$link->id=$dblink->link_id;
$cached_links[$dblink->link_id] = $dblink;
$link->read();
$user = new User($link->author);
#print_r($link);
$category_name = $db->get_var($sql="SELECT category_name FROM " . table_categories . " WHERE category_id = {$link->category}");
#print $sql;
$link->link_summary = str_replace("\n", "<br />", $link->link_summary);
$link->link_summary = str_replace("’", "'", $link->link_summary);
$link->link_summary = str_replace("–", "-", $link->link_summary);
$link->link_summary = str_replace("—", "-", $link->link_summary);
$link->link_summary = str_replace("“", "\"", $link->link_summary);
$link->link_summary = str_replace("â€", "\"", $link->link_summary);
echo "<item>\n";
echo " <title>". htmlspecialchars($link->title) . "</title>\n";
echo " <link>".getmyFullurl("storyURL", $link->category_safe_names($link->category), urlencode($link->title_url), $link->id)."</link>\n";
$vars = array('link' => $link);
check_actions('rss_add_data', $vars);
$story_url = $link->url;
if ($story_url != '' && $story_url != 'http://'){
echo " <source>".htmlspecialchars($story_url)."</source>\n";
}
$description = htmlspecialchars($link->content);
$description = preg_replace('/\r/', ' ', $description);
$description = preg_replace('/\n/', ' <br />', $description);
echo " <description><![CDATA[ " . $description . " ]]></description>\n";
if (!empty($link_date))
echo " <pubDate>".date('D, d M Y H:i:s T', $link->$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 " <dc:creator>" . htmlspecialchars($user->username) . "</dc:creator>\n";
echo " <category>" . htmlspecialchars($category_name) . "</category>\n";
// Calculate total vote count based on votes-downvotes
$vote_total = $link->votes - $link->reports;
echo " <votes>" . $vote_total . "</votes>\n";
echo " <upvotes>" . $link->votes . "</upvotes>\n";
echo " <downvotes>" . $link->reports . "</downvotes>\n";
echo " <guid>".getmyFullurl("storyURL", $link->category_safe_names($link->category), urlencode($link->title_url), $link->id)."</guid>\n";
// module system hook
$vars = array('item' => $link);
check_actions('rss_item', $vars);
echo "</item>\n\n";
}
}
// module system hook
$vars = '';
check_actions('rss_end_data', $vars);
do_rss_footer();
function do_rss_header($title) {
global $last_modified, $dblang, $main_smarty;
header('Content-type: text/xml; charset=utf-8', true);
echo '<?xml version="1.0"?>' . "\n";
echo '<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">'. "\n";
echo '<channel>'."\n";
echo '<title>'.htmlspecialchars($main_smarty->get_config_vars("PLIGG_Visual_Name")).' '.trim($title).'</title>'."\n";
echo '<link>'.my_base_url.my_pligg_base.'</link>'."\n";
echo '<description>'.$main_smarty->get_config_vars("PLIGG_Visual_RSS_Description").'</description>'."\n";
echo '<pubDate>'.date('D, d M Y H:i:s T', $last_modified-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);
}
?>