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