forked from Kliqqi-CMS/Kliqqi-CMS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
userrss.php
255 lines (228 loc) · 9.68 KB
/
userrss.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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<?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');
//status = 'published', 'new' or 'all' // link/story status
//rows = x // number of links/stories to show
//user = x // the users name
//time = x // how far back in time (seconds) to go
if(isset($_GET['user']) && sanitize($_GET['user'], 3) != ''){
$login = sanitize($_GET['user'], 3);
} else {
header("Location: $my_pligg_base/error_404.php");
die;
}
$user=new User();
$user->username = $login;
if(!$user->read()) {
//echo "error: user does not exist";
header("Location: $my_pligg_base/error_404.php");
// header('Location: error_404.php');
die;
}
$rows = isset($_GET['rows']) && is_numeric($_GET['rows']) ? $_GET['rows'] : 40;
$time = isset($_GET['time']) && is_numeric($_GET['time']) ? $_GET['time'] : 0;
if($time > 0) {
// Prepare for times
$sql = "SELECT *, count(*) as votes FROM " . table_votes . ", " . table_links . "
LEFT JOIN " . table_users . " ON link_author=user_id
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;
$search = $tmpsearch->get_search_clause();
// The link_status to search
$status = isset($_GET['status']) && sanitize($_GET['status'], 3) != '' ? sanitize($_GET['status'], 3) : 'submitted';
switch ($status) {
case 'published':
$title = $main_smarty->get_config_vars("PLIGG_Visual_Published_News");
$order_field = 'link_published_date';
$link_date = 'published_date';
$from_where = "FROM " . table_links . "
LEFT JOIN " . table_users . " ON link_author=user_id
WHERE link_status='published' ";
$from_where .= " AND link_author=$user->id ";
break;
case 'new':
$title = $main_smarty->get_config_vars("PLIGG_Visual_Pligg_Queued");
$order_field = 'link_date';
$link_date = "date";
$from_where = "FROM " . table_links . "
LEFT JOIN " . table_users . " ON link_author=user_id
WHERE link_status='new' ";
$from_where .= " AND link_author=$user->id ";
break;
case 'submitted':
$title = $main_smarty->get_config_vars("PLIGG_Visual_RSS_All");
$order_field = 'link_date';
$link_date = "date";
$from_where = "FROM " . table_links . "
LEFT JOIN " . table_users . " ON link_author=user_id
WHERE (link_status='published' OR link_status='new') ";
$from_where .= " AND link_author=$user->id ";
break;
case 'voted':
$title = $main_smarty->get_config_vars("PLIGG_Visual_RSS_Voted");
$order_field = 'link_date';
$link_date = "date";
$from_where = "FROM " . table_links . "
LEFT JOIN " . table_votes . " ON vote_link_id=link_id
LEFT JOIN " . table_users . " ON link_author=user_id
WHERE vote_user_id=$user->id AND (link_status='published' OR link_status='new') ";
break;
case 'upvoted':
$title = $main_smarty->get_config_vars("PLIGG_Visual_UpVoted");
$order_field = 'link_date';
$link_date = "date";
$from_where = "FROM " . table_links . "
LEFT JOIN " . table_votes . " ON vote_link_id=link_id
LEFT JOIN " . table_users . " ON link_author=user_id
WHERE vote_user_id=$user->id AND (link_status='published' OR link_status='new') AND vote_value>0";
break;
case 'downvoted':
$title = $main_smarty->get_config_vars("PLIGG_Visual_DownVoted");
$order_field = 'link_date';
$link_date = "date";
$from_where = "FROM " . table_links . "
LEFT JOIN " . table_votes . " ON vote_link_id=link_id
LEFT JOIN " . table_users . " ON link_author=user_id
WHERE vote_user_id=$user->id AND (link_status='published' OR link_status='new') AND vote_value<0";
break;
case 'commented':
$title = $main_smarty->get_config_vars("PLIGG_Visual_RSS_Commented");
$user->username = $login;
$order_field = 'link_date';
$link_date = "date";
$from_where = "FROM " . table_links . "
LEFT JOIN " . table_comments . " ON comment_link_id=link_id
LEFT JOIN " . table_users . " ON link_author=user_id
WHERE comment_status='published' AND comment_user_id=$user->id AND (link_status='published' OR link_status='new') ";
break;
case 'saved':
$title = $main_smarty->get_config_vars("PLIGG_Visual_RSS_Saved");
$user->username = $login;
$order_field = 'saved_id';
$link_date = "date";
$from_where = "FROM " . table_links . "
LEFT JOIN " . table_saved_links . " ON saved_link_id=link_id
LEFT JOIN " . table_users . " ON link_author=user_id
WHERE saved_user_id=$user->id AND (link_status='published' OR link_status='new') ";
break;
default:
header("Location: $my_pligg_base/error_404.php");
die();
break;
}
$cat = isset($_GET['category']) && is_numeric($_GET['category']) ? $_GET['category'] : 0;
if($cat > 0) {
$child_cats = '';
// do we also search the subcategories?
if( Independent_Subcategories == true){
$child_array = '';
// get a list of all children and put them in $child_array.
children_id_to_array($child_array, table_categories, $cat);
if ($child_array != '') {
// build the sql
foreach($child_array as $child_cat_id) {
$child_cat_sql .= ' OR `link_category` = ' . $child_cat_id . ' ';
if (Multiple_Categories)
$child_cat_sql .= ' OR ac_cat_id = ' . $child_cat_id . ' ';
}
}
}
if (Multiple_Categories)
{
$from_where = str_replace("WHERE", " LEFT JOIN ".table_additional_categories. " ON ac_link_id=link_id WHERE", $from_where);
$child_cat_sql .= " OR ac_cat_id = $cat ";
}
$from_where .= " AND (link_category=$cat " . $child_cat_sql . ")";
$category_name = $db->get_var("SELECT category_name FROM " . table_categories . " WHERE category_id = $cat AND category_lang='$dblang'");
$title .= " | ".$category_name;
}
//This doesn't seem to work -kb
if($search) {
$from_where .= $search;
$title = htmlspecialchars(sanitize($_GET['search'], 3));
}
$order_by = " ORDER BY $order_field DESC ";
$last_modified = $db->get_var("SELECT UNIX_TIMESTAMP(max($order_field)) links $from_where");
$sql = "SELECT DISTINCT * $from_where GROUP BY link_id $order_by LIMIT $rows";
}
do_rss_header($title);
$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();
$category_name = $db->get_var("SELECT category_name FROM " . table_categories . " WHERE category_id = $link->category AND category_lang='$dblang'");
$link->content = str_replace("\n", "<br />", $link->content);
$link->content = str_replace("’", "'", $link->content);
$link->content = str_replace("–", "-", $link->content);
$link->content = str_replace("—", "-", $link->content);
$link->content = str_replace("“", "\"", $link->content);
$link->content = str_replace("”", "\"", $link->content);
echo "<item>\n";
echo " <title><![CDATA[". $link->title ."]]></title>\n";
echo " <link>".getmyFullurl("storyURL", $link->category_safe_names($link->category), $link->title_url, $link->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[" . $link->content . " ]]></description>\n";
if (!empty($link_date))
echo " <pubDate>".date("r", $link->$link_date-misc_timezone*3600)."</pubDate>\n";
else
echo " <pubDate>".date("r", time()-misc_timezone*3600)."</pubDate>\n";
echo " <author>" . $dblink->user_login . "</author>\n";
echo " <category>" . htmlspecialchars($category_name) . "</category>\n";
echo " <votes>".$link->votes."</votes>\n";
echo " <guid>".getmyFullurl("storyURL", $link->category_safe_names($link->category), $link->title_url, $link->id)."</guid>\n";
echo "</item>\n\n";
}
}
do_rss_footer();
function do_rss_header($title) {
global $last_modified, $dblang, $login, $main_smarty;
header('Content-type: text/xml; charset=utf-8', true);
echo '<?phpxml 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")).' / '.$login.' / '.$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("r", $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);
}
?>