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