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