]> git.wh0rd.org - tt-rss.git/blame - backend.php
add special class for postReply taglist
[tt-rss.git] / backend.php
CommitLineData
1d3a17c7 1<?php
36bfab86 2 require_once "sessions.php";
c339343b 3 require_once "modules/backend-rpc.php";
36bfab86 4
59b8192f 5 header("Cache-Control: no-cache, must-revalidate");
ce0619bb
AD
6 header("Pragma: no-cache");
7 header("Expires: -1");
de696427 8
894ebcf5 9/* if ($_GET["debug"]) {
cce28758
AD
10 define('DEFAULT_ERROR_LEVEL', E_ALL);
11 } else {
12 define('DEFAULT_ERROR_LEVEL', E_ERROR | E_WARNING | E_PARSE);
13 }
894ebcf5
AD
14
15 error_reporting(DEFAULT_ERROR_LEVEL); */
cce28758 16
262bd8ea
AD
17 $op = $_REQUEST["op"];
18
9ebaec05 19 define('SCHEMA_VERSION', 12);
657770a0
AD
20
21 require_once "sanity_check.php";
22 require_once "config.php";
af106b0e
AD
23
24 require_once "db.php";
25 require_once "db-prefs.php";
26 require_once "functions.php";
657770a0 27
c339343b 28 $print_exec_time = false;
7e3634d9 29
4803eed2 30 if ((!$op || $op == "rpc" || $op == "rss" || $op == "digestSend" ||
18664970 31 $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
262bd8ea
AD
32 header("Content-Type: application/xml");
33 }
34
f3acc32e
AD
35 if (!$op) {
36 header("Content-Type: application/xml");
37 print_error_xml(7); exit;
38 }
39
40 if (!$_SESSION["uid"] && $op != "globalUpdateFeeds" && $op != "rss" && $op != "getUnread") {
262bd8ea 41
a2770077 42 if ($op == "rpc") {
af106b0e 43 print_error_xml(6); die;
04269460
AD
44 } else {
45 print "
46 <html><body>
47 <p>Error: Not logged in.</p>
48 <script type=\"text/javascript\">
49 if (parent.window != 'undefined') {
50 parent.window.location = \"login.php\";
51 } else {
52 window.location = \"login.php\";
53 }
54 </script>
55 </body></html>
56 ";
262bd8ea
AD
57 }
58 exit;
59 }
1c7f75ed 60
ad815c71 61 $purge_intervals = array(
c6932f8d 62 0 => "Use default",
ad815c71 63 -1 => "Never purge",
c6932f8d
AD
64 5 => "1 week old",
65 14 => "2 weeks old",
66 31 => "1 month old",
67 60 => "2 months old",
68 90 => "3 months old");
ad815c71
AD
69
70 $update_intervals = array(
c6932f8d 71 0 => "Use default",
ad815c71 72 -1 => "Disable updates",
c6932f8d
AD
73 30 => "Each 30 minutes",
74 60 => "Hourly",
75 240 => "Each 4 hours",
76 720 => "Each 12 hours",
ad815c71
AD
77 1440 => "Daily",
78 10080 => "Weekly");
79
d20f3544 80
3c5783b7
AD
81 $access_level_names = array(
82 0 => "User",
83 10 => "Administrator");
84
f27d955a 85 require_once "modules/pref-prefs.php";
ef8be8ea
AD
86 require_once "modules/popup-dialog.php";
87 require_once "modules/help.php";
88 require_once "modules/pref-feeds.php";
89 require_once "modules/pref-filters.php";
90 require_once "modules/pref-labels.php";
91 require_once "modules/pref-users.php";
c339343b 92 require_once "modules/pref-feed-browser.php";
ef8be8ea 93
406d9489
AD
94 $script_started = getmicrotime();
95
648472a7 96 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
d76a3b03 97
5136011e
AD
98 if (!$link) {
99 if (DB_TYPE == "mysql") {
100 print mysql_error();
101 }
102 // PG seems to display its own errors just fine by default.
103 return;
104 }
105
648472a7
AD
106 if (DB_TYPE == "pgsql") {
107 pg_query("set client_encoding = 'utf-8'");
108 }
7ec2a838 109
b2804af7 110 if (!sanity_check($link)) { return; }
023fe037 111
c3b81db0 112 if ($op == "rpc") {
01b3e191 113 handle_rpc_request($link);
c3b81db0
AD
114 }
115
116 if ($op == "feeds") {
117
8143ae1f
AD
118 $tags = $_GET["tags"];
119
c3b81db0
AD
120 $subop = $_GET["subop"];
121
122 if ($subop == "catchupAll") {
b018b49b 123 db_query($link, "UPDATE ttrss_user_entries SET
6d15e1ef 124 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
c3b81db0
AD
125 }
126
fe14aeb8
AD
127 if ($subop == "collapse") {
128 $cat_id = db_escape_string($_GET["cid"]);
280ee9a3 129
fe14aeb8
AD
130 db_query($link, "UPDATE ttrss_feed_categories SET
131 collapsed = NOT collapsed WHERE id = '$cat_id' AND owner_uid = " .
132 $_SESSION["uid"]);
133 return;
134 }
135
8143ae1f 136 outputFeedList($link, $tags);
c3b81db0 137
1cd17194
AD
138 }
139
140 if ($op == "view") {
141
70f6dbb1
AD
142 $id = db_escape_string($_GET["id"]);
143 $feed_id = db_escape_string($_GET["feed"]);
144
145 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
146 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
147
148 if (db_num_rows($result) == 1) {
149 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
150 } else {
151 $rtl_content = false;
152 }
153
154 if ($rtl_content) {
155 $rtl_tag = "dir=\"RTL\"";
ed51e128 156 $rtl_class = "RTL";
70f6dbb1
AD
157 } else {
158 $rtl_tag = "";
ed51e128 159 $rtl_class = "";
70f6dbb1 160 }
d76a3b03 161
4c193675
AD
162 $result = db_query($link, "UPDATE ttrss_user_entries
163 SET unread = false,last_read = NOW()
276eecef 164 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
a1a8a2be 165
21703604 166 $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
9167e250 167 SUBSTRING(updated,1,16) as updated,
11b0dce2 168 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url,
a545b564
AD
169 num_comments,
170 author
4c193675 171 FROM ttrss_entries,ttrss_user_entries
12fb24b9 172 WHERE id = '$id' AND ref_id = id AND owner_uid = " . $_SESSION["uid"]);
1cd17194 173
d76a3b03 174 if ($result) {
1cd17194 175
c1826240
AD
176 $link_target = "";
177
178 if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) {
179 $link_target = "target=\"_new\"";
180 }
181
648472a7 182 $line = db_fetch_assoc($result);
1cd17194 183
b7f4bda2
AD
184 if ($line["icon_url"]) {
185 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
186 } else {
187 $feed_icon = "&nbsp;";
188 }
d76a3b03 189
11b0dce2 190/* if ($line["comments"] && $line["link"] != $line["comments"]) {
f7181e9b
AD
191 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
192 } else {
193 $entry_comments = "";
11b0dce2
AD
194 } */
195
196 $num_comments = $line["num_comments"];
197 $entry_comments = "";
198
199 if ($num_comments > 0) {
200 if ($line["comments"]) {
201 $comments_url = $line["comments"];
202 } else {
203 $comments_url = $line["link"];
204 }
c1826240 205 $entry_comments = "<a $link_target href=\"$comments_url\">$num_comments comments</a>";
11b0dce2
AD
206 } else {
207 if ($line["comments"] && $line["link"] != $line["comments"]) {
c1826240 208 $entry_comments = "<a $link_target href=\"".$line["comments"]."\">comments</a>";
11b0dce2 209 }
f7181e9b
AD
210 }
211
e828e31e
AD
212 print "<div class=\"postReply\">";
213
b810a0f1 214 print "<div class=\"postHeader\">";
21703604 215
a545b564
AD
216 $entry_author = $line["author"];
217
218 if ($entry_author) {
219 $entry_author = " - by $entry_author";
220 }
1f64b1be 221
9167e250
AD
222 $parsed_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
223 strtotime($line["updated"]));
224
b810a0f1
AD
225 print "<div class=\"postDate$rtl_class\">$parsed_updated</div>";
226
227 if ($line["link"]) {
228 print "<div clear='both'><a $link_target href=\"" . $line["link"] . "\">" .
229 $line["title"] . "</a>$entry_author</div>";
230 } else {
231 print "<div clear='both'>" . $line["title"] . "$entry_author</div>";
232 }
21703604
AD
233
234 $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM
235 ttrss_tags WHERE post_int_id = " . $line["int_id"] . "
236 ORDER BY tag_name");
237
238 $tags_str = "";
42918a07
AD
239 $f_tags_str = "";
240
241 $num_tags = 0;
21703604
AD
242
243 while ($tmp_line = db_fetch_assoc($tmp_result)) {
42918a07
AD
244 $num_tags++;
245 $tag = $tmp_line["tag_name"];
ca676fb5 246 $tag_str = "<a href=\"javascript:viewfeed('$tag')\">$tag</a>, ";
42918a07 247
b810a0f1 248 if ($num_tags == 6) {
42918a07 249 $tags_str .= "<a href=\"javascript:showBlockElement('allEntryTags')\">...</a>";
b810a0f1 250 } else if ($num_tags < 6) {
42918a07
AD
251 $tags_str .= $tag_str;
252 }
253 $f_tags_str .= $tag_str;
254 }
21703604 255
42918a07
AD
256 $tags_str = preg_replace("/, $/", "", $tags_str);
257 $f_tags_str = preg_replace("/, $/", "", $f_tags_str);
e828e31e 258
b810a0f1 259 if (!$entry_comments) $entry_comments = "&nbsp;"; # placeholder
21703604 260
99206d5c 261 if (!$tags_str) $tags_str = '<span class="tagList">no tags</span>';
3db880c6 262
b810a0f1 263 print "<div style='float : right'>$tags_str
ffb761c9
AD
264 <a title=\"Edit tags for this article\"
265 href=\"javascript:editArticleTags($id, $feed_id)\">(+)</a></div>
b810a0f1 266 <div clear='both'>$entry_comments</div>";
21703604 267
b810a0f1 268 print "</div>";
e828e31e
AD
269
270 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
42918a07
AD
271 print "<div class=\"postContent\">";
272
0b126ac2 273 if (db_num_rows($tmp_result) > 0) {
42918a07
AD
274 print "<div id=\"allEntryTags\">Tags: $f_tags_str</div>";
275 }
276
68511f86
AD
277 if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) {
278 $line["content"] = preg_replace("/href=/i", "target=\"_new\" href=", $line["content"]);
279 }
280
a262b161
AD
281 $line["content"] = sanitize_rss($line["content"]);
282
42918a07 283 print $line["content"] . "</div>";
e828e31e
AD
284
285 print "</div>";
286
d76a3b03 287 }
1cd17194
AD
288 }
289
290 if ($op == "viewfeed") {
291
3c81ae1a 292 $feed = db_escape_string($_GET["feed"]);
3c81ae1a 293 $subop = db_escape_string($_GET["subop"]);
86b682ce 294 $view_mode = db_escape_string($_GET["view_mode"]);
3c81ae1a
AD
295 $limit = db_escape_string($_GET["limit"]);
296 $cat_view = db_escape_string($_GET["cat"]);
e0998414 297 $next_unread_feed = db_escape_string($_GET["nuf"]);
a1a8a2be 298
476cac42 299 if ($subop == "undefined") $subop = "";
1cd17194 300
472782e8
AD
301 if ($subop == "CatchupSelected") {
302 $ids = split(",", db_escape_string($_GET["ids"]));
303 $cmode = sprintf("%d", $_GET["cmode"]);
304
305 catchupArticlesById($link, $ids, $cmode);
306 }
307
e0998414
AD
308 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
309 update_generic_feed($link, $feed, $cat_view);
310 }
311
312 if ($subop == "MarkAllRead") {
313 catchup_feed($link, $feed, $cat_view);
314
315 if (get_pref($link, 'ON_CATCHUP_SHOW_NEXT_FEED')) {
adba6b85
AD
316 if ($next_unread_feed) {
317 $feed = $next_unread_feed;
318 }
e0998414
AD
319 }
320 }
321
a6b4a12a
AD
322 if ($feed_id > 0) {
323 $result = db_query($link,
324 "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1");
e33a1fda 325
a6b4a12a
AD
326 if (db_num_rows($result) == 0) {
327 print "<div align='center'>
328 Feed not found.</div>";
329 return;
330 }
e33a1fda
AD
331 }
332
2e915ba9
AD
333 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
334
335 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
336 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
70f6dbb1 337
2e915ba9
AD
338 if (db_num_rows($result) == 1) {
339 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
340 } else {
341 $rtl_content = false;
342 }
343
344 if ($rtl_content) {
345 $rtl_tag = "dir=\"RTL\"";
346 } else {
347 $rtl_tag = "";
348 }
70f6dbb1
AD
349 } else {
350 $rtl_tag = "";
2e915ba9 351 $rtl_content = false;
70f6dbb1
AD
352 }
353
8911ac8b
AD
354 $script_dt_add = get_script_dt_add();
355
6b4163cb 356/* print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
86b682ce 357 <script type=\"text/javascript\" src=\"prototype.js\"></script>
53515ff1
AD
358 <script type=\"text/javascript\" src=\"functions.js?$script_dt_add\"></script>
359 <script type=\"text/javascript\" src=\"viewfeed.js?$script_dt_add\"></script>
59b8192f
AD
360 <!--[if gte IE 5.5000]>
361 <script type=\"text/javascript\" src=\"pngfix.js\"></script>
362 <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\">
363 <![endif]-->
10031c3b 364 </head><body $rtl_tag>
59b8192f
AD
365 <script type=\"text/javascript\">
366 if (document.addEventListener) {
367 document.addEventListener(\"DOMContentLoaded\", init, null);
368 }
369 window.onload = init;
6b4163cb 370 </script>"; */
59b8192f 371
ef393de7
AD
372 /// START /////////////////////////////////////////////////////////////////////////////////
373
86b682ce
AD
374 $search = db_escape_string($_GET["query"]);
375 $search_mode = db_escape_string($_GET["search_mode"]);
376 $match_on = db_escape_string($_GET["match_on"]);
52b51244 377
86b682ce
AD
378 if (!$match_on) {
379 $match_on = "both";
380 }
5c365f60 381
ef393de7 382 $qfh_ret = queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, $search, $search_mode, $match_on);
b0005823 383
ef393de7
AD
384 $result = $qfh_ret[0];
385 $feed_title = $qfh_ret[1];
c7188969
AD
386 $feed_site_url = $qfh_ret[2];
387 $last_error = $qfh_ret[3];
48f0adb0 388
ef393de7 389 /// STOP //////////////////////////////////////////////////////////////////////////////////
48f0adb0 390
b15442c6 391 print "<div id=\"headlinesContainer\" $rtl_tag>";
386cbf27 392
48f0adb0 393 if (!$result) {
386cbf27
AD
394 print "<div align='center'>
395 Could not display feed (query failed). Please check label match syntax or local configuration.</div>";
396 return;
adccd201 397 }
98bea1b1
AD
398
399 if (db_num_rows($result) > 0) {
400
c1c9df00 401 print_headline_subtoolbar($link, $feed_site_url, $feed_title, false,
e1eb2147 402 $rtl_content, $feed, $cat_view, $search, $match_on, $search_mode);
98bea1b1 403
11befbb2
AD
404 print "<div id=\"headlinesInnerContainer\">";
405
386cbf27 406 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
adccd201 407 print "<table class=\"headlinesList\" id=\"headlinesList\"
10031c3b 408 cellspacing=\"0\" width=\"100%\">";
f4c10d44 409 }
386cbf27 410
e5a99b88
AD
411 $lnum = 0;
412
413 error_reporting (DEFAULT_ERROR_LEVEL);
414
415 $num_unread = 0;
416
417 while ($line = db_fetch_assoc($result)) {
adccd201 418
e5a99b88
AD
419 $class = ($lnum % 2) ? "even" : "odd";
420
421 $id = $line["id"];
422 $feed_id = $line["feed_id"];
423
424 if ($line["last_read"] == "" &&
425 ($line["unread"] != "t" && $line["unread"] != "1")) {
426
427 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
428 alt=\"Updated\">";
429 } else {
430 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
431 alt=\"Updated\">";
432 }
433
434 if ($line["unread"] == "t" || $line["unread"] == "1") {
435 $class .= "Unread";
436 ++$num_unread;
386cbf27 437 $is_unread = true;
adccd201 438 } else {
386cbf27 439 $is_unread = false;
e5a99b88
AD
440 }
441
442 if ($line["marked"] == "t" || $line["marked"] == "1") {
443 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
9932fb06 444 alt=\"Reset mark\" onclick='javascript:toggleMark($id)'>";
e5a99b88
AD
445 } else {
446 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
9932fb06 447 alt=\"Set mark\" onclick='javascript:toggleMark($id)'>";
e5a99b88 448 }
a753538d
AD
449
450# $content_link = "<a target=\"_new\" href=\"".$line["link"]."\">" .
451# $line["title"] . "</a>";
452
e454a889 453 $content_link = "<a href=\"javascript:view($id,$feed_id);\">" .
e5a99b88 454 $line["title"] . "</a>";
adccd201 455
a753538d
AD
456# $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" .
457# $line["title"] . "</a>";
458
e5a99b88
AD
459 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
460 $updated_fmt = smart_date_time(strtotime($line["updated"]));
461 } else {
462 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
463 $updated_fmt = date($short_date, strtotime($line["updated"]));
464 }
adccd201
AD
465
466 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
8fd0c717 467 $content_preview = truncate_string(strip_tags($line["content_preview"]),
070d0d2a 468 100);
adccd201
AD
469 }
470
d4b4b9de
AD
471 $entry_author = $line["author"];
472
473 if ($entry_author) {
474 $entry_author = " - by $entry_author";
475 }
476
386cbf27 477 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
adccd201
AD
478
479 print "<tr class='$class' id='RROW-$id'>";
adccd201
AD
480
481 print "<td class='hlUpdatePic'>$update_pic</td>";
482
483 print "<td class='hlSelectRow'>
484 <input type=\"checkbox\" onclick=\"toggleSelectRow(this)\"
485 class=\"feedCheckBox\" id=\"RCHK-$id\">
486 </td>";
487
488 print "<td class='hlMarkedPic'>$marked_pic</td>";
d4b4b9de 489
adccd201
AD
490 if ($line["feed_title"]) {
491 print "<td class='hlContent'>$content_link</td>";
492 print "<td class='hlFeed'>
faf40998 493 <a href=\"javascript:viewfeed($feed_id, '', false)\">".
9b1424fe 494 $line["feed_title"]."</a>&nbsp;</td>";
adccd201 495 } else {
de244d27 496 print "<td class='hlContent' valign='middle'>";
e688bab8 497
00dacdc1
AD
498 print "<a href=\"javascript:view($id,$feed_id);\">" .
499 $line["title"];
500
70f6dbb1 501 if (get_pref($link, 'SHOW_CONTENT_PREVIEW') && !$rtl_tag) {
adccd201
AD
502 if ($content_preview) {
503 print "<span class=\"contentPreview\"> - $content_preview</span>";
504 }
505 }
506
507 print "</a>";
508 print "</td>";
509 }
510
511 print "<td class=\"hlUpdated\"><nobr>$updated_fmt&nbsp;</nobr></td>";
512
513 print "</tr>";
514
515 } else {
386cbf27
AD
516
517 if ($is_unread) {
518 $add_class = "Unread";
519 } else {
520 $add_class = "";
521 }
522
523 print "<div class=\"cdmArticle$add_class\" id=\"RROW-$id\">";
524
525 print "<div class=\"cdmHeader\">";
adccd201 526
5f51022a
AD
527 print "<div style=\"float : right\">$updated_fmt,
528 <a class=\"cdmToggleLink\"
529 href=\"javascript:toggleUnread($id)\">Toggle unread</a>
530 </div>";
386cbf27 531
5f51022a
AD
532 print "<a class=\"title\"
533 onclick=\"javascript:toggleUnread($id, 0)\"
534 target=\"new\" href=\"".$line["link"]."\">".$line["title"]."</a>";
adccd201 535
d4b4b9de
AD
536 print $entry_author;
537
386cbf27
AD
538 if ($line["feed_title"]) {
539 print "&nbsp;(<a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a>)";
adccd201 540 }
adccd201 541
386cbf27
AD
542 print "</div>";
543
752bd598 544 print "<div class=\"cdmContent\">" . $line["content_preview"] . "</div><br clear=\"all\">";
5f51022a 545
386cbf27 546 print "<div style=\"float : right\">$marked_pic</div>
5f51022a 547 <div lass=\"cdmFooter\">
386cbf27
AD
548 <input type=\"checkbox\" onclick=\"toggleSelectRowById(this,
549 'RROW-$id')\" class=\"feedCheckBox\" id=\"RCHK-$id\"></div>";
550
5f51022a
AD
551# print "<div align=\"center\"><a class=\"cdmToggleLink\"
552# href=\"javascript:toggleUnread($id)\">
553# Toggle unread</a></div>";
554
386cbf27
AD
555 print "</div>";
556
557 }
e5a99b88
AD
558
559 ++$lnum;
254e0e4b 560 }
adccd201 561
386cbf27 562 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
adccd201 563 print "</table>";
adccd201 564 }
d76a3b03 565
11befbb2
AD
566 print "</div>";
567
568// print_headline_subtoolbar($link,
569// "javascript:catchupPage()", "Mark page as read", true, $rtl_content);
98bea1b1
AD
570
571
e5a99b88 572 } else {
6a4413b4 573 print "<div class='whiteBox'>No articles found.</div>";
a1a8a2be 574 }
d76a3b03 575
386cbf27 576 print "</div>";
1cd17194
AD
577 }
578
0e091d38 579 if ($op == "pref-feeds") {
ef8be8ea
AD
580 module_pref_feeds($link);
581 }
a7f22b70 582
ef8be8ea
AD
583 if ($op == "pref-filters") {
584 module_pref_filters($link);
585 }
a0476535 586
ef8be8ea
AD
587 if ($op == "pref-labels") {
588 module_pref_labels($link);
589 }
d0000401 590
f27d955a
AD
591 if ($op == "pref-prefs") {
592 module_pref_prefs($link);
593 }
594
595 if ($op == "pref-users") {
596 module_pref_users($link);
ef8be8ea 597 }
a0476535 598
ef8be8ea
AD
599 if ($op == "help") {
600 module_help($link);
601 }
a0476535 602
ef8be8ea
AD
603 if ($op == "dlg") {
604 module_popup_dialog($link);
605 }
a7f22b70 606
ef8be8ea
AD
607 // update feeds of all users, may be used anonymously
608 if ($op == "globalUpdateFeeds") {
a7f22b70 609
ef8be8ea 610 $result = db_query($link, "SELECT id FROM ttrss_users");
a0476535 611
ef8be8ea
AD
612 while ($line = db_fetch_assoc($result)) {
613 $user_id = $line["id"];
614// print "<!-- updating feeds of uid $user_id -->";
615 update_all_feeds($link, false, $user_id);
616 }
e2f728be 617
ef8be8ea
AD
618 print "<rpc-reply>
619 <message msg=\"All feeds updated\"/>
620 </rpc-reply>";
e5d758e3 621
ef8be8ea 622 }
f9cb39ac 623
ef8be8ea 624 if ($op == "user-details") {
0af33e87 625
ef8be8ea
AD
626 if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) {
627 return;
628 }
629
630/* print "<html><head>
631 <title>Tiny Tiny RSS : User Details</title>
632 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
633 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
634 </head><body>"; */
0af33e87 635
ef8be8ea 636 $uid = sprintf("%d", $_GET["id"]);
dc932d0a 637
ef8be8ea 638 print "<div id=\"infoBoxTitle\">User details</div>";
dc932d0a 639
ef8be8ea 640 print "<div class='infoBoxContents'>";
f9cb39ac 641
ef8be8ea
AD
642 $result = db_query($link, "SELECT login,
643 SUBSTRING(last_login,1,16) AS last_login,
644 access_level,
645 (SELECT COUNT(int_id) FROM ttrss_user_entries
646 WHERE owner_uid = id) AS stored_articles
647 FROM ttrss_users
648 WHERE id = '$uid'");
f9cb39ac 649
ef8be8ea
AD
650 if (db_num_rows($result) == 0) {
651 print "<h1>User not found</h1>";
652 return;
653 }
654
655# print "<h1>User Details</h1>";
f9cb39ac 656
ef8be8ea 657 $login = db_fetch_result($result, 0, "login");
b92e6209 658
ef8be8ea 659# print "<h1>$login</h1>";
dc932d0a 660
ef8be8ea 661 print "<table width='100%'>";
dc932d0a 662
ef8be8ea
AD
663 $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'),
664 strtotime(db_fetch_result($result, 0, "last_login")));
665 $access_level = db_fetch_result($result, 0, "access_level");
666 $stored_articles = db_fetch_result($result, 0, "stored_articles");
f9cb39ac 667
ef8be8ea
AD
668# print "<tr><td>Username</td><td>$login</td></tr>";
669# print "<tr><td>Access level</td><td>$access_level</td></tr>";
670 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
671 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
f9cb39ac 672
ef8be8ea
AD
673 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
674 WHERE owner_uid = '$uid'");
f9cb39ac 675
ef8be8ea 676 $num_feeds = db_fetch_result($result, 0, "num_feeds");
f9cb39ac 677
ef8be8ea 678 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
0ea4fb50 679
ef8be8ea
AD
680/* $result = db_query($link, "SELECT
681 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
682 FROM ttrss_user_entries,ttrss_entries
683 WHERE owner_uid = '$uid' AND ref_id = id");
0ea4fb50 684
ef8be8ea 685 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
0ea4fb50 686
ef8be8ea 687 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
e5d758e3 688
ef8be8ea 689 print "</table>";
e5d758e3 690
ef8be8ea 691 print "<h1>Subscribed feeds</h1>";
e5d758e3 692
ef8be8ea
AD
693 $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds
694 WHERE owner_uid = '$uid' ORDER BY title");
0ea4fb50 695
ef8be8ea 696 print "<ul class=\"userFeedList\">";
0ea4fb50 697
ef8be8ea 698 $row_class = "odd";
0ea4fb50 699
ef8be8ea 700 while ($line = db_fetch_assoc($result)) {
0ea4fb50 701
ef8be8ea 702 $icon_file = ICONS_URL."/".$line["id"].".ico";
ad815c71 703
ef8be8ea
AD
704 if (file_exists($icon_file) && filesize($icon_file) > 0) {
705 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
706 } else {
707 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
708 }
0ea4fb50 709
ef8be8ea 710 print "<li class=\"$row_class\">$feed_icon&nbsp;<a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>";
0ea4fb50 711
ef8be8ea 712 $row_class = toggleEvenOdd($row_class);
0ea4fb50 713
ef8be8ea 714 }
a283b8d1 715
ef8be8ea
AD
716 if (db_num_rows($result) < $num_feeds) {
717 // FIXME - add link to show ALL subscribed feeds here somewhere
718 print "<li><img
719 class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">&nbsp;...</li>";
720 }
721
722 print "</ul>";
a283b8d1 723
ef8be8ea 724 print "</div>";
0ea4fb50 725
ef8be8ea
AD
726 print "<div align='center'>
727 <input type='submit' class='button'
728 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
0ea4fb50 729
ef8be8ea 730// print "</body></html>";
0ea4fb50 731
ef8be8ea 732 }
ad815c71 733
ef8be8ea 734 if ($op == "pref-feed-browser") {
f27d955a 735 module_pref_feed_browser($link);
c6232e43
AD
736 }
737
18664970
AD
738 if ($op == "rss") {
739 $feed = db_escape_string($_GET["id"]);
740 $user = db_escape_string($_GET["user"]);
741 $pass = db_escape_string($_GET["pass"]);
742 $is_cat = $_GET["is_cat"] != false;
743
e1eb2147
AD
744 $search = db_escape_string($_GET["q"]);
745 $match_on = db_escape_string($_GET["m"]);
746 $search_mode = db_escape_string($_GET["smode"]);
747
18664970
AD
748 if (!$_SESSION["uid"] && $user && $pass) {
749 authenticate_user($link, $user, $pass);
750 }
751
752 if ($_SESSION["uid"] ||
753 http_authenticate_user($link)) {
754
e1eb2147
AD
755 generate_syndicated_feed($link, $feed, $is_cat,
756 $search, $search_mode, $match_on);
18664970
AD
757 }
758 }
759
88040f57
AD
760 if ($op == "labelFromSearch") {
761 $search = db_escape_string($_GET["search"]);
762 $search_mode = db_escape_string($_GET["smode"]);
763 $match_on = db_escape_string($_GET["match"]);
764 $is_cat = db_escape_string($_GET["is_cat"]);
765 $title = db_escape_string($_GET["title"]);
766 $feed = sprintf("%d", $_GET["feed"]);
767
768 $label_qparts = array();
769
770 $search_expr = getSearchSql($search, $match_on);
771
772 if ($is_cat) {
773 if ($feed != 0) {
774 $search_expr .= " AND ttrss_feeds.cat_id = $feed ";
775 } else {
776 $search_expr .= " AND ttrss_feeds.cat_id IS NULL ";
777 }
778 } else {
779 if ($search_mode == "all_feeds") {
780 // NOOP
781 } else if ($search_mode == "this_cat") {
782
783 $tmp_result = db_query($link, "SELECT cat_id
784 FROM ttrss_feeds WHERE id = '$feed'");
785
786 $cat_id = db_fetch_result($tmp_result, 0, "cat_id");
787
788 if ($cat_id > 0) {
789 $search_expr .= " AND ttrss_feeds.cat_id = $cat_id ";
790 } else {
791 $search_expr .= " AND ttrss_feeds.cat_id IS NULL ";
792 }
793 } else {
794 $search_expr .= " AND ttrss_feeds.id = $feed ";
795 }
796
797 }
798
799 $search_expr = db_escape_string($search_expr);
800
801 print $search_expr;
802
803 if ($title) {
804 $result = db_query($link,
805 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
806 VALUES ('$search_expr', '$title', '".$_SESSION["uid"]."')");
807 }
808 }
809
f3acc32e
AD
810 if ($op == "getUnread") {
811 $login = db_escape_string($_GET["login"]);
812
7e3634d9 813 header("Content-Type: text/plain; charset=utf-8");
f3acc32e
AD
814
815 $result = db_query($link, "SELECT id FROM ttrss_users WHERE login = '$login'");
816
817 if (db_num_rows($result) == 1) {
818 $uid = db_fetch_result($result, 0, "id");
819 print getGlobalUnread($link, $uid);
820 } else {
0599d09e 821 print "-1;User not found";
f3acc32e 822 }
7e3634d9
AD
823
824 $print_exec_time = false;
825 }
826
827 if ($op == "digestTest") {
828 header("Content-Type: text/plain");
9cd7c995
AD
829 print_r(prepare_headlines_digest($link, $_SESSION["uid"]));
830 $print_exec_time = false;
831
832 }
448b0abd 833
9cd7c995
AD
834 if ($op == "digestSend") {
835 header("Content-Type: text/plain");
836 send_headlines_digests($link);
7e3634d9
AD
837 $print_exec_time = false;
838
f3acc32e
AD
839 }
840
4b3dff6e 841 db_close($link);
1cd17194 842?>
406d9489 843
7e3634d9 844<?php if ($print_exec_time) { ?>
1d3a17c7 845<!-- <?php echo sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->
f3acc32e 846<?php } ?>