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