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