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