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