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