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