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