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