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