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