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