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