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