]> git.wh0rd.org - tt-rss.git/blob - modules/pref-feeds.php
infobox-based feed category editor
[tt-rss.git] / modules / pref-feeds.php
1 <?php
2
3 function module_pref_feeds($link) {
4
5 global $update_intervals;
6 global $purge_intervals;
7
8 $subop = $_REQUEST["subop"];
9 $quiet = $_REQUEST["quiet"];
10
11 if ($subop == "massSubscribe") {
12 $ids = split(",", db_escape_string($_GET["ids"]));
13
14 $subscribed = array();
15
16 foreach ($ids as $id) {
17 $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds
18 WHERE id = '$id'");
19
20 $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url"));
21 $title = db_escape_string(db_fetch_result($result, 0, "title"));
22
23 $title_orig = db_fetch_result($result, 0, "title");
24
25 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
26 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
27
28 if (db_num_rows($result) == 0) {
29 $result = db_query($link,
30 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id)
31 VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)");
32
33 array_push($subscribed, $title_orig);
34 }
35 }
36
37 if (count($subscribed) > 0) {
38 print "<div class=\"notice\">";
39 print "<b>Subscribed to feeds:</b>";
40 print "<ul class=\"nomarks\">";
41 foreach ($subscribed as $title) {
42 print "<li>$title</li>";
43 }
44 print "</ul>";
45 print "</div>";
46 }
47 }
48
49 if ($subop == "browse") {
50
51 if (!ENABLE_FEED_BROWSER) {
52 print "Feed browser is administratively disabled.";
53 return;
54 }
55
56 print "<div id=\"infoBoxTitle\">Other feeds: Top 25</div>";
57
58 print "<div class=\"infoBoxContents\">";
59
60 print "<p>Showing top 25 registered feeds, sorted by popularity:</p>";
61
62 # $result = db_query($link, "SELECT feed_url,count(id) AS subscribers
63 # FROM ttrss_feeds
64 # WHERE auth_login = '' AND auth_pass = '' AND private = false
65 # GROUP BY feed_url ORDER BY subscribers DESC LIMIT 25");
66
67 $owner_uid = $_SESSION["uid"];
68
69 $result = db_query($link, "SELECT feed_url,COUNT(id) AS subscribers
70 FROM ttrss_feeds WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf
71 WHERE tf.feed_url = ttrss_feeds.feed_url
72 AND owner_uid = '$owner_uid') GROUP BY feed_url
73 ORDER BY subscribers DESC LIMIT 25");
74
75 print "<ul class='browseFeedList' id='browseFeedList'>";
76
77 $feedctr = 0;
78
79 while ($line = db_fetch_assoc($result)) {
80 $feed_url = $line["feed_url"];
81 $subscribers = $line["subscribers"];
82
83 $det_result = db_query($link, "SELECT site_url,title,id
84 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
85
86 $details = db_fetch_assoc($det_result);
87
88 $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico";
89
90 if (file_exists($icon_file) && filesize($icon_file) > 0) {
91 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL .
92 "/".$details["id"].".ico\">";
93 } else {
94 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
95 }
96
97 $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB'
98 type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
99
100 $class = ($feedctr % 2) ? "even" : "odd";
101
102 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
103 "$feed_icon " . db_unescape_string($details["title"]) .
104 "&nbsp;<span class='subscribers'>($subscribers)</span></li>";
105
106 ++$feedctr;
107 }
108
109 if ($feedctr == 0) {
110 print "<li>No feeds found to subscribe.</li>";
111 }
112
113 print "</ul>";
114
115 print "<div align='center'>
116 <input type=\"submit\" class=\"button\"
117 onclick=\"feedBrowserSubscribe()\" value=\"Subscribe\">
118 <input type='submit' class='button'
119 onclick=\"closeInfoBox()\" value=\"Cancel\"></div>";
120
121 print "</div>";
122 return;
123 }
124
125 if ($subop == "editfeed") {
126 $feed_id = db_escape_string($_REQUEST["id"]);
127
128 $result = db_query($link,
129 "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND
130 owner_uid = " . $_SESSION["uid"]);
131
132 $title = htmlspecialchars(db_unescape_string(db_fetch_result($result,
133 0, "title")));
134
135 $icon_file = ICONS_DIR . "/$feed_id.ico";
136
137 if (file_exists($icon_file) && filesize($icon_file) > 0) {
138 $feed_icon = "<img width=\"16\" height=\"16\"
139 src=\"" . ICONS_URL . "/$feed_id.ico\">";
140 } else {
141 $feed_icon = "";
142 }
143
144 print "<div id=\"infoBoxTitle\">Feed editor</div>";
145
146 print "<div class=\"infoBoxContents\">";
147
148 print "<form id=\"edit_feed_form\">";
149
150 print "<input type=\"hidden\" name=\"id\" value=\"$feed_id\">";
151 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
152 print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
153
154 print "<table width='100%'>";
155
156 print "<tr><td>Title:</td>";
157 print "<td><input class=\"iedit\" onkeypress=\"return filterCR(event, feedEditSave)\"
158 name=\"title\" value=\"$title\"></td></tr>";
159
160 $feed_url = db_fetch_result($result, 0, "feed_url");
161 $feed_url = htmlspecialchars(db_unescape_string(db_fetch_result($result,
162 0, "feed_url")));
163
164 print "<tr><td>Feed URL:</td>";
165 print "<td><input class=\"iedit\" onkeypress=\"return filterCR(event, feedEditSave)\"
166 name=\"feed_url\" value=\"$feed_url\"></td></tr>";
167
168 if (get_pref($link, 'ENABLE_FEED_CATS')) {
169
170 $cat_id = db_fetch_result($result, 0, "cat_id");
171
172 print "<tr><td>Category:</td>";
173 print "<td>";
174
175 $parent_feed = db_fetch_result($result, 0, "parent_feed");
176
177 if (sprintf("%d", $parent_feed) > 0) {
178 $disabled = "disabled";
179 } else {
180 $disabled = "";
181 }
182
183 print_feed_cat_select($link, "cat_id", $cat_id, "class=\"iedit\" $disabled");
184
185 print "</td>";
186 print "</td></tr>";
187
188 }
189
190 $update_interval = db_fetch_result($result, 0, "update_interval");
191
192 print "<tr><td>Update Interval:</td>";
193
194 print "<td>";
195
196 print_select_hash("update_interval", $update_interval, $update_intervals,
197 "class=\"iedit\"");
198
199 print "</td>";
200
201 print "<tr><td>Link to:</td><td>";
202
203 $tmp_result = db_query($link, "SELECT COUNT(id) AS count
204 FROM ttrss_feeds WHERE parent_feed = '$feed_id'");
205
206 $linked_count = db_fetch_result($tmp_result, 0, "count");
207
208 $parent_feed = db_fetch_result($result, 0, "parent_feed");
209
210 if ($linked_count > 0) {
211 $disabled = "disabled";
212 } else {
213 $disabled = "";
214 }
215
216 print "<select class=\"iedit\" $disabled name=\"parent_feed\">";
217
218 print "<option value=\"0\">Not linked</option>";
219
220 if (get_pref($link, 'ENABLE_FEED_CATS')) {
221 if ($cat_id) {
222 $cat_qpart = "AND cat_id = '$cat_id'";
223 } else {
224 $cat_qpart = "AND cat_id IS NULL";
225 }
226 }
227
228 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
229 WHERE id != '$feed_id' AND owner_uid = ".$_SESSION["uid"]." AND
230 (SELECT COUNT(id) FROM ttrss_feeds AS T2 WHERE T2.id = ttrss_feeds.parent_feed) = 0
231 $cat_qpart ORDER BY title");
232
233 if (db_num_rows($tmp_result) > 0) {
234 print "<option disabled>--------</option>";
235 }
236
237 while ($tmp_line = db_fetch_assoc($tmp_result)) {
238 if ($tmp_line["id"] == $parent_feed) {
239 $is_selected = "selected";
240 } else {
241 $is_selected = "";
242 }
243 printf("<option $is_selected value='%d'>%s</option>",
244 $tmp_line["id"], $tmp_line["title"]);
245 }
246
247 print "</select>";
248 print "</td></tr>";
249
250 $purge_interval = db_fetch_result($result, 0, "purge_interval");
251
252 print "<tr><td>Article purging:</td>";
253
254 print "<td>";
255
256 print_select_hash("purge_interval", $purge_interval, $purge_intervals,
257 "class=\"iedit\"");
258
259 print "</td>";
260
261 $auth_login = escape_for_form(db_fetch_result($result, 0, "auth_login"));
262
263 print "<tr><td>Login:</td>";
264 print "<td><input class=\"iedit\" onkeypress=\"return filterCR(event, feedEditSave)\"
265 name=\"auth_login\" value=\"$auth_login\"></td></tr>";
266
267 $auth_pass = escape_for_form(db_fetch_result($result, 0, "auth_pass"));
268
269 print "<tr><td>Password:</td>";
270 print "<td><input class=\"iedit\" type=\"password\" name=\"auth_pass\"
271 onkeypress=\"return filterCR(event, feedEditSave)\"
272 value=\"$auth_pass\"></td></tr>";
273
274 $private = sql_bool_to_bool(db_fetch_result($result, 0, "private"));
275
276 if ($private) {
277 $checked = "checked";
278 } else {
279 $checked = "";
280 }
281
282 print "<tr><td valign='top'>Options:</td>";
283 print "<td><input type=\"checkbox\" name=\"private\" id=\"private\"
284 $checked><label for=\"private\">Hide from \"Other Feeds\"</label>";
285
286 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
287
288 if ($rtl_content) {
289 $checked = "checked";
290 } else {
291 $checked = "";
292 }
293
294 print "<br><input type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"
295 $checked><label for=\"rtl_content\">Right-to-left content</label>";
296
297 $hidden = sql_bool_to_bool(db_fetch_result($result, 0, "hidden"));
298
299 if ($hidden) {
300 $checked = "checked";
301 } else {
302 $checked = "";
303 }
304
305 print "<br><input type=\"checkbox\" id=\"hidden\" name=\"hidden\"
306 $checked><label for=\"hidden\">Hide from my feed list</label>";
307
308 $include_in_digest = sql_bool_to_bool(db_fetch_result($result, 0, "include_in_digest"));
309
310 if ($include_in_digest) {
311 $checked = "checked";
312 } else {
313 $checked = "";
314 }
315
316 print "<br><input type=\"checkbox\" id=\"include_in_digest\"
317 name=\"include_in_digest\"
318 $checked><label for=\"include_in_digest\">Include in e-mail digest</label>";
319
320 print "</td></tr>";
321
322 print "</table>";
323
324 print "</form>";
325
326 print "<div align='right'>
327 <input type=\"submit\" class=\"button\"
328 onclick=\"return feedEditSave()\" value=\"Save\">
329 <input type='submit' class='button'
330 onclick=\"return feedEditCancel()\" value=\"Cancel\"></div>";
331
332 print "</div>";
333
334 return;
335 }
336
337 if ($subop == "editSave") {
338
339 $feed_title = db_escape_string(trim($_POST["title"]));
340 $feed_link = db_escape_string(trim($_POST["feed_url"]));
341 $upd_intl = db_escape_string($_POST["update_interval"]);
342 $purge_intl = db_escape_string($_POST["purge_interval"]);
343 $feed_id = db_escape_string($_POST["id"]);
344 $cat_id = db_escape_string($_POST["cat_id"]);
345 $auth_login = db_escape_string(trim($_POST["auth_login"]));
346 $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
347 $parent_feed = db_escape_string($_POST["parent_feed"]);
348 $private = checkbox_to_sql_bool(db_escape_string($_POST["private"]));
349 $rtl_content = checkbox_to_sql_bool(db_escape_string($_POST["rtl_content"]));
350 $hidden = checkbox_to_sql_bool(db_escape_string($_POST["hidden"]));
351 $include_in_digest = checkbox_to_sql_bool(
352 db_escape_string($_POST["include_in_digest"]));
353
354 if (get_pref($link, 'ENABLE_FEED_CATS')) {
355 if ($cat_id && $cat_id != 0) {
356 $category_qpart = "cat_id = '$cat_id',";
357 $category_qpart_nocomma = "cat_id = '$cat_id'";
358 } else {
359 $category_qpart = 'cat_id = NULL,';
360 $category_qpart_nocomma = 'cat_id = NULL';
361 }
362 } else {
363 $category_qpart = "";
364 $category_qpart_nocomma = "";
365 }
366
367 if ($parent_feed && $parent_feed != 0) {
368 $parent_qpart = "parent_feed = '$parent_feed'";
369 } else {
370 $parent_qpart = 'parent_feed = NULL';
371 }
372
373 $result = db_query($link, "UPDATE ttrss_feeds SET
374 $category_qpart $parent_qpart,
375 title = '$feed_title', feed_url = '$feed_link',
376 update_interval = '$upd_intl',
377 purge_interval = '$purge_intl',
378 auth_login = '$auth_login',
379 auth_pass = '$auth_pass',
380 private = $private,
381 rtl_content = $rtl_content,
382 hidden = $hidden,
383 include_in_digest = $include_in_digest
384 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
385
386 if (get_pref($link, 'ENABLE_FEED_CATS')) {
387 # update linked feed categories
388 $result = db_query($link, "UPDATE ttrss_feeds SET
389 $category_qpart_nocomma WHERE parent_feed = '$feed_id' AND
390 owner_uid = " . $_SESSION["uid"]);
391 }
392 }
393
394 /* if ($subop == "saveCat") {
395 $cat_title = db_escape_string(trim($_GET["title"]));
396 $cat_id = db_escape_string($_GET["id"]);
397
398 $result = db_query($link, "UPDATE ttrss_feed_categories SET
399 title = '$cat_title' WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
400
401 } */
402
403 if ($subop == "remove") {
404
405 if (!WEB_DEMO_MODE) {
406
407 $ids = split(",", db_escape_string($_GET["ids"]));
408
409 foreach ($ids as $id) {
410
411 if ($id > 0) {
412
413 db_query($link, "DELETE FROM ttrss_feeds
414 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
415
416 $icons_dir = ICONS_DIR;
417
418 if (file_exists($icons_dir . "/$id.ico")) {
419 unlink($icons_dir . "/$id.ico");
420 }
421 } else if ($id < -10) {
422
423 $label_id = -$id - 11;
424
425 db_query($link, "DELETE FROM ttrss_labels
426 WHERE id = '$label_id' AND owner_uid = " . $_SESSION["uid"]);
427 }
428 }
429 }
430 }
431
432 if ($subop == "add") {
433
434 if (!WEB_DEMO_MODE) {
435
436 $feed_url = db_escape_string(trim($_GET["feed_url"]));
437 $cat_id = db_escape_string($_GET["cat_id"]);
438
439 if (subscribe_to_feed($link, $feed_url, $cat_id)) {
440 print "Added feed.";
441 } else {
442 print "<div class=\"warning\">
443 Feed <b>$feed_url</b> already exists in the database.
444 </div>";
445 }
446 }
447 }
448
449 /* if ($subop == "addCat") {
450
451 if (!WEB_DEMO_MODE) {
452
453 $feed_cat = db_escape_string(trim($_GET["cat"]));
454
455 $result = db_query($link,
456 "SELECT id FROM ttrss_feed_categories
457 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
458
459 if (db_num_rows($result) == 0) {
460
461 $result = db_query($link,
462 "INSERT INTO ttrss_feed_categories (owner_uid,title)
463 VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
464
465 } else {
466
467 print "<div class=\"warning\">
468 Category <b>$feed_cat</b> already exists in the database.
469 </div>";
470 }
471
472
473 }
474 }
475
476 if ($subop == "removeCats") {
477
478 if (!WEB_DEMO_MODE) {
479
480 $ids = split(",", db_escape_string($_GET["ids"]));
481
482 foreach ($ids as $id) {
483
484 db_query($link, "BEGIN");
485
486 $result = db_query($link,
487 "SELECT count(id) as num_feeds FROM ttrss_feeds
488 WHERE cat_id = '$id'");
489
490 $num_feeds = db_fetch_result($result, 0, "num_feeds");
491
492 if ($num_feeds == 0) {
493 db_query($link, "DELETE FROM ttrss_feed_categories
494 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
495 } else {
496
497 print "<div class=\"warning\">
498 Unable to delete non empty feed categories.</div>";
499
500 }
501
502 db_query($link, "COMMIT");
503 }
504 }
505 } */
506
507 if ($subop == "categorize") {
508
509 if (!WEB_DEMO_MODE) {
510
511 $ids = split(",", db_escape_string($_GET["ids"]));
512
513 $cat_id = db_escape_string($_GET["cat_id"]);
514
515 if ($cat_id == 0) {
516 $cat_id_qpart = 'NULL';
517 } else {
518 $cat_id_qpart = "'$cat_id'";
519 }
520
521 db_query($link, "BEGIN");
522
523 foreach ($ids as $id) {
524
525 db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
526 WHERE id = '$id' AND parent_feed IS NULL
527 AND owner_uid = " . $_SESSION["uid"]);
528
529 # update linked feed categories
530 db_query($link, "UPDATE ttrss_feeds SET
531 cat_id = $cat_id_qpart WHERE parent_feed = '$id' AND
532 owner_uid = " . $_SESSION["uid"]);
533
534 }
535
536 db_query($link, "COMMIT");
537 }
538
539 }
540
541 if ($subop == "editCats") {
542
543 print "<div id=\"infoBoxTitle\">Category editor</div>";
544
545 print "<div class=\"infoBoxContents\">";
546
547 $action = $_REQUEST["action"];
548
549 if ($action == "save") {
550
551 $cat_title = db_escape_string(trim($_GET["title"]));
552 $cat_id = db_escape_string($_GET["id"]);
553
554 $result = db_query($link, "UPDATE ttrss_feed_categories SET
555 title = '$cat_title' WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
556
557 }
558
559 if ($action == "add") {
560
561 if (!WEB_DEMO_MODE) {
562
563 $feed_cat = db_escape_string(trim($_GET["cat"]));
564
565 $result = db_query($link,
566 "SELECT id FROM ttrss_feed_categories
567 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
568
569 if (db_num_rows($result) == 0) {
570
571 $result = db_query($link,
572 "INSERT INTO ttrss_feed_categories (owner_uid,title)
573 VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
574
575 } else {
576
577 print "<div class=\"warning\">
578 Category <b>$feed_cat</b> already exists in the database.
579 </div>";
580 }
581
582 }
583 }
584
585 if ($action == "remove") {
586
587 if (!WEB_DEMO_MODE) {
588
589 $ids = split(",", db_escape_string($_GET["ids"]));
590
591 foreach ($ids as $id) {
592
593 db_query($link, "BEGIN");
594
595 $result = db_query($link,
596 "SELECT count(id) as num_feeds FROM ttrss_feeds
597 WHERE cat_id = '$id'");
598
599 $num_feeds = db_fetch_result($result, 0, "num_feeds");
600
601 if ($num_feeds == 0) {
602 db_query($link, "DELETE FROM ttrss_feed_categories
603 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
604 } else {
605
606 print "<div class=\"warning\">
607 Unable to delete non empty feed categories.</div>";
608
609 }
610
611 db_query($link, "COMMIT");
612 }
613 }
614 }
615
616 print "<div class=\"prefGenericAddBox\">
617 <input id=\"fadd_cat\"
618 onkeyup=\"toggleSubmitNotEmpty(this, 'catadd_submit_btn')\"
619 size=\"40\">&nbsp;
620 <input
621 type=\"submit\" class=\"button\" disabled=\"true\" id=\"catadd_submit_btn\"
622 onclick=\"javascript:addFeedCat()\" value=\"Create category\"></div>";
623
624 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
625 WHERE owner_uid = ".$_SESSION["uid"]."
626 ORDER BY title");
627
628 print "<p>";
629
630 if (db_num_rows($result) != 0) {
631
632 print "<table width=\"100%\" class=\"prefFeedCatList\"
633 cellspacing=\"0\">";
634
635 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
636 Select:
637 <a href=\"javascript:selectPrefRows('fcat', true)\">All</a>,
638 <a href=\"javascript:selectPrefRows('fcat', false)\">None</a>
639 </td></tr>";
640
641 print "</table>";
642
643 print "<div class=\"prefFeedCatHolder\">";
644
645 print "<form id=\"feed_cat_edit_form\">";
646
647 print "<table width=\"100%\" class=\"prefFeedCatList\"
648 cellspacing=\"0\" id=\"prefFeedCatList\">";
649
650 /* print "<tr class=\"title\">
651 <td width=\"5%\">&nbsp;</td><td width=\"80%\">Title</td>
652 </tr>"; */
653
654 $lnum = 0;
655
656 while ($line = db_fetch_assoc($result)) {
657
658 $class = ($lnum % 2) ? "even" : "odd";
659
660 $cat_id = $line["id"];
661
662 $edit_cat_id = $_GET["id"];
663
664 if ($action == "edit" && $cat_id != $edit_cat_id) {
665 $class .= "Grayed";
666 $this_row_id = "";
667 } else {
668 $this_row_id = "id=\"FCATR-$cat_id\"";
669 }
670
671 print "<tr class=\"$class\" $this_row_id>";
672
673 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
674
675 if (!$edit_cat_id || $action != "edit") {
676
677 print "<td width='5%' align='center'><input onclick='toggleSelectPrefRow(this, \"fcat\");'
678 type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>";
679
680 print "<td><a href=\"javascript:editFeedCat($cat_id);\">" .
681 $edit_title . "</a></td>";
682
683 } else if ($cat_id != $edit_cat_id) {
684
685 print "<td width='5%' align='center'><input disabled=\"true\" type=\"checkbox\"
686 id=\"FRCHK-".$line["id"]."\"></td>";
687
688 print "<td>$edit_title</td>";
689
690 } else {
691
692 print "<td width='5%' align='center'><input disabled=\"true\" type=\"checkbox\" checked>";
693
694 print "<input type=\"hidden\" name=\"id\" value=\"$cat_id\">";
695 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
696 print "<input type=\"hidden\" name=\"subop\" value=\"editCats\">";
697 print "<input type=\"hidden\" name=\"action\" value=\"save\">";
698
699 print "</td>";
700
701 print "<td><input onkeypress=\"return filterCR(event)\"
702 name=\"title\" size=\"40\" value=\"$edit_title\"></td>";
703
704 }
705
706 print "</tr>";
707
708 ++$lnum;
709 }
710
711 print "</table>";
712
713 print "</form>";
714
715 print "</div>";
716
717 print "<div style='float : right'>
718 <input type='submit' class='button'
719 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
720
721 print "<div id=\"catOpToolbar\">";
722
723 if ($action == "edit") {
724 print "<input type=\"submit\" class=\"button\"
725 onclick=\"return feedCatEditSave()\" value=\"Save\">
726 <input type=\"submit\" class=\"button\"
727 onclick=\"return feedCatEditCancel()\" value=\"Cancel\">";
728 } else {
729
730 print "
731 <input type=\"submit\" class=\"button\" disabled=\"true\"
732 onclick=\"return editSelectedFeedCat()\" value=\"Edit\">
733 <input type=\"submit\" class=\"button\" disabled=\"true\"
734 onclick=\"return removeSelectedFeedCats()\" value=\"Remove\">";
735
736 }
737
738 print "</div>";
739
740 } else {
741 print "<p>No feed categories defined.</p>";
742 }
743
744 print "</div>";
745
746 return;
747
748 }
749
750 if ($quiet) return;
751
752 // print "<h3>Edit Feeds</h3>";
753
754 $result = db_query($link, "SELECT id,title,feed_url,last_error
755 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
756
757 if (db_num_rows($result) > 0) {
758
759 print "<div class=\"warning\">";
760
761 // print"<img class=\"closeButton\"
762 // onclick=\"javascript:hideParentElement(this);\" src=\"images/close.png\">";
763
764 print "<a href=\"javascript:showBlockElement('feedUpdateErrors')\">
765 <b>Some feeds have update errors (click for details)</b></a>";
766
767 print "<ul id=\"feedUpdateErrors\" class=\"nomarks\">";
768
769 while ($line = db_fetch_assoc($result)) {
770 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
771 $line["last_error"];
772 }
773
774 print "</ul>";
775 print "</div>";
776
777 }
778
779 $feed_search = db_escape_string($_GET["search"]);
780
781 if (array_key_exists("search", $_GET)) {
782 $_SESSION["prefs_feed_search"] = $feed_search;
783 } else {
784 $feed_search = $_SESSION["prefs_feed_search"];
785 }
786
787 print "<div class=\"feedEditSearch\">
788 <input id=\"feed_search\" size=\"20\"
789 onchange=\"javascript:updateFeedList()\" value=\"$feed_search\">
790 <input type=\"submit\" class=\"button\"
791 onclick=\"javascript:updateFeedList()\" value=\"Search\">
792 </div>";
793
794 print "<div class=\"prefGenericAddBox\">
795 <input id=\"fadd_link\"
796 onkeyup=\"toggleSubmitNotEmpty(this, 'fadd_submit_btn')\"
797 size=\"40\">
798 <input type=\"submit\" class=\"button\"
799 disabled=\"true\" id=\"fadd_submit_btn\"
800 onclick=\"addFeed()\" value=\"Subscribe\">";
801
802 if (ENABLE_FEED_BROWSER && !SINGLE_USER_MODE) {
803 print " <input type=\"submit\" class=\"button\"
804 onclick=\"javascript:browseFeeds()\" value=\"Top 25\">";
805 }
806
807 print "</div>";
808
809 $feeds_sort = db_escape_string($_GET["sort"]);
810
811 if (!$feeds_sort || $feeds_sort == "undefined") {
812 $feeds_sort = $_SESSION["pref_sort_feeds"];
813 if (!$feeds_sort) $feeds_sort = "title";
814 }
815
816 $_SESSION["pref_sort_feeds"] = $feeds_sort;
817
818 if ($feed_search) {
819 $search_qpart = "(UPPER(F1.title) LIKE UPPER('%$feed_search%') OR
820 UPPER(F1.feed_url) LIKE UPPER('%$feed_search%')) AND";
821 } else {
822 $search_qpart = "";
823 }
824
825 if (get_pref($link, 'ENABLE_FEED_CATS')) {
826 $order_by_qpart = "category,$feeds_sort,title";
827 } else {
828 $order_by_qpart = "$feeds_sort,title";
829 }
830
831 $result = db_query($link, "SELECT
832 F1.id,
833 F1.title,
834 F1.feed_url,
835 substring(F1.last_updated,1,16) AS last_updated,
836 F1.parent_feed,
837 F1.update_interval,
838 F1.purge_interval,
839 F1.cat_id,
840 F2.title AS parent_title,
841 C1.title AS category,
842 F1.hidden,
843 F1.include_in_digest,
844 (SELECT SUBSTRING(MAX(updated),1,16) FROM ttrss_user_entries,
845 ttrss_entries WHERE ref_id = ttrss_entries.id
846 AND feed_id = F1.id) AS last_article
847 FROM
848 ttrss_feeds AS F1
849 LEFT JOIN ttrss_feeds AS F2
850 ON (F1.parent_feed = F2.id)
851 LEFT JOIN ttrss_feed_categories AS C1
852 ON (F1.cat_id = C1.id)
853 WHERE
854 $search_qpart F1.owner_uid = '".$_SESSION["uid"]."'
855 ORDER by $order_by_qpart");
856
857 if (db_num_rows($result) != 0) {
858
859 // print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
860
861 print "<p><table width=\"100%\" cellspacing=\"0\"
862 class=\"prefFeedList\" id=\"prefFeedList\">";
863 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
864 Select:
865 <a href=\"javascript:selectPrefRows('feed', true)\">All</a>,
866 <a href=\"javascript:selectPrefRows('feed', false)\">None</a>
867 </td</tr>";
868
869 if (!get_pref($link, 'ENABLE_FEED_CATS')) {
870 print "<tr class=\"title\">
871 <td width='5%' align='center'>&nbsp;</td>";
872
873 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
874 print "<td width='3%'>&nbsp;</td>";
875 }
876
877 print "
878 <td width='35%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
879 <td width='35%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
880 <td width='15%'><a href=\"javascript:updateFeedList('last_article')\">Last&nbsp;Article</a></td>
881 <td width='15%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">Updated</a></td>";
882 }
883
884 $lnum = 0;
885
886 $cur_cat_id = -1;
887
888 while ($line = db_fetch_assoc($result)) {
889
890 $feed_id = $line["id"];
891 $cat_id = $line["cat_id"];
892
893 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
894 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
895 $edit_cat = htmlspecialchars(db_unescape_string($line["category"]));
896
897 $hidden = sql_bool_to_bool($line["hidden"]);
898
899 if (!$edit_cat) $edit_cat = "Uncategorized";
900
901 $last_updated = $line["last_updated"];
902
903 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
904 $last_updated = smart_date_time(strtotime($last_updated));
905 } else {
906 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
907 $last_updated = date($short_date, strtotime($last_updated));
908 }
909
910 $last_article = $line["last_article"];
911
912 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
913 $last_article = smart_date_time(strtotime($last_article));
914 } else {
915 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
916 $last_article = date($short_date, strtotime($last_article));
917 }
918
919 if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) {
920 $lnum = 0;
921
922 print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>";
923
924 print "<tr class=\"title\">
925 <td width='5%'>&nbsp;</td>";
926
927 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
928 print "<td width='3%'>&nbsp;</td>";
929 }
930
931 print "<td width='35%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
932 <td width='35%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
933 <td width='15%'><a href=\"javascript:updateFeedList('last_article')\">Last&nbsp;Article</a></td>
934 <td width='15%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">Updated</a></td>";
935
936 $cur_cat_id = $cat_id;
937 }
938
939 $class = ($lnum % 2) ? "even" : "odd";
940 $this_row_id = "id=\"FEEDR-$feed_id\"";
941
942 print "<tr class=\"$class\" $this_row_id>";
943
944 $icon_file = ICONS_DIR . "/$feed_id.ico";
945
946 if (file_exists($icon_file) && filesize($icon_file) > 0) {
947 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . "/$feed_id.ico\">";
948 } else {
949 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
950 }
951
952 print "<td class='feedSelect'><input onclick='toggleSelectPrefRow(this, \"feed\");'
953 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
954
955 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
956 print "<td class='feedIcon'>$feed_icon</td>";
957 }
958
959 $edit_title = truncate_string($edit_title, 40);
960 $edit_link = truncate_string($edit_link, 60);
961
962 if ($hidden) {
963 $edit_title = "<span class=\"insensitive\">$edit_title (Hidden)</span>";
964 $edit_link = "<span class=\"insensitive\">$edit_link</span>";
965 $last_updated = "<span class=\"insensitive\">$last_updated</span>";
966 $last_article = "<span class=\"insensitive\">$last_article</span>";
967 }
968
969 $parent_title = $line["parent_title"];
970 if ($parent_title) {
971 $parent_title = "<span class='groupPrompt'>(linked to
972 $parent_title)</span>";
973 }
974
975 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
976 "$edit_title $parent_title" . "</a></td>";
977
978 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
979 $edit_link . "</a></td>";
980
981 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
982 "$last_article</a></td>";
983
984 print "<td align='right'><a href=\"javascript:editFeed($feed_id);\">" .
985 "$last_updated</a></td>";
986
987 print "</tr>";
988
989 ++$lnum;
990 }
991
992 print "</table>";
993
994 print "<p><span id=\"feedOpToolbar\">";
995
996 if ($subop == "edit") {
997 print "Edit feed:&nbsp;
998 <input type=\"submit\" class=\"button\"
999 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
1000 <input type=\"submit\" class=\"button\"
1001 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
1002 } else {
1003
1004 print "
1005 Selection:&nbsp;
1006 <input type=\"submit\" class=\"button\" disabled=\"true\"
1007 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
1008 <input type=\"submit\" class=\"button\" disabled=\"true\"
1009 onclick=\"javascript:removeSelectedFeeds()\" value=\"Unsubscribe\">";
1010
1011 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1012
1013 print "&nbsp;|&nbsp;";
1014
1015 print_feed_cat_select($link, "sfeed_set_fcat", "", "disabled");
1016
1017 print " <input type=\"submit\" class=\"button\" disabled=\"true\"
1018 onclick=\"javascript:categorizeSelectedFeeds()\" value=\"Recategorize\">";
1019
1020 }
1021
1022 print "</span>";
1023
1024 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1025
1026 print " <input type=\"submit\" class=\"button\"
1027 onclick=\"javascript:editFeedCats()\" value=\"Edit categories\">";
1028
1029 print "&nbsp;|&nbsp;";
1030
1031 }
1032
1033 print "All feeds: <input type=\"submit\"
1034 class=\"button\" onclick=\"gotoExportOpml()\"
1035 value=\"Export OPML\">";
1036 }
1037 } else {
1038
1039 print "<p>No feeds defined.</p>";
1040
1041 }
1042
1043
1044 /* if (get_pref($link, 'ENABLE_FEED_CATS')) {
1045
1046 print "<h3>Edit Categories</h3>";
1047
1048 print "<div class=\"prefGenericAddBox\">
1049 <input id=\"fadd_cat\"
1050 onkeyup=\"toggleSubmitNotEmpty(this, 'catadd_submit_btn')\"
1051 size=\"40\">&nbsp;
1052 <input
1053 type=\"submit\" class=\"button\" disabled=\"true\" id=\"catadd_submit_btn\"
1054 onclick=\"javascript:addFeedCat()\" value=\"Create category\"></div>";
1055
1056 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
1057 WHERE owner_uid = ".$_SESSION["uid"]."
1058 ORDER BY title");
1059
1060 if (db_num_rows($result) != 0) {
1061
1062 print "<form id=\"feed_cat_edit_form\">";
1063
1064 print "<p><table width=\"100%\" class=\"prefFeedCatList\"
1065 cellspacing=\"0\" id=\"prefFeedCatList\">";
1066
1067 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1068 Select:
1069 <a href=\"javascript:selectPrefRows('fcat', true)\">All</a>,
1070 <a href=\"javascript:selectPrefRows('fcat', false)\">None</a>
1071 </td</tr>";
1072
1073 print "<tr class=\"title\">
1074 <td width=\"5%\">&nbsp;</td><td width=\"80%\">Title</td>
1075 </tr>";
1076
1077 $lnum = 0;
1078
1079 while ($line = db_fetch_assoc($result)) {
1080
1081 $class = ($lnum % 2) ? "even" : "odd";
1082
1083 $cat_id = $line["id"];
1084
1085 $edit_cat_id = $_GET["id"];
1086
1087 if ($subop == "editCat" && $cat_id != $edit_cat_id) {
1088 $class .= "Grayed";
1089 $this_row_id = "";
1090 } else {
1091 $this_row_id = "id=\"FCATR-$cat_id\"";
1092 }
1093
1094 print "<tr class=\"$class\" $this_row_id>";
1095
1096 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1097
1098 if (!$edit_cat_id || $subop != "editCat") {
1099
1100 print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"fcat\");'
1101 type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>";
1102
1103 print "<td><a href=\"javascript:editFeedCat($cat_id);\">" .
1104 $edit_title . "</a></td>";
1105
1106 } else if ($cat_id != $edit_cat_id) {
1107
1108 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
1109 id=\"FRCHK-".$line["id"]."\"></td>";
1110
1111 print "<td>$edit_title</td>";
1112
1113 } else {
1114
1115 print "<td align='center'><input disabled=\"true\" type=\"checkbox\" checked>";
1116
1117 print "<input type=\"hidden\" name=\"id\" value=\"$cat_id\">";
1118 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
1119 print "<input type=\"hidden\" name=\"subop\" value=\"saveCat\">";
1120
1121 print "</td>";
1122
1123 print "<td><input onkeypress=\"return filterCR(event)\"
1124 name=\"title\" class=\"iedit\" value=\"$edit_title\"></td>";
1125
1126 }
1127
1128 print "</tr>";
1129
1130 ++$lnum;
1131 }
1132
1133 print "</table>";
1134
1135 print "</form>";
1136
1137 print "<p id=\"catOpToolbar\">";
1138
1139 if ($subop == "editCat") {
1140 print "Edit category:&nbsp;
1141 <input type=\"submit\" class=\"button\"
1142 onclick=\"return feedCatEditSave()\" value=\"Save\">
1143 <input type=\"submit\" class=\"button\"
1144 onclick=\"return feedCatEditCancel()\" value=\"Cancel\">";
1145 } else {
1146
1147 print "
1148 Selection:&nbsp;
1149 <input type=\"submit\" class=\"button\" disabled=\"true\"
1150 onclick=\"return editSelectedFeedCat()\" value=\"Edit\">
1151 <input type=\"submit\" class=\"button\" disabled=\"true\"
1152 onclick=\"return removeSelectedFeedCats()\" value=\"Remove\">";
1153
1154 }
1155
1156 } else {
1157 print "<p>No feed categories defined.</p>";
1158 }
1159 } */
1160
1161 print "<h3>Import OPML</h3>
1162 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
1163 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
1164 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
1165 type=\"submit\" value=\"Import\">
1166 </form>";
1167 }
1168 ?>