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