]> git.wh0rd.org - tt-rss.git/blame - classes/pref/feeds.php
Revert "update: reenable first ref_id/id transaction"
[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
AD
36
37 if ($search) $search_qpart = " AND LOWER(title) LIKE LOWER('%$search%')";
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
AD
64 $num_children = $this->calculate_children_count($cat);
65 $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', $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
AD
86 $feed['error'] = $feed_line['last_error'];
87 $feed['icon'] = 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
f822a8e5 174 $label_id = 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
AD
213 $num_children = $this->calculate_children_count($cat);
214 $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', $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'];
249 $feed['icon'] = 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
AD
263 $num_children = $this->calculate_children_count($root);
264 $root['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', $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'];
281 $feed['icon'] = 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 {
300 $fl['items'] =& $root['items'];
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
327 $bare_item_id = 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
342 $order_id = 0;
343
344 $cat = $data_map[$item_id];
345
346 if ($cat && is_array($cat)) {
347 foreach ($cat as $item) {
348 $id = $item['_reference'];
349 $bare_id = substr($id, strpos($id, ':')+1);
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 {
413 $data_map[$item['id']] =& $item['items'];
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
d9c85e0f 536 $feed_id = $this->dbh->escape_string($_REQUEST["id"]);
afcfe6ca 537
d9c85e0f 538 $result = $this->dbh->query(
afcfe6ca
AD
539 "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND
540 owner_uid = " . $_SESSION["uid"]);
541
d9c85e0f 542 $auth_pass_encrypted = sql_bool_to_bool($this->dbh->fetch_result($result, 0,
044cff2d
AD
543 "auth_pass_encrypted"));
544
d9c85e0f 545 $title = htmlspecialchars($this->dbh->fetch_result($result,
afcfe6ca
AD
546 0, "title"));
547
548 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"$feed_id\">";
549 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-feeds\">";
550 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"editSave\">";
551
552 print "<div class=\"dlgSec\">".__("Feed")."</div>";
553 print "<div class=\"dlgSecCont\">";
554
555 /* Title */
556
557 print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\"
558 placeHolder=\"".__("Feed Title")."\"
559 style=\"font-size : 16px; width: 20em\" name=\"title\" value=\"$title\">";
560
561 /* Feed URL */
562
d9c85e0f
AD
563 $feed_url = $this->dbh->fetch_result($result, 0, "feed_url");
564 $feed_url = htmlspecialchars($this->dbh->fetch_result($result,
afcfe6ca
AD
565 0, "feed_url"));
566
567 print "<hr/>";
568
569 print __('URL:') . " ";
570 print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\"
571 placeHolder=\"".__("Feed URL")."\"
572 regExp='^(http|https)://.*' style=\"width : 20em\"
573 name=\"feed_url\" value=\"$feed_url\">";
574
d9c85e0f 575 $last_error = $this->dbh->fetch_result($result, 0, "last_error");
afcfe6ca
AD
576
577 if ($last_error) {
1a545dcb
AD
578 print "&nbsp;<img src=\"images/error.png\" alt=\"(error)\"
579 style=\"vertical-align : middle\"
580 title=\"".htmlspecialchars($last_error)."\">";
afcfe6ca
AD
581
582 }
583
584 /* Category */
585
a42c55f0 586 if (get_pref('ENABLE_FEED_CATS')) {
afcfe6ca 587
d9c85e0f 588 $cat_id = $this->dbh->fetch_result($result, 0, "cat_id");
afcfe6ca
AD
589
590 print "<hr/>";
591
592 print __('Place in category:') . " ";
593
a42c55f0 594 print_feed_cat_select("cat_id", $cat_id,
afcfe6ca
AD
595 'dojoType="dijit.form.Select"');
596 }
597
df659891
AD
598 /* FTS Stemming Language */
599
600 if (DB_TYPE == "pgsql") {
601 $feed_language = $this->dbh->fetch_result($result, 0, "feed_language");
602
603 print "<hr/>";
604
605 print __('Language:') . " ";
606 print_select("feed_language", $feed_language, $this::$feed_languages,
607 'dojoType="dijit.form.Select"');
608 }
609
afcfe6ca
AD
610 print "</div>";
611
612 print "<div class=\"dlgSec\">".__("Update")."</div>";
613 print "<div class=\"dlgSecCont\">";
614
615 /* Update Interval */
616
d9c85e0f 617 $update_interval = $this->dbh->fetch_result($result, 0, "update_interval");
afcfe6ca
AD
618
619 print_select_hash("update_interval", $update_interval, $update_intervals,
620 'dojoType="dijit.form.Select"');
621
19b3992b 622 /* Purge intl */
afcfe6ca 623
d9c85e0f 624 $purge_interval = $this->dbh->fetch_result($result, 0, "purge_interval");
afcfe6ca 625
afcfe6ca
AD
626 print "<hr/>";
627 print __('Article purging:') . " ";
628
629 print_select_hash("purge_interval", $purge_interval, $purge_intervals,
630 'dojoType="dijit.form.Select" ' .
631 ((FORCE_ARTICLE_PURGE == 0) ? "" : 'disabled="1"'));
632
633 print "</div>";
634 print "<div class=\"dlgSec\">".__("Authentication")."</div>";
635 print "<div class=\"dlgSecCont\">";
636
d9c85e0f 637 $auth_login = htmlspecialchars($this->dbh->fetch_result($result, 0, "auth_login"));
afcfe6ca
AD
638
639 print "<input dojoType=\"dijit.form.TextBox\" id=\"feedEditDlg_login\"
640 placeHolder=\"".__("Login")."\"
641 name=\"auth_login\" value=\"$auth_login\"><hr/>";
642
d9c85e0f 643 $auth_pass = $this->dbh->fetch_result($result, 0, "auth_pass");
044cff2d
AD
644
645 if ($auth_pass_encrypted) {
646 require_once "crypt.php";
647 $auth_pass = decrypt_string($auth_pass);
648 }
649
650 $auth_pass = htmlspecialchars($auth_pass);
afcfe6ca
AD
651
652 print "<input dojoType=\"dijit.form.TextBox\" type=\"password\" name=\"auth_pass\"
653 placeHolder=\"".__("Password")."\"
654 value=\"$auth_pass\">";
655
656 print "<div dojoType=\"dijit.Tooltip\" connectId=\"feedEditDlg_login\" position=\"below\">
657 ".__('<b>Hint:</b> you need to fill in your login information if your feed requires authentication, except for Twitter feeds.')."
658 </div>";
659
660 print "</div>";
661 print "<div class=\"dlgSec\">".__("Options")."</div>";
662 print "<div class=\"dlgSecCont\">";
663
d9c85e0f 664 $private = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "private"));
afcfe6ca
AD
665
666 if ($private) {
667 $checked = "checked=\"1\"";
668 } else {
669 $checked = "";
670 }
671
672 print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"private\" id=\"private\"
673 $checked>&nbsp;<label for=\"private\">".__('Hide from Popular feeds')."</label>";
674
d9c85e0f 675 $include_in_digest = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "include_in_digest"));
afcfe6ca
AD
676
677 if ($include_in_digest) {
678 $checked = "checked=\"1\"";
679 } else {
680 $checked = "";
681 }
682
683 print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"include_in_digest\"
684 name=\"include_in_digest\"
685 $checked>&nbsp;<label for=\"include_in_digest\">".__('Include in e-mail digest')."</label>";
686
687
d9c85e0f 688 $always_display_enclosures = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "always_display_enclosures"));
afcfe6ca
AD
689
690 if ($always_display_enclosures) {
691 $checked = "checked";
692 } else {
693 $checked = "";
694 }
695
696 print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"always_display_enclosures\"
697 name=\"always_display_enclosures\"
698 $checked>&nbsp;<label for=\"always_display_enclosures\">".__('Always display image attachments')."</label>";
699
d9c85e0f 700 $hide_images = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "hide_images"));
bfd61d3f
AD
701
702 if ($hide_images) {
703 $checked = "checked=\"1\"";
704 } else {
705 $checked = "";
706 }
707
708 print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"hide_images\"
709 name=\"hide_images\"
710 $checked>&nbsp;<label for=\"hide_images\">".
711 __('Do not embed images')."</label>";
afcfe6ca 712
d9c85e0f 713 $cache_images = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "cache_images"));
afcfe6ca
AD
714
715 if ($cache_images) {
716 $checked = "checked=\"1\"";
717 } else {
718 $checked = "";
719 }
720
3c696512
AD
721 print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"cache_images\"
722 name=\"cache_images\"
afcfe6ca 723 $checked>&nbsp;<label for=\"cache_images\">".
3c696512 724 __('Cache images locally')."</label>";
afcfe6ca 725
d9c85e0f 726 $mark_unread_on_update = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "mark_unread_on_update"));
afcfe6ca
AD
727
728 if ($mark_unread_on_update) {
729 $checked = "checked";
730 } else {
731 $checked = "";
732 }
733
734 print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"mark_unread_on_update\"
735 name=\"mark_unread_on_update\"
736 $checked>&nbsp;<label for=\"mark_unread_on_update\">".__('Mark updated articles as unread')."</label>";
737
afcfe6ca
AD
738 print "</div>";
739
740 /* Icon */
741
742 print "<div class=\"dlgSec\">".__("Icon")."</div>";
743 print "<div class=\"dlgSecCont\">";
744
745 print "<iframe name=\"icon_upload_iframe\"
746 style=\"width: 400px; height: 100px; display: none;\"></iframe>";
747
748 print "<form style='display : block' target=\"icon_upload_iframe\"
749 enctype=\"multipart/form-data\" method=\"POST\"
750 action=\"backend.php\">
751 <input id=\"icon_file\" size=\"10\" name=\"icon_file\" type=\"file\">
752 <input type=\"hidden\" name=\"op\" value=\"pref-feeds\">
753 <input type=\"hidden\" name=\"feed_id\" value=\"$feed_id\">
754 <input type=\"hidden\" name=\"method\" value=\"uploadicon\">
4a1d122c 755 <button class=\"small\" dojoType=\"dijit.form.Button\" onclick=\"return uploadFeedIcon();\"
afcfe6ca 756 type=\"submit\">".__('Replace')."</button>
4a1d122c 757 <button class=\"small\" dojoType=\"dijit.form.Button\" onclick=\"return removeFeedIcon($feed_id);\"
afcfe6ca
AD
758 type=\"submit\">".__('Remove')."</button>
759 </form>";
760
761 print "</div>";
762
057177eb
AD
763 PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_EDIT_FEED,
764 "hook_prefs_edit_feed", $feed_id);
765
afcfe6ca
AD
766 $title = htmlspecialchars($title, ENT_QUOTES);
767
768 print "<div class='dlgButtons'>
769 <div style=\"float : left\">
770 <button dojoType=\"dijit.form.Button\" onclick='return unsubscribeFeed($feed_id, \"$title\")'>".
771 __('Unsubscribe')."</button>";
772
773 if (PUBSUBHUBBUB_ENABLED) {
d9c85e0f 774 $pubsub_state = $this->dbh->fetch_result($result, 0, "pubsub_state");
afcfe6ca
AD
775 $pubsub_btn_disabled = ($pubsub_state == 2) ? "" : "disabled=\"1\"";
776
777 print "<button dojoType=\"dijit.form.Button\" id=\"pubsubReset_Btn\" $pubsub_btn_disabled
778 onclick='return resetPubSub($feed_id, \"$title\")'>".__('Resubscribe to push updates').
779 "</button>";
780 }
781
782 print "</div>";
783
784 print "<div dojoType=\"dijit.Tooltip\" connectId=\"pubsubReset_Btn\" position=\"below\">".
785 __('Resets PubSubHubbub subscription status for push-enabled feeds.')."</div>";
786
787 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedEditDlg').execute()\">".__('Save')."</button>
788 <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedEditDlg').hide()\">".__('Cancel')."</button>
789 </div>";
790
791 return;
792 }
793
794 function editfeeds() {
795 global $purge_intervals;
796 global $update_intervals;
46da73c2 797
d9c85e0f 798 $feed_ids = $this->dbh->escape_string($_REQUEST["ids"]);
afcfe6ca 799
fcef9eea
AD
800 print_notice("Enable the options you wish to apply using checkboxes on the right:");
801
802 print "<p>";
ca6a0741 803
afcfe6ca
AD
804 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"ids\" value=\"$feed_ids\">";
805 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-feeds\">";
806 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"batchEditSave\">";
807
808 print "<div class=\"dlgSec\">".__("Feed")."</div>";
809 print "<div class=\"dlgSecCont\">";
810
afcfe6ca
AD
811 /* Category */
812
a42c55f0 813 if (get_pref('ENABLE_FEED_CATS')) {
afcfe6ca 814
afcfe6ca
AD
815 print __('Place in category:') . " ";
816
d29357fa 817 print_feed_cat_select("cat_id", false,
afcfe6ca
AD
818 'disabled="1" dojoType="dijit.form.Select"');
819
820 $this->batch_edit_cbox("cat_id");
821
822 }
823
df659891
AD
824 /* FTS Stemming Language */
825
826 if (DB_TYPE == "pgsql") {
827 print "<hr/>";
828
829 print __('Language:') . " ";
830 print_select("feed_language", "", $this::$feed_languages,
831 'disabled="1" dojoType="dijit.form.Select"');
832
833 $this->batch_edit_cbox("feed_language");
834 }
835
afcfe6ca
AD
836 print "</div>";
837
838 print "<div class=\"dlgSec\">".__("Update")."</div>";
839 print "<div class=\"dlgSecCont\">";
840
841 /* Update Interval */
842
d29357fa 843 print_select_hash("update_interval", "", $update_intervals,
afcfe6ca
AD
844 'disabled="1" dojoType="dijit.form.Select"');
845
846 $this->batch_edit_cbox("update_interval");
847
afcfe6ca
AD
848 /* Purge intl */
849
850 if (FORCE_ARTICLE_PURGE == 0) {
851
852 print "<br/>";
853
854 print __('Article purging:') . " ";
855
d29357fa 856 print_select_hash("purge_interval", "", $purge_intervals,
afcfe6ca
AD
857 'disabled="1" dojoType="dijit.form.Select"');
858
859 $this->batch_edit_cbox("purge_interval");
860 }
861
862 print "</div>";
863 print "<div class=\"dlgSec\">".__("Authentication")."</div>";
864 print "<div class=\"dlgSecCont\">";
865
866 print "<input dojoType=\"dijit.form.TextBox\"
867 placeHolder=\"".__("Login")."\" disabled=\"1\"
d29357fa 868 name=\"auth_login\" value=\"\">";
afcfe6ca
AD
869
870 $this->batch_edit_cbox("auth_login");
871
44727c79 872 print "<hr/> <input dojoType=\"dijit.form.TextBox\" type=\"password\" name=\"auth_pass\"
afcfe6ca 873 placeHolder=\"".__("Password")."\" disabled=\"1\"
d29357fa 874 value=\"\">";
afcfe6ca
AD
875
876 $this->batch_edit_cbox("auth_pass");
877
878 print "</div>";
879 print "<div class=\"dlgSec\">".__("Options")."</div>";
880 print "<div class=\"dlgSecCont\">";
881
882 print "<input disabled=\"1\" type=\"checkbox\" name=\"private\" id=\"private\"
883 dojoType=\"dijit.form.CheckBox\">&nbsp;<label id=\"private_l\" class='insensitive' for=\"private\">".__('Hide from Popular feeds')."</label>";
884
885 print "&nbsp;"; $this->batch_edit_cbox("private", "private_l");
886
afcfe6ca
AD
887 print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"include_in_digest\"
888 name=\"include_in_digest\"
889 dojoType=\"dijit.form.CheckBox\">&nbsp;<label id=\"include_in_digest_l\" class='insensitive' for=\"include_in_digest\">".__('Include in e-mail digest')."</label>";
890
891 print "&nbsp;"; $this->batch_edit_cbox("include_in_digest", "include_in_digest_l");
892
893 print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"always_display_enclosures\"
894 name=\"always_display_enclosures\"
895 dojoType=\"dijit.form.CheckBox\">&nbsp;<label id=\"always_display_enclosures_l\" class='insensitive' for=\"always_display_enclosures\">".__('Always display image attachments')."</label>";
896
897 print "&nbsp;"; $this->batch_edit_cbox("always_display_enclosures", "always_display_enclosures_l");
898
bfd61d3f
AD
899 print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"hide_images\"
900 name=\"hide_images\"
901 dojoType=\"dijit.form.CheckBox\">&nbsp;<label class='insensitive' id=\"hide_images_l\"
902 for=\"hide_images\">".
903 __('Do not embed images')."</label>";
904
905 print "&nbsp;"; $this->batch_edit_cbox("hide_images", "hide_images_l");
906
3c696512
AD
907 print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"cache_images\"
908 name=\"cache_images\"
909 dojoType=\"dijit.form.CheckBox\">&nbsp;<label class='insensitive' id=\"cache_images_l\"
910 for=\"cache_images\">".
911 __('Cache images locally')."</label>";
afcfe6ca 912
3c696512 913 print "&nbsp;"; $this->batch_edit_cbox("cache_images", "cache_images_l");
afcfe6ca
AD
914
915 print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"mark_unread_on_update\"
916 name=\"mark_unread_on_update\"
917 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>";
918
919 print "&nbsp;"; $this->batch_edit_cbox("mark_unread_on_update", "mark_unread_on_update_l");
920
afcfe6ca
AD
921 print "</div>";
922
923 print "<div class='dlgButtons'>
924 <button dojoType=\"dijit.form.Button\"
925 onclick=\"return dijit.byId('feedEditDlg').execute()\">".
926 __('Save')."</button>
927 <button dojoType=\"dijit.form.Button\"
928 onclick=\"return dijit.byId('feedEditDlg').hide()\">".
929 __('Cancel')."</button>
930 </div>";
931
932 return;
933 }
934
935 function batchEditSave() {
3a76e2a2 936 return $this->editsaveops(true);
afcfe6ca 937 }
46da73c2 938
afcfe6ca 939 function editSave() {
3a76e2a2 940 return $this->editsaveops(false);
afcfe6ca 941 }
46da73c2
AD
942
943 function editsaveops($batch) {
944
d9c85e0f
AD
945 $feed_title = $this->dbh->escape_string(trim($_POST["title"]));
946 $feed_link = $this->dbh->escape_string(trim($_POST["feed_url"]));
947 $upd_intl = (int) $this->dbh->escape_string($_POST["update_interval"]);
948 $purge_intl = (int) $this->dbh->escape_string($_POST["purge_interval"]);
949 $feed_id = (int) $this->dbh->escape_string($_POST["id"]); /* editSave */
950 $feed_ids = $this->dbh->escape_string($_POST["ids"]); /* batchEditSave */
951 $cat_id = (int) $this->dbh->escape_string($_POST["cat_id"]);
952 $auth_login = $this->dbh->escape_string(trim($_POST["auth_login"]));
41694a95 953 $auth_pass = trim($_POST["auth_pass"]);
d9c85e0f 954 $private = checkbox_to_sql_bool($this->dbh->escape_string($_POST["private"]));
afcfe6ca 955 $include_in_digest = checkbox_to_sql_bool(
d9c85e0f 956 $this->dbh->escape_string($_POST["include_in_digest"]));
afcfe6ca 957 $cache_images = checkbox_to_sql_bool(
d9c85e0f 958 $this->dbh->escape_string($_POST["cache_images"]));
bfd61d3f 959 $hide_images = checkbox_to_sql_bool(
d9c85e0f 960 $this->dbh->escape_string($_POST["hide_images"]));
afcfe6ca 961 $always_display_enclosures = checkbox_to_sql_bool(
d9c85e0f 962 $this->dbh->escape_string($_POST["always_display_enclosures"]));
afcfe6ca
AD
963
964 $mark_unread_on_update = checkbox_to_sql_bool(
d9c85e0f 965 $this->dbh->escape_string($_POST["mark_unread_on_update"]));
afcfe6ca 966
df659891
AD
967 $feed_language = $this->dbh->escape_string(trim($_POST["feed_language"]));
968
044cff2d
AD
969 if (strlen(FEED_CRYPT_KEY) > 0) {
970 require_once "crypt.php";
971 $auth_pass = substr(encrypt_string($auth_pass), 0, 250);
972 $auth_pass_encrypted = 'true';
973 } else {
974 $auth_pass_encrypted = 'false';
975 }
976
d9c85e0f 977 $auth_pass = $this->dbh->escape_string($auth_pass);
41694a95 978
a42c55f0 979 if (get_pref('ENABLE_FEED_CATS')) {
afcfe6ca
AD
980 if ($cat_id && $cat_id != 0) {
981 $category_qpart = "cat_id = '$cat_id',";
982 $category_qpart_nocomma = "cat_id = '$cat_id'";
983 } else {
984 $category_qpart = 'cat_id = NULL,';
985 $category_qpart_nocomma = 'cat_id = NULL';
986 }
987 } else {
988 $category_qpart = "";
989 $category_qpart_nocomma = "";
990 }
991
3a76e2a2 992 if (!$batch) {
afcfe6ca 993
4a80c57c 994 $this->dbh->query("UPDATE ttrss_feeds SET
afcfe6ca
AD
995 $category_qpart
996 title = '$feed_title', feed_url = '$feed_link',
997 update_interval = '$upd_intl',
998 purge_interval = '$purge_intl',
999 auth_login = '$auth_login',
1000 auth_pass = '$auth_pass',
044cff2d 1001 auth_pass_encrypted = $auth_pass_encrypted,
afcfe6ca 1002 private = $private,
87764a50 1003 cache_images = $cache_images,
bfd61d3f 1004 hide_images = $hide_images,
afcfe6ca
AD
1005 include_in_digest = $include_in_digest,
1006 always_display_enclosures = $always_display_enclosures,
df659891
AD
1007 mark_unread_on_update = $mark_unread_on_update,
1008 feed_language = '$feed_language'
19b3992b 1009 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
afcfe6ca 1010
8cefe38a
AD
1011 PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_SAVE_FEED,
1012 "hook_prefs_save_feed", $feed_id);
1013
3a76e2a2 1014 } else {
afcfe6ca
AD
1015 $feed_data = array();
1016
1017 foreach (array_keys($_POST) as $k) {
1018 if ($k != "op" && $k != "method" && $k != "ids") {
1019 $feed_data[$k] = $_POST[$k];
1020 }
1021 }
1022
d9c85e0f 1023 $this->dbh->query("BEGIN");
afcfe6ca
AD
1024
1025 foreach (array_keys($feed_data) as $k) {
1026
1027 $qpart = "";
1028
1029 switch ($k) {
1030 case "title":
1031 $qpart = "title = '$feed_title'";
1032 break;
1033
1034 case "feed_url":
1035 $qpart = "feed_url = '$feed_link'";
1036 break;
1037
1038 case "update_interval":
1039 $qpart = "update_interval = '$upd_intl'";
1040 break;
1041
1042 case "purge_interval":
1043 $qpart = "purge_interval = '$purge_intl'";
1044 break;
1045
1046 case "auth_login":
1047 $qpart = "auth_login = '$auth_login'";
1048 break;
1049
1050 case "auth_pass":
044cff2d
AD
1051 $qpart = "auth_pass = '$auth_pass' AND
1052 auth_pass_encrypted = $auth_pass_encrypted";
afcfe6ca
AD
1053 break;
1054
1055 case "private":
a498d18b 1056 $qpart = "private = $private";
afcfe6ca
AD
1057 break;
1058
1059 case "include_in_digest":
a498d18b 1060 $qpart = "include_in_digest = $include_in_digest";
afcfe6ca
AD
1061 break;
1062
1063 case "always_display_enclosures":
a498d18b 1064 $qpart = "always_display_enclosures = $always_display_enclosures";
afcfe6ca
AD
1065 break;
1066
1067 case "mark_unread_on_update":
a498d18b 1068 $qpart = "mark_unread_on_update = $mark_unread_on_update";
afcfe6ca
AD
1069 break;
1070
afcfe6ca 1071 case "cache_images":
a498d18b 1072 $qpart = "cache_images = $cache_images";
afcfe6ca
AD
1073 break;
1074
bfd61d3f
AD
1075 case "hide_images":
1076 $qpart = "hide_images = $hide_images";
1077 break;
1078
afcfe6ca
AD
1079 case "cat_id":
1080 $qpart = $category_qpart_nocomma;
1081 break;
1082
df659891
AD
1083 case "feed_language":
1084 $qpart = "feed_language = '$feed_language'";
1085 break;
1086
afcfe6ca
AD
1087 }
1088
1089 if ($qpart) {
d9c85e0f 1090 $this->dbh->query(
afcfe6ca
AD
1091 "UPDATE ttrss_feeds SET $qpart WHERE id IN ($feed_ids)
1092 AND owner_uid = " . $_SESSION["uid"]);
1093 print "<br/>";
1094 }
1095 }
1096
d9c85e0f 1097 $this->dbh->query("COMMIT");
afcfe6ca
AD
1098 }
1099 return;
1100 }
1101
1102 function resetPubSub() {
1103
d9c85e0f 1104 $ids = $this->dbh->escape_string($_REQUEST["ids"]);
afcfe6ca 1105
d9c85e0f 1106 $this->dbh->query("UPDATE ttrss_feeds SET pubsub_state = 0 WHERE id IN ($ids)
afcfe6ca
AD
1107 AND owner_uid = " . $_SESSION["uid"]);
1108
1109 return;
1110 }
1111
1112 function remove() {
1113
d9c85e0f 1114 $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"]));
afcfe6ca
AD
1115
1116 foreach ($ids as $id) {
a42c55f0 1117 Pref_Feeds::remove_feed($id, $_SESSION["uid"]);
afcfe6ca
AD
1118 }
1119
1120 return;
1121 }
1122
1123 function clear() {
d9c85e0f 1124 $id = $this->dbh->escape_string($_REQUEST["id"]);
a42c55f0 1125 $this->clear_feed_articles($id);
afcfe6ca
AD
1126 }
1127
1128 function rescore() {
92c14e9d
AD
1129 require_once "rssfuncs.php";
1130
d9c85e0f 1131 $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"]));
afcfe6ca
AD
1132
1133 foreach ($ids as $id) {
1134
a42c55f0 1135 $filters = load_filters($id, $_SESSION["uid"], 6);
afcfe6ca 1136
d9c85e0f 1137 $result = $this->dbh->query("SELECT
afcfe6ca
AD
1138 title, content, link, ref_id, author,".
1139 SUBSTRING_FOR_DATE."(updated, 1, 19) AS updated
1140 FROM
1141 ttrss_user_entries, ttrss_entries
1142 WHERE ref_id = id AND feed_id = '$id' AND
1143 owner_uid = " .$_SESSION['uid']."
1144 ");
1145
1146 $scores = array();
1147
d9c85e0f 1148 while ($line = $this->dbh->fetch_assoc($result)) {
afcfe6ca 1149
a42c55f0 1150 $tags = get_article_tags($line["ref_id"]);
afcfe6ca
AD
1151
1152 $article_filters = get_article_filters($filters, $line['title'],
1153 $line['content'], $line['link'], strtotime($line['updated']),
1154 $line['author'], $tags);
1155
1156 $new_score = calculate_article_score($article_filters);
1157
1158 if (!$scores[$new_score]) $scores[$new_score] = array();
1159
1160 array_push($scores[$new_score], $line['ref_id']);
1161 }
1162
1163 foreach (array_keys($scores) as $s) {
1164 if ($s > 1000) {
d9c85e0f 1165 $this->dbh->query("UPDATE ttrss_user_entries SET score = '$s',
afcfe6ca
AD
1166 marked = true WHERE
1167 ref_id IN (" . join(',', $scores[$s]) . ")");
1168 } else if ($s < -500) {
d9c85e0f 1169 $this->dbh->query("UPDATE ttrss_user_entries SET score = '$s',
afcfe6ca
AD
1170 unread = false WHERE
1171 ref_id IN (" . join(',', $scores[$s]) . ")");
1172 } else {
d9c85e0f 1173 $this->dbh->query("UPDATE ttrss_user_entries SET score = '$s' WHERE
afcfe6ca
AD
1174 ref_id IN (" . join(',', $scores[$s]) . ")");
1175 }
1176 }
1177 }
1178
1179 print __("All done.");
1180
1181 }
1182
1183 function rescoreAll() {
1184
d9c85e0f 1185 $result = $this->dbh->query(
afcfe6ca
AD
1186 "SELECT id FROM ttrss_feeds WHERE owner_uid = " . $_SESSION['uid']);
1187
d9c85e0f 1188 while ($feed_line = $this->dbh->fetch_assoc($result)) {
afcfe6ca
AD
1189
1190 $id = $feed_line["id"];
1191
a42c55f0 1192 $filters = load_filters($id, $_SESSION["uid"], 6);
afcfe6ca 1193
d9c85e0f 1194 $tmp_result = $this->dbh->query("SELECT
afcfe6ca
AD
1195 title, content, link, ref_id, author,".
1196 SUBSTRING_FOR_DATE."(updated, 1, 19) AS updated
1197 FROM
1198 ttrss_user_entries, ttrss_entries
1199 WHERE ref_id = id AND feed_id = '$id' AND
1200 owner_uid = " .$_SESSION['uid']."
1201 ");
1202
1203 $scores = array();
1204
d9c85e0f 1205 while ($line = $this->dbh->fetch_assoc($tmp_result)) {
afcfe6ca 1206
a42c55f0 1207 $tags = get_article_tags($line["ref_id"]);
afcfe6ca
AD
1208
1209 $article_filters = get_article_filters($filters, $line['title'],
1210 $line['content'], $line['link'], strtotime($line['updated']),
1211 $line['author'], $tags);
1212
1213 $new_score = calculate_article_score($article_filters);
1214
1215 if (!$scores[$new_score]) $scores[$new_score] = array();
1216
1217 array_push($scores[$new_score], $line['ref_id']);
1218 }
1219
1220 foreach (array_keys($scores) as $s) {
1221 if ($s > 1000) {
d9c85e0f 1222 $this->dbh->query("UPDATE ttrss_user_entries SET score = '$s',
afcfe6ca
AD
1223 marked = true WHERE
1224 ref_id IN (" . join(',', $scores[$s]) . ")");
1225 } else {
d9c85e0f 1226 $this->dbh->query("UPDATE ttrss_user_entries SET score = '$s' WHERE
afcfe6ca
AD
1227 ref_id IN (" . join(',', $scores[$s]) . ")");
1228 }
1229 }
1230 }
1231
1232 print __("All done.");
1233
1234 }
1235
afcfe6ca 1236 function categorize() {
d9c85e0f 1237 $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"]));
afcfe6ca 1238
d9c85e0f 1239 $cat_id = $this->dbh->escape_string($_REQUEST["cat_id"]);
afcfe6ca
AD
1240
1241 if ($cat_id == 0) {
1242 $cat_id_qpart = 'NULL';
1243 } else {
1244 $cat_id_qpart = "'$cat_id'";
1245 }
1246
d9c85e0f 1247 $this->dbh->query("BEGIN");
afcfe6ca
AD
1248
1249 foreach ($ids as $id) {
1250
d9c85e0f 1251 $this->dbh->query("UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
afcfe6ca
AD
1252 WHERE id = '$id'
1253 AND owner_uid = " . $_SESSION["uid"]);
1254
1255 }
1256
d9c85e0f 1257 $this->dbh->query("COMMIT");
afcfe6ca
AD
1258 }
1259
28537341 1260 function removeCat() {
d9c85e0f 1261 $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"]));
28537341 1262 foreach ($ids as $id) {
a42c55f0 1263 $this->remove_feed_category($id, $_SESSION["uid"]);
28537341
AD
1264 }
1265 }
1266
1267 function addCat() {
d9c85e0f 1268 $feed_cat = $this->dbh->escape_string(trim($_REQUEST["cat"]));
28537341 1269
a42c55f0 1270 add_feed_category($feed_cat);
28537341
AD
1271 }
1272
afcfe6ca
AD
1273 function index() {
1274
1275 print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
1276 print "<div id=\"pref-feeds-feeds\" dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Feeds')."\">";
1277
d9c85e0f 1278 $result = $this->dbh->query("SELECT COUNT(id) AS num_errors
afcfe6ca
AD
1279 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1280
d9c85e0f 1281 $num_errors = $this->dbh->fetch_result($result, 0, "num_errors");
afcfe6ca
AD
1282
1283 if ($num_errors > 0) {
1284
1285 $error_button = "<button dojoType=\"dijit.form.Button\"
1286 onclick=\"showFeedsWithErrors()\" id=\"errorButton\">" .
1287 __("Feeds with errors") . "</button>";
1288 }
1289
1290 if (DB_TYPE == "pgsql") {
1291 $interval_qpart = "NOW() - INTERVAL '3 months'";
1292 } else {
1293 $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)";
1294 }
1295
34899cf9
AD
1296 // could be performance-intensive and prevent feeds pref-panel from showing
1297 if (!defined('_DISABLE_INACTIVE_FEEDS') || !_DISABLE_INACTIVE_FEEDS) {
1298 $result = $this->dbh->query("SELECT COUNT(*) AS num_inactive FROM ttrss_feeds WHERE
afcfe6ca
AD
1299 (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE
1300 ttrss_entries.id = ref_id AND
1301 ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart AND
1302 ttrss_feeds.owner_uid = ".$_SESSION["uid"]);
1303
34899cf9
AD
1304 $num_inactive = $this->dbh->fetch_result($result, 0, "num_inactive");
1305 } else {
1306 $num_inactive = 0;
1307 }
afcfe6ca
AD
1308
1309 if ($num_inactive > 0) {
1310 $inactive_button = "<button dojoType=\"dijit.form.Button\"
1311 onclick=\"showInactiveFeeds()\">" .
1312 __("Inactive feeds") . "</button>";
1313 }
1314
d9c85e0f 1315 $feed_search = $this->dbh->escape_string($_REQUEST["search"]);
afcfe6ca
AD
1316
1317 if (array_key_exists("search", $_REQUEST)) {
1318 $_SESSION["prefs_feed_search"] = $feed_search;
1319 } else {
1320 $feed_search = $_SESSION["prefs_feed_search"];
1321 }
1322
1323 print '<div dojoType="dijit.layout.BorderContainer" gutters="false">';
1324
1325 print "<div region='top' dojoType=\"dijit.Toolbar\">"; #toolbar
1326
1327 print "<div style='float : right; padding-right : 4px;'>
1328 <input dojoType=\"dijit.form.TextBox\" id=\"feed_search\" size=\"20\" type=\"search\"
1329 value=\"$feed_search\">
1330 <button dojoType=\"dijit.form.Button\" onclick=\"updateFeedList()\">".
1331 __('Search')."</button>
1332 </div>";
1333
1334 print "<div dojoType=\"dijit.form.DropDownButton\">".
1335 "<span>" . __('Select')."</span>";
1336 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
1337 print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(true)\"
1338 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
1339 print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(false)\"
1340 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
1341 print "</div></div>";
1342
1343 print "<div dojoType=\"dijit.form.DropDownButton\">".
1344 "<span>" . __('Feeds')."</span>";
1345 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
1346 print "<div onclick=\"quickAddFeed()\"
1347 dojoType=\"dijit.MenuItem\">".__('Subscribe to feed')."</div>";
1348 print "<div onclick=\"editSelectedFeed()\"
1349 dojoType=\"dijit.MenuItem\">".__('Edit selected feeds')."</div>";
1350 print "<div onclick=\"resetFeedOrder()\"
1351 dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>";
33f0fdd0
AD
1352 print "<div onclick=\"batchSubscribe()\"
1353 dojoType=\"dijit.MenuItem\">".__('Batch subscribe')."</div>";
0671359f
AD
1354 print "<div dojoType=\"dijit.MenuItem\" onclick=\"removeSelectedFeeds()\">"
1355 .__('Unsubscribe')."</div> ";
afcfe6ca
AD
1356 print "</div></div>";
1357
a42c55f0 1358 if (get_pref('ENABLE_FEED_CATS')) {
afcfe6ca
AD
1359 print "<div dojoType=\"dijit.form.DropDownButton\">".
1360 "<span>" . __('Categories')."</span>";
1361 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
5ef071e0
AD
1362 print "<div onclick=\"createCategory()\"
1363 dojoType=\"dijit.MenuItem\">".__('Add category')."</div>";
afcfe6ca
AD
1364 print "<div onclick=\"resetCatOrder()\"
1365 dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>";
fd26d5bf
AD
1366 print "<div onclick=\"removeSelectedCategories()\"
1367 dojoType=\"dijit.MenuItem\">".__('Remove selected')."</div>";
afcfe6ca
AD
1368 print "</div></div>";
1369
1370 }
1371
1372 print $error_button;
1373 print $inactive_button;
1374
afcfe6ca
AD
1375 if (defined('_ENABLE_FEED_DEBUGGING')) {
1376
1377 print "<select id=\"feedActionChooser\" onchange=\"feedActionChange()\">
1378 <option value=\"facDefault\" selected>".__('More actions...')."</option>";
1379
1380 if (FORCE_ARTICLE_PURGE == 0) {
1381 print
1382 "<option value=\"facPurge\">".__('Manual purge')."</option>";
1383 }
1384
1385 print "
1386 <option value=\"facClear\">".__('Clear feed data')."</option>
1387 <option value=\"facRescore\">".__('Rescore articles')."</option>";
1388
1389 print "</select>";
1390
1391 }
1392
1393 print "</div>"; # toolbar
1394
1395 //print '</div>';
1396 print '<div dojoType="dijit.layout.ContentPane" region="center">';
1397
1398 print "<div id=\"feedlistLoading\">
1399 <img src='images/indicator_tiny.gif'>".
1400 __("Loading, please wait...")."</div>";
1401
1402 print "<div dojoType=\"fox.PrefFeedStore\" jsId=\"feedStore\"
1403 url=\"backend.php?op=pref-feeds&method=getfeedtree\">
1404 </div>
1405 <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"feedModel\" store=\"feedStore\"
1406 query=\"{id:'root'}\" rootId=\"root\" rootLabel=\"Feeds\"
1407 childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">
1408 </div>
1409 <div dojoType=\"fox.PrefFeedTree\" id=\"feedTree\"
1410 dndController=\"dijit.tree.dndSource\"
1411 betweenThreshold=\"5\"
1412 model=\"feedModel\" openOnClick=\"false\">
1413 <script type=\"dojo/method\" event=\"onClick\" args=\"item\">
1414 var id = String(item.id);
1415 var bare_id = id.substr(id.indexOf(':')+1);
1416
1417 if (id.match('FEED:')) {
1418 editFeed(bare_id);
1419 } else if (id.match('CAT:')) {
1420 editCat(bare_id, item);
1421 }
1422 </script>
1423 <script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
1424 Element.hide(\"feedlistLoading\");
1425 </script>
1426 </div>";
1427
ba5296a1
AD
1428# print "<div dojoType=\"dijit.Tooltip\" connectId=\"feedTree\" position=\"below\">
1429# ".__('<b>Hint:</b> you can drag feeds and categories around.')."
1430# </div>";
afcfe6ca
AD
1431
1432 print '</div>';
1433 print '</div>';
1434
1435 print "</div>"; # feeds pane
1436
6c2637d9 1437 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('OPML')."\">";
afcfe6ca 1438
11334fdf 1439 print_notice(__("Using OPML you can export and import your feeds, filters, labels and Tiny Tiny RSS settings.") . __("Only main settings profile can be migrated using OPML."));
afcfe6ca 1440
55f34b81 1441 print "<iframe id=\"upload_iframe\"
afcfe6ca
AD
1442 name=\"upload_iframe\" onload=\"opmlImportComplete(this)\"
1443 style=\"width: 400px; height: 100px; display: none;\"></iframe>";
1444
1445 print "<form name=\"opml_form\" style='display : block' target=\"upload_iframe\"
1446 enctype=\"multipart/form-data\" method=\"POST\"
55f34b81 1447 action=\"backend.php\">
afcfe6ca
AD
1448 <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
1449 <input type=\"hidden\" name=\"op\" value=\"dlg\">
c4c74732 1450 <input type=\"hidden\" name=\"method\" value=\"importOpml\">
afcfe6ca 1451 <button dojoType=\"dijit.form.Button\" onclick=\"return opmlImport();\" type=\"submit\">" .
a1159c01 1452 __('Import my OPML') . "</button>";
afcfe6ca 1453
a1159c01 1454 print "<hr>";
afcfe6ca
AD
1455
1456 print "<p>" . __('Filename:') .
1457 " <input type=\"text\" id=\"filename\" value=\"TinyTinyRSS.opml\" />&nbsp;" .
a1159c01 1458 __('Include settings') . "<input type=\"checkbox\" id=\"settings\" checked=\"1\"/>";
afcfe6ca 1459
a1159c01 1460 print "</p><button dojoType=\"dijit.form.Button\"
afcfe6ca 1461 onclick=\"gotoExportOpml(document.opml_form.filename.value, document.opml_form.settings.checked)\" >" .
a1159c01 1462 __('Export OPML') . "</button></p></form>";
afcfe6ca 1463
a1159c01 1464 print "<hr>";
afcfe6ca
AD
1465
1466 print "<p>".__('Your OPML can be published publicly and can be subscribed by anyone who knows the URL below.') . " ";
1467
566faa14 1468 print __("Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds.") . "</p>";
afcfe6ca 1469
fb54e3b1 1470 print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('".__("Public OPML URL")."','pubOPMLUrl')\">".
a1159c01 1471 __('Display published OPML URL')."</button> ";
afcfe6ca 1472
1ffe3391 1473 PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
699daf58
AD
1474 "hook_prefs_tab_section", "prefFeedsOPML");
1475
afcfe6ca
AD
1476 print "</div>"; # pane
1477
1478 if (strpos($_SERVER['HTTP_USER_AGENT'], "Firefox") !== false) {
1479
1480 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Firefox integration')."\">";
1481
11334fdf 1482 print_notice(__('This Tiny Tiny RSS site can be used as a Firefox Feed Reader by clicking the link below.'));
afcfe6ca
AD
1483
1484 print "<p>";
1485
1486 print "<button onclick='window.navigator.registerContentHandler(" .
1487 "\"application/vnd.mozilla.maybe.feed\", " .
1488 "\"" . add_feed_url() . "\", " . " \"Tiny Tiny RSS\")'>" .
1489 __('Click here to register this site as a feed reader.') .
1490 "</button>";
1491
1492 print "</p>";
1493
1494 print "</div>"; # pane
1495 }
1496
e95e7819 1497 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Published & shared articles / Generated feeds')."\">";
afcfe6ca 1498
11334fdf 1499 print_notice(__('Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the URL specified below.'));
afcfe6ca
AD
1500
1501 $rss_url = '-2::' . htmlspecialchars(get_self_url_prefix() .
1502 "/public.php?op=rss&id=-2&view-mode=all_articles");;
1503
11334fdf
AD
1504 print "<p>";
1505
fb54e3b1 1506 print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('".__("View as RSS")."','generatedFeed', '$rss_url')\">".
afcfe6ca
AD
1507 __('Display URL')."</button> ";
1508
1509 print "<button dojoType=\"dijit.form.Button\" onclick=\"return clearFeedAccessKeys()\">".
1510 __('Clear all generated URLs')."</button> ";
1511
11334fdf 1512 print "</p>";
afcfe6ca 1513
1ffe3391 1514 PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
699daf58
AD
1515 "hook_prefs_tab_section", "prefFeedsPublishedGenerated");
1516
afcfe6ca
AD
1517 print "</div>"; #pane
1518
1ffe3391 1519 PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB,
6065f3ad
AD
1520 "hook_prefs_tab", "prefFeeds");
1521
afcfe6ca 1522 print "</div>"; #container
afcfe6ca 1523 }
2ecd2df5 1524
88918ca6 1525 private function feedlist_init_cat($cat_id) {
2ecd2df5
AD
1526 $obj = array();
1527 $cat_id = (int) $cat_id;
1528
1529 if ($cat_id > 0) {
a42c55f0 1530 $cat_unread = ccache_find($cat_id, $_SESSION["uid"], true);
2ecd2df5 1531 } else if ($cat_id == 0 || $cat_id == -2) {
a42c55f0 1532 $cat_unread = getCategoryUnread($cat_id);
2ecd2df5
AD
1533 }
1534
1535 $obj['id'] = 'CAT:' . $cat_id;
1536 $obj['items'] = array();
a42c55f0 1537 $obj['name'] = getCategoryTitle($cat_id);
2ecd2df5
AD
1538 $obj['type'] = 'category';
1539 $obj['unread'] = (int) $cat_unread;
2ecd2df5
AD
1540 $obj['bare_id'] = $cat_id;
1541
1542 return $obj;
1543 }
1544
1545 private function feedlist_init_feed($feed_id, $title = false, $unread = false, $error = '', $updated = '') {
1546 $obj = array();
1547 $feed_id = (int) $feed_id;
1548
1549 if (!$title)
a42c55f0 1550 $title = getFeedTitle($feed_id, false);
2ecd2df5
AD
1551
1552 if ($unread === false)
a42c55f0 1553 $unread = getFeedUnread($feed_id, false);
2ecd2df5
AD
1554
1555 $obj['id'] = 'FEED:' . $feed_id;
1556 $obj['name'] = $title;
1557 $obj['unread'] = (int) $unread;
1558 $obj['type'] = 'feed';
1559 $obj['error'] = $error;
1560 $obj['updated'] = $updated;
1561 $obj['icon'] = getFeedIcon($feed_id);
1562 $obj['bare_id'] = $feed_id;
c594eca0 1563 $obj['auxcounter'] = 0;
2ecd2df5
AD
1564
1565 return $obj;
1566 }
1567
bc6fa236
AD
1568 function inactiveFeeds() {
1569
1570 if (DB_TYPE == "pgsql") {
1571 $interval_qpart = "NOW() - INTERVAL '3 months'";
1572 } else {
1573 $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)";
1574 }
1575
d9c85e0f 1576 $result = $this->dbh->query("SELECT ttrss_feeds.title, ttrss_feeds.site_url,
bc6fa236
AD
1577 ttrss_feeds.feed_url, ttrss_feeds.id, MAX(updated) AS last_article
1578 FROM ttrss_feeds, ttrss_entries, ttrss_user_entries WHERE
1579 (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE
1580 ttrss_entries.id = ref_id AND
1581 ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart
1582 AND ttrss_feeds.owner_uid = ".$_SESSION["uid"]." AND
1583 ttrss_user_entries.feed_id = ttrss_feeds.id AND
1584 ttrss_entries.id = ref_id
1585 GROUP BY ttrss_feeds.title, ttrss_feeds.id, ttrss_feeds.site_url, ttrss_feeds.feed_url
1586 ORDER BY last_article");
1587
11334fdf 1588 print "<p" .__("These feeds have not been updated with new content for 3 months (oldest first):") . "</p>";
bc6fa236
AD
1589
1590 print "<div dojoType=\"dijit.Toolbar\">";
1591 print "<div dojoType=\"dijit.form.DropDownButton\">".
1592 "<span>" . __('Select')."</span>";
1593 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
1594 print "<div onclick=\"selectTableRows('prefInactiveFeedList', 'all')\"
1595 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
1596 print "<div onclick=\"selectTableRows('prefInactiveFeedList', 'none')\"
1597 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
1598 print "</div></div>";
1599 print "</div>"; #toolbar
1600
1601 print "<div class=\"inactiveFeedHolder\">";
1602
1603 print "<table width=\"100%\" cellspacing=\"0\" id=\"prefInactiveFeedList\">";
1604
1605 $lnum = 1;
1606
d9c85e0f 1607 while ($line = $this->dbh->fetch_assoc($result)) {
bc6fa236 1608
bc6fa236
AD
1609 $feed_id = $line["id"];
1610 $this_row_id = "id=\"FUPDD-$feed_id\"";
1611
1612 # class needed for selectTableRows()
1613 print "<tr class=\"placeholder\" $this_row_id>";
1614
bc6fa236
AD
1615 # id needed for selectTableRows()
1616 print "<td width='5%' align='center'><input
1617 onclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\"
1618 type=\"checkbox\" id=\"FUPDC-$feed_id\"></td>";
1619 print "<td>";
1620
1621 print "<a class=\"visibleLink\" href=\"#\" ".
1622 "title=\"".__("Click to edit feed")."\" ".
1623 "onclick=\"editFeed(".$line["id"].")\">".
1624 htmlspecialchars($line["title"])."</a>";
1625
1626 print "</td><td class=\"insensitive\" align='right'>";
a42c55f0 1627 print make_local_datetime($line['last_article'], false);
bc6fa236
AD
1628 print "</td>";
1629 print "</tr>";
1630
1631 ++$lnum;
1632 }
1633
1634 print "</table>";
1635 print "</div>";
1636
1637 print "<div class='dlgButtons'>";
1638 print "<div style='float : left'>";
1639 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('inactiveFeedsDlg').removeSelected()\">"
1640 .__('Unsubscribe from selected feeds')."</button> ";
1641 print "</div>";
1642
1643 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('inactiveFeedsDlg').hide()\">".
1644 __('Close this window')."</button>";
1645
1646 print "</div>";
1647
1648 }
1649
1650 function feedsWithErrors() {
d9c85e0f 1651 $result = $this->dbh->query("SELECT id,title,feed_url,last_error,site_url
bc6fa236
AD
1652 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1653
1654 print "<div dojoType=\"dijit.Toolbar\">";
1655 print "<div dojoType=\"dijit.form.DropDownButton\">".
1656 "<span>" . __('Select')."</span>";
1657 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
1658 print "<div onclick=\"selectTableRows('prefErrorFeedList', 'all')\"
1659 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
1660 print "<div onclick=\"selectTableRows('prefErrorFeedList', 'none')\"
1661 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
1662 print "</div></div>";
1663 print "</div>"; #toolbar
1664
1665 print "<div class=\"inactiveFeedHolder\">";
1666
1667 print "<table width=\"100%\" cellspacing=\"0\" id=\"prefErrorFeedList\">";
1668
1669 $lnum = 1;
1670
d9c85e0f 1671 while ($line = $this->dbh->fetch_assoc($result)) {
bc6fa236 1672
bc6fa236
AD
1673 $feed_id = $line["id"];
1674 $this_row_id = "id=\"FERDD-$feed_id\"";
1675
1676 # class needed for selectTableRows()
1677 print "<tr class=\"placeholder\" $this_row_id>";
1678
bc6fa236
AD
1679 # id needed for selectTableRows()
1680 print "<td width='5%' align='center'><input
1681 onclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\"
1682 type=\"checkbox\" id=\"FERDC-$feed_id\"></td>";
1683 print "<td>";
1684
1685 print "<a class=\"visibleLink\" href=\"#\" ".
1686 "title=\"".__("Click to edit feed")."\" ".
1687 "onclick=\"editFeed(".$line["id"].")\">".
1688 htmlspecialchars($line["title"])."</a>: ";
1689
1690 print "<span class=\"insensitive\">";
1691 print htmlspecialchars($line["last_error"]);
1692 print "</span>";
1693
1694 print "</td>";
1695 print "</tr>";
1696
1697 ++$lnum;
1698 }
1699
1700 print "</table>";
1701 print "</div>";
1702
1703 print "<div class='dlgButtons'>";
1704 print "<div style='float : left'>";
1705 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('errorFeedsDlg').removeSelected()\">"
1706 .__('Unsubscribe from selected feeds')."</button> ";
1707 print "</div>";
1708
1709 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('errorFeedsDlg').hide()\">".
1710 __('Close this window')."</button>";
1711
1712 print "</div>";
1713 }
1714
87d7e850
AD
1715 /**
1716 * Purge a feed contents, marked articles excepted.
1717 *
1718 * @param mixed $link The database connection.
1719 * @param integer $id The id of the feed to purge.
1720 * @return void
1721 */
6322ac79 1722 private function clear_feed_articles($id) {
87d7e850
AD
1723
1724 if ($id != 0) {
d9c85e0f 1725 $result = $this->dbh->query("DELETE FROM ttrss_user_entries
87d7e850
AD
1726 WHERE feed_id = '$id' AND marked = false AND owner_uid = " . $_SESSION["uid"]);
1727 } else {
d9c85e0f 1728 $result = $this->dbh->query("DELETE FROM ttrss_user_entries
87d7e850
AD
1729 WHERE feed_id IS NULL AND marked = false AND owner_uid = " . $_SESSION["uid"]);
1730 }
1731
d9c85e0f 1732 $result = $this->dbh->query("DELETE FROM ttrss_entries WHERE
87d7e850
AD
1733 (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0");
1734
a42c55f0 1735 ccache_update($id, $_SESSION['uid']);
87d7e850
AD
1736 } // function clear_feed_articles
1737
a42c55f0 1738 private function remove_feed_category($id, $owner_uid) {
a6a9b812 1739
d9c85e0f 1740 $this->dbh->query("DELETE FROM ttrss_feed_categories
a6a9b812
AD
1741 WHERE id = '$id' AND owner_uid = $owner_uid");
1742
a42c55f0 1743 ccache_remove($id, $owner_uid, true);
a6a9b812
AD
1744 }
1745
a42c55f0 1746 static function remove_feed($id, $owner_uid) {
a6a9b812
AD
1747
1748 if ($id > 0) {
1749
1750 /* save starred articles in Archived feed */
1751
a42c55f0 1752 db_query("BEGIN");
a6a9b812
AD
1753
1754 /* prepare feed if necessary */
1755
a42c55f0 1756 $result = db_query("SELECT feed_url FROM ttrss_feeds WHERE id = $id
aa5ac2cd
AD
1757 AND owner_uid = $owner_uid");
1758
a42c55f0 1759 $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url"));
aa5ac2cd 1760
a42c55f0 1761 $result = db_query("SELECT id FROM ttrss_archived_feeds
aa5ac2cd 1762 WHERE feed_url = '$feed_url' AND owner_uid = $owner_uid");
a6a9b812
AD
1763
1764 if (db_num_rows($result) == 0) {
a42c55f0 1765 $result = db_query("SELECT MAX(id) AS id FROM ttrss_archived_feeds");
b1df14d0
AD
1766 $new_feed_id = (int)db_fetch_result($result, 0, "id") + 1;
1767
a42c55f0 1768 db_query("INSERT INTO ttrss_archived_feeds
a6a9b812 1769 (id, owner_uid, title, feed_url, site_url)
b1df14d0 1770 SELECT $new_feed_id, owner_uid, title, feed_url, site_url from ttrss_feeds
aa5ac2cd
AD
1771 WHERE id = '$id'");
1772
b1df14d0 1773 $archive_id = $new_feed_id;
aa5ac2cd
AD
1774 } else {
1775 $archive_id = db_fetch_result($result, 0, "id");
a6a9b812
AD
1776 }
1777
a42c55f0 1778 db_query("UPDATE ttrss_user_entries SET feed_id = NULL,
aa5ac2cd 1779 orig_feed_id = '$archive_id' WHERE feed_id = '$id' AND
a6a9b812
AD
1780 marked = true AND owner_uid = $owner_uid");
1781
1782 /* Remove access key for the feed */
1783
a42c55f0 1784 db_query("DELETE FROM ttrss_access_keys WHERE
a6a9b812
AD
1785 feed_id = '$id' AND owner_uid = $owner_uid");
1786
1787 /* remove the feed */
1788
a42c55f0 1789 db_query("DELETE FROM ttrss_feeds
a6a9b812
AD
1790 WHERE id = '$id' AND owner_uid = $owner_uid");
1791
a42c55f0 1792 db_query("COMMIT");
a6a9b812
AD
1793
1794 if (file_exists(ICONS_DIR . "/$id.ico")) {
1795 unlink(ICONS_DIR . "/$id.ico");
1796 }
1797
a42c55f0 1798 ccache_remove($id, $owner_uid);
a6a9b812
AD
1799
1800 } else {
a42c55f0
AD
1801 label_remove(feed_to_label_id($id), $owner_uid);
1802 //ccache_remove($id, $owner_uid); don't think labels are cached
a6a9b812
AD
1803 }
1804 }
87d7e850 1805
201bb1ca 1806 function batchSubscribe() {
96e3ae8c 1807 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-feeds\">";
201bb1ca
AD
1808 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"batchaddfeeds\">";
1809
1810 print "<table width='100%'><tr><td>
1811 ".__("Add one valid RSS feed per line (no feed detection is done)")."
1812 </td><td align='right'>";
a42c55f0 1813 if (get_pref('ENABLE_FEED_CATS')) {
201bb1ca 1814 print __('Place in category:') . " ";
a42c55f0 1815 print_feed_cat_select("cat", false, 'dojoType="dijit.form.Select"');
201bb1ca
AD
1816 }
1817 print "</td></tr><tr><td colspan='2'>";
1818 print "<textarea
1819 style='font-size : 12px; width : 100%; height: 200px;'
1820 placeHolder=\"".__("Feeds to subscribe, One per line")."\"
1821 dojoType=\"dijit.form.SimpleTextarea\" required=\"1\" name=\"feeds\"></textarea>";
1822
1823 print "</td></tr><tr><td colspan='2'>";
1824
1825 print "<div id='feedDlg_loginContainer' style='display : none'>
1826 " .
1827 " <input dojoType=\"dijit.form.TextBox\" name='login'\"
1828 placeHolder=\"".__("Login")."\"
1829 style=\"width : 10em;\"> ".
1830 " <input
1831 placeHolder=\"".__("Password")."\"
1832 dojoType=\"dijit.form.TextBox\" type='password'
1833 style=\"width : 10em;\" name='pass'\">".
1834 "</div>";
1835
1836 print "</td></tr><tr><td colspan='2'>";
1837
1838 print "<div style=\"clear : both\">
1839 <input type=\"checkbox\" name=\"need_auth\" dojoType=\"dijit.form.CheckBox\" id=\"feedDlg_loginCheck\"
1840 onclick='checkboxToggleElement(this, \"feedDlg_loginContainer\")'>
1841 <label for=\"feedDlg_loginCheck\">".
1842 __('Feeds require authentication.')."</div>";
1843
1844 print "</form>";
1845
1846 print "</td></tr></table>";
1847
1848 print "<div class=\"dlgButtons\">
1849 <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('batchSubDlg').execute()\">".__('Subscribe')."</button>
1850 <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('batchSubDlg').hide()\">".__('Cancel')."</button>
1851 </div>";
1852 }
1853
96e3ae8c 1854 function batchAddFeeds() {
d9c85e0f 1855 $cat_id = $this->dbh->escape_string($_REQUEST['cat']);
2714d5ca 1856 $feeds = explode("\n", $_REQUEST['feeds']);
d9c85e0f 1857 $login = $this->dbh->escape_string($_REQUEST['login']);
41694a95 1858 $pass = trim($_REQUEST['pass']);
96e3ae8c
AD
1859
1860 foreach ($feeds as $feed) {
d9c85e0f 1861 $feed = $this->dbh->escape_string(trim($feed));
96e3ae8c
AD
1862
1863 if (validate_feed_url($feed)) {
1864
d9c85e0f 1865 $this->dbh->query("BEGIN");
96e3ae8c
AD
1866
1867 if ($cat_id == "0" || !$cat_id) {
1868 $cat_qpart = "NULL";
1869 } else {
1870 $cat_qpart = "'$cat_id'";
1871 }
1872
d9c85e0f 1873 $result = $this->dbh->query(
96e3ae8c
AD
1874 "SELECT id FROM ttrss_feeds
1875 WHERE feed_url = '$feed' AND owner_uid = ".$_SESSION["uid"]);
1876
044cff2d
AD
1877 if (strlen(FEED_CRYPT_KEY) > 0) {
1878 require_once "crypt.php";
1879 $pass = substr(encrypt_string($pass), 0, 250);
1880 $auth_pass_encrypted = 'true';
1881 } else {
1882 $auth_pass_encrypted = 'false';
1883 }
1884
d9c85e0f 1885 $pass = $this->dbh->escape_string($pass);
41694a95 1886
d9c85e0f
AD
1887 if ($this->dbh->num_rows($result) == 0) {
1888 $result = $this->dbh->query(
96e3ae8c 1889 "INSERT INTO ttrss_feeds
044cff2d 1890 (owner_uid,feed_url,title,cat_id,auth_login,auth_pass,update_method,auth_pass_encrypted)
96e3ae8c 1891 VALUES ('".$_SESSION["uid"]."', '$feed',
044cff2d 1892 '[Unknown]', $cat_qpart, '$login', '$pass', 0, $auth_pass_encrypted)");
96e3ae8c
AD
1893 }
1894
d9c85e0f 1895 $this->dbh->query("COMMIT");
96e3ae8c
AD
1896 }
1897 }
1898 }
201bb1ca 1899
195187c4 1900 function regenOPMLKey() {
a42c55f0 1901 $this->update_feed_access_key('OPML:Publish',
195187c4
AD
1902 false, $_SESSION["uid"]);
1903
6322ac79 1904 $new_link = Opml::opml_publish_url();
195187c4
AD
1905
1906 print json_encode(array("link" => $new_link));
1907 }
1908
1909 function regenFeedKey() {
d9c85e0f
AD
1910 $feed_id = $this->dbh->escape_string($_REQUEST['id']);
1911 $is_cat = $this->dbh->escape_string($_REQUEST['is_cat']) == "true";
195187c4 1912
a42c55f0 1913 $new_key = $this->update_feed_access_key($feed_id, $is_cat);
195187c4
AD
1914
1915 print json_encode(array("link" => $new_key));
1916 }
1917
1918
a42c55f0 1919 private function update_feed_access_key($feed_id, $is_cat, $owner_uid = false) {
195187c4
AD
1920 if (!$owner_uid) $owner_uid = $_SESSION["uid"];
1921
1922 $sql_is_cat = bool_to_sql_bool($is_cat);
1923
d9c85e0f 1924 $result = $this->dbh->query("SELECT access_key FROM ttrss_access_keys
195187c4
AD
1925 WHERE feed_id = '$feed_id' AND is_cat = $sql_is_cat
1926 AND owner_uid = " . $owner_uid);
1927
d9c85e0f 1928 if ($this->dbh->num_rows($result) == 1) {
3ceb893f 1929 $key = $this->dbh->escape_string(uniqid_short());
195187c4 1930
d9c85e0f 1931 $this->dbh->query("UPDATE ttrss_access_keys SET access_key = '$key'
195187c4
AD
1932 WHERE feed_id = '$feed_id' AND is_cat = $sql_is_cat
1933 AND owner_uid = " . $owner_uid);
1934
1935 return $key;
1936
1937 } else {
a42c55f0 1938 return get_feed_access_key($feed_id, $is_cat, $owner_uid);
195187c4
AD
1939 }
1940 }
1941
1942 // Silent
1943 function clearKeys() {
d9c85e0f 1944 $this->dbh->query("DELETE FROM ttrss_access_keys WHERE
195187c4
AD
1945 owner_uid = " . $_SESSION["uid"]);
1946 }
1947
496195db
AD
1948 private function calculate_children_count($cat) {
1949 $c = 0;
1950
1951 foreach ($cat['items'] as $child) {
1952 if ($child['type'] == 'category') {
1953 $c += $this->calculate_children_count($child);
1954 } else {
1955 $c += 1;
1956 }
1957 }
1958
1959 return $c;
1960 }
195187c4 1961
afcfe6ca
AD
1962}
1963?>