]>
Commit | Line | Data |
---|---|---|
1d3a17c7 | 1 | <?php |
ce885e21 AD |
2 | /* remove ill effects of magic quotes */ |
3 | ||
5fa17372 | 4 | if (get_magic_quotes_gpc()) { |
c0793f64 | 5 | function stripslashes_deep($value) { |
009646d2 | 6 | $value = is_array($value) ? |
c0793f64 AD |
7 | array_map('stripslashes_deep', $value) : stripslashes($value); |
8 | return $value; | |
9 | } | |
10 | ||
11 | $_POST = array_map('stripslashes_deep', $_POST); | |
12 | $_GET = array_map('stripslashes_deep', $_GET); | |
13 | $_COOKIE = array_map('stripslashes_deep', $_COOKIE); | |
14 | $_REQUEST = array_map('stripslashes_deep', $_REQUEST); | |
ce885e21 AD |
15 | } |
16 | ||
f9da2388 AD |
17 | $op = $_REQUEST["op"]; |
18 | ||
fb074239 | 19 | require_once "functions.php"; |
f9da2388 | 20 | if ($op != "share") require_once "sessions.php"; |
c339343b | 21 | require_once "modules/backend-rpc.php"; |
657770a0 AD |
22 | require_once "sanity_check.php"; |
23 | require_once "config.php"; | |
af106b0e AD |
24 | require_once "db.php"; |
25 | require_once "db-prefs.php"; | |
657770a0 | 26 | |
dc56b3b7 | 27 | no_cache_incantation(); |
8d039718 | 28 | |
7b26a148 | 29 | startup_gettext(); |
dc56b3b7 | 30 | |
7f0acba7 AD |
31 | $script_started = getmicrotime(); |
32 | ||
009646d2 | 33 | $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); |
7f0acba7 AD |
34 | |
35 | if (!$link) { | |
36 | if (DB_TYPE == "mysql") { | |
37 | print mysql_error(); | |
38 | } | |
009646d2 | 39 | // PG seems to display its own errors just fine by default. |
7f0acba7 AD |
40 | return; |
41 | } | |
42 | ||
f29ba148 | 43 | init_connection($link); |
7f0acba7 | 44 | |
d9084cf2 | 45 | $subop = $_REQUEST["subop"]; |
fac5e7d1 | 46 | $mode = $_REQUEST["mode"]; |
7f0acba7 | 47 | |
565ca565 AD |
48 | if ((!$op || $op == "rss" || $op == "dlg") && !$_REQUEST["noxml"]) { |
49 | header("Content-Type: application/xml; charset=utf-8"); | |
50 | } else { | |
9fdf7824 | 51 | header("Content-Type: text/plain; charset=utf-8"); |
262bd8ea AD |
52 | } |
53 | ||
bd202c3f AD |
54 | if (ENABLE_GZIP_OUTPUT) { |
55 | ob_start("ob_gzhandler"); | |
56 | } | |
57 | ||
9c883208 AD |
58 | if (SINGLE_USER_MODE) { |
59 | authenticate_user($link, "admin", null); | |
60 | } | |
61 | ||
009646d2 | 62 | if (!($_SESSION["uid"] && validate_session($link)) && $op != "globalUpdateFeeds" && |
83cd33fc | 63 | $op != "rss" && $op != "getUnread" && $op != "getProfiles" && $op != "share" && |
ae5f7bb1 | 64 | $op != "fbexport" && $op != "logout" && $op != "pubsub") { |
009646d2 | 65 | |
d0f73380 AD |
66 | if ($op == 'pref-feeds' && $_REQUEST['subop'] == 'add') { |
67 | header("Content-Type: text/html"); | |
68 | login_sequence($link); | |
69 | render_login_form($link); | |
70 | } else { | |
71 | header("Content-Type: text/plain"); | |
72 | print json_encode(array("error" => array("code" => 6))); | |
73 | } | |
009646d2 | 74 | return; |
262bd8ea | 75 | } |
1c7f75ed | 76 | |
ad815c71 | 77 | $purge_intervals = array( |
d1db26aa AD |
78 | 0 => __("Use default"), |
79 | -1 => __("Never purge"), | |
80 | 5 => __("1 week old"), | |
81 | 14 => __("2 weeks old"), | |
82 | 31 => __("1 month old"), | |
83 | 60 => __("2 months old"), | |
84 | 90 => __("3 months old")); | |
ad815c71 AD |
85 | |
86 | $update_intervals = array( | |
ecace165 | 87 | 0 => __("Default interval"), |
d1db26aa | 88 | -1 => __("Disable updates"), |
1e7cbe16 | 89 | 15 => __("Each 15 minutes"), |
d1db26aa | 90 | 30 => __("Each 30 minutes"), |
505f2f0e AD |
91 | 60 => __("Hourly"), |
92 | 240 => __("Each 4 hours"), | |
93 | 720 => __("Each 12 hours"), | |
94 | 1440 => __("Daily"), | |
95 | 10080 => __("Weekly")); | |
96 | ||
97 | $update_intervals_nodefault = array( | |
98 | -1 => __("Disable updates"), | |
99 | 15 => __("Each 15 minutes"), | |
100 | 30 => __("Each 30 minutes"), | |
d1db26aa AD |
101 | 60 => __("Hourly"), |
102 | 240 => __("Each 4 hours"), | |
103 | 720 => __("Each 12 hours"), | |
104 | 1440 => __("Daily"), | |
105 | 10080 => __("Weekly")); | |
ad815c71 | 106 | |
16211ddb | 107 | $update_methods = array( |
ecace165 | 108 | 0 => __("Default"), |
0dd9c0cf | 109 | 1 => __("Magpie"), |
009646d2 | 110 | 2 => __("SimplePie"), |
b3009bcd | 111 | 3 => __("Twitter OAuth")); |
16211ddb | 112 | |
78a5c296 | 113 | if (DEFAULT_UPDATE_METHOD == "1") { |
16211ddb AD |
114 | $update_methods[0] .= ' (SimplePie)'; |
115 | } else { | |
116 | $update_methods[0] .= ' (Magpie)'; | |
117 | } | |
118 | ||
3c5783b7 | 119 | $access_level_names = array( |
009646d2 | 120 | 0 => __("User"), |
a88d37e5 | 121 | 5 => __("Power User"), |
d1db26aa | 122 | 10 => __("Administrator")); |
3c5783b7 | 123 | |
f27d955a | 124 | require_once "modules/pref-prefs.php"; |
ef8be8ea AD |
125 | require_once "modules/popup-dialog.php"; |
126 | require_once "modules/help.php"; | |
127 | require_once "modules/pref-feeds.php"; | |
128 | require_once "modules/pref-filters.php"; | |
129 | require_once "modules/pref-labels.php"; | |
130 | require_once "modules/pref-users.php"; | |
373266eb | 131 | require_once "modules/pref-instances.php"; |
ef8be8ea | 132 | |
ebb948c2 AD |
133 | $error = sanity_check($link); |
134 | ||
2376ad49 | 135 | if ($error['code'] != 0 && $op != "logout") { |
ebb948c2 AD |
136 | print json_encode(array("error" => $error)); |
137 | return; | |
138 | } | |
023fe037 | 139 | |
45004d43 AD |
140 | switch($op) { // Select action according to $op value. |
141 | case "rpc": | |
142 | // Handle remote procedure calls. | |
143 | handle_rpc_request($link); | |
144 | break; // rpc | |
145 | ||
146 | case "feeds": | |
b4e75b2a | 147 | $subop = $_REQUEST["subop"]; |
1985a5e0 | 148 | $root = (bool)$_REQUEST["root"]; |
45004d43 AD |
149 | |
150 | switch($subop) { | |
151 | case "catchupAll": | |
009646d2 | 152 | db_query($link, "UPDATE ttrss_user_entries SET |
45004d43 | 153 | last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]); |
ad0056a8 AD |
154 | ccache_zero_all($link, $_SESSION["uid"]); |
155 | ||
45004d43 AD |
156 | break; |
157 | ||
158 | case "collapse": | |
b4e75b2a | 159 | $cat_id = db_escape_string($_REQUEST["cid"]); |
fcf70c51 AD |
160 | $mode = (int) db_escape_string($_REQUEST['mode']); |
161 | toggle_collapse_cat($link, $cat_id, $mode); | |
45004d43 AD |
162 | return; |
163 | break; | |
164 | } | |
c3b81db0 | 165 | |
1985a5e0 AD |
166 | if (!$root) { |
167 | print json_encode(outputFeedList($link)); | |
168 | } else { | |
169 | ||
170 | $feeds = outputFeedList($link, false); | |
171 | ||
172 | $root = array(); | |
173 | $root['id'] = 'root'; | |
174 | $root['name'] = __('Feeds'); | |
175 | $root['items'] = $feeds['items']; | |
176 | ||
177 | $fl = array(); | |
178 | $fl['identifier'] = 'id'; | |
179 | $fl['label'] = 'name'; | |
180 | $fl['items'] = array($root); | |
181 | ||
182 | print json_encode($fl); | |
183 | } | |
13e785e0 | 184 | |
45004d43 | 185 | break; // feeds |
1cd17194 | 186 | |
b509d64e AD |
187 | case "la": |
188 | $id = db_escape_string($_REQUEST['id']); | |
189 | ||
190 | $result = db_query($link, "SELECT link FROM ttrss_entries, ttrss_user_entries | |
bfedfe69 AD |
191 | WHERE id = '$id' AND id = ref_id AND owner_uid = '".$_SESSION['uid']."' |
192 | LIMIT 1"); | |
b509d64e AD |
193 | |
194 | if (db_num_rows($result) == 1) { | |
195 | $article_url = db_fetch_result($result, 0, 'link'); | |
d4dcf8e9 | 196 | $article_url = str_replace("\n", "", $article_url); |
b509d64e AD |
197 | |
198 | header("Location: $article_url"); | |
199 | return; | |
200 | ||
201 | } else { | |
202 | print_error(__("Article not found.")); | |
203 | } | |
204 | break; | |
205 | ||
45004d43 | 206 | case "view": |
e097e8be | 207 | |
b4e75b2a | 208 | $id = db_escape_string($_REQUEST["id"]); |
9949bd15 | 209 | $cids = explode(",", db_escape_string($_REQUEST["cids"])); |
b4e75b2a AD |
210 | $mode = db_escape_string($_REQUEST["mode"]); |
211 | $omode = db_escape_string($_REQUEST["omode"]); | |
e097e8be | 212 | |
009646d2 | 213 | // in prefetch mode we only output requested cids, main article |
45004d43 | 214 | // just gets marked as read (it already exists in client cache) |
e097e8be | 215 | |
009646d2 AD |
216 | $articles = array(); |
217 | ||
45004d43 | 218 | if ($mode == "") { |
009646d2 | 219 | array_push($articles, format_article($link, $id, false)); |
eedfb635 | 220 | } else if ($mode == "zoom") { |
9949bd15 | 221 | array_push($articles, format_article($link, $id, true, true)); |
f4f0f80d | 222 | } else if ($mode == "raw") { |
fcfa9ef1 AD |
223 | if ($_REQUEST['html']) { |
224 | header("Content-Type: text/html"); | |
225 | print '<link rel="stylesheet" type="text/css" href="tt-rss.css"/>'; | |
226 | } | |
f4f0f80d AD |
227 | |
228 | $article = format_article($link, $id, false); | |
f4f0f80d AD |
229 | print $article['content']; |
230 | return; | |
45004d43 | 231 | } |
e097e8be | 232 | |
f7cffd2c AD |
233 | catchupArticleById($link, $id, 0); |
234 | ||
a598370d AD |
235 | if (!$_SESSION["bw_limit"]) { |
236 | foreach ($cids as $cid) { | |
237 | if ($cid) { | |
009646d2 | 238 | array_push($articles, format_article($link, $cid, false, false)); |
a598370d | 239 | } |
45004d43 | 240 | } |
e097e8be | 241 | } |
e097e8be | 242 | |
009646d2 | 243 | print json_encode($articles); |
5a94a953 | 244 | |
45004d43 | 245 | break; // view |
1cd17194 | 246 | |
45004d43 | 247 | case "viewfeed": |
1cd17194 | 248 | |
45004d43 | 249 | $timing_info = getmicrotime(); |
46921916 | 250 | |
bd202c3f | 251 | $reply = array(); |
3de0261a | 252 | |
b4e75b2a | 253 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info); |
46921916 | 254 | |
b4e75b2a | 255 | $omode = db_escape_string($_REQUEST["omode"]); |
3de0261a | 256 | |
b4e75b2a AD |
257 | $feed = db_escape_string($_REQUEST["feed"]); |
258 | $subop = db_escape_string($_REQUEST["subop"]); | |
259 | $view_mode = db_escape_string($_REQUEST["view_mode"]); | |
6f068202 | 260 | $limit = (int) get_pref($link, "DEFAULT_ARTICLE_LIMIT"); |
37c03d3a | 261 | @$cat_view = db_escape_string($_REQUEST["cat"]) == "true"; |
c3fddd05 AD |
262 | @$next_unread_feed = db_escape_string($_REQUEST["nuf"]); |
263 | @$offset = db_escape_string($_REQUEST["skip"]); | |
264 | @$vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]); | |
b4e75b2a | 265 | $order_by = db_escape_string($_REQUEST["order_by"]); |
203de776 | 266 | |
147f5632 CM |
267 | if (is_numeric($feed)) $feed = (int) $feed; |
268 | ||
fe1087fb AD |
269 | /* Feed -5 is a special case: it is used to display auxiliary information |
270 | * when there's nothing to load - e.g. no stuff in fresh feed */ | |
271 | ||
272 | if ($feed == -5) { | |
bd202c3f AD |
273 | print json_encode(generate_dashboard_feed($link)); |
274 | return; | |
275 | } | |
276 | ||
277 | $result = false; | |
278 | ||
279 | if ($feed < -10) { | |
81f6deea | 280 | $label_feed = -11-$feed; |
bd202c3f AD |
281 | $result = db_query($link, "SELECT id FROM ttrss_labels2 WHERE |
282 | id = '$label_feed' AND owner_uid = " . $_SESSION['uid']); | |
147f5632 | 283 | } else if (!$cat_view && is_numeric($feed) && $feed > 0) { |
bd202c3f AD |
284 | $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE |
285 | id = '$feed' AND owner_uid = " . $_SESSION['uid']); | |
147f5632 | 286 | } else if ($cat_view && is_numeric($feed) && $feed > 0) { |
bd202c3f AD |
287 | $result = db_query($link, "SELECT id FROM ttrss_feed_categories WHERE |
288 | id = '$feed' AND owner_uid = " . $_SESSION['uid']); | |
289 | } | |
290 | ||
291 | if ($result && db_num_rows($result) == 0) { | |
292 | print json_encode(generate_error_feed($link, __("Feed not found."))); | |
fe1087fb AD |
293 | return; |
294 | } | |
295 | ||
51e196de AD |
296 | /* Updating a label ccache means recalculating all of the caches |
297 | * so for performance reasons we don't do that here */ | |
298 | ||
5225d420 AD |
299 | if ($feed >= 0) { |
300 | ccache_update($link, $feed, $_SESSION["uid"], $cat_view); | |
301 | } | |
0737b95a | 302 | |
45004d43 AD |
303 | set_pref($link, "_DEFAULT_VIEW_MODE", $view_mode); |
304 | set_pref($link, "_DEFAULT_VIEW_LIMIT", $limit); | |
7b4d02a8 | 305 | set_pref($link, "_DEFAULT_VIEW_ORDER_BY", $order_by); |
40496720 | 306 | |
45004d43 AD |
307 | if (!$cat_view && preg_match("/^[0-9][0-9]*$/", $feed)) { |
308 | db_query($link, "UPDATE ttrss_feeds SET last_viewed = NOW() | |
309 | WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]); | |
310 | } | |
7466dc6a | 311 | |
bd202c3f AD |
312 | $reply['headlines'] = array(); |
313 | ||
314 | if (!$next_unread_feed) | |
315 | $reply['headlines']['id'] = $feed; | |
316 | else | |
317 | $reply['headlines']['id'] = $next_unread_feed; | |
318 | ||
319 | $reply['headlines']['is_cat'] = (bool) $cat_view; | |
009646d2 | 320 | |
a5c815d3 AD |
321 | $override_order = false; |
322 | ||
b3990c92 AD |
323 | if (get_pref($link, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) { |
324 | $date_sort_field = "updated"; | |
325 | } else { | |
326 | $date_sort_field = "date_entered"; | |
327 | } | |
328 | ||
a5c815d3 AD |
329 | switch ($order_by) { |
330 | case "date": | |
331 | if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) { | |
b3990c92 | 332 | $override_order = "$date_sort_field"; |
009646d2 | 333 | } else { |
b3990c92 | 334 | $override_order = "$date_sort_field DESC"; |
a5c815d3 AD |
335 | } |
336 | break; | |
c50e2b30 | 337 | |
a5c815d3 | 338 | case "title": |
7b20c977 | 339 | if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) { |
b3990c92 | 340 | $override_order = "title DESC, $date_sort_field"; |
7b20c977 | 341 | } else { |
b3990c92 | 342 | $override_order = "title, $date_sort_field DESC"; |
7b20c977 | 343 | } |
a5c815d3 | 344 | break; |
d76a3b03 | 345 | |
a5c815d3 | 346 | case "score": |
7b20c977 | 347 | if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) { |
b3990c92 | 348 | $override_order = "score, $date_sort_field"; |
7b20c977 | 349 | } else { |
b3990c92 | 350 | $override_order = "score DESC, $date_sort_field DESC"; |
7b20c977 | 351 | } |
a5c815d3 AD |
352 | break; |
353 | } | |
e19c1824 | 354 | |
905ff52a AD |
355 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info); |
356 | ||
bd202c3f | 357 | $ret = format_headlines_list($link, $feed, $subop, |
009646d2 | 358 | $view_mode, $limit, $cat_view, $next_unread_feed, $offset, |
a5c815d3 | 359 | $vgroup_last_feed, $override_order); |
7b4d02a8 | 360 | |
a5c815d3 AD |
361 | $topmost_article_ids = $ret[0]; |
362 | $headlines_count = $ret[1]; | |
363 | $returned_feed = $ret[2]; | |
364 | $disable_cache = $ret[3]; | |
365 | $vgroup_last_feed = $ret[4]; | |
7b4d02a8 | 366 | |
7d96bfcd AD |
367 | // if ($_REQUEST["debug"]) print_r($ret); |
368 | ||
369 | $reply['headlines']['content'] =& $ret[5]['content']; | |
370 | $reply['headlines']['toolbar'] =& $ret[5]['toolbar']; | |
46921916 | 371 | |
905ff52a AD |
372 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info); |
373 | ||
bd202c3f | 374 | $reply['headlines-info'] = array("count" => (int) $headlines_count, |
ffbe082d | 375 | "vgroup_last_feed" => $vgroup_last_feed, |
ffbe082d AD |
376 | "disable_cache" => (bool) $disable_cache); |
377 | ||
bd202c3f | 378 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info); |
009646d2 | 379 | |
bd202c3f | 380 | if (is_array($topmost_article_ids) && !get_pref($link, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) { |
009646d2 AD |
381 | $articles = array(); |
382 | ||
a5c815d3 | 383 | foreach ($topmost_article_ids as $id) { |
9949bd15 | 384 | array_push($articles, format_article($link, $id, false)); |
45004d43 | 385 | } |
009646d2 | 386 | |
bd202c3f AD |
387 | $reply['articles'] = $articles; |
388 | } | |
46921916 | 389 | |
81787bbf AD |
390 | // if ($subop) { |
391 | // $reply['counters'] = getAllCounters($link, $omode, $feed); | |
392 | // } | |
98bea1b1 | 393 | |
b4e75b2a | 394 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info); |
46921916 | 395 | |
bd202c3f AD |
396 | $reply['runtime-info'] = make_runtime_info($link); |
397 | ||
398 | print json_encode($reply); | |
03c88bdd | 399 | |
45004d43 | 400 | break; // viewfeed |
1cd17194 | 401 | |
45004d43 AD |
402 | case "pref-feeds": |
403 | module_pref_feeds($link); | |
404 | break; // pref-feeds | |
a7f22b70 | 405 | |
45004d43 AD |
406 | case "pref-filters": |
407 | module_pref_filters($link); | |
408 | break; // pref-filters | |
a0476535 | 409 | |
45004d43 AD |
410 | case "pref-labels": |
411 | module_pref_labels($link); | |
412 | break; // pref-labels | |
d0000401 | 413 | |
45004d43 AD |
414 | case "pref-prefs": |
415 | module_pref_prefs($link); | |
416 | break; // pref-prefs | |
f27d955a | 417 | |
45004d43 AD |
418 | case "pref-users": |
419 | module_pref_users($link); | |
420 | break; // prefs-users | |
a0476535 | 421 | |
45004d43 AD |
422 | case "help": |
423 | module_help($link); | |
424 | break; // help | |
a0476535 | 425 | |
45004d43 AD |
426 | case "dlg": |
427 | module_popup_dialog($link); | |
428 | break; // dlg | |
a7f22b70 | 429 | |
45004d43 AD |
430 | case "pref-pub-items": |
431 | module_pref_pub_items($link); | |
432 | break; // pref-pub-items | |
e4f4b46f | 433 | |
45004d43 | 434 | case "globalUpdateFeeds": |
45004d43 | 435 | // Update all feeds needing a update. |
5cbaf873 | 436 | update_daemon_common($link, 0, true, true); |
45004d43 | 437 | break; // globalUpdateFeeds |
e5d758e3 | 438 | |
45004d43 AD |
439 | case "pref-feed-browser": |
440 | module_pref_feed_browser($link); | |
441 | break; // pref-feed-browser | |
c6232e43 | 442 | |
373266eb AD |
443 | case "pref-instances": |
444 | module_pref_instances($link); | |
445 | break; // pref-instances | |
446 | ||
45004d43 | 447 | case "rss": |
b4e75b2a | 448 | $feed = db_escape_string($_REQUEST["id"]); |
8801fb01 | 449 | $key = db_escape_string($_REQUEST["key"]); |
b4e75b2a AD |
450 | $is_cat = $_REQUEST["is_cat"] != false; |
451 | $limit = (int)db_escape_string($_REQUEST["limit"]); | |
e1eb2147 | 452 | |
b4e75b2a AD |
453 | $search = db_escape_string($_REQUEST["q"]); |
454 | $match_on = db_escape_string($_REQUEST["m"]); | |
455 | $search_mode = db_escape_string($_REQUEST["smode"]); | |
2f2bd1b3 | 456 | $view_mode = db_escape_string($_REQUEST["view-mode"]); |
18664970 | 457 | |
b4798282 AD |
458 | if (SINGLE_USER_MODE) { |
459 | authenticate_user($link, "admin", null); | |
460 | } | |
461 | ||
8e57cfbe | 462 | $owner_id = false; |
19039fd0 | 463 | |
8e57cfbe | 464 | if ($key) { |
8801fb01 AD |
465 | $result = db_query($link, "SELECT owner_uid FROM |
466 | ttrss_access_keys WHERE access_key = '$key' AND feed_id = '$feed'"); | |
467 | ||
468 | if (db_num_rows($result) == 1) | |
8e57cfbe | 469 | $owner_id = db_fetch_result($result, 0, "owner_uid"); |
45004d43 | 470 | } |
18664970 | 471 | |
8e57cfbe AD |
472 | if ($owner_id) { |
473 | $_SESSION['uid'] = $owner_id; | |
474 | ||
23d72f39 AD |
475 | generate_syndicated_feed($link, 0, $feed, $is_cat, $limit, |
476 | $search, $search_mode, $match_on, $view_mode); | |
19039fd0 AD |
477 | } else { |
478 | header('HTTP/1.1 403 Forbidden'); | |
45004d43 AD |
479 | } |
480 | break; // rss | |
18664970 | 481 | |
45004d43 | 482 | case "getUnread": |
b4e75b2a | 483 | $login = db_escape_string($_REQUEST["login"]); |
1f7b77d1 | 484 | $fresh = $_REQUEST["fresh"] == "1"; |
f3acc32e | 485 | |
45004d43 | 486 | $result = db_query($link, "SELECT id FROM ttrss_users WHERE login = '$login'"); |
7e3634d9 | 487 | |
45004d43 AD |
488 | if (db_num_rows($result) == 1) { |
489 | $uid = db_fetch_result($result, 0, "id"); | |
1f7b77d1 | 490 | |
45004d43 | 491 | print getGlobalUnread($link, $uid); |
1f7b77d1 AD |
492 | |
493 | if ($fresh) { | |
494 | print ";"; | |
495 | print getFeedArticles($link, -3, false, true, $uid); | |
496 | } | |
497 | ||
45004d43 AD |
498 | } else { |
499 | print "-1;User not found"; | |
500 | } | |
7e3634d9 | 501 | |
45004d43 | 502 | break; // getUnread |
9cd7c995 | 503 | |
45004d43 | 504 | case "digestTest": |
45004d43 | 505 | print_r(prepare_headlines_digest($link, $_SESSION["uid"])); |
45004d43 | 506 | break; // digestTest |
448b0abd | 507 | |
45004d43 | 508 | case "digestSend": |
45004d43 | 509 | send_headlines_digests($link); |
45004d43 | 510 | break; // digestSend |
7e3634d9 | 511 | |
ba7e88e5 | 512 | case "loading": |
347b467b | 513 | header("Content-type: text/html"); |
009646d2 | 514 | print __("Loading, please wait...") . " " . |
ba7e88e5 | 515 | "<img src='images/indicator_tiny.gif'>"; |
373266eb | 516 | break; // loading |
ba7e88e5 | 517 | |
d9084cf2 AD |
518 | case "getProfiles": |
519 | $login = db_escape_string($_REQUEST["login"]); | |
520 | $password = db_escape_string($_REQUEST["password"]); | |
521 | ||
522 | if (authenticate_user($link, $login, $password)) { | |
523 | $result = db_query($link, "SELECT * FROM ttrss_settings_profiles | |
524 | WHERE owner_uid = " . $_SESSION["uid"] . " ORDER BY title"); | |
525 | ||
526 | print "<select style='width: 100%' name='profile'>"; | |
527 | ||
528 | print "<option value='0'>" . __("Default profile") . "</option>"; | |
529 | ||
530 | while ($line = db_fetch_assoc($result)) { | |
531 | $id = $line["id"]; | |
532 | $title = $line["title"]; | |
533 | ||
534 | print "<option value='$id'>$title</option>"; | |
535 | } | |
536 | ||
537 | print "</select>"; | |
538 | ||
539 | $_SESSION = array(); | |
0456176a | 540 | } |
373266eb | 541 | break; // getprofiles |
d9084cf2 | 542 | |
5ab9791f AD |
543 | case "pubsub": |
544 | $mode = db_escape_string($_REQUEST['hub_mode']); | |
4dd369d4 | 545 | $feed_id = (int) db_escape_string($_REQUEST['id']); |
5ab9791f AD |
546 | $feed_url = db_escape_string($_REQUEST['hub_topic']); |
547 | ||
e2d2339c AD |
548 | if (!PUBSUBHUBBUB_ENABLED) { |
549 | header('HTTP/1.0 404 Not Found'); | |
550 | echo "404 Not found"; | |
551 | return; | |
552 | } | |
553 | ||
5ab9791f AD |
554 | // TODO: implement hub_verifytoken checking |
555 | ||
556 | $result = db_query($link, "SELECT feed_url FROM ttrss_feeds | |
557 | WHERE id = '$feed_id'"); | |
558 | ||
97279fe6 | 559 | if (db_num_rows($result) != 0) { |
5ab9791f | 560 | |
97279fe6 | 561 | $check_feed_url = db_fetch_result($result, 0, "feed_url"); |
5ab9791f | 562 | |
97279fe6 AD |
563 | if ($check_feed_url && ($check_feed_url == $feed_url || !$feed_url)) { |
564 | if ($mode == "subscribe") { | |
5ab9791f | 565 | |
97279fe6 AD |
566 | db_query($link, "UPDATE ttrss_feeds SET pubsub_state = 2 |
567 | WHERE id = '$feed_id'"); | |
7e0943c6 | 568 | |
97279fe6 AD |
569 | print $_REQUEST['hub_challenge']; |
570 | return; | |
5ab9791f | 571 | |
97279fe6 | 572 | } else if ($mode == "unsubscribe") { |
5ab9791f | 573 | |
97279fe6 AD |
574 | db_query($link, "UPDATE ttrss_feeds SET pubsub_state = 0 |
575 | WHERE id = '$feed_id'"); | |
7e0943c6 | 576 | |
97279fe6 AD |
577 | print $_REQUEST['hub_challenge']; |
578 | return; | |
f3acc32e | 579 | |
97279fe6 | 580 | } else if (!$mode) { |
5ab9791f | 581 | |
97279fe6 | 582 | // Received update ping, schedule feed update. |
1b790343 | 583 | //update_rss_feed($link, $feed_id, true, true); |
5ab9791f | 584 | |
1b790343 AD |
585 | db_query($link, "UPDATE ttrss_feeds SET |
586 | last_update_started = '1970-01-01', | |
587 | last_updated = '1970-01-01' WHERE id = '$feed_id' AND | |
588 | owner_uid = ".$_SESSION["uid"]); | |
97279fe6 AD |
589 | |
590 | } | |
591 | } else { | |
592 | header('HTTP/1.0 404 Not Found'); | |
593 | echo "404 Not found"; | |
5ab9791f AD |
594 | } |
595 | } else { | |
596 | header('HTTP/1.0 404 Not Found'); | |
97279fe6 | 597 | echo "404 Not found"; |
5ab9791f AD |
598 | } |
599 | ||
373266eb | 600 | break; // pubsub |
1ca77e0a AD |
601 | |
602 | case "logout": | |
603 | logout_user(); | |
604 | header("Location: tt-rss.php"); | |
373266eb | 605 | break; // logout |
1ca77e0a | 606 | |
ae5f7bb1 AD |
607 | case "fbexport": |
608 | ||
9b201046 | 609 | $access_key = db_escape_string($_POST["key"]); |
ae5f7bb1 AD |
610 | |
611 | // TODO: rate limit checking using last_connected | |
612 | $result = db_query($link, "SELECT id FROM ttrss_linked_instances | |
613 | WHERE access_key = '$access_key'"); | |
614 | ||
615 | if (db_num_rows($result) == 1) { | |
616 | ||
617 | $instance_id = db_fetch_result($result, 0, "id"); | |
618 | ||
109662e1 | 619 | $result = db_query($link, "SELECT feed_url, site_url, title, subscribers |
ae5f7bb1 AD |
620 | FROM ttrss_feedbrowser_cache ORDER BY subscribers DESC LIMIT 100"); |
621 | ||
622 | $feeds = array(); | |
623 | ||
624 | while ($line = db_fetch_assoc($result)) { | |
625 | array_push($feeds, $line); | |
626 | } | |
627 | ||
572d66c6 | 628 | db_query($link, "UPDATE ttrss_linked_instances SET |
ae5f7bb1 AD |
629 | last_status_in = 1 WHERE id = '$instance_id'"); |
630 | ||
631 | print json_encode(array("feeds" => $feeds)); | |
632 | } else { | |
633 | print json_encode(array("error" => array("code" => 6))); | |
634 | } | |
635 | break; // fbexport | |
636 | ||
83cd33fc AD |
637 | case "share": |
638 | $uuid = db_escape_string($_REQUEST["key"]); | |
639 | ||
640 | $result = db_query($link, "SELECT ref_id, owner_uid FROM ttrss_user_entries WHERE | |
641 | uuid = '$uuid'"); | |
642 | ||
643 | if (db_num_rows($result) != 0) { | |
644 | header("Content-Type: text/html"); | |
645 | ||
646 | $id = db_fetch_result($result, 0, "ref_id"); | |
647 | $owner_uid = db_fetch_result($result, 0, "owner_uid"); | |
648 | ||
f9da2388 | 649 | $_SESSION["uid"] = $owner_uid; |
83cd33fc | 650 | $article = format_article($link, $id, false, true); |
f9da2388 | 651 | $_SESSION["uid"] = ""; |
83cd33fc AD |
652 | |
653 | print_r($article['content']); | |
654 | ||
655 | } else { | |
656 | print "Article not found."; | |
657 | } | |
658 | ||
659 | break; | |
660 | ||
1ca77e0a AD |
661 | default: |
662 | header("Content-Type: text/plain"); | |
663 | print json_encode(array("error" => array("code" => 7))); | |
373266eb | 664 | break; // fallback |
5ab9791f | 665 | } // Select action according to $op value. |
ba7e88e5 | 666 | |
45004d43 | 667 | // We close the connection to database. |
4b3dff6e | 668 | db_close($link); |
1cd17194 | 669 | ?> |