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