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