]> git.wh0rd.org - tt-rss.git/blame - backend.php
misc headlines view tweaks
[tt-rss.git] / backend.php
CommitLineData
1cd17194 1<?
4356293a 2 session_start();
090e250b 3
cce28758
AD
4 if ($_GET["debug"]) {
5 define('DEFAULT_ERROR_LEVEL', E_ALL);
6 } else {
7 define('DEFAULT_ERROR_LEVEL', E_ERROR | E_WARNING | E_PARSE);
8 }
9
10 error_reporting(DEFAULT_ERROR_LEVEL);
11
262bd8ea
AD
12 $op = $_REQUEST["op"];
13
a2770077 14 if ((!$op || $op == "rpc" || $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
262bd8ea
AD
15 header("Content-Type: application/xml");
16 }
17
a2770077 18 if (!$_SESSION["uid"] && $op != "globalUpdateFeeds") {
262bd8ea 19
a2770077 20 if ($op == "rpc") {
262bd8ea
AD
21 print "<error error-code=\"6\"/>";
22 }
23 exit;
24 }
1c7f75ed 25
a2770077
AD
26 if (!$op) {
27 print "<error error-code=\"7\"/>";
28 exit;
29 }
30
cce28758 31 define('SCHEMA_VERSION', 2);
1cd17194 32
66581886 33 require_once "sanity_check.php";
82baad4a 34 require_once "config.php";
648472a7 35 require_once "db.php";
3bac89ad 36 require_once "db-prefs.php";
82baad4a
AD
37 require_once "functions.php";
38 require_once "magpierss/rss_fetch.inc";
1cd17194 39
406d9489
AD
40 $script_started = getmicrotime();
41
648472a7 42 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
d76a3b03 43
5136011e
AD
44 if (!$link) {
45 if (DB_TYPE == "mysql") {
46 print mysql_error();
47 }
48 // PG seems to display its own errors just fine by default.
49 return;
50 }
51
648472a7
AD
52 if (DB_TYPE == "pgsql") {
53 pg_query("set client_encoding = 'utf-8'");
54 }
7ec2a838 55
331900c6 56 $fetch = $_GET["fetch"];
175847de 57
1572afe5
AD
58 function getAllCounters($link) {
59 getLabelCounters($link);
60 getFeedCounters($link);
61 getTagCounters($link);
62 getGlobalCounters($link);
63 }
64
8143ae1f
AD
65 /* FIXME this needs reworking */
66
fc69e641 67 function getGlobalCounters($link) {
4c193675
AD
68 $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries,ttrss_user_entries
69 WHERE unread = true AND
70 ttrss_user_entries.ref_id = ttrss_entries.id AND
71 owner_uid = " . $_SESSION["uid"]);
fc69e641
AD
72 $c_id = db_fetch_result($result, 0, "c_id");
73 print "<counter id='global-unread' counter='$c_id'/>";
74 }
75
8143ae1f 76 function getTagCounters($link) {
05732aa0 77
8143ae1f 78 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
4c193675
AD
79 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
80 ttrss_user_entries.ref_id = ttrss_entries.id AND
4356293a 81 ttrss_tags.owner_uid = ".$_SESSION["uid"]." AND
05732aa0 82 post_int_id = ttrss_user_entries.int_id AND unread = true GROUP BY tag_name
8143ae1f 83 UNION
4356293a
AD
84 select tag_name,0 as count FROM ttrss_tags
85 WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]);
8143ae1f
AD
86
87 $tags = array();
88
89 while ($line = db_fetch_assoc($result)) {
90 $tags[$line["tag_name"]] += $line["count"];
91 }
92
93 foreach (array_keys($tags) as $tag) {
94 $unread = $tags[$tag];
95
96 $tag = htmlspecialchars($tag);
97 print "<tag id=\"$tag\" counter=\"$unread\"/>";
98 }
99 }
100
090e250b
AD
101 function getLabelCounters($link) {
102
4c193675
AD
103 $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries
104 WHERE marked = true AND ttrss_user_entries.ref_id = ttrss_entries.id AND
105 unread = true AND owner_uid = ".$_SESSION["uid"]);
090e250b 106
d61fd764 107 $count = db_fetch_result($result, 0, "count");
090e250b
AD
108
109 print "<label id=\"-1\" counter=\"$count\"/>";
110
4356293a
AD
111 $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM
112 ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description");
090e250b
AD
113
114 while ($line = db_fetch_assoc($result)) {
115
116 $id = -$line["id"] - 11;
117
118 error_reporting (0);
d61fd764 119
4c193675 120 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_user_entries,ttrss_entries
655be073 121 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
4c193675 122 ttrss_user_entries.ref_id = ttrss_entries.id AND
655be073 123 owner_uid = ".$_SESSION["uid"]);
090e250b 124
d61fd764 125 $count = db_fetch_result($tmp_result, 0, "count");
090e250b 126
ab3f3f72 127 print "<label id=\"$id\" counter=\"$count\"/>";
090e250b 128
cce28758 129 error_reporting (DEFAULT_ERROR_LEVEL);
090e250b
AD
130
131 }
132 }
133
8073cce7
AD
134 function getFeedCounter($link, $id) {
135
136 $result = db_query($link, "SELECT
4c193675
AD
137 count(id) as count FROM ttrss_entries,ttrss_user_entries
138 WHERE feed_id = '$id' AND unread = true
139 AND ttrss_user_entries.ref_id = ttrss_entries.id");
8073cce7
AD
140
141 $count = db_fetch_result($result, 0, "count");
142
143 print "<feed id=\"$id\" counter=\"$count\"/>";
144 }
090e250b 145
8073cce7
AD
146 function getFeedCounters($link) {
147
090e250b 148 $result = db_query($link, "SELECT id,
4c193675
AD
149 (SELECT count(id)
150 FROM ttrss_entries,ttrss_user_entries
151 WHERE feed_id = ttrss_feeds.id AND ttrss_user_entries.ref_id = ttrss_entries.id
b88917af 152 AND unread = true AND owner_uid = ".$_SESSION["uid"].") as count
4356293a 153 FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"]);
090e250b
AD
154
155 while ($line = db_fetch_assoc($result)) {
156
157 $id = $line["id"];
158 $count = $line["count"];
159
160 print "<feed id=\"$id\" counter=\"$count\"/>";
161 }
162 }
163
8143ae1f 164 function outputFeedList($link, $tags = false) {
175847de 165
1a66d16e
AD
166 print "<html><head>
167 <title>Tiny Tiny RSS : Feedlist</title>
430bf183
AD
168 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
169
503eb349
AD
170 $user_theme = $_SESSION["theme"];
171 if ($user_theme) {
172 print "<link rel=\"stylesheet\" type=\"text/css\"
173 href=\"themes/$user_theme/theme.css\">";
174 }
175
4769ddaf 176 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
430bf183
AD
177 print "<link rel=\"stylesheet\" type=\"text/css\"
178 href=\"tt-rss_compact.css\"/>";
179 } else {
180 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
181 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
182 }
183
184 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
1a66d16e
AD
185 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
186 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
3745788e 187 </head><body onload=\"init()\">";
254e0e4b
AD
188
189 print "<ul class=\"feedList\" id=\"feedList\">";
190
4356293a
AD
191 $owner_uid = $_SESSION["uid"];
192
8143ae1f 193 if (!$tags) {
254e0e4b 194
8143ae1f 195 /* virtual feeds */
254e0e4b 196
91ff844a
AD
197 if (get_pref($link, 'ENABLE_FEED_CATS')) {
198 print "<li class=\"feedCat\">Special</li>";
703b632e 199 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
91ff844a
AD
200 }
201
8143ae1f 202 $result = db_query($link, "SELECT count(id) as num_starred
4c193675
AD
203 FROM ttrss_entries,ttrss_user_entries
204 WHERE marked = true AND
205 ttrss_user_entries.ref_id = ttrss_entries.id AND
206 unread = true AND owner_uid = '$owner_uid'");
8143ae1f 207 $num_starred = db_fetch_result($result, 0, "num_starred");
254e0e4b 208
3745788e 209 $class = "virt";
8add756a
AD
210
211 if ($num_starred > 0) $class .= "Unread";
212
213 printFeedEntry(-1, $class, "Starred articles", $num_starred,
4668523d 214 "images/mark_set.png", $link);
48f0adb0 215
91ff844a 216 if (get_pref($link, 'ENABLE_FEED_CATS')) {
703b632e 217 print "</li></ul>";
91ff844a
AD
218 }
219
4769ddaf 220 if (get_pref($link, 'ENABLE_LABELS')) {
8143ae1f
AD
221
222 $result = db_query($link, "SELECT id,sql_exp,description FROM
4356293a 223 ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
8143ae1f
AD
224
225 if (db_num_rows($result) > 0) {
91ff844a
AD
226 if (get_pref($link, 'ENABLE_FEED_CATS')) {
227 print "<li class=\"feedCat\">Labels</li>";
703b632e 228 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
91ff844a
AD
229 } else {
230 print "<li><hr></li>";
231 }
8143ae1f
AD
232 }
233
234 while ($line = db_fetch_assoc($result)) {
48f0adb0 235
8143ae1f
AD
236 error_reporting (0);
237
4c193675
AD
238 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries
239 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
240 ttrss_user_entries.ref_id = ttrss_entries.id
655be073 241 AND owner_uid = '$owner_uid'");
8143ae1f
AD
242
243 $count = db_fetch_result($tmp_result, 0, "count");
244
3745788e 245 $class = "label";
8143ae1f
AD
246
247 if ($count > 0) {
248 $class .= "Unread";
249 }
250
cce28758 251 error_reporting (DEFAULT_ERROR_LEVEL);
8143ae1f
AD
252
253 printFeedEntry(-$line["id"]-11,
4668523d 254 $class, $line["description"], $count, "images/label.png", $link);
8143ae1f
AD
255
256 }
91ff844a
AD
257
258 if (db_num_rows($result) > 0) {
259 if (get_pref($link, 'ENABLE_FEED_CATS')) {
703b632e 260 print "</li></ul>";
91ff844a
AD
261 }
262 }
263
264 }
265
266// if (!get_pref($link, 'ENABLE_FEED_CATS')) {
267 print "<li><hr></li>";
268// }
269
270 if (get_pref($link, 'ENABLE_FEED_CATS')) {
271 $order_by_qpart = "category,title";
272 } else {
273 $order_by_qpart = "title";
48f0adb0 274 }
8143ae1f
AD
275
276 $result = db_query($link, "SELECT *,
4c193675
AD
277 (SELECT count(id) FROM ttrss_entries,ttrss_user_entries
278 WHERE feed_id = ttrss_feeds.id AND
279 ttrss_user_entries.ref_id = ttrss_entries.id AND
280 owner_uid = '$owner_uid') AS total,
281 (SELECT count(id) FROM ttrss_entries,ttrss_user_entries
b88917af 282 WHERE feed_id = ttrss_feeds.id AND unread = true
4c193675 283 AND ttrss_user_entries.ref_id = ttrss_entries.id
91ff844a
AD
284 AND owner_uid = '$owner_uid') as unread,
285 (SELECT title FROM ttrss_feed_categories
286 WHERE id = cat_id) AS category
287 FROM ttrss_feeds WHERE owner_uid = '$owner_uid' ORDER BY $order_by_qpart");
8143ae1f
AD
288
289 $actid = $_GET["actid"];
290
291 /* real feeds */
292
293 $lnum = 0;
294
295 $total_unread = 0;
91ff844a
AD
296
297 $category = "";
8143ae1f 298
48f0adb0 299 while ($line = db_fetch_assoc($result)) {
8143ae1f
AD
300
301 $feed = $line["title"];
302 $feed_id = $line["id"];
303
304 $subop = $_GET["subop"];
305
306 $total = $line["total"];
307 $unread = $line["unread"];
91ff844a
AD
308
309 $tmp_category = $line["category"];
310
311 if (!$tmp_category) {
312 $tmp_category = "Uncategorized";
313 }
8143ae1f
AD
314
315 // $class = ($lnum % 2) ? "even" : "odd";
48f0adb0 316
3745788e 317 $class = "feed";
8143ae1f
AD
318
319 if ($unread > 0) $class .= "Unread";
320
321 if ($actid == $feed_id) {
322 $class .= "Selected";
392d4563 323 }
48f0adb0 324
8143ae1f 325 $total_unread += $unread;
91ff844a
AD
326
327 if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) {
328
329 if ($category) {
330 print "</li></ul></li>";
331 }
332
333 $category = $tmp_category;
334
335 print "<li class=\"feedCat\">$category</li>";
703b632e 336 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
91ff844a 337 }
8143ae1f 338
91ff844a
AD
339 printFeedEntry($feed_id, $class, $feed, $unread,
340 "icons/$feed_id.ico", $link);
8143ae1f
AD
341
342 ++$lnum;
48f0adb0 343 }
91ff844a 344
8143ae1f 345 } else {
a1a8a2be 346
8143ae1f 347 // tags
a1a8a2be 348
8143ae1f 349 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
05732aa0
AD
350 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
351 post_int_id = ttrss_user_entries.int_id AND
352 unread = true AND ref_id = ttrss_entries.id
3b0948c4 353 AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name
8143ae1f 354 UNION
3b0948c4
AD
355 select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid'
356 ORDER BY tag_name");
8143ae1f
AD
357
358 $tags = array();
359
360 while ($line = db_fetch_assoc($result)) {
361 $tags[$line["tag_name"]] += $line["count"];
1a66d16e 362 }
8143ae1f
AD
363
364 foreach (array_keys($tags) as $tag) {
365
366 $unread = $tags[$tag];
367
83957936 368 $class = "tag";
8143ae1f
AD
369
370 if ($unread > 0) {
371 $class .= "Unread";
372 }
373
4668523d 374 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link);
8143ae1f
AD
375
376 }
1a66d16e 377
e828e31e 378 }
82baad4a 379
dc33ec95 380 if (db_num_rows($result) == 0) {
8037c618
AD
381 if ($tags) {
382 $what = "tags";
383 } else {
384 $what = "feeds";
385 }
386 print "<li>No $what to display.</li>";
dc33ec95
AD
387 }
388
8143ae1f 389 print "</ul>";
1cd17194 390
caa4e57f
AD
391 print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
392
c3b81db0
AD
393 }
394
395
396 if ($op == "rpc") {
397
398 $subop = $_GET["subop"];
399
090e250b 400 if ($subop == "getLabelCounters") {
8073cce7 401 $aid = $_GET["aid"];
090e250b
AD
402 print "<rpc-reply>";
403 getLabelCounters($link);
8073cce7
AD
404 if ($aid) {
405 getFeedCounter($link, $aid);
406 }
090e250b
AD
407 print "</rpc-reply>";
408 }
409
410 if ($subop == "getFeedCounters") {
411 print "<rpc-reply>";
412 getFeedCounters($link);
413 print "</rpc-reply>";
414 }
415
416 if ($subop == "getAllCounters") {
417 print "<rpc-reply>";
1572afe5 418 getAllCounters($link);
090e250b 419 print "</rpc-reply>";
090e250b
AD
420 }
421
f4c10d44
AD
422 if ($subop == "mark") {
423 $mark = $_GET["mark"];
648472a7 424 $id = db_escape_string($_GET["id"]);
f4c10d44
AD
425
426 if ($mark == "1") {
427 $mark = "true";
428 } else {
429 $mark = "false";
430 }
431
b5137506
AD
432 // FIXME this needs collision testing
433
434 $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark
435 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
f4c10d44
AD
436 }
437
caa4e57f 438 if ($subop == "updateFeed") {
648472a7 439 $feed_id = db_escape_string($_GET["feed"]);
9cfc649a 440
648472a7 441 $result = db_query($link,
a5873b2e
AD
442 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'
443 AND owner_uid = " . $_SESSION["uid"]);
9cfc649a 444
648472a7
AD
445 if (db_num_rows($result) > 0) {
446 $feed_url = db_fetch_result($result, 0, "feed_url");
a5873b2e 447 update_rss_feed($link, $feed_url, $feed_id);
caa4e57f 448 }
9cfc649a 449
a5873b2e
AD
450 print "<rpc-reply>";
451 getFeedCounter($link, $feed_id);
452 print "</rpc-reply>";
453
caa4e57f 454 return;
9cfc649a
AD
455 }
456
090e250b 457 if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") {
c5142cca 458
05732aa0 459 update_all_feeds($link, $subop == "forceUpdateAllFeeds");
c3b81db0 460
ab3f3f72
AD
461 $omode = $_GET["omode"];
462
463 if (!$omode) $omode = "tfl";
464
090e250b 465 print "<rpc-reply>";
ab3f3f72
AD
466 if (strchr($omode, "l")) getLabelCounters($link);
467 if (strchr($omode, "f")) getFeedCounters($link);
468 if (strchr($omode, "t")) getTagCounters($link);
fc69e641 469 getGlobalCounters($link);
090e250b 470 print "</rpc-reply>";
c3b81db0 471 }
1572afe5
AD
472
473 /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
b018b49b 474 if ($subop == "catchupSelected") {
c3b81db0
AD
475
476 $ids = split(",", $_GET["ids"]);
477
1572afe5 478 $cmode = sprintf("%d", $_GET["cmode"]);
c3b81db0 479
1572afe5 480 foreach ($ids as $id) {
c3b81db0 481
1572afe5
AD
482 if ($cmode == 0) {
483 db_query($link, "UPDATE ttrss_user_entries SET
484 unread = false,last_read = NOW()
485 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
486 } else if ($cmode == 1) {
487 db_query($link, "UPDATE ttrss_user_entries SET
488 unread = true
489 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
490 } else {
491 db_query($link, "UPDATE ttrss_user_entries SET
492 unread = NOT unread,last_read = NOW()
493 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
494 }
c3b81db0 495 }
1572afe5
AD
496 print "<rpc-reply>";
497 getAllCounters($link);
498 print "</rpc-reply>";
499 }
c3b81db0 500
1572afe5
AD
501 if ($subop == "markSelected") {
502
503 $ids = split(",", $_GET["ids"]);
504
505 $cmode = sprintf("%d", $_GET["cmode"]);
506
507 foreach ($ids as $id) {
508
509 if ($cmode == 0) {
510 db_query($link, "UPDATE ttrss_user_entries SET
511 marked = false
512 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
513 } else if ($cmode == 1) {
514 db_query($link, "UPDATE ttrss_user_entries SET
515 marked = true
516 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
517 } else {
518 db_query($link, "UPDATE ttrss_user_entries SET
519 marked = NOT marked
520 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
521 }
522 }
523 print "<rpc-reply>";
524 getAllCounters($link);
525 print "</rpc-reply>";
c3b81db0 526 }
295f9b42
AD
527
528 if ($subop == "sanityCheck") {
529
530 $error_code = 0;
531
532 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
533
534 $schema_version = db_fetch_result($result, 0, "schema_version");
535
536 if ($schema_version != SCHEMA_VERSION) {
537 $error_code = 5;
538 }
539
262bd8ea 540 print "<error error-code='$error_code'/>";
295f9b42 541 }
fefa6ca3
AD
542
543 if ($subop == "globalPurge") {
544
545 print "<rpc-reply>";
546 global_purge_old_posts($link, true);
547 print "</rpc-reply>";
548
549 }
550
c3b81db0
AD
551 }
552
553 if ($op == "feeds") {
554
8143ae1f
AD
555 $tags = $_GET["tags"];
556
c3b81db0
AD
557 $subop = $_GET["subop"];
558
559 if ($subop == "catchupAll") {
b018b49b 560 db_query($link, "UPDATE ttrss_user_entries SET
6d15e1ef 561 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
c3b81db0
AD
562 }
563
8143ae1f 564 outputFeedList($link, $tags);
c3b81db0 565
1cd17194
AD
566 }
567
568 if ($op == "view") {
569
d76a3b03 570 $id = $_GET["id"];
8073cce7 571 $feed_id = $_GET["feed"];
d76a3b03 572
4c193675
AD
573 $result = db_query($link, "UPDATE ttrss_user_entries
574 SET unread = false,last_read = NOW()
575 WHERE ref_id = '$id' AND feed_id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
a1a8a2be 576
70830c87
AD
577 $addheader = $_GET["addheader"];
578
21703604 579 $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
9167e250 580 SUBSTRING(updated,1,16) as updated,
21703604 581 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url
4c193675
AD
582 FROM ttrss_entries,ttrss_user_entries
583 WHERE id = '$id' AND ref_id = id");
1cd17194 584
70830c87 585 if ($addheader) {
f0601b87 586 print "<html><head>
70830c87 587 <title>Tiny Tiny RSS : Article $id</title>
503eb349
AD
588 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
589
590 $user_theme = $_SESSION["theme"];
591 if ($user_theme) {
592 print "<link rel=\"stylesheet\" type=\"text/css\"
593 href=\"themes/$user_theme/theme.css\">";
594 }
595
596 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
597 print "<link rel=\"stylesheet\" type=\"text/css\"
598 href=\"tt-rss_compact.css\"/>";
599 } else {
600 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
601 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
602 }
603
604 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
70830c87 605 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
f0601b87 606 </head><body>";
70830c87
AD
607 }
608
d76a3b03 609 if ($result) {
1cd17194 610
648472a7 611 $line = db_fetch_assoc($result);
1cd17194 612
b7f4bda2
AD
613 if ($line["icon_url"]) {
614 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
615 } else {
616 $feed_icon = "&nbsp;";
617 }
d76a3b03 618
f7181e9b
AD
619 if ($line["comments"] && $line["link"] != $line["comments"]) {
620 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
621 } else {
622 $entry_comments = "";
623 }
624
e828e31e
AD
625 print "<div class=\"postReply\">";
626
21703604
AD
627 print "<div class=\"postHeader\"><table width=\"100%\">";
628
9167e250
AD
629 print "<tr><td>" . $line["title"] . "</td>";
630
631 $parsed_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
632 strtotime($line["updated"]));
633
634 print "<td class=\"postDate\">$parsed_updated</td>";
635
636 print "</tr>";
21703604
AD
637
638 $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM
639 ttrss_tags WHERE post_int_id = " . $line["int_id"] . "
640 ORDER BY tag_name");
641
642 $tags_str = "";
643
644 while ($tmp_line = db_fetch_assoc($tmp_result)) {
645 $tag = $tmp_line["tag_name"];
b400ca77 646 $tags_str .= "<a href=\"javascript:parent.viewfeed('$tag')\">$tag</a>, ";
21703604
AD
647 }
648
b400ca77 649 $tags_str = preg_replace("/, $/", "", $tags_str);
e828e31e 650
b400ca77 651 print "<tr><td width='50%'>
f7181e9b 652 <a href=\"" . $line["link"] . "\">".$line["link"]."</a>
21703604
AD
653 $entry_comments</td>
654 <td align=\"right\">$tags_str</td></tr>";
655
656/* if ($tags_str) {
657 print "<tr><td><b>Tags:</b></td>
658 <td width='100%'>$tags_str</td></tr>";
659 } */
660
e828e31e
AD
661 print "</table></div>";
662
663 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
664 print "<div class=\"postContent\">" . $line["content"] . "</div>";
665
666 print "</div>";
667
090e250b 668 print "<script type=\"text/javascript\">
4f3a84f4 669 update_all_counters('$feed_id');
090e250b 670 </script>";
d76a3b03 671 }
70830c87
AD
672
673 if ($addheader) {
674 print "</body></html>";
675 }
1cd17194
AD
676 }
677
678 if ($op == "viewfeed") {
679
680 $feed = $_GET["feed"];
d76a3b03 681 $skip = $_GET["skip"];
476cac42 682 $subop = $_GET["subop"];
f175937c 683 $view_mode = $_GET["view"];
f0601b87 684 $addheader = $_GET["addheader"];
cb1083a1 685 $limit = $_GET["limit"];
a1a8a2be 686
8d7008c7 687 if (!$feed) {
8d7008c7
AD
688 return;
689 }
690
ac53063a
AD
691 if (!$skip) $skip = 0;
692
476cac42 693 if ($subop == "undefined") $subop = "";
1cd17194 694
f0601b87
AD
695 if ($addheader) {
696 print "<html><head>
ac43eba1 697 <title>Tiny Tiny RSS : Feed $feed</title>
430bf183
AD
698 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
699
503eb349
AD
700 $user_theme = $_SESSION["theme"];
701 if ($user_theme) {
702 print "<link rel=\"stylesheet\" type=\"text/css\"
703 href=\"themes/$user_theme/theme.css\">";
704 }
705
4769ddaf 706 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
430bf183
AD
707 print "<link rel=\"stylesheet\"
708 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
709
710 } else {
711 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
712 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
713 }
503eb349 714
430bf183 715 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
f0601b87
AD
716 <script type=\"text/javascript\" src=\"functions.js\"></script>
717 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
b623b3ed 718 </head><body onload='init()'>";
f0601b87
AD
719 }
720
dcee8f61
AD
721 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
722
723 $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
724 WHERE id = '$feed'");
725
726 $feed_url = db_fetch_result($tmp_result, 0, "feed_url");
727
728 update_rss_feed($link, $feed_url, $feed);
729
730 }
731
0e32076b 732 if ($subop == "MarkAllRead") {
d76a3b03 733
0e32076b
AD
734 if (sprintf("%d", $feed) != 0) {
735
736 if ($feed > 0) {
f23a2177 737 db_query($link, "UPDATE ttrss_user_entries
0e32076b 738 SET unread = false,last_read = NOW()
f23a2177 739 WHERE feed_id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
0e32076b
AD
740
741 } else if ($feed < 0 && $feed > -10) { // special, like starred
742
743 if ($feed == -1) {
f23a2177 744 db_query($link, "UPDATE ttrss_user_entries
0e32076b 745 SET unread = false,last_read = NOW()
5859be02 746 WHERE marked = true AND owner_uid = ".$_SESSION["uid"]);
0e32076b
AD
747 }
748
749 } else if ($feed < -10) { // label
750
f23a2177
AD
751 // TODO make this more efficient
752
7db95187 753 $label_id = -$feed - 11;
0e32076b 754
7db95187 755 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
f23a2177 756 WHERE id = '$label_id'");
7db95187
AD
757
758 if ($tmp_result) {
759 $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp");
760
f23a2177
AD
761 db_query($link, "BEGIN");
762
763 $tmp2_result = db_query($link,
764 "SELECT
765 int_id
766 FROM
767 ttrss_user_entries,ttrss_entries
768 WHERE
769 ref_id = id AND
770 $sql_exp AND
771 owner_uid = " . $_SESSION["uid"]);
772
773 while ($tmp_line = db_fetch_assoc($tmp2_result)) {
774 db_query($link, "UPDATE
775 ttrss_user_entries
776 SET
777 unread = false, last_read = NOW()
778 WHERE
779 int_id = " . $tmp_line["int_id"]);
780 }
781
782 db_query($link, "COMMIT");
783
784/* db_query($link, "UPDATE ttrss_user_entries,ttrss_entries
7db95187 785 SET unread = false,last_read = NOW()
f23a2177
AD
786 WHERE $sql_exp
787 AND ref_id = id
788 AND owner_uid = ".$_SESSION["uid"]); */
7db95187 789 }
254e0e4b 790 }
0e32076b 791 } else { // tag
7eec90cf
AD
792 db_query($link, "BEGIN");
793
794 $tag_name = db_escape_string($feed);
795
796 $result = db_query($link, "SELECT post_int_id FROM ttrss_tags
797 WHERE tag_name = '$tag_name' AND owner_uid = " . $_SESSION["uid"]);
798
799 while ($line = db_fetch_assoc($result)) {
800 db_query($link, "UPDATE ttrss_user_entries SET
801 unread = false, last_read = NOW()
802 WHERE int_id = " . $line["post_int_id"]);
803 }
804 db_query($link, "COMMIT");
a1a8a2be 805 }
0e32076b 806
a1a8a2be 807 }
d76a3b03 808
c374a3fe
AD
809 $search = $_GET["search"];
810
52b51244
AD
811 $search_mode = $_GET["smode"];
812
f175937c 813 if ($search) {
ac53063a
AD
814 $search_query_part = "(upper(title) LIKE upper('%$search%')
815 OR content LIKE '%$search%') AND";
f175937c
AD
816 } else {
817 $search_query_part = "";
818 }
819
820 $view_query_part = "";
821
822 if ($view_mode == "Starred") {
823 $view_query_part = " marked = true AND ";
ac53063a
AD
824 }
825
ac43eba1
AD
826 if ($view_mode == "Unread") {
827 $view_query_part = " unread = true AND ";
828 }
829
b5aa95e7
AD
830 if ($view_mode == "Unread or Starred") {
831 $view_query_part = " (unread = true OR marked = true) AND ";
832 }
833
bdd01d3f
AD
834 if ($view_mode == "Unread or Updated") {
835 $view_query_part = " (unread = true OR last_read is NULL) AND ";
836 }
837
254e0e4b 838/* $result = db_query($link, "SELECT count(id) AS total_entries
36bf7496
AD
839 FROM ttrss_entries WHERE
840 $search_query_part
841 feed_id = '$feed'");
e6d1c0a0 842
254e0e4b 843 $total_entries = db_fetch_result($result, 0, "total_entries"); */
e6d1c0a0 844
648472a7 845/* $result = db_query("SELECT count(id) AS unread_entries
ac43eba1
AD
846 FROM ttrss_entries WHERE
847 $search_query_part
848 unread = true AND
849 feed_id = '$feed'");
850
648472a7 851 $unread_entries = db_fetch_result($result, 0, "unread_entries"); */
ac43eba1 852
8d7008c7 853 if ($limit && $limit != "All") {
82c9223c 854 $limit_query_part = "LIMIT " . $limit;
ad3cb710 855 }
f0601b87 856
254e0e4b
AD
857 $vfeed_query_part = "";
858
52b51244 859 // override query strategy and enable feed display when searching globally
d3416913 860 if ($search && $search_mode == "All feeds") {
52b51244
AD
861 $query_strategy_part = "id > 0";
862 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
863 id = feed_id) as feed_title,";
864 } else if (sprintf("%d", $feed) == 0) {
8143ae1f
AD
865 $query_strategy_part = "ttrss_entries.id > 0";
866 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
867 id = feed_id) as feed_title,";
868 } else if ($feed >= 0) {
254e0e4b 869 $query_strategy_part = "feed_id = '$feed'";
48f0adb0 870 } else if ($feed == -1) { // starred virtual feed
254e0e4b 871 $query_strategy_part = "marked = true";
48f0adb0
AD
872 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
873 id = feed_id) as feed_title,";
874 } else if ($feed <= -10) { // labels
875 $label_id = -$feed - 11;
876
877 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
878 WHERE id = '$label_id'");
879
880 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
881
254e0e4b
AD
882 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
883 id = feed_id) as feed_title,";
884 } else {
48f0adb0 885 $query_strategy_part = "id > 0"; // dumb
254e0e4b
AD
886 }
887
f99321a3
AD
888 $order_by = "updated DESC";
889
890// if ($feed < -10) {
891// $order_by = "feed_id,updated DESC";
892// }
893
1572afe5
AD
894 $feed_title = "";
895
896 if ($search && $search_mode == "All feeds") {
897 $feed_title = "Search results";
898 } else if (sprintf("%d", $feed) == 0) {
899 $feed_title = $feed;
900 } else if ($feed > 0) {
901 $result = db_query($link, "SELECT title,site_url FROM ttrss_feeds
902 WHERE id = '$feed'");
903
904 $feed_title = db_fetch_result($result, 0, "title");
905 $feed_site_url = db_fetch_result($result, 0, "site_url");
906
907 } else if ($feed == -1) {
908 $feed_title = "Starred articles";
909 } else if ($feed < -10) {
910 $label_id = -$feed - 11;
911 $result = db_query($link, "SELECT description FROM ttrss_labels
912 WHERE id = '$label_id'");
913 $feed_title = db_fetch_result($result, 0, "description");
914 } else {
915 $feed_title = "?";
916 }
917
48f0adb0
AD
918 if ($feed < -10) error_reporting (0);
919
8143ae1f
AD
920 if (sprintf("%d", $feed) != 0) {
921
21703604
AD
922 if ($feed > 0) {
923 $feed_kind = "Feeds";
924 } else {
925 $feed_kind = "Labels";
926 }
927
bd34c528
AD
928 if (!$vfeed_query_part) {
929 $content_query_part = "content as content_preview,";
930 } else {
931 $content_query_part = "";
932 }
933
8143ae1f 934 $result = db_query($link, "SELECT
1572afe5
AD
935 id,title,
936 SUBSTRING(updated,1,16) as updated,
937 unread,feed_id,marked,link,last_read,
8143ae1f
AD
938 SUBSTRING(last_read,1,19) as last_read_noms,
939 $vfeed_query_part
bd34c528
AD
940 $content_query_part
941 SUBSTRING(updated,1,19) as updated_noms
8143ae1f 942 FROM
4c193675 943 ttrss_entries,ttrss_user_entries
8143ae1f 944 WHERE
4c193675 945 ttrss_user_entries.ref_id = ttrss_entries.id AND
aee86c2e 946 owner_uid = '".$_SESSION["uid"]."' AND
8143ae1f
AD
947 $search_query_part
948 $view_query_part
949 $query_strategy_part ORDER BY $order_by
950 $limit_query_part");
951
952 } else {
953 // browsing by tag
954
21703604
AD
955 $feed_kind = "Tags";
956
8143ae1f 957 $result = db_query($link, "SELECT
1572afe5
AD
958 ttrss_entries.id as id,title,
959 SUBSTRING(updated,1,16) as updated,
960 unread,feed_id,
8143ae1f 961 marked,link,last_read,
c05a19f3 962 SUBSTRING(last_read,1,19) as last_read_noms,
254e0e4b 963 $vfeed_query_part
bd34c528
AD
964 $content_query_part
965 SUBSTRING(updated,1,19) as updated_noms
8143ae1f 966 FROM
05732aa0 967 ttrss_entries,ttrss_user_entries,ttrss_tags
8143ae1f 968 WHERE
05732aa0
AD
969 ref_id = ttrss_entries.id AND
970 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
971 post_int_id = int_id AND tag_name = '$feed' AND
8143ae1f
AD
972 $view_query_part
973 $search_query_part
974 $query_strategy_part ORDER BY $order_by
975 $limit_query_part");
976 }
d76a3b03 977
48f0adb0 978 if (!$result) {
f56ec297
AD
979 print "<div align='center'>
980 Could not display feed (query failed). Please check match syntax or local configuration.</div>";
48f0adb0
AD
981 return;
982 }
983
f56ec297
AD
984 if (db_num_rows($result) > 0) {
985
e5a99b88
AD
986 print "<table class=\"headlinesSubToolbar\"
987 width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
988
989 print "<td class=\"headlineActions\">
990 Select:
991 <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList',
992 'RROW-', 'RCHK-', true)\">All</a>,
993 <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList',
994 'RROW-', 'RCHK-', true, 'Unread')\">Unread</a>,
995 <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList',
996 'RROW-', 'RCHK-', false)\">None</a>
997 &nbsp;&nbsp;
998 Toggle: <a href=\"javascript:toggleUnread()\">Unread</a>,
999 <a href=\"javascript:toggleStarred()\">Starred</a>";
1000
1001 print "</td>";
1002
1003 print "<td class=\"headlineTitle\">";
1004
1005 if ($feed_site_url) {
1006 print "<a target=\"_blank\" href=\"$feed_site_url\">$feed_title</a>";
f4c10d44 1007 } else {
e5a99b88 1008 print $feed_title;
f4c10d44 1009 }
e5a99b88
AD
1010
1011 print "</td>";
1012 print "</tr></table>";
1013
1014
1015 print "<table class=\"headlinesList\" id=\"headlinesList\"
1016 cellspacing=\"0\" width=\"100%\">";
1017
1018 $lnum = 0;
1019
1020 error_reporting (DEFAULT_ERROR_LEVEL);
1021
1022 $num_unread = 0;
1023
1024 while ($line = db_fetch_assoc($result)) {
1025
1026 $class = ($lnum % 2) ? "even" : "odd";
1027
1028 $id = $line["id"];
1029 $feed_id = $line["feed_id"];
1030
1031 if ($line["last_read"] == "" &&
1032 ($line["unread"] != "t" && $line["unread"] != "1")) {
1033
1034 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
1035 alt=\"Updated\">";
1036 } else {
1037 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
1038 alt=\"Updated\">";
1039 }
1040
1041 if ($line["unread"] == "t" || $line["unread"] == "1") {
1042 $class .= "Unread";
1043 ++$num_unread;
1044 }
1045
1046 if ($line["marked"] == "t" || $line["marked"] == "1") {
1047 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
1048 alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>";
1049 } else {
1050 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
1051 alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>";
1052 }
1053
1054 $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
1055 $line["title"] . "</a>";
1056
1057 print "<tr class='$class' id='RROW-$id'>";
1058 // onclick=\"javascript:view($id,$feed_id)\">
1059
1060 print "<td class='hlUpdatePic'>$update_pic</td>";
1061
1062 print "<td class='hlSelectRow'>
1063 <input type=\"checkbox\" onclick=\"toggleSelectRow(this)\"
1064 class=\"feedCheckBox\" id=\"RCHK-$id\">
1065 </td>";
1066
1067 print "<td class='hlMarkedPic'>$marked_pic</td>";
1068
1069 if ($line["feed_title"]) {
1070 print "<td class='hlContent'>$content_link</td>";
1071 print "<td class='hlFeed'>
1072 <a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a></td>";
1073 } else {
1074 print "<td class='hlContent'>";
1075
1076 print "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
1077 $line["title"];
1078
1079 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
1080
1081 $content_preview = truncate_string(strip_tags($line["content_preview"]),
1082 101);
1083
1084 if ($content_preview) {
1085 print "<span class=\"contentPreview\"> - $content_preview</span>";
1086 }
ad3dee91 1087 }
e5a99b88
AD
1088
1089 print "</a>";
1090 print "</td>";
591c396d 1091 }
e5a99b88
AD
1092
1093 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
1094 $updated_fmt = smart_date_time(strtotime($line["updated"]));
1095 } else {
1096 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1097 $updated_fmt = date($short_date, strtotime($line["updated"]));
1098 }
1099
1100 print "<td class=\"hlUpdated\"><nobr>$updated_fmt&nbsp;</nobr></td>";
1101
1102 print "</tr>";
1103
1104 ++$lnum;
254e0e4b 1105 }
be773442 1106
e5a99b88 1107 print "</table>";
d76a3b03 1108
e5a99b88
AD
1109 } else {
1110 print "<div width='100%' align='center'>No articles found.</div>";
a1a8a2be 1111 }
d76a3b03 1112
6113ef7d 1113 print "<script type=\"text/javascript\">
bb7cface 1114 document.onkeydown = hotkey_handler;
4f3a84f4 1115 update_all_counters('$feed');
6113ef7d 1116 </script>";
d76a3b03 1117
f0601b87
AD
1118 if ($addheader) {
1119 print "</body></html>";
1120 }
1121
1cd17194
AD
1122 }
1123
0e091d38 1124 if ($op == "pref-rpc") {
331900c6 1125
0e091d38 1126 $subop = $_GET["subop"];
331900c6 1127
83fe4d6d
AD
1128 if ($subop == "unread") {
1129 $ids = split(",", $_GET["ids"]);
1130 foreach ($ids as $id) {
a5873b2e
AD
1131 db_query($link, "UPDATE ttrss_user_entries SET unread = true
1132 WHERE feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
83fe4d6d 1133 }
0e091d38 1134
a5873b2e 1135 print "Marked selected feeds as unread.";
83fe4d6d
AD
1136 }
1137
1138 if ($subop == "read") {
1139 $ids = split(",", $_GET["ids"]);
1140 foreach ($ids as $id) {
a5873b2e
AD
1141 db_query($link, "UPDATE ttrss_user_entries
1142 SET unread = false,last_read = NOW() WHERE
1143 feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
83fe4d6d 1144 }
0e091d38 1145
a5873b2e 1146 print "Marked selected feeds as read.";
0e091d38
AD
1147
1148 }
1149
1150 }
1151
1152 if ($op == "pref-feeds") {
1153
1154 $subop = $_GET["subop"];
1155
508a81e1 1156 if ($subop == "editSave") {
648472a7
AD
1157 $feed_title = db_escape_string($_GET["t"]);
1158 $feed_link = db_escape_string($_GET["l"]);
d148926e 1159 $upd_intl = db_escape_string($_GET["ui"]);
5d73494a 1160 $purge_intl = db_escape_string($_GET["pi"]);
91ff844a
AD
1161 $feed_id = db_escape_string($_GET["id"]);
1162 $cat_id = db_escape_string($_GET["catid"]);
508a81e1 1163
d148926e
AD
1164 if (strtoupper($upd_intl) == "DEFAULT")
1165 $upd_intl = 0;
1166
5d73494a
AD
1167 if (strtoupper($purge_intl) == "DEFAULT")
1168 $purge_intl = 0;
1169
140aae81
AD
1170 if (strtoupper($purge_intl) == "DISABLED")
1171 $purge_intl = -1;
1172
91ff844a
AD
1173 if ($cat_id != 0) {
1174 $category_qpart = "cat_id = '$cat_id'";
1175 } else {
1176 $category_qpart = 'cat_id = NULL';
1177 }
1178
648472a7 1179 $result = db_query($link, "UPDATE ttrss_feeds SET
91ff844a 1180 $category_qpart,
d148926e 1181 title = '$feed_title', feed_url = '$feed_link',
5d73494a 1182 update_interval = '$upd_intl',
91ff844a 1183 purge_interval = '$purge_intl'
f72dbbde 1184 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
508a81e1 1185
83fe4d6d
AD
1186 }
1187
331900c6 1188 if ($subop == "remove") {
331900c6 1189
b0b4abcf 1190 if (!WEB_DEMO_MODE) {
331900c6 1191
b0b4abcf
AD
1192 $ids = split(",", $_GET["ids"]);
1193
1194 foreach ($ids as $id) {
f72dbbde
AD
1195 db_query($link, "DELETE FROM ttrss_feeds
1196 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
4769ddaf 1197
273a2f6b 1198 $icons_dir = ICONS_DIR;
d5caaae5 1199
4769ddaf
AD
1200 if (file_exists($icons_dir . "/$id.ico")) {
1201 unlink($icons_dir . "/$id.ico");
d5caaae5 1202 }
b0b4abcf 1203 }
331900c6
AD
1204 }
1205 }
1206
1207 if ($subop == "add") {
b0b4abcf
AD
1208
1209 if (!WEB_DEMO_MODE) {
331900c6 1210
b6b535ca 1211 $feed_link = db_escape_string(trim($_GET["link"]));
331900c6 1212
648472a7 1213 $result = db_query($link,
7e9a3986
AD
1214 "SELECT id FROM ttrss_feeds
1215 WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]);
1216
1217 if (db_num_rows($result) == 0) {
1218
1219 $result = db_query($link,
1220 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title)
1221 VALUES ('".$_SESSION["uid"]."', '$feed_link', '')");
331900c6 1222
7e9a3986
AD
1223 $result = db_query($link,
1224 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'
1225 AND owner_uid = " . $_SESSION["uid"]);
1226
1227 $feed_id = db_fetch_result($result, 0, "id");
1228
1229 if ($feed_id) {
ddb68b81 1230 update_rss_feed($link, $feed_link, $feed_id, true);
7e9a3986
AD
1231 }
1232 } else {
331900c6 1233
7e9a3986
AD
1234 print "<div class=\"warning\">
1235 Feed <b>$feed_link</b> already exists in the database.
1236 </div>";
b0b4abcf
AD
1237 }
1238 }
331900c6 1239 }
a0d53889 1240
91ff844a
AD
1241 if ($subop == "addCat") {
1242
1243 if (!WEB_DEMO_MODE) {
1244
1245 $feed_cat = db_escape_string(trim($_GET["cat"]));
1246
1247 $result = db_query($link,
1248 "SELECT id FROM ttrss_feed_categories
1249 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
1250
1251 if (db_num_rows($result) == 0) {
1252
1253 $result = db_query($link,
1254 "INSERT INTO ttrss_feed_categories (owner_uid,title)
1255 VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
1256
1257 } else {
1258
1259 print "<div class=\"warning\">
1260 Category <b>$feed_cat</b> already exists in the database.
1261 </div>";
1262 }
1263
1264
1265 }
1266 }
1267
1268 if ($subop == "removeCats") {
1269
1270 if (!WEB_DEMO_MODE) {
1271
1272 $ids = split(",", $_GET["ids"]);
1273
1274 foreach ($ids as $id) {
1275
1276 db_query($link, "BEGIN");
1277
1278 $result = db_query($link,
1279 "SELECT count(id) as num_feeds FROM ttrss_feeds
1280 WHERE cat_id = '$id'");
1281
1282 $num_feeds = db_fetch_result($result, 0, "num_feeds");
1283
1284 if ($num_feeds == 0) {
1285 db_query($link, "DELETE FROM ttrss_feed_categories
1286 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1287 } else {
1288
1289 print "<div class=\"warning\">
1290 Unable to delete non empty feed categories.</div>";
1291
1292 }
1293
1294 db_query($link, "COMMIT");
1295 }
1296 }
1297 }
1298
c64d5b03 1299// print "<h3>Edit Feeds</h3>";
91ff844a 1300
4904f845
AD
1301 $result = db_query($link, "SELECT id,title,feed_url,last_error
1302 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1303
1304 if (db_num_rows($result) > 0) {
1305
1306 print "<div class=\"warning\">";
1307
1308 print "<b>Feeds with update errors:</b>";
1309
1310 print "<ul class=\"nomarks\">";
1311
1312 while ($line = db_fetch_assoc($result)) {
1313 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
1314 $line["last_error"];
1315 }
1316
1317 print "</ul>";
1318 print "</div>";
1319
1320 }
1321
c64d5b03 1322 print "<p><div class=\"prefGenericAddBox\">
2c7070b5
AD
1323 <input id=\"fadd_link\" size=\"40\">&nbsp;<input
1324 type=\"submit\" class=\"button\"
1325 onclick=\"javascript:addFeed()\" value=\"Add feed\"></div>";
a0d53889 1326
b83c7545
AD
1327 $feeds_sort = db_escape_string($_GET["sort"]);
1328
1329 if (!$feeds_sort || $feeds_sort == "undefined") {
1330 $feeds_sort = $_SESSION["pref_sort_feeds"];
1331 if (!$feeds_sort) $feeds_sort = "title";
1332 }
1333
1334 $_SESSION["pref_sort_feeds"] = $feeds_sort;
1335
648472a7 1336 $result = db_query($link, "SELECT
d148926e 1337 id,title,feed_url,substring(last_updated,1,16) as last_updated,
91ff844a
AD
1338 update_interval,purge_interval,
1339 (SELECT title FROM ttrss_feed_categories
1340 WHERE id = cat_id) AS category
c0e5a40e 1341 FROM
b83c7545
AD
1342 ttrss_feeds WHERE owner_uid = '".$_SESSION["uid"]."'
1343 ORDER by $feeds_sort,title");
1cd17194 1344
3b0feb9b 1345 if (db_num_rows($result) != 0) {
91ff844a 1346
3b0feb9b 1347 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
35f3c923 1348
f4fe2cde
AD
1349 print "<p><table width=\"100%\" cellspacing=\"0\"
1350 class=\"prefFeedList\" id=\"prefFeedList\">";
35f3c923
AD
1351 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1352 Select:
1353 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
3055bc41 1354 'FEEDR-', 'FRCHK-', true)\">All</a>,
35f3c923 1355 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
3055bc41 1356 'FEEDR-', 'FRCHK-', false)\">None</a>
35f3c923
AD
1357 </td</tr>";
1358
3b0feb9b 1359 print "<tr class=\"title\">
3547842a
AD
1360 <td width=\"3%\">&nbsp;</td>
1361 <td width=\"3%\">Select</td>
3b0feb9b
AD
1362 <td width=\"20%\">
1363 <a href=\"javascript:updateFeedList('title')\">Title</a></td>
1364 <td width=\"20%\">
1365 <a href=\"javascript:updateFeedList('feed_url')\">Link</a>
1366 </td>";
54d3ba50 1367
3b0feb9b
AD
1368 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1369 print "<td width=\"10%\">
1370 <a href=\"javascript:updateFeedList('category')\">Category</a></td>";
603c27f8 1371 }
603c27f8 1372
f92db4f5 1373 print "
3b0feb9b
AD
1374 <td width=\"10%\">
1375 <a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a>
1376 </td>
1377 <td width=\"10%\">
1378 <a href=\"javascript:updateFeedList('purge_interval')\">Purge Days</a>
1379 </td>
3b0feb9b
AD
1380 </tr>";
1381
c64d5b03
AD
1382 $lnum = 0;
1383
1384 while ($line = db_fetch_assoc($result)) {
1385
1386 $class = ($lnum % 2) ? "even" : "odd";
1387
3b0feb9b 1388 $feed_id = $line["id"];
c64d5b03 1389
3b0feb9b 1390 $edit_feed_id = $_GET["id"];
c64d5b03 1391
3b0feb9b 1392 if ($subop == "edit" && $feed_id != $edit_feed_id) {
c64d5b03 1393 $class .= "Grayed";
53226edc
AD
1394 $this_row_id = "";
1395 } else {
1396 $this_row_id = "id=\"FEEDR-$feed_id\"";
c64d5b03
AD
1397 }
1398
53226edc 1399 print "<tr class=\"$class\" $this_row_id>";
3b0feb9b
AD
1400
1401 $icon_file = ICONS_DIR . "/$feed_id.ico";
1402
1403 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1404 $feed_icon = "<img width=\"16\" height=\"16\"
1405 src=\"" . ICONS_URL . "/$feed_id.ico\">";
1406 } else {
1407 $feed_icon = "&nbsp;";
1408 }
1409 print "<td align='center'>$feed_icon</td>";
c64d5b03
AD
1410
1411 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
3b0feb9b
AD
1412 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
1413 $edit_cat = htmlspecialchars(db_unescape_string($line["category"]));
1414
1415 if (!$edit_cat) $edit_cat = "Uncategorized";
c64d5b03 1416
3b0feb9b 1417 if (!$edit_feed_id || $subop != "edit") {
c64d5b03
AD
1418
1419 print "<td><input onclick='toggleSelectRow(this);'
3b0feb9b 1420 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
3547842a
AD
1421
1422 $edit_title = truncate_string($edit_title, 40);
1423 $edit_link = truncate_string($edit_link, 60);
c64d5b03 1424
3b0feb9b 1425 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
c64d5b03 1426 $edit_title . "</a></td>";
3b0feb9b
AD
1427
1428 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1429 $edit_link . "</a></td>";
1430
1431 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1432 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1433 $edit_cat . "</a></td>";
1434 }
1435
1436 if ($line["update_interval"] == "0")
1437 $line["update_interval"] = "Default";
c64d5b03 1438
3b0feb9b
AD
1439 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1440 $line["update_interval"] . "</a></td>";
1441
1442 if ($line["purge_interval"] == "0")
1443 $line["purge_interval"] = "Default";
1444
1445 if ($line["purge_interval"] < 0)
1446 $line["purge_interval"] = "Disabled";
1447
1448 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1449 $line["purge_interval"] . "</a></td>";
1450
1451 } else if ($feed_id != $edit_feed_id) {
c64d5b03
AD
1452
1453 print "<td><input disabled=\"true\" type=\"checkbox\"
1454 id=\"FRCHK-".$line["id"]."\"></td>";
3547842a
AD
1455
1456 $edit_title = truncate_string($edit_title, 40);
1457 $edit_link = truncate_string($edit_link, 60);
1458
c64d5b03 1459 print "<td>$edit_title</td>";
3b0feb9b
AD
1460 print "<td>$edit_link</td>";
1461
1462 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1463 print "<td>$edit_cat</td>";
1464 }
1465
1466 if ($line["update_interval"] == "0")
1467 $line["update_interval"] = "Default";
1468
1469 print "<td>" . $line["update_interval"] . "</td>";
1470
1471 if ($line["purge_interval"] == "0")
1472 $line["purge_interval"] = "Default";
1473
1474 if ($line["purge_interval"] < 0)
1475 $line["purge_interval"] = "Disabled";
1476
1477 print "<td>" . $line["purge_interval"] . "</td>";
c64d5b03
AD
1478
1479 } else {
1480
1481 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1482
1483 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
3b0feb9b
AD
1484 print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>";
1485
1486 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1487
1488 print "<td>";
1489 print "<select id=\"iedit_fcat\">";
1490 print "<option id=\"0\">Uncategorized</option>";
1491
1492 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feed_categories
1493 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1494
1495 if (db_num_rows($tmp_result) > 0) {
1496 print "<option disabled>--------</option>";
1497 }
1498
1499 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1500 if ($tmp_line["id"] == $line["cat_id"]) {
1501 $is_selected = "selected";
1502 } else {
1503 $is_selected = "";
1504 }
1505 printf("<option $is_selected id='%d'>%s</option>",
1506 $tmp_line["id"], $tmp_line["title"]);
1507 }
1508
1509 print "</select></td>";
1510 print "</td>";
1511
1512 }
c64d5b03 1513
3b0feb9b
AD
1514 print "<td><input id=\"iedit_updintl\"
1515 value=\"".$line["update_interval"]."\"></td>";
1516 print "<td><input id=\"iedit_purgintl\"
1517 value=\"".$line["purge_interval"]."\"></td>";
1518
c64d5b03 1519 }
3b0feb9b 1520
3547842a 1521/* if (!$line["last_updated"]) $line["last_updated"] = "Never";
3b0feb9b 1522
3547842a 1523 print "<td>" . $line["last_updated"] . "</td>"; */
c64d5b03
AD
1524
1525 print "</tr>";
1526
1527 ++$lnum;
1528 }
1529
c64d5b03 1530 print "</table>";
3b0feb9b 1531
c64d5b03
AD
1532 print "<p>";
1533
3b0feb9b
AD
1534 if ($subop == "edit") {
1535 print "Edit feed:&nbsp;
c64d5b03 1536 <input type=\"submit\" class=\"button\"
3b0feb9b 1537 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
c64d5b03 1538 <input type=\"submit\" class=\"button\"
3b0feb9b
AD
1539 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
1540 } else {
c64d5b03
AD
1541
1542 print "
1543 Selection:&nbsp;
1544 <input type=\"submit\" class=\"button\"
3b0feb9b 1545 onclick=\"javascript:selectedFeedDetails()\" value=\"Details\">
c64d5b03 1546 <input type=\"submit\" class=\"button\"
3b0feb9b
AD
1547 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
1548 <input type=\"submit\" class=\"button\"
1549 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
1550
1551 if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) {
1552 print "
1553 <input type=\"submit\" class=\"button\"
4f3a84f4 1554 onclick=\"javascript:readSelectedFeeds(true)\" value=\"Mark as read\">
3b0feb9b 1555 <input type=\"submit\" class=\"button\"
4f3a84f4 1556 onclick=\"javascript:readSelectedFeeds(false)\"
3b0feb9b
AD
1557 value=\"Mark as unread\">&nbsp;";
1558 }
1559
1560 print "
1561 All feeds: <input type=\"submit\"
1562 class=\"button\" onclick=\"gotoExportOpml()\"
1563 value=\"Export OPML\">";
1564 }
1565 } else {
1566
1567 print "<p>No feeds defined.</p>";
1568
1569 }
1570
1571 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1572
1573 print "<h3>Edit Categories</h3>";
1574
1575 // print "<h3>Categories</h3>";
1576
1577 print "<div class=\"prefGenericAddBox\">
1578 <input id=\"fadd_cat\" size=\"40\">&nbsp;<input
1579 type=\"submit\" class=\"button\"
1580 onclick=\"javascript:addFeedCat()\" value=\"Add category\"></div>";
1581
1582 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
1583 WHERE owner_uid = ".$_SESSION["uid"]."
1584 ORDER BY title");
1585
1586 if (db_num_rows($result) != 0) {
1587
35f3c923 1588 print "<p><table width=\"100%\" class=\"prefFeedCatList\"
f4fe2cde 1589 cellspacing=\"0\" id=\"prefFeedCatList\">";
35f3c923
AD
1590
1591 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1592 Select:
1593 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
3055bc41 1594 'FCATR-', 'FCCHK-', true)\">All</a>,
35f3c923 1595 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
3055bc41 1596 'FCATR-', 'FCCHK-', false)\">None</a>
35f3c923
AD
1597 </td</tr>";
1598
3b0feb9b
AD
1599 print "<tr class=\"title\">
1600 <td width=\"10%\">Select</td><td width=\"80%\">Title</td>
1601 </tr>";
1602
1603 $lnum = 0;
1604
1605 while ($line = db_fetch_assoc($result)) {
1606
1607 $class = ($lnum % 2) ? "even" : "odd";
1608
1609 $cat_id = $line["id"];
1610
1611 $edit_cat_id = $_GET["id"];
1612
1613 if ($subop == "editCat" && $cat_id != $edit_cat_id) {
1614 $class .= "Grayed";
53226edc
AD
1615 $this_row_id = "";
1616 } else {
1617 $this_row_id = "id=\"FCATR-$cat_id\"";
3b0feb9b
AD
1618 }
1619
53226edc 1620 print "<tr class=\"$class\" $this_row_id>";
3b0feb9b
AD
1621
1622 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1623
1624 if (!$edit_cat_id || $subop != "editCat") {
1625
1626 print "<td><input onclick='toggleSelectRow(this);'
1627 type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>";
1628
1629 print "<td><a href=\"javascript:editFeedCat($cat_id);\">" .
1630 $edit_title . "</a></td>";
1631
1632 } else if ($cat_id != $edit_cat_id) {
1633
1634 print "<td><input disabled=\"true\" type=\"checkbox\"
1635 id=\"FRCHK-".$line["id"]."\"></td>";
1636
1637 print "<td>$edit_title</td>";
1638
1639 } else {
1640
1641 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1642
1643 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
1644
1645 }
1646
1647 print "</tr>";
1648
1649 ++$lnum;
1650 }
1651
1652 print "</table>";
1653
1654 print "<p>";
1655
1656 if ($subop == "editCat") {
1657 print "Edit category:&nbsp;
1658 <input type=\"submit\" class=\"button\"
1659 onclick=\"javascript:feedCatEditCancel()\" value=\"Cancel\">
1660 <input type=\"submit\" class=\"button\"
1661 onclick=\"javascript:feedCatEditSave()\" value=\"Save\">";
1662 } else {
1663
1664 print "
1665 Selection:&nbsp;
1666 <input type=\"submit\" class=\"button\"
1667 onclick=\"javascript:editSelectedFeedCat()\" value=\"Edit\">
1668 <input type=\"submit\" class=\"button\"
1669 onclick=\"javascript:removeSelectedFeedCats()\" value=\"Remove\">";
1670
1671 }
1672
1673 } else {
1674 print "<p>No feed categories defined.</p>";
1675 }
c64d5b03
AD
1676 }
1677
1678 print "<h3>Import OPML</h3>
f5a50b25
AD
1679 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
1680 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
1681 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
1682 type=\"submit\" value=\"Import\">
1683 </form>";
1684
007bda35
AD
1685 }
1686
a0d53889
AD
1687 if ($op == "pref-filters") {
1688
1689 $subop = $_GET["subop"];
1690
1691 if ($subop == "editSave") {
a0d53889 1692
648472a7
AD
1693 $regexp = db_escape_string($_GET["r"]);
1694 $descr = db_escape_string($_GET["d"]);
1695 $match = db_escape_string($_GET["m"]);
1696 $filter_id = db_escape_string($_GET["id"]);
ead60402
AD
1697 $feed_id = db_escape_string($_GET["fid"]);
1698
1699 if (!$feed_id) {
1700 $feed_id = 'NULL';
1701 } else {
1702 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
1703 }
0afbd851 1704
648472a7 1705 $result = db_query($link, "UPDATE ttrss_filters SET
4b3dff6e 1706 reg_exp = '$regexp',
0afbd851 1707 description = '$descr',
ead60402 1708 feed_id = $feed_id,
0afbd851
AD
1709 filter_type = (SELECT id FROM ttrss_filter_types WHERE
1710 description = '$match')
1711 WHERE id = '$filter_id'");
a0d53889
AD
1712 }
1713
1714 if ($subop == "remove") {
1715
1716 if (!WEB_DEMO_MODE) {
1717
1718 $ids = split(",", $_GET["ids"]);
1719
1720 foreach ($ids as $id) {
648472a7 1721 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
a0d53889
AD
1722
1723 }
1724 }
1725 }
1726
1727 if ($subop == "add") {
1728
de435974 1729 if (!WEB_DEMO_MODE) {
a0d53889 1730
b6b535ca
AD
1731 $regexp = db_escape_string(trim($_GET["regexp"]));
1732 $match = db_escape_string(trim($_GET["match"]));
ead60402
AD
1733 $feed_id = db_escape_string($_GET["fid"]);
1734
1735 if (!$feed_id) {
1736 $feed_id = 'NULL';
1737 } else {
1738 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
1739 }
4401bf04 1740
648472a7 1741 $result = db_query($link,
ead60402 1742 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id) VALUES
de435974 1743 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
ead60402 1744 description = '$match'),'".$_SESSION["uid"]."', $feed_id)");
de435974 1745 }
a0d53889
AD
1746 }
1747
648472a7 1748 $result = db_query($link, "SELECT description
a0d53889
AD
1749 FROM ttrss_filter_types ORDER BY description");
1750
1751 $filter_types = array();
1752
648472a7 1753 while ($line = db_fetch_assoc($result)) {
a0d53889
AD
1754 array_push($filter_types, $line["description"]);
1755 }
1756
2c7070b5
AD
1757 print "<div class=\"prefGenericAddBox\">
1758 <input id=\"fadd_regexp\" size=\"40\">&nbsp;";
1759
ead60402
AD
1760 print_select("fadd_match", "Title", $filter_types);
1761
1762 print "&nbsp;<select id=\"fadd_feed\">";
1763
1764 print "<option selected id=\"0\">All feeds</option>";
1765
1766 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
1767 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1768
1769 if (db_num_rows($result) > 0) {
1770 print "<option disabled>--------</option>";
1771 }
1772
1773 while ($line = db_fetch_assoc($result)) {
1774 printf("<option id='%d'>%s</option>", $line["id"], $line["title"]);
1775 }
1776
2c7070b5 1777 print "</select>&nbsp;";
a0d53889 1778
2c7070b5
AD
1779 print "<input type=\"submit\"
1780 class=\"button\" onclick=\"javascript:addFilter()\"
1781 value=\"Add filter\">";
a0d53889 1782
648472a7 1783 $result = db_query($link, "SELECT
ead60402
AD
1784 ttrss_filters.id AS id,reg_exp,
1785 ttrss_filters.description AS description,
1786 ttrss_filter_types.name AS filter_type_name,
1787 ttrss_filter_types.description AS filter_type_descr,
1788 feed_id,
1789 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
a0d53889 1790 FROM
ead60402 1791 ttrss_filters,ttrss_filter_types
4356293a 1792 WHERE
ead60402
AD
1793 filter_type = ttrss_filter_types.id AND
1794 ttrss_filters.owner_uid = ".$_SESSION["uid"]."
4356293a 1795 ORDER by reg_exp");
a0d53889 1796
3b0feb9b 1797 if (db_num_rows($result) != 0) {
a0d53889 1798
f4fe2cde
AD
1799 print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\"
1800 id=\"prefFilterList\">";
35f3c923
AD
1801
1802 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1803 Select:
1804 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
3055bc41 1805 'FILRR-', 'FICHK-', true)\">All</a>,
35f3c923 1806 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
3055bc41 1807 'FILRR-', 'FICHK-', false)\">None</a>
35f3c923
AD
1808 </td</tr>";
1809
3b0feb9b
AD
1810 print "<tr class=\"title\">
1811 <td width=\"5%\">Select</td><td width=\"30%\">Filter expression</td>
1812 <td width=\"30%\">Feed</td><td width=\"10%\">Match</td>
1813 <td width=\"30%\">Description</td></tr>";
a0d53889 1814
3b0feb9b
AD
1815 $lnum = 0;
1816
1817 while ($line = db_fetch_assoc($result)) {
1818
1819 $class = ($lnum % 2) ? "even" : "odd";
1820
1821 $filter_id = $line["id"];
1822 $edit_filter_id = $_GET["id"];
1823
1824 if ($subop == "edit" && $filter_id != $edit_filter_id) {
1825 $class .= "Grayed";
53226edc
AD
1826 $this_row_id = "";
1827 } else {
1828 $this_row_id = "id=\"FILRR-$filter_id\"";
ead60402 1829 }
3b0feb9b 1830
53226edc 1831 print "<tr class=\"$class\" $this_row_id>";
3b0feb9b
AD
1832
1833 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
1834 $line["description"] = htmlspecialchars($line["description"]);
1835
1836 if (!$line["feed_title"]) $line["feed_title"] = "All feeds";
1837
1838 if (!$edit_filter_id || $subop != "edit") {
1839
1840 if (!$line["description"]) $line["description"] = "[No description]";
1841
1842 print "<td><input onclick='toggleSelectRow(this);'
1843 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
1844
1845 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1846 $line["reg_exp"] . "</td>";
1847
1848 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1849 $line["feed_title"] . "</td>";
1850
1851 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1852 $line["filter_type_descr"] . "</td>";
1853
1854 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1855 $line["description"] . "</td>";
1856
1857 } else if ($filter_id != $edit_filter_id) {
1858
1859 if (!$line["description"]) $line["description"] = "[No description]";
1860
1861 print "<td><input disabled=\"true\" type=\"checkbox\"
1862 id=\"FICHK-".$line["id"]."\"></td>";
1863
1864 print "<td>".$line["reg_exp"]."</td>";
1865 print "<td>".$line["feed_title"]."</td>";
1866 print "<td>".$line["filter_type_descr"]."</td>";
1867 print "<td>".$line["description"]."</td>";
1868
1869 } else {
1870
1871 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1872
1873 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
1874 "\"></td>";
1875
1876 print "<td>";
1877
1878 print "<select id=\"iedit_feed\">";
1879
1880 print "<option id=\"0\">All feeds</option>";
1881
1882 if (db_num_rows($result) > 0) {
1883 print "<option disabled>--------</option>";
1884 }
1885
1886 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
1887 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1888
1889 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1890 if ($tmp_line["id"] == $line["feed_id"]) {
1891 $is_selected = "selected";
1892 } else {
1893 $is_selected = "";
1894 }
1895 printf("<option $is_selected id='%d'>%s</option>",
1896 $tmp_line["id"], $tmp_line["title"]);
ead60402 1897 }
3b0feb9b
AD
1898
1899 print "</select></td>";
1900
1901 print "<td>";
1902 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
1903 print "</td>";
1904
1905 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1906 "\"></td>";
1907
1908 print "</td>";
ead60402 1909 }
3b0feb9b
AD
1910
1911 print "</tr>";
1912
1913 ++$lnum;
a0d53889 1914 }
3b0feb9b
AD
1915
1916 if ($lnum == 0) {
1917 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
1918 }
1919
1920 print "</table>";
1921
1922 print "<p>";
1923
1924 if ($subop == "edit") {
1925 print "Edit feed:
1926 <input type=\"submit\" class=\"button\"
1927 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
1928 <input type=\"submit\" class=\"button\"
1929 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
1930
1931 } else {
1932
1933 print "
1934 Selection:
e828e31e 1935 <input type=\"submit\" class=\"button\"
3b0feb9b 1936 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
e828e31e 1937 <input type=\"submit\" class=\"button\"
3b0feb9b
AD
1938 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
1939 }
1940
a0d53889
AD
1941 } else {
1942
3b0feb9b
AD
1943 print "<p>No filters defined.</p>";
1944
a0d53889
AD
1945 }
1946 }
1947
48f0adb0
AD
1948 if ($op == "pref-labels") {
1949
1950 $subop = $_GET["subop"];
1951
d9dde1d6
AD
1952 if ($subop == "test") {
1953
1954 $expr = $_GET["expr"];
1955 $descr = $_GET["descr"];
1956
1957 print "<div class='infoBoxContents'>";
1958
1959 print "<h1>Label &laquo;$descr&raquo;</h1>";
1960
1961// print "<p><b>Expression</b>: $expr</p>";
1962
1963 $result = db_query($link,
1964 "SELECT count(id) AS num_matches
1965 FROM ttrss_entries,ttrss_user_entries
1966 WHERE ($expr) AND
1967 ttrss_user_entries.ref_id = ttrss_entries.id AND
1968 owner_uid = " . $_SESSION["uid"]);
1969
1970 $num_matches = db_fetch_result($result, 0, "num_matches");;
1971
1972 if ($num_matches > 0) {
1973
a31a7b39 1974 print "<p>Query returned <b>$num_matches</b> matches, first 5 follow:</p>";
d9dde1d6
AD
1975
1976 $result = db_query($link,
1977 "SELECT title,
1978 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
1979 FROM ttrss_entries,ttrss_user_entries
1980 WHERE ($expr) AND
1981 ttrss_user_entries.ref_id = ttrss_entries.id
1982 AND owner_uid = " . $_SESSION["uid"] . "
1983 ORDER BY date_entered DESC LIMIT 5");
1984
1985 print "<ul class=\"nomarks\">";
1986 while ($line = db_fetch_assoc($result)) {
1987 print "<li>".$line["title"].
1988 " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>";
1989 }
1990 print "</ul>";
1991
1992 } else {
1993 print "<p>Query didn't return any matches.</p>";
1994 }
1995
1996 print "</div>";
1997
1998 print "<div align='center'>
1999 <input type='submit' class='button'
2000 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2001 return;
2002 }
2003
48f0adb0
AD
2004 if ($subop == "editSave") {
2005
2006 $sql_exp = $_GET["s"];
2007 $descr = $_GET["d"];
2008 $label_id = db_escape_string($_GET["id"]);
2009
2010// print "$sql_exp : $descr : $label_id";
2011
2012 $result = db_query($link, "UPDATE ttrss_labels SET
2013 sql_exp = '$sql_exp',
2014 description = '$descr'
2015 WHERE id = '$label_id'");
2016 }
2017
2018 if ($subop == "remove") {
2019
2020 if (!WEB_DEMO_MODE) {
2021
2022 $ids = split(",", $_GET["ids"]);
2023
2024 foreach ($ids as $id) {
2025 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
2026
2027 }
2028 }
2029 }
2030
2031 if ($subop == "add") {
2032
2033 if (!WEB_DEMO_MODE) {
2034
4401bf04
AD
2035 // no escaping is done here on purpose
2036 $exp = trim($_GET["exp"]);
48f0adb0
AD
2037
2038 $result = db_query($link,
4356293a
AD
2039 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
2040 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
48f0adb0
AD
2041 }
2042 }
2043
2c7070b5
AD
2044 print "<div class=\"prefGenericAddBox\">
2045 <input size=\"40\" id=\"ladd_expr\">&nbsp;";
48f0adb0 2046
2c7070b5
AD
2047 print"<input type=\"submit\" class=\"button\"
2048 onclick=\"javascript:addLabel()\" value=\"Add label\"></div>";
48f0adb0
AD
2049
2050 $result = db_query($link, "SELECT
2051 id,sql_exp,description
2052 FROM
4356293a
AD
2053 ttrss_labels
2054 WHERE
2055 owner_uid = ".$_SESSION["uid"]."
2056 ORDER by description");
48f0adb0 2057
d9dde1d6
AD
2058 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
2059
3b0feb9b 2060 if (db_num_rows($result) != 0) {
48f0adb0 2061
f4fe2cde
AD
2062 print "<p><table width=\"100%\" cellspacing=\"0\"
2063 class=\"prefLabelList\" id=\"prefLabelList\">";
35f3c923
AD
2064
2065 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2066 Select:
2067 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
3055bc41 2068 'LILRR-', 'LICHK-', true)\">All</a>,
35f3c923 2069 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
3055bc41 2070 'LILRR-', 'LICHK-', false)\">None</a>
35f3c923
AD
2071 </td</tr>";
2072
3b0feb9b
AD
2073 print "<tr class=\"title\">
2074 <td width=\"5%\">Select</td><td width=\"40%\">SQL expression
01c9c74a 2075 <a class=\"helpLink\" href=\"javascript:displayHelpInfobox(1)\">(?)</a>
3b0feb9b
AD
2076 </td>
2077 <td width=\"40%\">Caption</td></tr>";
2078
2079 $lnum = 0;
2080
2081 while ($line = db_fetch_assoc($result)) {
2082
2083 $class = ($lnum % 2) ? "even" : "odd";
2084
2085 $label_id = $line["id"];
2086 $edit_label_id = $_GET["id"];
2087
2088 if ($subop == "edit" && $label_id != $edit_label_id) {
2089 $class .= "Grayed";
53226edc
AD
2090 $this_row_id = "";
2091 } else {
2092 $this_row_id = "id=\"LILRR-$label_id\"";
3b0feb9b
AD
2093 }
2094
53226edc 2095 print "<tr class=\"$class\" $this_row_id>";
3b0feb9b
AD
2096
2097 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
2098 $line["description"] = htmlspecialchars($line["description"]);
2099
2100 if (!$edit_label_id || $subop != "edit") {
2101
2102 if (!$line["description"]) $line["description"] = "[No caption]";
2103
2104 print "<td><input onclick='toggleSelectRow(this);'
2105 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
2106
2107 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2108 $line["sql_exp"] . "</td>";
48f0adb0 2109
3b0feb9b
AD
2110 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2111 $line["description"] . "</td>";
2112
2113 } else if ($label_id != $edit_label_id) {
2114
2115 if (!$line["description"]) $line["description"] = "[No description]";
2116
2117 print "<td><input disabled=\"true\" type=\"checkbox\"
2118 id=\"LICHK-".$line["id"]."\"></td>";
2119
2120 print "<td>".$line["sql_exp"]."</td>";
2121 print "<td>".$line["description"]."</td>";
2122
2123 } else {
2124
2125 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2126
2127 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
2128 "\"></td>";
2129
2130 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
2131 "\"></td>";
2132
2133 }
2134
48f0adb0 2135
3b0feb9b
AD
2136 print "</tr>";
2137
2138 ++$lnum;
2139 }
2140
2141 if ($lnum == 0) {
2142 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
2143 }
2144
2145 print "</table>";
2146
2147 print "<p>";
2148
2149 if ($subop == "edit") {
2150 print "Edit label:
d9dde1d6
AD
2151 <input type=\"submit\" class=\"button\"
2152 onclick=\"javascript:labelTest()\" value=\"Test\">
3b0feb9b
AD
2153 <input type=\"submit\" class=\"button\"
2154 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
2155 <input type=\"submit\" class=\"button\"
2156 onclick=\"javascript:labelEditSave()\" value=\"Save\">";
2157
2158 } else {
2159
2160 print "
2161 Selection:
48f0adb0 2162 <input type=\"submit\" class=\"button\"
3b0feb9b 2163 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
48f0adb0 2164 <input type=\"submit\" class=\"button\"
3b0feb9b
AD
2165 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
2166 }
48f0adb0 2167 } else {
3b0feb9b 2168 print "<p>No labels defined.</p>";
48f0adb0
AD
2169 }
2170 }
2171
e828e31e
AD
2172 if ($op == "error") {
2173 print "<div width=\"100%\" align='center'>";
2174 $msg = $_GET["msg"];
2175 print $msg;
2176 print "</div>";
2177 }
2178
7dc66a61 2179 if ($op == "help") {
01c9c74a
AD
2180 if (!$_GET["noheaders"]) {
2181 print "<html><head>
2182 <title>Tiny Tiny RSS : Help</title>
2183 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2184 <script type=\"text/javascript\" src=\"functions.js\"></script>
2185 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2186 </head><body>";
2187 }
7dc66a61
AD
2188
2189 $tid = sprintf("%d", $_GET["tid"]);
2190
01c9c74a 2191 print "<div class='infoBoxContents'>";
7dc66a61 2192
01c9c74a
AD
2193 if (file_exists("help/$tid.php")) {
2194 include("help/$tid.php");
2195 } else {
2196 print "<p>Help topic not found.</p>";
2197 }
7dc66a61 2198
01c9c74a 2199 print "</div>";
7dc66a61
AD
2200
2201 print "<div align='center'>
01c9c74a
AD
2202 <input type='submit' class='button'
2203 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
7dc66a61 2204
01c9c74a
AD
2205 if (!$_GET["noheaders"]) {
2206 print "</body></html>";
2207 }
7dc66a61
AD
2208
2209 }
2210
f84a97a3
AD
2211 if ($op == "dlg") {
2212 $id = $_GET["id"];
6de5d056 2213 $param = $_GET["param"];
f84a97a3
AD
2214
2215 if ($id == "quickAddFeed") {
76332f3c
AD
2216 print "
2217 Feed URL: <input
033e47e0
AD
2218 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2219 id=\"qafInput\">
f84a97a3
AD
2220 <input class=\"button\"
2221 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
2222 <input class=\"button\"
2223 type=\"submit\" onclick=\"javascript:closeDlg()\"
2224 value=\"Cancel\">";
2225 }
6de5d056
AD
2226
2227 if ($id == "quickDelFeed") {
2228
2229 $param = db_escape_string($param);
2230
2231 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
2232
2233 if ($result) {
2234
2235 $f_title = db_fetch_result($result, 0, "title");
2236
76332f3c 2237 print "Remove current feed (<b>$f_title</b>)?&nbsp;
6de5d056
AD
2238 <input class=\"button\"
2239 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
2240 <input class=\"button\"
2241 type=\"submit\" onclick=\"javascript:closeDlg()\"
2242 value=\"Cancel\">";
2243 } else {
2244 print "Error: Feed $param not found.&nbsp;
2245 <input class=\"button\"
2246 type=\"submit\" onclick=\"javascript:closeDlg()\"
2247 value=\"Cancel\">";
2248 }
2249 }
2250
033e47e0
AD
2251 if ($id == "search") {
2252
2253 print "<input id=\"searchbox\" class=\"extSearch\"
2254 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2255 onchange=\"javascript:search()\">
2256 <select id=\"searchmodebox\">
2257 <option selected>All feeds</option>
2258 <option>This feed</option>
2259 </select>
2260 <input type=\"submit\"
2261 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
2262 <input class=\"button\"
2263 type=\"submit\" onclick=\"javascript:closeDlg()\"
2264 value=\"Close\">";
2265
2266 }
2267
f84a97a3
AD
2268 }
2269
a2770077
AD
2270 // update feeds of all users, may be used anonymously
2271 if ($op == "globalUpdateFeeds") {
2272
2273 $result = db_query($link, "SELECT id FROM ttrss_users");
2274
2275 while ($line = db_fetch_assoc($result)) {
2276 $user_id = $line["id"];
2277// print "<!-- updating feeds of uid $user_id -->";
2278 update_all_feeds($link, false, $user_id);
2279 }
e65af9c1 2280
a2770077
AD
2281 print "<rpc-reply>
2282 <message msg=\"All feeds updated\"/>
2283 </rpc-reply>";
e65af9c1
AD
2284
2285 }
2286
77e96719
AD
2287 if ($op == "pref-prefs") {
2288
b1895692 2289 $subop = $_REQUEST["subop"];
77e96719
AD
2290
2291 if ($subop == "Save configuration") {
2292
d2892032
AD
2293 if (WEB_DEMO_MODE) {
2294 header("Location: prefs.php");
2295 return;
2296 }
01d68cf9 2297
93cb4442
AD
2298 $_SESSION["prefs_op_result"] = "save-config";
2299
77e96719
AD
2300 foreach (array_keys($_POST) as $pref_name) {
2301
2302 $pref_name = db_escape_string($pref_name);
2303 $value = db_escape_string($_POST[$pref_name]);
2304
2305 $result = db_query($link, "SELECT type_name
2306 FROM ttrss_prefs,ttrss_prefs_types
2307 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
2308
2309 if (db_num_rows($result) > 0) {
2310
2311 $type_name = db_fetch_result($result, 0, "type_name");
2312
5da169d9
AD
2313// print "$pref_name : $type_name : $value<br>";
2314
77e96719 2315 if ($type_name == "bool") {
5da169d9 2316 if ($value == "1") {
77e96719
AD
2317 $value = "true";
2318 } else {
2319 $value = "false";
2320 }
2321 } else if ($type_name == "integer") {
2322 $value = sprintf("%d", $value);
2323 }
2324
2325// print "$pref_name : $type_name : $value<br>";
2326
ff485f1d
AD
2327 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
2328 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
77e96719
AD
2329
2330 }
2331
2332 header("Location: prefs.php");
2333
2334 }
2335
b1895692
AD
2336 } else if ($subop == "getHelp") {
2337
2338 $pref_name = db_escape_string($_GET["pn"]);
2339
2340 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
2341 WHERE pref_name = '$pref_name'");
2342
2343 if (db_num_rows($result) > 0) {
2344 $help_text = db_fetch_result($result, 0, "help_text");
2345 print $help_text;
2346 } else {
2347 print "Unknown option: $pref_name";
2348 }
2349
1c7f75ed
AD
2350 } else if ($subop == "Change password") {
2351
d2892032
AD
2352 if (WEB_DEMO_MODE) {
2353 header("Location: prefs.php");
2354 return;
2355 }
1c7f75ed
AD
2356
2357 $old_pw = $_POST["OLD_PASSWORD"];
2358 $new_pw = $_POST["OLD_PASSWORD"];
2359
2360 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
2361 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
2362
2363 $active_uid = $_SESSION["uid"];
2364
2365 if ($old_pw && $new_pw) {
2366
2367 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
2368
2369 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
2370 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
2371 pwd_hash = '$old_pw_hash')");
2372
2373 if (db_num_rows($result) == 1) {
2374 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
2375 WHERE id = '$active_uid'");
b791095d
AD
2376
2377 $_SESSION["pwd_change_result"] = "ok";
2378 } else {
2379 $_SESSION["pwd_change_result"] = "failed";
1c7f75ed
AD
2380 }
2381 }
2382
2383 header("Location: prefs.php");
b791095d 2384
77e96719
AD
2385 } else if ($subop == "Reset to defaults") {
2386
d2892032
AD
2387 if (WEB_DEMO_MODE) {
2388 header("Location: prefs.php");
2389 return;
2390 }
01d68cf9 2391
93cb4442
AD
2392 $_SESSION["prefs_op_result"] = "reset-to-defaults";
2393
e1aa0559
AD
2394 if (DB_TYPE == "pgsql") {
2395 db_query($link,"UPDATE ttrss_user_prefs
2396 SET value = ttrss_prefs.def_value
2397 WHERE owner_uid = '".$_SESSION["uid"]."' AND
2398 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
2399 } else {
2400 db_query($link, "DELETE FROM ttrss_user_prefs
2401 WHERE owner_uid = ".$_SESSION["uid"]);
2402 initialize_user_prefs($link, $_SESSION["uid"]);
2403 }
5da169d9 2404
77e96719
AD
2405 header("Location: prefs.php");
2406
58f8ad54
AD
2407 } else if ($subop == "Change theme") {
2408
2409 $theme = db_escape_string($_POST["theme"]);
2410
2411 if ($theme == "Default") {
2412 $theme_qpart = 'NULL';
2413 } else {
2414 $theme_qpart = "'$theme'";
2415 }
2416
6752e330
AD
2417 $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
2418 WHERE theme_name = '$theme'");
2419
2420 if (db_num_rows($result) == 1) {
2421 $theme_id = db_fetch_result($result, 0, "id");
2422 $theme_path = db_fetch_result($result, 0, "theme_path");
2423 } else {
2424 $theme_id = "NULL";
2425 $theme_path = "";
2426 }
2427
58f8ad54 2428 db_query($link, "UPDATE ttrss_users SET
6752e330 2429 theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
58f8ad54 2430
6752e330 2431 $_SESSION["theme"] = $theme_path;
503eb349 2432
58f8ad54
AD
2433 header("Location: prefs.php");
2434
77e96719
AD
2435 } else {
2436
7d4c898a 2437 if (!SINGLE_USER_MODE) {
1c7f75ed 2438
a029d530
AD
2439 $result = db_query($link, "SELECT id FROM ttrss_users
2440 WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR
2441 pwd_hash = 'SHA1:".sha1("password")."')");
2442
2443 if (db_num_rows($result) != 0) {
b791095d 2444 print "<div class=\"warning\">
a029d530
AD
2445 Your password is at default value, please change it.
2446 </div>";
2447 }
2448
b791095d
AD
2449 if ($_SESSION["pwd_change_result"] == "failed") {
2450 print "<div class=\"warning\">
2451 There was an error while changing your password.
2452 </div>";
2453 }
2454
2455 if ($_SESSION["pwd_change_result"] == "ok") {
2456 print "<div class=\"notice\">
2457 Password changed successfully.
2458 </div>";
2459 }
2460
2461 $_SESSION["pwd_change_result"] = "";
2462
93cb4442
AD
2463 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
2464 print "<div class=\"notice\">
2465 Your configuration was reset to defaults.
2466 </div>";
2467 }
2468
2469 if ($_SESSION["prefs_op_result"] == "save-config") {
2470 print "<div class=\"notice\">
2471 Your configuration was saved successfully.
2472 </div>";
2473 }
2474
2475 $_SESSION["prefs_op_result"] = "";
2476
7d4c898a
AD
2477 print "<form action=\"backend.php\" method=\"POST\">";
2478
2479 print "<table width=\"100%\" class=\"prefPrefsList\">";
2480 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
2481
2482 print "<tr><td width=\"40%\">Old password</td>";
2483 print "<td><input class=\"editbox\" type=\"password\"
2484 name=\"OLD_PASSWORD\"></td></tr>";
2485
2486 print "<tr><td width=\"40%\">New password</td>";
2487
2488 print "<td><input class=\"editbox\" type=\"password\"
2489 name=\"NEW_PASSWORD\"></td></tr>";
2490
2491 print "</table>";
2492
2493 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2494
2495 print "<p><input class=\"button\" type=\"submit\"
2496 value=\"Change password\" name=\"subop\">";
2497
2498 print "</form>";
1c7f75ed 2499
7d4c898a 2500 }
1c7f75ed 2501
58f8ad54
AD
2502 $result = db_query($link, "SELECT
2503 theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
2504
2505 $user_theme_id = db_fetch_result($result, 0, "theme_id");
2506
2507 $result = db_query($link, "SELECT
2508 id,theme_name FROM ttrss_themes ORDER BY theme_name");
2509
2510 if (db_num_rows($result) > 0) {
6752e330
AD
2511
2512 print "<form action=\"backend.php\" method=\"POST\">";
2513 print "<table width=\"100%\" class=\"prefPrefsList\">";
2514 print "<tr><td colspan='3'><h3>Themes</h3></tr></td>";
2515 print "<tr><td width=\"40%\">Select theme</td>";
2516 print "<td><select name=\"theme\">";
2517 print "<option>Default</option>";
58f8ad54 2518 print "<option disabled>--------</option>";
6752e330 2519
58f8ad54
AD
2520 while ($line = db_fetch_assoc($result)) {
2521 if ($line["id"] == $user_theme_id) {
2522 $selected = "selected";
2523 } else {
2524 $selected = "";
2525 }
2526 print "<option $selected>" . $line["theme_name"] . "</option>";
2527 }
6752e330
AD
2528 print "</select></td></tr>";
2529 print "</table>";
2530 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2531 print "<p><input class=\"button\" type=\"submit\"
2532 value=\"Change theme\" name=\"subop\">";
2533 print "</form>";
58f8ad54
AD
2534 }
2535
77e96719 2536 $result = db_query($link, "SELECT
ff485f1d 2537 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
77e96719 2538 section_name,def_value
ff485f1d 2539 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
77e96719 2540 WHERE type_id = ttrss_prefs_types.id AND
ff485f1d 2541 section_id = ttrss_prefs_sections.id AND
a2411bd9
AD
2542 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
2543 owner_uid = ".$_SESSION["uid"]."
650bc435 2544 ORDER BY section_id,short_desc");
77e96719
AD
2545
2546 print "<form action=\"backend.php\" method=\"POST\">";
2547
77e96719
AD
2548 $lnum = 0;
2549
2550 $active_section = "";
2551
2552 while ($line = db_fetch_assoc($result)) {
2553
2554 if ($active_section != $line["section_name"]) {
59a654ba
AD
2555
2556 if ($active_section != "") {
1c7f75ed 2557 print "</table>";
59a654ba 2558 }
1c7f75ed
AD
2559
2560 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
59a654ba
AD
2561
2562 $active_section = $line["section_name"];
2563
77e96719 2564 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
59a654ba
AD
2565// print "<tr class=\"title\">
2566// <td width=\"25%\">Option</td><td>Value</td></tr>";
7268adf7
AD
2567
2568 $lnum = 0;
77e96719
AD
2569 }
2570
650bc435 2571// $class = ($lnum % 2) ? "even" : "odd";
77e96719 2572
650bc435 2573 print "<tr>";
77e96719 2574
77e96719
AD
2575 $type_name = $line["type_name"];
2576 $pref_name = $line["pref_name"];
2577 $value = $line["value"];
2578 $def_value = $line["def_value"];
b1895692
AD
2579 $help_text = $line["help_text"];
2580
2581 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
2582
2583 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
2584
2585 print "</td>";
77e96719
AD
2586
2587 print "<td>";
2588
2589 if ($type_name == "bool") {
2590// print_select($pref_name, $value, array("true", "false"));
2591
2592 if ($value == "true") {
2593 $value = "Yes";
2594 } else {
2595 $value = "No";
2596 }
2597
2598 print_radio($pref_name, $value, array("Yes", "No"));
2599
2600 } else {
2601 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
2602 }
2603
2604 print "</td>";
2605
2606 print "</tr>";
2607
2608 $lnum++;
2609 }
2610
2611 print "</table>";
2612
2613 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2614
2615 print "<p><input class=\"button\" type=\"submit\"
2616 name=\"subop\" value=\"Save configuration\">";
2617
2618 print "&nbsp;<input class=\"button\" type=\"submit\"
2619 name=\"subop\" value=\"Reset to defaults\"></p>";
2620
2621 print "</form>";
2622
2623 }
2624
2625 }
2626
e6cb77a0
AD
2627 if ($op == "pref-users") {
2628
2629 $subop = $_GET["subop"];
2630
2631 if ($subop == "editSave") {
2632
2633 if (!WEB_DEMO_MODE) {
2634
2635 $login = db_escape_string($_GET["l"]);
2636 $uid = db_escape_string($_GET["id"]);
2637 $access_level = sprintf("%d", $_GET["al"]);
2638
2639 db_query($link, "UPDATE ttrss_users SET login = '$login', access_level = '$access_level' WHERE id = '$uid'");
2640
2641 }
2642 } else if ($subop == "remove") {
2643
2644 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
2645
2646 $ids = split(",", $_GET["ids"]);
2647
2648 foreach ($ids as $id) {
2649 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
2650
2651 }
2652 }
2653 } else if ($subop == "add") {
2654
2655 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
2656
b6b535ca 2657 $login = db_escape_string(trim($_GET["login"]));
e6cb77a0
AD
2658 $tmp_user_pwd = make_password(8);
2659 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
2660
2661 db_query($link, "INSERT INTO ttrss_users (login,pwd_hash,access_level)
2662 VALUES ('$login', '$pwd_hash', 0)");
2663
2664
2665 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
2666 login = '$login' AND pwd_hash = '$pwd_hash'");
2667
2668 if (db_num_rows($result) == 1) {
2669
2670 $new_uid = db_fetch_result($result, 0, "id");
2671
2672 print "<div class=\"notice\">Added user <b>".$_GET["login"].
2673 "</b> with password <b>$tmp_user_pwd</b>.</div>";
2674
2675 initialize_user($link, $new_uid);
2676
2677 } else {
2678
2679 print "<div class=\"warning\">Error while adding user <b>".
2680 $_GET["login"].".</b></div>";
2681
2682 }
2683 }
2684 } else if ($subop == "resetPass") {
2685
2686 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
2687
2688 $uid = db_escape_string($_GET["id"]);
2689
2690 $result = db_query($link, "SELECT login FROM ttrss_users WHERE id = '$uid'");
2691
2692 $login = db_fetch_result($result, 0, "login");
2693 $tmp_user_pwd = make_password(8);
2694 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
2695
2696 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
2697 WHERE id = '$uid'");
2698
2699 print "<div class=\"notice\">Changed password of
2700 user <b>$login</b> to <b>$tmp_user_pwd</b>.</div>";
2701
2702 }
2703 }
2704
2c7070b5
AD
2705 print "<div class=\"prefGenericAddBox\">
2706 <input id=\"uadd_box\" size=\"40\">&nbsp;";
e6cb77a0 2707
2c7070b5
AD
2708 print"<input type=\"submit\" class=\"button\"
2709 onclick=\"javascript:addUser()\" value=\"Add user\"></div>";
e6cb77a0
AD
2710
2711 $result = db_query($link, "SELECT
fe99ab12
AD
2712 id,login,access_level,
2713 SUBSTRING(last_login,1,16) as last_login
e6cb77a0
AD
2714 FROM
2715 ttrss_users
2716 ORDER by login");
2717
2317ffaa 2718 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
1a7572cb 2719
f4fe2cde
AD
2720 print "<p><table width=\"100%\" cellspacing=\"0\"
2721 class=\"prefUserList\" id=\"prefUserList\">";
e6cb77a0 2722
35f3c923
AD
2723 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2724 Select:
2725 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
3055bc41 2726 'UMRR-', 'UMCHK-', true)\">All</a>,
35f3c923 2727 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
3055bc41 2728 'UMRR-', 'UMCHK-', false)\">None</a>
35f3c923
AD
2729 </td</tr>";
2730
e6cb77a0 2731 print "<tr class=\"title\">
f6f32198
AD
2732 <td width=\"5%\">Select</td>
2733 <td width='30%'>Username</td>
2734 <td width='30%'>Access Level</td>
2735 <td width='30%'>Last login</td></tr>";
e6cb77a0
AD
2736
2737 $lnum = 0;
2738
2739 while ($line = db_fetch_assoc($result)) {
2740
2741 $class = ($lnum % 2) ? "even" : "odd";
2742
2743 $uid = $line["id"];
2744 $edit_uid = $_GET["id"];
2745
2746 if ($uid == $_SESSION["uid"] || ($subop == "edit" && $uid != $edit_uid)) {
2747 $class .= "Grayed";
53226edc
AD
2748 $this_row_id = "";
2749 } else {
2750 $this_row_id = "id=\"UMRR-$uid\"";
2751 }
2752
2753 print "<tr class=\"$class\" $this_row_id>";
e6cb77a0
AD
2754
2755 $line["login"] = htmlspecialchars($line["login"]);
2756
2757 if ($uid == $_SESSION["uid"]) {
2758
2759 print "<td><input disabled=\"true\" type=\"checkbox\"
2760 id=\"UMCHK-".$line["id"]."\"></td>";
2761
2762 print "<td>".$line["login"]."</td>";
2763 print "<td>".$line["access_level"]."</td>";
e6cb77a0
AD
2764
2765 } else if (!$edit_uid || $subop != "edit") {
2766
2767 print "<td><input onclick='toggleSelectRow(this);'
1a7572cb 2768 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
e6cb77a0
AD
2769
2770 print "<td><a href=\"javascript:editUser($uid);\">" .
2771 $line["login"] . "</td>";
2772
2773 print "<td><a href=\"javascript:editUser($uid);\">" .
2774 $line["access_level"] . "</td>";
2775
2776 } else if ($uid != $edit_uid) {
2777
2778 print "<td><input disabled=\"true\" type=\"checkbox\"
2779 id=\"UMCHK-".$line["id"]."\"></td>";
2780
2781 print "<td>".$line["login"]."</td>";
2782 print "<td>".$line["access_level"]."</td>";
2783
2784 } else {
2785
2786 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2787
2788 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
2789 "\"></td>";
2790
2791 print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"].
2792 "\"></td>";
2793
2794 }
2795
f6f32198
AD
2796 print "<td>".$line["last_login"]."</td>";
2797
e6cb77a0
AD
2798 print "</tr>";
2799
2800 ++$lnum;
2801 }
2802
2803 print "</table>";
2804
2805 print "<p>";
2806
2807 if ($subop == "edit") {
2808 print "Edit label:
2809 <input type=\"submit\" class=\"button\"
2810 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">
2811 <input type=\"submit\" class=\"button\"
2812 onclick=\"javascript:userEditSave()\" value=\"Save\">";
2813
2814 } else {
2815
2816 print "
2817 Selection:
2818 <input type=\"submit\" class=\"button\"
717f5e64 2819 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
e6cb77a0
AD
2820 <input type=\"submit\" class=\"button\"
2821 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
2822 <input type=\"submit\" class=\"button\"
717f5e64
AD
2823 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
2824 <input type=\"submit\" class=\"button\"
2825 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
2826
2827 }
2828 }
2829
2830 if ($op == "user-details") {
2831
2832 if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) {
2833 return;
2834 }
2835
1a7572cb 2836/* print "<html><head>
717f5e64
AD
2837 <title>Tiny Tiny RSS : User Details</title>
2838 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2839 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1a7572cb 2840 </head><body>"; */
717f5e64
AD
2841
2842 $uid = sprintf("%d", $_GET["id"]);
2843
c6c3a07f 2844 print "<div class='infoBoxContents'>";
717f5e64 2845
fe99ab12
AD
2846 $result = db_query($link, "SELECT login,
2847 SUBSTRING(last_login,1,16) AS last_login,
2848 access_level,
c6c3a07f
AD
2849 (SELECT COUNT(int_id) FROM ttrss_user_entries
2850 WHERE owner_uid = id) AS stored_articles
717f5e64
AD
2851 FROM ttrss_users
2852 WHERE id = '$uid'");
2853
2854 if (db_num_rows($result) == 0) {
2855 print "<h1>User not found</h1>";
2856 return;
2857 }
2858
2859 print "<h1>User Details</h1>";
2860
2861 print "<table width='100%'>";
2862
2863 $login = db_fetch_result($result, 0, "login");
2864 $last_login = db_fetch_result($result, 0, "last_login");
2865 $access_level = db_fetch_result($result, 0, "access_level");
c6c3a07f 2866 $stored_articles = db_fetch_result($result, 0, "stored_articles");
717f5e64
AD
2867
2868 print "<tr><td>Username</td><td>$login</td></tr>";
2869 print "<tr><td>Access level</td><td>$access_level</td></tr>";
2870 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
c6c3a07f 2871 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
717f5e64
AD
2872
2873 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
2874 WHERE owner_uid = '$uid'");
2875
2876 $num_feeds = db_fetch_result($result, 0, "num_feeds");
2877
2878 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
2879
5d15d3ea 2880/* $result = db_query($link, "SELECT
717f5e64 2881 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
c6c3a07f
AD
2882 FROM ttrss_user_entries,ttrss_entries
2883 WHERE owner_uid = '$uid' AND ref_id = id");
717f5e64 2884
d9f115c3 2885 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
717f5e64 2886
c6c3a07f 2887 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
717f5e64
AD
2888
2889 print "</table>";
2890
2891 print "<h1>Subscribed feeds</h1>";
2892
2893 $result = db_query($link, "SELECT id,title,feed_url FROM ttrss_feeds
d9f115c3 2894 WHERE owner_uid = '$uid' ORDER BY title");
717f5e64
AD
2895
2896 print "<ul class=\"nomarks\">";
2897
2898 while ($line = db_fetch_assoc($result)) {
2899
2900 $icon_file = ICONS_URL."/".$line["id"].".ico";
2901
2902 if (file_exists($icon_file) && filesize($icon_file) > 0) {
6c56687e 2903 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
717f5e64 2904 } else {
5951ded1 2905 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
717f5e64
AD
2906 }
2907
2908 print "<li>$feed_icon&nbsp;<a href=\"".$line["feed_url"]."\">".$line["title"]."</a></li>";
e6cb77a0 2909 }
717f5e64
AD
2910
2911 print "</ul>";
2912
717f5e64
AD
2913 print "</div>";
2914
1a7572cb
AD
2915 print "<div align='center'>
2916 <input type='submit' class='button'
c6c3a07f 2917 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
1a7572cb
AD
2918
2919// print "</body></html>";
717f5e64 2920
e6cb77a0
AD
2921 }
2922
c6c3a07f
AD
2923 if ($op == "feed-details") {
2924
2925 $feed_id = $_GET["id"];
2926
2927 $result = db_query($link,
2928 "SELECT
f324892e 2929 title,feed_url,last_updated,icon_url,site_url,
c6c3a07f
AD
2930 (SELECT COUNT(int_id) FROM ttrss_user_entries
2931 WHERE feed_id = id) AS total,
2932 (SELECT COUNT(int_id) FROM ttrss_user_entries
2933 WHERE feed_id = id AND unread = true) AS unread,
2934 (SELECT COUNT(int_id) FROM ttrss_user_entries
2935 WHERE feed_id = id AND marked = true) AS marked
2936 FROM ttrss_feeds
2937 WHERE id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]);
2938
2939 if (db_num_rows($result) == 0) return;
2940
2941 $title = db_fetch_result($result, 0, "title");
2942 $last_updated = db_fetch_result($result, 0, "last_updated");
2943 $feed_url = db_fetch_result($result, 0, "feed_url");
4fec9fd7 2944 $icon_url = db_fetch_result($result, 0, "icon_url");
c6c3a07f
AD
2945 $total = db_fetch_result($result, 0, "total");
2946 $unread = db_fetch_result($result, 0, "unread");
2947 $marked = db_fetch_result($result, 0, "marked");
f324892e 2948 $site_url = db_fetch_result($result, 0, "site_url");
4fec9fd7
AD
2949
2950 $result = db_query($link, "SELECT COUNT(id) AS subscribed
2951 FROM ttrss_feeds WHERE feed_url = '$feed_url'");
2952
2953 $subscribed = db_fetch_result($result, 0, "subscribed");
2954
2955 print "<div class=\"infoBoxContents\">";
2956
2957 $icon_file = ICONS_DIR . "/$feed_id.ico";
2958
2959 if (file_exists($icon_file) && filesize($icon_file) > 0) {
2960 $feed_icon = "<img width=\"16\" height=\"16\"
2961 src=\"" . ICONS_URL . "/$feed_id.ico\">";
2962 } else {
2963 $feed_icon = "";
2964 }
2965
2966 print "<h1>$feed_icon $title</h1>";
c6c3a07f
AD
2967
2968 print "<table width='100%'>";
2969
f324892e
AD
2970 if ($site_url) {
2971 print "<tr><td width='30%'>Link</td>
2972 <td><a href=\"$site_url\">$site_url</a>
2973 <a href=\"$feed_url\">(feed)</a></td>
2974 </td></tr>";
2975 } else {
2976 print "<tr><td width='30%'>Feed URL</td>
2977 <td><a href=\"$feed_url\">$feed_url</a></td></tr>";
2978 }
c6c3a07f
AD
2979 print "<tr><td>Last updated</td><td>$last_updated</td></tr>";
2980 print "<tr><td>Total articles</td><td>$total</td></tr>";
2981 print "<tr><td>Unread articles</td><td>$unread</td></tr>";
2982 print "<tr><td>Starred articles</td><td>$marked</td></tr>";
4fec9fd7 2983 print "<tr><td>Subscribed users</td><td>$subscribed</td></tr>";
c6c3a07f
AD
2984
2985 print "</table>";
2986
bffdddd0
AD
2987 $result = db_query($link, "SELECT title,
2988 SUBSTRING(updated,1,16) AS updated,unread
bca02305
AD
2989 FROM ttrss_entries,ttrss_user_entries
2990 WHERE ref_id = id AND feed_id = '$feed_id'
c565e1ef 2991 ORDER BY date_entered DESC LIMIT 5");
c6c3a07f 2992
bca02305
AD
2993 if (db_num_rows($result) > 0) {
2994
2995 print "<h1>Latest headlines</h1>";
c6c3a07f 2996
bca02305
AD
2997 print "<ul class=\"nomarks\">";
2998
2999 while ($line = db_fetch_assoc($result)) {
c565e1ef
AD
3000 if ($line["unread"] == "t" || $line["unread"] == "1") {
3001 $line["title"] = "<b>" . $line["title"] . "</b>";
3002 }
bca02305
AD
3003 print "<li>" . $line["title"].
3004 "&nbsp;<span class=\"insensitive\">(" .$line["updated"].")</span></li>";
3005 }
3006
3007 print "</ul>";
3008
3009 print "</div>";
3010
3011 print "<div align='center'>
3012 <input type='submit' class='button'
3013 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3014 }
c6c3a07f
AD
3015 }
3016
4b3dff6e 3017 db_close($link);
1cd17194 3018?>
406d9489
AD
3019
3020<!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->
3021