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