]> git.wh0rd.org - tt-rss.git/blame - modules/pref-feeds.php
code cleanup; remove unnecessary callbacks; rework subscribtion dialog
[tt-rss.git] / modules / pref-feeds.php
CommitLineData
ef8be8ea 1<?php
d20f3544 2
758e1c4a 3 function batch_edit_cbox($elem, $label = false) {
cd935c42 4 print "<input type=\"checkbox\" title=\"".__("Check to enable field")."\"
758e1c4a
AD
5 onchange=\"batchFeedsToggleField(this, '$elem', '$label')\">";
6 }
7
ef8be8ea
AD
8 function module_pref_feeds($link) {
9
d20f3544
AD
10 global $update_intervals;
11 global $purge_intervals;
16211ddb 12 global $update_methods;
d20f3544 13
ef8be8ea
AD
14 $subop = $_REQUEST["subop"];
15 $quiet = $_REQUEST["quiet"];
082ae95b 16 $mode = $_REQUEST["mode"];
ef8be8ea
AD
17
18 if ($subop == "massSubscribe") {
b4e75b2a 19 $ids = split(",", db_escape_string($_REQUEST["ids"]));
ef8be8ea
AD
20
21 $subscribed = array();
22
23 foreach ($ids as $id) {
ef8be8ea 24
082ae95b
AD
25 if ($mode == 1) {
26 $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds
27 WHERE id = '$id'");
28 } else if ($mode == 2) {
47030945 29 $result = db_query($link, "SELECT * FROM ttrss_archived_feeds
082ae95b
AD
30 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
31 $orig_id = db_escape_string(db_fetch_result($result, 0, "id"));
47030945 32 $site_url = db_escape_string(db_fetch_result($result, 0, "site_url"));
082ae95b
AD
33 }
34
ef8be8ea
AD
35 $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url"));
36 $title = db_escape_string(db_fetch_result($result, 0, "title"));
082ae95b 37
ef8be8ea 38 $title_orig = db_fetch_result($result, 0, "title");
082ae95b 39
ef8be8ea 40 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
082ae95b
AD
41 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
42
ef8be8ea 43 if (db_num_rows($result) == 0) {
082ae95b
AD
44 if ($mode == 1) {
45 $result = db_query($link,
46 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id)
47 VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)");
48 } else if ($mode == 2) {
49 $result = db_query($link,
47030945
AD
50 "INSERT INTO ttrss_feeds (id,owner_uid,feed_url,title,cat_id,site_url)
51 VALUES ('$orig_id','".$_SESSION["uid"]."', '$feed_url', '$title', NULL, '$site_url')");
082ae95b 52 }
ef8be8ea
AD
53 array_push($subscribed, $title_orig);
54 }
55 }
56
57 if (count($subscribed) > 0) {
31cc42f6 58 $msg = "<b>".__('Subscribed to feeds:')."</b>".
0d32b41e
AD
59 "<ul class=\"nomarks\">";
60
ef8be8ea 61 foreach ($subscribed as $title) {
0d32b41e 62 $msg .= "<li>$title</li>";
ef8be8ea 63 }
0d32b41e
AD
64 $msg .= "</ul>";
65
66 print format_notice($msg);
ef8be8ea
AD
67 }
68 }
69
70 if ($subop == "browse") {
71
b56465dd 72 print "<div id=\"infoBoxTitle\">".__('Feed Browser')."</div>";
ef8be8ea
AD
73
74 print "<div class=\"infoBoxContents\">";
75
b4e75b2a 76 $browser_search = db_escape_string($_REQUEST["search"]);
ef8be8ea 77
b56465dd 78 //print "<p>".__("Showing top 25 registered feeds, sorted by popularity:")."</p>";
c2913898 79
082ae95b
AD
80 print "<form onsubmit='return false;' display='inline' name='feed_browser' id='feed_browser'>";
81
c2913898
AD
82 print "
83 <div style='float : right'>
f4280bdd
AD
84 <img style='display : none'
85 id='feed_browser_spinner' src='images/indicator_white.gif'>
082ae95b 86 <input name=\"search\" size=\"20\" type=\"search\"
577399e8
AD
87 onchange=\"javascript:updateFeedBrowser()\" value=\"$browser_search\">
88 <button onclick=\"javascript:updateFeedBrowser()\">".__('Search')."</button>
c2913898
AD
89 </div>";
90
082ae95b
AD
91 print " <select name=\"mode\" onchange=\"updateFeedBrowser()\">
92 <option value='1'>" . __('Popular feeds') . "</option>
93 <option value='2'>" . __('Feed archive') . "</option>
94 </select> ";
95
96 print __("limit:");
97
577399e8 98 print " <select name=\"limit\" onchange='updateFeedBrowser()'>";
c2913898
AD
99
100 foreach (array(25, 50, 100, 200) as $l) {
101 $issel = ($l == $limit) ? "selected" : "";
102 print "<option $issel>$l</option>";
103 }
104
082ae95b
AD
105 print "</select> ";
106
b56465dd 107 print "<p>";
ef8be8ea 108
b56465dd 109 $owner_uid = $_SESSION["uid"];
ef8be8ea 110
b56465dd 111 print "<ul class='browseFeedList' id='browseFeedList'>";
f88c7814 112 print_feed_browser($link, $search, 25);
ef8be8ea
AD
113 print "</ul>";
114
115 print "<div align='center'>
f88c7814
AD
116 <button onclick=\"feedBrowserSubscribe()\">".__('Subscribe')."</button>
117 <button onclick=\"closeInfoBox()\" >".__('Cancel')."</button></div>";
ef8be8ea
AD
118
119 print "</div>";
120 return;
121 }
122
123 if ($subop == "editfeed") {
124 $feed_id = db_escape_string($_REQUEST["id"]);
125
126 $result = db_query($link,
127 "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND
128 owner_uid = " . $_SESSION["uid"]);
129
47439031
AD
130 $title = htmlspecialchars(db_fetch_result($result,
131 0, "title"));
ef8be8ea
AD
132
133 $icon_file = ICONS_DIR . "/$feed_id.ico";
134
135 if (file_exists($icon_file) && filesize($icon_file) > 0) {
136 $feed_icon = "<img width=\"16\" height=\"16\"
137 src=\"" . ICONS_URL . "/$feed_id.ico\">";
138 } else {
139 $feed_icon = "";
140 }
141
ecace165 142 print "<div id=\"infoBoxTitle\">".__('Feed Editor')."</div>";
ef8be8ea
AD
143
144 print "<div class=\"infoBoxContents\">";
145
e6312f6c 146 print "<form id=\"edit_feed_form\" onsubmit=\"return false\">";
ef8be8ea
AD
147
148 print "<input type=\"hidden\" name=\"id\" value=\"$feed_id\">";
149 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
150 print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
151
ecace165
AD
152 print "<div class=\"dlgSec\">".__("Feed")."</div>";
153 print "<div class=\"dlgSecCont\">";
ef8be8ea 154
ecace165
AD
155 /* Title */
156
157 print "<input style=\"font-size : 16px\" size=\"40\" onkeypress=\"return filterCR(event, feedEditSave)\"
158 name=\"title\" value=\"$title\">";
159
160 /* Feed URL */
ef8be8ea
AD
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"));
ecace165
AD
165
166 print "<br/>";
167
168 print __('URL:') . " ";
169 print "<input size=\"40\" onkeypress=\"return filterCR(event, feedEditSave)\"
170 name=\"feed_url\" value=\"$feed_url\">";
171
172 /* Category */
ef8be8ea
AD
173
174 if (get_pref($link, 'ENABLE_FEED_CATS')) {
175
176 $cat_id = db_fetch_result($result, 0, "cat_id");
177
ecace165
AD
178 print "<br/>";
179
180 print __('Place in category:') . " ";
ef8be8ea
AD
181
182 $parent_feed = db_fetch_result($result, 0, "parent_feed");
183
184 if (sprintf("%d", $parent_feed) > 0) {
185 $disabled = "disabled";
186 } else {
187 $disabled = "";
188 }
189
ecace165 190 print_feed_cat_select($link, "cat_id", $cat_id, $disabled);
ef8be8ea
AD
191 }
192
ecace165 193 /* Link to */
ef8be8ea 194
ecace165 195 print "<br/>";
ef8be8ea 196
ecace165 197 print __('Link to feed:') . " ";
ef8be8ea
AD
198
199 $tmp_result = db_query($link, "SELECT COUNT(id) AS count
200 FROM ttrss_feeds WHERE parent_feed = '$feed_id'");
201
202 $linked_count = db_fetch_result($tmp_result, 0, "count");
203
204 $parent_feed = db_fetch_result($result, 0, "parent_feed");
205
206 if ($linked_count > 0) {
207 $disabled = "disabled";
208 } else {
209 $disabled = "";
210 }
211
ecace165 212 print "<select $disabled name=\"parent_feed\">";
ef8be8ea 213
31cc42f6 214 print "<option value=\"0\">".__('Not linked')."</option>";
ef8be8ea
AD
215
216 if (get_pref($link, 'ENABLE_FEED_CATS')) {
217 if ($cat_id) {
218 $cat_qpart = "AND cat_id = '$cat_id'";
219 } else {
220 $cat_qpart = "AND cat_id IS NULL";
221 }
222 }
223
224 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
225 WHERE id != '$feed_id' AND owner_uid = ".$_SESSION["uid"]." AND
226 (SELECT COUNT(id) FROM ttrss_feeds AS T2 WHERE T2.id = ttrss_feeds.parent_feed) = 0
227 $cat_qpart ORDER BY title");
228
229 if (db_num_rows($tmp_result) > 0) {
230 print "<option disabled>--------</option>";
231 }
232
233 while ($tmp_line = db_fetch_assoc($tmp_result)) {
234 if ($tmp_line["id"] == $parent_feed) {
235 $is_selected = "selected";
236 } else {
237 $is_selected = "";
238 }
a6c78e0a 239
c8358b5b 240 $linked_title = truncate_string(htmlspecialchars($tmp_line["title"]), 40);
a6c78e0a 241
ef8be8ea 242 printf("<option $is_selected value='%d'>%s</option>",
c8358b5b 243 $tmp_line["id"], $linked_title);
ef8be8ea
AD
244 }
245
246 print "</select>";
ef8be8ea 247
ef8be8ea 248
ecace165 249 print "</div>";
ef8be8ea 250
e6bf0f4b 251 print "<div class=\"dlgSec\">".__("Update")."</div>";
ecace165 252 print "<div class=\"dlgSecCont\">";
ef8be8ea 253
ecace165 254 /* Update Interval */
ef8be8ea 255
ecace165
AD
256 $update_interval = db_fetch_result($result, 0, "update_interval");
257
258 print_select_hash("update_interval", $update_interval, $update_intervals);
16211ddb 259
ecace165
AD
260 /* Update method */
261
262 if (ALLOW_SELECT_UPDATE_METHOD) {
34459667 263 $update_method = db_fetch_result($result, 0, "update_method");
ecace165
AD
264
265 print " " . __('using') . " ";
266 print_select_hash("update_method", $update_method, $update_methods);
34459667 267 }
16211ddb 268
22c1bc60
AD
269 $purge_interval = db_fetch_result($result, 0, "purge_interval");
270
3907ef71 271 if (FORCE_ARTICLE_PURGE == 0) {
ecace165 272
3907ef71
AD
273 /* Purge intl */
274
275 print "<br/>";
276
3907ef71 277 print __('Article purging:') . " ";
ecace165 278
3907ef71 279 print_select_hash("purge_interval", $purge_interval, $purge_intervals);
ecace165 280
22c1bc60
AD
281 } else {
282 print "<input type='hidden' name='purge_interval' value='$purge_interval'>";
283
3907ef71 284 }
ecace165
AD
285
286 print "</div>";
287 print "<div class=\"dlgSec\">".__("Authentication")."</div>";
288 print "<div class=\"dlgSecCont\">";
289
47439031 290 $auth_login = htmlspecialchars(db_fetch_result($result, 0, "auth_login"));
ef8be8ea 291
d616904c
AD
292 print "<table>";
293
294 print "<tr><td>" . __('Login:') . "</td><td>";
295
ecace165
AD
296 print "<input size=\"20\" onkeypress=\"return filterCR(event, feedEditSave)\"
297 name=\"auth_login\" value=\"$auth_login\">";
298
d616904c 299 print "</tr><tr><td>" . __("Password:") . "</td><td>";
ef8be8ea 300
47439031 301 $auth_pass = htmlspecialchars(db_fetch_result($result, 0, "auth_pass"));
ef8be8ea 302
ecace165 303 print "<input size=\"20\" type=\"password\" name=\"auth_pass\"
ef8be8ea 304 onkeypress=\"return filterCR(event, feedEditSave)\"
ecace165 305 value=\"$auth_pass\">";
ef8be8ea 306
d616904c
AD
307 print "</td></tr></table>";
308
ecace165
AD
309 print "</div>";
310 print "<div class=\"dlgSec\">".__("Options")."</div>";
311 print "<div class=\"dlgSecCont\">";
ef8be8ea 312
ecace165 313 print "<div style=\"line-height : 100%\">";
ef8be8ea 314
886d4bce
AD
315 $private = sql_bool_to_bool(db_fetch_result($result, 0, "private"));
316
317 if ($private) {
318 $checked = "checked";
319 } else {
320 $checked = "";
321 }
322
ecace165 323 print "<input type=\"checkbox\" name=\"private\" id=\"private\"
117335bf 324 $checked>&nbsp;<label for=\"private\">".__('Hide from Popular feeds')."</label>";
ef8be8ea
AD
325
326 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
327
328 if ($rtl_content) {
329 $checked = "checked";
330 } else {
331 $checked = "";
332 }
333
ecace165
AD
334 print "<br/><input type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"
335 $checked>&nbsp;<label for=\"rtl_content\">".__('Right-to-left content')."</label>";
ef8be8ea 336
ef8be8ea
AD
337 $include_in_digest = sql_bool_to_bool(db_fetch_result($result, 0, "include_in_digest"));
338
339 if ($include_in_digest) {
340 $checked = "checked";
341 } else {
342 $checked = "";
343 }
344
ecace165 345 print "<br/><input type=\"checkbox\" id=\"include_in_digest\"
ef8be8ea 346 name=\"include_in_digest\"
ecace165 347 $checked>&nbsp;<label for=\"include_in_digest\">".__('Include in e-mail digest')."</label>";
ef8be8ea 348
54e61a68
AD
349
350 $always_display_enclosures = sql_bool_to_bool(db_fetch_result($result, 0, "always_display_enclosures"));
351
352 if ($always_display_enclosures) {
353 $checked = "checked";
354 } else {
355 $checked = "";
356 }
357
358 print "<br/><input type=\"checkbox\" id=\"always_display_enclosures\"
359 name=\"always_display_enclosures\"
360 $checked>&nbsp;<label for=\"always_display_enclosures\">".__('Always display image attachments')."</label>";
361
362
bc0f0785
AD
363 $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
364
365 if ($cache_images) {
366 $checked = "checked";
367 } else {
368 $checked = "";
369 }
370
371 if (ENABLE_SIMPLEPIE && SIMPLEPIE_CACHE_IMAGES) {
372 $disabled = "";
373 $label_class = "";
374 } else {
375 $disabled = "disabled";
376 $label_class = "class='insensitive'";
377 }
378
ecace165 379 print "<br/><input type=\"checkbox\" id=\"cache_images\"
bc0f0785 380 name=\"cache_images\" $disabled
ecace165 381 $checked>&nbsp;<label $label_class for=\"cache_images\">".
bc0f0785
AD
382 __('Cache images locally')."</label>";
383
ef8be8ea 384
ecace165
AD
385 print "</div>";
386 print "</div>";
ef8be8ea
AD
387
388 print "</form>";
389
ddb61e79
AD
390 $title = htmlspecialchars($title, ENT_QUOTES);
391
ecace165 392 print "<div class='dlgButtons'>
143a4973 393 <div style=\"float : left\">
ad491d75
AD
394 <button onclick='return unsubscribeFeed($feed_id, \"$title\")'>".
395 __('Unsubscribe')."</button>
143a4973 396 </div>
ad491d75
AD
397 <button onclick=\"return feedEditSave()\">".__('Save')."</button>
398 <button onclick=\"return feedEditCancel()\">".__('Cancel')."</button>
c8d5dcfe 399 </div>";
ef8be8ea 400
ef8be8ea
AD
401 return;
402 }
403
758e1c4a
AD
404 if ($subop == "editfeeds") {
405
406 $feed_ids = db_escape_string($_REQUEST["ids"]);
407
b0f015a2 408 print "<div id=\"infoBoxTitle\">".__('Multiple Feed Editor')."</div>";
758e1c4a
AD
409
410 print "<div class=\"infoBoxContents\">";
411
758e1c4a
AD
412 print "<form id=\"batch_edit_feed_form\" onsubmit=\"return false\">";
413
414 print "<input type=\"hidden\" name=\"ids\" value=\"$feed_ids\">";
415 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
416 print "<input type=\"hidden\" name=\"subop\" value=\"batchEditSave\">";
417
418 print "<div class=\"dlgSec\">".__("Feed")."</div>";
419 print "<div class=\"dlgSecCont\">";
420
421 /* Title */
422
423 print "<input disabled style=\"font-size : 16px\" size=\"35\" onkeypress=\"return filterCR(event, feedEditSave)\"
424 name=\"title\" value=\"$title\">";
425
426 batch_edit_cbox("title");
427
428 /* Feed URL */
429
430 print "<br/>";
431
432 print __('URL:') . " ";
433 print "<input disabled size=\"40\" onkeypress=\"return filterCR(event, feedEditSave)\"
434 name=\"feed_url\" value=\"$feed_url\">";
435
436 batch_edit_cbox("feed_url");
437
438 /* Category */
439
440 if (get_pref($link, 'ENABLE_FEED_CATS')) {
441
442 print "<br/>";
443
444 print __('Place in category:') . " ";
445
446 print_feed_cat_select($link, "cat_id", $cat_id, "disabled");
447
448 batch_edit_cbox("cat_id");
449
450 }
451
452 print "</div>";
453
454 print "<div class=\"dlgSec\">".__("Update")."</div>";
455 print "<div class=\"dlgSecCont\">";
456
457 /* Update Interval */
458
459 print_select_hash("update_interval", $update_interval, $update_intervals,
460 "disabled");
461
462 batch_edit_cbox("update_interval");
463
464 /* Update method */
465
466 if (ALLOW_SELECT_UPDATE_METHOD) {
467 print " " . __('using') . " ";
468 print_select_hash("update_method", $update_method, $update_methods,
469 "disabled");
470 batch_edit_cbox("update_method");
471 }
472
473 /* Purge intl */
474
3907ef71 475 if (FORCE_ARTICLE_PURGE != 0) {
758e1c4a 476
3907ef71 477 print "<br/>";
758e1c4a 478
3907ef71 479 print __('Article purging:') . " ";
758e1c4a 480
3907ef71
AD
481 print_select_hash("purge_interval", $purge_interval, $purge_intervals,
482 "disabled");
483
484 batch_edit_cbox("purge_interval");
485 }
758e1c4a
AD
486
487 print "</div>";
488 print "<div class=\"dlgSec\">".__("Authentication")."</div>";
489 print "<div class=\"dlgSecCont\">";
490
491 print __('Login:') . " ";
492 print "<input disabled size=\"15\" onkeypress=\"return filterCR(event, feedEditSave)\"
493 name=\"auth_login\" value=\"$auth_login\">";
494
495 batch_edit_cbox("auth_login");
496
497 print " " . __("Password:") . " ";
498
499 print "<input disabled size=\"15\" type=\"password\" name=\"auth_pass\"
500 onkeypress=\"return filterCR(event, feedEditSave)\"
501 value=\"$auth_pass\">";
502
503 batch_edit_cbox("auth_pass");
504
505 print "</div>";
506 print "<div class=\"dlgSec\">".__("Options")."</div>";
507 print "<div class=\"dlgSecCont\">";
508
509 print "<div style=\"line-height : 100%\">";
510
511 print "<input disabled type=\"checkbox\" name=\"private\" id=\"private\"
43f0968e 512 $checked>&nbsp;<label id=\"private_l\" class='insensitive' for=\"private\">".__('Hide from Popular feeds')."</label>";
758e1c4a
AD
513
514 print "&nbsp;"; batch_edit_cbox("private", "private_l");
515
516 print "<br/><input disabled type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"
517 $checked>&nbsp;<label class='insensitive' id=\"rtl_content_l\" for=\"rtl_content\">".__('Right-to-left content')."</label>";
518
519 print "&nbsp;"; batch_edit_cbox("rtl_content", "rtl_content_l");
520
758e1c4a
AD
521 print "<br/><input disabled type=\"checkbox\" id=\"include_in_digest\"
522 name=\"include_in_digest\"
523 $checked>&nbsp;<label id=\"include_in_digest_l\" class='insensitive' for=\"include_in_digest\">".__('Include in e-mail digest')."</label>";
524
525 print "&nbsp;"; batch_edit_cbox("include_in_digest", "include_in_digest_l");
526
c9f185bd
AD
527 print "<br/><input disabled type=\"checkbox\" id=\"always_display_enclosures\"
528 name=\"always_display_enclosures\"
529 $checked>&nbsp;<label id=\"always_display_enclosures_l\" class='insensitive' for=\"always_display_enclosures\">".__('Always display image attachments')."</label>";
530
531 print "&nbsp;"; batch_edit_cbox("always_display_enclosures", "always_display_enclosures_l");
532
758e1c4a
AD
533 print "<br/><input disabled type=\"checkbox\" id=\"cache_images\"
534 name=\"cache_images\"
535 $checked>&nbsp;<label class='insensitive' id=\"cache_images_l\"
536 for=\"cache_images\">".
537 __('Cache images locally')."</label>";
538
539
540 if (ENABLE_SIMPLEPIE && SIMPLEPIE_CACHE_IMAGES) {
541 print "&nbsp;"; batch_edit_cbox("cache_images", "cache_images_l");
542 }
543
544 print "</div>";
545 print "</div>";
546
547 print "</form>";
548
549 print "<div class='dlgButtons'>
550 <input type=\"submit\" class=\"button\"
551 onclick=\"return feedsEditSave()\" value=\"".__('Save')."\">
552 <input type='submit' class='button'
553 onclick=\"return feedEditCancel()\" value=\"".__('Cancel')."\">
554 </div>";
555
556 return;
557 }
558
b0f015a2 559 if ($subop == "editSave" || $subop == "batchEditSave") {
ef8be8ea
AD
560
561 $feed_title = db_escape_string(trim($_POST["title"]));
562 $feed_link = db_escape_string(trim($_POST["feed_url"]));
563 $upd_intl = db_escape_string($_POST["update_interval"]);
564 $purge_intl = db_escape_string($_POST["purge_interval"]);
b0f015a2
AD
565 $feed_id = db_escape_string($_POST["id"]); /* editSave */
566 $feed_ids = db_escape_string($_POST["ids"]); /* batchEditSave */
ef8be8ea
AD
567 $cat_id = db_escape_string($_POST["cat_id"]);
568 $auth_login = db_escape_string(trim($_POST["auth_login"]));
569 $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
570 $parent_feed = db_escape_string($_POST["parent_feed"]);
571 $private = checkbox_to_sql_bool(db_escape_string($_POST["private"]));
572 $rtl_content = checkbox_to_sql_bool(db_escape_string($_POST["rtl_content"]));
ef8be8ea
AD
573 $include_in_digest = checkbox_to_sql_bool(
574 db_escape_string($_POST["include_in_digest"]));
bc0f0785
AD
575 $cache_images = checkbox_to_sql_bool(
576 db_escape_string($_POST["cache_images"]));
16211ddb 577 $update_method = (int) db_escape_string($_POST["update_method"]);
ef8be8ea 578
54e61a68
AD
579 $always_display_enclosures = checkbox_to_sql_bool(
580 db_escape_string($_POST["always_display_enclosures"]));
581
ef8be8ea
AD
582 if (get_pref($link, 'ENABLE_FEED_CATS')) {
583 if ($cat_id && $cat_id != 0) {
584 $category_qpart = "cat_id = '$cat_id',";
585 $category_qpart_nocomma = "cat_id = '$cat_id'";
586 } else {
587 $category_qpart = 'cat_id = NULL,';
588 $category_qpart_nocomma = 'cat_id = NULL';
589 }
590 } else {
591 $category_qpart = "";
592 $category_qpart_nocomma = "";
593 }
594
595 if ($parent_feed && $parent_feed != 0) {
596 $parent_qpart = "parent_feed = '$parent_feed'";
597 } else {
598 $parent_qpart = 'parent_feed = NULL';
599 }
600
bc0f0785
AD
601 if (ENABLE_SIMPLEPIE && SIMPLEPIE_CACHE_IMAGES) {
602 $cache_images_qpart = "cache_images = $cache_images,";
603 } else {
604 $cache_images_qpart = "";
605 }
606
b0f015a2
AD
607 if ($subop == "editSave") {
608
609 $result = db_query($link, "UPDATE ttrss_feeds SET
610 $category_qpart $parent_qpart,
611 title = '$feed_title', feed_url = '$feed_link',
612 update_interval = '$upd_intl',
613 purge_interval = '$purge_intl',
614 auth_login = '$auth_login',
615 auth_pass = '$auth_pass',
616 private = $private,
617 rtl_content = $rtl_content,
b0f015a2
AD
618 $cache_images_qpart
619 include_in_digest = $include_in_digest,
54e61a68 620 always_display_enclosures = $always_display_enclosures,
b0f015a2 621 update_method = '$update_method'
5ffd798d 622 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
b0f015a2
AD
623
624 if (get_pref($link, 'ENABLE_FEED_CATS')) {
625 # update linked feed categories
626 $result = db_query($link, "UPDATE ttrss_feeds SET
627 $category_qpart_nocomma WHERE parent_feed = '$feed_id' AND
628 owner_uid = " . $_SESSION["uid"]);
629 }
630 } else if ($subop == "batchEditSave") {
631 $feed_data = array();
ef8be8ea 632
b0f015a2
AD
633 foreach (array_keys($_POST) as $k) {
634 if ($k != "op" && $k != "subop" && $k != "ids") {
635 $feed_data[$k] = $_POST[$k];
636 }
637 }
638
639 db_query($link, "BEGIN");
640
641 foreach (array_keys($feed_data) as $k) {
642
643 $qpart = "";
644
645 switch ($k) {
646 case "title":
647 $qpart = "title = '$feed_title'";
648 break;
649
650 case "feed_url":
651 $qpart = "feed_url = '$feed_link'";
652 break;
653
654 case "update_interval":
655 $qpart = "update_interval = '$upd_intl'";
656 break;
657
658 case "purge_interval":
659 $qpart = "purge_interval = '$purge_intl'";
660 break;
661
662 case "auth_login":
663 $qpart = "auth_login = '$auth_login'";
664 break;
665
666 case "auth_pass":
667 $qpart = "auth_pass = '$auth_pass'";
668 break;
669
670 case "private":
671 $qpart = "private = '$private'";
672 break;
673
b0f015a2
AD
674 case "include_in_digest":
675 $qpart = "include_in_digest = '$include_in_digest'";
676 break;
677
c9f185bd
AD
678 case "always_display_enclosures":
679 $qpart = "always_display_enclosures = '$always_display_enclosures'";
680 break;
681
5d538f4f
AD
682 case "cache_images":
683 $qpart = "cache_images = '$cache_images'";
684 break;
685
686 case "rtl_content":
687 $qpart = "rtl_content = '$rtl_content'";
688 break;
689
b0f015a2
AD
690 case "update_method":
691 $qpart = "update_method = '$update_method'";
692 break;
693
694 case "cat_id":
695 $qpart = $category_qpart_nocomma;
696 break;
697
698 }
699
700 if ($qpart) {
cff7a3a2 701 db_query($link,
b0f015a2 702 "UPDATE ttrss_feeds SET $qpart WHERE id IN ($feed_ids)
cd935c42
AD
703 AND owner_uid = " . $_SESSION["uid"]);
704 print "<br/>";
b0f015a2
AD
705 }
706 }
707
708 db_query($link, "COMMIT");
ef8be8ea 709 }
b0f015a2 710
ef8be8ea
AD
711 }
712
ef8be8ea
AD
713 if ($subop == "remove") {
714
b4e75b2a 715 $ids = split(",", db_escape_string($_REQUEST["ids"]));
ef8be8ea 716
810b1561 717 foreach ($ids as $id) {
7e329f13 718 remove_feed($link, $id, $_SESSION["uid"]);
ef8be8ea
AD
719 }
720 }
721
d1f0c584 722 if ($subop == "clear") {
b4e75b2a 723 $id = db_escape_string($_REQUEST["id"]);
d1f0c584
AD
724 clear_feed_articles($link, $id);
725 }
726
fee840fb 727 if ($subop == "rescore") {
b4e75b2a 728 $ids = split(",", db_escape_string($_REQUEST["ids"]));
fee840fb
AD
729
730 foreach ($ids as $id) {
731
732 $filters = load_filters($link, $id, $_SESSION["uid"], 6);
733
734 $result = db_query($link, "SELECT title, content, link, ref_id FROM
735 ttrss_user_entries, ttrss_entries
736 WHERE ref_id = id AND feed_id = '$id' AND
737 owner_uid = " .$_SESSION['uid']."
ef1b0366 738 ");
fee840fb
AD
739
740 $scores = array();
741
742 while ($line = db_fetch_assoc($result)) {
743
744 $article_filters = get_article_filters($filters, $line['title'],
745 $line['content'], $line['link']);
746
747 $new_score = calculate_article_score($article_filters);
748
749 if (!$scores[$new_score]) $scores[$new_score] = array();
750
751 array_push($scores[$new_score], $line['ref_id']);
752 }
753
754 foreach (array_keys($scores) as $s) {
755 if ($s > 1000) {
756 db_query($link, "UPDATE ttrss_user_entries SET score = '$s',
757 marked = true WHERE
95a948a5 758 ref_id IN (" . join(',', $scores[$s]) . ")");
1618a849
AD
759 } else if ($s < -500) {
760 db_query($link, "UPDATE ttrss_user_entries SET score = '$s',
761 unread = false WHERE
762 ref_id IN (" . join(',', $scores[$s]) . ")");
95a948a5
AD
763 } else {
764 db_query($link, "UPDATE ttrss_user_entries SET score = '$s' WHERE
765 ref_id IN (" . join(',', $scores[$s]) . ")");
766 }
767 }
768 }
769
770 print __("All done.");
771
772 }
773
774 if ($subop == "rescoreAll") {
775
776 $result = db_query($link,
777 "SELECT id FROM ttrss_feeds WHERE owner_uid = " . $_SESSION['uid']);
778
779 while ($feed_line = db_fetch_assoc($result)) {
780
781 $id = $feed_line["id"];
782
783 $filters = load_filters($link, $id, $_SESSION["uid"], 6);
784
785 $tmp_result = db_query($link, "SELECT title, content, link, ref_id FROM
786 ttrss_user_entries, ttrss_entries
787 WHERE ref_id = id AND feed_id = '$id' AND
788 owner_uid = " .$_SESSION['uid']."
789 ");
790
791 $scores = array();
792
793 while ($line = db_fetch_assoc($tmp_result)) {
794
795 $article_filters = get_article_filters($filters, $line['title'],
796 $line['content'], $line['link']);
797
798 $new_score = calculate_article_score($article_filters);
799
800 if (!$scores[$new_score]) $scores[$new_score] = array();
801
802 array_push($scores[$new_score], $line['ref_id']);
803 }
804
805 foreach (array_keys($scores) as $s) {
806 if ($s > 1000) {
807 db_query($link, "UPDATE ttrss_user_entries SET score = '$s',
808 marked = true WHERE
fee840fb
AD
809 ref_id IN (" . join(',', $scores[$s]) . ")");
810 } else {
811 db_query($link, "UPDATE ttrss_user_entries SET score = '$s' WHERE
812 ref_id IN (" . join(',', $scores[$s]) . ")");
813 }
814 }
815 }
816
817 print __("All done.");
818
819 }
820
ef8be8ea 821 if ($subop == "add") {
ef8be8ea 822
a5819bb3
AD
823 $feed_url = db_escape_string(trim($_REQUEST["feed_url"]));
824 $cat_id = db_escape_string($_REQUEST["cat_id"]);
825 $p_from = db_escape_string($_REQUEST["from"]);
ef8be8ea 826
a5819bb3 827 /* only read authentication information from POST */
aa2122d4 828
a5819bb3
AD
829 $auth_login = db_escape_string(trim($_POST["auth_login"]));
830 $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
aa2122d4 831
a5819bb3
AD
832 if ($p_from != 'tt-rss') {
833 print "<html>
834 <head>
835 <title>Tiny Tiny RSS</title>
836 <link rel=\"stylesheet\" type=\"text/css\" href=\"utility.css\">
837 </head>
838 <body>
839 <img class=\"floatingLogo\" src=\"images/ttrss_logo.png\"
840 alt=\"Tiny Tiny RSS\"/>
841 <h1>Subscribe to feed...</h1>";
842 }
d70c5ae4 843
a5819bb3
AD
844 $rc = subscribe_to_feed($link, $feed_url, $cat_id, $auth_login, $auth_pass);
845
846 switch ($rc) {
847 case 1:
848 print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
849 break;
850 case 2:
851 print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
852 break;
853 case 0:
854 print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
855 break;
856 }
e513a74a 857
a5819bb3
AD
858 if ($p_from != 'tt-rss') {
859 $tt_uri = ($_SERVER['HTTPS'] != "on" ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . preg_replace('/backend\.php.*$/', 'tt-rss.php', $_SERVER["REQUEST_URI"]);
e513a74a 860
e513a74a 861
a5819bb3 862 $tp_uri = ($_SERVER['HTTPS'] != "on" ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . preg_replace('/backend\.php.*$/', 'prefs.php', $_SERVER["REQUEST_URI"]);
6906f145 863
a5819bb3
AD
864 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
865 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
e513a74a 866
a5819bb3 867 $feed_id = db_fetch_result($result, 0, "id");
aa2122d4 868
a5819bb3
AD
869 print "<p>";
870
871 if ($feed_id) {
872 print "<form method=\"GET\" style='display: inline'
873 action=\"$tp_uri\">
874 <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
875 <input type=\"hidden\" name=\"subop\" value=\"editFeed\">
876 <input type=\"hidden\" name=\"subopparam\" value=\"$feed_id\">
877 <input type=\"submit\" value=\"".__("Edit subscription options")."\">
878 </form>";
aa2122d4 879 }
442d77f1 880
a5819bb3
AD
881 print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
882 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
883 </form></p>";
884
885 print "</body></html>";
886 return;
ef8be8ea
AD
887 }
888 }
889
ef8be8ea
AD
890 if ($subop == "categorize") {
891
892 if (!WEB_DEMO_MODE) {
893
b4e75b2a 894 $ids = split(",", db_escape_string($_REQUEST["ids"]));
ef8be8ea 895
b4e75b2a 896 $cat_id = db_escape_string($_REQUEST["cat_id"]);
ef8be8ea
AD
897
898 if ($cat_id == 0) {
899 $cat_id_qpart = 'NULL';
900 } else {
901 $cat_id_qpart = "'$cat_id'";
902 }
903
904 db_query($link, "BEGIN");
905
906 foreach ($ids as $id) {
907
908 db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
909 WHERE id = '$id' AND parent_feed IS NULL
910 AND owner_uid = " . $_SESSION["uid"]);
911
912 # update linked feed categories
913 db_query($link, "UPDATE ttrss_feeds SET
914 cat_id = $cat_id_qpart WHERE parent_feed = '$id' AND
915 owner_uid = " . $_SESSION["uid"]);
916
917 }
918
919 db_query($link, "COMMIT");
920 }
921
922 }
923
9c483746
AD
924 if ($subop == "editCats") {
925
9c483746
AD
926 $action = $_REQUEST["action"];
927
928 if ($action == "save") {
929
11f083e7 930 $cat_title = db_escape_string(trim($_REQUEST["value"]));
b4e75b2a 931 $cat_id = db_escape_string($_REQUEST["cid"]);
11f083e7 932
8f708155
AD
933 db_query($link, "BEGIN");
934
935 $result = db_query($link, "SELECT title FROM ttrss_feed_categories
936 WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
937
938 if (db_num_rows($result) == 1) {
939
940 $old_title = db_fetch_result($result, 0, "title");
941
942 if ($cat_title != "") {
943 $result = db_query($link, "UPDATE ttrss_feed_categories SET
944 title = '$cat_title' WHERE id = '$cat_id' AND
945 owner_uid = ".$_SESSION["uid"]);
946
947 print $cat_title;
948 } else {
949 print $old_title;
950 }
951 } else {
952 print $_REQUEST["value"];
953 }
954
955 db_query($link, "COMMIT");
11f083e7
AD
956
957 return;
958
9c483746
AD
959 }
960
11f083e7
AD
961 print "<div id=\"infoBoxTitle\">".__('Category editor')."</div>";
962
963 print "<div class=\"infoBoxContents\">";
964
965
9c483746
AD
966 if ($action == "add") {
967
968 if (!WEB_DEMO_MODE) {
969
b4e75b2a 970 $feed_cat = db_escape_string(trim($_REQUEST["cat"]));
9c483746
AD
971
972 $result = db_query($link,
973 "SELECT id FROM ttrss_feed_categories
974 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
975
976 if (db_num_rows($result) == 0) {
977
978 $result = db_query($link,
979 "INSERT INTO ttrss_feed_categories (owner_uid,title)
980 VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
981
982 } else {
983
4dccf1ed
AD
984 print_warning(T_sprintf("Category <b>$%s</b> already exists in the database.",
985 $feed_cat));
9c483746
AD
986 }
987
988 }
989 }
990
991 if ($action == "remove") {
992
b4e75b2a 993 $ids = split(",", db_escape_string($_REQUEST["ids"]));
9c483746 994
7e329f13
AD
995 foreach ($ids as $id) {
996 remove_feed_category($link, $id, $_SESSION["uid"]);
9c483746
AD
997 }
998 }
999
1000 print "<div class=\"prefGenericAddBox\">
1001 <input id=\"fadd_cat\"
1043a8c3 1002 onkeypress=\"return filterCR(event, addFeedCat)\"
d60009cd
AD
1003 size=\"40\">
1004 <button onclick=\"javascript:addFeedCat()\">".
1005 __('Create category')."</button></div>";
9c483746
AD
1006
1007 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
1008 WHERE owner_uid = ".$_SESSION["uid"]."
1009 ORDER BY title");
1010
1011 print "<p>";
1012
1013 if (db_num_rows($result) != 0) {
1014
d60009cd 1015 print __('Select:')."
e8d0177d 1016 <a href=\"javascript:selectPrefRows('fcat', true)\">".__('All')."</a>,
d60009cd 1017 <a href=\"javascript:selectPrefRows('fcat', false)\">".__('None')."</a>";
9c483746
AD
1018
1019 print "<div class=\"prefFeedCatHolder\">";
1020
e6312f6c 1021 print "<form id=\"feed_cat_edit_form\" onsubmit=\"return false\">";
9c483746
AD
1022
1023 print "<table width=\"100%\" class=\"prefFeedCatList\"
1024 cellspacing=\"0\" id=\"prefFeedCatList\">";
9c483746
AD
1025
1026 $lnum = 0;
1027
1028 while ($line = db_fetch_assoc($result)) {
1029
1030 $class = ($lnum % 2) ? "even" : "odd";
1031
1032 $cat_id = $line["id"];
11f083e7 1033 $this_row_id = "id=\"FCATR-$cat_id\"";
9c483746
AD
1034
1035 print "<tr class=\"$class\" $this_row_id>";
1036
47439031 1037 $edit_title = htmlspecialchars($line["title"]);
9c483746 1038
11f083e7
AD
1039 print "<td width='5%' align='center'><input
1040 onclick='toggleSelectPrefRow(this, \"fcat\");'
1041 type=\"checkbox\" id=\"FCCHK-$cat_id\"></td>";
1042
1043 print "<td><span id=\"FCATT-$cat_id\">" .
1044 $edit_title . "</span></td>";
9c483746
AD
1045
1046 print "</tr>";
1047
1048 ++$lnum;
1049 }
1050
1051 print "</table>";
1052
1053 print "</form>";
1054
1055 print "</div>";
1056
6f5b1e04 1057 } else {
31cc42f6 1058 print "<p>".__('No feed categories defined.')."</p>";
6f5b1e04 1059 }
9c483746 1060
d60009cd
AD
1061 print "<div class='dlgButtons'>
1062 <div style='float : left'>
1063 <button onclick=\"return removeSelectedFeedCats()\">".
1064 __('Remove')."</button>
1065 </div>";
9c483746 1066
d60009cd
AD
1067 print "<button onclick=\"selectTab('feedConfig')\">".
1068 __('Close this window')."</button></div>";
9c483746 1069
6f5b1e04
AD
1070 print "</div>";
1071
9c483746
AD
1072 return;
1073
1074 }
1075
ef8be8ea
AD
1076 if ($quiet) return;
1077
442d77f1
AD
1078 set_pref($link, "_PREFS_ACTIVE_TAB", "feedConfig");
1079
a3656a41 1080 $result = db_query($link, "SELECT COUNT(id) AS num_errors
ef8be8ea
AD
1081 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1082
a3656a41 1083 $num_errors = db_fetch_result($result, 0, "num_errors");
ef8be8ea 1084
a3656a41 1085 if ($num_errors > 0) {
ef8be8ea 1086
31cc42f6
AD
1087 print format_notice("<a href=\"javascript:showFeedsWithErrors()\">".
1088 __('Some feeds have update errors (click for details)')."</a>");
ef8be8ea
AD
1089 }
1090
b4e75b2a 1091 $feed_search = db_escape_string($_REQUEST["search"]);
ef8be8ea 1092
b4e75b2a 1093 if (array_key_exists("search", $_REQUEST)) {
ef8be8ea
AD
1094 $_SESSION["prefs_feed_search"] = $feed_search;
1095 } else {
1096 $feed_search = $_SESSION["prefs_feed_search"];
1097 }
1098
577399e8 1099 print "<div style='float : right'>
3dc8ee84 1100 <input id=\"feed_search\" size=\"20\" type=\"search\"
4cf6fc6a
AD
1101 onfocus=\"javascript:disableHotkeys();\"
1102 onblur=\"javascript:enableHotkeys();\"
ef8be8ea 1103 onchange=\"javascript:updateFeedList()\" value=\"$feed_search\">
577399e8
AD
1104 <button onclick=\"javascript:updateFeedList()\">".
1105 __('Search')."</button>
ef8be8ea 1106 </div>";
5e6f933a 1107
577399e8
AD
1108 print "<button onclick=\"javascript:displayDlg('quickAddFeed')\">"
1109 .__('Subscribe to feed')."</button> ";
1e5548db 1110
577399e8
AD
1111 print "<button onclick=\"javascript:editSelectedFeed()\">".
1112 __('Edit feeds')."</button> ";
1e5548db
AD
1113
1114 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1115
577399e8
AD
1116 print "<button onclick=\"javascript:editFeedCats()\">".
1117 __('Edit categories')."</button> ";
1e5548db
AD
1118 }
1119
577399e8
AD
1120 print "<button onclick=\"javascript:removeSelectedFeeds()\">"
1121 .__('Unsubscribe')."</button> ";
1e5548db
AD
1122
1123/* print "<select id=\"feedActionChooser\" onchange=\"feedActionChange()\">
1124 <option value=\"facDefault\" selected>".__('Other actions...')."</option>";
1125
1126 if (FORCE_ARTICLE_PURGE == 0) {
1127 print
1128 "<option value=\"facPurge\">".__('Manual purge')."</option>";
1129 }
1130
1131 print "
1132 <option value=\"facClear\">".__('Clear feed data')."</option>
1133 <option value=\"facRescore\">".__('Rescore articles')."</option>
1134 <option value=\"facUnsubscribe\">".__('Unsubscribe')."</option>";
1135
1136 print "</select>"; */
ef8be8ea 1137
69877646 1138/* if (ENABLE_FEED_BROWSER && !SINGLE_USER_MODE) {
ef8be8ea 1139 print " <input type=\"submit\" class=\"button\"
a349077c 1140 id=\"top25_feeds_btn\"
082ae95b 1141 onclick=\"javascript:browseFeeds()\" value=\"".__('More feeds')."\">";
69877646 1142 } */
ef8be8ea 1143
b4e75b2a 1144 $feeds_sort = db_escape_string($_REQUEST["sort"]);
ef8be8ea
AD
1145
1146 if (!$feeds_sort || $feeds_sort == "undefined") {
1147 $feeds_sort = $_SESSION["pref_sort_feeds"];
1148 if (!$feeds_sort) $feeds_sort = "title";
1149 }
1150
1151 $_SESSION["pref_sort_feeds"] = $feeds_sort;
1152
1153 if ($feed_search) {
1638fc4e
AD
1154
1155 $feed_search = split(" ", $feed_search);
1156 $tokens = array();
1157
1158 foreach ($feed_search as $token) {
1159
1160 $token = trim($token);
1161
1162 array_push($tokens, "(UPPER(F1.title) LIKE UPPER('%$token%') OR
1163 UPPER(C1.title) LIKE UPPER('%$token%') OR
1164 UPPER(F1.feed_url) LIKE UPPER('%$token%'))");
1165 }
1166
1167 $search_qpart = "(" . join($tokens, " AND ") . ") AND ";
1168
ef8be8ea
AD
1169 } else {
1170 $search_qpart = "";
1171 }
1172
400b60d8
AD
1173 $show_last_article_info = false;
1174 $show_last_article_checked = "";
1175 $show_last_article_qpart = "";
1176
b4e75b2a 1177 if ($_REQUEST["slat"] == "true") {
400b60d8
AD
1178 $show_last_article_info = true;
1179 $show_last_article_checked = "checked";
fc2b26a6 1180 $show_last_article_qpart = ", (SELECT ".SUBSTRING_FOR_DATE."(MAX(updated),1,16) FROM ttrss_user_entries,
400b60d8
AD
1181 ttrss_entries WHERE ref_id = ttrss_entries.id
1182 AND feed_id = F1.id) AS last_article";
d2ca9130
AD
1183 } else if ($feeds_sort == "last_article") {
1184 $feeds_sort = "title";
1185 }
1186
1187 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1188 $order_by_qpart = "category,$feeds_sort,title";
1189 } else {
1190 $order_by_qpart = "$feeds_sort,title";
400b60d8
AD
1191 }
1192
ef8be8ea
AD
1193 $result = db_query($link, "SELECT
1194 F1.id,
1195 F1.title,
1196 F1.feed_url,
2ac6b765 1197 ".SUBSTRING_FOR_DATE."(F1.last_updated,1,16) AS last_updated,
ef8be8ea
AD
1198 F1.parent_feed,
1199 F1.update_interval,
365f95dc 1200 F1.last_error,
ef8be8ea
AD
1201 F1.purge_interval,
1202 F1.cat_id,
1203 F2.title AS parent_title,
1204 C1.title AS category,
400b60d8
AD
1205 F1.include_in_digest
1206 $show_last_article_qpart
ef8be8ea
AD
1207 FROM
1208 ttrss_feeds AS F1
1209 LEFT JOIN ttrss_feeds AS F2
1210 ON (F1.parent_feed = F2.id)
1211 LEFT JOIN ttrss_feed_categories AS C1
1212 ON (F1.cat_id = C1.id)
1213 WHERE
1214 $search_qpart F1.owner_uid = '".$_SESSION["uid"]."'
1215 ORDER by $order_by_qpart");
1216
1217 if (db_num_rows($result) != 0) {
1218
1219// print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
1220
1221 print "<p><table width=\"100%\" cellspacing=\"0\"
1222 class=\"prefFeedList\" id=\"prefFeedList\">";
400b60d8
AD
1223 print "<tr><td class=\"selectPrompt\" colspan=\"8\">".
1224 "<div style='float : right'>".
1225 "<input id='show_last_article_times' type='checkbox' onchange='feedlistToggleSLAT()'
1226 $show_last_article_checked><label
1227 for='show_last_article_times'>".__('Show last article times')."</label></div>".
1228 __('Select:')."
e8d0177d
AD
1229 <a href=\"javascript:selectPrefRows('feed', true)\">".__('All')."</a>,
1230 <a href=\"javascript:selectPrefRows('feed', false)\">".__('None')."</a>
ef8be8ea
AD
1231 </td</tr>";
1232
1233 if (!get_pref($link, 'ENABLE_FEED_CATS')) {
1234 print "<tr class=\"title\">
1235 <td width='5%' align='center'>&nbsp;</td>";
1236
1237 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
1238 print "<td width='3%'>&nbsp;</td>";
1239 }
1240
c4b0f96c
AD
1241 print "<td width='60%'><a href=\"javascript:updateFeedList('title')\">".__('Title')."</a></td>";
1242
1243 if ($show_last_article_info) {
1244 print "<td width='20%' align='right'><a href=\"javascript:updateFeedList('last_article')\">".__('Last&nbsp;Article')."</a></td>";
1245 }
1246
1247 print "<td width='20%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">".__('Updated')."</a></td>";
ef8be8ea
AD
1248 }
1249
1250 $lnum = 0;
1251
1252 $cur_cat_id = -1;
1253
1254 while ($line = db_fetch_assoc($result)) {
1255
1256 $feed_id = $line["id"];
1257 $cat_id = $line["cat_id"];
1258
47439031
AD
1259 $edit_title = htmlspecialchars($line["title"]);
1260 $edit_cat = htmlspecialchars($line["category"]);
ef8be8ea 1261
365f95dc
AD
1262 $last_error = $line["last_error"];
1263
3692e98f 1264 if (!$edit_cat) $edit_cat = __("Uncategorized");
ef8be8ea
AD
1265
1266 $last_updated = $line["last_updated"];
1267
7a74abd5
AD
1268 if (!$last_updated) {
1269 $last_updated = "&mdash;";
1270 } else if (get_pref($link, 'HEADLINES_SMART_DATE')) {
ef8be8ea
AD
1271 $last_updated = smart_date_time(strtotime($last_updated));
1272 } else {
1273 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1274 $last_updated = date($short_date, strtotime($last_updated));
1275 }
1276
1277 $last_article = $line["last_article"];
1278
7a74abd5
AD
1279 if (!$last_article) {
1280 $last_article = "&mdash;";
1281 } else if (get_pref($link, 'HEADLINES_SMART_DATE')) {
ef8be8ea
AD
1282 $last_article = smart_date_time(strtotime($last_article));
1283 } else {
1284 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1285 $last_article = date($short_date, strtotime($last_article));
1286 }
1287
1288 if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) {
1289 $lnum = 0;
1290
1291 print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>";
1292
1293 print "<tr class=\"title\">
1294 <td width='5%'>&nbsp;</td>";
1295
1296 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
1297 print "<td width='3%'>&nbsp;</td>";
1298 }
1299
400b60d8
AD
1300 print "<td width='60%'><a href=\"javascript:updateFeedList('title')\">".__('Title')."</a></td>";
1301
1302 if ($show_last_article_info) {
1303 print "<td width='20%' align='right'>
1304 <a href=\"javascript:updateFeedList('last_article')\">".__('Last&nbsp;Article')."</a></td>";
1305 }
1306
1307 print "<td width='20%' align='right'>
1308 <a href=\"javascript:updateFeedList('last_updated')\">".__('Updated')."</a></td>";
ef8be8ea
AD
1309
1310 $cur_cat_id = $cat_id;
1311 }
1312
1313 $class = ($lnum % 2) ? "even" : "odd";
1314 $this_row_id = "id=\"FEEDR-$feed_id\"";
1315
1316 print "<tr class=\"$class\" $this_row_id>";
1317
1318 $icon_file = ICONS_DIR . "/$feed_id.ico";
1319
1320 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1321 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . "/$feed_id.ico\">";
1322 } else {
1323 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1324 }
1325
1326 print "<td class='feedSelect'><input onclick='toggleSelectPrefRow(this, \"feed\");'
1327 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
1328
a95da136
AD
1329 $onclick = "onclick='editFeed($feed_id)' title='".__('Click to edit')."'";
1330
ef8be8ea 1331 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
a95da136 1332 print "<td $onclick class='feedIcon'>$feed_icon</td>";
ef8be8ea 1333 }
365f95dc
AD
1334
1335 if ($last_error) {
1fc77c25 1336 $edit_title = "<span class=\"feed_error\">$edit_title</span>";
365f95dc
AD
1337 $last_updated = "<span class=\"feed_error\">$last_updated</span>";
1338 $last_article = "<span class=\"feed_error\">$last_article</span>";
ef8be8ea
AD
1339 }
1340
1341 $parent_title = $line["parent_title"];
1342 if ($parent_title) {
2a52d96f
AD
1343 $linked_to = sprintf(__("(linked to %s)"), $parent_title);
1344 $parent_title = "<span class='groupPrompt'>$linked_to</span>";
ef8be8ea
AD
1345 }
1346
a95da136 1347 print "<td $onclick>" . "$edit_title $parent_title" . "</td>";
ef8be8ea 1348
400b60d8 1349 if ($show_last_article_info) {
a95da136
AD
1350 print "<td align='right' $onclick>" .
1351 "$last_article</td>";
400b60d8 1352 }
ef8be8ea 1353
fe5bfa00 1354 print "<td $onclick align='right'>$last_updated</td>";
ef8be8ea
AD
1355
1356 print "</tr>";
1357
1358 ++$lnum;
1359 }
1360
1361 print "</table>";
1362
e88a65f4 1363 print "<p>";
c4a36709 1364
cea04d61
AD
1365 } else {
1366
1367 print "<p>";
1368
1369 if (!$feed_search) {
1370 print_warning(__("You don't have any subscribed feeds."));
1371 } else {
1372 print_warning(__('No matching feeds found.'));
1373 }
1374 print "</p>";
1375
ef8be8ea
AD
1376 }
1377
a3c159c4 1378 print "<h3>".__('OPML')."</h3>
94a4ba88
AD
1379
1380 <div style='float : left'>
ef8be8ea 1381 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
999703d1
AD
1382 ".__('File:')." <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
1383 <input type=\"hidden\" name=\"op\" value=\"Import\">
577399e8
AD
1384 <button onclick=\"return validateOpmlImport();\"
1385 type=\"submit\">".__('Import')."</button>
94a4ba88
AD
1386 </form></div>";
1387
3692e98f 1388 print "&nbsp;";
94a4ba88 1389
577399e8
AD
1390 print "<button onclick=\"gotoExportOpml()\">".
1391 __('Export OPML')."</button>";
94a4ba88 1392
e4f4b46f 1393
755a43ee
AD
1394 print "<h3>" . __("Firefox Integration") . "</h3>";
1395
cf9dc032
AD
1396 print "<p>" . __('This Tiny Tiny RSS site can be used as a Firefox Feed Reader by clicking the link below.') . "</p>";
1397
1398 print "<p";
1399
1400 print "<button onclick='window.navigator.registerContentHandler(" .
755a43ee
AD
1401 "\"application/vnd.mozilla.maybe.feed\", " .
1402 "\"" . add_feed_url() . "\", " . " \"Tiny Tiny RSS\")'>" .
cf9dc032
AD
1403 __('Click here to register this site as a feed reader.') .
1404 "</button>";
755a43ee 1405
cf9dc032 1406 print "</p>";
755a43ee 1407
e400230e 1408 print "<h3>".__("Published articles")."</h3>";
e4f4b46f
AD
1409
1410 if (!get_pref($link, "_PREFS_PUBLISH_KEY")) {
1411 set_pref($link, "_PREFS_PUBLISH_KEY", generate_publish_key());
1412 }
1413
e635d56a 1414 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 1415
cf9dc032
AD
1416 print "<button onclick=\"return displayDlg('pubUrl')\">".
1417 __('Display URL')."</button> ";
e4f4b46f 1418
e4f4b46f 1419
ef8be8ea 1420 }
b56465dd 1421
082ae95b 1422 function print_feed_browser($link, $search, $limit, $mode = 1) {
b56465dd 1423
c2913898
AD
1424 $owner_uid = $_SESSION["uid"];
1425
1426 if ($search) {
1427 $search_qpart = "AND (UPPER(feed_url) LIKE UPPER('%$search%') OR
1428 UPPER(title) LIKE UPPER('%$search%'))";
1429 } else {
1430 $search_qpart = "";
1431 }
1432
082ae95b
AD
1433 if ($mode == 1) {
1434 $result = db_query($link, "SELECT feed_url, subscribers FROM
1435 ttrss_feedbrowser_cache WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf
1436 WHERE tf.feed_url = ttrss_feedbrowser_cache.feed_url
1437 AND owner_uid = '$owner_uid') $search_qpart
1438 ORDER BY subscribers DESC LIMIT $limit");
1439 } else if ($mode == 2) {
1440 $result = db_query($link, "SELECT * FROM
1441 ttrss_archived_feeds WHERE
1442 (SELECT COUNT(*) FROM ttrss_feeds
1443 WHERE ttrss_feeds.feed_url = ttrss_archived_feeds.feed_url AND
1444 owner_uid = '$owner_uid') = 0 AND
1445 owner_uid = '$owner_uid' $search_qpart
1446 ORDER BY id DESC LIMIT $limit");
1447 }
b56465dd
AD
1448
1449 $feedctr = 0;
1450
1451 while ($line = db_fetch_assoc($result)) {
b56465dd 1452
082ae95b 1453 if ($mode == 1) {
b56465dd 1454
082ae95b
AD
1455 $feed_url = $line["feed_url"];
1456 $subscribers = $line["subscribers"];
1457
1458 $det_result = db_query($link, "SELECT site_url,title,id
1459 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
1460
1461 $details = db_fetch_assoc($det_result);
1462
1463 $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico";
1464
1465 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1466 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL .
1467 "/".$details["id"].".ico\">";
1468 } else {
1469 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1470 }
1471
1472 $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB'
1473 type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
1474
1475 $class = ($feedctr % 2) ? "even" : "odd";
1476
1477 if ($details["site_url"]) {
1478 $site_url = "<a target=\"_blank\" href=\"".$details["site_url"]."\">
1479 <img style='border-width : 0px' src='images/www.png' alt='www'></a>";
1480 } else {
1481 $site_url = "";
1482 }
1483
1484 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
1485 "$feed_icon " . $details["title"] .
1486 "&nbsp;<span class='subscribers'>($subscribers)</span>
1487 $site_url
1488 </li>";
1489
1490 } else if ($mode == 2) {
1491 $feed_url = $line["feed_url"];
69877646
AD
1492
1493 $icon_file = ICONS_DIR . "/" . $line["id"] . ".ico";
082ae95b 1494
69877646
AD
1495 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1496 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL .
1497 "/".$line["id"].".ico\">";
1498 } else {
1499 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1500 }
1501
082ae95b
AD
1502 $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB'
1503 type=\"checkbox\" id=\"FBCHK-" . $line["id"] . "\">";
1504
1505 $class = ($feedctr % 2) ? "even" : "odd";
1506
1507 if ($line["site_url"]) {
1508 $site_url = "<a target=\"_blank\" href=\"".$line["site_url"]."\">
1509 <img style='border-width : 0px' src='images/www.png' alt='www'></a>";
1510 } else {
1511 $site_url = "";
1512 }
1513
1514 print "<li class='$class' id=\"FBROW-".$line["id"]."\">$check_box".
69877646 1515 "$feed_icon " . $line["title"] . $site_url . "</li>";
b56465dd 1516
b56465dd 1517
2bab8824
AD
1518 }
1519
082ae95b 1520 ++$feedctr;
b56465dd
AD
1521 }
1522
1523 if ($feedctr == 0) {
1524 print "<li style=\"text-align : center\"><p>".__('No feeds found.')."</p></li>";
1525 }
1526
1527 return $feedctr;
1528
1529 }
a5819bb3 1530
ef8be8ea 1531?>