]> git.wh0rd.org - tt-rss.git/blame - modules/pref-feeds.php
small dialog tweaks to better center elements vertically
[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")."\"
05acc0d6 5 onchange=\"dijit.byId('feedEditDlg').toggleField(this, '$elem', '$label')\">";
758e1c4a
AD
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 276
bcf5ed46 277 print "<hr/>";
ecace165
AD
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
bcf5ed46 291 print "<hr/>";
ecace165
AD
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
bcf5ed46 326 print "<hr/>";
3907ef71 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 349 placeHolder=\"".__("Login")."\"
bcf5ed46 350 name=\"auth_login\" value=\"$auth_login\"><hr/>";
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
bcf5ed46 387 print "<hr/><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
bcf5ed46 398 print "<hr/><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
bcf5ed46 411 print "<hr/><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
bcf5ed46 424 print "<hr/><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
7abf159d 435 print "<div class=\"dlgSec\">".__("Icon")."</div>";
c3b7b797
AD
436 print "<div class=\"dlgSecCont\">";
437
438 print "<iframe name=\"icon_upload_iframe\"
439 style=\"width: 400px; height: 100px; display: none;\"></iframe>";
440
441 print "<form style='display : block' target=\"icon_upload_iframe\"
442 enctype=\"multipart/form-data\" method=\"POST\"
443 action=\"backend.php\">
7abf159d 444 <input id=\"icon_file\" size=\"10\" name=\"icon_file\" type=\"file\">
c3b7b797 445 <input type=\"hidden\" name=\"op\" value=\"pref-feeds\">
7abf159d 446 <input type=\"hidden\" name=\"feed_id\" value=\"$feed_id\">
c3b7b797 447 <input type=\"hidden\" name=\"subop\" value=\"uploadicon\">
f9c388f5 448 <button dojoType=\"dijit.form.Button\" onclick=\"return uploadFeedIcon();\"
c3b7b797 449 type=\"submit\">".__('Replace')."</button>
f9c388f5 450 <button dojoType=\"dijit.form.Button\" onclick=\"return removeFeedIcon($feed_id);\"
7abf159d 451 type=\"submit\">".__('Remove')."</button>
c3b7b797
AD
452 </form>";
453
7abf159d 454 print "</div>";
c3b7b797 455
ddb61e79
AD
456 $title = htmlspecialchars($title, ENT_QUOTES);
457
ecace165 458 print "<div class='dlgButtons'>
143a4973 459 <div style=\"float : left\">
f9c388f5 460 <button dojoType=\"dijit.form.Button\" onclick='return unsubscribeFeed($feed_id, \"$title\")'>".
ad491d75 461 __('Unsubscribe')."</button>
143a4973 462 </div>
f9c388f5
AD
463 <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedEditDlg').execute()\">".__('Save')."</button>
464 <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedEditDlg').hide()\">".__('Cancel')."</button>
465 </div>";
951906dc 466
ef8be8ea
AD
467 return;
468 }
469
758e1c4a
AD
470 if ($subop == "editfeeds") {
471
472 $feed_ids = db_escape_string($_REQUEST["ids"]);
758e1c4a 473
05acc0d6
AD
474 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"ids\" value=\"$feed_ids\">";
475 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-feeds\">";
476 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"batchEditSave\">";
758e1c4a
AD
477
478 print "<div class=\"dlgSec\">".__("Feed")."</div>";
479 print "<div class=\"dlgSecCont\">";
480
481 /* Title */
482
05acc0d6
AD
483 print "<input dojoType=\"dijit.form.ValidationTextBox\"
484 disabled=\"1\" style=\"font-size : 16px; width : 20em;\" required=\"1\"
485 name=\"title\" value=\"$title\">";
758e1c4a
AD
486
487 batch_edit_cbox("title");
488
489 /* Feed URL */
490
491 print "<br/>";
492
493 print __('URL:') . " ";
05acc0d6
AD
494 print "<input dojoType=\"dijit.form.ValidationTextBox\" disabled=\"1\"
495 required=\"1\" regExp='^(http|https)://.*' style=\"width : 20em\"
758e1c4a
AD
496 name=\"feed_url\" value=\"$feed_url\">";
497
498 batch_edit_cbox("feed_url");
499
500 /* Category */
501
502 if (get_pref($link, 'ENABLE_FEED_CATS')) {
503
504 print "<br/>";
505
506 print __('Place in category:') . " ";
507
05acc0d6
AD
508 print_feed_cat_select($link, "cat_id", $cat_id,
509 'disabled="1" dojoType="dijit.form.Select"');
758e1c4a
AD
510
511 batch_edit_cbox("cat_id");
512
513 }
514
515 print "</div>";
516
517 print "<div class=\"dlgSec\">".__("Update")."</div>";
518 print "<div class=\"dlgSecCont\">";
519
520 /* Update Interval */
521
522 print_select_hash("update_interval", $update_interval, $update_intervals,
05acc0d6 523 'disabled="1" dojoType="dijit.form.Select"');
758e1c4a
AD
524
525 batch_edit_cbox("update_interval");
526
527 /* Update method */
528
34f29d78
AD
529 print " " . __('using') . " ";
530 print_select_hash("update_method", $update_method, $update_methods,
05acc0d6 531 'disabled="1" dojoType="dijit.form.Select"');
34f29d78 532 batch_edit_cbox("update_method");
758e1c4a
AD
533
534 /* Purge intl */
535
05acc0d6 536 if (FORCE_ARTICLE_PURGE == 0) {
758e1c4a 537
3907ef71 538 print "<br/>";
758e1c4a 539
3907ef71 540 print __('Article purging:') . " ";
758e1c4a 541
3907ef71 542 print_select_hash("purge_interval", $purge_interval, $purge_intervals,
05acc0d6 543 'disabled="1" dojoType="dijit.form.Select"');
3907ef71
AD
544
545 batch_edit_cbox("purge_interval");
546 }
758e1c4a
AD
547
548 print "</div>";
549 print "<div class=\"dlgSec\">".__("Authentication")."</div>";
550 print "<div class=\"dlgSecCont\">";
551
05acc0d6
AD
552 print "<input dojoType=\"dijit.form.TextBox\"
553 placeHolder=\"".__("Login")."\" disabled=\"1\"
758e1c4a
AD
554 name=\"auth_login\" value=\"$auth_login\">";
555
556 batch_edit_cbox("auth_login");
557
05acc0d6
AD
558 print "<br/><input dojoType=\"dijit.form.TextBox\" type=\"password\" name=\"auth_pass\"
559 placeHolder=\"".__("Password")."\" disabled=\"1\"
758e1c4a
AD
560 value=\"$auth_pass\">";
561
562 batch_edit_cbox("auth_pass");
563
564 print "</div>";
565 print "<div class=\"dlgSec\">".__("Options")."</div>";
566 print "<div class=\"dlgSecCont\">";
567
05acc0d6
AD
568 print "<input disabled=\"1\" type=\"checkbox\" name=\"private\" id=\"private\"
569 dojoType=\"dijit.form.CheckBox\">&nbsp;<label id=\"private_l\" class='insensitive' for=\"private\">".__('Hide from Popular feeds')."</label>";
758e1c4a
AD
570
571 print "&nbsp;"; batch_edit_cbox("private", "private_l");
572
05acc0d6
AD
573 print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"
574 dojoType=\"dijit.form.CheckBox\">&nbsp;<label class='insensitive' id=\"rtl_content_l\" for=\"rtl_content\">".__('Right-to-left content')."</label>";
758e1c4a
AD
575
576 print "&nbsp;"; batch_edit_cbox("rtl_content", "rtl_content_l");
577
05acc0d6 578 print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"include_in_digest\"
758e1c4a 579 name=\"include_in_digest\"
05acc0d6 580 dojoType=\"dijit.form.CheckBox\">&nbsp;<label id=\"include_in_digest_l\" class='insensitive' for=\"include_in_digest\">".__('Include in e-mail digest')."</label>";
758e1c4a
AD
581
582 print "&nbsp;"; batch_edit_cbox("include_in_digest", "include_in_digest_l");
583
05acc0d6 584 print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"always_display_enclosures\"
c9f185bd 585 name=\"always_display_enclosures\"
05acc0d6 586 dojoType=\"dijit.form.CheckBox\">&nbsp;<label id=\"always_display_enclosures_l\" class='insensitive' for=\"always_display_enclosures\">".__('Always display image attachments')."</label>";
c9f185bd
AD
587
588 print "&nbsp;"; batch_edit_cbox("always_display_enclosures", "always_display_enclosures_l");
589
05acc0d6 590 print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"cache_images\"
758e1c4a 591 name=\"cache_images\"
05acc0d6 592 dojoType=\"dijit.form.CheckBox\">&nbsp;<label class='insensitive' id=\"cache_images_l\"
758e1c4a
AD
593 for=\"cache_images\">".
594 __('Cache images locally')."</label>";
595
596
05acc0d6 597 print "&nbsp;"; batch_edit_cbox("cache_images", "cache_images_l");
758e1c4a 598
758e1c4a
AD
599 print "</div>";
600
758e1c4a 601 print "<div class='dlgButtons'>
e1218480
AD
602 <button dojoType=\"dijit.form.Button\"
603 onclick=\"return dijit.byId('feedEditDlg').execute()\">".
604 __('Save')."</button>
605 <button dojoType=\"dijit.form.Button\"
606 onclick=\"return dijit.byId('feedEditDlg').hide()\">".
607 __('Cancel')."</button>
758e1c4a 608 </div>";
05acc0d6 609
758e1c4a
AD
610 return;
611 }
612
b0f015a2 613 if ($subop == "editSave" || $subop == "batchEditSave") {
ef8be8ea
AD
614
615 $feed_title = db_escape_string(trim($_POST["title"]));
616 $feed_link = db_escape_string(trim($_POST["feed_url"]));
617 $upd_intl = db_escape_string($_POST["update_interval"]);
618 $purge_intl = db_escape_string($_POST["purge_interval"]);
b0f015a2
AD
619 $feed_id = db_escape_string($_POST["id"]); /* editSave */
620 $feed_ids = db_escape_string($_POST["ids"]); /* batchEditSave */
ef8be8ea
AD
621 $cat_id = db_escape_string($_POST["cat_id"]);
622 $auth_login = db_escape_string(trim($_POST["auth_login"]));
623 $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
ef8be8ea
AD
624 $private = checkbox_to_sql_bool(db_escape_string($_POST["private"]));
625 $rtl_content = checkbox_to_sql_bool(db_escape_string($_POST["rtl_content"]));
ef8be8ea
AD
626 $include_in_digest = checkbox_to_sql_bool(
627 db_escape_string($_POST["include_in_digest"]));
bc0f0785
AD
628 $cache_images = checkbox_to_sql_bool(
629 db_escape_string($_POST["cache_images"]));
16211ddb 630 $update_method = (int) db_escape_string($_POST["update_method"]);
ef8be8ea 631
54e61a68
AD
632 $always_display_enclosures = checkbox_to_sql_bool(
633 db_escape_string($_POST["always_display_enclosures"]));
634
ef8be8ea
AD
635 if (get_pref($link, 'ENABLE_FEED_CATS')) {
636 if ($cat_id && $cat_id != 0) {
637 $category_qpart = "cat_id = '$cat_id',";
638 $category_qpart_nocomma = "cat_id = '$cat_id'";
639 } else {
640 $category_qpart = 'cat_id = NULL,';
641 $category_qpart_nocomma = 'cat_id = NULL';
642 }
643 } else {
644 $category_qpart = "";
645 $category_qpart_nocomma = "";
646 }
647
78a5c296 648 if (SIMPLEPIE_CACHE_IMAGES) {
bc0f0785
AD
649 $cache_images_qpart = "cache_images = $cache_images,";
650 } else {
651 $cache_images_qpart = "";
652 }
653
b0f015a2
AD
654 if ($subop == "editSave") {
655
656 $result = db_query($link, "UPDATE ttrss_feeds SET
6e63a7c3 657 $category_qpart
b0f015a2
AD
658 title = '$feed_title', feed_url = '$feed_link',
659 update_interval = '$upd_intl',
660 purge_interval = '$purge_intl',
661 auth_login = '$auth_login',
662 auth_pass = '$auth_pass',
663 private = $private,
664 rtl_content = $rtl_content,
b0f015a2
AD
665 $cache_images_qpart
666 include_in_digest = $include_in_digest,
54e61a68 667 always_display_enclosures = $always_display_enclosures,
b0f015a2 668 update_method = '$update_method'
5ffd798d 669 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
b0f015a2 670
b0f015a2
AD
671 } else if ($subop == "batchEditSave") {
672 $feed_data = array();
ef8be8ea 673
b0f015a2
AD
674 foreach (array_keys($_POST) as $k) {
675 if ($k != "op" && $k != "subop" && $k != "ids") {
676 $feed_data[$k] = $_POST[$k];
677 }
678 }
679
680 db_query($link, "BEGIN");
681
682 foreach (array_keys($feed_data) as $k) {
683
684 $qpart = "";
685
686 switch ($k) {
687 case "title":
688 $qpart = "title = '$feed_title'";
689 break;
690
691 case "feed_url":
692 $qpart = "feed_url = '$feed_link'";
693 break;
694
695 case "update_interval":
696 $qpart = "update_interval = '$upd_intl'";
697 break;
698
699 case "purge_interval":
700 $qpart = "purge_interval = '$purge_intl'";
701 break;
702
703 case "auth_login":
704 $qpart = "auth_login = '$auth_login'";
705 break;
706
707 case "auth_pass":
708 $qpart = "auth_pass = '$auth_pass'";
709 break;
710
711 case "private":
712 $qpart = "private = '$private'";
713 break;
714
b0f015a2
AD
715 case "include_in_digest":
716 $qpart = "include_in_digest = '$include_in_digest'";
717 break;
718
c9f185bd
AD
719 case "always_display_enclosures":
720 $qpart = "always_display_enclosures = '$always_display_enclosures'";
721 break;
722
5d538f4f
AD
723 case "cache_images":
724 $qpart = "cache_images = '$cache_images'";
725 break;
726
727 case "rtl_content":
728 $qpart = "rtl_content = '$rtl_content'";
729 break;
730
b0f015a2
AD
731 case "update_method":
732 $qpart = "update_method = '$update_method'";
733 break;
734
735 case "cat_id":
736 $qpart = $category_qpart_nocomma;
737 break;
738
739 }
740
741 if ($qpart) {
cff7a3a2 742 db_query($link,
b0f015a2 743 "UPDATE ttrss_feeds SET $qpart WHERE id IN ($feed_ids)
cd935c42
AD
744 AND owner_uid = " . $_SESSION["uid"]);
745 print "<br/>";
b0f015a2
AD
746 }
747 }
748
749 db_query($link, "COMMIT");
ef8be8ea 750 }
05acc0d6 751 return;
ef8be8ea
AD
752 }
753
ef8be8ea
AD
754 if ($subop == "remove") {
755
b4e75b2a 756 $ids = split(",", db_escape_string($_REQUEST["ids"]));
ef8be8ea 757
810b1561 758 foreach ($ids as $id) {
7e329f13 759 remove_feed($link, $id, $_SESSION["uid"]);
ef8be8ea 760 }
b6a6e262
AD
761
762 return;
ef8be8ea
AD
763 }
764
d1f0c584 765 if ($subop == "clear") {
b4e75b2a 766 $id = db_escape_string($_REQUEST["id"]);
d1f0c584
AD
767 clear_feed_articles($link, $id);
768 }
769
fee840fb 770 if ($subop == "rescore") {
b4e75b2a 771 $ids = split(",", db_escape_string($_REQUEST["ids"]));
fee840fb
AD
772
773 foreach ($ids as $id) {
774
775 $filters = load_filters($link, $id, $_SESSION["uid"], 6);
776
38edb151
AD
777 $result = db_query($link, "SELECT
778 title, content, link, ref_id, author,".
779 SUBSTRING_FOR_DATE."(updated, 1, 19) AS updated
780 FROM
fee840fb
AD
781 ttrss_user_entries, ttrss_entries
782 WHERE ref_id = id AND feed_id = '$id' AND
783 owner_uid = " .$_SESSION['uid']."
ef1b0366 784 ");
fee840fb
AD
785
786 $scores = array();
787
788 while ($line = db_fetch_assoc($result)) {
789
38edb151
AD
790 $tags = get_article_tags($link, $line["ref_id"]);
791
fee840fb 792 $article_filters = get_article_filters($filters, $line['title'],
38edb151
AD
793 $line['content'], $line['link'], strtotime($line['updated']),
794 $line['author'], $tags);
fee840fb
AD
795
796 $new_score = calculate_article_score($article_filters);
797
798 if (!$scores[$new_score]) $scores[$new_score] = array();
799
800 array_push($scores[$new_score], $line['ref_id']);
801 }
802
803 foreach (array_keys($scores) as $s) {
804 if ($s > 1000) {
805 db_query($link, "UPDATE ttrss_user_entries SET score = '$s',
806 marked = true WHERE
95a948a5 807 ref_id IN (" . join(',', $scores[$s]) . ")");
1618a849
AD
808 } else if ($s < -500) {
809 db_query($link, "UPDATE ttrss_user_entries SET score = '$s',
810 unread = false WHERE
811 ref_id IN (" . join(',', $scores[$s]) . ")");
95a948a5
AD
812 } else {
813 db_query($link, "UPDATE ttrss_user_entries SET score = '$s' WHERE
814 ref_id IN (" . join(',', $scores[$s]) . ")");
815 }
816 }
817 }
818
819 print __("All done.");
820
821 }
822
823 if ($subop == "rescoreAll") {
824
825 $result = db_query($link,
826 "SELECT id FROM ttrss_feeds WHERE owner_uid = " . $_SESSION['uid']);
827
828 while ($feed_line = db_fetch_assoc($result)) {
829
830 $id = $feed_line["id"];
831
832 $filters = load_filters($link, $id, $_SESSION["uid"], 6);
833
38edb151
AD
834 $tmp_result = db_query($link, "SELECT
835 title, content, link, ref_id, author,".
836 SUBSTRING_FOR_DATE."(updated, 1, 19) AS updated
837 FROM
95a948a5
AD
838 ttrss_user_entries, ttrss_entries
839 WHERE ref_id = id AND feed_id = '$id' AND
840 owner_uid = " .$_SESSION['uid']."
841 ");
842
843 $scores = array();
844
845 while ($line = db_fetch_assoc($tmp_result)) {
846
38edb151
AD
847 $tags = get_article_tags($link, $line["ref_id"]);
848
95a948a5 849 $article_filters = get_article_filters($filters, $line['title'],
38edb151
AD
850 $line['content'], $line['link'], strtotime($line['updated']),
851 $line['author'], $tags);
852
95a948a5
AD
853 $new_score = calculate_article_score($article_filters);
854
855 if (!$scores[$new_score]) $scores[$new_score] = array();
856
857 array_push($scores[$new_score], $line['ref_id']);
858 }
859
860 foreach (array_keys($scores) as $s) {
861 if ($s > 1000) {
862 db_query($link, "UPDATE ttrss_user_entries SET score = '$s',
863 marked = true WHERE
fee840fb
AD
864 ref_id IN (" . join(',', $scores[$s]) . ")");
865 } else {
866 db_query($link, "UPDATE ttrss_user_entries SET score = '$s' WHERE
867 ref_id IN (" . join(',', $scores[$s]) . ")");
868 }
869 }
870 }
871
872 print __("All done.");
873
874 }
875
ef8be8ea 876 if ($subop == "add") {
ef8be8ea 877
a5819bb3
AD
878 $feed_url = db_escape_string(trim($_REQUEST["feed_url"]));
879 $cat_id = db_escape_string($_REQUEST["cat_id"]);
880 $p_from = db_escape_string($_REQUEST["from"]);
ef8be8ea 881
a5819bb3 882 /* only read authentication information from POST */
aa2122d4 883
a5819bb3
AD
884 $auth_login = db_escape_string(trim($_POST["auth_login"]));
885 $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
aa2122d4 886
a5819bb3
AD
887 if ($p_from != 'tt-rss') {
888 print "<html>
889 <head>
890 <title>Tiny Tiny RSS</title>
891 <link rel=\"stylesheet\" type=\"text/css\" href=\"utility.css\">
892 </head>
893 <body>
894 <img class=\"floatingLogo\" src=\"images/ttrss_logo.png\"
895 alt=\"Tiny Tiny RSS\"/>
896 <h1>Subscribe to feed...</h1>";
897 }
d70c5ae4 898
a5819bb3
AD
899 $rc = subscribe_to_feed($link, $feed_url, $cat_id, $auth_login, $auth_pass);
900
901 switch ($rc) {
902 case 1:
903 print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
904 break;
905 case 2:
906 print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
907 break;
908 case 0:
909 print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
910 break;
911 }
e513a74a 912
a5819bb3
AD
913 if ($p_from != 'tt-rss') {
914 $tt_uri = ($_SERVER['HTTPS'] != "on" ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . preg_replace('/backend\.php.*$/', 'tt-rss.php', $_SERVER["REQUEST_URI"]);
e513a74a 915
e513a74a 916
a5819bb3 917 $tp_uri = ($_SERVER['HTTPS'] != "on" ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . preg_replace('/backend\.php.*$/', 'prefs.php', $_SERVER["REQUEST_URI"]);
6906f145 918
a5819bb3
AD
919 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
920 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
e513a74a 921
a5819bb3 922 $feed_id = db_fetch_result($result, 0, "id");
aa2122d4 923
a5819bb3
AD
924 print "<p>";
925
926 if ($feed_id) {
927 print "<form method=\"GET\" style='display: inline'
928 action=\"$tp_uri\">
929 <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
930 <input type=\"hidden\" name=\"subop\" value=\"editFeed\">
931 <input type=\"hidden\" name=\"subopparam\" value=\"$feed_id\">
932 <input type=\"submit\" value=\"".__("Edit subscription options")."\">
933 </form>";
aa2122d4 934 }
442d77f1 935
a5819bb3
AD
936 print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
937 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
938 </form></p>";
939
940 print "</body></html>";
941 return;
ef8be8ea
AD
942 }
943 }
944
ef8be8ea
AD
945 if ($subop == "categorize") {
946
ef8be8ea 947
913f374b 948 $ids = split(",", db_escape_string($_REQUEST["ids"]));
ef8be8ea 949
913f374b 950 $cat_id = db_escape_string($_REQUEST["cat_id"]);
ef8be8ea 951
913f374b
AD
952 if ($cat_id == 0) {
953 $cat_id_qpart = 'NULL';
954 } else {
955 $cat_id_qpart = "'$cat_id'";
956 }
ef8be8ea 957
913f374b 958 db_query($link, "BEGIN");
ef8be8ea 959
913f374b
AD
960 foreach ($ids as $id) {
961
962 db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
6e63a7c3 963 WHERE id = '$id'
913f374b 964 AND owner_uid = " . $_SESSION["uid"]);
ef8be8ea 965
ef8be8ea
AD
966 }
967
913f374b
AD
968 db_query($link, "COMMIT");
969
ef8be8ea
AD
970 }
971
9c483746
AD
972 if ($subop == "editCats") {
973
9c483746
AD
974 $action = $_REQUEST["action"];
975
976 if ($action == "save") {
977
11f083e7 978 $cat_title = db_escape_string(trim($_REQUEST["value"]));
b4e75b2a 979 $cat_id = db_escape_string($_REQUEST["cid"]);
11f083e7 980
8f708155
AD
981 db_query($link, "BEGIN");
982
983 $result = db_query($link, "SELECT title FROM ttrss_feed_categories
984 WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
985
986 if (db_num_rows($result) == 1) {
987
988 $old_title = db_fetch_result($result, 0, "title");
989
990 if ($cat_title != "") {
991 $result = db_query($link, "UPDATE ttrss_feed_categories SET
992 title = '$cat_title' WHERE id = '$cat_id' AND
993 owner_uid = ".$_SESSION["uid"]);
994
995 print $cat_title;
996 } else {
997 print $old_title;
998 }
999 } else {
1000 print $_REQUEST["value"];
1001 }
1002
1003 db_query($link, "COMMIT");
11f083e7
AD
1004
1005 return;
1006
9c483746
AD
1007 }
1008
1009 if ($action == "add") {
1010
913f374b
AD
1011 $feed_cat = db_escape_string(trim($_REQUEST["cat"]));
1012
5c7c7da9
AD
1013 if (!add_feed_category($link, $feed_cat))
1014 print_warning(T_sprintf("Category <b>$%s</b> already exists in the database.", $feed_cat));
913f374b 1015
9c483746
AD
1016 }
1017
1018 if ($action == "remove") {
1019
b4e75b2a 1020 $ids = split(",", db_escape_string($_REQUEST["ids"]));
9c483746 1021
7e329f13
AD
1022 foreach ($ids as $id) {
1023 remove_feed_category($link, $id, $_SESSION["uid"]);
9c483746
AD
1024 }
1025 }
1026
a8328019 1027 print "<div dojoType=\"dijit.Toolbar\">
da1f74c9
AD
1028 <input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"newcat\">
1029 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedCatEditDlg').addCategory()\">".
1030 __('Create category')."</button></div>";
9c483746
AD
1031
1032 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
1033 WHERE owner_uid = ".$_SESSION["uid"]."
1034 ORDER BY title");
1035
a8328019 1036# print "<p>";
9c483746
AD
1037
1038 if (db_num_rows($result) != 0) {
1039
9c483746
AD
1040 print "<div class=\"prefFeedCatHolder\">";
1041
da1f74c9 1042# print "<form id=\"feed_cat_edit_form\" onsubmit=\"return false\">";
9c483746
AD
1043
1044 print "<table width=\"100%\" class=\"prefFeedCatList\"
1045 cellspacing=\"0\" id=\"prefFeedCatList\">";
9c483746
AD
1046
1047 $lnum = 0;
1048
1049 while ($line = db_fetch_assoc($result)) {
1050
1051 $class = ($lnum % 2) ? "even" : "odd";
1052
1053 $cat_id = $line["id"];
11f083e7 1054 $this_row_id = "id=\"FCATR-$cat_id\"";
9c483746 1055
a8328019 1056 print "<tr class=\"\" $this_row_id>";
9c483746 1057
47439031 1058 $edit_title = htmlspecialchars($line["title"]);
9c483746 1059
11f083e7 1060 print "<td width='5%' align='center'><input
a8328019 1061 onclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\"
22988692 1062 type=\"checkbox\"></td>";
11f083e7 1063
44e05f79 1064 print "<td>";
9c483746 1065
44e05f79
AD
1066# print "<span id=\"FCATT-$cat_id\">" .
1067# $edit_title . "</span>";
1068
1069 print "<span dojoType=\"dijit.InlineEditBox\"
1070 width=\"300px\" autoSave=\"false\"
1071 cat-id=\"$cat_id\">" . $edit_title .
1072 "<script type=\"dojo/method\" event=\"onChange\" args=\"item\">
1073 var elem = this;
1074 dojo.xhrPost({
1075 url: 'backend.php',
1076 content: {op: 'pref-feeds', subop: 'editCats',
1077 action: 'save',
1078 value: this.value,
1079 cid: this.srcNodeRef.getAttribute('cat-id')},
1080 load: function(response) {
1081 elem.attr('value', response);
da1f74c9 1082 updateFeedList();
44e05f79
AD
1083 }
1084 });
1085 </script>
1086 </span>";
1087
1088 print "</td></tr>";
9c483746
AD
1089
1090 ++$lnum;
1091 }
1092
1093 print "</table>";
1094
da1f74c9 1095# print "</form>";
9c483746
AD
1096
1097 print "</div>";
1098
6f5b1e04 1099 } else {
31cc42f6 1100 print "<p>".__('No feed categories defined.')."</p>";
6f5b1e04 1101 }
9c483746 1102
d60009cd
AD
1103 print "<div class='dlgButtons'>
1104 <div style='float : left'>
da1f74c9
AD
1105 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedCatEditDlg').removeSelected()\">".
1106 __('Remove selected categories')."</button>
d60009cd 1107 </div>";
9c483746 1108
da1f74c9 1109 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedCatEditDlg').hide()\">".
d60009cd 1110 __('Close this window')."</button></div>";
9c483746
AD
1111
1112 return;
1113
1114 }
1115
ef8be8ea
AD
1116 if ($quiet) return;
1117
8df7184c 1118 print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
29f11825 1119 print "<div id=\"pref-feeds-feeds\" dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Feeds')."\">";
8df7184c 1120
a3656a41 1121 $result = db_query($link, "SELECT COUNT(id) AS num_errors
ef8be8ea
AD
1122 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1123
a3656a41 1124 $num_errors = db_fetch_result($result, 0, "num_errors");
ef8be8ea 1125
a3656a41 1126 if ($num_errors > 0) {
ef8be8ea 1127
49c6c279
AD
1128 $error_button = "<button dojoType=\"dijit.form.Button\"
1129 onclick=\"showFeedsWithErrors\" id=\"errorButton\">" .
1130 __("Feeds with errors") . "</button>";
1131
1132// print format_notice("<a href=\"javascript:showFeedsWithErrors()\">".
1133// __('Some feeds have update errors (click for details)')."</a>");
ef8be8ea
AD
1134 }
1135
b4e75b2a 1136 $feed_search = db_escape_string($_REQUEST["search"]);
ef8be8ea 1137
b4e75b2a 1138 if (array_key_exists("search", $_REQUEST)) {
ef8be8ea
AD
1139 $_SESSION["prefs_feed_search"] = $feed_search;
1140 } else {
1141 $feed_search = $_SESSION["prefs_feed_search"];
1142 }
1143
8df7184c
AD
1144 print "<div dojoType=\"dijit.Toolbar\">";
1145
1985a5e0 1146 print "<div dojoType=\"dijit.form.DropDownButton\">".
d69fa6d6 1147 "<span>" . __('Select')."</span>";
1985a5e0
AD
1148 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
1149 print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(true)\"
1150 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
1151 print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(false)\"
1152 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
d69fa6d6 1153 print "</div></div>";
1e5548db 1154
7b8a143f
AD
1155 print "<div dojoType=\"dijit.form.DropDownButton\">".
1156 "<span>" . __('Feeds')."</span>";
1157 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
1158 print "<div onclick=\"quickAddFeed()\"
1159 dojoType=\"dijit.MenuItem\">".__('Subscribe to feed')."</div>";
1160 print "<div onclick=\"editSelectedFeed()\"
82aea978 1161 dojoType=\"dijit.MenuItem\">".__('Edit selected feeds')."</div>";
7b8a143f
AD
1162 print "<div onclick=\"resetFeedOrder()\"
1163 dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>";
1164 print "</div></div>";
1e5548db
AD
1165
1166 if (get_pref($link, 'ENABLE_FEED_CATS')) {
7b8a143f
AD
1167 print "<div dojoType=\"dijit.form.DropDownButton\">".
1168 "<span>" . __('Categories')."</span>";
1169 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
1170 print "<div onclick=\"editFeedCats()\"
1171 dojoType=\"dijit.MenuItem\">".__('Edit categories')."</div>";
1172 print "<div onclick=\"resetCatOrder()\"
1173 dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>";
1174 print "</div></div>";
1e5548db 1175
1e5548db
AD
1176 }
1177
49c6c279
AD
1178 print $error_button;
1179
1985a5e0
AD
1180 print "<button dojoType=\"dijit.form.Button\" onclick=\"removeSelectedFeeds()\">"
1181 .__('Unsubscribe')."</button dojoType=\"dijit.form.Button\"> ";
1e5548db 1182
a522a767 1183 if (defined('_ENABLE_FEED_DEBUGGING')) {
ef8be8ea 1184
a522a767
AD
1185 print "<select id=\"feedActionChooser\" onchange=\"feedActionChange()\">
1186 <option value=\"facDefault\" selected>".__('More actions...')."</option>";
1187
1188 if (FORCE_ARTICLE_PURGE == 0) {
1189 print
1190 "<option value=\"facPurge\">".__('Manual purge')."</option>";
1191 }
1192
1193 print "
1194 <option value=\"facClear\">".__('Clear feed data')."</option>
1195 <option value=\"facRescore\">".__('Rescore articles')."</option>";
1196
1197 print "</select>";
0b9751cd 1198
a522a767 1199 }
0b9751cd 1200
8df7184c
AD
1201 print "</div>"; # toolbar
1202
1985a5e0
AD
1203 print "<div id=\"feedlistLoading\">
1204 <img src='images/indicator_tiny.gif'>".
1205 __("Loading, please wait...")."</div>";
1206
7b8a143f
AD
1207 print "<div dojoType=\"fox.PrefFeedStore\" jsId=\"feedStore\"
1208 url=\"backend.php?op=pref-feeds&subop=getfeedtree\">
1985a5e0
AD
1209 </div>
1210 <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"feedModel\" store=\"feedStore\"
1211 query=\"{id:'root'}\" rootId=\"root\" rootLabel=\"Feeds\"
1212 childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">
1213 </div>
2148e0d5
AD
1214 <div dojoType=\"fox.PrefFeedTree\" id=\"feedTree\"
1215 dndController=\"dijit.tree.dndSource\"
7b8a143f 1216 betweenThreshold=\"5\"
1985a5e0
AD
1217 model=\"feedModel\" openOnClick=\"false\">
1218 <script type=\"dojo/method\" event=\"onClick\" args=\"item\">
1219 var id = String(item.id);
1220 var bare_id = id.substr(id.indexOf(':')+1);
1221
7b8a143f 1222 if (id.match('FEED:')) {
1985a5e0 1223 editFeed(bare_id, event);
7b8a143f
AD
1224 } else if (id.match('CAT:')) {
1225 editCat(bare_id, item, event);
1226 }
1985a5e0
AD
1227 </script>
1228 <script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
1229 Element.hide(\"feedlistLoading\");
1230 </script>
1985a5e0
AD
1231 </div>";
1232
a740f4b5
AD
1233 print "<div dojoType=\"dijit.Tooltip\" connectId=\"feedTree\" position=\"below\">
1234 <b>Hint:</b> you can drag feeds and categories around.
1235 </div>";
1236
8df7184c 1237 print "</div>"; # feeds pane
94a4ba88 1238
8df7184c 1239 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('OPML')."\">";
b6a6e262 1240
00a35bb6
AD
1241 print "<p>" . __("Using OPML you can export and import your feeds and Tiny Tiny RSS settings.");
1242
254ac705 1243 print "<div class=\"insensitive\">" . __("Note: Only main settings profile can be migrated using OPML.") . "</div>";
c107797c 1244
00a35bb6
AD
1245 print "</p>";
1246
e1218480
AD
1247 print "<iframe id=\"upload_iframe\"
1248 name=\"upload_iframe\" onload=\"opmlImportComplete(this)\"
b6a6e262
AD
1249 style=\"width: 400px; height: 100px; display: none;\"></iframe>";
1250
b6a6e262
AD
1251 print "<form style='display : block' target=\"upload_iframe\"
1252 enctype=\"multipart/form-data\" method=\"POST\"
1253 action=\"backend.php\">
1254 <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
1255 <input type=\"hidden\" name=\"op\" value=\"dlg\">
1256 <input type=\"hidden\" name=\"id\" value=\"importOpml\">
d2d75353 1257 <button dojoType=\"dijit.form.Button\" onclick=\"return opmlImport();\"
b6a6e262 1258 type=\"submit\">".__('Import')."</button>
d2d75353 1259 <button dojoType=\"dijit.form.Button\" onclick=\"gotoExportOpml()\">".__('Export OPML')."</button>
b6a6e262 1260 </form>";
94a4ba88 1261
c107797c
AD
1262 print "<p>".__('Your OPML can be published publicly and can be subscribed by anyone who knows the URL below.');
1263
1264 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 1265
d2d75353 1266 print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('pubOPMLUrl')\">".
c107797c
AD
1267 __('Display URL')."</button> ";
1268
1269
8df7184c
AD
1270 print "</div>"; # pane
1271
68313e5d 1272 if (strpos($_SERVER['HTTP_USER_AGENT'], "Firefox") !== false) {
8df7184c
AD
1273
1274 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Firefox integration')."\">";
755a43ee 1275
c107797c 1276 print "<p>" . __('This Tiny Tiny RSS site can be used as a Firefox Feed Reader by clicking the link below.') . "</p>";
cf9dc032 1277
68313e5d 1278 print "<p>";
cf9dc032 1279
c107797c 1280 print "<button onclick='window.navigator.registerContentHandler(" .
755a43ee
AD
1281 "\"application/vnd.mozilla.maybe.feed\", " .
1282 "\"" . add_feed_url() . "\", " . " \"Tiny Tiny RSS\")'>" .
cf9dc032
AD
1283 __('Click here to register this site as a feed reader.') .
1284 "</button>";
755a43ee 1285
c107797c 1286 print "</p>";
755a43ee 1287
8df7184c
AD
1288 print "</div>"; # pane
1289 }
46dc1538 1290
8df7184c
AD
1291 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Subscribing using bookmarklet')."\">";
1292
46dc1538
AD
1293 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>";
1294
1295 $bm_subscribe_url = str_replace('%s', '', add_feed_url());
1296
1297 $confirm_str = __('Subscribe to %s in Tiny Tiny RSS?');
1298
1299 $bm_url = htmlspecialchars("javascript:{if(confirm('$confirm_str'.replace('%s',window.location.href)))window.location.href='$bm_subscribe_url'+window.location.href}");
1300
d2d75353 1301 print "<a href=\"$bm_url\" class='bookmarklet'>" . __('Subscribe in Tiny Tiny RSS'). "</a>";
46dc1538 1302
8df7184c
AD
1303 print "</div>"; #pane
1304
1305 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Published articles and generated feeds')."\">";
e4f4b46f 1306
e635d56a 1307 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 1308
8801fb01
AD
1309 $rss_url = '-2::' . htmlspecialchars(get_self_url_prefix() .
1310 "/backend.php?op=rss&id=-2&view-mode=all_articles");;
1311
d2d75353 1312 print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('generatedFeed', '$rss_url')\">".
cf9dc032 1313 __('Display URL')."</button> ";
c107797c 1314
d2d75353 1315 print "<button dojoType=\"dijit.form.Button\" onclick=\"return clearFeedAccessKeys()\">".
8d86f15f 1316 __('Clear all generated URLs')."</button> ";
e4f4b46f 1317
8df7184c
AD
1318 print "</div>"; #pane
1319 print "</div>"; #container
1320
ef8be8ea 1321 }
b56465dd 1322
082ae95b 1323 function print_feed_browser($link, $search, $limit, $mode = 1) {
b56465dd 1324
c2913898
AD
1325 $owner_uid = $_SESSION["uid"];
1326
1327 if ($search) {
1328 $search_qpart = "AND (UPPER(feed_url) LIKE UPPER('%$search%') OR
1329 UPPER(title) LIKE UPPER('%$search%'))";
1330 } else {
1331 $search_qpart = "";
1332 }
1333
082ae95b
AD
1334 if ($mode == 1) {
1335 $result = db_query($link, "SELECT feed_url, subscribers FROM
1336 ttrss_feedbrowser_cache WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf
1337 WHERE tf.feed_url = ttrss_feedbrowser_cache.feed_url
1338 AND owner_uid = '$owner_uid') $search_qpart
1339 ORDER BY subscribers DESC LIMIT $limit");
1340 } else if ($mode == 2) {
ef88b1cc
AD
1341 $result = db_query($link, "SELECT *,
1342 (SELECT COUNT(*) FROM ttrss_user_entries WHERE
1343 orig_feed_id = ttrss_archived_feeds.id) AS articles_archived
1344 FROM
1345 ttrss_archived_feeds
1346 WHERE
082ae95b
AD
1347 (SELECT COUNT(*) FROM ttrss_feeds
1348 WHERE ttrss_feeds.feed_url = ttrss_archived_feeds.feed_url AND
1349 owner_uid = '$owner_uid') = 0 AND
1350 owner_uid = '$owner_uid' $search_qpart
1351 ORDER BY id DESC LIMIT $limit");
1352 }
b56465dd
AD
1353
1354 $feedctr = 0;
1355
1356 while ($line = db_fetch_assoc($result)) {
b56465dd 1357
082ae95b 1358 if ($mode == 1) {
b56465dd 1359
2211a391 1360 $feed_url = $line["feed_url"];
082ae95b 1361 $subscribers = $line["subscribers"];
2211a391 1362
082ae95b
AD
1363 $det_result = db_query($link, "SELECT site_url,title,id
1364 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
1365
1366 $details = db_fetch_assoc($det_result);
1367
1368 $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico";
1369
1370 if (file_exists($icon_file) && filesize($icon_file) > 0) {
a8328019 1371 $feed_icon = "<img style=\"vertical-align : middle\" class=\"tinyFeedIcon\" src=\"" . ICONS_URL .
082ae95b
AD
1372 "/".$details["id"].".ico\">";
1373 } else {
1374 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1375 }
1376
a8328019
AD
1377 $check_box = "<input onclick='toggleSelectListRow2(this)'
1378 dojoType=\"dijit.form.CheckBox\"
11b9d0be 1379 type=\"checkbox\" \">";
082ae95b
AD
1380
1381 $class = ($feedctr % 2) ? "even" : "odd";
1382
2211a391
AD
1383 $feed_url = htmlspecialchars($line["feed_url"]);
1384
082ae95b 1385 if ($details["site_url"]) {
ef88b1cc
AD
1386 $site_url = "<a target=\"_blank\" href=\"".
1387 htmlspecialchars($details["site_url"])."\">
082ae95b
AD
1388 <img style='border-width : 0px' src='images/www.png' alt='www'></a>";
1389 } else {
1390 $site_url = "";
1391 }
e15bb6f7
AD
1392
1393 $feed_url = "<a target=\"_blank\" href=\"$feed_url\"><img
1394 style='border-width : 0px; vertical-align : middle'
1395 src='images/feed-icon-12x12.png'></a>";
1396
ef88b1cc 1397 print "<li title=\"".htmlspecialchars($details["site_url"])."\"
a8328019 1398 id=\"FBROW-".$details["id"]."\">$check_box".
e15bb6f7 1399 "$feed_icon $feed_url " . htmlspecialchars($details["title"]) .
082ae95b 1400 "&nbsp;<span class='subscribers'>($subscribers)</span>
ef88b1cc 1401 $site_url</li>";
082ae95b
AD
1402
1403 } else if ($mode == 2) {
ef88b1cc
AD
1404 $feed_url = htmlspecialchars($line["feed_url"]);
1405 $site_url = htmlspecialchars($line["site_url"]);
1406 $title = htmlspecialchars($line["title"]);
69877646
AD
1407
1408 $icon_file = ICONS_DIR . "/" . $line["id"] . ".ico";
082ae95b 1409
69877646
AD
1410 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1411 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL .
1412 "/".$line["id"].".ico\">";
1413 } else {
1414 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1415 }
1416
11b9d0be
AD
1417 $check_box = "<input onclick='toggleSelectListRow2(this)' dojoType=\"dijit.form.CheckBox\"
1418 type=\"checkbox\">";
082ae95b
AD
1419
1420 $class = ($feedctr % 2) ? "even" : "odd";
ef88b1cc
AD
1421
1422 if ($line['articles_archived'] > 0) {
1423 $archived = sprintf(__("%d archived articles"), $line['articles_archived']);
1424 $archived = "&nbsp;<span class='subscribers'>($archived)</span>";
1425 } else {
1426 $archived = '';
1427 }
1428
082ae95b 1429 if ($line["site_url"]) {
ef88b1cc 1430 $site_url = "<a target=\"_blank\" href=\"$site_url\">
082ae95b
AD
1431 <img style='border-width : 0px' src='images/www.png' alt='www'></a>";
1432 } else {
1433 $site_url = "";
1434 }
e15bb6f7
AD
1435
1436 $feed_url = "<a target=\"_blank\" href=\"$feed_url\"><img
1437 style='border-width : 0px; vertical-align : middle'
1438 src='images/feed-icon-12x12.png'></a>";
1439
ef88b1cc
AD
1440 print "<li title='".$line['site_url']."' class='$class'
1441 id=\"FBROW-".$line["id"]."\">".
e15bb6f7
AD
1442 $check_box . "$feed_icon $feed_url " . $title .
1443 $archived . $site_url . "</li>";
b56465dd 1444
b56465dd 1445
2bab8824
AD
1446 }
1447
082ae95b 1448 ++$feedctr;
b56465dd
AD
1449 }
1450
1451 if ($feedctr == 0) {
1452 print "<li style=\"text-align : center\"><p>".__('No feeds found.')."</p></li>";
1453 }
1454
1455 return $feedctr;
1456
1457 }
a5819bb3 1458
ef8be8ea 1459?>