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