]> git.wh0rd.org - tt-rss.git/blob - modules/pref-feeds.php
rework OPML import to use popup dialog
[tt-rss.git] / modules / pref-feeds.php
1 <?php
2
3 function batch_edit_cbox($elem, $label = false) {
4 print "<input type=\"checkbox\" title=\"".__("Check to enable field")."\"
5 onchange=\"batchFeedsToggleField(this, '$elem', '$label')\">";
6 }
7
8 function module_pref_feeds($link) {
9
10 global $update_intervals;
11 global $purge_intervals;
12 global $update_methods;
13
14 $subop = $_REQUEST["subop"];
15 $quiet = $_REQUEST["quiet"];
16 $mode = $_REQUEST["mode"];
17
18 /* if ($subop == "massSubscribe") {
19 $ids = split(",", db_escape_string($_REQUEST["ids"]));
20
21 $subscribed = array();
22
23 foreach ($ids as $id) {
24
25 if ($mode == 1) {
26 $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds
27 WHERE id = '$id'");
28 } else if ($mode == 2) {
29 $result = db_query($link, "SELECT * FROM ttrss_archived_feeds
30 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
31 $orig_id = db_escape_string(db_fetch_result($result, 0, "id"));
32 $site_url = db_escape_string(db_fetch_result($result, 0, "site_url"));
33 }
34
35 $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url"));
36 $title = db_escape_string(db_fetch_result($result, 0, "title"));
37
38 $title_orig = db_fetch_result($result, 0, "title");
39
40 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
41 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
42
43 if (db_num_rows($result) == 0) {
44 if ($mode == 1) {
45 $result = db_query($link,
46 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id)
47 VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)");
48 } else if ($mode == 2) {
49 $result = db_query($link,
50 "INSERT INTO ttrss_feeds (id,owner_uid,feed_url,title,cat_id,site_url)
51 VALUES ('$orig_id','".$_SESSION["uid"]."', '$feed_url', '$title', NULL, '$site_url')");
52 }
53 array_push($subscribed, $title_orig);
54 }
55 }
56
57 if (count($subscribed) > 0) {
58 $msg = "<b>".__('Subscribed to feeds:')."</b>".
59 "<ul class=\"nomarks\">";
60
61 foreach ($subscribed as $title) {
62 $msg .= "<li>$title</li>";
63 }
64 $msg .= "</ul>";
65
66 print format_notice($msg);
67 }
68
69 return;
70 } */
71
72 /* if ($subop == "browse") {
73
74 print "<div id=\"infoBoxTitle\">".__('Feed Browser')."</div>";
75
76 print "<div class=\"infoBoxContents\">";
77
78 $browser_search = db_escape_string($_REQUEST["search"]);
79
80 //print "<p>".__("Showing top 25 registered feeds, sorted by popularity:")."</p>";
81
82 print "<form onsubmit='return false;' display='inline' name='feed_browser' id='feed_browser'>";
83
84 print "
85 <div style='float : right'>
86 <img style='display : none'
87 id='feed_browser_spinner' src='images/indicator_white.gif'>
88 <input name=\"search\" size=\"20\" type=\"search\"
89 onchange=\"javascript:updateFeedBrowser()\" value=\"$browser_search\">
90 <button onclick=\"javascript:updateFeedBrowser()\">".__('Search')."</button>
91 </div>";
92
93 print " <select name=\"mode\" onchange=\"updateFeedBrowser()\">
94 <option value='1'>" . __('Popular feeds') . "</option>
95 <option value='2'>" . __('Feed archive') . "</option>
96 </select> ";
97
98 print __("limit:");
99
100 print " <select name=\"limit\" onchange='updateFeedBrowser()'>";
101
102 foreach (array(25, 50, 100, 200) as $l) {
103 $issel = ($l == $limit) ? "selected" : "";
104 print "<option $issel>$l</option>";
105 }
106
107 print "</select> ";
108
109 print "<p>";
110
111 $owner_uid = $_SESSION["uid"];
112
113 print "<ul class='browseFeedList' id='browseFeedList'>";
114 print_feed_browser($link, $search, 25);
115 print "</ul>";
116
117 print "<div align='center'>
118 <button onclick=\"feedBrowserSubscribe()\">".__('Subscribe')."</button>
119 <button onclick=\"closeInfoBox()\" >".__('Cancel')."</button></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_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\" onsubmit=\"return false\">";
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 "<div class=\"dlgSec\">".__("Feed")."</div>";
155 print "<div class=\"dlgSecCont\">";
156
157 /* Title */
158
159 print "<input style=\"font-size : 16px\" size=\"40\" onkeypress=\"return filterCR(event, feedEditSave)\"
160 name=\"title\" value=\"$title\">";
161
162 /* Feed URL */
163
164 $feed_url = db_fetch_result($result, 0, "feed_url");
165 $feed_url = htmlspecialchars(db_fetch_result($result,
166 0, "feed_url"));
167
168 print "<br/>";
169
170 print __('URL:') . " ";
171 print "<input size=\"40\" onkeypress=\"return filterCR(event, feedEditSave)\"
172 name=\"feed_url\" value=\"$feed_url\">";
173
174 /* Category */
175
176 if (get_pref($link, 'ENABLE_FEED_CATS')) {
177
178 $cat_id = db_fetch_result($result, 0, "cat_id");
179
180 print "<br/>";
181
182 print __('Place in category:') . " ";
183
184 $parent_feed = db_fetch_result($result, 0, "parent_feed");
185
186 if (sprintf("%d", $parent_feed) > 0) {
187 $disabled = "disabled";
188 } else {
189 $disabled = "";
190 }
191
192 print_feed_cat_select($link, "cat_id", $cat_id, $disabled);
193 }
194
195 /* Link to */
196
197 print "<br/>";
198
199 print __('Link to feed:') . " ";
200
201 $tmp_result = db_query($link, "SELECT COUNT(id) AS count
202 FROM ttrss_feeds WHERE parent_feed = '$feed_id'");
203
204 $linked_count = db_fetch_result($tmp_result, 0, "count");
205
206 $parent_feed = db_fetch_result($result, 0, "parent_feed");
207
208 if ($linked_count > 0) {
209 $disabled = "disabled";
210 } else {
211 $disabled = "";
212 }
213
214 print "<select $disabled name=\"parent_feed\">";
215
216 print "<option value=\"0\">".__('Not linked')."</option>";
217
218 if (get_pref($link, 'ENABLE_FEED_CATS')) {
219 if ($cat_id) {
220 $cat_qpart = "AND cat_id = '$cat_id'";
221 } else {
222 $cat_qpart = "AND cat_id IS NULL";
223 }
224 }
225
226 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
227 WHERE id != '$feed_id' AND owner_uid = ".$_SESSION["uid"]." AND
228 (SELECT COUNT(id) FROM ttrss_feeds AS T2 WHERE T2.id = ttrss_feeds.parent_feed) = 0
229 $cat_qpart ORDER BY title");
230
231 if (db_num_rows($tmp_result) > 0) {
232 print "<option disabled>--------</option>";
233 }
234
235 while ($tmp_line = db_fetch_assoc($tmp_result)) {
236 if ($tmp_line["id"] == $parent_feed) {
237 $is_selected = "selected";
238 } else {
239 $is_selected = "";
240 }
241
242 $linked_title = truncate_string(htmlspecialchars($tmp_line["title"]), 40);
243
244 printf("<option $is_selected value='%d'>%s</option>",
245 $tmp_line["id"], $linked_title);
246 }
247
248 print "</select>";
249
250
251 print "</div>";
252
253 print "<div class=\"dlgSec\">".__("Update")."</div>";
254 print "<div class=\"dlgSecCont\">";
255
256 /* Update Interval */
257
258 $update_interval = db_fetch_result($result, 0, "update_interval");
259
260 print_select_hash("update_interval", $update_interval, $update_intervals);
261
262 /* Update method */
263
264 if (ALLOW_SELECT_UPDATE_METHOD) {
265 $update_method = db_fetch_result($result, 0, "update_method");
266
267 print " " . __('using') . " ";
268 print_select_hash("update_method", $update_method, $update_methods);
269 }
270
271 $purge_interval = db_fetch_result($result, 0, "purge_interval");
272
273 if (FORCE_ARTICLE_PURGE == 0) {
274
275 /* Purge intl */
276
277 print "<br/>";
278
279 print __('Article purging:') . " ";
280
281 print_select_hash("purge_interval", $purge_interval, $purge_intervals);
282
283 } else {
284 print "<input type='hidden' name='purge_interval' value='$purge_interval'>";
285
286 }
287
288 print "</div>";
289 print "<div class=\"dlgSec\">".__("Authentication")."</div>";
290 print "<div class=\"dlgSecCont\">";
291
292 $auth_login = htmlspecialchars(db_fetch_result($result, 0, "auth_login"));
293
294 print "<table>";
295
296 print "<tr><td>" . __('Login:') . "</td><td>";
297
298 print "<input size=\"20\" onkeypress=\"return filterCR(event, feedEditSave)\"
299 name=\"auth_login\" value=\"$auth_login\">";
300
301 print "</tr><tr><td>" . __("Password:") . "</td><td>";
302
303 $auth_pass = htmlspecialchars(db_fetch_result($result, 0, "auth_pass"));
304
305 print "<input size=\"20\" type=\"password\" name=\"auth_pass\"
306 onkeypress=\"return filterCR(event, feedEditSave)\"
307 value=\"$auth_pass\">";
308
309 print "</td></tr></table>";
310
311 print "</div>";
312 print "<div class=\"dlgSec\">".__("Options")."</div>";
313 print "<div class=\"dlgSecCont\">";
314
315 print "<div style=\"line-height : 100%\">";
316
317 $private = sql_bool_to_bool(db_fetch_result($result, 0, "private"));
318
319 if ($private) {
320 $checked = "checked";
321 } else {
322 $checked = "";
323 }
324
325 print "<input type=\"checkbox\" name=\"private\" id=\"private\"
326 $checked>&nbsp;<label for=\"private\">".__('Hide from Popular feeds')."</label>";
327
328 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
329
330 if ($rtl_content) {
331 $checked = "checked";
332 } else {
333 $checked = "";
334 }
335
336 print "<br/><input type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"
337 $checked>&nbsp;<label for=\"rtl_content\">".__('Right-to-left content')."</label>";
338
339 $include_in_digest = sql_bool_to_bool(db_fetch_result($result, 0, "include_in_digest"));
340
341 if ($include_in_digest) {
342 $checked = "checked";
343 } else {
344 $checked = "";
345 }
346
347 print "<br/><input type=\"checkbox\" id=\"include_in_digest\"
348 name=\"include_in_digest\"
349 $checked>&nbsp;<label for=\"include_in_digest\">".__('Include in e-mail digest')."</label>";
350
351
352 $always_display_enclosures = sql_bool_to_bool(db_fetch_result($result, 0, "always_display_enclosures"));
353
354 if ($always_display_enclosures) {
355 $checked = "checked";
356 } else {
357 $checked = "";
358 }
359
360 print "<br/><input type=\"checkbox\" id=\"always_display_enclosures\"
361 name=\"always_display_enclosures\"
362 $checked>&nbsp;<label for=\"always_display_enclosures\">".__('Always display image attachments')."</label>";
363
364
365 $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
366
367 if ($cache_images) {
368 $checked = "checked";
369 } else {
370 $checked = "";
371 }
372
373 if (ENABLE_SIMPLEPIE && SIMPLEPIE_CACHE_IMAGES) {
374 $disabled = "";
375 $label_class = "";
376 } else {
377 $disabled = "disabled";
378 $label_class = "class='insensitive'";
379 }
380
381 print "<br/><input type=\"checkbox\" id=\"cache_images\"
382 name=\"cache_images\" $disabled
383 $checked>&nbsp;<label $label_class for=\"cache_images\">".
384 __('Cache images locally')."</label>";
385
386
387 print "</div>";
388 print "</div>";
389
390 print "</form>";
391
392 $title = htmlspecialchars($title, ENT_QUOTES);
393
394 print "<div class='dlgButtons'>
395 <div style=\"float : left\">
396 <button onclick='return unsubscribeFeed($feed_id, \"$title\")'>".
397 __('Unsubscribe')."</button>
398 </div>
399 <button onclick=\"return feedEditSave()\">".__('Save')."</button>
400 <button onclick=\"return feedEditCancel()\">".__('Cancel')."</button>
401 </div>";
402
403 return;
404 }
405
406 if ($subop == "editfeeds") {
407
408 $feed_ids = db_escape_string($_REQUEST["ids"]);
409
410 print "<div id=\"infoBoxTitle\">".__('Multiple Feed Editor')."</div>";
411
412 print "<div class=\"infoBoxContents\">";
413
414 print "<form id=\"batch_edit_feed_form\" onsubmit=\"return false\">";
415
416 print "<input type=\"hidden\" name=\"ids\" value=\"$feed_ids\">";
417 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
418 print "<input type=\"hidden\" name=\"subop\" value=\"batchEditSave\">";
419
420 print "<div class=\"dlgSec\">".__("Feed")."</div>";
421 print "<div class=\"dlgSecCont\">";
422
423 /* Title */
424
425 print "<input disabled style=\"font-size : 16px\" size=\"35\" onkeypress=\"return filterCR(event, feedEditSave)\"
426 name=\"title\" value=\"$title\">";
427
428 batch_edit_cbox("title");
429
430 /* Feed URL */
431
432 print "<br/>";
433
434 print __('URL:') . " ";
435 print "<input disabled size=\"40\" onkeypress=\"return filterCR(event, feedEditSave)\"
436 name=\"feed_url\" value=\"$feed_url\">";
437
438 batch_edit_cbox("feed_url");
439
440 /* Category */
441
442 if (get_pref($link, 'ENABLE_FEED_CATS')) {
443
444 print "<br/>";
445
446 print __('Place in category:') . " ";
447
448 print_feed_cat_select($link, "cat_id", $cat_id, "disabled");
449
450 batch_edit_cbox("cat_id");
451
452 }
453
454 print "</div>";
455
456 print "<div class=\"dlgSec\">".__("Update")."</div>";
457 print "<div class=\"dlgSecCont\">";
458
459 /* Update Interval */
460
461 print_select_hash("update_interval", $update_interval, $update_intervals,
462 "disabled");
463
464 batch_edit_cbox("update_interval");
465
466 /* Update method */
467
468 if (ALLOW_SELECT_UPDATE_METHOD) {
469 print " " . __('using') . " ";
470 print_select_hash("update_method", $update_method, $update_methods,
471 "disabled");
472 batch_edit_cbox("update_method");
473 }
474
475 /* Purge intl */
476
477 if (FORCE_ARTICLE_PURGE != 0) {
478
479 print "<br/>";
480
481 print __('Article purging:') . " ";
482
483 print_select_hash("purge_interval", $purge_interval, $purge_intervals,
484 "disabled");
485
486 batch_edit_cbox("purge_interval");
487 }
488
489 print "</div>";
490 print "<div class=\"dlgSec\">".__("Authentication")."</div>";
491 print "<div class=\"dlgSecCont\">";
492
493 print __('Login:') . " ";
494 print "<input disabled size=\"15\" onkeypress=\"return filterCR(event, feedEditSave)\"
495 name=\"auth_login\" value=\"$auth_login\">";
496
497 batch_edit_cbox("auth_login");
498
499 print " " . __("Password:") . " ";
500
501 print "<input disabled size=\"15\" type=\"password\" name=\"auth_pass\"
502 onkeypress=\"return filterCR(event, feedEditSave)\"
503 value=\"$auth_pass\">";
504
505 batch_edit_cbox("auth_pass");
506
507 print "</div>";
508 print "<div class=\"dlgSec\">".__("Options")."</div>";
509 print "<div class=\"dlgSecCont\">";
510
511 print "<div style=\"line-height : 100%\">";
512
513 print "<input disabled type=\"checkbox\" name=\"private\" id=\"private\"
514 $checked>&nbsp;<label id=\"private_l\" class='insensitive' for=\"private\">".__('Hide from Popular feeds')."</label>";
515
516 print "&nbsp;"; batch_edit_cbox("private", "private_l");
517
518 print "<br/><input disabled type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"
519 $checked>&nbsp;<label class='insensitive' id=\"rtl_content_l\" for=\"rtl_content\">".__('Right-to-left content')."</label>";
520
521 print "&nbsp;"; batch_edit_cbox("rtl_content", "rtl_content_l");
522
523 print "<br/><input disabled type=\"checkbox\" id=\"include_in_digest\"
524 name=\"include_in_digest\"
525 $checked>&nbsp;<label id=\"include_in_digest_l\" class='insensitive' for=\"include_in_digest\">".__('Include in e-mail digest')."</label>";
526
527 print "&nbsp;"; batch_edit_cbox("include_in_digest", "include_in_digest_l");
528
529 print "<br/><input disabled type=\"checkbox\" id=\"always_display_enclosures\"
530 name=\"always_display_enclosures\"
531 $checked>&nbsp;<label id=\"always_display_enclosures_l\" class='insensitive' for=\"always_display_enclosures\">".__('Always display image attachments')."</label>";
532
533 print "&nbsp;"; batch_edit_cbox("always_display_enclosures", "always_display_enclosures_l");
534
535 print "<br/><input disabled type=\"checkbox\" id=\"cache_images\"
536 name=\"cache_images\"
537 $checked>&nbsp;<label class='insensitive' id=\"cache_images_l\"
538 for=\"cache_images\">".
539 __('Cache images locally')."</label>";
540
541
542 if (ENABLE_SIMPLEPIE && SIMPLEPIE_CACHE_IMAGES) {
543 print "&nbsp;"; batch_edit_cbox("cache_images", "cache_images_l");
544 }
545
546 print "</div>";
547 print "</div>";
548
549 print "</form>";
550
551 print "<div class='dlgButtons'>
552 <input type=\"submit\" class=\"button\"
553 onclick=\"return feedsEditSave()\" value=\"".__('Save')."\">
554 <input type='submit' class='button'
555 onclick=\"return feedEditCancel()\" value=\"".__('Cancel')."\">
556 </div>";
557
558 return;
559 }
560
561 if ($subop == "editSave" || $subop == "batchEditSave") {
562
563 $feed_title = db_escape_string(trim($_POST["title"]));
564 $feed_link = db_escape_string(trim($_POST["feed_url"]));
565 $upd_intl = db_escape_string($_POST["update_interval"]);
566 $purge_intl = db_escape_string($_POST["purge_interval"]);
567 $feed_id = db_escape_string($_POST["id"]); /* editSave */
568 $feed_ids = db_escape_string($_POST["ids"]); /* batchEditSave */
569 $cat_id = db_escape_string($_POST["cat_id"]);
570 $auth_login = db_escape_string(trim($_POST["auth_login"]));
571 $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
572 $parent_feed = db_escape_string($_POST["parent_feed"]);
573 $private = checkbox_to_sql_bool(db_escape_string($_POST["private"]));
574 $rtl_content = checkbox_to_sql_bool(db_escape_string($_POST["rtl_content"]));
575 $include_in_digest = checkbox_to_sql_bool(
576 db_escape_string($_POST["include_in_digest"]));
577 $cache_images = checkbox_to_sql_bool(
578 db_escape_string($_POST["cache_images"]));
579 $update_method = (int) db_escape_string($_POST["update_method"]);
580
581 $always_display_enclosures = checkbox_to_sql_bool(
582 db_escape_string($_POST["always_display_enclosures"]));
583
584 if (get_pref($link, 'ENABLE_FEED_CATS')) {
585 if ($cat_id && $cat_id != 0) {
586 $category_qpart = "cat_id = '$cat_id',";
587 $category_qpart_nocomma = "cat_id = '$cat_id'";
588 } else {
589 $category_qpart = 'cat_id = NULL,';
590 $category_qpart_nocomma = 'cat_id = NULL';
591 }
592 } else {
593 $category_qpart = "";
594 $category_qpart_nocomma = "";
595 }
596
597 if ($parent_feed && $parent_feed != 0) {
598 $parent_qpart = "parent_feed = '$parent_feed'";
599 } else {
600 $parent_qpart = 'parent_feed = NULL';
601 }
602
603 if (ENABLE_SIMPLEPIE && SIMPLEPIE_CACHE_IMAGES) {
604 $cache_images_qpart = "cache_images = $cache_images,";
605 } else {
606 $cache_images_qpart = "";
607 }
608
609 if ($subop == "editSave") {
610
611 $result = db_query($link, "UPDATE ttrss_feeds SET
612 $category_qpart $parent_qpart,
613 title = '$feed_title', feed_url = '$feed_link',
614 update_interval = '$upd_intl',
615 purge_interval = '$purge_intl',
616 auth_login = '$auth_login',
617 auth_pass = '$auth_pass',
618 private = $private,
619 rtl_content = $rtl_content,
620 $cache_images_qpart
621 include_in_digest = $include_in_digest,
622 always_display_enclosures = $always_display_enclosures,
623 update_method = '$update_method'
624 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
625
626 if (get_pref($link, 'ENABLE_FEED_CATS')) {
627 # update linked feed categories
628 $result = db_query($link, "UPDATE ttrss_feeds SET
629 $category_qpart_nocomma WHERE parent_feed = '$feed_id' AND
630 owner_uid = " . $_SESSION["uid"]);
631 }
632 } else if ($subop == "batchEditSave") {
633 $feed_data = array();
634
635 foreach (array_keys($_POST) as $k) {
636 if ($k != "op" && $k != "subop" && $k != "ids") {
637 $feed_data[$k] = $_POST[$k];
638 }
639 }
640
641 db_query($link, "BEGIN");
642
643 foreach (array_keys($feed_data) as $k) {
644
645 $qpart = "";
646
647 switch ($k) {
648 case "title":
649 $qpart = "title = '$feed_title'";
650 break;
651
652 case "feed_url":
653 $qpart = "feed_url = '$feed_link'";
654 break;
655
656 case "update_interval":
657 $qpart = "update_interval = '$upd_intl'";
658 break;
659
660 case "purge_interval":
661 $qpart = "purge_interval = '$purge_intl'";
662 break;
663
664 case "auth_login":
665 $qpart = "auth_login = '$auth_login'";
666 break;
667
668 case "auth_pass":
669 $qpart = "auth_pass = '$auth_pass'";
670 break;
671
672 case "private":
673 $qpart = "private = '$private'";
674 break;
675
676 case "include_in_digest":
677 $qpart = "include_in_digest = '$include_in_digest'";
678 break;
679
680 case "always_display_enclosures":
681 $qpart = "always_display_enclosures = '$always_display_enclosures'";
682 break;
683
684 case "cache_images":
685 $qpart = "cache_images = '$cache_images'";
686 break;
687
688 case "rtl_content":
689 $qpart = "rtl_content = '$rtl_content'";
690 break;
691
692 case "update_method":
693 $qpart = "update_method = '$update_method'";
694 break;
695
696 case "cat_id":
697 $qpart = $category_qpart_nocomma;
698 break;
699
700 }
701
702 if ($qpart) {
703 db_query($link,
704 "UPDATE ttrss_feeds SET $qpart WHERE id IN ($feed_ids)
705 AND owner_uid = " . $_SESSION["uid"]);
706 print "<br/>";
707 }
708 }
709
710 db_query($link, "COMMIT");
711 }
712
713 }
714
715 if ($subop == "remove") {
716
717 $ids = split(",", db_escape_string($_REQUEST["ids"]));
718
719 foreach ($ids as $id) {
720 remove_feed($link, $id, $_SESSION["uid"]);
721 }
722
723 return;
724 }
725
726 if ($subop == "clear") {
727 $id = db_escape_string($_REQUEST["id"]);
728 clear_feed_articles($link, $id);
729 }
730
731 if ($subop == "rescore") {
732 $ids = split(",", db_escape_string($_REQUEST["ids"]));
733
734 foreach ($ids as $id) {
735
736 $filters = load_filters($link, $id, $_SESSION["uid"], 6);
737
738 $result = db_query($link, "SELECT title, content, link, ref_id FROM
739 ttrss_user_entries, ttrss_entries
740 WHERE ref_id = id AND feed_id = '$id' AND
741 owner_uid = " .$_SESSION['uid']."
742 ");
743
744 $scores = array();
745
746 while ($line = db_fetch_assoc($result)) {
747
748 $article_filters = get_article_filters($filters, $line['title'],
749 $line['content'], $line['link']);
750
751 $new_score = calculate_article_score($article_filters);
752
753 if (!$scores[$new_score]) $scores[$new_score] = array();
754
755 array_push($scores[$new_score], $line['ref_id']);
756 }
757
758 foreach (array_keys($scores) as $s) {
759 if ($s > 1000) {
760 db_query($link, "UPDATE ttrss_user_entries SET score = '$s',
761 marked = true WHERE
762 ref_id IN (" . join(',', $scores[$s]) . ")");
763 } else if ($s < -500) {
764 db_query($link, "UPDATE ttrss_user_entries SET score = '$s',
765 unread = false WHERE
766 ref_id IN (" . join(',', $scores[$s]) . ")");
767 } else {
768 db_query($link, "UPDATE ttrss_user_entries SET score = '$s' WHERE
769 ref_id IN (" . join(',', $scores[$s]) . ")");
770 }
771 }
772 }
773
774 print __("All done.");
775
776 }
777
778 if ($subop == "rescoreAll") {
779
780 $result = db_query($link,
781 "SELECT id FROM ttrss_feeds WHERE owner_uid = " . $_SESSION['uid']);
782
783 while ($feed_line = db_fetch_assoc($result)) {
784
785 $id = $feed_line["id"];
786
787 $filters = load_filters($link, $id, $_SESSION["uid"], 6);
788
789 $tmp_result = db_query($link, "SELECT title, content, link, ref_id FROM
790 ttrss_user_entries, ttrss_entries
791 WHERE ref_id = id AND feed_id = '$id' AND
792 owner_uid = " .$_SESSION['uid']."
793 ");
794
795 $scores = array();
796
797 while ($line = db_fetch_assoc($tmp_result)) {
798
799 $article_filters = get_article_filters($filters, $line['title'],
800 $line['content'], $line['link']);
801
802 $new_score = calculate_article_score($article_filters);
803
804 if (!$scores[$new_score]) $scores[$new_score] = array();
805
806 array_push($scores[$new_score], $line['ref_id']);
807 }
808
809 foreach (array_keys($scores) as $s) {
810 if ($s > 1000) {
811 db_query($link, "UPDATE ttrss_user_entries SET score = '$s',
812 marked = true WHERE
813 ref_id IN (" . join(',', $scores[$s]) . ")");
814 } else {
815 db_query($link, "UPDATE ttrss_user_entries SET score = '$s' WHERE
816 ref_id IN (" . join(',', $scores[$s]) . ")");
817 }
818 }
819 }
820
821 print __("All done.");
822
823 }
824
825 if ($subop == "add") {
826
827 $feed_url = db_escape_string(trim($_REQUEST["feed_url"]));
828 $cat_id = db_escape_string($_REQUEST["cat_id"]);
829 $p_from = db_escape_string($_REQUEST["from"]);
830
831 /* only read authentication information from POST */
832
833 $auth_login = db_escape_string(trim($_POST["auth_login"]));
834 $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
835
836 if ($p_from != 'tt-rss') {
837 print "<html>
838 <head>
839 <title>Tiny Tiny RSS</title>
840 <link rel=\"stylesheet\" type=\"text/css\" href=\"utility.css\">
841 </head>
842 <body>
843 <img class=\"floatingLogo\" src=\"images/ttrss_logo.png\"
844 alt=\"Tiny Tiny RSS\"/>
845 <h1>Subscribe to feed...</h1>";
846 }
847
848 $rc = subscribe_to_feed($link, $feed_url, $cat_id, $auth_login, $auth_pass);
849
850 switch ($rc) {
851 case 1:
852 print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
853 break;
854 case 2:
855 print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
856 break;
857 case 0:
858 print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
859 break;
860 }
861
862 if ($p_from != 'tt-rss') {
863 $tt_uri = ($_SERVER['HTTPS'] != "on" ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . preg_replace('/backend\.php.*$/', 'tt-rss.php', $_SERVER["REQUEST_URI"]);
864
865
866 $tp_uri = ($_SERVER['HTTPS'] != "on" ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . preg_replace('/backend\.php.*$/', 'prefs.php', $_SERVER["REQUEST_URI"]);
867
868 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
869 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
870
871 $feed_id = db_fetch_result($result, 0, "id");
872
873 print "<p>";
874
875 if ($feed_id) {
876 print "<form method=\"GET\" style='display: inline'
877 action=\"$tp_uri\">
878 <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
879 <input type=\"hidden\" name=\"subop\" value=\"editFeed\">
880 <input type=\"hidden\" name=\"subopparam\" value=\"$feed_id\">
881 <input type=\"submit\" value=\"".__("Edit subscription options")."\">
882 </form>";
883 }
884
885 print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
886 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
887 </form></p>";
888
889 print "</body></html>";
890 return;
891 }
892 }
893
894 if ($subop == "categorize") {
895
896 if (!WEB_DEMO_MODE) {
897
898 $ids = split(",", db_escape_string($_REQUEST["ids"]));
899
900 $cat_id = db_escape_string($_REQUEST["cat_id"]);
901
902 if ($cat_id == 0) {
903 $cat_id_qpart = 'NULL';
904 } else {
905 $cat_id_qpart = "'$cat_id'";
906 }
907
908 db_query($link, "BEGIN");
909
910 foreach ($ids as $id) {
911
912 db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
913 WHERE id = '$id' AND parent_feed IS NULL
914 AND owner_uid = " . $_SESSION["uid"]);
915
916 # update linked feed categories
917 db_query($link, "UPDATE ttrss_feeds SET
918 cat_id = $cat_id_qpart WHERE parent_feed = '$id' AND
919 owner_uid = " . $_SESSION["uid"]);
920
921 }
922
923 db_query($link, "COMMIT");
924 }
925
926 }
927
928 if ($subop == "editCats") {
929
930 $action = $_REQUEST["action"];
931
932 if ($action == "save") {
933
934 $cat_title = db_escape_string(trim($_REQUEST["value"]));
935 $cat_id = db_escape_string($_REQUEST["cid"]);
936
937 db_query($link, "BEGIN");
938
939 $result = db_query($link, "SELECT title FROM ttrss_feed_categories
940 WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
941
942 if (db_num_rows($result) == 1) {
943
944 $old_title = db_fetch_result($result, 0, "title");
945
946 if ($cat_title != "") {
947 $result = db_query($link, "UPDATE ttrss_feed_categories SET
948 title = '$cat_title' WHERE id = '$cat_id' AND
949 owner_uid = ".$_SESSION["uid"]);
950
951 print $cat_title;
952 } else {
953 print $old_title;
954 }
955 } else {
956 print $_REQUEST["value"];
957 }
958
959 db_query($link, "COMMIT");
960
961 return;
962
963 }
964
965 print "<div id=\"infoBoxTitle\">".__('Category editor')."</div>";
966
967 print "<div class=\"infoBoxContents\">";
968
969
970 if ($action == "add") {
971
972 if (!WEB_DEMO_MODE) {
973
974 $feed_cat = db_escape_string(trim($_REQUEST["cat"]));
975
976 $result = db_query($link,
977 "SELECT id FROM ttrss_feed_categories
978 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
979
980 if (db_num_rows($result) == 0) {
981
982 $result = db_query($link,
983 "INSERT INTO ttrss_feed_categories (owner_uid,title)
984 VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
985
986 } else {
987
988 print_warning(T_sprintf("Category <b>$%s</b> already exists in the database.",
989 $feed_cat));
990 }
991
992 }
993 }
994
995 if ($action == "remove") {
996
997 $ids = split(",", db_escape_string($_REQUEST["ids"]));
998
999 foreach ($ids as $id) {
1000 remove_feed_category($link, $id, $_SESSION["uid"]);
1001 }
1002 }
1003
1004 print "<div>
1005 <input id=\"fadd_cat\"
1006 onkeypress=\"return filterCR(event, addFeedCat)\"
1007 size=\"40\">
1008 <button onclick=\"javascript:addFeedCat()\">".
1009 __('Create category')."</button></div>";
1010
1011 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
1012 WHERE owner_uid = ".$_SESSION["uid"]."
1013 ORDER BY title");
1014
1015 print "<p>";
1016
1017 if (db_num_rows($result) != 0) {
1018
1019 print __('Select:')."
1020 <a href=\"javascript:selectPrefRows('fcat', true)\">".__('All')."</a>,
1021 <a href=\"javascript:selectPrefRows('fcat', false)\">".__('None')."</a>";
1022
1023 print "<div class=\"prefFeedCatHolder\">";
1024
1025 print "<form id=\"feed_cat_edit_form\" onsubmit=\"return false\">";
1026
1027 print "<table width=\"100%\" class=\"prefFeedCatList\"
1028 cellspacing=\"0\" id=\"prefFeedCatList\">";
1029
1030 $lnum = 0;
1031
1032 while ($line = db_fetch_assoc($result)) {
1033
1034 $class = ($lnum % 2) ? "even" : "odd";
1035
1036 $cat_id = $line["id"];
1037 $this_row_id = "id=\"FCATR-$cat_id\"";
1038
1039 print "<tr class=\"$class\" $this_row_id>";
1040
1041 $edit_title = htmlspecialchars($line["title"]);
1042
1043 print "<td width='5%' align='center'><input
1044 onclick='toggleSelectPrefRow(this, \"fcat\");'
1045 type=\"checkbox\" id=\"FCCHK-$cat_id\"></td>";
1046
1047 print "<td><span id=\"FCATT-$cat_id\">" .
1048 $edit_title . "</span></td>";
1049
1050 print "</tr>";
1051
1052 ++$lnum;
1053 }
1054
1055 print "</table>";
1056
1057 print "</form>";
1058
1059 print "</div>";
1060
1061 } else {
1062 print "<p>".__('No feed categories defined.')."</p>";
1063 }
1064
1065 print "<div class='dlgButtons'>
1066 <div style='float : left'>
1067 <button onclick=\"return removeSelectedFeedCats()\">".
1068 __('Remove')."</button>
1069 </div>";
1070
1071 print "<button onclick=\"selectTab('feedConfig')\">".
1072 __('Close this window')."</button></div>";
1073
1074 print "</div>";
1075
1076 return;
1077
1078 }
1079
1080 if ($quiet) return;
1081
1082 set_pref($link, "_PREFS_ACTIVE_TAB", "feedConfig");
1083
1084 $result = db_query($link, "SELECT COUNT(id) AS num_errors
1085 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1086
1087 $num_errors = db_fetch_result($result, 0, "num_errors");
1088
1089 if ($num_errors > 0) {
1090
1091 print format_notice("<a href=\"javascript:showFeedsWithErrors()\">".
1092 __('Some feeds have update errors (click for details)')."</a>");
1093 }
1094
1095 $feed_search = db_escape_string($_REQUEST["search"]);
1096
1097 if (array_key_exists("search", $_REQUEST)) {
1098 $_SESSION["prefs_feed_search"] = $feed_search;
1099 } else {
1100 $feed_search = $_SESSION["prefs_feed_search"];
1101 }
1102
1103 print "<div style='float : right'>
1104 <input id=\"feed_search\" size=\"20\" type=\"search\"
1105 onfocus=\"javascript:disableHotkeys();\"
1106 onblur=\"javascript:enableHotkeys();\"
1107 onchange=\"javascript:updateFeedList()\" value=\"$feed_search\">
1108 <button onclick=\"javascript:updateFeedList()\">".
1109 __('Search')."</button>
1110 </div>";
1111
1112 print "<button onclick=\"javascript:displayDlg('quickAddFeed')\">"
1113 .__('Subscribe to feed')."</button> ";
1114
1115 print "<button onclick=\"javascript:editSelectedFeed()\">".
1116 __('Edit feeds')."</button> ";
1117
1118 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1119
1120 print "<button onclick=\"javascript:editFeedCats()\">".
1121 __('Edit categories')."</button> ";
1122 }
1123
1124 print "<button onclick=\"javascript:removeSelectedFeeds()\">"
1125 .__('Unsubscribe')."</button> ";
1126
1127 /* print "<select id=\"feedActionChooser\" onchange=\"feedActionChange()\">
1128 <option value=\"facDefault\" selected>".__('Other actions...')."</option>";
1129
1130 if (FORCE_ARTICLE_PURGE == 0) {
1131 print
1132 "<option value=\"facPurge\">".__('Manual purge')."</option>";
1133 }
1134
1135 print "
1136 <option value=\"facClear\">".__('Clear feed data')."</option>
1137 <option value=\"facRescore\">".__('Rescore articles')."</option>
1138 <option value=\"facUnsubscribe\">".__('Unsubscribe')."</option>";
1139
1140 print "</select>"; */
1141
1142 /* if (ENABLE_FEED_BROWSER && !SINGLE_USER_MODE) {
1143 print " <input type=\"submit\" class=\"button\"
1144 id=\"top25_feeds_btn\"
1145 onclick=\"javascript:browseFeeds()\" value=\"".__('More feeds')."\">";
1146 } */
1147
1148 $feeds_sort = db_escape_string($_REQUEST["sort"]);
1149
1150 if (!$feeds_sort || $feeds_sort == "undefined") {
1151 $feeds_sort = $_SESSION["pref_sort_feeds"];
1152 if (!$feeds_sort) $feeds_sort = "title";
1153 }
1154
1155 $_SESSION["pref_sort_feeds"] = $feeds_sort;
1156
1157 if ($feed_search) {
1158
1159 $feed_search = split(" ", $feed_search);
1160 $tokens = array();
1161
1162 foreach ($feed_search as $token) {
1163
1164 $token = trim($token);
1165
1166 array_push($tokens, "(UPPER(F1.title) LIKE UPPER('%$token%') OR
1167 UPPER(C1.title) LIKE UPPER('%$token%') OR
1168 UPPER(F1.feed_url) LIKE UPPER('%$token%'))");
1169 }
1170
1171 $search_qpart = "(" . join($tokens, " AND ") . ") AND ";
1172
1173 } else {
1174 $search_qpart = "";
1175 }
1176
1177 $show_last_article_info = false;
1178 $show_last_article_checked = "";
1179 $show_last_article_qpart = "";
1180
1181 if ($_REQUEST["slat"] == "true") {
1182 $show_last_article_info = true;
1183 $show_last_article_checked = "checked";
1184 $show_last_article_qpart = ", (SELECT ".SUBSTRING_FOR_DATE."(MAX(updated),1,16) FROM ttrss_user_entries,
1185 ttrss_entries WHERE ref_id = ttrss_entries.id
1186 AND feed_id = F1.id) AS last_article";
1187 } else if ($feeds_sort == "last_article") {
1188 $feeds_sort = "title";
1189 }
1190
1191 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1192 $order_by_qpart = "category,$feeds_sort,title";
1193 } else {
1194 $order_by_qpart = "$feeds_sort,title";
1195 }
1196
1197 $result = db_query($link, "SELECT
1198 F1.id,
1199 F1.title,
1200 F1.feed_url,
1201 ".SUBSTRING_FOR_DATE."(F1.last_updated,1,16) AS last_updated,
1202 F1.parent_feed,
1203 F1.update_interval,
1204 F1.last_error,
1205 F1.purge_interval,
1206 F1.cat_id,
1207 F2.title AS parent_title,
1208 C1.title AS category,
1209 F1.include_in_digest
1210 $show_last_article_qpart
1211 FROM
1212 ttrss_feeds AS F1
1213 LEFT JOIN ttrss_feeds AS F2
1214 ON (F1.parent_feed = F2.id)
1215 LEFT JOIN ttrss_feed_categories AS C1
1216 ON (F1.cat_id = C1.id)
1217 WHERE
1218 $search_qpart F1.owner_uid = '".$_SESSION["uid"]."'
1219 ORDER by $order_by_qpart");
1220
1221 if (db_num_rows($result) != 0) {
1222
1223 // print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
1224
1225 print "<p><table width=\"100%\" cellspacing=\"0\"
1226 class=\"prefFeedList\" id=\"prefFeedList\">";
1227 print "<tr><td class=\"selectPrompt\" colspan=\"8\">".
1228 "<div style='float : right'>".
1229 "<input id='show_last_article_times' type='checkbox' onchange='feedlistToggleSLAT()'
1230 $show_last_article_checked><label
1231 for='show_last_article_times'>".__('Show last article times')."</label></div>".
1232 __('Select:')."
1233 <a href=\"javascript:selectPrefRows('feed', true)\">".__('All')."</a>,
1234 <a href=\"javascript:selectPrefRows('feed', false)\">".__('None')."</a>
1235 </td</tr>";
1236
1237 if (!get_pref($link, 'ENABLE_FEED_CATS')) {
1238 print "<tr class=\"title\">
1239 <td width='5%' align='center'>&nbsp;</td>";
1240
1241 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
1242 print "<td width='3%'>&nbsp;</td>";
1243 }
1244
1245 print "<td width='60%'><a href=\"javascript:updateFeedList('title')\">".__('Title')."</a></td>";
1246
1247 if ($show_last_article_info) {
1248 print "<td width='20%' align='right'><a href=\"javascript:updateFeedList('last_article')\">".__('Last&nbsp;Article')."</a></td>";
1249 }
1250
1251 print "<td width='20%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">".__('Updated')."</a></td>";
1252 }
1253
1254 $lnum = 0;
1255
1256 $cur_cat_id = -1;
1257
1258 while ($line = db_fetch_assoc($result)) {
1259
1260 $feed_id = $line["id"];
1261 $cat_id = $line["cat_id"];
1262
1263 $edit_title = htmlspecialchars($line["title"]);
1264 $edit_cat = htmlspecialchars($line["category"]);
1265
1266 $last_error = $line["last_error"];
1267
1268 if (!$edit_cat) $edit_cat = __("Uncategorized");
1269
1270 $last_updated = $line["last_updated"];
1271
1272 if (!$last_updated) {
1273 $last_updated = "&mdash;";
1274 } else if (get_pref($link, 'HEADLINES_SMART_DATE')) {
1275 $last_updated = smart_date_time(strtotime($last_updated));
1276 } else {
1277 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1278 $last_updated = date($short_date, strtotime($last_updated));
1279 }
1280
1281 $last_article = $line["last_article"];
1282
1283 if (!$last_article) {
1284 $last_article = "&mdash;";
1285 } else if (get_pref($link, 'HEADLINES_SMART_DATE')) {
1286 $last_article = smart_date_time(strtotime($last_article));
1287 } else {
1288 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1289 $last_article = date($short_date, strtotime($last_article));
1290 }
1291
1292 if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) {
1293 $lnum = 0;
1294
1295 print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>";
1296
1297 print "<tr class=\"title\">
1298 <td width='5%'>&nbsp;</td>";
1299
1300 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
1301 print "<td width='3%'>&nbsp;</td>";
1302 }
1303
1304 print "<td width='60%'><a href=\"javascript:updateFeedList('title')\">".__('Title')."</a></td>";
1305
1306 if ($show_last_article_info) {
1307 print "<td width='20%' align='right'>
1308 <a href=\"javascript:updateFeedList('last_article')\">".__('Last&nbsp;Article')."</a></td>";
1309 }
1310
1311 print "<td width='20%' align='right'>
1312 <a href=\"javascript:updateFeedList('last_updated')\">".__('Updated')."</a></td>";
1313
1314 $cur_cat_id = $cat_id;
1315 }
1316
1317 $class = ($lnum % 2) ? "even" : "odd";
1318 $this_row_id = "id=\"FEEDR-$feed_id\"";
1319
1320 print "<tr class=\"$class\" $this_row_id>";
1321
1322 $icon_file = ICONS_DIR . "/$feed_id.ico";
1323
1324 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1325 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . "/$feed_id.ico\">";
1326 } else {
1327 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1328 }
1329
1330 print "<td class='feedSelect'><input onclick='toggleSelectPrefRow(this, \"feed\");'
1331 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
1332
1333 $onclick = "onclick='editFeed($feed_id)' title='".__('Click to edit')."'";
1334
1335 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
1336 print "<td $onclick class='feedIcon'>$feed_icon</td>";
1337 }
1338
1339 if ($last_error) {
1340 $edit_title = "<span class=\"feed_error\">$edit_title</span>";
1341 $last_updated = "<span class=\"feed_error\">$last_updated</span>";
1342 $last_article = "<span class=\"feed_error\">$last_article</span>";
1343 }
1344
1345 $parent_title = $line["parent_title"];
1346 if ($parent_title) {
1347 $linked_to = sprintf(__("(linked to %s)"), $parent_title);
1348 $parent_title = "<span class='groupPrompt'>$linked_to</span>";
1349 }
1350
1351 print "<td $onclick>" . "$edit_title $parent_title" . "</td>";
1352
1353 if ($show_last_article_info) {
1354 print "<td align='right' $onclick>" .
1355 "$last_article</td>";
1356 }
1357
1358 print "<td $onclick align='right'>$last_updated</td>";
1359
1360 print "</tr>";
1361
1362 ++$lnum;
1363 }
1364
1365 print "</table>";
1366
1367 print "<p>";
1368
1369 } else {
1370
1371 print "<p>";
1372
1373 if (!$feed_search) {
1374 print_warning(__("You don't have any subscribed feeds."));
1375 } else {
1376 print_warning(__('No matching feeds found.'));
1377 }
1378 print "</p>";
1379
1380 }
1381
1382 print "<h3>".__('OPML')."</h3>";
1383
1384 /* print "<div style='float : left'>
1385 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
1386 ".__('File:')." <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
1387 <input type=\"hidden\" name=\"op\" value=\"Import\">
1388 <button onclick=\"return validateOpmlImport();\"
1389 type=\"submit\">".__('Import')."</button>
1390 </form></div>";
1391
1392 print "&nbsp;"; */
1393
1394 print "<iframe name=\"upload_iframe\" onchange=\"opml_import_handler(this)\"
1395 style=\"width: 400px; height: 100px; display: none;\"></iframe>";
1396
1397 print "<div style='float : left'>";
1398 print "<form style='display : block' target=\"upload_iframe\"
1399 enctype=\"multipart/form-data\" method=\"POST\"
1400 action=\"backend.php\">
1401 <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
1402 <input type=\"hidden\" name=\"op\" value=\"dlg\">
1403 <input type=\"hidden\" name=\"id\" value=\"importOpml\">
1404 <button onclick=\"return opmlImport();\"
1405 type=\"submit\">".__('Import')."</button>
1406 </form>";
1407 print "</div>&nbsp;";
1408
1409 print "<button onclick=\"gotoExportOpml()\">".
1410 __('Export OPML')."</button>";
1411
1412
1413 print "<h3>" . __("Firefox Integration") . "</h3>";
1414
1415 print "<p>" . __('This Tiny Tiny RSS site can be used as a Firefox Feed Reader by clicking the link below.') . "</p>";
1416
1417 print "<p";
1418
1419 print "<button onclick='window.navigator.registerContentHandler(" .
1420 "\"application/vnd.mozilla.maybe.feed\", " .
1421 "\"" . add_feed_url() . "\", " . " \"Tiny Tiny RSS\")'>" .
1422 __('Click here to register this site as a feed reader.') .
1423 "</button>";
1424
1425 print "</p>";
1426
1427 print "<h3>".__("Published articles")."</h3>";
1428
1429 if (!get_pref($link, "_PREFS_PUBLISH_KEY")) {
1430 set_pref($link, "_PREFS_PUBLISH_KEY", generate_publish_key());
1431 }
1432
1433 print "<p>".__('Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the URL specified below.')."</p>";
1434
1435 print "<button onclick=\"return displayDlg('pubUrl')\">".
1436 __('Display URL')."</button> ";
1437
1438
1439 }
1440
1441 function print_feed_browser($link, $search, $limit, $mode = 1) {
1442
1443 $owner_uid = $_SESSION["uid"];
1444
1445 if ($search) {
1446 $search_qpart = "AND (UPPER(feed_url) LIKE UPPER('%$search%') OR
1447 UPPER(title) LIKE UPPER('%$search%'))";
1448 } else {
1449 $search_qpart = "";
1450 }
1451
1452 if ($mode == 1) {
1453 $result = db_query($link, "SELECT feed_url, subscribers FROM
1454 ttrss_feedbrowser_cache WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf
1455 WHERE tf.feed_url = ttrss_feedbrowser_cache.feed_url
1456 AND owner_uid = '$owner_uid') $search_qpart
1457 ORDER BY subscribers DESC LIMIT $limit");
1458 } else if ($mode == 2) {
1459 $result = db_query($link, "SELECT *,
1460 (SELECT COUNT(*) FROM ttrss_user_entries WHERE
1461 orig_feed_id = ttrss_archived_feeds.id) AS articles_archived
1462 FROM
1463 ttrss_archived_feeds
1464 WHERE
1465 (SELECT COUNT(*) FROM ttrss_feeds
1466 WHERE ttrss_feeds.feed_url = ttrss_archived_feeds.feed_url AND
1467 owner_uid = '$owner_uid') = 0 AND
1468 owner_uid = '$owner_uid' $search_qpart
1469 ORDER BY id DESC LIMIT $limit");
1470 }
1471
1472 $feedctr = 0;
1473
1474 while ($line = db_fetch_assoc($result)) {
1475
1476 if ($mode == 1) {
1477
1478 $feed_url = htmlspecialchars($line["feed_url"]);
1479 $subscribers = $line["subscribers"];
1480
1481 $det_result = db_query($link, "SELECT site_url,title,id
1482 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
1483
1484 $details = db_fetch_assoc($det_result);
1485
1486 $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico";
1487
1488 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1489 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL .
1490 "/".$details["id"].".ico\">";
1491 } else {
1492 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1493 }
1494
1495 $check_box = "<input onclick='toggleSelectListRow(this)'
1496 class='feedBrowseCB'
1497 type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
1498
1499 $class = ($feedctr % 2) ? "even" : "odd";
1500
1501 if ($details["site_url"]) {
1502 $site_url = "<a target=\"_blank\" href=\"".
1503 htmlspecialchars($details["site_url"])."\">
1504 <img style='border-width : 0px' src='images/www.png' alt='www'></a>";
1505 } else {
1506 $site_url = "";
1507 }
1508
1509 print "<li title=\"".htmlspecialchars($details["site_url"])."\"
1510 class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
1511 "$feed_icon " . htmlspecialchars($details["title"]) .
1512 "&nbsp;<span class='subscribers'>($subscribers)</span>
1513 $site_url</li>";
1514
1515 } else if ($mode == 2) {
1516 $feed_url = htmlspecialchars($line["feed_url"]);
1517 $site_url = htmlspecialchars($line["site_url"]);
1518 $title = htmlspecialchars($line["title"]);
1519
1520 $icon_file = ICONS_DIR . "/" . $line["id"] . ".ico";
1521
1522 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1523 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL .
1524 "/".$line["id"].".ico\">";
1525 } else {
1526 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1527 }
1528
1529 $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB'
1530 type=\"checkbox\" id=\"FBCHK-" . $line["id"] . "\">";
1531
1532 $class = ($feedctr % 2) ? "even" : "odd";
1533
1534 if ($line['articles_archived'] > 0) {
1535 $archived = sprintf(__("%d archived articles"), $line['articles_archived']);
1536 $archived = "&nbsp;<span class='subscribers'>($archived)</span>";
1537 } else {
1538 $archived = '';
1539 }
1540
1541 if ($line["site_url"]) {
1542 $site_url = "<a target=\"_blank\" href=\"$site_url\">
1543 <img style='border-width : 0px' src='images/www.png' alt='www'></a>";
1544 } else {
1545 $site_url = "";
1546 }
1547
1548 print "<li title='".$line['site_url']."' class='$class'
1549 id=\"FBROW-".$line["id"]."\">".
1550 $check_box . "$feed_icon " . $title . $archived . $site_url . "</li>";
1551
1552
1553 }
1554
1555 ++$feedctr;
1556 }
1557
1558 if ($feedctr == 0) {
1559 print "<li style=\"text-align : center\"><p>".__('No feeds found.')."</p></li>";
1560 }
1561
1562 return $feedctr;
1563
1564 }
1565
1566 ?>