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