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