]> git.wh0rd.org - tt-rss.git/blame - modules/pref-feeds.php
CDM: implement scoring display
[tt-rss.git] / modules / pref-feeds.php
CommitLineData
ef8be8ea 1<?php
d20f3544 2
ef8be8ea
AD
3 function module_pref_feeds($link) {
4
d20f3544
AD
5 global $update_intervals;
6 global $purge_intervals;
16211ddb 7 global $update_methods;
d20f3544 8
ef8be8ea
AD
9 $subop = $_REQUEST["subop"];
10 $quiet = $_REQUEST["quiet"];
11
12 if ($subop == "massSubscribe") {
13 $ids = split(",", db_escape_string($_GET["ids"]));
14
15 $subscribed = array();
16
17 foreach ($ids as $id) {
18 $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds
19 WHERE id = '$id'");
20
21 $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url"));
22 $title = db_escape_string(db_fetch_result($result, 0, "title"));
23
24 $title_orig = db_fetch_result($result, 0, "title");
25
26 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
27 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
28
29 if (db_num_rows($result) == 0) {
30 $result = db_query($link,
31 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id)
32 VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)");
33
34 array_push($subscribed, $title_orig);
35 }
36 }
37
38 if (count($subscribed) > 0) {
31cc42f6 39 $msg = "<b>".__('Subscribed to feeds:')."</b>".
0d32b41e
AD
40 "<ul class=\"nomarks\">";
41
ef8be8ea 42 foreach ($subscribed as $title) {
0d32b41e 43 $msg .= "<li>$title</li>";
ef8be8ea 44 }
0d32b41e
AD
45 $msg .= "</ul>";
46
47 print format_notice($msg);
ef8be8ea
AD
48 }
49 }
50
51 if ($subop == "browse") {
52
53 if (!ENABLE_FEED_BROWSER) {
31cc42f6 54 print __("Feed browser is administratively disabled.");
ef8be8ea
AD
55 return;
56 }
57
31cc42f6 58 print "<div id=\"infoBoxTitle\">".__('Other feeds: Top 25')."</div>";
ef8be8ea
AD
59
60 print "<div class=\"infoBoxContents\">";
61
31cc42f6 62 print "<p>".__("Showing top 25 registered feeds, sorted by popularity:")."</p>";
ef8be8ea
AD
63
64# $result = db_query($link, "SELECT feed_url,count(id) AS subscribers
65# FROM ttrss_feeds
66# WHERE auth_login = '' AND auth_pass = '' AND private = false
67# GROUP BY feed_url ORDER BY subscribers DESC LIMIT 25");
68
69 $owner_uid = $_SESSION["uid"];
70
71 $result = db_query($link, "SELECT feed_url,COUNT(id) AS subscribers
72 FROM ttrss_feeds WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf
73 WHERE tf.feed_url = ttrss_feeds.feed_url
74 AND owner_uid = '$owner_uid') GROUP BY feed_url
75 ORDER BY subscribers DESC LIMIT 25");
76
77 print "<ul class='browseFeedList' id='browseFeedList'>";
78
79 $feedctr = 0;
80
81 while ($line = db_fetch_assoc($result)) {
82 $feed_url = $line["feed_url"];
83 $subscribers = $line["subscribers"];
84
85 $det_result = db_query($link, "SELECT site_url,title,id
86 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
87
88 $details = db_fetch_assoc($det_result);
89
90 $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico";
91
92 if (file_exists($icon_file) && filesize($icon_file) > 0) {
93 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL .
94 "/".$details["id"].".ico\">";
95 } else {
96 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
97 }
98
99 $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB'
100 type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
101
102 $class = ($feedctr % 2) ? "even" : "odd";
103
104 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
47439031 105 "$feed_icon " . $details["title"] .
ef8be8ea
AD
106 "&nbsp;<span class='subscribers'>($subscribers)</span></li>";
107
108 ++$feedctr;
109 }
110
111 if ($feedctr == 0) {
31cc42f6 112 print "<li>".__('No feeds found to subscribe.')."</li>";
ef8be8ea
AD
113 }
114
115 print "</ul>";
116
117 print "<div align='center'>
118 <input type=\"submit\" class=\"button\"
31cc42f6 119 onclick=\"feedBrowserSubscribe()\" value=\"".__('Subscribe')."\">
ef8be8ea 120 <input type='submit' class='button'
31cc42f6 121 onclick=\"closeInfoBox()\" value=\"".__('Cancel')."\"></div>";
ef8be8ea
AD
122
123 print "</div>";
124 return;
125 }
126
127 if ($subop == "editfeed") {
128 $feed_id = db_escape_string($_REQUEST["id"]);
129
130 $result = db_query($link,
131 "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND
132 owner_uid = " . $_SESSION["uid"]);
133
47439031
AD
134 $title = htmlspecialchars(db_fetch_result($result,
135 0, "title"));
ef8be8ea
AD
136
137 $icon_file = ICONS_DIR . "/$feed_id.ico";
138
139 if (file_exists($icon_file) && filesize($icon_file) > 0) {
140 $feed_icon = "<img width=\"16\" height=\"16\"
141 src=\"" . ICONS_URL . "/$feed_id.ico\">";
142 } else {
143 $feed_icon = "";
144 }
145
31cc42f6 146 print "<div id=\"infoBoxTitle\">".__('Feed editor')."</div>";
ef8be8ea
AD
147
148 print "<div class=\"infoBoxContents\">";
149
e6312f6c 150 print "<form id=\"edit_feed_form\" onsubmit=\"return false\">";
ef8be8ea
AD
151
152 print "<input type=\"hidden\" name=\"id\" value=\"$feed_id\">";
153 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
154 print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
155
156 print "<table width='100%'>";
157
31cc42f6 158 print "<tr><td>".__('Title:')."</td>";
ef8be8ea
AD
159 print "<td><input class=\"iedit\" onkeypress=\"return filterCR(event, feedEditSave)\"
160 name=\"title\" value=\"$title\"></td></tr>";
161
162 $feed_url = db_fetch_result($result, 0, "feed_url");
47439031
AD
163 $feed_url = htmlspecialchars(db_fetch_result($result,
164 0, "feed_url"));
ef8be8ea 165
31cc42f6 166 print "<tr><td>".__('Feed URL:')."</td>";
ef8be8ea
AD
167 print "<td><input class=\"iedit\" onkeypress=\"return filterCR(event, feedEditSave)\"
168 name=\"feed_url\" value=\"$feed_url\"></td></tr>";
169
170 if (get_pref($link, 'ENABLE_FEED_CATS')) {
171
172 $cat_id = db_fetch_result($result, 0, "cat_id");
173
31cc42f6 174 print "<tr><td>".__('Category:')."</td>";
ef8be8ea
AD
175 print "<td>";
176
177 $parent_feed = db_fetch_result($result, 0, "parent_feed");
178
179 if (sprintf("%d", $parent_feed) > 0) {
180 $disabled = "disabled";
181 } else {
182 $disabled = "";
183 }
184
185 print_feed_cat_select($link, "cat_id", $cat_id, "class=\"iedit\" $disabled");
186
187 print "</td>";
188 print "</td></tr>";
189
190 }
191
192 $update_interval = db_fetch_result($result, 0, "update_interval");
193
31cc42f6 194 print "<tr><td>".__('Update Interval:')."</td>";
ef8be8ea
AD
195
196 print "<td>";
197
198 print_select_hash("update_interval", $update_interval, $update_intervals,
199 "class=\"iedit\"");
200
201 print "</td>";
202
31cc42f6 203 print "<tr><td>".__('Link to:')."</td><td>";
ef8be8ea
AD
204
205 $tmp_result = db_query($link, "SELECT COUNT(id) AS count
206 FROM ttrss_feeds WHERE parent_feed = '$feed_id'");
207
208 $linked_count = db_fetch_result($tmp_result, 0, "count");
209
210 $parent_feed = db_fetch_result($result, 0, "parent_feed");
211
212 if ($linked_count > 0) {
213 $disabled = "disabled";
214 } else {
215 $disabled = "";
216 }
217
218 print "<select class=\"iedit\" $disabled name=\"parent_feed\">";
219
31cc42f6 220 print "<option value=\"0\">".__('Not linked')."</option>";
ef8be8ea
AD
221
222 if (get_pref($link, 'ENABLE_FEED_CATS')) {
223 if ($cat_id) {
224 $cat_qpart = "AND cat_id = '$cat_id'";
225 } else {
226 $cat_qpart = "AND cat_id IS NULL";
227 }
228 }
229
230 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
231 WHERE id != '$feed_id' AND owner_uid = ".$_SESSION["uid"]." AND
232 (SELECT COUNT(id) FROM ttrss_feeds AS T2 WHERE T2.id = ttrss_feeds.parent_feed) = 0
233 $cat_qpart ORDER BY title");
234
235 if (db_num_rows($tmp_result) > 0) {
236 print "<option disabled>--------</option>";
237 }
238
239 while ($tmp_line = db_fetch_assoc($tmp_result)) {
240 if ($tmp_line["id"] == $parent_feed) {
241 $is_selected = "selected";
242 } else {
243 $is_selected = "";
244 }
245 printf("<option $is_selected value='%d'>%s</option>",
246 $tmp_line["id"], $tmp_line["title"]);
247 }
248
249 print "</select>";
250 print "</td></tr>";
251
252 $purge_interval = db_fetch_result($result, 0, "purge_interval");
253
31cc42f6 254 print "<tr><td>".__('Article purging:')."</td>";
ef8be8ea
AD
255
256 print "<td>";
257
258 print_select_hash("purge_interval", $purge_interval, $purge_intervals,
259 "class=\"iedit\"");
260
261 print "</td>";
262
34459667 263 if (ALLOW_SELECT_UPDATE_METHOD) {
16211ddb 264
34459667
AD
265 $update_method = db_fetch_result($result, 0, "update_method");
266
267 print "<tr><td>".__('Update using:')."</td>";
268
269 print "<td>";
270
271 print_select_hash("update_method", $update_method, $update_methods,
272 "class=\"iedit\"");
273
274 print "</td>";
275 }
16211ddb 276
47439031 277 $auth_login = htmlspecialchars(db_fetch_result($result, 0, "auth_login"));
ef8be8ea 278
31cc42f6 279 print "<tr><td>".__('Login:')."</td>";
ef8be8ea
AD
280 print "<td><input class=\"iedit\" onkeypress=\"return filterCR(event, feedEditSave)\"
281 name=\"auth_login\" value=\"$auth_login\"></td></tr>";
282
47439031 283 $auth_pass = htmlspecialchars(db_fetch_result($result, 0, "auth_pass"));
ef8be8ea 284
31cc42f6 285 print "<tr><td>".__('Password:')."</td>";
ef8be8ea
AD
286 print "<td><input class=\"iedit\" type=\"password\" name=\"auth_pass\"
287 onkeypress=\"return filterCR(event, feedEditSave)\"
288 value=\"$auth_pass\"></td></tr>";
289
290 $private = sql_bool_to_bool(db_fetch_result($result, 0, "private"));
291
292 if ($private) {
293 $checked = "checked";
294 } else {
295 $checked = "";
296 }
297
31cc42f6 298 print "<tr><td valign='top'>".__('Options:')."</td>";
ef8be8ea 299 print "<td><input type=\"checkbox\" name=\"private\" id=\"private\"
31cc42f6 300 $checked><label for=\"private\">".__('Hide from "Other Feeds"')."</label>";
ef8be8ea
AD
301
302 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
303
304 if ($rtl_content) {
305 $checked = "checked";
306 } else {
307 $checked = "";
308 }
309
310 print "<br><input type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"
3692e98f 311 $checked><label for=\"rtl_content\">".__('Right-to-left content')."</label>";
ef8be8ea
AD
312
313 $hidden = sql_bool_to_bool(db_fetch_result($result, 0, "hidden"));
314
315 if ($hidden) {
316 $checked = "checked";
317 } else {
318 $checked = "";
319 }
320
321 print "<br><input type=\"checkbox\" id=\"hidden\" name=\"hidden\"
31cc42f6 322 $checked><label for=\"hidden\">".__('Hide from my feed list')."</label>";
ef8be8ea
AD
323
324 $include_in_digest = sql_bool_to_bool(db_fetch_result($result, 0, "include_in_digest"));
325
326 if ($include_in_digest) {
327 $checked = "checked";
328 } else {
329 $checked = "";
330 }
331
332 print "<br><input type=\"checkbox\" id=\"include_in_digest\"
333 name=\"include_in_digest\"
31cc42f6 334 $checked><label for=\"include_in_digest\">".__('Include in e-mail digest')."</label>";
ef8be8ea 335
bc0f0785
AD
336 $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
337
338 if ($cache_images) {
339 $checked = "checked";
340 } else {
341 $checked = "";
342 }
343
344 if (ENABLE_SIMPLEPIE && SIMPLEPIE_CACHE_IMAGES) {
345 $disabled = "";
346 $label_class = "";
347 } else {
348 $disabled = "disabled";
349 $label_class = "class='insensitive'";
350 }
351
352 print "<br><input type=\"checkbox\" id=\"cache_images\"
353 name=\"cache_images\" $disabled
354 $checked><label $label_class for=\"cache_images\">".
355 __('Cache images locally')."</label>";
356
ef8be8ea
AD
357 print "</td></tr>";
358
359 print "</table>";
360
361 print "</form>";
362
363 print "<div align='right'>
364 <input type=\"submit\" class=\"button\"
31cc42f6 365 onclick=\"return feedEditSave()\" value=\"".__('Save')."\">
ef8be8ea 366 <input type='submit' class='button'
31cc42f6 367 onclick=\"return feedEditCancel()\" value=\"".__('Cancel')."\"></div>";
ef8be8ea
AD
368
369 print "</div>";
370
371 return;
372 }
373
374 if ($subop == "editSave") {
375
376 $feed_title = db_escape_string(trim($_POST["title"]));
377 $feed_link = db_escape_string(trim($_POST["feed_url"]));
378 $upd_intl = db_escape_string($_POST["update_interval"]);
379 $purge_intl = db_escape_string($_POST["purge_interval"]);
380 $feed_id = db_escape_string($_POST["id"]);
381 $cat_id = db_escape_string($_POST["cat_id"]);
382 $auth_login = db_escape_string(trim($_POST["auth_login"]));
383 $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
384 $parent_feed = db_escape_string($_POST["parent_feed"]);
385 $private = checkbox_to_sql_bool(db_escape_string($_POST["private"]));
386 $rtl_content = checkbox_to_sql_bool(db_escape_string($_POST["rtl_content"]));
387 $hidden = checkbox_to_sql_bool(db_escape_string($_POST["hidden"]));
388 $include_in_digest = checkbox_to_sql_bool(
389 db_escape_string($_POST["include_in_digest"]));
bc0f0785
AD
390 $cache_images = checkbox_to_sql_bool(
391 db_escape_string($_POST["cache_images"]));
16211ddb 392 $update_method = (int) db_escape_string($_POST["update_method"]);
ef8be8ea
AD
393
394 if (get_pref($link, 'ENABLE_FEED_CATS')) {
395 if ($cat_id && $cat_id != 0) {
396 $category_qpart = "cat_id = '$cat_id',";
397 $category_qpart_nocomma = "cat_id = '$cat_id'";
398 } else {
399 $category_qpart = 'cat_id = NULL,';
400 $category_qpart_nocomma = 'cat_id = NULL';
401 }
402 } else {
403 $category_qpart = "";
404 $category_qpart_nocomma = "";
405 }
406
407 if ($parent_feed && $parent_feed != 0) {
408 $parent_qpart = "parent_feed = '$parent_feed'";
409 } else {
410 $parent_qpart = 'parent_feed = NULL';
411 }
412
bc0f0785
AD
413 if (ENABLE_SIMPLEPIE && SIMPLEPIE_CACHE_IMAGES) {
414 $cache_images_qpart = "cache_images = $cache_images,";
415 } else {
416 $cache_images_qpart = "";
417 }
418
ef8be8ea
AD
419 $result = db_query($link, "UPDATE ttrss_feeds SET
420 $category_qpart $parent_qpart,
421 title = '$feed_title', feed_url = '$feed_link',
422 update_interval = '$upd_intl',
423 purge_interval = '$purge_intl',
424 auth_login = '$auth_login',
425 auth_pass = '$auth_pass',
426 private = $private,
427 rtl_content = $rtl_content,
428 hidden = $hidden,
bc0f0785 429 $cache_images_qpart
16211ddb
AD
430 include_in_digest = $include_in_digest,
431 update_method = '$update_method'
ef8be8ea
AD
432 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
433
434 if (get_pref($link, 'ENABLE_FEED_CATS')) {
435 # update linked feed categories
436 $result = db_query($link, "UPDATE ttrss_feeds SET
437 $category_qpart_nocomma WHERE parent_feed = '$feed_id' AND
438 owner_uid = " . $_SESSION["uid"]);
439 }
440 }
441
ef8be8ea
AD
442 if ($subop == "remove") {
443
444 if (!WEB_DEMO_MODE) {
445
446 $ids = split(",", db_escape_string($_GET["ids"]));
447
448 foreach ($ids as $id) {
449
450 if ($id > 0) {
451
452 db_query($link, "DELETE FROM ttrss_feeds
453 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
454
455 $icons_dir = ICONS_DIR;
456
457 if (file_exists($icons_dir . "/$id.ico")) {
458 unlink($icons_dir . "/$id.ico");
459 }
460 } else if ($id < -10) {
461
462 $label_id = -$id - 11;
463
464 db_query($link, "DELETE FROM ttrss_labels
465 WHERE id = '$label_id' AND owner_uid = " . $_SESSION["uid"]);
466 }
467 }
468 }
469 }
470
d1f0c584
AD
471 if ($subop == "clear") {
472 $id = db_escape_string($_GET["id"]);
473 clear_feed_articles($link, $id);
474 }
475
fee840fb
AD
476 if ($subop == "rescore") {
477 $ids = split(",", db_escape_string($_GET["ids"]));
478
479 foreach ($ids as $id) {
480
481 $filters = load_filters($link, $id, $_SESSION["uid"], 6);
482
483 $result = db_query($link, "SELECT title, content, link, ref_id FROM
484 ttrss_user_entries, ttrss_entries
485 WHERE ref_id = id AND feed_id = '$id' AND
486 owner_uid = " .$_SESSION['uid']."
487 ORDER BY updated DESC LIMIT 100");
488
489 $scores = array();
490
491 while ($line = db_fetch_assoc($result)) {
492
493 $article_filters = get_article_filters($filters, $line['title'],
494 $line['content'], $line['link']);
495
496 $new_score = calculate_article_score($article_filters);
497
498 if (!$scores[$new_score]) $scores[$new_score] = array();
499
500 array_push($scores[$new_score], $line['ref_id']);
501 }
502
503 foreach (array_keys($scores) as $s) {
504 if ($s > 1000) {
505 db_query($link, "UPDATE ttrss_user_entries SET score = '$s',
506 marked = true WHERE
507 ref_id IN (" . join(',', $scores[$s]) . ")");
508 } else {
509 db_query($link, "UPDATE ttrss_user_entries SET score = '$s' WHERE
510 ref_id IN (" . join(',', $scores[$s]) . ")");
511 }
512 }
513 }
514
515 print __("All done.");
516
517 }
518
ef8be8ea
AD
519 if ($subop == "add") {
520
521 if (!WEB_DEMO_MODE) {
522
f27de515
AD
523 $feed_url = db_escape_string(trim($_REQUEST["feed_url"]));
524 $cat_id = db_escape_string($_REQUEST["cat_id"]);
525 $p_from = db_escape_string($_REQUEST["from"]);
526
527 /* only read authentication information from POST */
528
529 $auth_login = db_escape_string(trim($_POST["auth_login"]));
530 $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
aa2122d4 531
e513a74a 532 if ($p_from != 'tt-rss') {
aa2122d4
AD
533 print "<html>
534 <head>
535 <title>Tiny Tiny RSS - Subscribe to feed...</title>
536 <link rel=\"stylesheet\" type=\"text/css\" href=\"quicksub.css\">
537 </head>
538 <body>
539 <img class=\"logo\" src=\"images/ttrss_logo.png\"
540 alt=\"Tiny Tiny RSS\"/>
e513a74a
AD
541 <h1>Subscribe to feed...</h1>
542 <div class=\"content\">";
aa2122d4 543 }
ef8be8ea 544
f27de515 545 if (subscribe_to_feed($link, $feed_url, $cat_id, $auth_login, $auth_pass)) {
4dccf1ed 546 print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
ef8be8ea 547 } else {
4dccf1ed 548 print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
ef8be8ea 549 }
aa2122d4 550
e513a74a 551 if ($p_from != 'tt-rss') {
d70c5ae4 552 $tt_uri = ($_SERVER['HTTPS'] != "on" ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . preg_replace('/backend\.php.*$/', 'tt-rss.php', $_SERVER["REQUEST_URI"]);
aa2122d4 553
d70c5ae4
AD
554
555 $tp_uri = ($_SERVER['HTTPS'] != "on" ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . preg_replace('/backend\.php.*$/', 'prefs.php', $_SERVER["REQUEST_URI"]);
e513a74a
AD
556
557 print "<p><a href='$tt_uri'>Return to Tiny Tiny RSS</a> |";
558
559 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
560 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
561
562 $feed_id = db_fetch_result($result, 0, "id");
563
564 if ($feed_id) {
565 print "<a href='$tp_uri?tab=feedConfig&subop=editFeed:$feed_id'>
566 Edit subscription options</a> | ";
567 }
568
569 print "<a href='javascript:window.close()'>Close this window</a>.</p>";
aa2122d4 570
e513a74a 571 print "</div></body></html>";
aa2122d4
AD
572 return;
573 }
442d77f1 574
ef8be8ea
AD
575 }
576 }
577
ef8be8ea
AD
578 if ($subop == "categorize") {
579
580 if (!WEB_DEMO_MODE) {
581
582 $ids = split(",", db_escape_string($_GET["ids"]));
583
584 $cat_id = db_escape_string($_GET["cat_id"]);
585
586 if ($cat_id == 0) {
587 $cat_id_qpart = 'NULL';
588 } else {
589 $cat_id_qpart = "'$cat_id'";
590 }
591
592 db_query($link, "BEGIN");
593
594 foreach ($ids as $id) {
595
596 db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
597 WHERE id = '$id' AND parent_feed IS NULL
598 AND owner_uid = " . $_SESSION["uid"]);
599
600 # update linked feed categories
601 db_query($link, "UPDATE ttrss_feeds SET
602 cat_id = $cat_id_qpart WHERE parent_feed = '$id' AND
603 owner_uid = " . $_SESSION["uid"]);
604
605 }
606
607 db_query($link, "COMMIT");
608 }
609
610 }
611
9c483746
AD
612 if ($subop == "editCats") {
613
9c483746
AD
614 $action = $_REQUEST["action"];
615
616 if ($action == "save") {
617
11f083e7
AD
618 $cat_title = db_escape_string(trim($_REQUEST["value"]));
619 $cat_id = db_escape_string($_GET["cid"]);
9c483746
AD
620
621 $result = db_query($link, "UPDATE ttrss_feed_categories SET
622 title = '$cat_title' WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
11f083e7
AD
623
624 print $_REQUEST["value"];
625
626 return;
627
9c483746
AD
628 }
629
11f083e7
AD
630 print "<div id=\"infoBoxTitle\">".__('Category editor')."</div>";
631
632 print "<div class=\"infoBoxContents\">";
633
634
9c483746
AD
635 if ($action == "add") {
636
637 if (!WEB_DEMO_MODE) {
638
639 $feed_cat = db_escape_string(trim($_GET["cat"]));
640
641 $result = db_query($link,
642 "SELECT id FROM ttrss_feed_categories
643 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
644
645 if (db_num_rows($result) == 0) {
646
647 $result = db_query($link,
648 "INSERT INTO ttrss_feed_categories (owner_uid,title)
649 VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
650
651 } else {
652
4dccf1ed
AD
653 print_warning(T_sprintf("Category <b>$%s</b> already exists in the database.",
654 $feed_cat));
9c483746
AD
655 }
656
657 }
658 }
659
660 if ($action == "remove") {
661
662 if (!WEB_DEMO_MODE) {
663
664 $ids = split(",", db_escape_string($_GET["ids"]));
665
666 foreach ($ids as $id) {
667
668 db_query($link, "BEGIN");
669
670 $result = db_query($link,
671 "SELECT count(id) as num_feeds FROM ttrss_feeds
672 WHERE cat_id = '$id'");
673
674 $num_feeds = db_fetch_result($result, 0, "num_feeds");
675
676 if ($num_feeds == 0) {
677 db_query($link, "DELETE FROM ttrss_feed_categories
678 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
679 } else {
680
31cc42f6 681 print format_warning(__("Unable to delete non empty feed categories."));
9c483746
AD
682
683 }
684
685 db_query($link, "COMMIT");
686 }
687 }
688 }
689
690 print "<div class=\"prefGenericAddBox\">
691 <input id=\"fadd_cat\"
1043a8c3 692 onkeypress=\"return filterCR(event, addFeedCat)\"
9c483746 693 onkeyup=\"toggleSubmitNotEmpty(this, 'catadd_submit_btn')\"
b5015f72 694 onchange=\"toggleSubmitNotEmpty(this, 'catadd_submit_btn')\"
9c483746
AD
695 size=\"40\">&nbsp;
696 <input
697 type=\"submit\" class=\"button\" disabled=\"true\" id=\"catadd_submit_btn\"
31cc42f6 698 onclick=\"javascript:addFeedCat()\" value=\"".__('Create category')."\"></div>";
9c483746
AD
699
700 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
701 WHERE owner_uid = ".$_SESSION["uid"]."
702 ORDER BY title");
703
704 print "<p>";
705
706 if (db_num_rows($result) != 0) {
707
708 print "<table width=\"100%\" class=\"prefFeedCatList\"
709 cellspacing=\"0\">";
710
711 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
e8d0177d
AD
712 ".__('Select:')."
713 <a href=\"javascript:selectPrefRows('fcat', true)\">".__('All')."</a>,
714 <a href=\"javascript:selectPrefRows('fcat', false)\">".__('None')."</a>
9c483746
AD
715 </td></tr>";
716
717 print "</table>";
718
719 print "<div class=\"prefFeedCatHolder\">";
720
e6312f6c 721 print "<form id=\"feed_cat_edit_form\" onsubmit=\"return false\">";
9c483746
AD
722
723 print "<table width=\"100%\" class=\"prefFeedCatList\"
724 cellspacing=\"0\" id=\"prefFeedCatList\">";
9c483746
AD
725
726 $lnum = 0;
727
728 while ($line = db_fetch_assoc($result)) {
729
730 $class = ($lnum % 2) ? "even" : "odd";
731
732 $cat_id = $line["id"];
11f083e7 733 $this_row_id = "id=\"FCATR-$cat_id\"";
9c483746
AD
734
735 print "<tr class=\"$class\" $this_row_id>";
736
47439031 737 $edit_title = htmlspecialchars($line["title"]);
9c483746 738
11f083e7
AD
739 print "<td width='5%' align='center'><input
740 onclick='toggleSelectPrefRow(this, \"fcat\");'
741 type=\"checkbox\" id=\"FCCHK-$cat_id\"></td>";
742
743 print "<td><span id=\"FCATT-$cat_id\">" .
744 $edit_title . "</span></td>";
9c483746
AD
745
746 print "</tr>";
747
748 ++$lnum;
749 }
750
751 print "</table>";
752
753 print "</form>";
754
755 print "</div>";
756
6f5b1e04 757 } else {
31cc42f6 758 print "<p>".__('No feed categories defined.')."</p>";
6f5b1e04 759 }
9c483746 760
6f5b1e04
AD
761 print "<div style='float : right'>
762 <input type='submit' class='button'
31cc42f6 763 onclick=\"selectTab('feedConfig')\" value=\"".__('Close this window')."\"></div>";
9c483746 764
6f5b1e04 765 print "<div id=\"catOpToolbar\">";
9c483746 766
11f083e7 767 print "
6f5b1e04 768 <input type=\"submit\" class=\"button\" disabled=\"true\"
31cc42f6 769 onclick=\"return removeSelectedFeedCats()\" value=\"".__('Remove')."\">";
11f083e7 770
9c483746
AD
771 print "</div>";
772
6f5b1e04
AD
773 print "</div>";
774
9c483746
AD
775 return;
776
777 }
778
ef8be8ea
AD
779 if ($quiet) return;
780
442d77f1
AD
781 set_pref($link, "_PREFS_ACTIVE_TAB", "feedConfig");
782
a3656a41 783 $result = db_query($link, "SELECT COUNT(id) AS num_errors
ef8be8ea
AD
784 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
785
a3656a41 786 $num_errors = db_fetch_result($result, 0, "num_errors");
ef8be8ea 787
a3656a41 788 if ($num_errors > 0) {
ef8be8ea 789
31cc42f6
AD
790 print format_notice("<a href=\"javascript:showFeedsWithErrors()\">".
791 __('Some feeds have update errors (click for details)')."</a>");
ef8be8ea
AD
792 }
793
794 $feed_search = db_escape_string($_GET["search"]);
795
796 if (array_key_exists("search", $_GET)) {
797 $_SESSION["prefs_feed_search"] = $feed_search;
798 } else {
799 $feed_search = $_SESSION["prefs_feed_search"];
800 }
801
802 print "<div class=\"feedEditSearch\">
3dc8ee84 803 <input id=\"feed_search\" size=\"20\" type=\"search\"
ef8be8ea
AD
804 onchange=\"javascript:updateFeedList()\" value=\"$feed_search\">
805 <input type=\"submit\" class=\"button\"
a3c159c4 806 onclick=\"javascript:updateFeedList()\" value=\"".__('Search')."\">
ef8be8ea 807 </div>";
5e6f933a 808
442d77f1 809/* print "<input id=\"fadd_link\"
ef8be8ea 810 onkeyup=\"toggleSubmitNotEmpty(this, 'fadd_submit_btn')\"
b5015f72 811 onchange=\"toggleSubmitNotEmpty(this, 'fadd_submit_btn')\"
ef8be8ea
AD
812 size=\"40\">
813 <input type=\"submit\" class=\"button\"
814 disabled=\"true\" id=\"fadd_submit_btn\"
442d77f1
AD
815 onclick=\"addFeed()\" value=\"".__('Subscribe')."\">"; */
816
817 print "<input onclick=\"javascript:displayDlg('quickAddFeed')\"
a349077c 818 type=\"submit\" id=\"subscribe_to_feed_btn\"
442d77f1 819 class=\"button\" value=\"".__('Subscribe to feed')."\">";
ef8be8ea
AD
820
821 if (ENABLE_FEED_BROWSER && !SINGLE_USER_MODE) {
822 print " <input type=\"submit\" class=\"button\"
a349077c 823 id=\"top25_feeds_btn\"
a3c159c4 824 onclick=\"javascript:browseFeeds()\" value=\"".__('Top 25')."\">";
ef8be8ea
AD
825 }
826
ef8be8ea
AD
827 $feeds_sort = db_escape_string($_GET["sort"]);
828
829 if (!$feeds_sort || $feeds_sort == "undefined") {
830 $feeds_sort = $_SESSION["pref_sort_feeds"];
831 if (!$feeds_sort) $feeds_sort = "title";
832 }
833
834 $_SESSION["pref_sort_feeds"] = $feeds_sort;
835
836 if ($feed_search) {
837 $search_qpart = "(UPPER(F1.title) LIKE UPPER('%$feed_search%') OR
838 UPPER(F1.feed_url) LIKE UPPER('%$feed_search%')) AND";
839 } else {
840 $search_qpart = "";
841 }
842
400b60d8
AD
843 $show_last_article_info = false;
844 $show_last_article_checked = "";
845 $show_last_article_qpart = "";
846
847 if ($_GET["slat"] == "true") {
848 $show_last_article_info = true;
849 $show_last_article_checked = "checked";
fc2b26a6 850 $show_last_article_qpart = ", (SELECT ".SUBSTRING_FOR_DATE."(MAX(updated),1,16) FROM ttrss_user_entries,
400b60d8
AD
851 ttrss_entries WHERE ref_id = ttrss_entries.id
852 AND feed_id = F1.id) AS last_article";
d2ca9130
AD
853 } else if ($feeds_sort == "last_article") {
854 $feeds_sort = "title";
855 }
856
857 if (get_pref($link, 'ENABLE_FEED_CATS')) {
858 $order_by_qpart = "category,$feeds_sort,title";
859 } else {
860 $order_by_qpart = "$feeds_sort,title";
400b60d8
AD
861 }
862
ef8be8ea
AD
863 $result = db_query($link, "SELECT
864 F1.id,
865 F1.title,
866 F1.feed_url,
2ac6b765 867 ".SUBSTRING_FOR_DATE."(F1.last_updated,1,16) AS last_updated,
ef8be8ea
AD
868 F1.parent_feed,
869 F1.update_interval,
365f95dc 870 F1.last_error,
ef8be8ea
AD
871 F1.purge_interval,
872 F1.cat_id,
873 F2.title AS parent_title,
874 C1.title AS category,
875 F1.hidden,
400b60d8
AD
876 F1.include_in_digest
877 $show_last_article_qpart
ef8be8ea
AD
878 FROM
879 ttrss_feeds AS F1
880 LEFT JOIN ttrss_feeds AS F2
881 ON (F1.parent_feed = F2.id)
882 LEFT JOIN ttrss_feed_categories AS C1
883 ON (F1.cat_id = C1.id)
884 WHERE
885 $search_qpart F1.owner_uid = '".$_SESSION["uid"]."'
886 ORDER by $order_by_qpart");
887
888 if (db_num_rows($result) != 0) {
889
890// print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
891
892 print "<p><table width=\"100%\" cellspacing=\"0\"
893 class=\"prefFeedList\" id=\"prefFeedList\">";
400b60d8
AD
894 print "<tr><td class=\"selectPrompt\" colspan=\"8\">".
895 "<div style='float : right'>".
896 "<input id='show_last_article_times' type='checkbox' onchange='feedlistToggleSLAT()'
897 $show_last_article_checked><label
898 for='show_last_article_times'>".__('Show last article times')."</label></div>".
899 __('Select:')."
e8d0177d
AD
900 <a href=\"javascript:selectPrefRows('feed', true)\">".__('All')."</a>,
901 <a href=\"javascript:selectPrefRows('feed', false)\">".__('None')."</a>
ef8be8ea
AD
902 </td</tr>";
903
904 if (!get_pref($link, 'ENABLE_FEED_CATS')) {
905 print "<tr class=\"title\">
906 <td width='5%' align='center'>&nbsp;</td>";
907
908 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
909 print "<td width='3%'>&nbsp;</td>";
910 }
911
c4b0f96c
AD
912 print "<td width='60%'><a href=\"javascript:updateFeedList('title')\">".__('Title')."</a></td>";
913
914 if ($show_last_article_info) {
915 print "<td width='20%' align='right'><a href=\"javascript:updateFeedList('last_article')\">".__('Last&nbsp;Article')."</a></td>";
916 }
917
918 print "<td width='20%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">".__('Updated')."</a></td>";
ef8be8ea
AD
919 }
920
921 $lnum = 0;
922
923 $cur_cat_id = -1;
924
925 while ($line = db_fetch_assoc($result)) {
926
927 $feed_id = $line["id"];
928 $cat_id = $line["cat_id"];
929
47439031
AD
930 $edit_title = htmlspecialchars($line["title"]);
931 $edit_cat = htmlspecialchars($line["category"]);
ef8be8ea
AD
932
933 $hidden = sql_bool_to_bool($line["hidden"]);
934
365f95dc
AD
935 $last_error = $line["last_error"];
936
3692e98f 937 if (!$edit_cat) $edit_cat = __("Uncategorized");
ef8be8ea
AD
938
939 $last_updated = $line["last_updated"];
940
7a74abd5
AD
941 if (!$last_updated) {
942 $last_updated = "&mdash;";
943 } else if (get_pref($link, 'HEADLINES_SMART_DATE')) {
ef8be8ea
AD
944 $last_updated = smart_date_time(strtotime($last_updated));
945 } else {
946 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
947 $last_updated = date($short_date, strtotime($last_updated));
948 }
949
950 $last_article = $line["last_article"];
951
7a74abd5
AD
952 if (!$last_article) {
953 $last_article = "&mdash;";
954 } else if (get_pref($link, 'HEADLINES_SMART_DATE')) {
ef8be8ea
AD
955 $last_article = smart_date_time(strtotime($last_article));
956 } else {
957 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
958 $last_article = date($short_date, strtotime($last_article));
959 }
960
961 if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) {
962 $lnum = 0;
963
964 print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>";
965
966 print "<tr class=\"title\">
967 <td width='5%'>&nbsp;</td>";
968
969 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
970 print "<td width='3%'>&nbsp;</td>";
971 }
972
400b60d8
AD
973 print "<td width='60%'><a href=\"javascript:updateFeedList('title')\">".__('Title')."</a></td>";
974
975 if ($show_last_article_info) {
976 print "<td width='20%' align='right'>
977 <a href=\"javascript:updateFeedList('last_article')\">".__('Last&nbsp;Article')."</a></td>";
978 }
979
980 print "<td width='20%' align='right'>
981 <a href=\"javascript:updateFeedList('last_updated')\">".__('Updated')."</a></td>";
ef8be8ea
AD
982
983 $cur_cat_id = $cat_id;
984 }
985
986 $class = ($lnum % 2) ? "even" : "odd";
987 $this_row_id = "id=\"FEEDR-$feed_id\"";
988
989 print "<tr class=\"$class\" $this_row_id>";
990
991 $icon_file = ICONS_DIR . "/$feed_id.ico";
992
993 if (file_exists($icon_file) && filesize($icon_file) > 0) {
994 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . "/$feed_id.ico\">";
995 } else {
996 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
997 }
998
999 print "<td class='feedSelect'><input onclick='toggleSelectPrefRow(this, \"feed\");'
1000 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
1001
1002 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
1003 print "<td class='feedIcon'>$feed_icon</td>";
1004 }
1005
ef8be8ea
AD
1006 if ($hidden) {
1007 $edit_title = "<span class=\"insensitive\">$edit_title (Hidden)</span>";
ef8be8ea
AD
1008 $last_updated = "<span class=\"insensitive\">$last_updated</span>";
1009 $last_article = "<span class=\"insensitive\">$last_article</span>";
365f95dc
AD
1010 }
1011
1012 if ($last_error) {
1fc77c25 1013 $edit_title = "<span class=\"feed_error\">$edit_title</span>";
365f95dc
AD
1014 $last_updated = "<span class=\"feed_error\">$last_updated</span>";
1015 $last_article = "<span class=\"feed_error\">$last_article</span>";
ef8be8ea
AD
1016 }
1017
1018 $parent_title = $line["parent_title"];
1019 if ($parent_title) {
1020 $parent_title = "<span class='groupPrompt'>(linked to
1021 $parent_title)</span>";
1022 }
1023
1024 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1025 "$edit_title $parent_title" . "</a></td>";
ef8be8ea 1026
400b60d8
AD
1027 if ($show_last_article_info) {
1028 print "<td align='right'><a href=\"javascript:editFeed($feed_id);\">" .
1029 "$last_article</a></td>";
1030 }
ef8be8ea
AD
1031
1032 print "<td align='right'><a href=\"javascript:editFeed($feed_id);\">" .
1033 "$last_updated</a></td>";
1034
1035 print "</tr>";
1036
1037 ++$lnum;
1038 }
1039
1040 print "</table>";
1041
e88a65f4 1042 print "<p>";
c4a36709 1043
19d96beb
AD
1044 print "<div id=\"feedOpToolbar\">";
1045
1046 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1047
1048 print __('Selection:') . " ";
1049
1050 print_feed_cat_select($link, "sfeed_set_fcat", "", "disabled");
1051
1052 print " <input type=\"submit\" class=\"button\" disabled=\"true\"
1053 onclick=\"javascript:categorizeSelectedFeeds()\" value=\"".
1054 __('Recategorize')."\">";
1055 }
1056
1057 print "</div>";
1058
c4a36709
AD
1059 print "<select id=\"feedActionChooser\" onchange=\"feedActionChange()\">
1060 <option value=\"facDefault\" selected>".__('Actions...')."</option>
1061 <option disabled>--------</option>
1062 <option style=\"color : #5050aa\" disabled>".__('Selection:')."</option>
1063 <option value=\"facEdit\">&nbsp;&nbsp;".__('Edit')."</option>
e88a65f4 1064 <option value=\"facPurge\">&nbsp;&nbsp;".__('Manual purge')."</option>
c4a36709 1065 <option value=\"facClear\">&nbsp;&nbsp;".__('Clear feed data')."</option>
fee840fb 1066 <option value=\"facRescore\">&nbsp;&nbsp;".__('Rescore articles')."</option>
c4a36709
AD
1067 <option value=\"facUnsubscribe\">&nbsp;&nbsp;".__('Unsubscribe')."</option>";
1068
1069 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1070
1071 print "<option disabled>--------</option>
1072 <option style=\"color : #5050aa\" disabled>".__('Other:')."</option>
1073 <option value=\"facEditCats\">&nbsp;&nbsp;".__('Edit categories')."
1074 </option>";
1075 }
1076
19d96beb 1077 print "</select>";
e88a65f4 1078
c4a36709 1079 /* print "<input type=\"submit\" class=\"button\" disabled=\"true\"
a3c159c4
AD
1080 onclick=\"javascript:editSelectedFeed()\" value=\"".__('Edit')."\">
1081 <input type=\"submit\" class=\"button\" disabled=\"true\"
1082 onclick=\"javascript:removeSelectedFeeds()\"
c4a36709 1083 value=\"".__('Unsubscribe')."\">"; */
ef8be8ea 1084
e88a65f4 1085// if (get_pref($link, 'ENABLE_FEED_CATS')) {
9c483746 1086
c4a36709 1087/* print " <input type=\"submit\" class=\"button\"
3692e98f 1088 onclick=\"javascript:editFeedCats()\" value=\"".
c4a36709 1089 __("Edit categories")."\">"; */
9c483746 1090
a3c159c4 1091# print "&nbsp;|&nbsp;";
9c483746 1092
e88a65f4 1093// }
ef8be8ea
AD
1094 } else {
1095
6f5b1e04 1096// print "<p>No feeds defined.</p>";
ef8be8ea
AD
1097
1098 }
1099
a3c159c4 1100 print "<h3>".__('OPML')."</h3>
94a4ba88
AD
1101
1102 <div style='float : left'>
ef8be8ea 1103 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
999703d1
AD
1104 ".__('File:')." <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
1105 <input type=\"hidden\" name=\"op\" value=\"Import\">
1106 <input class=\"button\" onclick=\"return validateOpmlImport();\"
a3c159c4 1107 type=\"submit\" value=\"".__('Import')."\">
94a4ba88
AD
1108 </form></div>";
1109
3692e98f 1110 print "&nbsp;";
94a4ba88
AD
1111
1112 print "<input type=\"submit\"
1113 class=\"button\" onclick=\"gotoExportOpml()\"
a3c159c4 1114 value=\"".__('Export OPML')."\">";
94a4ba88 1115
e4f4b46f 1116
755a43ee
AD
1117 print "<h3>" . __("Firefox Integration") . "</h3>";
1118
1119 print "<p>" . __('This Tiny Tiny RSS site can be used as a Firefox Feed Reader by clicking the link below.');
e635d56a 1120 print "</p><p> <a class='visibleLink' href='javascript:window.navigator.registerContentHandler(" .
755a43ee
AD
1121 "\"application/vnd.mozilla.maybe.feed\", " .
1122 "\"" . add_feed_url() . "\", " . " \"Tiny Tiny RSS\")'>" .
1123 __('Click here to register this site as a feed reader.') . "</a></p>";
1124
1125
e400230e 1126 print "<h3>".__("Published articles")."</h3>";
e4f4b46f
AD
1127
1128 if (!get_pref($link, "_PREFS_PUBLISH_KEY")) {
1129 set_pref($link, "_PREFS_PUBLISH_KEY", generate_publish_key());
1130 }
1131
e635d56a 1132 print "<p>".__('Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the URL specified below.')."</p>";
e4f4b46f 1133
f56e3080 1134 $url_path = article_publish_url($link);
e4f4b46f 1135
e635d56a 1136 print "<p><a class=\"visibleLink\" id=\"pubGenAddress\" target=\"_new\" href=\"$url_path\">Link to published articles feed.</a></p>";
e4f4b46f 1137
8a8f7c55 1138 print "<p><input type=\"submit\" onclick=\"return pubRegenKey()\" class=\"button\"
e635d56a
AD
1139 value=\"".__('Generate another link')."\">";
1140 /* print " <input type=\"submit\" onclick=\"return pubToClipboard()\" class=\"button\"
1141 value=\"".__('Copy link to clipboard')."\">"; */
1142 print "</p>";
e4f4b46f 1143
ef8be8ea
AD
1144 }
1145?>