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