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