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