]> git.wh0rd.org - tt-rss.git/blame - backend.php
support for changing category of selected feeds, misc RPC security fixes and prefs...
[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 475
f932bc9f 476 $ids = split(",", db_escape_string($_GET["ids"]));
c3b81db0 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
f932bc9f 503 $ids = split(",", db_escape_string($_GET["ids"]));
1572afe5
AD
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"];
adccd201
AD
686 $omode = $_GET["omode"];
687
688 if ($omode == "xml") {
689 header("Content-Type: application/xml");
690 }
a1a8a2be 691
8d7008c7 692 if (!$feed) {
8d7008c7
AD
693 return;
694 }
695
ac53063a
AD
696 if (!$skip) $skip = 0;
697
476cac42 698 if ($subop == "undefined") $subop = "";
1cd17194 699
f0601b87
AD
700 if ($addheader) {
701 print "<html><head>
ac43eba1 702 <title>Tiny Tiny RSS : Feed $feed</title>
430bf183
AD
703 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
704
503eb349
AD
705 $user_theme = $_SESSION["theme"];
706 if ($user_theme) {
707 print "<link rel=\"stylesheet\" type=\"text/css\"
708 href=\"themes/$user_theme/theme.css\">";
709 }
710
4769ddaf 711 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
430bf183
AD
712 print "<link rel=\"stylesheet\"
713 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
714
715 } else {
716 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
717 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
718 }
503eb349 719
430bf183 720 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
f0601b87
AD
721 <script type=\"text/javascript\" src=\"functions.js\"></script>
722 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
b623b3ed 723 </head><body onload='init()'>";
f0601b87
AD
724 }
725
dcee8f61
AD
726 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
727
728 $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
729 WHERE id = '$feed'");
730
731 $feed_url = db_fetch_result($tmp_result, 0, "feed_url");
732
733 update_rss_feed($link, $feed_url, $feed);
734
735 }
736
0e32076b 737 if ($subop == "MarkAllRead") {
d76a3b03 738
0e32076b
AD
739 if (sprintf("%d", $feed) != 0) {
740
741 if ($feed > 0) {
f23a2177 742 db_query($link, "UPDATE ttrss_user_entries
0e32076b 743 SET unread = false,last_read = NOW()
f23a2177 744 WHERE feed_id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
0e32076b
AD
745
746 } else if ($feed < 0 && $feed > -10) { // special, like starred
747
748 if ($feed == -1) {
f23a2177 749 db_query($link, "UPDATE ttrss_user_entries
0e32076b 750 SET unread = false,last_read = NOW()
5859be02 751 WHERE marked = true AND owner_uid = ".$_SESSION["uid"]);
0e32076b
AD
752 }
753
754 } else if ($feed < -10) { // label
755
f23a2177
AD
756 // TODO make this more efficient
757
7db95187 758 $label_id = -$feed - 11;
0e32076b 759
7db95187 760 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
f23a2177 761 WHERE id = '$label_id'");
7db95187
AD
762
763 if ($tmp_result) {
764 $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp");
765
f23a2177
AD
766 db_query($link, "BEGIN");
767
768 $tmp2_result = db_query($link,
769 "SELECT
770 int_id
771 FROM
772 ttrss_user_entries,ttrss_entries
773 WHERE
774 ref_id = id AND
775 $sql_exp AND
776 owner_uid = " . $_SESSION["uid"]);
777
778 while ($tmp_line = db_fetch_assoc($tmp2_result)) {
779 db_query($link, "UPDATE
780 ttrss_user_entries
781 SET
782 unread = false, last_read = NOW()
783 WHERE
784 int_id = " . $tmp_line["int_id"]);
785 }
786
787 db_query($link, "COMMIT");
788
789/* db_query($link, "UPDATE ttrss_user_entries,ttrss_entries
7db95187 790 SET unread = false,last_read = NOW()
f23a2177
AD
791 WHERE $sql_exp
792 AND ref_id = id
793 AND owner_uid = ".$_SESSION["uid"]); */
7db95187 794 }
254e0e4b 795 }
0e32076b 796 } else { // tag
7eec90cf
AD
797 db_query($link, "BEGIN");
798
799 $tag_name = db_escape_string($feed);
800
801 $result = db_query($link, "SELECT post_int_id FROM ttrss_tags
802 WHERE tag_name = '$tag_name' AND owner_uid = " . $_SESSION["uid"]);
803
804 while ($line = db_fetch_assoc($result)) {
805 db_query($link, "UPDATE ttrss_user_entries SET
806 unread = false, last_read = NOW()
807 WHERE int_id = " . $line["post_int_id"]);
808 }
809 db_query($link, "COMMIT");
a1a8a2be 810 }
0e32076b 811
a1a8a2be 812 }
d76a3b03 813
f932bc9f
AD
814 $search = db_escape_string($_GET["search"]);
815 $search_mode = db_escape_string($_GET["smode"]);
52b51244 816
f175937c 817 if ($search) {
ac53063a
AD
818 $search_query_part = "(upper(title) LIKE upper('%$search%')
819 OR content LIKE '%$search%') AND";
f175937c
AD
820 } else {
821 $search_query_part = "";
822 }
823
824 $view_query_part = "";
825
826 if ($view_mode == "Starred") {
827 $view_query_part = " marked = true AND ";
ac53063a
AD
828 }
829
ac43eba1
AD
830 if ($view_mode == "Unread") {
831 $view_query_part = " unread = true AND ";
832 }
833
b5aa95e7
AD
834 if ($view_mode == "Unread or Starred") {
835 $view_query_part = " (unread = true OR marked = true) AND ";
836 }
837
bdd01d3f
AD
838 if ($view_mode == "Unread or Updated") {
839 $view_query_part = " (unread = true OR last_read is NULL) AND ";
840 }
841
254e0e4b 842/* $result = db_query($link, "SELECT count(id) AS total_entries
36bf7496
AD
843 FROM ttrss_entries WHERE
844 $search_query_part
845 feed_id = '$feed'");
e6d1c0a0 846
254e0e4b 847 $total_entries = db_fetch_result($result, 0, "total_entries"); */
e6d1c0a0 848
648472a7 849/* $result = db_query("SELECT count(id) AS unread_entries
ac43eba1
AD
850 FROM ttrss_entries WHERE
851 $search_query_part
852 unread = true AND
853 feed_id = '$feed'");
854
648472a7 855 $unread_entries = db_fetch_result($result, 0, "unread_entries"); */
ac43eba1 856
8d7008c7 857 if ($limit && $limit != "All") {
82c9223c 858 $limit_query_part = "LIMIT " . $limit;
ad3cb710 859 }
f0601b87 860
254e0e4b
AD
861 $vfeed_query_part = "";
862
52b51244 863 // override query strategy and enable feed display when searching globally
d3416913 864 if ($search && $search_mode == "All feeds") {
52b51244
AD
865 $query_strategy_part = "id > 0";
866 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
867 id = feed_id) as feed_title,";
868 } else if (sprintf("%d", $feed) == 0) {
8143ae1f
AD
869 $query_strategy_part = "ttrss_entries.id > 0";
870 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
871 id = feed_id) as feed_title,";
872 } else if ($feed >= 0) {
254e0e4b 873 $query_strategy_part = "feed_id = '$feed'";
48f0adb0 874 } else if ($feed == -1) { // starred virtual feed
254e0e4b 875 $query_strategy_part = "marked = true";
48f0adb0
AD
876 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
877 id = feed_id) as feed_title,";
878 } else if ($feed <= -10) { // labels
879 $label_id = -$feed - 11;
880
881 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
882 WHERE id = '$label_id'");
883
884 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
885
254e0e4b
AD
886 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
887 id = feed_id) as feed_title,";
888 } else {
48f0adb0 889 $query_strategy_part = "id > 0"; // dumb
254e0e4b
AD
890 }
891
f99321a3
AD
892 $order_by = "updated DESC";
893
894// if ($feed < -10) {
895// $order_by = "feed_id,updated DESC";
896// }
897
1572afe5
AD
898 $feed_title = "";
899
900 if ($search && $search_mode == "All feeds") {
901 $feed_title = "Search results";
902 } else if (sprintf("%d", $feed) == 0) {
903 $feed_title = $feed;
904 } else if ($feed > 0) {
905 $result = db_query($link, "SELECT title,site_url FROM ttrss_feeds
906 WHERE id = '$feed'");
907
908 $feed_title = db_fetch_result($result, 0, "title");
909 $feed_site_url = db_fetch_result($result, 0, "site_url");
910
911 } else if ($feed == -1) {
912 $feed_title = "Starred articles";
913 } else if ($feed < -10) {
914 $label_id = -$feed - 11;
915 $result = db_query($link, "SELECT description FROM ttrss_labels
916 WHERE id = '$label_id'");
917 $feed_title = db_fetch_result($result, 0, "description");
918 } else {
919 $feed_title = "?";
920 }
921
48f0adb0
AD
922 if ($feed < -10) error_reporting (0);
923
8143ae1f
AD
924 if (sprintf("%d", $feed) != 0) {
925
21703604
AD
926 if ($feed > 0) {
927 $feed_kind = "Feeds";
928 } else {
929 $feed_kind = "Labels";
930 }
931
bd34c528
AD
932 if (!$vfeed_query_part) {
933 $content_query_part = "content as content_preview,";
934 } else {
935 $content_query_part = "";
936 }
937
8143ae1f 938 $result = db_query($link, "SELECT
1572afe5
AD
939 id,title,
940 SUBSTRING(updated,1,16) as updated,
941 unread,feed_id,marked,link,last_read,
8143ae1f
AD
942 SUBSTRING(last_read,1,19) as last_read_noms,
943 $vfeed_query_part
bd34c528
AD
944 $content_query_part
945 SUBSTRING(updated,1,19) as updated_noms
8143ae1f 946 FROM
4c193675 947 ttrss_entries,ttrss_user_entries
8143ae1f 948 WHERE
4c193675 949 ttrss_user_entries.ref_id = ttrss_entries.id AND
aee86c2e 950 owner_uid = '".$_SESSION["uid"]."' AND
8143ae1f
AD
951 $search_query_part
952 $view_query_part
953 $query_strategy_part ORDER BY $order_by
954 $limit_query_part");
955
956 } else {
957 // browsing by tag
958
21703604
AD
959 $feed_kind = "Tags";
960
8143ae1f 961 $result = db_query($link, "SELECT
1572afe5
AD
962 ttrss_entries.id as id,title,
963 SUBSTRING(updated,1,16) as updated,
964 unread,feed_id,
8143ae1f 965 marked,link,last_read,
c05a19f3 966 SUBSTRING(last_read,1,19) as last_read_noms,
254e0e4b 967 $vfeed_query_part
bd34c528
AD
968 $content_query_part
969 SUBSTRING(updated,1,19) as updated_noms
8143ae1f 970 FROM
05732aa0 971 ttrss_entries,ttrss_user_entries,ttrss_tags
8143ae1f 972 WHERE
05732aa0
AD
973 ref_id = ttrss_entries.id AND
974 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
975 post_int_id = int_id AND tag_name = '$feed' AND
8143ae1f
AD
976 $view_query_part
977 $search_query_part
978 $query_strategy_part ORDER BY $order_by
979 $limit_query_part");
980 }
d76a3b03 981
48f0adb0 982 if (!$result) {
adccd201
AD
983 if ($omode != "xml") {
984 print "<div align='center'>
985 Could not display feed (query failed). Please check label match syntax or local configuration.</div>";
986 return;
987 } else {
988 print "<error error-code=\"8\"/>";
48f0adb0 989
adccd201
AD
990 }
991 }
992
f56ec297
AD
993 if (db_num_rows($result) > 0) {
994
adccd201
AD
995 if ($omode != "xml") {
996
997 print "<table class=\"headlinesSubToolbar\"
998 width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
999
1000 print "<td class=\"headlineActions\">
1001 Select:
1002 <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList',
1003 'RROW-', 'RCHK-', true)\">All</a>,
1004 <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList',
1005 'RROW-', 'RCHK-', true, 'Unread')\">Unread</a>,
1006 <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList',
1007 'RROW-', 'RCHK-', false)\">None</a>
1008 &nbsp;&nbsp;
1009 Toggle: <a href=\"javascript:toggleUnread()\">Unread</a>,
1010 <a href=\"javascript:toggleStarred()\">Starred</a>";
1011
1012 print "</td>";
1013
1014 print "<td class=\"headlineTitle\">";
1015
1016 if ($feed_site_url) {
1017 print "<a target=\"_blank\" href=\"$feed_site_url\">$feed_title</a>";
1018 } else {
1019 print $feed_title;
1020 }
1021
1022 print "</td>";
1023 print "</tr></table>";
1024
1025 print "<table class=\"headlinesList\" id=\"headlinesList\"
1026 cellspacing=\"0\" width=\"100%\">";
1027
f4c10d44 1028 } else {
adccd201 1029 print "<headlines feed=\"$feed\" title=\"$feed_title\" site_url=\"$feed_site_url\">";
f4c10d44 1030 }
e5a99b88
AD
1031
1032 $lnum = 0;
1033
1034 error_reporting (DEFAULT_ERROR_LEVEL);
1035
1036 $num_unread = 0;
1037
1038 while ($line = db_fetch_assoc($result)) {
adccd201 1039
e5a99b88
AD
1040 $class = ($lnum % 2) ? "even" : "odd";
1041
1042 $id = $line["id"];
1043 $feed_id = $line["feed_id"];
1044
1045 if ($line["last_read"] == "" &&
1046 ($line["unread"] != "t" && $line["unread"] != "1")) {
1047
1048 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
1049 alt=\"Updated\">";
1050 } else {
1051 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
1052 alt=\"Updated\">";
1053 }
1054
1055 if ($line["unread"] == "t" || $line["unread"] == "1") {
1056 $class .= "Unread";
1057 ++$num_unread;
adccd201
AD
1058 $is_unread = 'true';
1059 } else {
1060 $is_unread = 'false';
e5a99b88
AD
1061 }
1062
1063 if ($line["marked"] == "t" || $line["marked"] == "1") {
1064 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
1065 alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>";
1066 } else {
1067 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
1068 alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>";
1069 }
1070
e454a889 1071 $content_link = "<a href=\"javascript:view($id,$feed_id);\">" .
e5a99b88 1072 $line["title"] . "</a>";
adccd201 1073
e5a99b88
AD
1074 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
1075 $updated_fmt = smart_date_time(strtotime($line["updated"]));
1076 } else {
1077 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1078 $updated_fmt = date($short_date, strtotime($line["updated"]));
1079 }
adccd201
AD
1080
1081 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
1082 $content_preview = truncate_string(strip_tags($line["content_preview"]), 101);
1083 }
1084
1085 if ($omode != "xml") {
1086
1087 print "<tr class='$class' id='RROW-$id'>";
1088 // onclick=\"javascript:view($id,$feed_id)\">
1089
1090 print "<td class='hlUpdatePic'>$update_pic</td>";
1091
1092 print "<td class='hlSelectRow'>
1093 <input type=\"checkbox\" onclick=\"toggleSelectRow(this)\"
1094 class=\"feedCheckBox\" id=\"RCHK-$id\">
1095 </td>";
1096
1097 print "<td class='hlMarkedPic'>$marked_pic</td>";
1098
1099 if ($line["feed_title"]) {
1100 print "<td class='hlContent'>$content_link</td>";
1101 print "<td class='hlFeed'>
1102 <a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a></td>";
1103 } else {
1104 print "<td class='hlContent'>";
1105
e454a889 1106 print "<a href=\"javascript:view($id,$feed_id);\">" .
adccd201
AD
1107 $line["title"];
1108
1109 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
1110
1111 if ($content_preview) {
1112 print "<span class=\"contentPreview\"> - $content_preview</span>";
1113 }
1114 }
1115
1116 print "</a>";
1117 print "</td>";
1118 }
1119
1120 print "<td class=\"hlUpdated\"><nobr>$updated_fmt&nbsp;</nobr></td>";
1121
1122 print "</tr>";
1123
1124 } else {
1125
1126 print "<entry unread='$is_unread' id='$id'>";
1127 print "<title><![CDATA[" . $line["title"] . "]]></title>";
1128 print "<link>" . $line["link"] . "</link>";
1129 print "<updated>$updated_fmt</updated>";
1130 if ($content_preview) {
1131 print "<preview><![CDATA[ $content_preview ]]></preview>";
1132 }
1133
1134 if ($line["feed_title"]) {
1135 print "<feed id='$feed_id'><![CDATA[" . $line["feed_title"] . "]]></feed>";
1136 }
1137 print "</entry>";
1138
1139 }
e5a99b88 1140
e5a99b88
AD
1141
1142 ++$lnum;
254e0e4b 1143 }
adccd201
AD
1144
1145 if ($omode != "xml") {
1146 print "</table>";
1147 } else {
1148 print "</headlines>";
1149 }
d76a3b03 1150
e5a99b88
AD
1151 } else {
1152 print "<div width='100%' align='center'>No articles found.</div>";
a1a8a2be 1153 }
d76a3b03 1154
adccd201 1155 if ($omode != "xml") {
d76a3b03 1156
adccd201
AD
1157 print "<script type=\"text/javascript\">
1158 document.onkeydown = hotkey_handler;
1159 update_all_counters('$feed');
1160 </script>";
1161
1162 if ($addheader) {
1163 print "</body></html>";
1164 }
f0601b87 1165 }
1cd17194
AD
1166 }
1167
0e091d38 1168 if ($op == "pref-rpc") {
331900c6 1169
0e091d38 1170 $subop = $_GET["subop"];
331900c6 1171
83fe4d6d 1172 if ($subop == "unread") {
f932bc9f 1173 $ids = split(",", db_escape_string($_GET["ids"]));
83fe4d6d 1174 foreach ($ids as $id) {
a5873b2e
AD
1175 db_query($link, "UPDATE ttrss_user_entries SET unread = true
1176 WHERE feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
83fe4d6d 1177 }
0e091d38 1178
a5873b2e 1179 print "Marked selected feeds as unread.";
83fe4d6d
AD
1180 }
1181
1182 if ($subop == "read") {
f932bc9f 1183 $ids = split(",", db_escape_string($_GET["ids"]));
83fe4d6d 1184 foreach ($ids as $id) {
a5873b2e
AD
1185 db_query($link, "UPDATE ttrss_user_entries
1186 SET unread = false,last_read = NOW() WHERE
1187 feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
83fe4d6d 1188 }
0e091d38 1189
a5873b2e 1190 print "Marked selected feeds as read.";
0e091d38
AD
1191
1192 }
1193
1194 }
1195
1196 if ($op == "pref-feeds") {
1197
1198 $subop = $_GET["subop"];
1199
508a81e1 1200 if ($subop == "editSave") {
648472a7
AD
1201 $feed_title = db_escape_string($_GET["t"]);
1202 $feed_link = db_escape_string($_GET["l"]);
d148926e 1203 $upd_intl = db_escape_string($_GET["ui"]);
5d73494a 1204 $purge_intl = db_escape_string($_GET["pi"]);
91ff844a
AD
1205 $feed_id = db_escape_string($_GET["id"]);
1206 $cat_id = db_escape_string($_GET["catid"]);
508a81e1 1207
d148926e
AD
1208 if (strtoupper($upd_intl) == "DEFAULT")
1209 $upd_intl = 0;
1210
5d73494a
AD
1211 if (strtoupper($purge_intl) == "DEFAULT")
1212 $purge_intl = 0;
1213
140aae81
AD
1214 if (strtoupper($purge_intl) == "DISABLED")
1215 $purge_intl = -1;
1216
91ff844a
AD
1217 if ($cat_id != 0) {
1218 $category_qpart = "cat_id = '$cat_id'";
1219 } else {
1220 $category_qpart = 'cat_id = NULL';
1221 }
1222
648472a7 1223 $result = db_query($link, "UPDATE ttrss_feeds SET
91ff844a 1224 $category_qpart,
d148926e 1225 title = '$feed_title', feed_url = '$feed_link',
5d73494a 1226 update_interval = '$upd_intl',
91ff844a 1227 purge_interval = '$purge_intl'
f72dbbde 1228 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
508a81e1 1229
83fe4d6d
AD
1230 }
1231
331900c6 1232 if ($subop == "remove") {
331900c6 1233
b0b4abcf 1234 if (!WEB_DEMO_MODE) {
331900c6 1235
f932bc9f 1236 $ids = split(",", db_escape_string($_GET["ids"]));
b0b4abcf
AD
1237
1238 foreach ($ids as $id) {
f72dbbde
AD
1239 db_query($link, "DELETE FROM ttrss_feeds
1240 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
4769ddaf 1241
273a2f6b 1242 $icons_dir = ICONS_DIR;
d5caaae5 1243
4769ddaf
AD
1244 if (file_exists($icons_dir . "/$id.ico")) {
1245 unlink($icons_dir . "/$id.ico");
d5caaae5 1246 }
b0b4abcf 1247 }
331900c6
AD
1248 }
1249 }
1250
1251 if ($subop == "add") {
b0b4abcf
AD
1252
1253 if (!WEB_DEMO_MODE) {
331900c6 1254
b6b535ca 1255 $feed_link = db_escape_string(trim($_GET["link"]));
331900c6 1256
648472a7 1257 $result = db_query($link,
7e9a3986
AD
1258 "SELECT id FROM ttrss_feeds
1259 WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]);
1260
1261 if (db_num_rows($result) == 0) {
1262
1263 $result = db_query($link,
1264 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title)
1265 VALUES ('".$_SESSION["uid"]."', '$feed_link', '')");
331900c6 1266
7e9a3986
AD
1267 $result = db_query($link,
1268 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'
1269 AND owner_uid = " . $_SESSION["uid"]);
1270
1271 $feed_id = db_fetch_result($result, 0, "id");
1272
1273 if ($feed_id) {
ddb68b81 1274 update_rss_feed($link, $feed_link, $feed_id, true);
7e9a3986
AD
1275 }
1276 } else {
331900c6 1277
7e9a3986
AD
1278 print "<div class=\"warning\">
1279 Feed <b>$feed_link</b> already exists in the database.
1280 </div>";
b0b4abcf
AD
1281 }
1282 }
331900c6 1283 }
a0d53889 1284
91ff844a
AD
1285 if ($subop == "addCat") {
1286
1287 if (!WEB_DEMO_MODE) {
1288
1289 $feed_cat = db_escape_string(trim($_GET["cat"]));
1290
1291 $result = db_query($link,
1292 "SELECT id FROM ttrss_feed_categories
1293 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
1294
1295 if (db_num_rows($result) == 0) {
1296
1297 $result = db_query($link,
1298 "INSERT INTO ttrss_feed_categories (owner_uid,title)
1299 VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
1300
1301 } else {
1302
1303 print "<div class=\"warning\">
1304 Category <b>$feed_cat</b> already exists in the database.
1305 </div>";
1306 }
1307
1308
1309 }
1310 }
1311
1312 if ($subop == "removeCats") {
1313
1314 if (!WEB_DEMO_MODE) {
1315
f932bc9f 1316 $ids = split(",", db_escape_string($_GET["ids"]));
91ff844a
AD
1317
1318 foreach ($ids as $id) {
1319
1320 db_query($link, "BEGIN");
1321
1322 $result = db_query($link,
1323 "SELECT count(id) as num_feeds FROM ttrss_feeds
1324 WHERE cat_id = '$id'");
1325
1326 $num_feeds = db_fetch_result($result, 0, "num_feeds");
1327
1328 if ($num_feeds == 0) {
1329 db_query($link, "DELETE FROM ttrss_feed_categories
1330 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1331 } else {
1332
1333 print "<div class=\"warning\">
1334 Unable to delete non empty feed categories.</div>";
1335
1336 }
1337
1338 db_query($link, "COMMIT");
1339 }
1340 }
1341 }
1342
f932bc9f
AD
1343 if ($subop == "categorize") {
1344
1345 if (!WEB_DEMO_MODE) {
1346
1347 $ids = split(",", db_escape_string($_GET["ids"]));
1348
1349 $cat_id = db_escape_string($_GET["cat_id"]);
1350
1351 if ($cat_id == 0) {
1352 $cat_id_qpart = 'NULL';
1353 } else {
1354 $cat_id_qpart = "'$cat_id'";
1355 }
1356
1357 db_query($link, "BEGIN");
1358
1359 foreach ($ids as $id) {
1360
1361 db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
1362 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1363 }
1364
1365 db_query($link, "COMMIT");
1366 }
1367
1368 }
1369
c64d5b03 1370// print "<h3>Edit Feeds</h3>";
91ff844a 1371
4904f845
AD
1372 $result = db_query($link, "SELECT id,title,feed_url,last_error
1373 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1374
1375 if (db_num_rows($result) > 0) {
1376
1377 print "<div class=\"warning\">";
1378
1379 print "<b>Feeds with update errors:</b>";
1380
1381 print "<ul class=\"nomarks\">";
1382
1383 while ($line = db_fetch_assoc($result)) {
1384 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
1385 $line["last_error"];
1386 }
1387
1388 print "</ul>";
1389 print "</div>";
1390
1391 }
1392
f932bc9f
AD
1393 $feed_search = db_escape_string($_GET["search"]);
1394
1395 if (array_key_exists("search", $_GET)) {
1396 $_SESSION["prefs_feed_search"] = $feed_search;
1397 } else {
1398 $feed_search = $_SESSION["prefs_feed_search"];
1399 }
1400
1401 print "<table width='100%' class=\"prefGenericAddBox\"
1402 cellspacing='0' cellpadding='0'><tr>
1403 <td>
1404 <input id=\"fadd_link\"
1405 onchange=\"javascript:addFeed()\"
1406 size=\"40\">
1407 <input type=\"submit\" class=\"button\"
1408 onclick=\"javascript:addFeed()\" value=\"Add feed\">
1409 </td><td align='right'>
1410 <input id=\"feed_search\" size=\"20\"
1411 onchange=\"javascript:updateFeedList()\"
1412 value=\"$feed_search\">
1413 <input type=\"submit\" class=\"button\"
1414 onclick=\"javascript:updateFeedList()\" value=\"Search\">
1415 </td>
1416 </tr></table>";
a0d53889 1417
b83c7545
AD
1418 $feeds_sort = db_escape_string($_GET["sort"]);
1419
1420 if (!$feeds_sort || $feeds_sort == "undefined") {
1421 $feeds_sort = $_SESSION["pref_sort_feeds"];
1422 if (!$feeds_sort) $feeds_sort = "title";
1423 }
1424
1425 $_SESSION["pref_sort_feeds"] = $feeds_sort;
1426
f932bc9f
AD
1427 if ($feed_search) {
1428 $search_qpart = "UPPER(title) LIKE UPPER('%$feed_search%') AND";
1429 } else {
1430 $search_qpart = "";
1431 }
1432
648472a7 1433 $result = db_query($link, "SELECT
d148926e 1434 id,title,feed_url,substring(last_updated,1,16) as last_updated,
91ff844a
AD
1435 update_interval,purge_interval,
1436 (SELECT title FROM ttrss_feed_categories
1437 WHERE id = cat_id) AS category
c0e5a40e 1438 FROM
f932bc9f
AD
1439 ttrss_feeds
1440 WHERE
1441 $search_qpart owner_uid = '".$_SESSION["uid"]."'
b83c7545 1442 ORDER by $feeds_sort,title");
1cd17194 1443
3b0feb9b 1444 if (db_num_rows($result) != 0) {
91ff844a 1445
3b0feb9b 1446 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
35f3c923 1447
f4fe2cde
AD
1448 print "<p><table width=\"100%\" cellspacing=\"0\"
1449 class=\"prefFeedList\" id=\"prefFeedList\">";
35f3c923
AD
1450 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1451 Select:
1452 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
3055bc41 1453 'FEEDR-', 'FRCHK-', true)\">All</a>,
35f3c923 1454 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
3055bc41 1455 'FEEDR-', 'FRCHK-', false)\">None</a>
35f3c923
AD
1456 </td</tr>";
1457
3b0feb9b 1458 print "<tr class=\"title\">
3547842a
AD
1459 <td width=\"3%\">&nbsp;</td>
1460 <td width=\"3%\">Select</td>
3b0feb9b
AD
1461 <td width=\"20%\">
1462 <a href=\"javascript:updateFeedList('title')\">Title</a></td>
1463 <td width=\"20%\">
1464 <a href=\"javascript:updateFeedList('feed_url')\">Link</a>
1465 </td>";
54d3ba50 1466
3b0feb9b
AD
1467 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1468 print "<td width=\"10%\">
1469 <a href=\"javascript:updateFeedList('category')\">Category</a></td>";
603c27f8 1470 }
603c27f8 1471
f92db4f5 1472 print "
3b0feb9b
AD
1473 <td width=\"10%\">
1474 <a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a>
1475 </td>
1476 <td width=\"10%\">
1477 <a href=\"javascript:updateFeedList('purge_interval')\">Purge Days</a>
1478 </td>
3b0feb9b
AD
1479 </tr>";
1480
c64d5b03
AD
1481 $lnum = 0;
1482
1483 while ($line = db_fetch_assoc($result)) {
1484
1485 $class = ($lnum % 2) ? "even" : "odd";
1486
3b0feb9b 1487 $feed_id = $line["id"];
c64d5b03 1488
3b0feb9b 1489 $edit_feed_id = $_GET["id"];
c64d5b03 1490
3b0feb9b 1491 if ($subop == "edit" && $feed_id != $edit_feed_id) {
c64d5b03 1492 $class .= "Grayed";
53226edc
AD
1493 $this_row_id = "";
1494 } else {
1495 $this_row_id = "id=\"FEEDR-$feed_id\"";
c64d5b03
AD
1496 }
1497
53226edc 1498 print "<tr class=\"$class\" $this_row_id>";
3b0feb9b
AD
1499
1500 $icon_file = ICONS_DIR . "/$feed_id.ico";
1501
1502 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1503 $feed_icon = "<img width=\"16\" height=\"16\"
1504 src=\"" . ICONS_URL . "/$feed_id.ico\">";
1505 } else {
1506 $feed_icon = "&nbsp;";
1507 }
1508 print "<td align='center'>$feed_icon</td>";
c64d5b03
AD
1509
1510 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
3b0feb9b
AD
1511 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
1512 $edit_cat = htmlspecialchars(db_unescape_string($line["category"]));
1513
1514 if (!$edit_cat) $edit_cat = "Uncategorized";
c64d5b03 1515
3b0feb9b 1516 if (!$edit_feed_id || $subop != "edit") {
c64d5b03
AD
1517
1518 print "<td><input onclick='toggleSelectRow(this);'
3b0feb9b 1519 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
3547842a
AD
1520
1521 $edit_title = truncate_string($edit_title, 40);
1522 $edit_link = truncate_string($edit_link, 60);
c64d5b03 1523
3b0feb9b 1524 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
c64d5b03 1525 $edit_title . "</a></td>";
3b0feb9b
AD
1526
1527 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1528 $edit_link . "</a></td>";
1529
1530 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1531 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1532 $edit_cat . "</a></td>";
1533 }
1534
1535 if ($line["update_interval"] == "0")
1536 $line["update_interval"] = "Default";
c64d5b03 1537
3b0feb9b
AD
1538 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1539 $line["update_interval"] . "</a></td>";
1540
1541 if ($line["purge_interval"] == "0")
1542 $line["purge_interval"] = "Default";
1543
1544 if ($line["purge_interval"] < 0)
1545 $line["purge_interval"] = "Disabled";
1546
1547 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1548 $line["purge_interval"] . "</a></td>";
1549
1550 } else if ($feed_id != $edit_feed_id) {
c64d5b03
AD
1551
1552 print "<td><input disabled=\"true\" type=\"checkbox\"
1553 id=\"FRCHK-".$line["id"]."\"></td>";
3547842a
AD
1554
1555 $edit_title = truncate_string($edit_title, 40);
1556 $edit_link = truncate_string($edit_link, 60);
1557
c64d5b03 1558 print "<td>$edit_title</td>";
3b0feb9b
AD
1559 print "<td>$edit_link</td>";
1560
1561 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1562 print "<td>$edit_cat</td>";
1563 }
1564
1565 if ($line["update_interval"] == "0")
1566 $line["update_interval"] = "Default";
1567
1568 print "<td>" . $line["update_interval"] . "</td>";
1569
1570 if ($line["purge_interval"] == "0")
1571 $line["purge_interval"] = "Default";
1572
1573 if ($line["purge_interval"] < 0)
1574 $line["purge_interval"] = "Disabled";
1575
1576 print "<td>" . $line["purge_interval"] . "</td>";
c64d5b03
AD
1577
1578 } else {
1579
1580 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1581
1582 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
3b0feb9b
AD
1583 print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>";
1584
1585 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1586
1587 print "<td>";
1588 print "<select id=\"iedit_fcat\">";
1589 print "<option id=\"0\">Uncategorized</option>";
1590
1591 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feed_categories
1592 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1593
1594 if (db_num_rows($tmp_result) > 0) {
1595 print "<option disabled>--------</option>";
1596 }
1597
1598 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1599 if ($tmp_line["id"] == $line["cat_id"]) {
1600 $is_selected = "selected";
1601 } else {
1602 $is_selected = "";
1603 }
1604 printf("<option $is_selected id='%d'>%s</option>",
1605 $tmp_line["id"], $tmp_line["title"]);
1606 }
1607
1608 print "</select></td>";
1609 print "</td>";
1610
1611 }
c64d5b03 1612
3b0feb9b
AD
1613 print "<td><input id=\"iedit_updintl\"
1614 value=\"".$line["update_interval"]."\"></td>";
1615 print "<td><input id=\"iedit_purgintl\"
1616 value=\"".$line["purge_interval"]."\"></td>";
1617
c64d5b03 1618 }
3b0feb9b 1619
3547842a 1620/* if (!$line["last_updated"]) $line["last_updated"] = "Never";
3b0feb9b 1621
3547842a 1622 print "<td>" . $line["last_updated"] . "</td>"; */
c64d5b03
AD
1623
1624 print "</tr>";
1625
1626 ++$lnum;
1627 }
1628
c64d5b03 1629 print "</table>";
3b0feb9b 1630
c64d5b03
AD
1631 print "<p>";
1632
3b0feb9b
AD
1633 if ($subop == "edit") {
1634 print "Edit feed:&nbsp;
c64d5b03 1635 <input type=\"submit\" class=\"button\"
3b0feb9b 1636 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
c64d5b03 1637 <input type=\"submit\" class=\"button\"
3b0feb9b
AD
1638 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
1639 } else {
c64d5b03
AD
1640
1641 print "
1642 Selection:&nbsp;
1643 <input type=\"submit\" class=\"button\"
3b0feb9b 1644 onclick=\"javascript:selectedFeedDetails()\" value=\"Details\">
c64d5b03 1645 <input type=\"submit\" class=\"button\"
3b0feb9b
AD
1646 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
1647 <input type=\"submit\" class=\"button\"
1648 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
f932bc9f
AD
1649
1650 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1651
1652 print "&nbsp;&nbsp;";
1653
1654 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
1655 WHERE owner_uid = ".$_SESSION["uid"]."
1656 ORDER BY title");
1657
1658 print "<select id=\"sfeed_set_fcat\">";
1659 print "<option id=\"0\">Uncategorized</option>";
1660
1661 if (db_num_rows($result) != 0) {
1662
1663 print "<option disabled>--------</option>";
1664
1665 while ($line = db_fetch_assoc($result)) {
1666 printf("<option id='%d'>%s</option>",
1667 $line["id"], $line["title"]);
1668 }
1669 }
1670
1671 print "</select>";
1672
1673 print " <input type=\"submit\" class=\"button\"
1674 onclick=\"javascript:categorizeSelectedFeeds()\" value=\"Set category\">";
1675
1676 }
1677
3b0feb9b
AD
1678 if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) {
1679 print "
1680 <input type=\"submit\" class=\"button\"
4f3a84f4 1681 onclick=\"javascript:readSelectedFeeds(true)\" value=\"Mark as read\">
3b0feb9b 1682 <input type=\"submit\" class=\"button\"
4f3a84f4 1683 onclick=\"javascript:readSelectedFeeds(false)\"
3b0feb9b
AD
1684 value=\"Mark as unread\">&nbsp;";
1685 }
1686
1687 print "
f932bc9f 1688 &nbsp;All feeds: <input type=\"submit\"
3b0feb9b
AD
1689 class=\"button\" onclick=\"gotoExportOpml()\"
1690 value=\"Export OPML\">";
1691 }
1692 } else {
1693
1694 print "<p>No feeds defined.</p>";
1695
1696 }
1697
1698 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1699
1700 print "<h3>Edit Categories</h3>";
1701
1702 // print "<h3>Categories</h3>";
1703
1704 print "<div class=\"prefGenericAddBox\">
f932bc9f
AD
1705 <input id=\"fadd_cat\"
1706 onchange=\"javascript:addFeedCat()\"
1707 size=\"40\">&nbsp;
1708 <input
3b0feb9b
AD
1709 type=\"submit\" class=\"button\"
1710 onclick=\"javascript:addFeedCat()\" value=\"Add category\"></div>";
1711
1712 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
1713 WHERE owner_uid = ".$_SESSION["uid"]."
1714 ORDER BY title");
1715
1716 if (db_num_rows($result) != 0) {
1717
35f3c923 1718 print "<p><table width=\"100%\" class=\"prefFeedCatList\"
f4fe2cde 1719 cellspacing=\"0\" id=\"prefFeedCatList\">";
35f3c923
AD
1720
1721 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1722 Select:
1723 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
3055bc41 1724 'FCATR-', 'FCCHK-', true)\">All</a>,
35f3c923 1725 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
3055bc41 1726 'FCATR-', 'FCCHK-', false)\">None</a>
35f3c923
AD
1727 </td</tr>";
1728
3b0feb9b
AD
1729 print "<tr class=\"title\">
1730 <td width=\"10%\">Select</td><td width=\"80%\">Title</td>
1731 </tr>";
1732
1733 $lnum = 0;
1734
1735 while ($line = db_fetch_assoc($result)) {
1736
1737 $class = ($lnum % 2) ? "even" : "odd";
1738
1739 $cat_id = $line["id"];
1740
1741 $edit_cat_id = $_GET["id"];
1742
1743 if ($subop == "editCat" && $cat_id != $edit_cat_id) {
1744 $class .= "Grayed";
53226edc
AD
1745 $this_row_id = "";
1746 } else {
1747 $this_row_id = "id=\"FCATR-$cat_id\"";
3b0feb9b
AD
1748 }
1749
53226edc 1750 print "<tr class=\"$class\" $this_row_id>";
3b0feb9b
AD
1751
1752 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1753
1754 if (!$edit_cat_id || $subop != "editCat") {
1755
1756 print "<td><input onclick='toggleSelectRow(this);'
1757 type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>";
1758
1759 print "<td><a href=\"javascript:editFeedCat($cat_id);\">" .
1760 $edit_title . "</a></td>";
1761
1762 } else if ($cat_id != $edit_cat_id) {
1763
1764 print "<td><input disabled=\"true\" type=\"checkbox\"
1765 id=\"FRCHK-".$line["id"]."\"></td>";
1766
1767 print "<td>$edit_title</td>";
1768
1769 } else {
1770
1771 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1772
1773 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
1774
1775 }
1776
1777 print "</tr>";
1778
1779 ++$lnum;
1780 }
1781
1782 print "</table>";
1783
1784 print "<p>";
1785
1786 if ($subop == "editCat") {
1787 print "Edit category:&nbsp;
1788 <input type=\"submit\" class=\"button\"
1789 onclick=\"javascript:feedCatEditCancel()\" value=\"Cancel\">
1790 <input type=\"submit\" class=\"button\"
1791 onclick=\"javascript:feedCatEditSave()\" value=\"Save\">";
1792 } else {
1793
1794 print "
1795 Selection:&nbsp;
1796 <input type=\"submit\" class=\"button\"
1797 onclick=\"javascript:editSelectedFeedCat()\" value=\"Edit\">
1798 <input type=\"submit\" class=\"button\"
1799 onclick=\"javascript:removeSelectedFeedCats()\" value=\"Remove\">";
1800
1801 }
1802
1803 } else {
1804 print "<p>No feed categories defined.</p>";
1805 }
c64d5b03
AD
1806 }
1807
1808 print "<h3>Import OPML</h3>
f5a50b25
AD
1809 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
1810 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
1811 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
1812 type=\"submit\" value=\"Import\">
1813 </form>";
1814
007bda35
AD
1815 }
1816
a0d53889
AD
1817 if ($op == "pref-filters") {
1818
1819 $subop = $_GET["subop"];
1820
1821 if ($subop == "editSave") {
a0d53889 1822
648472a7
AD
1823 $regexp = db_escape_string($_GET["r"]);
1824 $descr = db_escape_string($_GET["d"]);
1825 $match = db_escape_string($_GET["m"]);
1826 $filter_id = db_escape_string($_GET["id"]);
ead60402
AD
1827 $feed_id = db_escape_string($_GET["fid"]);
1828
1829 if (!$feed_id) {
1830 $feed_id = 'NULL';
1831 } else {
1832 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
1833 }
0afbd851 1834
648472a7 1835 $result = db_query($link, "UPDATE ttrss_filters SET
4b3dff6e 1836 reg_exp = '$regexp',
0afbd851 1837 description = '$descr',
ead60402 1838 feed_id = $feed_id,
0afbd851
AD
1839 filter_type = (SELECT id FROM ttrss_filter_types WHERE
1840 description = '$match')
1841 WHERE id = '$filter_id'");
a0d53889
AD
1842 }
1843
1844 if ($subop == "remove") {
1845
1846 if (!WEB_DEMO_MODE) {
1847
f932bc9f 1848 $ids = split(",", db_escape_string($_GET["ids"]));
a0d53889
AD
1849
1850 foreach ($ids as $id) {
648472a7 1851 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
a0d53889
AD
1852
1853 }
1854 }
1855 }
1856
1857 if ($subop == "add") {
1858
de435974 1859 if (!WEB_DEMO_MODE) {
a0d53889 1860
b6b535ca
AD
1861 $regexp = db_escape_string(trim($_GET["regexp"]));
1862 $match = db_escape_string(trim($_GET["match"]));
ead60402
AD
1863 $feed_id = db_escape_string($_GET["fid"]);
1864
1865 if (!$feed_id) {
1866 $feed_id = 'NULL';
1867 } else {
1868 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
1869 }
4401bf04 1870
648472a7 1871 $result = db_query($link,
ead60402 1872 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id) VALUES
de435974 1873 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
ead60402 1874 description = '$match'),'".$_SESSION["uid"]."', $feed_id)");
de435974 1875 }
a0d53889
AD
1876 }
1877
648472a7 1878 $result = db_query($link, "SELECT description
a0d53889
AD
1879 FROM ttrss_filter_types ORDER BY description");
1880
1881 $filter_types = array();
1882
648472a7 1883 while ($line = db_fetch_assoc($result)) {
a0d53889
AD
1884 array_push($filter_types, $line["description"]);
1885 }
1886
2c7070b5 1887 print "<div class=\"prefGenericAddBox\">
f932bc9f 1888 <input id=\"fadd_regexp\" onchange=\"javascript:addFilter()\" size=\"40\">&nbsp;";
2c7070b5 1889
ead60402
AD
1890 print_select("fadd_match", "Title", $filter_types);
1891
1892 print "&nbsp;<select id=\"fadd_feed\">";
1893
1894 print "<option selected id=\"0\">All feeds</option>";
1895
1896 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
1897 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1898
1899 if (db_num_rows($result) > 0) {
1900 print "<option disabled>--------</option>";
1901 }
1902
1903 while ($line = db_fetch_assoc($result)) {
1904 printf("<option id='%d'>%s</option>", $line["id"], $line["title"]);
1905 }
1906
2c7070b5 1907 print "</select>&nbsp;";
a0d53889 1908
2c7070b5
AD
1909 print "<input type=\"submit\"
1910 class=\"button\" onclick=\"javascript:addFilter()\"
1911 value=\"Add filter\">";
a0d53889 1912
648472a7 1913 $result = db_query($link, "SELECT
ead60402
AD
1914 ttrss_filters.id AS id,reg_exp,
1915 ttrss_filters.description AS description,
1916 ttrss_filter_types.name AS filter_type_name,
1917 ttrss_filter_types.description AS filter_type_descr,
1918 feed_id,
1919 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
a0d53889 1920 FROM
ead60402 1921 ttrss_filters,ttrss_filter_types
4356293a 1922 WHERE
ead60402
AD
1923 filter_type = ttrss_filter_types.id AND
1924 ttrss_filters.owner_uid = ".$_SESSION["uid"]."
4356293a 1925 ORDER by reg_exp");
a0d53889 1926
3b0feb9b 1927 if (db_num_rows($result) != 0) {
a0d53889 1928
f4fe2cde
AD
1929 print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\"
1930 id=\"prefFilterList\">";
35f3c923
AD
1931
1932 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1933 Select:
1934 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
3055bc41 1935 'FILRR-', 'FICHK-', true)\">All</a>,
35f3c923 1936 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
3055bc41 1937 'FILRR-', 'FICHK-', false)\">None</a>
35f3c923
AD
1938 </td</tr>";
1939
3b0feb9b
AD
1940 print "<tr class=\"title\">
1941 <td width=\"5%\">Select</td><td width=\"30%\">Filter expression</td>
1942 <td width=\"30%\">Feed</td><td width=\"10%\">Match</td>
1943 <td width=\"30%\">Description</td></tr>";
a0d53889 1944
3b0feb9b
AD
1945 $lnum = 0;
1946
1947 while ($line = db_fetch_assoc($result)) {
1948
1949 $class = ($lnum % 2) ? "even" : "odd";
1950
1951 $filter_id = $line["id"];
1952 $edit_filter_id = $_GET["id"];
1953
1954 if ($subop == "edit" && $filter_id != $edit_filter_id) {
1955 $class .= "Grayed";
53226edc
AD
1956 $this_row_id = "";
1957 } else {
1958 $this_row_id = "id=\"FILRR-$filter_id\"";
ead60402 1959 }
3b0feb9b 1960
53226edc 1961 print "<tr class=\"$class\" $this_row_id>";
3b0feb9b
AD
1962
1963 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
1964 $line["description"] = htmlspecialchars($line["description"]);
1965
1966 if (!$line["feed_title"]) $line["feed_title"] = "All feeds";
1967
1968 if (!$edit_filter_id || $subop != "edit") {
1969
1970 if (!$line["description"]) $line["description"] = "[No description]";
1971
1972 print "<td><input onclick='toggleSelectRow(this);'
1973 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
1974
1975 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1976 $line["reg_exp"] . "</td>";
1977
1978 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1979 $line["feed_title"] . "</td>";
1980
1981 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1982 $line["filter_type_descr"] . "</td>";
1983
1984 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1985 $line["description"] . "</td>";
1986
1987 } else if ($filter_id != $edit_filter_id) {
1988
1989 if (!$line["description"]) $line["description"] = "[No description]";
1990
1991 print "<td><input disabled=\"true\" type=\"checkbox\"
1992 id=\"FICHK-".$line["id"]."\"></td>";
1993
1994 print "<td>".$line["reg_exp"]."</td>";
1995 print "<td>".$line["feed_title"]."</td>";
1996 print "<td>".$line["filter_type_descr"]."</td>";
1997 print "<td>".$line["description"]."</td>";
1998
1999 } else {
2000
2001 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2002
2003 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
2004 "\"></td>";
2005
2006 print "<td>";
2007
2008 print "<select id=\"iedit_feed\">";
2009
2010 print "<option id=\"0\">All feeds</option>";
2011
2012 if (db_num_rows($result) > 0) {
2013 print "<option disabled>--------</option>";
2014 }
2015
2016 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
2017 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2018
2019 while ($tmp_line = db_fetch_assoc($tmp_result)) {
2020 if ($tmp_line["id"] == $line["feed_id"]) {
2021 $is_selected = "selected";
2022 } else {
2023 $is_selected = "";
2024 }
2025 printf("<option $is_selected id='%d'>%s</option>",
2026 $tmp_line["id"], $tmp_line["title"]);
ead60402 2027 }
3b0feb9b
AD
2028
2029 print "</select></td>";
2030
2031 print "<td>";
2032 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
2033 print "</td>";
2034
2035 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
2036 "\"></td>";
2037
2038 print "</td>";
ead60402 2039 }
3b0feb9b
AD
2040
2041 print "</tr>";
2042
2043 ++$lnum;
a0d53889 2044 }
3b0feb9b
AD
2045
2046 if ($lnum == 0) {
2047 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
2048 }
2049
2050 print "</table>";
2051
2052 print "<p>";
2053
2054 if ($subop == "edit") {
2055 print "Edit feed:
2056 <input type=\"submit\" class=\"button\"
2057 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
2058 <input type=\"submit\" class=\"button\"
2059 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
2060
2061 } else {
2062
2063 print "
2064 Selection:
e828e31e 2065 <input type=\"submit\" class=\"button\"
3b0feb9b 2066 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
e828e31e 2067 <input type=\"submit\" class=\"button\"
3b0feb9b
AD
2068 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
2069 }
2070
a0d53889
AD
2071 } else {
2072
3b0feb9b
AD
2073 print "<p>No filters defined.</p>";
2074
a0d53889
AD
2075 }
2076 }
2077
48f0adb0
AD
2078 if ($op == "pref-labels") {
2079
2080 $subop = $_GET["subop"];
2081
d9dde1d6
AD
2082 if ($subop == "test") {
2083
2084 $expr = $_GET["expr"];
2085 $descr = $_GET["descr"];
2086
2087 print "<div class='infoBoxContents'>";
2088
2089 print "<h1>Label &laquo;$descr&raquo;</h1>";
2090
2091// print "<p><b>Expression</b>: $expr</p>";
2092
2093 $result = db_query($link,
2094 "SELECT count(id) AS num_matches
2095 FROM ttrss_entries,ttrss_user_entries
2096 WHERE ($expr) AND
2097 ttrss_user_entries.ref_id = ttrss_entries.id AND
2098 owner_uid = " . $_SESSION["uid"]);
2099
2100 $num_matches = db_fetch_result($result, 0, "num_matches");;
2101
2102 if ($num_matches > 0) {
2103
a31a7b39 2104 print "<p>Query returned <b>$num_matches</b> matches, first 5 follow:</p>";
d9dde1d6
AD
2105
2106 $result = db_query($link,
2107 "SELECT title,
2108 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
2109 FROM ttrss_entries,ttrss_user_entries
2110 WHERE ($expr) AND
2111 ttrss_user_entries.ref_id = ttrss_entries.id
2112 AND owner_uid = " . $_SESSION["uid"] . "
2113 ORDER BY date_entered DESC LIMIT 5");
2114
2115 print "<ul class=\"nomarks\">";
2116 while ($line = db_fetch_assoc($result)) {
2117 print "<li>".$line["title"].
2118 " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>";
2119 }
2120 print "</ul>";
2121
2122 } else {
2123 print "<p>Query didn't return any matches.</p>";
2124 }
2125
2126 print "</div>";
2127
2128 print "<div align='center'>
2129 <input type='submit' class='button'
2130 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2131 return;
2132 }
2133
48f0adb0
AD
2134 if ($subop == "editSave") {
2135
2136 $sql_exp = $_GET["s"];
2137 $descr = $_GET["d"];
2138 $label_id = db_escape_string($_GET["id"]);
2139
2140// print "$sql_exp : $descr : $label_id";
2141
2142 $result = db_query($link, "UPDATE ttrss_labels SET
2143 sql_exp = '$sql_exp',
2144 description = '$descr'
2145 WHERE id = '$label_id'");
2146 }
2147
2148 if ($subop == "remove") {
2149
2150 if (!WEB_DEMO_MODE) {
2151
f932bc9f 2152 $ids = split(",", db_escape_string($_GET["ids"]));
48f0adb0
AD
2153
2154 foreach ($ids as $id) {
2155 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
2156
2157 }
2158 }
2159 }
2160
2161 if ($subop == "add") {
2162
2163 if (!WEB_DEMO_MODE) {
2164
4401bf04
AD
2165 // no escaping is done here on purpose
2166 $exp = trim($_GET["exp"]);
48f0adb0
AD
2167
2168 $result = db_query($link,
4356293a
AD
2169 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
2170 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
48f0adb0
AD
2171 }
2172 }
2173
2c7070b5
AD
2174 print "<div class=\"prefGenericAddBox\">
2175 <input size=\"40\" id=\"ladd_expr\">&nbsp;";
48f0adb0 2176
2c7070b5
AD
2177 print"<input type=\"submit\" class=\"button\"
2178 onclick=\"javascript:addLabel()\" value=\"Add label\"></div>";
48f0adb0
AD
2179
2180 $result = db_query($link, "SELECT
2181 id,sql_exp,description
2182 FROM
4356293a
AD
2183 ttrss_labels
2184 WHERE
2185 owner_uid = ".$_SESSION["uid"]."
2186 ORDER by description");
48f0adb0 2187
d9dde1d6
AD
2188 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
2189
3b0feb9b 2190 if (db_num_rows($result) != 0) {
48f0adb0 2191
f4fe2cde
AD
2192 print "<p><table width=\"100%\" cellspacing=\"0\"
2193 class=\"prefLabelList\" id=\"prefLabelList\">";
35f3c923
AD
2194
2195 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2196 Select:
2197 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
3055bc41 2198 'LILRR-', 'LICHK-', true)\">All</a>,
35f3c923 2199 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
3055bc41 2200 'LILRR-', 'LICHK-', false)\">None</a>
35f3c923
AD
2201 </td</tr>";
2202
3b0feb9b
AD
2203 print "<tr class=\"title\">
2204 <td width=\"5%\">Select</td><td width=\"40%\">SQL expression
01c9c74a 2205 <a class=\"helpLink\" href=\"javascript:displayHelpInfobox(1)\">(?)</a>
3b0feb9b
AD
2206 </td>
2207 <td width=\"40%\">Caption</td></tr>";
2208
2209 $lnum = 0;
2210
2211 while ($line = db_fetch_assoc($result)) {
2212
2213 $class = ($lnum % 2) ? "even" : "odd";
2214
2215 $label_id = $line["id"];
2216 $edit_label_id = $_GET["id"];
2217
2218 if ($subop == "edit" && $label_id != $edit_label_id) {
2219 $class .= "Grayed";
53226edc
AD
2220 $this_row_id = "";
2221 } else {
2222 $this_row_id = "id=\"LILRR-$label_id\"";
3b0feb9b
AD
2223 }
2224
53226edc 2225 print "<tr class=\"$class\" $this_row_id>";
3b0feb9b
AD
2226
2227 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
2228 $line["description"] = htmlspecialchars($line["description"]);
2229
2230 if (!$edit_label_id || $subop != "edit") {
2231
2232 if (!$line["description"]) $line["description"] = "[No caption]";
2233
2234 print "<td><input onclick='toggleSelectRow(this);'
2235 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
2236
2237 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2238 $line["sql_exp"] . "</td>";
48f0adb0 2239
3b0feb9b
AD
2240 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2241 $line["description"] . "</td>";
2242
2243 } else if ($label_id != $edit_label_id) {
2244
2245 if (!$line["description"]) $line["description"] = "[No description]";
2246
2247 print "<td><input disabled=\"true\" type=\"checkbox\"
2248 id=\"LICHK-".$line["id"]."\"></td>";
2249
2250 print "<td>".$line["sql_exp"]."</td>";
2251 print "<td>".$line["description"]."</td>";
2252
2253 } else {
2254
2255 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2256
2257 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
2258 "\"></td>";
2259
2260 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
2261 "\"></td>";
2262
2263 }
2264
48f0adb0 2265
3b0feb9b
AD
2266 print "</tr>";
2267
2268 ++$lnum;
2269 }
2270
2271 if ($lnum == 0) {
2272 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
2273 }
2274
2275 print "</table>";
2276
2277 print "<p>";
2278
2279 if ($subop == "edit") {
2280 print "Edit label:
d9dde1d6
AD
2281 <input type=\"submit\" class=\"button\"
2282 onclick=\"javascript:labelTest()\" value=\"Test\">
3b0feb9b
AD
2283 <input type=\"submit\" class=\"button\"
2284 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
2285 <input type=\"submit\" class=\"button\"
2286 onclick=\"javascript:labelEditSave()\" value=\"Save\">";
2287
2288 } else {
2289
2290 print "
2291 Selection:
48f0adb0 2292 <input type=\"submit\" class=\"button\"
3b0feb9b 2293 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
48f0adb0 2294 <input type=\"submit\" class=\"button\"
3b0feb9b
AD
2295 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
2296 }
48f0adb0 2297 } else {
3b0feb9b 2298 print "<p>No labels defined.</p>";
48f0adb0
AD
2299 }
2300 }
2301
e828e31e
AD
2302 if ($op == "error") {
2303 print "<div width=\"100%\" align='center'>";
2304 $msg = $_GET["msg"];
2305 print $msg;
2306 print "</div>";
2307 }
2308
7dc66a61 2309 if ($op == "help") {
01c9c74a
AD
2310 if (!$_GET["noheaders"]) {
2311 print "<html><head>
2312 <title>Tiny Tiny RSS : Help</title>
2313 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2314 <script type=\"text/javascript\" src=\"functions.js\"></script>
2315 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2316 </head><body>";
2317 }
7dc66a61
AD
2318
2319 $tid = sprintf("%d", $_GET["tid"]);
2320
01c9c74a 2321 print "<div class='infoBoxContents'>";
7dc66a61 2322
01c9c74a
AD
2323 if (file_exists("help/$tid.php")) {
2324 include("help/$tid.php");
2325 } else {
2326 print "<p>Help topic not found.</p>";
2327 }
7dc66a61 2328
01c9c74a 2329 print "</div>";
7dc66a61
AD
2330
2331 print "<div align='center'>
01c9c74a
AD
2332 <input type='submit' class='button'
2333 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
7dc66a61 2334
01c9c74a
AD
2335 if (!$_GET["noheaders"]) {
2336 print "</body></html>";
2337 }
7dc66a61
AD
2338
2339 }
2340
f84a97a3
AD
2341 if ($op == "dlg") {
2342 $id = $_GET["id"];
6de5d056 2343 $param = $_GET["param"];
f84a97a3
AD
2344
2345 if ($id == "quickAddFeed") {
76332f3c
AD
2346 print "
2347 Feed URL: <input
033e47e0
AD
2348 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2349 id=\"qafInput\">
f84a97a3
AD
2350 <input class=\"button\"
2351 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
2352 <input class=\"button\"
2353 type=\"submit\" onclick=\"javascript:closeDlg()\"
2354 value=\"Cancel\">";
2355 }
6de5d056
AD
2356
2357 if ($id == "quickDelFeed") {
2358
2359 $param = db_escape_string($param);
2360
2361 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
2362
2363 if ($result) {
2364
2365 $f_title = db_fetch_result($result, 0, "title");
2366
76332f3c 2367 print "Remove current feed (<b>$f_title</b>)?&nbsp;
6de5d056
AD
2368 <input class=\"button\"
2369 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
2370 <input class=\"button\"
2371 type=\"submit\" onclick=\"javascript:closeDlg()\"
2372 value=\"Cancel\">";
2373 } else {
2374 print "Error: Feed $param not found.&nbsp;
2375 <input class=\"button\"
2376 type=\"submit\" onclick=\"javascript:closeDlg()\"
2377 value=\"Cancel\">";
2378 }
2379 }
2380
033e47e0
AD
2381 if ($id == "search") {
2382
2383 print "<input id=\"searchbox\" class=\"extSearch\"
2384 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2385 onchange=\"javascript:search()\">
2386 <select id=\"searchmodebox\">
2387 <option selected>All feeds</option>
2388 <option>This feed</option>
2389 </select>
2390 <input type=\"submit\"
2391 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
2392 <input class=\"button\"
2393 type=\"submit\" onclick=\"javascript:closeDlg()\"
2394 value=\"Close\">";
2395
2396 }
2397
f84a97a3
AD
2398 }
2399
a2770077
AD
2400 // update feeds of all users, may be used anonymously
2401 if ($op == "globalUpdateFeeds") {
2402
2403 $result = db_query($link, "SELECT id FROM ttrss_users");
2404
2405 while ($line = db_fetch_assoc($result)) {
2406 $user_id = $line["id"];
2407// print "<!-- updating feeds of uid $user_id -->";
2408 update_all_feeds($link, false, $user_id);
2409 }
e65af9c1 2410
a2770077
AD
2411 print "<rpc-reply>
2412 <message msg=\"All feeds updated\"/>
2413 </rpc-reply>";
e65af9c1
AD
2414
2415 }
2416
77e96719
AD
2417 if ($op == "pref-prefs") {
2418
b1895692 2419 $subop = $_REQUEST["subop"];
77e96719
AD
2420
2421 if ($subop == "Save configuration") {
2422
d2892032
AD
2423 if (WEB_DEMO_MODE) {
2424 header("Location: prefs.php");
2425 return;
2426 }
01d68cf9 2427
93cb4442
AD
2428 $_SESSION["prefs_op_result"] = "save-config";
2429
77e96719
AD
2430 foreach (array_keys($_POST) as $pref_name) {
2431
2432 $pref_name = db_escape_string($pref_name);
2433 $value = db_escape_string($_POST[$pref_name]);
2434
2435 $result = db_query($link, "SELECT type_name
2436 FROM ttrss_prefs,ttrss_prefs_types
2437 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
2438
2439 if (db_num_rows($result) > 0) {
2440
2441 $type_name = db_fetch_result($result, 0, "type_name");
2442
5da169d9
AD
2443// print "$pref_name : $type_name : $value<br>";
2444
77e96719 2445 if ($type_name == "bool") {
5da169d9 2446 if ($value == "1") {
77e96719
AD
2447 $value = "true";
2448 } else {
2449 $value = "false";
2450 }
2451 } else if ($type_name == "integer") {
2452 $value = sprintf("%d", $value);
2453 }
2454
2455// print "$pref_name : $type_name : $value<br>";
2456
ff485f1d
AD
2457 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
2458 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
77e96719
AD
2459
2460 }
2461
2462 header("Location: prefs.php");
2463
2464 }
2465
b1895692
AD
2466 } else if ($subop == "getHelp") {
2467
2468 $pref_name = db_escape_string($_GET["pn"]);
2469
2470 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
2471 WHERE pref_name = '$pref_name'");
2472
2473 if (db_num_rows($result) > 0) {
2474 $help_text = db_fetch_result($result, 0, "help_text");
2475 print $help_text;
2476 } else {
2477 print "Unknown option: $pref_name";
2478 }
2479
1c7f75ed
AD
2480 } else if ($subop == "Change password") {
2481
d2892032
AD
2482 if (WEB_DEMO_MODE) {
2483 header("Location: prefs.php");
2484 return;
2485 }
1c7f75ed
AD
2486
2487 $old_pw = $_POST["OLD_PASSWORD"];
2488 $new_pw = $_POST["OLD_PASSWORD"];
2489
2490 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
2491 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
2492
2493 $active_uid = $_SESSION["uid"];
2494
2495 if ($old_pw && $new_pw) {
2496
2497 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
2498
2499 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
2500 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
2501 pwd_hash = '$old_pw_hash')");
2502
2503 if (db_num_rows($result) == 1) {
2504 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
2505 WHERE id = '$active_uid'");
b791095d
AD
2506
2507 $_SESSION["pwd_change_result"] = "ok";
2508 } else {
2509 $_SESSION["pwd_change_result"] = "failed";
1c7f75ed
AD
2510 }
2511 }
2512
2513 header("Location: prefs.php");
b791095d 2514
77e96719
AD
2515 } else if ($subop == "Reset to defaults") {
2516
d2892032
AD
2517 if (WEB_DEMO_MODE) {
2518 header("Location: prefs.php");
2519 return;
2520 }
01d68cf9 2521
93cb4442
AD
2522 $_SESSION["prefs_op_result"] = "reset-to-defaults";
2523
e1aa0559
AD
2524 if (DB_TYPE == "pgsql") {
2525 db_query($link,"UPDATE ttrss_user_prefs
2526 SET value = ttrss_prefs.def_value
2527 WHERE owner_uid = '".$_SESSION["uid"]."' AND
2528 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
2529 } else {
2530 db_query($link, "DELETE FROM ttrss_user_prefs
2531 WHERE owner_uid = ".$_SESSION["uid"]);
2532 initialize_user_prefs($link, $_SESSION["uid"]);
2533 }
5da169d9 2534
77e96719
AD
2535 header("Location: prefs.php");
2536
58f8ad54
AD
2537 } else if ($subop == "Change theme") {
2538
2539 $theme = db_escape_string($_POST["theme"]);
2540
2541 if ($theme == "Default") {
2542 $theme_qpart = 'NULL';
2543 } else {
2544 $theme_qpart = "'$theme'";
2545 }
2546
6752e330
AD
2547 $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
2548 WHERE theme_name = '$theme'");
2549
2550 if (db_num_rows($result) == 1) {
2551 $theme_id = db_fetch_result($result, 0, "id");
2552 $theme_path = db_fetch_result($result, 0, "theme_path");
2553 } else {
2554 $theme_id = "NULL";
2555 $theme_path = "";
2556 }
2557
58f8ad54 2558 db_query($link, "UPDATE ttrss_users SET
6752e330 2559 theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
58f8ad54 2560
6752e330 2561 $_SESSION["theme"] = $theme_path;
503eb349 2562
58f8ad54
AD
2563 header("Location: prefs.php");
2564
77e96719
AD
2565 } else {
2566
7d4c898a 2567 if (!SINGLE_USER_MODE) {
1c7f75ed 2568
a029d530
AD
2569 $result = db_query($link, "SELECT id FROM ttrss_users
2570 WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR
2571 pwd_hash = 'SHA1:".sha1("password")."')");
2572
2573 if (db_num_rows($result) != 0) {
b791095d 2574 print "<div class=\"warning\">
a029d530
AD
2575 Your password is at default value, please change it.
2576 </div>";
2577 }
2578
b791095d
AD
2579 if ($_SESSION["pwd_change_result"] == "failed") {
2580 print "<div class=\"warning\">
2581 There was an error while changing your password.
2582 </div>";
2583 }
2584
2585 if ($_SESSION["pwd_change_result"] == "ok") {
2586 print "<div class=\"notice\">
2587 Password changed successfully.
2588 </div>";
2589 }
2590
2591 $_SESSION["pwd_change_result"] = "";
2592
93cb4442
AD
2593 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
2594 print "<div class=\"notice\">
2595 Your configuration was reset to defaults.
2596 </div>";
2597 }
2598
2599 if ($_SESSION["prefs_op_result"] == "save-config") {
2600 print "<div class=\"notice\">
2601 Your configuration was saved successfully.
2602 </div>";
2603 }
2604
2605 $_SESSION["prefs_op_result"] = "";
2606
7d4c898a
AD
2607 print "<form action=\"backend.php\" method=\"POST\">";
2608
2609 print "<table width=\"100%\" class=\"prefPrefsList\">";
2610 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
2611
2612 print "<tr><td width=\"40%\">Old password</td>";
2613 print "<td><input class=\"editbox\" type=\"password\"
2614 name=\"OLD_PASSWORD\"></td></tr>";
2615
2616 print "<tr><td width=\"40%\">New password</td>";
2617
2618 print "<td><input class=\"editbox\" type=\"password\"
2619 name=\"NEW_PASSWORD\"></td></tr>";
2620
2621 print "</table>";
2622
2623 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2624
2625 print "<p><input class=\"button\" type=\"submit\"
2626 value=\"Change password\" name=\"subop\">";
2627
2628 print "</form>";
1c7f75ed 2629
7d4c898a 2630 }
1c7f75ed 2631
58f8ad54
AD
2632 $result = db_query($link, "SELECT
2633 theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
2634
2635 $user_theme_id = db_fetch_result($result, 0, "theme_id");
2636
2637 $result = db_query($link, "SELECT
2638 id,theme_name FROM ttrss_themes ORDER BY theme_name");
2639
2640 if (db_num_rows($result) > 0) {
6752e330
AD
2641
2642 print "<form action=\"backend.php\" method=\"POST\">";
2643 print "<table width=\"100%\" class=\"prefPrefsList\">";
2644 print "<tr><td colspan='3'><h3>Themes</h3></tr></td>";
2645 print "<tr><td width=\"40%\">Select theme</td>";
2646 print "<td><select name=\"theme\">";
2647 print "<option>Default</option>";
58f8ad54 2648 print "<option disabled>--------</option>";
6752e330 2649
58f8ad54
AD
2650 while ($line = db_fetch_assoc($result)) {
2651 if ($line["id"] == $user_theme_id) {
2652 $selected = "selected";
2653 } else {
2654 $selected = "";
2655 }
2656 print "<option $selected>" . $line["theme_name"] . "</option>";
2657 }
6752e330
AD
2658 print "</select></td></tr>";
2659 print "</table>";
2660 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2661 print "<p><input class=\"button\" type=\"submit\"
2662 value=\"Change theme\" name=\"subop\">";
2663 print "</form>";
58f8ad54
AD
2664 }
2665
77e96719 2666 $result = db_query($link, "SELECT
ff485f1d 2667 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
77e96719 2668 section_name,def_value
ff485f1d 2669 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
77e96719 2670 WHERE type_id = ttrss_prefs_types.id AND
ff485f1d 2671 section_id = ttrss_prefs_sections.id AND
a2411bd9
AD
2672 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
2673 owner_uid = ".$_SESSION["uid"]."
650bc435 2674 ORDER BY section_id,short_desc");
77e96719
AD
2675
2676 print "<form action=\"backend.php\" method=\"POST\">";
2677
77e96719
AD
2678 $lnum = 0;
2679
2680 $active_section = "";
2681
2682 while ($line = db_fetch_assoc($result)) {
2683
2684 if ($active_section != $line["section_name"]) {
59a654ba
AD
2685
2686 if ($active_section != "") {
1c7f75ed 2687 print "</table>";
59a654ba 2688 }
1c7f75ed
AD
2689
2690 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
59a654ba
AD
2691
2692 $active_section = $line["section_name"];
2693
77e96719 2694 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
59a654ba
AD
2695// print "<tr class=\"title\">
2696// <td width=\"25%\">Option</td><td>Value</td></tr>";
7268adf7
AD
2697
2698 $lnum = 0;
77e96719
AD
2699 }
2700
650bc435 2701// $class = ($lnum % 2) ? "even" : "odd";
77e96719 2702
650bc435 2703 print "<tr>";
77e96719 2704
77e96719
AD
2705 $type_name = $line["type_name"];
2706 $pref_name = $line["pref_name"];
2707 $value = $line["value"];
2708 $def_value = $line["def_value"];
b1895692
AD
2709 $help_text = $line["help_text"];
2710
2711 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
2712
2713 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
2714
2715 print "</td>";
77e96719
AD
2716
2717 print "<td>";
2718
2719 if ($type_name == "bool") {
2720// print_select($pref_name, $value, array("true", "false"));
2721
2722 if ($value == "true") {
2723 $value = "Yes";
2724 } else {
2725 $value = "No";
2726 }
2727
2728 print_radio($pref_name, $value, array("Yes", "No"));
2729
2730 } else {
2731 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
2732 }
2733
2734 print "</td>";
2735
2736 print "</tr>";
2737
2738 $lnum++;
2739 }
2740
2741 print "</table>";
2742
2743 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2744
2745 print "<p><input class=\"button\" type=\"submit\"
2746 name=\"subop\" value=\"Save configuration\">";
2747
2748 print "&nbsp;<input class=\"button\" type=\"submit\"
2749 name=\"subop\" value=\"Reset to defaults\"></p>";
2750
2751 print "</form>";
2752
2753 }
2754
2755 }
2756
e6cb77a0
AD
2757 if ($op == "pref-users") {
2758
2759 $subop = $_GET["subop"];
2760
2761 if ($subop == "editSave") {
2762
2763 if (!WEB_DEMO_MODE) {
2764
2765 $login = db_escape_string($_GET["l"]);
2766 $uid = db_escape_string($_GET["id"]);
2767 $access_level = sprintf("%d", $_GET["al"]);
2768
2769 db_query($link, "UPDATE ttrss_users SET login = '$login', access_level = '$access_level' WHERE id = '$uid'");
2770
2771 }
2772 } else if ($subop == "remove") {
2773
2774 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
2775
f932bc9f 2776 $ids = split(",", db_escape_string($_GET["ids"]));
e6cb77a0
AD
2777
2778 foreach ($ids as $id) {
2779 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
2780
2781 }
2782 }
2783 } else if ($subop == "add") {
2784
2785 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
2786
b6b535ca 2787 $login = db_escape_string(trim($_GET["login"]));
e6cb77a0
AD
2788 $tmp_user_pwd = make_password(8);
2789 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
2790
2791 db_query($link, "INSERT INTO ttrss_users (login,pwd_hash,access_level)
2792 VALUES ('$login', '$pwd_hash', 0)");
2793
2794
2795 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
2796 login = '$login' AND pwd_hash = '$pwd_hash'");
2797
2798 if (db_num_rows($result) == 1) {
2799
2800 $new_uid = db_fetch_result($result, 0, "id");
2801
2802 print "<div class=\"notice\">Added user <b>".$_GET["login"].
2803 "</b> with password <b>$tmp_user_pwd</b>.</div>";
2804
2805 initialize_user($link, $new_uid);
2806
2807 } else {
2808
2809 print "<div class=\"warning\">Error while adding user <b>".
2810 $_GET["login"].".</b></div>";
2811
2812 }
2813 }
2814 } else if ($subop == "resetPass") {
2815
2816 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
2817
2818 $uid = db_escape_string($_GET["id"]);
2819
2820 $result = db_query($link, "SELECT login FROM ttrss_users WHERE id = '$uid'");
2821
2822 $login = db_fetch_result($result, 0, "login");
2823 $tmp_user_pwd = make_password(8);
2824 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
2825
2826 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
2827 WHERE id = '$uid'");
2828
2829 print "<div class=\"notice\">Changed password of
2830 user <b>$login</b> to <b>$tmp_user_pwd</b>.</div>";
2831
2832 }
2833 }
2834
2c7070b5 2835 print "<div class=\"prefGenericAddBox\">
f932bc9f 2836 <input id=\"uadd_box\" onchange=\"javascript:addUser()\" size=\"40\">&nbsp;";
e6cb77a0 2837
2c7070b5
AD
2838 print"<input type=\"submit\" class=\"button\"
2839 onclick=\"javascript:addUser()\" value=\"Add user\"></div>";
e6cb77a0
AD
2840
2841 $result = db_query($link, "SELECT
fe99ab12
AD
2842 id,login,access_level,
2843 SUBSTRING(last_login,1,16) as last_login
e6cb77a0
AD
2844 FROM
2845 ttrss_users
2846 ORDER by login");
2847
2317ffaa 2848 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
1a7572cb 2849
f4fe2cde
AD
2850 print "<p><table width=\"100%\" cellspacing=\"0\"
2851 class=\"prefUserList\" id=\"prefUserList\">";
e6cb77a0 2852
35f3c923
AD
2853 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2854 Select:
2855 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
3055bc41 2856 'UMRR-', 'UMCHK-', true)\">All</a>,
35f3c923 2857 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
3055bc41 2858 'UMRR-', 'UMCHK-', false)\">None</a>
35f3c923
AD
2859 </td</tr>";
2860
e6cb77a0 2861 print "<tr class=\"title\">
f6f32198
AD
2862 <td width=\"5%\">Select</td>
2863 <td width='30%'>Username</td>
2864 <td width='30%'>Access Level</td>
2865 <td width='30%'>Last login</td></tr>";
e6cb77a0
AD
2866
2867 $lnum = 0;
2868
2869 while ($line = db_fetch_assoc($result)) {
2870
2871 $class = ($lnum % 2) ? "even" : "odd";
2872
2873 $uid = $line["id"];
2874 $edit_uid = $_GET["id"];
2875
2876 if ($uid == $_SESSION["uid"] || ($subop == "edit" && $uid != $edit_uid)) {
2877 $class .= "Grayed";
53226edc
AD
2878 $this_row_id = "";
2879 } else {
2880 $this_row_id = "id=\"UMRR-$uid\"";
2881 }
2882
2883 print "<tr class=\"$class\" $this_row_id>";
e6cb77a0
AD
2884
2885 $line["login"] = htmlspecialchars($line["login"]);
2886
2887 if ($uid == $_SESSION["uid"]) {
2888
2889 print "<td><input disabled=\"true\" type=\"checkbox\"
2890 id=\"UMCHK-".$line["id"]."\"></td>";
2891
2892 print "<td>".$line["login"]."</td>";
2893 print "<td>".$line["access_level"]."</td>";
e6cb77a0
AD
2894
2895 } else if (!$edit_uid || $subop != "edit") {
2896
2897 print "<td><input onclick='toggleSelectRow(this);'
1a7572cb 2898 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
e6cb77a0
AD
2899
2900 print "<td><a href=\"javascript:editUser($uid);\">" .
2901 $line["login"] . "</td>";
2902
2903 print "<td><a href=\"javascript:editUser($uid);\">" .
2904 $line["access_level"] . "</td>";
2905
2906 } else if ($uid != $edit_uid) {
2907
2908 print "<td><input disabled=\"true\" type=\"checkbox\"
2909 id=\"UMCHK-".$line["id"]."\"></td>";
2910
2911 print "<td>".$line["login"]."</td>";
2912 print "<td>".$line["access_level"]."</td>";
2913
2914 } else {
2915
2916 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2917
2918 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
2919 "\"></td>";
2920
2921 print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"].
2922 "\"></td>";
2923
2924 }
2925
f6f32198
AD
2926 print "<td>".$line["last_login"]."</td>";
2927
e6cb77a0
AD
2928 print "</tr>";
2929
2930 ++$lnum;
2931 }
2932
2933 print "</table>";
2934
2935 print "<p>";
2936
2937 if ($subop == "edit") {
2938 print "Edit label:
2939 <input type=\"submit\" class=\"button\"
2940 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">
2941 <input type=\"submit\" class=\"button\"
2942 onclick=\"javascript:userEditSave()\" value=\"Save\">";
2943
2944 } else {
2945
2946 print "
2947 Selection:
2948 <input type=\"submit\" class=\"button\"
717f5e64 2949 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
e6cb77a0
AD
2950 <input type=\"submit\" class=\"button\"
2951 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
2952 <input type=\"submit\" class=\"button\"
717f5e64
AD
2953 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
2954 <input type=\"submit\" class=\"button\"
2955 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
2956
2957 }
2958 }
2959
2960 if ($op == "user-details") {
2961
2962 if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) {
2963 return;
2964 }
2965
1a7572cb 2966/* print "<html><head>
717f5e64
AD
2967 <title>Tiny Tiny RSS : User Details</title>
2968 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2969 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1a7572cb 2970 </head><body>"; */
717f5e64
AD
2971
2972 $uid = sprintf("%d", $_GET["id"]);
2973
c6c3a07f 2974 print "<div class='infoBoxContents'>";
717f5e64 2975
fe99ab12
AD
2976 $result = db_query($link, "SELECT login,
2977 SUBSTRING(last_login,1,16) AS last_login,
2978 access_level,
c6c3a07f
AD
2979 (SELECT COUNT(int_id) FROM ttrss_user_entries
2980 WHERE owner_uid = id) AS stored_articles
717f5e64
AD
2981 FROM ttrss_users
2982 WHERE id = '$uid'");
2983
2984 if (db_num_rows($result) == 0) {
2985 print "<h1>User not found</h1>";
2986 return;
2987 }
2988
2989 print "<h1>User Details</h1>";
2990
2991 print "<table width='100%'>";
2992
2993 $login = db_fetch_result($result, 0, "login");
2994 $last_login = db_fetch_result($result, 0, "last_login");
2995 $access_level = db_fetch_result($result, 0, "access_level");
c6c3a07f 2996 $stored_articles = db_fetch_result($result, 0, "stored_articles");
717f5e64
AD
2997
2998 print "<tr><td>Username</td><td>$login</td></tr>";
2999 print "<tr><td>Access level</td><td>$access_level</td></tr>";
3000 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
c6c3a07f 3001 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
717f5e64
AD
3002
3003 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
3004 WHERE owner_uid = '$uid'");
3005
3006 $num_feeds = db_fetch_result($result, 0, "num_feeds");
3007
3008 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
3009
5d15d3ea 3010/* $result = db_query($link, "SELECT
717f5e64 3011 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
c6c3a07f
AD
3012 FROM ttrss_user_entries,ttrss_entries
3013 WHERE owner_uid = '$uid' AND ref_id = id");
717f5e64 3014
d9f115c3 3015 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
717f5e64 3016
c6c3a07f 3017 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
717f5e64
AD
3018
3019 print "</table>";
3020
3021 print "<h1>Subscribed feeds</h1>";
3022
3023 $result = db_query($link, "SELECT id,title,feed_url FROM ttrss_feeds
d9f115c3 3024 WHERE owner_uid = '$uid' ORDER BY title");
717f5e64
AD
3025
3026 print "<ul class=\"nomarks\">";
3027
3028 while ($line = db_fetch_assoc($result)) {
3029
3030 $icon_file = ICONS_URL."/".$line["id"].".ico";
3031
3032 if (file_exists($icon_file) && filesize($icon_file) > 0) {
6c56687e 3033 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
717f5e64 3034 } else {
5951ded1 3035 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
717f5e64
AD
3036 }
3037
3038 print "<li>$feed_icon&nbsp;<a href=\"".$line["feed_url"]."\">".$line["title"]."</a></li>";
e6cb77a0 3039 }
717f5e64
AD
3040
3041 print "</ul>";
3042
717f5e64
AD
3043 print "</div>";
3044
1a7572cb
AD
3045 print "<div align='center'>
3046 <input type='submit' class='button'
c6c3a07f 3047 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
1a7572cb
AD
3048
3049// print "</body></html>";
717f5e64 3050
e6cb77a0
AD
3051 }
3052
c6c3a07f
AD
3053 if ($op == "feed-details") {
3054
3055 $feed_id = $_GET["id"];
3056
3057 $result = db_query($link,
3058 "SELECT
f324892e 3059 title,feed_url,last_updated,icon_url,site_url,
c6c3a07f
AD
3060 (SELECT COUNT(int_id) FROM ttrss_user_entries
3061 WHERE feed_id = id) AS total,
3062 (SELECT COUNT(int_id) FROM ttrss_user_entries
3063 WHERE feed_id = id AND unread = true) AS unread,
3064 (SELECT COUNT(int_id) FROM ttrss_user_entries
3065 WHERE feed_id = id AND marked = true) AS marked
3066 FROM ttrss_feeds
3067 WHERE id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]);
3068
3069 if (db_num_rows($result) == 0) return;
3070
3071 $title = db_fetch_result($result, 0, "title");
3072 $last_updated = db_fetch_result($result, 0, "last_updated");
3073 $feed_url = db_fetch_result($result, 0, "feed_url");
4fec9fd7 3074 $icon_url = db_fetch_result($result, 0, "icon_url");
c6c3a07f
AD
3075 $total = db_fetch_result($result, 0, "total");
3076 $unread = db_fetch_result($result, 0, "unread");
3077 $marked = db_fetch_result($result, 0, "marked");
f324892e 3078 $site_url = db_fetch_result($result, 0, "site_url");
4fec9fd7
AD
3079
3080 $result = db_query($link, "SELECT COUNT(id) AS subscribed
3081 FROM ttrss_feeds WHERE feed_url = '$feed_url'");
3082
3083 $subscribed = db_fetch_result($result, 0, "subscribed");
3084
3085 print "<div class=\"infoBoxContents\">";
3086
3087 $icon_file = ICONS_DIR . "/$feed_id.ico";
3088
3089 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3090 $feed_icon = "<img width=\"16\" height=\"16\"
3091 src=\"" . ICONS_URL . "/$feed_id.ico\">";
3092 } else {
3093 $feed_icon = "";
3094 }
3095
3096 print "<h1>$feed_icon $title</h1>";
c6c3a07f
AD
3097
3098 print "<table width='100%'>";
3099
f324892e
AD
3100 if ($site_url) {
3101 print "<tr><td width='30%'>Link</td>
3102 <td><a href=\"$site_url\">$site_url</a>
3103 <a href=\"$feed_url\">(feed)</a></td>
3104 </td></tr>";
3105 } else {
3106 print "<tr><td width='30%'>Feed URL</td>
3107 <td><a href=\"$feed_url\">$feed_url</a></td></tr>";
3108 }
c6c3a07f
AD
3109 print "<tr><td>Last updated</td><td>$last_updated</td></tr>";
3110 print "<tr><td>Total articles</td><td>$total</td></tr>";
3111 print "<tr><td>Unread articles</td><td>$unread</td></tr>";
3112 print "<tr><td>Starred articles</td><td>$marked</td></tr>";
4fec9fd7 3113 print "<tr><td>Subscribed users</td><td>$subscribed</td></tr>";
c6c3a07f
AD
3114
3115 print "</table>";
3116
bffdddd0
AD
3117 $result = db_query($link, "SELECT title,
3118 SUBSTRING(updated,1,16) AS updated,unread
bca02305
AD
3119 FROM ttrss_entries,ttrss_user_entries
3120 WHERE ref_id = id AND feed_id = '$feed_id'
c565e1ef 3121 ORDER BY date_entered DESC LIMIT 5");
c6c3a07f 3122
bca02305
AD
3123 if (db_num_rows($result) > 0) {
3124
3125 print "<h1>Latest headlines</h1>";
c6c3a07f 3126
bca02305
AD
3127 print "<ul class=\"nomarks\">";
3128
3129 while ($line = db_fetch_assoc($result)) {
c565e1ef
AD
3130 if ($line["unread"] == "t" || $line["unread"] == "1") {
3131 $line["title"] = "<b>" . $line["title"] . "</b>";
3132 }
bca02305
AD
3133 print "<li>" . $line["title"].
3134 "&nbsp;<span class=\"insensitive\">(" .$line["updated"].")</span></li>";
3135 }
3136
3137 print "</ul>";
3138
3139 print "</div>";
3140
3141 print "<div align='center'>
3142 <input type='submit' class='button'
3143 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3144 }
c6c3a07f
AD
3145 }
3146
4b3dff6e 3147 db_close($link);
1cd17194 3148?>
406d9489
AD
3149
3150<!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->
3151