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