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