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