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