]>
Commit | Line | Data |
---|---|---|
1d3a17c7 | 1 | <?php |
d65981e2 AD |
2 | error_reporting(E_ERROR | E_WARNING | E_PARSE); |
3 | ||
36bfab86 | 4 | require_once "sessions.php"; |
c339343b | 5 | require_once "modules/backend-rpc.php"; |
dc56b3b7 | 6 | |
894ebcf5 | 7 | /* if ($_GET["debug"]) { |
cce28758 AD |
8 | define('DEFAULT_ERROR_LEVEL', E_ALL); |
9 | } else { | |
10 | define('DEFAULT_ERROR_LEVEL', E_ERROR | E_WARNING | E_PARSE); | |
11 | } | |
894ebcf5 AD |
12 | |
13 | error_reporting(DEFAULT_ERROR_LEVEL); */ | |
cce28758 | 14 | |
657770a0 AD |
15 | require_once "sanity_check.php"; |
16 | require_once "config.php"; | |
af106b0e AD |
17 | |
18 | require_once "db.php"; | |
19 | require_once "db-prefs.php"; | |
20 | require_once "functions.php"; | |
657770a0 | 21 | |
dc56b3b7 | 22 | no_cache_incantation(); |
1025ad87 | 23 | startup_gettext(); |
dc56b3b7 | 24 | |
7f0acba7 AD |
25 | $script_started = getmicrotime(); |
26 | ||
27 | $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); | |
28 | ||
29 | if (!$link) { | |
30 | if (DB_TYPE == "mysql") { | |
31 | print mysql_error(); | |
32 | } | |
33 | // PG seems to display its own errors just fine by default. | |
34 | return; | |
35 | } | |
36 | ||
37 | if (DB_TYPE == "pgsql") { | |
38 | pg_query("set client_encoding = 'UTF-8'"); | |
39 | pg_set_client_encoding("UNICODE"); | |
40 | } | |
41 | ||
42 | $op = $_REQUEST["op"]; | |
43 | ||
c339343b | 44 | $print_exec_time = false; |
7e3634d9 | 45 | |
3de0261a AD |
46 | if ((!$op || $op == "rpc" || $op == "rss" || $op == "view" || |
47 | $op == "digestSend" || $op == "viewfeed" || | |
18664970 | 48 | $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) { |
6002818b AD |
49 | header("Content-Type: application/xml; charset=utf-8"); |
50 | } else { | |
51 | header("Content-Type: text/html; charset=utf-8"); | |
262bd8ea AD |
52 | } |
53 | ||
f3acc32e AD |
54 | if (!$op) { |
55 | header("Content-Type: application/xml"); | |
56 | print_error_xml(7); exit; | |
57 | } | |
42c32916 | 58 | |
7f0acba7 AD |
59 | if (!($_SESSION["uid"] && validate_session($link)) && $op != "globalUpdateFeeds" |
60 | && $op != "rss" && $op != "getUnread") { | |
262bd8ea | 61 | |
a2770077 | 62 | if ($op == "rpc") { |
af106b0e | 63 | print_error_xml(6); die; |
04269460 AD |
64 | } else { |
65 | print " | |
66 | <html><body> | |
67 | <p>Error: Not logged in.</p> | |
68 | <script type=\"text/javascript\"> | |
69 | if (parent.window != 'undefined') { | |
01a87dff | 70 | parent.window.location = \"tt-rss.php\"; |
04269460 | 71 | } else { |
01a87dff | 72 | window.location = \"tt-rss.php\"; |
04269460 AD |
73 | } |
74 | </script> | |
75 | </body></html> | |
76 | "; | |
262bd8ea AD |
77 | } |
78 | exit; | |
79 | } | |
1c7f75ed | 80 | |
ad815c71 | 81 | $purge_intervals = array( |
d1db26aa AD |
82 | 0 => __("Use default"), |
83 | -1 => __("Never purge"), | |
84 | 5 => __("1 week old"), | |
85 | 14 => __("2 weeks old"), | |
86 | 31 => __("1 month old"), | |
87 | 60 => __("2 months old"), | |
88 | 90 => __("3 months old")); | |
ad815c71 AD |
89 | |
90 | $update_intervals = array( | |
d1db26aa AD |
91 | 0 => __("Use default"), |
92 | -1 => __("Disable updates"), | |
93 | 30 => __("Each 30 minutes"), | |
94 | 60 => __("Hourly"), | |
95 | 240 => __("Each 4 hours"), | |
96 | 720 => __("Each 12 hours"), | |
97 | 1440 => __("Daily"), | |
98 | 10080 => __("Weekly")); | |
ad815c71 | 99 | |
d20f3544 | 100 | |
3c5783b7 | 101 | $access_level_names = array( |
d1db26aa AD |
102 | 0 => __("User"), |
103 | 10 => __("Administrator")); | |
3c5783b7 | 104 | |
f27d955a | 105 | require_once "modules/pref-prefs.php"; |
ef8be8ea AD |
106 | require_once "modules/popup-dialog.php"; |
107 | require_once "modules/help.php"; | |
108 | require_once "modules/pref-feeds.php"; | |
109 | require_once "modules/pref-filters.php"; | |
110 | require_once "modules/pref-labels.php"; | |
111 | require_once "modules/pref-users.php"; | |
c339343b | 112 | require_once "modules/pref-feed-browser.php"; |
ef8be8ea | 113 | |
7ec2a838 | 114 | |
b2804af7 | 115 | if (!sanity_check($link)) { return; } |
023fe037 | 116 | |
c3b81db0 | 117 | if ($op == "rpc") { |
01b3e191 | 118 | handle_rpc_request($link); |
c3b81db0 AD |
119 | } |
120 | ||
121 | if ($op == "feeds") { | |
122 | ||
8143ae1f AD |
123 | $tags = $_GET["tags"]; |
124 | ||
c3b81db0 AD |
125 | $subop = $_GET["subop"]; |
126 | ||
127 | if ($subop == "catchupAll") { | |
b018b49b | 128 | db_query($link, "UPDATE ttrss_user_entries SET |
6d15e1ef | 129 | last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]); |
c3b81db0 AD |
130 | } |
131 | ||
fe14aeb8 AD |
132 | if ($subop == "collapse") { |
133 | $cat_id = db_escape_string($_GET["cid"]); | |
280ee9a3 | 134 | |
fe14aeb8 AD |
135 | db_query($link, "UPDATE ttrss_feed_categories SET |
136 | collapsed = NOT collapsed WHERE id = '$cat_id' AND owner_uid = " . | |
137 | $_SESSION["uid"]); | |
138 | return; | |
139 | } | |
140 | ||
8143ae1f | 141 | outputFeedList($link, $tags); |
c3b81db0 | 142 | |
1cd17194 AD |
143 | } |
144 | ||
e097e8be AD |
145 | if ($op == "view") { |
146 | ||
147 | $id = db_escape_string($_GET["id"]); | |
148 | $feed_id = db_escape_string($_GET["feed"]); | |
149 | $cids = split(",", db_escape_string($_GET["cids"])); | |
150 | $mode = db_escape_string($_GET["mode"]); | |
5a94a953 | 151 | $omode = db_escape_string($_GET["omode"]); |
e097e8be AD |
152 | |
153 | print "<reply>"; | |
154 | ||
155 | // in prefetch mode we only output requested cids, main article | |
156 | // just gets marked as read (it already exists in client cache) | |
157 | ||
addb5836 | 158 | if ($mode == "") { |
e097e8be | 159 | outputArticleXML($link, $id, $feed_id); |
53761dda | 160 | } else { |
e097e8be AD |
161 | catchupArticleById($link, $id, 0); |
162 | } | |
163 | ||
164 | foreach ($cids as $cid) { | |
165 | if ($cid) { | |
166 | outputArticleXML($link, $cid, $feed_id, false); | |
167 | } | |
168 | } | |
169 | ||
addb5836 AD |
170 | if ($mode != "prefetch_old") { |
171 | print "<counters>"; | |
172 | getAllCounters($link, $omode); | |
173 | print "</counters>"; | |
174 | } | |
5a94a953 | 175 | |
e097e8be | 176 | print "</reply>"; |
1cd17194 AD |
177 | } |
178 | ||
179 | if ($op == "viewfeed") { | |
180 | ||
46921916 AD |
181 | $print_exec_time = true; |
182 | $timing_info = getmicrotime(); | |
183 | ||
3de0261a AD |
184 | print "<reply>"; |
185 | ||
46921916 AD |
186 | if ($_GET["debug"]) $timing_info = print_checkpoint("0", $timing_info); |
187 | ||
3de0261a AD |
188 | $omode = db_escape_string($_GET["omode"]); |
189 | ||
3c81ae1a | 190 | $feed = db_escape_string($_GET["feed"]); |
3c81ae1a | 191 | $subop = db_escape_string($_GET["subop"]); |
86b682ce | 192 | $view_mode = db_escape_string($_GET["view_mode"]); |
3c81ae1a AD |
193 | $limit = db_escape_string($_GET["limit"]); |
194 | $cat_view = db_escape_string($_GET["cat"]); | |
e0998414 | 195 | $next_unread_feed = db_escape_string($_GET["nuf"]); |
203de776 AD |
196 | $offset = db_escape_string($_GET["skip"]); |
197 | ||
40496720 AD |
198 | set_pref($link, "_DEFAULT_VIEW_MODE", $view_mode); |
199 | set_pref($link, "_DEFAULT_VIEW_LIMIT", $limit); | |
200 | ||
3de0261a | 201 | print "<headlines id=\"$feed\"><![CDATA["; |
c50e2b30 | 202 | |
961f4c73 AD |
203 | $topmost_article_ids = outputHeadlinesList($link, $feed, $subop, |
204 | $view_mode, $limit, $cat_view, $next_unread_feed, $offset); | |
d76a3b03 | 205 | |
3de0261a | 206 | print "]]></headlines>"; |
98bea1b1 | 207 | |
46921916 AD |
208 | if ($_GET["debug"]) $timing_info = print_checkpoint("10", $timing_info); |
209 | ||
a8f8e30f | 210 | if (is_array($topmost_article_ids) && !get_pref($link, 'COMBINED_DISPLAY_MODE')) { |
961f4c73 AD |
211 | print "<articles>"; |
212 | foreach ($topmost_article_ids as $id) { | |
213 | outputArticleXML($link, $id, $feed, false); | |
214 | } | |
215 | print "</articles>"; | |
216 | } | |
217 | ||
46921916 AD |
218 | if ($_GET["debug"]) $timing_info = print_checkpoint("20", $timing_info); |
219 | ||
3de0261a AD |
220 | print "<counters>"; |
221 | getAllCounters($link, $omode); | |
222 | print "</counters>"; | |
98bea1b1 | 223 | |
46921916 AD |
224 | if ($_GET["debug"]) $timing_info = print_checkpoint("30", $timing_info); |
225 | ||
3de0261a | 226 | print "</reply>"; |
1cd17194 AD |
227 | } |
228 | ||
0e091d38 | 229 | if ($op == "pref-feeds") { |
ef8be8ea AD |
230 | module_pref_feeds($link); |
231 | } | |
a7f22b70 | 232 | |
ef8be8ea AD |
233 | if ($op == "pref-filters") { |
234 | module_pref_filters($link); | |
235 | } | |
a0476535 | 236 | |
ef8be8ea AD |
237 | if ($op == "pref-labels") { |
238 | module_pref_labels($link); | |
239 | } | |
d0000401 | 240 | |
f27d955a AD |
241 | if ($op == "pref-prefs") { |
242 | module_pref_prefs($link); | |
243 | } | |
244 | ||
245 | if ($op == "pref-users") { | |
246 | module_pref_users($link); | |
ef8be8ea | 247 | } |
a0476535 | 248 | |
ef8be8ea AD |
249 | if ($op == "help") { |
250 | module_help($link); | |
251 | } | |
a0476535 | 252 | |
ef8be8ea AD |
253 | if ($op == "dlg") { |
254 | module_popup_dialog($link); | |
255 | } | |
a7f22b70 | 256 | |
ef8be8ea AD |
257 | // update feeds of all users, may be used anonymously |
258 | if ($op == "globalUpdateFeeds") { | |
a7f22b70 | 259 | |
ef8be8ea | 260 | $result = db_query($link, "SELECT id FROM ttrss_users"); |
a0476535 | 261 | |
ef8be8ea AD |
262 | while ($line = db_fetch_assoc($result)) { |
263 | $user_id = $line["id"]; | |
264 | // print "<!-- updating feeds of uid $user_id -->"; | |
265 | update_all_feeds($link, false, $user_id); | |
266 | } | |
e2f728be | 267 | |
ef8be8ea AD |
268 | print "<rpc-reply> |
269 | <message msg=\"All feeds updated\"/> | |
270 | </rpc-reply>"; | |
e5d758e3 | 271 | |
ef8be8ea | 272 | } |
f9cb39ac | 273 | |
ef8be8ea | 274 | if ($op == "user-details") { |
0af33e87 | 275 | |
ef8be8ea AD |
276 | if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) { |
277 | return; | |
278 | } | |
279 | ||
280 | /* print "<html><head> | |
281 | <title>Tiny Tiny RSS : User Details</title> | |
282 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\"> | |
283 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
284 | </head><body>"; */ | |
0af33e87 | 285 | |
ef8be8ea | 286 | $uid = sprintf("%d", $_GET["id"]); |
dc932d0a | 287 | |
ef8be8ea | 288 | print "<div id=\"infoBoxTitle\">User details</div>"; |
dc932d0a | 289 | |
ef8be8ea | 290 | print "<div class='infoBoxContents'>"; |
f9cb39ac | 291 | |
ef8be8ea AD |
292 | $result = db_query($link, "SELECT login, |
293 | SUBSTRING(last_login,1,16) AS last_login, | |
294 | access_level, | |
295 | (SELECT COUNT(int_id) FROM ttrss_user_entries | |
296 | WHERE owner_uid = id) AS stored_articles | |
297 | FROM ttrss_users | |
298 | WHERE id = '$uid'"); | |
f9cb39ac | 299 | |
ef8be8ea AD |
300 | if (db_num_rows($result) == 0) { |
301 | print "<h1>User not found</h1>"; | |
302 | return; | |
303 | } | |
304 | ||
305 | # print "<h1>User Details</h1>"; | |
f9cb39ac | 306 | |
ef8be8ea | 307 | $login = db_fetch_result($result, 0, "login"); |
b92e6209 | 308 | |
ef8be8ea | 309 | # print "<h1>$login</h1>"; |
dc932d0a | 310 | |
ef8be8ea | 311 | print "<table width='100%'>"; |
dc932d0a | 312 | |
ef8be8ea AD |
313 | $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'), |
314 | strtotime(db_fetch_result($result, 0, "last_login"))); | |
315 | $access_level = db_fetch_result($result, 0, "access_level"); | |
316 | $stored_articles = db_fetch_result($result, 0, "stored_articles"); | |
f9cb39ac | 317 | |
ef8be8ea AD |
318 | # print "<tr><td>Username</td><td>$login</td></tr>"; |
319 | # print "<tr><td>Access level</td><td>$access_level</td></tr>"; | |
320 | print "<tr><td>Last logged in</td><td>$last_login</td></tr>"; | |
321 | print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>"; | |
f9cb39ac | 322 | |
ef8be8ea AD |
323 | $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds |
324 | WHERE owner_uid = '$uid'"); | |
f9cb39ac | 325 | |
ef8be8ea | 326 | $num_feeds = db_fetch_result($result, 0, "num_feeds"); |
f9cb39ac | 327 | |
ef8be8ea | 328 | print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>"; |
0ea4fb50 | 329 | |
ef8be8ea AD |
330 | /* $result = db_query($link, "SELECT |
331 | SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size | |
332 | FROM ttrss_user_entries,ttrss_entries | |
333 | WHERE owner_uid = '$uid' AND ref_id = id"); | |
0ea4fb50 | 334 | |
ef8be8ea | 335 | $db_size = round(db_fetch_result($result, 0, "db_size") / 1024); |
0ea4fb50 | 336 | |
ef8be8ea | 337 | print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */ |
e5d758e3 | 338 | |
ef8be8ea | 339 | print "</table>"; |
e5d758e3 | 340 | |
ef8be8ea | 341 | print "<h1>Subscribed feeds</h1>"; |
e5d758e3 | 342 | |
ef8be8ea AD |
343 | $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds |
344 | WHERE owner_uid = '$uid' ORDER BY title"); | |
0ea4fb50 | 345 | |
ef8be8ea | 346 | print "<ul class=\"userFeedList\">"; |
0ea4fb50 | 347 | |
ef8be8ea | 348 | $row_class = "odd"; |
0ea4fb50 | 349 | |
ef8be8ea | 350 | while ($line = db_fetch_assoc($result)) { |
0ea4fb50 | 351 | |
ef8be8ea | 352 | $icon_file = ICONS_URL."/".$line["id"].".ico"; |
ad815c71 | 353 | |
ef8be8ea AD |
354 | if (file_exists($icon_file) && filesize($icon_file) > 0) { |
355 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">"; | |
356 | } else { | |
357 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">"; | |
358 | } | |
0ea4fb50 | 359 | |
ef8be8ea | 360 | print "<li class=\"$row_class\">$feed_icon <a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>"; |
0ea4fb50 | 361 | |
ef8be8ea | 362 | $row_class = toggleEvenOdd($row_class); |
0ea4fb50 | 363 | |
ef8be8ea | 364 | } |
a283b8d1 | 365 | |
ef8be8ea AD |
366 | if (db_num_rows($result) < $num_feeds) { |
367 | // FIXME - add link to show ALL subscribed feeds here somewhere | |
368 | print "<li><img | |
369 | class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\"> ...</li>"; | |
370 | } | |
371 | ||
372 | print "</ul>"; | |
a283b8d1 | 373 | |
ef8be8ea | 374 | print "</div>"; |
0ea4fb50 | 375 | |
ef8be8ea AD |
376 | print "<div align='center'> |
377 | <input type='submit' class='button' | |
378 | onclick=\"closeInfoBox()\" value=\"Close this window\"></div>"; | |
0ea4fb50 | 379 | |
ef8be8ea | 380 | // print "</body></html>"; |
0ea4fb50 | 381 | |
ef8be8ea | 382 | } |
ad815c71 | 383 | |
ef8be8ea | 384 | if ($op == "pref-feed-browser") { |
f27d955a | 385 | module_pref_feed_browser($link); |
c6232e43 AD |
386 | } |
387 | ||
18664970 AD |
388 | if ($op == "rss") { |
389 | $feed = db_escape_string($_GET["id"]); | |
390 | $user = db_escape_string($_GET["user"]); | |
391 | $pass = db_escape_string($_GET["pass"]); | |
392 | $is_cat = $_GET["is_cat"] != false; | |
393 | ||
e1eb2147 AD |
394 | $search = db_escape_string($_GET["q"]); |
395 | $match_on = db_escape_string($_GET["m"]); | |
396 | $search_mode = db_escape_string($_GET["smode"]); | |
397 | ||
18664970 AD |
398 | if (!$_SESSION["uid"] && $user && $pass) { |
399 | authenticate_user($link, $user, $pass); | |
400 | } | |
401 | ||
402 | if ($_SESSION["uid"] || | |
403 | http_authenticate_user($link)) { | |
404 | ||
e1eb2147 AD |
405 | generate_syndicated_feed($link, $feed, $is_cat, |
406 | $search, $search_mode, $match_on); | |
18664970 AD |
407 | } |
408 | } | |
409 | ||
88040f57 AD |
410 | if ($op == "labelFromSearch") { |
411 | $search = db_escape_string($_GET["search"]); | |
412 | $search_mode = db_escape_string($_GET["smode"]); | |
413 | $match_on = db_escape_string($_GET["match"]); | |
414 | $is_cat = db_escape_string($_GET["is_cat"]); | |
415 | $title = db_escape_string($_GET["title"]); | |
416 | $feed = sprintf("%d", $_GET["feed"]); | |
417 | ||
418 | $label_qparts = array(); | |
419 | ||
420 | $search_expr = getSearchSql($search, $match_on); | |
421 | ||
422 | if ($is_cat) { | |
423 | if ($feed != 0) { | |
424 | $search_expr .= " AND ttrss_feeds.cat_id = $feed "; | |
425 | } else { | |
426 | $search_expr .= " AND ttrss_feeds.cat_id IS NULL "; | |
427 | } | |
428 | } else { | |
429 | if ($search_mode == "all_feeds") { | |
430 | // NOOP | |
431 | } else if ($search_mode == "this_cat") { | |
432 | ||
433 | $tmp_result = db_query($link, "SELECT cat_id | |
434 | FROM ttrss_feeds WHERE id = '$feed'"); | |
435 | ||
436 | $cat_id = db_fetch_result($tmp_result, 0, "cat_id"); | |
437 | ||
438 | if ($cat_id > 0) { | |
439 | $search_expr .= " AND ttrss_feeds.cat_id = $cat_id "; | |
440 | } else { | |
441 | $search_expr .= " AND ttrss_feeds.cat_id IS NULL "; | |
442 | } | |
443 | } else { | |
444 | $search_expr .= " AND ttrss_feeds.id = $feed "; | |
445 | } | |
446 | ||
447 | } | |
448 | ||
449 | $search_expr = db_escape_string($search_expr); | |
450 | ||
451 | print $search_expr; | |
452 | ||
453 | if ($title) { | |
454 | $result = db_query($link, | |
455 | "INSERT INTO ttrss_labels (sql_exp,description,owner_uid) | |
456 | VALUES ('$search_expr', '$title', '".$_SESSION["uid"]."')"); | |
457 | } | |
458 | } | |
459 | ||
f3acc32e AD |
460 | if ($op == "getUnread") { |
461 | $login = db_escape_string($_GET["login"]); | |
462 | ||
7e3634d9 | 463 | header("Content-Type: text/plain; charset=utf-8"); |
f3acc32e AD |
464 | |
465 | $result = db_query($link, "SELECT id FROM ttrss_users WHERE login = '$login'"); | |
466 | ||
467 | if (db_num_rows($result) == 1) { | |
468 | $uid = db_fetch_result($result, 0, "id"); | |
469 | print getGlobalUnread($link, $uid); | |
470 | } else { | |
0599d09e | 471 | print "-1;User not found"; |
f3acc32e | 472 | } |
7e3634d9 AD |
473 | |
474 | $print_exec_time = false; | |
475 | } | |
476 | ||
477 | if ($op == "digestTest") { | |
478 | header("Content-Type: text/plain"); | |
9cd7c995 AD |
479 | print_r(prepare_headlines_digest($link, $_SESSION["uid"])); |
480 | $print_exec_time = false; | |
481 | ||
482 | } | |
448b0abd | 483 | |
9cd7c995 AD |
484 | if ($op == "digestSend") { |
485 | header("Content-Type: text/plain"); | |
486 | send_headlines_digests($link); | |
7e3634d9 AD |
487 | $print_exec_time = false; |
488 | ||
f3acc32e AD |
489 | } |
490 | ||
4b3dff6e | 491 | db_close($link); |
1cd17194 | 492 | ?> |
406d9489 | 493 | |
7e3634d9 | 494 | <?php if ($print_exec_time) { ?> |
1d3a17c7 | 495 | <!-- <?php echo sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> --> |
f3acc32e | 496 | <?php } ?> |