]> git.wh0rd.org - tt-rss.git/blob - modules/pref-feeds.php
tweak OPML panel UI a bit
[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 3:
1038 print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
1039 break;
1040 case 0:
1041 print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
1042 break;
1043 case 4:
1044 print_notice("Multiple feed URLs found.");
1045
1046 $feed_urls = get_feeds_from_html($feed_url);
1047 break;
1048 case 5:
1049 print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
1050 break;
1051 }
1052
1053 if ($p_from != 'tt-rss') {
1054
1055 if ($feed_urls) {
1056
1057 print "<form action=\"backend.php\">";
1058 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
1059 print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
1060 print "<input type=\"hidden\" name=\"subop\" value=\"add\">";
1061
1062 print "<select name=\"feed_url\">";
1063
1064 foreach ($feed_urls as $url => $name) {
1065 $url = htmlspecialchars($url);
1066 $name = htmlspecialchars($name);
1067
1068 print "<option value=\"$url\">$name</option>";
1069 }
1070
1071 print "<input type=\"submit\" value=\"".__("Subscribe to selected feed").
1072 "\">";
1073
1074 print "</form>";
1075 }
1076
1077 $tp_uri = get_self_url_prefix() . "/prefs.php";
1078 $tt_uri = get_self_url_prefix();
1079
1080 if ($rc <= 2){
1081 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
1082 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
1083
1084 $feed_id = db_fetch_result($result, 0, "id");
1085 } else {
1086 $feed_id = 0;
1087 }
1088 print "<p>";
1089
1090 if ($feed_id) {
1091 print "<form method=\"GET\" style='display: inline'
1092 action=\"$tp_uri\">
1093 <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
1094 <input type=\"hidden\" name=\"subop\" value=\"editFeed\">
1095 <input type=\"hidden\" name=\"subopparam\" value=\"$feed_id\">
1096 <input type=\"submit\" value=\"".__("Edit subscription options")."\">
1097 </form>";
1098 }
1099
1100 print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
1101 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
1102 </form></p>";
1103
1104 print "</body></html>";
1105 return;
1106 }
1107 }
1108
1109 if ($subop == "categorize") {
1110
1111
1112 $ids = split(",", db_escape_string($_REQUEST["ids"]));
1113
1114 $cat_id = db_escape_string($_REQUEST["cat_id"]);
1115
1116 if ($cat_id == 0) {
1117 $cat_id_qpart = 'NULL';
1118 } else {
1119 $cat_id_qpart = "'$cat_id'";
1120 }
1121
1122 db_query($link, "BEGIN");
1123
1124 foreach ($ids as $id) {
1125
1126 db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
1127 WHERE id = '$id'
1128 AND owner_uid = " . $_SESSION["uid"]);
1129
1130 }
1131
1132 db_query($link, "COMMIT");
1133
1134 }
1135
1136 if ($subop == "editCats") {
1137
1138 $action = $_REQUEST["action"];
1139
1140 if ($action == "save") {
1141
1142 $cat_title = db_escape_string(trim($_REQUEST["value"]));
1143 $cat_id = db_escape_string($_REQUEST["cid"]);
1144
1145 db_query($link, "BEGIN");
1146
1147 $result = db_query($link, "SELECT title FROM ttrss_feed_categories
1148 WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
1149
1150 if (db_num_rows($result) == 1) {
1151
1152 $old_title = db_fetch_result($result, 0, "title");
1153
1154 if ($cat_title != "") {
1155 $result = db_query($link, "UPDATE ttrss_feed_categories SET
1156 title = '$cat_title' WHERE id = '$cat_id' AND
1157 owner_uid = ".$_SESSION["uid"]);
1158
1159 print $cat_title;
1160 } else {
1161 print $old_title;
1162 }
1163 } else {
1164 print $_REQUEST["value"];
1165 }
1166
1167 db_query($link, "COMMIT");
1168
1169 return;
1170
1171 }
1172
1173 if ($action == "add") {
1174
1175 $feed_cat = db_escape_string(trim($_REQUEST["cat"]));
1176
1177 if (!add_feed_category($link, $feed_cat))
1178 print_warning(T_sprintf("Category <b>$%s</b> already exists in the database.", $feed_cat));
1179
1180 }
1181
1182 if ($action == "remove") {
1183
1184 $ids = split(",", db_escape_string($_REQUEST["ids"]));
1185
1186 foreach ($ids as $id) {
1187 remove_feed_category($link, $id, $_SESSION["uid"]);
1188 }
1189 }
1190
1191 print "<div dojoType=\"dijit.Toolbar\">
1192 <input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"newcat\">
1193 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedCatEditDlg').addCategory()\">".
1194 __('Create category')."</button></div>";
1195
1196 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
1197 WHERE owner_uid = ".$_SESSION["uid"]."
1198 ORDER BY title");
1199
1200 # print "<p>";
1201
1202 if (db_num_rows($result) != 0) {
1203
1204 print "<div class=\"prefFeedCatHolder\">";
1205
1206 # print "<form id=\"feed_cat_edit_form\" onsubmit=\"return false\">";
1207
1208 print "<table width=\"100%\" class=\"prefFeedCatList\"
1209 cellspacing=\"0\" id=\"prefFeedCatList\">";
1210
1211 $lnum = 0;
1212
1213 while ($line = db_fetch_assoc($result)) {
1214
1215 $class = ($lnum % 2) ? "even" : "odd";
1216
1217 $cat_id = $line["id"];
1218 $this_row_id = "id=\"FCATR-$cat_id\"";
1219
1220 print "<tr class=\"\" $this_row_id>";
1221
1222 $edit_title = htmlspecialchars($line["title"]);
1223
1224 print "<td width='5%' align='center'><input
1225 onclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\"
1226 type=\"checkbox\"></td>";
1227
1228 print "<td>";
1229
1230 # print "<span id=\"FCATT-$cat_id\">" .
1231 # $edit_title . "</span>";
1232
1233 print "<span dojoType=\"dijit.InlineEditBox\"
1234 width=\"300px\" autoSave=\"false\"
1235 cat-id=\"$cat_id\">" . $edit_title .
1236 "<script type=\"dojo/method\" event=\"onChange\" args=\"item\">
1237 var elem = this;
1238 dojo.xhrPost({
1239 url: 'backend.php',
1240 content: {op: 'pref-feeds', subop: 'editCats',
1241 action: 'save',
1242 value: this.value,
1243 cid: this.srcNodeRef.getAttribute('cat-id')},
1244 load: function(response) {
1245 elem.attr('value', response);
1246 updateFeedList();
1247 }
1248 });
1249 </script>
1250 </span>";
1251
1252 print "</td></tr>";
1253
1254 ++$lnum;
1255 }
1256
1257 print "</table>";
1258
1259 # print "</form>";
1260
1261 print "</div>";
1262
1263 } else {
1264 print "<p>".__('No feed categories defined.')."</p>";
1265 }
1266
1267 print "<div class='dlgButtons'>
1268 <div style='float : left'>
1269 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedCatEditDlg').removeSelected()\">".
1270 __('Remove selected categories')."</button>
1271 </div>";
1272
1273 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedCatEditDlg').hide()\">".
1274 __('Close this window')."</button></div>";
1275
1276 return;
1277
1278 }
1279
1280 if ($quiet) return;
1281
1282 print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
1283 print "<div id=\"pref-feeds-feeds\" dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Feeds')."\">";
1284
1285 $result = db_query($link, "SELECT COUNT(id) AS num_errors
1286 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1287
1288 $num_errors = db_fetch_result($result, 0, "num_errors");
1289
1290 if ($num_errors > 0) {
1291
1292 $error_button = "<button dojoType=\"dijit.form.Button\"
1293 onclick=\"showFeedsWithErrors()\" id=\"errorButton\">" .
1294 __("Feeds with errors") . "</button>";
1295
1296 // print format_notice("<a href=\"javascript:showFeedsWithErrors()\">".
1297 // __('Some feeds have update errors (click for details)')."</a>");
1298 }
1299
1300 if (DB_TYPE == "pgsql") {
1301 $interval_qpart = "NOW() - INTERVAL '3 months'";
1302 } else {
1303 $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)";
1304 }
1305
1306 $result = db_query($link, "SELECT COUNT(*) AS num_inactive FROM ttrss_feeds WHERE
1307 (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE
1308 ttrss_entries.id = ref_id AND
1309 ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart AND
1310 ttrss_feeds.owner_uid = ".$_SESSION["uid"]);
1311
1312 $num_inactive = db_fetch_result($result, 0, "num_inactive");
1313
1314 if ($num_inactive > 0) {
1315 $inactive_button = "<button dojoType=\"dijit.form.Button\"
1316 onclick=\"showInactiveFeeds()\">" .
1317 __("Inactive feeds") . "</button>";
1318 }
1319
1320 $feed_search = db_escape_string($_REQUEST["search"]);
1321
1322 if (array_key_exists("search", $_REQUEST)) {
1323 $_SESSION["prefs_feed_search"] = $feed_search;
1324 } else {
1325 $feed_search = $_SESSION["prefs_feed_search"];
1326 }
1327
1328 print "<div dojoType=\"dijit.Toolbar\">";
1329
1330 print "<div style='float : right; padding-right : 4px;'>
1331 <input dojoType=\"dijit.form.TextBox\" id=\"feed_search\" size=\"20\" type=\"search\"
1332 onchange=\"updateFeedList()\" value=\"$feed_search\">
1333 <button dojoType=\"dijit.form.Button\" onclick=\"updateFeedList()\">".
1334 __('Search')."</button>
1335 </div>";
1336
1337 print "<div dojoType=\"dijit.form.DropDownButton\">".
1338 "<span>" . __('Select')."</span>";
1339 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
1340 print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(true)\"
1341 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
1342 print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(false)\"
1343 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
1344 print "</div></div>";
1345
1346 print "<div dojoType=\"dijit.form.DropDownButton\">".
1347 "<span>" . __('Feeds')."</span>";
1348 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
1349 print "<div onclick=\"quickAddFeed()\"
1350 dojoType=\"dijit.MenuItem\">".__('Subscribe to feed')."</div>";
1351 print "<div onclick=\"editSelectedFeed()\"
1352 dojoType=\"dijit.MenuItem\">".__('Edit selected feeds')."</div>";
1353 print "<div onclick=\"resetFeedOrder()\"
1354 dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>";
1355 print "</div></div>";
1356
1357 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1358 print "<div dojoType=\"dijit.form.DropDownButton\">".
1359 "<span>" . __('Categories')."</span>";
1360 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
1361 print "<div onclick=\"editFeedCats()\"
1362 dojoType=\"dijit.MenuItem\">".__('Edit categories')."</div>";
1363 print "<div onclick=\"resetCatOrder()\"
1364 dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>";
1365 print "</div></div>";
1366
1367 }
1368
1369 print $error_button;
1370 print $inactive_button;
1371
1372 print "<button dojoType=\"dijit.form.Button\" onclick=\"removeSelectedFeeds()\">"
1373 .__('Unsubscribe')."</button dojoType=\"dijit.form.Button\"> ";
1374
1375 if (defined('_ENABLE_FEED_DEBUGGING')) {
1376
1377 print "<select id=\"feedActionChooser\" onchange=\"feedActionChange()\">
1378 <option value=\"facDefault\" selected>".__('More actions...')."</option>";
1379
1380 if (FORCE_ARTICLE_PURGE == 0) {
1381 print
1382 "<option value=\"facPurge\">".__('Manual purge')."</option>";
1383 }
1384
1385 print "
1386 <option value=\"facClear\">".__('Clear feed data')."</option>
1387 <option value=\"facRescore\">".__('Rescore articles')."</option>";
1388
1389 print "</select>";
1390
1391 }
1392
1393 print "</div>"; # toolbar
1394
1395 print "<div id=\"feedlistLoading\">
1396 <img src='images/indicator_tiny.gif'>".
1397 __("Loading, please wait...")."</div>";
1398
1399 print "<div dojoType=\"fox.PrefFeedStore\" jsId=\"feedStore\"
1400 url=\"backend.php?op=pref-feeds&subop=getfeedtree\">
1401 </div>
1402 <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"feedModel\" store=\"feedStore\"
1403 query=\"{id:'root'}\" rootId=\"root\" rootLabel=\"Feeds\"
1404 childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">
1405 </div>
1406 <div dojoType=\"fox.PrefFeedTree\" id=\"feedTree\"
1407 dndController=\"dijit.tree.dndSource\"
1408 betweenThreshold=\"5\"
1409 model=\"feedModel\" openOnClick=\"false\">
1410 <script type=\"dojo/method\" event=\"onClick\" args=\"item\">
1411 var id = String(item.id);
1412 var bare_id = id.substr(id.indexOf(':')+1);
1413
1414 if (id.match('FEED:')) {
1415 editFeed(bare_id);
1416 } else if (id.match('CAT:')) {
1417 editCat(bare_id, item);
1418 }
1419 </script>
1420 <script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
1421 Element.hide(\"feedlistLoading\");
1422 </script>
1423 </div>";
1424
1425 print "<div dojoType=\"dijit.Tooltip\" connectId=\"feedTree\" position=\"below\">
1426 ".__('<b>Hint:</b> you can drag feeds and categories around.')."
1427 </div>";
1428
1429 print "</div>"; # feeds pane
1430
1431 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('OPML')."\">";
1432
1433 print "<p>" . __("Using OPML you can export and import your feeds and Tiny Tiny RSS settings.") . " ";
1434
1435 print "<span class=\"insensitive\">" . __("Note: Only main settings profile can be migrated using OPML.") . "</span>";
1436
1437 print "</p>";
1438
1439 print "<h3>" . __("Import") . "</h3>";
1440
1441 print "<br/><iframe id=\"upload_iframe\"
1442 name=\"upload_iframe\" onload=\"opmlImportComplete(this)\"
1443 style=\"width: 400px; height: 100px; display: none;\"></iframe>";
1444
1445 print "<form name=\"opml_form\" style='display : block' target=\"upload_iframe\"
1446 enctype=\"multipart/form-data\" method=\"POST\"
1447 action=\"backend.php\">
1448 <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
1449 <input type=\"hidden\" name=\"op\" value=\"dlg\">
1450 <input type=\"hidden\" name=\"id\" value=\"importOpml\">
1451 <button dojoType=\"dijit.form.Button\" onclick=\"return opmlImport();\" type=\"submit\">" .
1452 __('Import') . "</button>";
1453
1454 print "<h3>" . __("Export") . "</h3>";
1455
1456 print "<p>" . __('Filename:') .
1457 " <input type=\"text\" id=\"filename\" value=\"TinyTinyRSS.opml\" />&nbsp;" .
1458 __('Include settings') . "<input type=\"checkbox\" id=\"settings\" CHECKED />" .
1459
1460 "<button dojoType=\"dijit.form.Button\"
1461 onclick=\"gotoExportOpml(document.opml_form.filename.value, document.opml_form.settings.checked)\" >" .
1462 __('Export') . "</button></p></form>";
1463
1464 print "<h3>" . __("Publish") . "</h3>";
1465
1466 print "<p>".__('Your OPML can be published publicly and can be subscribed by anyone who knows the URL below.') . " ";
1467
1468 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>";
1469
1470 print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('pubOPMLUrl')\">".
1471 __('Display URL')."</button> ";
1472
1473
1474 print "</div>"; # pane
1475
1476 if (strpos($_SERVER['HTTP_USER_AGENT'], "Firefox") !== false) {
1477
1478 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Firefox integration')."\">";
1479
1480 print "<p>" . __('This Tiny Tiny RSS site can be used as a Firefox Feed Reader by clicking the link below.') . "</p>";
1481
1482 print "<p>";
1483
1484 print "<button onclick='window.navigator.registerContentHandler(" .
1485 "\"application/vnd.mozilla.maybe.feed\", " .
1486 "\"" . add_feed_url() . "\", " . " \"Tiny Tiny RSS\")'>" .
1487 __('Click here to register this site as a feed reader.') .
1488 "</button>";
1489
1490 print "</p>";
1491
1492 print "</div>"; # pane
1493 }
1494
1495 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Subscribing using bookmarklet')."\">";
1496
1497 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>";
1498
1499 $bm_subscribe_url = str_replace('%s', '', add_feed_url());
1500
1501 $confirm_str = __('Subscribe to %s in Tiny Tiny RSS?');
1502
1503 $bm_url = htmlspecialchars("javascript:{if(confirm('$confirm_str'.replace('%s',window.location.href)))window.location.href='$bm_subscribe_url'+window.location.href}");
1504
1505 print "<a href=\"$bm_url\" class='bookmarklet'>" . __('Subscribe in Tiny Tiny RSS'). "</a>";
1506
1507 print "</div>"; #pane
1508
1509 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Published articles and generated feeds')."\">";
1510
1511 print "<p>".__('Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the URL specified below.')."</p>";
1512
1513 $rss_url = '-2::' . htmlspecialchars(get_self_url_prefix() .
1514 "/backend.php?op=rss&id=-2&view-mode=all_articles");;
1515
1516 print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('generatedFeed', '$rss_url')\">".
1517 __('Display URL')."</button> ";
1518
1519 print "<button dojoType=\"dijit.form.Button\" onclick=\"return clearFeedAccessKeys()\">".
1520 __('Clear all generated URLs')."</button> ";
1521
1522 print "</div>"; #pane
1523
1524 if (defined('CONSUMER_KEY') && CONSUMER_KEY != '') {
1525
1526 print "<div id=\"pref-feeds-twitter\" dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Twitter')."\">";
1527
1528 $result = db_query($link, "SELECT COUNT(*) AS cid FROM ttrss_users
1529 WHERE twitter_oauth IS NOT NULL AND twitter_oauth != '' AND
1530 id = " . $_SESSION['uid']);
1531
1532 $is_registered = db_fetch_result($result, 0, "cid") != 0;
1533
1534 if (!$is_registered) {
1535 print_notice(__('Before you can update your Twitter feeds, you must register this instance of Tiny Tiny RSS with Twitter.com.'));
1536 } else {
1537 print_notice(__('You have been successfully registered with Twitter.com and should be able to access your Twitter feeds.'));
1538 }
1539
1540 print "<button dojoType=\"dijit.form.Button\" onclick=\"window.location.href = 'twitter.php?op=register'\">".
1541 __("Register with Twitter.com")."</button>";
1542
1543 print " ";
1544
1545 print "<button dojoType=\"dijit.form.Button\"
1546 onclick=\"return clearTwitterCredentials()\">".
1547 __("Clear stored credentials")."</button>";
1548
1549 print "</div>"; # pane
1550
1551 }
1552
1553 print "</div>"; #container
1554
1555 }
1556
1557 function make_feed_browser($link, $search, $limit, $mode = 1) {
1558
1559 $owner_uid = $_SESSION["uid"];
1560 $rv = '';
1561
1562 if ($search) {
1563 $search_qpart = "AND (UPPER(feed_url) LIKE UPPER('%$search%') OR
1564 UPPER(title) LIKE UPPER('%$search%'))";
1565 } else {
1566 $search_qpart = "";
1567 }
1568
1569 if ($mode == 1) {
1570 /* $result = db_query($link, "SELECT feed_url, subscribers FROM
1571 ttrss_feedbrowser_cache WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf
1572 WHERE tf.feed_url = ttrss_feedbrowser_cache.feed_url
1573 AND owner_uid = '$owner_uid') $search_qpart
1574 ORDER BY subscribers DESC LIMIT $limit"); */
1575
1576 $result = db_query($link, "SELECT feed_url, site_url, title, SUM(subscribers) AS subscribers FROM
1577 (SELECT feed_url, site_url, title, subscribers FROM ttrss_feedbrowser_cache UNION ALL
1578 SELECT feed_url, site_url, title, subscribers FROM ttrss_linked_feeds) AS qqq
1579 WHERE
1580 (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf
1581 WHERE tf.feed_url = qqq.feed_url
1582 AND owner_uid = '$owner_uid') $search_qpart
1583 GROUP BY feed_url, site_url, title ORDER BY subscribers DESC LIMIT $limit");
1584
1585 } else if ($mode == 2) {
1586 $result = db_query($link, "SELECT *,
1587 (SELECT COUNT(*) FROM ttrss_user_entries WHERE
1588 orig_feed_id = ttrss_archived_feeds.id) AS articles_archived
1589 FROM
1590 ttrss_archived_feeds
1591 WHERE
1592 (SELECT COUNT(*) FROM ttrss_feeds
1593 WHERE ttrss_feeds.feed_url = ttrss_archived_feeds.feed_url AND
1594 owner_uid = '$owner_uid') = 0 AND
1595 owner_uid = '$owner_uid' $search_qpart
1596 ORDER BY id DESC LIMIT $limit");
1597 }
1598
1599 $feedctr = 0;
1600
1601 while ($line = db_fetch_assoc($result)) {
1602
1603 if ($mode == 1) {
1604
1605 $feed_url = htmlspecialchars($line["feed_url"]);
1606 $site_url = htmlspecialchars($line["site_url"]);
1607 $subscribers = $line["subscribers"];
1608
1609 $check_box = "<input onclick='toggleSelectListRow2(this)'
1610 dojoType=\"dijit.form.CheckBox\"
1611 type=\"checkbox\" \">";
1612
1613 $class = ($feedctr % 2) ? "even" : "odd";
1614
1615 $site_url = "<a target=\"_blank\"
1616 href=\"$site_url\">
1617 <span class=\"fb_feedTitle\">".
1618 htmlspecialchars($line["title"])."</span></a>";
1619
1620 $feed_url = "<a target=\"_blank\" class=\"fb_feedUrl\"
1621 href=\"$feed_url\"><img src='images/feed-icon-12x12.png'
1622 style='vertical-align : middle'></a>";
1623
1624 $rv .= "<li>$check_box $feed_url $site_url".
1625 "&nbsp;<span class='subscribers'>($subscribers)</span></li>";
1626
1627 } else if ($mode == 2) {
1628 $feed_url = htmlspecialchars($line["feed_url"]);
1629 $site_url = htmlspecialchars($line["site_url"]);
1630 $title = htmlspecialchars($line["title"]);
1631
1632 $check_box = "<input onclick='toggleSelectListRow2(this)' dojoType=\"dijit.form.CheckBox\"
1633 type=\"checkbox\">";
1634
1635 $class = ($feedctr % 2) ? "even" : "odd";
1636
1637 if ($line['articles_archived'] > 0) {
1638 $archived = sprintf(__("%d archived articles"), $line['articles_archived']);
1639 $archived = "&nbsp;<span class='subscribers'>($archived)</span>";
1640 } else {
1641 $archived = '';
1642 }
1643
1644 $site_url = "<a target=\"_blank\"
1645 href=\"$site_url\">
1646 <span class=\"fb_feedTitle\">".
1647 htmlspecialchars($line["title"])."</span></a>";
1648
1649 $feed_url = "<a target=\"_blank\" class=\"fb_feedUrl\"
1650 href=\"$feed_url\"><img src='images/feed-icon-12x12.png'
1651 style='vertical-align : middle'></a>";
1652
1653
1654 $rv .= "<li id=\"FBROW-".$line["id"]."\">".
1655 "$check_box $feed_url $site_url $archived</li>";
1656 }
1657
1658 ++$feedctr;
1659 }
1660
1661 if ($feedctr == 0) {
1662 $rv .= "<li style=\"text-align : center\"><p>".__('No feeds found.')."</p></li>";
1663 }
1664
1665 return $rv;
1666
1667 }
1668
1669 ?>