]> git.wh0rd.org - tt-rss.git/blob - modules/pref-feeds.php
add ttrss_feeds.update_on_checksum_change
[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 if (SIMPLEPIE_CACHE_IMAGES) {
447 print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"cache_images\"
448 name=\"cache_images\"
449 $checked>&nbsp;<label for=\"cache_images\">".
450 __('Cache images locally (SimplePie only)')."</label>";
451 }
452
453 $mark_unread_on_update = sql_bool_to_bool(db_fetch_result($result, 0, "mark_unread_on_update"));
454
455 if ($mark_unread_on_update) {
456 $checked = "checked";
457 } else {
458 $checked = "";
459 }
460
461 print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"mark_unread_on_update\"
462 name=\"mark_unread_on_update\"
463 $checked>&nbsp;<label for=\"mark_unread_on_update\">".__('Mark updated articles as unread')."</label>";
464
465 $update_on_checksum_change = sql_bool_to_bool(db_fetch_result($result, 0, "update_on_checksum_change"));
466
467 if ($update_on_checksum_change) {
468 $checked = "checked";
469 } else {
470 $checked = "";
471 }
472
473 print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"update_on_checksum_change\"
474 name=\"update_on_checksum_change\"
475 $checked>&nbsp;<label for=\"update_on_checksum_change\">".__('Mark posts as updated on content change')."</label>";
476
477 # print "</div>";
478 print "</div>";
479
480 /* Icon */
481
482 print "<div class=\"dlgSec\">".__("Icon")."</div>";
483 print "<div class=\"dlgSecCont\">";
484
485 print "<iframe name=\"icon_upload_iframe\"
486 style=\"width: 400px; height: 100px; display: none;\"></iframe>";
487
488 print "<form style='display : block' target=\"icon_upload_iframe\"
489 enctype=\"multipart/form-data\" method=\"POST\"
490 action=\"backend.php\">
491 <input id=\"icon_file\" size=\"10\" name=\"icon_file\" type=\"file\">
492 <input type=\"hidden\" name=\"op\" value=\"pref-feeds\">
493 <input type=\"hidden\" name=\"feed_id\" value=\"$feed_id\">
494 <input type=\"hidden\" name=\"subop\" value=\"uploadicon\">
495 <button dojoType=\"dijit.form.Button\" onclick=\"return uploadFeedIcon();\"
496 type=\"submit\">".__('Replace')."</button>
497 <button dojoType=\"dijit.form.Button\" onclick=\"return removeFeedIcon($feed_id);\"
498 type=\"submit\">".__('Remove')."</button>
499 </form>";
500
501 print "</div>";
502
503 $title = htmlspecialchars($title, ENT_QUOTES);
504
505 print "<div class='dlgButtons'>
506 <div style=\"float : left\">
507 <button dojoType=\"dijit.form.Button\" onclick='return unsubscribeFeed($feed_id, \"$title\")'>".
508 __('Unsubscribe')."</button>
509 </div>
510 <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedEditDlg').execute()\">".__('Save')."</button>
511 <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedEditDlg').hide()\">".__('Cancel')."</button>
512 </div>";
513
514 return;
515 }
516
517 if ($subop == "editfeeds") {
518
519 $feed_ids = db_escape_string($_REQUEST["ids"]);
520
521 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"ids\" value=\"$feed_ids\">";
522 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-feeds\">";
523 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"batchEditSave\">";
524
525 print "<div class=\"dlgSec\">".__("Feed")."</div>";
526 print "<div class=\"dlgSecCont\">";
527
528 /* Title */
529
530 print "<input dojoType=\"dijit.form.ValidationTextBox\"
531 disabled=\"1\" style=\"font-size : 16px; width : 20em;\" required=\"1\"
532 name=\"title\" value=\"$title\">";
533
534 batch_edit_cbox("title");
535
536 /* Feed URL */
537
538 print "<br/>";
539
540 print __('URL:') . " ";
541 print "<input dojoType=\"dijit.form.ValidationTextBox\" disabled=\"1\"
542 required=\"1\" regExp='^(http|https)://.*' style=\"width : 20em\"
543 name=\"feed_url\" value=\"$feed_url\">";
544
545 batch_edit_cbox("feed_url");
546
547 /* Category */
548
549 if (get_pref($link, 'ENABLE_FEED_CATS')) {
550
551 print "<br/>";
552
553 print __('Place in category:') . " ";
554
555 print_feed_cat_select($link, "cat_id", $cat_id,
556 'disabled="1" dojoType="dijit.form.Select"');
557
558 batch_edit_cbox("cat_id");
559
560 }
561
562 print "</div>";
563
564 print "<div class=\"dlgSec\">".__("Update")."</div>";
565 print "<div class=\"dlgSecCont\">";
566
567 /* Update Interval */
568
569 print_select_hash("update_interval", $update_interval, $update_intervals,
570 'disabled="1" dojoType="dijit.form.Select"');
571
572 batch_edit_cbox("update_interval");
573
574 /* Update method */
575
576 print " " . __('using') . " ";
577 print_select_hash("update_method", $update_method, $update_methods,
578 'disabled="1" dojoType="dijit.form.Select"');
579 batch_edit_cbox("update_method");
580
581 /* Purge intl */
582
583 if (FORCE_ARTICLE_PURGE == 0) {
584
585 print "<br/>";
586
587 print __('Article purging:') . " ";
588
589 print_select_hash("purge_interval", $purge_interval, $purge_intervals,
590 'disabled="1" dojoType="dijit.form.Select"');
591
592 batch_edit_cbox("purge_interval");
593 }
594
595 print "</div>";
596 print "<div class=\"dlgSec\">".__("Authentication")."</div>";
597 print "<div class=\"dlgSecCont\">";
598
599 print "<input dojoType=\"dijit.form.TextBox\"
600 placeHolder=\"".__("Login")."\" disabled=\"1\"
601 name=\"auth_login\" value=\"$auth_login\">";
602
603 batch_edit_cbox("auth_login");
604
605 print "<br/><input dojoType=\"dijit.form.TextBox\" type=\"password\" name=\"auth_pass\"
606 placeHolder=\"".__("Password")."\" disabled=\"1\"
607 value=\"$auth_pass\">";
608
609 batch_edit_cbox("auth_pass");
610
611 print "</div>";
612 print "<div class=\"dlgSec\">".__("Options")."</div>";
613 print "<div class=\"dlgSecCont\">";
614
615 print "<input disabled=\"1\" type=\"checkbox\" name=\"private\" id=\"private\"
616 dojoType=\"dijit.form.CheckBox\">&nbsp;<label id=\"private_l\" class='insensitive' for=\"private\">".__('Hide from Popular feeds')."</label>";
617
618 print "&nbsp;"; batch_edit_cbox("private", "private_l");
619
620 print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"
621 dojoType=\"dijit.form.CheckBox\">&nbsp;<label class='insensitive' id=\"rtl_content_l\" for=\"rtl_content\">".__('Right-to-left content')."</label>";
622
623 print "&nbsp;"; batch_edit_cbox("rtl_content", "rtl_content_l");
624
625 print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"include_in_digest\"
626 name=\"include_in_digest\"
627 dojoType=\"dijit.form.CheckBox\">&nbsp;<label id=\"include_in_digest_l\" class='insensitive' for=\"include_in_digest\">".__('Include in e-mail digest')."</label>";
628
629 print "&nbsp;"; batch_edit_cbox("include_in_digest", "include_in_digest_l");
630
631 print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"always_display_enclosures\"
632 name=\"always_display_enclosures\"
633 dojoType=\"dijit.form.CheckBox\">&nbsp;<label id=\"always_display_enclosures_l\" class='insensitive' for=\"always_display_enclosures\">".__('Always display image attachments')."</label>";
634
635 print "&nbsp;"; batch_edit_cbox("always_display_enclosures", "always_display_enclosures_l");
636
637 if (SIMPLEPIE_CACHE_IMAGES) {
638 print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"cache_images\"
639 name=\"cache_images\"
640 dojoType=\"dijit.form.CheckBox\">&nbsp;<label class='insensitive' id=\"cache_images_l\"
641 for=\"cache_images\">".
642 __('Cache images locally')."</label>";
643
644
645 print "&nbsp;"; batch_edit_cbox("cache_images", "cache_images_l");
646 }
647
648 print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"mark_unread_on_update\"
649 name=\"mark_unread_on_update\"
650 dojoType=\"dijit.form.CheckBox\">&nbsp;<label id=\"mark_unread_on_update_l\" class='insensitive' for=\"mark_unread_on_update\">".__('Mark updated articles as unread')."</label>";
651
652 print "&nbsp;"; batch_edit_cbox("mark_unread_on_update", "mark_unread_on_update_l");
653
654 print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"update_on_checksum_change\"
655 name=\"update_on_checksum_change\"
656 dojoType=\"dijit.form.CheckBox\">&nbsp;<label id=\"update_on_checksum_change_l\" class='insensitive' for=\"update_on_checksum_change\">".__('Mark posts as updated on content change')."</label>";
657
658 print "&nbsp;"; batch_edit_cbox("update_on_checksum_change", "update_on_checksum_change_l");
659
660 print "</div>";
661
662 print "<div class='dlgButtons'>
663 <button dojoType=\"dijit.form.Button\"
664 onclick=\"return dijit.byId('feedEditDlg').execute()\">".
665 __('Save')."</button>
666 <button dojoType=\"dijit.form.Button\"
667 onclick=\"return dijit.byId('feedEditDlg').hide()\">".
668 __('Cancel')."</button>
669 </div>";
670
671 return;
672 }
673
674 if ($subop == "editSave" || $subop == "batchEditSave") {
675
676 $feed_title = db_escape_string(trim($_POST["title"]));
677 $feed_link = db_escape_string(trim($_POST["feed_url"]));
678 $upd_intl = db_escape_string($_POST["update_interval"]);
679 $purge_intl = db_escape_string($_POST["purge_interval"]);
680 $feed_id = db_escape_string($_POST["id"]); /* editSave */
681 $feed_ids = db_escape_string($_POST["ids"]); /* batchEditSave */
682 $cat_id = db_escape_string($_POST["cat_id"]);
683 $auth_login = db_escape_string(trim($_POST["auth_login"]));
684 $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
685 $private = checkbox_to_sql_bool(db_escape_string($_POST["private"]));
686 $rtl_content = checkbox_to_sql_bool(db_escape_string($_POST["rtl_content"]));
687 $include_in_digest = checkbox_to_sql_bool(
688 db_escape_string($_POST["include_in_digest"]));
689 $cache_images = checkbox_to_sql_bool(
690 db_escape_string($_POST["cache_images"]));
691 $update_method = (int) db_escape_string($_POST["update_method"]);
692
693 $always_display_enclosures = checkbox_to_sql_bool(
694 db_escape_string($_POST["always_display_enclosures"]));
695
696 $mark_unread_on_update = checkbox_to_sql_bool(
697 db_escape_string($_POST["mark_unread_on_update"]));
698
699 $update_on_checksum_change = checkbox_to_sql_bool(
700 db_escape_string($_POST["update_on_checksum_change"]));
701
702 if (get_pref($link, 'ENABLE_FEED_CATS')) {
703 if ($cat_id && $cat_id != 0) {
704 $category_qpart = "cat_id = '$cat_id',";
705 $category_qpart_nocomma = "cat_id = '$cat_id'";
706 } else {
707 $category_qpart = 'cat_id = NULL,';
708 $category_qpart_nocomma = 'cat_id = NULL';
709 }
710 } else {
711 $category_qpart = "";
712 $category_qpart_nocomma = "";
713 }
714
715 if (SIMPLEPIE_CACHE_IMAGES) {
716 $cache_images_qpart = "cache_images = $cache_images,";
717 } else {
718 $cache_images_qpart = "";
719 }
720
721 if ($subop == "editSave") {
722
723 $result = db_query($link, "UPDATE ttrss_feeds SET
724 $category_qpart
725 title = '$feed_title', feed_url = '$feed_link',
726 update_interval = '$upd_intl',
727 purge_interval = '$purge_intl',
728 auth_login = '$auth_login',
729 auth_pass = '$auth_pass',
730 private = $private,
731 rtl_content = $rtl_content,
732 $cache_images_qpart
733 include_in_digest = $include_in_digest,
734 always_display_enclosures = $always_display_enclosures,
735 mark_unread_on_update = $mark_unread_on_update,
736 update_on_checksum_change = $update_on_checksum_change,
737 update_method = '$update_method'
738 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
739
740 } else if ($subop == "batchEditSave") {
741 $feed_data = array();
742
743 foreach (array_keys($_POST) as $k) {
744 if ($k != "op" && $k != "subop" && $k != "ids") {
745 $feed_data[$k] = $_POST[$k];
746 }
747 }
748
749 db_query($link, "BEGIN");
750
751 foreach (array_keys($feed_data) as $k) {
752
753 $qpart = "";
754
755 switch ($k) {
756 case "title":
757 $qpart = "title = '$feed_title'";
758 break;
759
760 case "feed_url":
761 $qpart = "feed_url = '$feed_link'";
762 break;
763
764 case "update_interval":
765 $qpart = "update_interval = '$upd_intl'";
766 break;
767
768 case "purge_interval":
769 $qpart = "purge_interval = '$purge_intl'";
770 break;
771
772 case "auth_login":
773 $qpart = "auth_login = '$auth_login'";
774 break;
775
776 case "auth_pass":
777 $qpart = "auth_pass = '$auth_pass'";
778 break;
779
780 case "private":
781 $qpart = "private = '$private'";
782 break;
783
784 case "include_in_digest":
785 $qpart = "include_in_digest = '$include_in_digest'";
786 break;
787
788 case "always_display_enclosures":
789 $qpart = "always_display_enclosures = '$always_display_enclosures'";
790 break;
791
792 case "mark_unread_on_update":
793 $qpart = "mark_unread_on_update = '$mark_unread_on_update'";
794 break;
795
796 case "update_on_checksum_change":
797 $qpart = "update_on_checksum_change = '$update_on_checksum_change'";
798 break;
799
800 case "cache_images":
801 $qpart = "cache_images = '$cache_images'";
802 break;
803
804 case "rtl_content":
805 $qpart = "rtl_content = '$rtl_content'";
806 break;
807
808 case "update_method":
809 $qpart = "update_method = '$update_method'";
810 break;
811
812 case "cat_id":
813 $qpart = $category_qpart_nocomma;
814 break;
815
816 }
817
818 if ($qpart) {
819 db_query($link,
820 "UPDATE ttrss_feeds SET $qpart WHERE id IN ($feed_ids)
821 AND owner_uid = " . $_SESSION["uid"]);
822 print "<br/>";
823 }
824 }
825
826 db_query($link, "COMMIT");
827 }
828 return;
829 }
830
831 if ($subop == "remove") {
832
833 $ids = split(",", db_escape_string($_REQUEST["ids"]));
834
835 foreach ($ids as $id) {
836 remove_feed($link, $id, $_SESSION["uid"]);
837 }
838
839 return;
840 }
841
842 if ($subop == "clear") {
843 $id = db_escape_string($_REQUEST["id"]);
844 clear_feed_articles($link, $id);
845 }
846
847 if ($subop == "rescore") {
848 $ids = split(",", db_escape_string($_REQUEST["ids"]));
849
850 foreach ($ids as $id) {
851
852 $filters = load_filters($link, $id, $_SESSION["uid"], 6);
853
854 $result = db_query($link, "SELECT
855 title, content, link, ref_id, author,".
856 SUBSTRING_FOR_DATE."(updated, 1, 19) AS updated
857 FROM
858 ttrss_user_entries, ttrss_entries
859 WHERE ref_id = id AND feed_id = '$id' AND
860 owner_uid = " .$_SESSION['uid']."
861 ");
862
863 $scores = array();
864
865 while ($line = db_fetch_assoc($result)) {
866
867 $tags = get_article_tags($link, $line["ref_id"]);
868
869 $article_filters = get_article_filters($filters, $line['title'],
870 $line['content'], $line['link'], strtotime($line['updated']),
871 $line['author'], $tags);
872
873 $new_score = calculate_article_score($article_filters);
874
875 if (!$scores[$new_score]) $scores[$new_score] = array();
876
877 array_push($scores[$new_score], $line['ref_id']);
878 }
879
880 foreach (array_keys($scores) as $s) {
881 if ($s > 1000) {
882 db_query($link, "UPDATE ttrss_user_entries SET score = '$s',
883 marked = true WHERE
884 ref_id IN (" . join(',', $scores[$s]) . ")");
885 } else if ($s < -500) {
886 db_query($link, "UPDATE ttrss_user_entries SET score = '$s',
887 unread = false WHERE
888 ref_id IN (" . join(',', $scores[$s]) . ")");
889 } else {
890 db_query($link, "UPDATE ttrss_user_entries SET score = '$s' WHERE
891 ref_id IN (" . join(',', $scores[$s]) . ")");
892 }
893 }
894 }
895
896 print __("All done.");
897
898 }
899
900 if ($subop == "rescoreAll") {
901
902 $result = db_query($link,
903 "SELECT id FROM ttrss_feeds WHERE owner_uid = " . $_SESSION['uid']);
904
905 while ($feed_line = db_fetch_assoc($result)) {
906
907 $id = $feed_line["id"];
908
909 $filters = load_filters($link, $id, $_SESSION["uid"], 6);
910
911 $tmp_result = db_query($link, "SELECT
912 title, content, link, ref_id, author,".
913 SUBSTRING_FOR_DATE."(updated, 1, 19) AS updated
914 FROM
915 ttrss_user_entries, ttrss_entries
916 WHERE ref_id = id AND feed_id = '$id' AND
917 owner_uid = " .$_SESSION['uid']."
918 ");
919
920 $scores = array();
921
922 while ($line = db_fetch_assoc($tmp_result)) {
923
924 $tags = get_article_tags($link, $line["ref_id"]);
925
926 $article_filters = get_article_filters($filters, $line['title'],
927 $line['content'], $line['link'], strtotime($line['updated']),
928 $line['author'], $tags);
929
930 $new_score = calculate_article_score($article_filters);
931
932 if (!$scores[$new_score]) $scores[$new_score] = array();
933
934 array_push($scores[$new_score], $line['ref_id']);
935 }
936
937 foreach (array_keys($scores) as $s) {
938 if ($s > 1000) {
939 db_query($link, "UPDATE ttrss_user_entries SET score = '$s',
940 marked = true WHERE
941 ref_id IN (" . join(',', $scores[$s]) . ")");
942 } else {
943 db_query($link, "UPDATE ttrss_user_entries SET score = '$s' WHERE
944 ref_id IN (" . join(',', $scores[$s]) . ")");
945 }
946 }
947 }
948
949 print __("All done.");
950
951 }
952
953 if ($subop == "add") {
954
955 $feed_url = db_escape_string(trim($_REQUEST["feed_url"]));
956 $cat_id = db_escape_string($_REQUEST["cat_id"]);
957 $p_from = db_escape_string($_REQUEST["from"]);
958
959 /* only read authentication information from POST */
960
961 $auth_login = db_escape_string(trim($_POST["auth_login"]));
962 $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
963
964 if ($p_from != 'tt-rss') {
965 print "<html>
966 <head>
967 <title>Tiny Tiny RSS</title>
968 <link rel=\"stylesheet\" type=\"text/css\" href=\"utility.css\">
969 </head>
970 <body>
971 <img class=\"floatingLogo\" src=\"images/ttrss_logo.png\"
972 alt=\"Tiny Tiny RSS\"/>
973 <h1>Subscribe to feed...</h1>";
974 }
975
976 $rc = subscribe_to_feed($link, $feed_url, $cat_id, $auth_login, $auth_pass);
977
978 switch ($rc) {
979 case 1:
980 print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
981 break;
982 case 2:
983 print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
984 break;
985 case 0:
986 print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
987 break;
988 case 4:
989 print_notice("Multiple feed URLs found.");
990
991 $feed_urls = get_feeds_from_html($feed_url);
992 break;
993 case 5:
994 print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
995 break;
996 }
997
998 if ($p_from != 'tt-rss') {
999
1000 if ($feed_urls) {
1001
1002 print "<form action=\"backend.php\">";
1003 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
1004 print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
1005 print "<input type=\"hidden\" name=\"subop\" value=\"add\">";
1006
1007 print "<select name=\"feed_url\">";
1008
1009 foreach ($feed_urls as $url => $name) {
1010 $url = htmlspecialchars($url);
1011 $name = htmlspecialchars($name);
1012
1013 print "<option value=\"$url\">$name</option>";
1014 }
1015
1016 print "<input type=\"submit\" value=\"".__("Subscribe to selected feed").
1017 "\">";
1018
1019 print "</form>";
1020 }
1021
1022 $tp_uri = get_self_url_prefix() . "/prefs.php";
1023 $tt_uri = get_self_url_prefix();
1024
1025 if ($rc <= 2){
1026 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
1027 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
1028
1029 $feed_id = db_fetch_result($result, 0, "id");
1030 } else {
1031 $feed_id = 0;
1032 }
1033 print "<p>";
1034
1035 if ($feed_id) {
1036 print "<form method=\"GET\" style='display: inline'
1037 action=\"$tp_uri\">
1038 <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
1039 <input type=\"hidden\" name=\"subop\" value=\"editFeed\">
1040 <input type=\"hidden\" name=\"subopparam\" value=\"$feed_id\">
1041 <input type=\"submit\" value=\"".__("Edit subscription options")."\">
1042 </form>";
1043 }
1044
1045 print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
1046 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
1047 </form></p>";
1048
1049 print "</body></html>";
1050 return;
1051 }
1052 }
1053
1054 if ($subop == "categorize") {
1055
1056
1057 $ids = split(",", db_escape_string($_REQUEST["ids"]));
1058
1059 $cat_id = db_escape_string($_REQUEST["cat_id"]);
1060
1061 if ($cat_id == 0) {
1062 $cat_id_qpart = 'NULL';
1063 } else {
1064 $cat_id_qpart = "'$cat_id'";
1065 }
1066
1067 db_query($link, "BEGIN");
1068
1069 foreach ($ids as $id) {
1070
1071 db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
1072 WHERE id = '$id'
1073 AND owner_uid = " . $_SESSION["uid"]);
1074
1075 }
1076
1077 db_query($link, "COMMIT");
1078
1079 }
1080
1081 if ($subop == "editCats") {
1082
1083 $action = $_REQUEST["action"];
1084
1085 if ($action == "save") {
1086
1087 $cat_title = db_escape_string(trim($_REQUEST["value"]));
1088 $cat_id = db_escape_string($_REQUEST["cid"]);
1089
1090 db_query($link, "BEGIN");
1091
1092 $result = db_query($link, "SELECT title FROM ttrss_feed_categories
1093 WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
1094
1095 if (db_num_rows($result) == 1) {
1096
1097 $old_title = db_fetch_result($result, 0, "title");
1098
1099 if ($cat_title != "") {
1100 $result = db_query($link, "UPDATE ttrss_feed_categories SET
1101 title = '$cat_title' WHERE id = '$cat_id' AND
1102 owner_uid = ".$_SESSION["uid"]);
1103
1104 print $cat_title;
1105 } else {
1106 print $old_title;
1107 }
1108 } else {
1109 print $_REQUEST["value"];
1110 }
1111
1112 db_query($link, "COMMIT");
1113
1114 return;
1115
1116 }
1117
1118 if ($action == "add") {
1119
1120 $feed_cat = db_escape_string(trim($_REQUEST["cat"]));
1121
1122 if (!add_feed_category($link, $feed_cat))
1123 print_warning(T_sprintf("Category <b>$%s</b> already exists in the database.", $feed_cat));
1124
1125 }
1126
1127 if ($action == "remove") {
1128
1129 $ids = split(",", db_escape_string($_REQUEST["ids"]));
1130
1131 foreach ($ids as $id) {
1132 remove_feed_category($link, $id, $_SESSION["uid"]);
1133 }
1134 }
1135
1136 print "<div dojoType=\"dijit.Toolbar\">
1137 <input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"newcat\">
1138 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedCatEditDlg').addCategory()\">".
1139 __('Create category')."</button></div>";
1140
1141 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
1142 WHERE owner_uid = ".$_SESSION["uid"]."
1143 ORDER BY title");
1144
1145 # print "<p>";
1146
1147 if (db_num_rows($result) != 0) {
1148
1149 print "<div class=\"prefFeedCatHolder\">";
1150
1151 # print "<form id=\"feed_cat_edit_form\" onsubmit=\"return false\">";
1152
1153 print "<table width=\"100%\" class=\"prefFeedCatList\"
1154 cellspacing=\"0\" id=\"prefFeedCatList\">";
1155
1156 $lnum = 0;
1157
1158 while ($line = db_fetch_assoc($result)) {
1159
1160 $class = ($lnum % 2) ? "even" : "odd";
1161
1162 $cat_id = $line["id"];
1163 $this_row_id = "id=\"FCATR-$cat_id\"";
1164
1165 print "<tr class=\"\" $this_row_id>";
1166
1167 $edit_title = htmlspecialchars($line["title"]);
1168
1169 print "<td width='5%' align='center'><input
1170 onclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\"
1171 type=\"checkbox\"></td>";
1172
1173 print "<td>";
1174
1175 # print "<span id=\"FCATT-$cat_id\">" .
1176 # $edit_title . "</span>";
1177
1178 print "<span dojoType=\"dijit.InlineEditBox\"
1179 width=\"300px\" autoSave=\"false\"
1180 cat-id=\"$cat_id\">" . $edit_title .
1181 "<script type=\"dojo/method\" event=\"onChange\" args=\"item\">
1182 var elem = this;
1183 dojo.xhrPost({
1184 url: 'backend.php',
1185 content: {op: 'pref-feeds', subop: 'editCats',
1186 action: 'save',
1187 value: this.value,
1188 cid: this.srcNodeRef.getAttribute('cat-id')},
1189 load: function(response) {
1190 elem.attr('value', response);
1191 updateFeedList();
1192 }
1193 });
1194 </script>
1195 </span>";
1196
1197 print "</td></tr>";
1198
1199 ++$lnum;
1200 }
1201
1202 print "</table>";
1203
1204 # print "</form>";
1205
1206 print "</div>";
1207
1208 } else {
1209 print "<p>".__('No feed categories defined.')."</p>";
1210 }
1211
1212 print "<div class='dlgButtons'>
1213 <div style='float : left'>
1214 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedCatEditDlg').removeSelected()\">".
1215 __('Remove selected categories')."</button>
1216 </div>";
1217
1218 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedCatEditDlg').hide()\">".
1219 __('Close this window')."</button></div>";
1220
1221 return;
1222
1223 }
1224
1225 if ($quiet) return;
1226
1227 print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
1228 print "<div id=\"pref-feeds-feeds\" dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Feeds')."\">";
1229
1230 $result = db_query($link, "SELECT COUNT(id) AS num_errors
1231 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1232
1233 $num_errors = db_fetch_result($result, 0, "num_errors");
1234
1235 if ($num_errors > 0) {
1236
1237 $error_button = "<button dojoType=\"dijit.form.Button\"
1238 onclick=\"showFeedsWithErrors()\" id=\"errorButton\">" .
1239 __("Feeds with errors") . "</button>";
1240
1241 // print format_notice("<a href=\"javascript:showFeedsWithErrors()\">".
1242 // __('Some feeds have update errors (click for details)')."</a>");
1243 }
1244
1245 if (DB_TYPE == "pgsql") {
1246 $interval_qpart = "NOW() - INTERVAL '3 months'";
1247 } else {
1248 $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)";
1249 }
1250
1251 $result = db_query($link, "SELECT COUNT(*) AS num_inactive FROM ttrss_feeds WHERE
1252 (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE
1253 ttrss_entries.id = ref_id AND
1254 ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart AND
1255 ttrss_feeds.owner_uid = ".$_SESSION["uid"]);
1256
1257 $num_inactive = db_fetch_result($result, 0, "num_inactive");
1258
1259 if ($num_inactive > 0) {
1260 $inactive_button = "<button dojoType=\"dijit.form.Button\"
1261 onclick=\"showInactiveFeeds()\">" .
1262 __("Inactive feeds") . "</button>";
1263 }
1264
1265 $feed_search = db_escape_string($_REQUEST["search"]);
1266
1267 if (array_key_exists("search", $_REQUEST)) {
1268 $_SESSION["prefs_feed_search"] = $feed_search;
1269 } else {
1270 $feed_search = $_SESSION["prefs_feed_search"];
1271 }
1272
1273 print "<div dojoType=\"dijit.Toolbar\">";
1274
1275 print "<div dojoType=\"dijit.form.DropDownButton\">".
1276 "<span>" . __('Select')."</span>";
1277 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
1278 print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(true)\"
1279 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
1280 print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(false)\"
1281 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
1282 print "</div></div>";
1283
1284 print "<div dojoType=\"dijit.form.DropDownButton\">".
1285 "<span>" . __('Feeds')."</span>";
1286 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
1287 print "<div onclick=\"quickAddFeed()\"
1288 dojoType=\"dijit.MenuItem\">".__('Subscribe to feed')."</div>";
1289 print "<div onclick=\"editSelectedFeed()\"
1290 dojoType=\"dijit.MenuItem\">".__('Edit selected feeds')."</div>";
1291 print "<div onclick=\"resetFeedOrder()\"
1292 dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>";
1293 print "</div></div>";
1294
1295 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1296 print "<div dojoType=\"dijit.form.DropDownButton\">".
1297 "<span>" . __('Categories')."</span>";
1298 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
1299 print "<div onclick=\"editFeedCats()\"
1300 dojoType=\"dijit.MenuItem\">".__('Edit categories')."</div>";
1301 print "<div onclick=\"resetCatOrder()\"
1302 dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>";
1303 print "</div></div>";
1304
1305 }
1306
1307 print $error_button;
1308 print $inactive_button;
1309
1310 print "<button dojoType=\"dijit.form.Button\" onclick=\"removeSelectedFeeds()\">"
1311 .__('Unsubscribe')."</button dojoType=\"dijit.form.Button\"> ";
1312
1313 if (defined('_ENABLE_FEED_DEBUGGING')) {
1314
1315 print "<select id=\"feedActionChooser\" onchange=\"feedActionChange()\">
1316 <option value=\"facDefault\" selected>".__('More actions...')."</option>";
1317
1318 if (FORCE_ARTICLE_PURGE == 0) {
1319 print
1320 "<option value=\"facPurge\">".__('Manual purge')."</option>";
1321 }
1322
1323 print "
1324 <option value=\"facClear\">".__('Clear feed data')."</option>
1325 <option value=\"facRescore\">".__('Rescore articles')."</option>";
1326
1327 print "</select>";
1328
1329 }
1330
1331 print "</div>"; # toolbar
1332
1333 print "<div id=\"feedlistLoading\">
1334 <img src='images/indicator_tiny.gif'>".
1335 __("Loading, please wait...")."</div>";
1336
1337 print "<div dojoType=\"fox.PrefFeedStore\" jsId=\"feedStore\"
1338 url=\"backend.php?op=pref-feeds&subop=getfeedtree\">
1339 </div>
1340 <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"feedModel\" store=\"feedStore\"
1341 query=\"{id:'root'}\" rootId=\"root\" rootLabel=\"Feeds\"
1342 childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">
1343 </div>
1344 <div dojoType=\"fox.PrefFeedTree\" id=\"feedTree\"
1345 dndController=\"dijit.tree.dndSource\"
1346 betweenThreshold=\"5\"
1347 model=\"feedModel\" openOnClick=\"false\">
1348 <script type=\"dojo/method\" event=\"onClick\" args=\"item\">
1349 var id = String(item.id);
1350 var bare_id = id.substr(id.indexOf(':')+1);
1351
1352 if (id.match('FEED:')) {
1353 editFeed(bare_id);
1354 } else if (id.match('CAT:')) {
1355 editCat(bare_id, item);
1356 }
1357 </script>
1358 <script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
1359 Element.hide(\"feedlistLoading\");
1360 </script>
1361 </div>";
1362
1363 print "<div dojoType=\"dijit.Tooltip\" connectId=\"feedTree\" position=\"below\">
1364 ".__('<b>Hint:</b> you can drag feeds and categories around.')."
1365 </div>";
1366
1367 print "</div>"; # feeds pane
1368
1369 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('OPML')."\">";
1370
1371 print "<p>" . __("Using OPML you can export and import your feeds and Tiny Tiny RSS settings.");
1372
1373 print "<div class=\"insensitive\">" . __("Note: Only main settings profile can be migrated using OPML.") . "</div>";
1374
1375 print "</p>";
1376
1377 print "<iframe id=\"upload_iframe\"
1378 name=\"upload_iframe\" onload=\"opmlImportComplete(this)\"
1379 style=\"width: 400px; height: 100px; display: none;\"></iframe>";
1380
1381 print "<form style='display : block' target=\"upload_iframe\"
1382 enctype=\"multipart/form-data\" method=\"POST\"
1383 action=\"backend.php\">
1384 <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
1385 <input type=\"hidden\" name=\"op\" value=\"dlg\">
1386 <input type=\"hidden\" name=\"id\" value=\"importOpml\">
1387 <button dojoType=\"dijit.form.Button\" onclick=\"return opmlImport();\"
1388 type=\"submit\">".__('Import')."</button>
1389 <button dojoType=\"dijit.form.Button\" onclick=\"gotoExportOpml()\">".__('Export OPML')."</button>
1390 </form>";
1391
1392 print "<p>".__('Your OPML can be published publicly and can be subscribed by anyone who knows the URL below.');
1393
1394 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>";
1395
1396 print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('pubOPMLUrl')\">".
1397 __('Display URL')."</button> ";
1398
1399
1400 print "</div>"; # pane
1401
1402 if (strpos($_SERVER['HTTP_USER_AGENT'], "Firefox") !== false) {
1403
1404 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Firefox integration')."\">";
1405
1406 print "<p>" . __('This Tiny Tiny RSS site can be used as a Firefox Feed Reader by clicking the link below.') . "</p>";
1407
1408 print "<p>";
1409
1410 print "<button onclick='window.navigator.registerContentHandler(" .
1411 "\"application/vnd.mozilla.maybe.feed\", " .
1412 "\"" . add_feed_url() . "\", " . " \"Tiny Tiny RSS\")'>" .
1413 __('Click here to register this site as a feed reader.') .
1414 "</button>";
1415
1416 print "</p>";
1417
1418 print "</div>"; # pane
1419 }
1420
1421 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Subscribing using bookmarklet')."\">";
1422
1423 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>";
1424
1425 $bm_subscribe_url = str_replace('%s', '', add_feed_url());
1426
1427 $confirm_str = __('Subscribe to %s in Tiny Tiny RSS?');
1428
1429 $bm_url = htmlspecialchars("javascript:{if(confirm('$confirm_str'.replace('%s',window.location.href)))window.location.href='$bm_subscribe_url'+window.location.href}");
1430
1431 print "<a href=\"$bm_url\" class='bookmarklet'>" . __('Subscribe in Tiny Tiny RSS'). "</a>";
1432
1433 print "</div>"; #pane
1434
1435 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Published articles and generated feeds')."\">";
1436
1437 print "<p>".__('Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the URL specified below.')."</p>";
1438
1439 $rss_url = '-2::' . htmlspecialchars(get_self_url_prefix() .
1440 "/backend.php?op=rss&id=-2&view-mode=all_articles");;
1441
1442 print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('generatedFeed', '$rss_url')\">".
1443 __('Display URL')."</button> ";
1444
1445 print "<button dojoType=\"dijit.form.Button\" onclick=\"return clearFeedAccessKeys()\">".
1446 __('Clear all generated URLs')."</button> ";
1447
1448 print "</div>"; #pane
1449
1450 if (defined('CONSUMER_KEY') && CONSUMER_KEY != '') {
1451
1452 print "<div id=\"pref-feeds-twitter\" dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Twitter')."\">";
1453
1454 $result = db_query($link, "SELECT COUNT(*) AS cid FROM ttrss_users
1455 WHERE twitter_oauth IS NOT NULL AND twitter_oauth != '' AND
1456 id = " . $_SESSION['uid']);
1457
1458 $is_registered = db_fetch_result($result, 0, "cid") != 0;
1459
1460 if (!$is_registered) {
1461 print_notice(__('Before you can update your Twitter feeds, you must register this instance of Tiny Tiny RSS with Twitter.com.'));
1462 } else {
1463 print_notice(__('You have been successfully registered with Twitter.com and should be able to access your Twitter feeds.'));
1464 }
1465
1466 print "<button dojoType=\"dijit.form.Button\" onclick=\"window.location.href = 'twitter.php?op=register'\">".
1467 __("Register with Twitter.com")."</button>";
1468
1469 print " ";
1470
1471 print "<button dojoType=\"dijit.form.Button\"
1472 onclick=\"return clearTwitterCredentials()\">".
1473 __("Clear stored credentials")."</button>";
1474
1475 print "</div>"; # pane
1476
1477 }
1478
1479 print "</div>"; #container
1480
1481 }
1482
1483 function make_feed_browser($link, $search, $limit, $mode = 1) {
1484
1485 $owner_uid = $_SESSION["uid"];
1486 $rv = '';
1487
1488 if ($search) {
1489 $search_qpart = "AND (UPPER(feed_url) LIKE UPPER('%$search%') OR
1490 UPPER(title) LIKE UPPER('%$search%'))";
1491 } else {
1492 $search_qpart = "";
1493 }
1494
1495 if ($mode == 1) {
1496 $result = db_query($link, "SELECT feed_url, subscribers FROM
1497 ttrss_feedbrowser_cache WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf
1498 WHERE tf.feed_url = ttrss_feedbrowser_cache.feed_url
1499 AND owner_uid = '$owner_uid') $search_qpart
1500 ORDER BY subscribers DESC LIMIT $limit");
1501 } else if ($mode == 2) {
1502 $result = db_query($link, "SELECT *,
1503 (SELECT COUNT(*) FROM ttrss_user_entries WHERE
1504 orig_feed_id = ttrss_archived_feeds.id) AS articles_archived
1505 FROM
1506 ttrss_archived_feeds
1507 WHERE
1508 (SELECT COUNT(*) FROM ttrss_feeds
1509 WHERE ttrss_feeds.feed_url = ttrss_archived_feeds.feed_url AND
1510 owner_uid = '$owner_uid') = 0 AND
1511 owner_uid = '$owner_uid' $search_qpart
1512 ORDER BY id DESC LIMIT $limit");
1513 }
1514
1515 $feedctr = 0;
1516
1517 while ($line = db_fetch_assoc($result)) {
1518
1519 if ($mode == 1) {
1520
1521 $feed_url = $line["feed_url"];
1522 $subscribers = $line["subscribers"];
1523
1524 $det_result = db_query($link, "SELECT site_url,title,id
1525 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
1526
1527 $details = db_fetch_assoc($det_result);
1528
1529 $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico";
1530
1531 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1532 $feed_icon = "<img style=\"vertical-align : middle\" class=\"tinyFeedIcon\" src=\"" . ICONS_URL .
1533 "/".$details["id"].".ico\">";
1534 } else {
1535 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1536 }
1537
1538 $check_box = "<input onclick='toggleSelectListRow2(this)'
1539 dojoType=\"dijit.form.CheckBox\"
1540 type=\"checkbox\" \">";
1541
1542 $class = ($feedctr % 2) ? "even" : "odd";
1543
1544 $feed_url = htmlspecialchars($line["feed_url"]);
1545
1546 if ($details["site_url"]) {
1547 $site_url = "<a target=\"_blank\" href=\"".
1548 htmlspecialchars($details["site_url"])."\">
1549 <img style='border-width : 0px' src='images/www.png' alt='www'></a>";
1550 } else {
1551 $site_url = "";
1552 }
1553
1554 $feed_url = "<a target=\"_blank\" href=\"$feed_url\"><img
1555 style='border-width : 0px; vertical-align : middle'
1556 src='images/feed-icon-12x12.png'></a>";
1557
1558 $rv .= "<li title=\"".htmlspecialchars($details["site_url"])."\"
1559 id=\"FBROW-".$details["id"]."\">$check_box".
1560 "$feed_icon $feed_url " . htmlspecialchars($details["title"]) .
1561 "&nbsp;<span class='subscribers'>($subscribers)</span>
1562 $site_url</li>";
1563
1564 } else if ($mode == 2) {
1565 $feed_url = htmlspecialchars($line["feed_url"]);
1566 $site_url = htmlspecialchars($line["site_url"]);
1567 $title = htmlspecialchars($line["title"]);
1568
1569 $icon_file = ICONS_DIR . "/" . $line["id"] . ".ico";
1570
1571 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1572 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL .
1573 "/".$line["id"].".ico\">";
1574 } else {
1575 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1576 }
1577
1578 $check_box = "<input onclick='toggleSelectListRow2(this)' dojoType=\"dijit.form.CheckBox\"
1579 type=\"checkbox\">";
1580
1581 $class = ($feedctr % 2) ? "even" : "odd";
1582
1583 if ($line['articles_archived'] > 0) {
1584 $archived = sprintf(__("%d archived articles"), $line['articles_archived']);
1585 $archived = "&nbsp;<span class='subscribers'>($archived)</span>";
1586 } else {
1587 $archived = '';
1588 }
1589
1590 if ($line["site_url"]) {
1591 $site_url = "<a target=\"_blank\" href=\"$site_url\">
1592 <img style='border-width : 0px' src='images/www.png' alt='www'></a>";
1593 } else {
1594 $site_url = "";
1595 }
1596
1597 $feed_url = "<a target=\"_blank\" href=\"$feed_url\"><img
1598 style='border-width : 0px; vertical-align : middle'
1599 src='images/feed-icon-12x12.png'></a>";
1600
1601 $rv .= "<li title='".$line['site_url']."' class='$class'
1602 id=\"FBROW-".$line["id"]."\">".
1603 $check_box . "$feed_icon $feed_url " . $title .
1604 $archived . $site_url . "</li>";
1605
1606
1607 }
1608
1609 ++$feedctr;
1610 }
1611
1612 if ($feedctr == 0) {
1613 $rv .= "<li style=\"text-align : center\"><p>".__('No feeds found.')."</p></li>";
1614 }
1615
1616 return $rv;
1617
1618 }
1619
1620 ?>