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