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