]> git.wh0rd.org Git - tt-rss.git/blob - modules/pref-feeds.php
Merge branch 'master' of /home/fox/public_html/testbox/tt-rss
[tt-rss.git] / modules / pref-feeds.php
1 <?php
2
3         function batch_edit_cbox($elem, $label = false) {
4                 print "<input type=\"checkbox\" title=\"".__("Check to enable field")."\"
5                         onchange=\"batchFeedsToggleField(this, '$elem', '$label')\">";
6         }
7
8         function module_pref_feeds($link) {
9
10                 global $update_intervals;
11                 global $purge_intervals;
12                 global $update_methods;
13
14                 $subop = $_REQUEST["subop"];
15                 $quiet = $_REQUEST["quiet"];
16
17                 if ($subop == "massSubscribe") {
18                         $ids = split(",", db_escape_string($_GET["ids"]));
19
20                         $subscribed = array();
21
22                         foreach ($ids as $id) {
23                                 $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds
24                                         WHERE id = '$id'");
25
26                                 $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url"));
27                                 $title = db_escape_string(db_fetch_result($result, 0, "title"));
28
29                                 $title_orig = db_fetch_result($result, 0, "title");
30
31                                 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
32                                         feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
33
34                                 if (db_num_rows($result) == 0) {                        
35                                         $result = db_query($link,
36                                                 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id) 
37                                                 VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)");
38
39                                         array_push($subscribed, $title_orig);
40                                 }
41                         }
42
43                         if (count($subscribed) > 0) {
44                                 $msg = "<b>".__('Subscribed to feeds:')."</b>".
45                                         "<ul class=\"nomarks\">";
46
47                                 foreach ($subscribed as $title) {
48                                         $msg .= "<li>$title</li>";
49                                 }
50                                 $msg .= "</ul>";
51
52                                 print format_notice($msg);
53                         }
54                 }               
55
56                 if ($subop == "browse") {
57
58                         if (!ENABLE_FEED_BROWSER) {
59                                 print __("Feed browser is administratively disabled.");
60                                 return;
61                         }
62
63                         print "<div id=\"infoBoxTitle\">".__('Feed Browser')."</div>";
64                         
65                         print "<div class=\"infoBoxContents\">";
66
67                         $browser_search = db_escape_string($_GET["search"]);
68
69                         //print "<p>".__("Showing top 25 registered feeds, sorted by popularity:")."</p>";
70
71                         print "
72                                 <div style='float : right'>
73                                 <input id=\"feed_browser_search\" size=\"20\" type=\"search\"
74                                 onfocus=\"javascript:disableHotkeys();\" 
75                                 onblur=\"javascript:enableHotkeys();\"
76                                 onchange=\"javascript:updateFeedBrowser()\" value=\"$browser_search\">
77                         <input type=\"submit\" class=\"button\" 
78                                 onclick=\"javascript:updateFeedBrowser()\" value=\"".__('Search')."\">
79                         </div>";
80
81                         print __('Top')." <select id=\"feed_browser_limit\">";
82
83                         foreach (array(25, 50, 100, 200) as $l) {
84                                 $issel = ($l == $limit) ? "selected" : "";
85                                 print "<option $issel>$l</option>";
86                         }
87                         
88                         print "</select>
89                                 <input type=\"submit\" class=\"button\"
90                                         onclick=\"updateFeedBrowser()\" value=\"".__('Show')."\">";
91
92                         print "<p>";
93
94                         $owner_uid = $_SESSION["uid"];
95
96                         print "<ul class='browseFeedList' id='browseFeedList'>";
97                         $subscribe_btn_disabled = print_feed_browser($link, $search, 25) == 0 ? "disabled" : "";
98                         print "</ul>";
99
100                         print "<div align='center'>
101                                 <input type=\"submit\" class=\"button\" id=\"feed_browser_subscribe\"
102                                 $subscribe_btn_disabled
103                                 onclick=\"feedBrowserSubscribe()\" value=\"".__('Subscribe')."\">
104                                 <input type='submit' class='button'                     
105                                 onclick=\"closeInfoBox()\" value=\"".__('Cancel')."\"></div>";
106
107                         print "</div>";
108                         return;
109                 }
110
111                 if ($subop == "editfeed") {
112                         $feed_id = db_escape_string($_REQUEST["id"]);
113
114                         $result = db_query($link, 
115                                 "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND
116                                         owner_uid = " . $_SESSION["uid"]);
117
118                         $title = htmlspecialchars(db_fetch_result($result,
119                                 0, "title"));
120
121                         $icon_file = ICONS_DIR . "/$feed_id.ico";
122         
123                         if (file_exists($icon_file) && filesize($icon_file) > 0) {
124                                         $feed_icon = "<img width=\"16\" height=\"16\"
125                                                 src=\"" . ICONS_URL . "/$feed_id.ico\">";
126                         } else {
127                                 $feed_icon = "";
128                         }
129
130                         print "<div id=\"infoBoxTitle\">".__('Feed Editor')."</div>";
131
132                         print "<div class=\"infoBoxContents\">";
133
134                         print "<form id=\"edit_feed_form\" onsubmit=\"return false\">"; 
135
136                         print "<input type=\"hidden\" name=\"id\" value=\"$feed_id\">";
137                         print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
138                         print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
139
140                         print "<div class=\"dlgSec\">".__("Feed")."</div>";
141                         print "<div class=\"dlgSecCont\">";
142
143                         /* Title */
144
145                         print "<input style=\"font-size : 16px\" size=\"40\" onkeypress=\"return filterCR(event, feedEditSave)\"
146                                             name=\"title\" value=\"$title\">";
147
148                         /* Feed URL */
149
150                         $feed_url = db_fetch_result($result, 0, "feed_url");
151                         $feed_url = htmlspecialchars(db_fetch_result($result,
152                                 0, "feed_url"));
153
154                         print "<br/>";
155
156                         print __('URL:') . " ";
157                         print "<input size=\"40\" onkeypress=\"return filterCR(event, feedEditSave)\"
158                                 name=\"feed_url\" value=\"$feed_url\">";
159
160                         /* Category */
161
162                         if (get_pref($link, 'ENABLE_FEED_CATS')) {
163
164                                 $cat_id = db_fetch_result($result, 0, "cat_id");
165
166                                 print "<br/>";
167
168                                 print __('Place in category:') . " ";
169
170                                 $parent_feed = db_fetch_result($result, 0, "parent_feed");
171
172                                 if (sprintf("%d", $parent_feed) > 0) {
173                                         $disabled = "disabled";
174                                 } else {
175                                         $disabled = "";
176                                 }
177
178                                 print_feed_cat_select($link, "cat_id", $cat_id, $disabled);
179                         }
180
181                         /* Link to */
182
183                         print "<br/>";
184
185                         print __('Link to feed:') . " ";
186
187                         $tmp_result = db_query($link, "SELECT COUNT(id) AS count
188                                 FROM ttrss_feeds WHERE parent_feed = '$feed_id'");
189
190                         $linked_count = db_fetch_result($tmp_result, 0, "count");
191
192                         $parent_feed = db_fetch_result($result, 0, "parent_feed");
193
194                         if ($linked_count > 0) {
195                                 $disabled = "disabled";
196                         } else {
197                                 $disabled = "";
198                         }
199
200                         print "<select $disabled name=\"parent_feed\">";
201                         
202                         print "<option value=\"0\">".__('Not linked')."</option>";
203
204                         if (get_pref($link, 'ENABLE_FEED_CATS')) {
205                                 if ($cat_id) {
206                                         $cat_qpart = "AND cat_id = '$cat_id'";
207                                 } else {
208                                         $cat_qpart = "AND cat_id IS NULL";
209                                 }
210                         }
211
212                         $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
213                                 WHERE id != '$feed_id' AND owner_uid = ".$_SESSION["uid"]." AND
214                                         (SELECT COUNT(id) FROM ttrss_feeds AS T2 WHERE T2.id = ttrss_feeds.parent_feed) = 0
215                                         $cat_qpart ORDER BY title");
216
217                                 if (db_num_rows($tmp_result) > 0) {
218                                         print "<option disabled>--------</option>";
219                                 }
220
221                                 while ($tmp_line = db_fetch_assoc($tmp_result)) {
222                                         if ($tmp_line["id"] == $parent_feed) {
223                                                 $is_selected = "selected";
224                                         } else {
225                                                 $is_selected = "";
226                                         }
227
228                                         $title = truncate_string(htmlspecialchars($tmp_line["title"]), 40);
229
230                                         printf("<option $is_selected value='%d'>%s</option>", 
231                                                 $tmp_line["id"], $title);
232                                 }
233
234                         print "</select>";
235
236
237                         print "</div>";
238
239                         print "<div class=\"dlgSec\">".__("Update")."</div>";
240                         print "<div class=\"dlgSecCont\">";
241
242                         /* Update Interval */
243
244                         $update_interval = db_fetch_result($result, 0, "update_interval");
245
246                         print_select_hash("update_interval", $update_interval, $update_intervals);
247
248                         /* Update method */
249
250                         if (ALLOW_SELECT_UPDATE_METHOD) {
251                                 $update_method = db_fetch_result($result, 0, "update_method");
252
253                                 print " " . __('using') . " ";
254                                 print_select_hash("update_method", $update_method, $update_methods);                    
255                         }
256
257                         $purge_interval = db_fetch_result($result, 0, "purge_interval");
258
259                         if (FORCE_ARTICLE_PURGE == 0) {
260
261                                 /* Purge intl */
262
263                                 print "<br/>";
264
265                                 print __('Article purging:') . " ";
266
267                                 print_select_hash("purge_interval", $purge_interval, $purge_intervals);
268
269                         } else {
270                                 print "<input type='hidden' name='purge_interval' value='$purge_interval'>";
271
272                         }
273
274                         print "</div>";
275                         print "<div class=\"dlgSec\">".__("Authentication")."</div>";
276                         print "<div class=\"dlgSecCont\">";
277
278                         $auth_login = htmlspecialchars(db_fetch_result($result, 0, "auth_login"));
279
280                         print "<table>";
281
282                         print "<tr><td>" . __('Login:') . "</td><td>";
283
284                         print "<input size=\"20\" onkeypress=\"return filterCR(event, feedEditSave)\"
285                                 name=\"auth_login\" value=\"$auth_login\">";
286
287                         print "</tr><tr><td>" . __("Password:") . "</td><td>";
288
289                         $auth_pass = htmlspecialchars(db_fetch_result($result, 0, "auth_pass"));
290
291                         print "<input size=\"20\" type=\"password\" name=\"auth_pass\" 
292                                 onkeypress=\"return filterCR(event, feedEditSave)\"
293                                 value=\"$auth_pass\">";
294
295                         print "</td></tr></table>";
296
297                         print "</div>";
298                         print "<div class=\"dlgSec\">".__("Options")."</div>";
299                         print "<div class=\"dlgSecCont\">";
300
301                         print "<div style=\"line-height : 100%\">";
302
303                         $private = sql_bool_to_bool(db_fetch_result($result, 0, "private"));
304
305                         if ($private) {
306                                 $checked = "checked";
307                         } else {
308                                 $checked = "";
309                         }
310
311                         print "<input type=\"checkbox\" name=\"private\" id=\"private\" 
312                                 $checked>&nbsp;<label for=\"private\">".__('Hide from "Other Feeds"')."</label>";
313
314                         $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
315
316                         if ($rtl_content) {
317                                 $checked = "checked";
318                         } else {
319                                 $checked = "";
320                         }
321
322                         print "<br/><input type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"
323                                 $checked>&nbsp;<label for=\"rtl_content\">".__('Right-to-left content')."</label>";
324
325                         $hidden = sql_bool_to_bool(db_fetch_result($result, 0, "hidden"));
326
327                         if ($hidden) {
328                                 $checked = "checked";
329                         } else {
330                                 $checked = "";
331                         }
332
333                         print "<br/><input type=\"checkbox\" id=\"hidden\" name=\"hidden\"
334                                 $checked>&nbsp;<label for=\"hidden\">".__('Hide from my feed list')."</label>";
335
336                         $include_in_digest = sql_bool_to_bool(db_fetch_result($result, 0, "include_in_digest"));
337
338                         if ($include_in_digest) {
339                                 $checked = "checked";
340                         } else {
341                                 $checked = "";
342                         }
343
344                         print "<br/><input type=\"checkbox\" id=\"include_in_digest\" 
345                                 name=\"include_in_digest\"
346                                 $checked>&nbsp;<label for=\"include_in_digest\">".__('Include in e-mail digest')."</label>";
347
348
349                         $always_display_enclosures = sql_bool_to_bool(db_fetch_result($result, 0, "always_display_enclosures"));
350
351                         if ($always_display_enclosures) {
352                                 $checked = "checked";
353                         } else {
354                                 $checked = "";
355                         }
356
357                         print "<br/><input type=\"checkbox\" id=\"always_display_enclosures\" 
358                                 name=\"always_display_enclosures\"
359                                 $checked>&nbsp;<label for=\"always_display_enclosures\">".__('Always display image attachments')."</label>";
360
361
362                         $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
363
364                         if ($cache_images) {
365                                 $checked = "checked";
366                         } else {
367                                 $checked = "";
368                         }
369
370                         if (ENABLE_SIMPLEPIE && SIMPLEPIE_CACHE_IMAGES) {
371                                 $disabled = "";
372                                 $label_class = "";
373                         } else {
374                                 $disabled = "disabled";
375                                 $label_class = "class='insensitive'";
376                         }
377
378                         print "<br/><input type=\"checkbox\" id=\"cache_images\" 
379                                 name=\"cache_images\" $disabled
380                                 $checked>&nbsp;<label $label_class for=\"cache_images\">".
381                                 __('Cache images locally')."</label>";
382
383
384                         print "</div>";
385                         print "</div>";
386
387                         print "</form>";
388
389                         $title = htmlspecialchars($title, ENT_QUOTES);
390
391                         print "<div class='dlgButtons'>
392                                 <div style=\"float : left\">
393                                         <input type='submit' class='button'                     
394                                         onclick='return unsubscribeFeed($feed_id, \"$title\")' value=\"".__('Unsubscribe')."\">
395                                 </div>
396                                 <input type=\"submit\" class=\"button\" 
397                                 onclick=\"return feedEditSave()\" value=\"".__('Save')."\">
398                                 <input type='submit' class='button'                     
399                                 onclick=\"return feedEditCancel()\" value=\"".__('Cancel')."\">
400                                 </div>";
401
402                         return;
403                 }
404
405                 if ($subop == "editfeeds") {
406
407                         $feed_ids = db_escape_string($_REQUEST["ids"]);
408
409                         print "<div id=\"infoBoxTitle\">".__('Multiple Feed Editor')."</div>";
410
411                         print "<div class=\"infoBoxContents\">";
412
413                         print "<form id=\"batch_edit_feed_form\" onsubmit=\"return false\">";   
414
415                         print "<input type=\"hidden\" name=\"ids\" value=\"$feed_ids\">";
416                         print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
417                         print "<input type=\"hidden\" name=\"subop\" value=\"batchEditSave\">";
418
419                         print "<div class=\"dlgSec\">".__("Feed")."</div>";
420                         print "<div class=\"dlgSecCont\">";
421
422                         /* Title */
423
424                         print "<input disabled style=\"font-size : 16px\" size=\"35\" onkeypress=\"return filterCR(event, feedEditSave)\"
425                                             name=\"title\" value=\"$title\">";
426
427                         batch_edit_cbox("title");
428
429                         /* Feed URL */
430
431                         print "<br/>";
432
433                         print __('URL:') . " ";
434                         print "<input disabled size=\"40\" onkeypress=\"return filterCR(event, feedEditSave)\"
435                                 name=\"feed_url\" value=\"$feed_url\">";
436
437                         batch_edit_cbox("feed_url");
438
439                         /* Category */
440
441                         if (get_pref($link, 'ENABLE_FEED_CATS')) {
442
443                                 print "<br/>";
444
445                                 print __('Place in category:') . " ";
446
447                                 print_feed_cat_select($link, "cat_id", $cat_id, "disabled");
448
449                                 batch_edit_cbox("cat_id");
450
451                         }
452
453                         print "</div>";
454
455                         print "<div class=\"dlgSec\">".__("Update")."</div>";
456                         print "<div class=\"dlgSecCont\">";
457
458                         /* Update Interval */
459
460                         print_select_hash("update_interval", $update_interval, $update_intervals, 
461                                 "disabled");
462
463                         batch_edit_cbox("update_interval");
464
465                         /* Update method */
466
467                         if (ALLOW_SELECT_UPDATE_METHOD) {
468                                 print " " . __('using') . " ";
469                                 print_select_hash("update_method", $update_method, $update_methods, 
470                                         "disabled");                    
471                                 batch_edit_cbox("update_method");
472                         }
473
474                         /* Purge intl */
475
476                         if (FORCE_ARTICLE_PURGE != 0) {
477
478                                 print "<br/>";
479
480                                 print __('Article purging:') . " ";
481
482                                 print_select_hash("purge_interval", $purge_interval, $purge_intervals,
483                                         "disabled");
484
485                                 batch_edit_cbox("purge_interval");
486                         }
487
488                         print "</div>";
489                         print "<div class=\"dlgSec\">".__("Authentication")."</div>";
490                         print "<div class=\"dlgSecCont\">";
491
492                         print __('Login:') . " ";
493                         print "<input disabled size=\"15\" onkeypress=\"return filterCR(event, feedEditSave)\"
494                                 name=\"auth_login\" value=\"$auth_login\">";
495
496                         batch_edit_cbox("auth_login");
497
498                         print " " . __("Password:") . " ";
499
500                         print "<input disabled size=\"15\" type=\"password\" name=\"auth_pass\" 
501                                 onkeypress=\"return filterCR(event, feedEditSave)\"
502                                 value=\"$auth_pass\">";
503
504                         batch_edit_cbox("auth_pass");
505
506                         print "</div>";
507                         print "<div class=\"dlgSec\">".__("Options")."</div>";
508                         print "<div class=\"dlgSecCont\">";
509
510                         print "<div style=\"line-height : 100%\">";
511
512                         print "<input disabled type=\"checkbox\" name=\"private\" id=\"private\" 
513                                 $checked>&nbsp;<label id=\"private_l\" class='insensitive' for=\"private\">".__('Hide from "Other Feeds"')."</label>";
514
515                         print "&nbsp;"; batch_edit_cbox("private", "private_l");
516
517                         print "<br/><input disabled type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"
518                                 $checked>&nbsp;<label class='insensitive' id=\"rtl_content_l\" for=\"rtl_content\">".__('Right-to-left content')."</label>";
519
520                         print "&nbsp;"; batch_edit_cbox("rtl_content", "rtl_content_l");
521
522                         print "<br/><input disabled type=\"checkbox\" id=\"hidden\" name=\"hidden\"
523                                 $checked>&nbsp;<label class='insensitive' id=\"hidden_l\" for=\"hidden\">".__('Hide from my feed list')."</label>";
524
525                         print "&nbsp;"; batch_edit_cbox("hidden", "hidden_l");
526
527                         print "<br/><input disabled type=\"checkbox\" id=\"include_in_digest\" 
528                                 name=\"include_in_digest\" 
529                                 $checked>&nbsp;<label id=\"include_in_digest_l\" class='insensitive' for=\"include_in_digest\">".__('Include in e-mail digest')."</label>";
530
531                         print "&nbsp;"; batch_edit_cbox("include_in_digest", "include_in_digest_l");
532
533                         print "<br/><input disabled type=\"checkbox\" id=\"always_display_enclosures\" 
534                                 name=\"always_display_enclosures\" 
535                                 $checked>&nbsp;<label id=\"always_display_enclosures_l\" class='insensitive' for=\"always_display_enclosures\">".__('Always display image attachments')."</label>";
536
537                         print "&nbsp;"; batch_edit_cbox("always_display_enclosures", "always_display_enclosures_l");
538
539                         print "<br/><input disabled type=\"checkbox\" id=\"cache_images\" 
540                                 name=\"cache_images\" 
541                                 $checked>&nbsp;<label class='insensitive' id=\"cache_images_l\" 
542                                         for=\"cache_images\">".
543                                 __('Cache images locally')."</label>";
544
545
546                         if (ENABLE_SIMPLEPIE && SIMPLEPIE_CACHE_IMAGES) {
547                                 print "&nbsp;"; batch_edit_cbox("cache_images", "cache_images_l");
548                         }
549
550                         print "</div>";
551                         print "</div>";
552
553                         print "</form>";
554
555                         print "<div class='dlgButtons'>
556                                 <input type=\"submit\" class=\"button\" 
557                                 onclick=\"return feedsEditSave()\" value=\"".__('Save')."\">
558                                 <input type='submit' class='button'                     
559                                 onclick=\"return feedEditCancel()\" value=\"".__('Cancel')."\">
560                                 </div>";
561
562                         return;
563                 }
564
565                 if ($subop == "editSave" || $subop == "batchEditSave") {
566
567                         $feed_title = db_escape_string(trim($_POST["title"]));
568                         $feed_link = db_escape_string(trim($_POST["feed_url"]));
569                         $upd_intl = db_escape_string($_POST["update_interval"]);
570                         $purge_intl = db_escape_string($_POST["purge_interval"]);
571                         $feed_id = db_escape_string($_POST["id"]); /* editSave */
572                         $feed_ids = db_escape_string($_POST["ids"]); /* batchEditSave */
573                         $cat_id = db_escape_string($_POST["cat_id"]);
574                         $auth_login = db_escape_string(trim($_POST["auth_login"]));
575                         $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
576                         $parent_feed = db_escape_string($_POST["parent_feed"]);
577                         $private = checkbox_to_sql_bool(db_escape_string($_POST["private"]));
578                         $rtl_content = checkbox_to_sql_bool(db_escape_string($_POST["rtl_content"]));
579                         $hidden = checkbox_to_sql_bool(db_escape_string($_POST["hidden"]));
580                         $include_in_digest = checkbox_to_sql_bool(
581                                 db_escape_string($_POST["include_in_digest"]));
582                         $cache_images = checkbox_to_sql_bool(
583                                 db_escape_string($_POST["cache_images"]));
584                         $update_method = (int) db_escape_string($_POST["update_method"]);
585
586                         $always_display_enclosures = checkbox_to_sql_bool(
587                                 db_escape_string($_POST["always_display_enclosures"]));
588
589                         if (get_pref($link, 'ENABLE_FEED_CATS')) {                      
590                                 if ($cat_id && $cat_id != 0) {
591                                         $category_qpart = "cat_id = '$cat_id',";
592                                         $category_qpart_nocomma = "cat_id = '$cat_id'";
593                                 } else {
594                                         $category_qpart = 'cat_id = NULL,';
595                                         $category_qpart_nocomma = 'cat_id = NULL';
596                                 }
597                         } else {
598                                 $category_qpart = "";
599                                 $category_qpart_nocomma = "";
600                         }
601
602                         if ($parent_feed && $parent_feed != 0) {
603                                 $parent_qpart = "parent_feed = '$parent_feed'";
604                         } else {
605                                 $parent_qpart = 'parent_feed = NULL';
606                         }
607
608                         if (ENABLE_SIMPLEPIE && SIMPLEPIE_CACHE_IMAGES) {
609                                 $cache_images_qpart = "cache_images = $cache_images,";
610                         } else {
611                                 $cache_images_qpart = "";
612                         }
613
614                         if ($subop == "editSave") {
615
616                                 $result = db_query($link, "UPDATE ttrss_feeds SET 
617                                         $category_qpart $parent_qpart,
618                                         title = '$feed_title', feed_url = '$feed_link',
619                                         update_interval = '$upd_intl',
620                                         purge_interval = '$purge_intl',
621                                         auth_login = '$auth_login',
622                                         auth_pass = '$auth_pass',
623                                         private = $private,
624                                         rtl_content = $rtl_content,
625                                         hidden = $hidden,
626                                         $cache_images_qpart
627                                         include_in_digest = $include_in_digest,
628                                         always_display_enclosures = $always_display_enclosures,
629                                         update_method = '$update_method'
630                                         WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
631
632                                 if (get_pref($link, 'ENABLE_FEED_CATS')) {
633                                         # update linked feed categories
634                                         $result = db_query($link, "UPDATE ttrss_feeds SET
635                                                 $category_qpart_nocomma WHERE parent_feed = '$feed_id' AND
636                                                 owner_uid = " . $_SESSION["uid"]);
637                                 }
638                         } else if ($subop == "batchEditSave") {
639                                 $feed_data = array();
640
641                                 foreach (array_keys($_POST) as $k) {
642                                         if ($k != "op" && $k != "subop" && $k != "ids") {
643                                                 $feed_data[$k] = $_POST[$k];
644                                         }
645                                 }
646
647                                 db_query($link, "BEGIN");
648
649                                 foreach (array_keys($feed_data) as $k) {
650
651                                         $qpart = "";
652
653                                         switch ($k) {
654                                                 case "title":                                                   
655                                                         $qpart = "title = '$feed_title'";
656                                                         break;
657
658                                                 case "feed_url":
659                                                         $qpart = "feed_url = '$feed_link'";
660                                                         break;
661
662                                                 case "update_interval":
663                                                         $qpart = "update_interval = '$upd_intl'";
664                                                         break;
665
666                                                 case "purge_interval":
667                                                         $qpart = "purge_interval = '$purge_intl'";
668                                                         break;
669
670                                                 case "auth_login":
671                                                         $qpart = "auth_login = '$auth_login'";
672                                                         break;
673
674                                                 case "auth_pass":
675                                                         $qpart = "auth_pass = '$auth_pass'";
676                                                         break;
677
678                                                 case "private":
679                                                         $qpart = "private = '$private'";
680                                                         break;
681
682                                                 case "hidden":
683                                                         $qpart = "hidden = '$hidden'";
684                                                         break;
685
686                                                 case "include_in_digest":
687                                                         $qpart = "include_in_digest = '$include_in_digest'";
688                                                         break;
689
690                                                 case "always_display_enclosures":
691                                                         $qpart = "always_display_enclosures = '$always_display_enclosures'";
692                                                         break;
693
694                                                 case "cache_images":
695                                                         $qpart = "cache_images = '$cache_images'";
696                                                         break;
697
698                                                 case "rtl_content":
699                                                         $qpart = "rtl_content = '$rtl_content'";
700                                                         break;
701
702                                                 case "update_method":
703                                                         $qpart = "update_method = '$update_method'";
704                                                         break;
705
706                                                 case "cat_id":
707                                                         $qpart = $category_qpart_nocomma;
708                                                         break;
709
710                                         }
711
712                                         if ($qpart) {
713                                                 db_query($link,
714                                                         "UPDATE ttrss_feeds SET $qpart WHERE id IN ($feed_ids)
715                                                         AND owner_uid = " . $_SESSION["uid"]);
716                                                 print "<br/>";
717                                         }
718                                 }
719
720                                 db_query($link, "COMMIT");
721                         }
722
723                 }
724
725                 if ($subop == "remove") {
726
727                         $ids = split(",", db_escape_string($_GET["ids"]));
728
729                         foreach ($ids as $id) {
730
731                                 if ($id > 0) {
732
733                                         db_query($link, "DELETE FROM ttrss_feeds 
734                                                 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
735
736                                         $icons_dir = ICONS_DIR;
737                                         
738                                         if (file_exists($icons_dir . "/$id.ico")) {
739                                                 unlink($icons_dir . "/$id.ico");
740                                         }
741
742                                         ccache_remove($link, $id, $_SESSION["uid"]);
743
744                                 } else {
745                                         label_remove($link, -11-$id, $_SESSION["uid"]);
746                                         ccache_remove($link, -11-$id, $_SESSION["uid"]);
747                                 }
748                         }
749                 }
750
751                 if ($subop == "clear") {
752                         $id = db_escape_string($_GET["id"]);
753                         clear_feed_articles($link, $id);
754                 }
755
756                 if ($subop == "rescore") {
757                         $ids = split(",", db_escape_string($_GET["ids"]));
758
759                         foreach ($ids as $id) {
760
761                                 $filters = load_filters($link, $id, $_SESSION["uid"], 6);
762
763                                 $result = db_query($link, "SELECT title, content, link, ref_id FROM
764                                                 ttrss_user_entries, ttrss_entries 
765                                                 WHERE ref_id = id AND feed_id = '$id' AND 
766                                                         owner_uid = " .$_SESSION['uid']."
767                                                 ");
768
769                                 $scores = array();
770
771                                 while ($line = db_fetch_assoc($result)) {
772
773                                         $article_filters = get_article_filters($filters, $line['title'], 
774                                                 $line['content'], $line['link']);
775                                         
776                                         $new_score = calculate_article_score($article_filters);
777
778                                         if (!$scores[$new_score]) $scores[$new_score] = array();
779
780                                         array_push($scores[$new_score], $line['ref_id']);
781                                 }
782
783                                 foreach (array_keys($scores) as $s) {
784                                         if ($s > 1000) {
785                                                 db_query($link, "UPDATE ttrss_user_entries SET score = '$s', 
786                                                         marked = true WHERE
787                                                         ref_id IN (" . join(',', $scores[$s]) . ")");
788                                         } else if ($s < -500) {
789                                                 db_query($link, "UPDATE ttrss_user_entries SET score = '$s', 
790                                                         unread = false WHERE
791                                                         ref_id IN (" . join(',', $scores[$s]) . ")");
792                                         } else {
793                                                 db_query($link, "UPDATE ttrss_user_entries SET score = '$s' WHERE
794                                                         ref_id IN (" . join(',', $scores[$s]) . ")");
795                                         }
796                                 }
797                         }
798
799                         print __("All done.");
800
801                 }
802
803                 if ($subop == "rescoreAll") {
804
805                         $result = db_query($link, 
806                                 "SELECT id FROM ttrss_feeds WHERE owner_uid = " . $_SESSION['uid']);
807
808                         while ($feed_line = db_fetch_assoc($result)) {
809
810                                 $id = $feed_line["id"];
811
812                                 $filters = load_filters($link, $id, $_SESSION["uid"], 6);
813
814                                 $tmp_result = db_query($link, "SELECT title, content, link, ref_id FROM
815                                                 ttrss_user_entries, ttrss_entries 
816                                                 WHERE ref_id = id AND feed_id = '$id' AND 
817                                                         owner_uid = " .$_SESSION['uid']."
818                                                 ");
819
820                                 $scores = array();
821
822                                 while ($line = db_fetch_assoc($tmp_result)) {
823
824                                         $article_filters = get_article_filters($filters, $line['title'], 
825                                                 $line['content'], $line['link']);
826                                         
827                                         $new_score = calculate_article_score($article_filters);
828
829                                         if (!$scores[$new_score]) $scores[$new_score] = array();
830
831                                         array_push($scores[$new_score], $line['ref_id']);
832                                 }
833
834                                 foreach (array_keys($scores) as $s) {
835                                         if ($s > 1000) {
836                                                 db_query($link, "UPDATE ttrss_user_entries SET score = '$s', 
837                                                         marked = true WHERE
838                                                         ref_id IN (" . join(',', $scores[$s]) . ")");
839                                         } else {
840                                                 db_query($link, "UPDATE ttrss_user_entries SET score = '$s' WHERE
841                                                         ref_id IN (" . join(',', $scores[$s]) . ")");
842                                         }
843                                 }
844                         }
845
846                         print __("All done.");
847
848                 }
849
850                 if ($subop == "add") {
851                 
852                         if (!WEB_DEMO_MODE) {
853
854                                 $feed_url = db_escape_string(trim($_REQUEST["feed_url"]));
855                                 $cat_id = db_escape_string($_REQUEST["cat_id"]);
856                                 $p_from = db_escape_string($_REQUEST["from"]);
857
858                                 /* only read authentication information from POST */
859
860                                 $auth_login = db_escape_string(trim($_POST["auth_login"]));
861                                 $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
862
863                                 if ($p_from != 'tt-rss') {
864                                         print "<html>
865                                                 <head>
866                                                         <title>Tiny Tiny RSS</title>
867                                                         <link rel=\"stylesheet\" type=\"text/css\" href=\"utility.css\">
868                                                 </head>
869                                                 <body>
870                                                 <img class=\"floatingLogo\" src=\"images/ttrss_logo.png\"
871                                                         alt=\"Tiny Tiny RSS\"/> 
872                                                 <h1>Subscribe to feed...</h1>";
873                                 }
874
875                                 if (subscribe_to_feed($link, $feed_url, $cat_id, $auth_login, $auth_pass)) {
876                                         print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
877                                 } else {
878                                         print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
879                                 }
880
881                                 if ($p_from != 'tt-rss') {
882                                         $tt_uri = ($_SERVER['HTTPS'] != "on" ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . preg_replace('/backend\.php.*$/', 'tt-rss.php', $_SERVER["REQUEST_URI"]);
883
884
885                                         $tp_uri = ($_SERVER['HTTPS'] != "on" ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . preg_replace('/backend\.php.*$/', 'prefs.php', $_SERVER["REQUEST_URI"]);
886
887                                         $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
888                                                 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
889
890                                         $feed_id = db_fetch_result($result, 0, "id");
891
892                                         print "<p>";
893
894                                         if ($feed_id) {
895                                                 print "<form method=\"GET\" style='display: inline' 
896                                                         action=\"$tp_uri\">
897                                                         <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
898                                                         <input type=\"hidden\" name=\"subop\" value=\"editFeed\">
899                                                         <input type=\"hidden\" name=\"subopparam\" value=\"$feed_id\">
900                                                         <input type=\"submit\" value=\"".__("Edit subscription options")."\">
901                                                         </form>";
902                                         }
903
904                                         print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
905                                                 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
906                                                 </form></p>";
907
908                                         print "</body></html>";
909                                         return;
910                                 }
911
912                         }
913                 }
914
915                 if ($subop == "categorize") {
916
917                         if (!WEB_DEMO_MODE) {
918
919                                 $ids = split(",", db_escape_string($_GET["ids"]));
920
921                                 $cat_id = db_escape_string($_GET["cat_id"]);
922
923                                 if ($cat_id == 0) {
924                                         $cat_id_qpart = 'NULL';
925                                 } else {
926                                         $cat_id_qpart = "'$cat_id'";
927                                 }
928
929                                 db_query($link, "BEGIN");
930
931                                 foreach ($ids as $id) {
932                                 
933                                         db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
934                                                 WHERE id = '$id' AND parent_feed IS NULL
935                                                 AND owner_uid = " . $_SESSION["uid"]);
936
937                                         # update linked feed categories
938                                         db_query($link, "UPDATE ttrss_feeds SET
939                                                 cat_id = $cat_id_qpart WHERE parent_feed = '$id' AND 
940                                                 owner_uid = " . $_SESSION["uid"]);
941
942                                 }
943
944                                 db_query($link, "COMMIT");
945                         }
946
947                 }
948
949                 if ($subop == "editCats") {
950
951                         $action = $_REQUEST["action"];
952
953                         if ($action == "save") {
954
955                                 $cat_title = db_escape_string(trim($_REQUEST["value"]));
956                                 $cat_id = db_escape_string($_GET["cid"]);
957
958                                 db_query($link, "BEGIN");
959
960                                 $result = db_query($link, "SELECT title FROM ttrss_feed_categories
961                                         WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
962
963                                 if (db_num_rows($result) == 1) {
964
965                                         $old_title = db_fetch_result($result, 0, "title");
966                                         
967                                         if ($cat_title != "") {
968                                                 $result = db_query($link, "UPDATE ttrss_feed_categories SET
969                                                         title = '$cat_title' WHERE id = '$cat_id' AND 
970                                                         owner_uid = ".$_SESSION["uid"]);
971
972                                                 print $cat_title;
973                                         } else {
974                                                 print $old_title;
975                                         }
976                                 } else {
977                                         print $_REQUEST["value"];
978                                 }
979
980                                 db_query($link, "COMMIT");
981
982                                 return;
983
984                         }
985
986                         print "<div id=\"infoBoxTitle\">".__('Category editor')."</div>";
987                         
988                         print "<div class=\"infoBoxContents\">";
989
990
991                         if ($action == "add") {
992
993                                 if (!WEB_DEMO_MODE) {
994         
995                                         $feed_cat = db_escape_string(trim($_GET["cat"]));
996         
997                                         $result = db_query($link,
998                                                 "SELECT id FROM ttrss_feed_categories
999                                                 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
1000         
1001                                         if (db_num_rows($result) == 0) {
1002                                                 
1003                                                 $result = db_query($link,
1004                                                         "INSERT INTO ttrss_feed_categories (owner_uid,title) 
1005                                                         VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
1006         
1007                                         } else {
1008         
1009                                                 print_warning(T_sprintf("Category <b>$%s</b> already exists in the database.", 
1010                                                         $feed_cat));
1011                                         }
1012
1013                                 }
1014                         }
1015
1016                         if ($action == "remove") {
1017         
1018                                 if (!WEB_DEMO_MODE) {
1019         
1020                                         $ids = split(",", db_escape_string($_GET["ids"]));
1021         
1022                                         foreach ($ids as $id) {
1023         
1024                                                 db_query($link, "BEGIN");
1025         
1026                                                 $result = db_query($link, 
1027                                                         "SELECT count(id) as num_feeds FROM ttrss_feeds 
1028                                                                 WHERE cat_id = '$id'");
1029         
1030                                                 $num_feeds = db_fetch_result($result, 0, "num_feeds");
1031         
1032                                                 if ($num_feeds == 0) {
1033                                                         db_query($link, "DELETE FROM ttrss_feed_categories
1034                                                                 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1035
1036                                                         ccache_remove($link, $id, $_SESSION["uid"], true);
1037
1038                                                 } else {
1039         
1040                                                         print format_warning(__("Unable to delete non empty feed categories."));
1041                                                                 
1042                                                 }
1043         
1044                                                 db_query($link, "COMMIT");
1045                                         }
1046                                 }
1047                         }
1048
1049                         print "<div class=\"prefGenericAddBox\">
1050                                 <input id=\"fadd_cat\" 
1051                                         onkeypress=\"return filterCR(event, addFeedCat)\"
1052                                         onkeyup=\"toggleSubmitNotEmpty(this, 'catadd_submit_btn')\"
1053                                         onchange=\"toggleSubmitNotEmpty(this, 'catadd_submit_btn')\"
1054                                         size=\"40\">&nbsp;
1055                                 <input 
1056                                         type=\"submit\" class=\"button\" disabled=\"true\" id=\"catadd_submit_btn\"
1057                                         onclick=\"javascript:addFeedCat()\" value=\"".__('Create category')."\"></div>";
1058         
1059                         $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
1060                                 WHERE owner_uid = ".$_SESSION["uid"]."
1061                                 ORDER BY title");
1062
1063                         print "<p>";
1064
1065                         if (db_num_rows($result) != 0) {
1066
1067                                 print "<table width=\"100%\" class=\"prefFeedCatList\" 
1068                                         cellspacing=\"0\">";
1069
1070                                 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1071                                 ".__('Select:')." 
1072                                         <a href=\"javascript:selectPrefRows('fcat', true)\">".__('All')."</a>,
1073                                         <a href=\"javascript:selectPrefRows('fcat', false)\">".__('None')."</a>
1074                                         </td></tr>";
1075
1076                                 print "</table>";
1077
1078                                 print "<div class=\"prefFeedCatHolder\">";
1079
1080                                 print "<form id=\"feed_cat_edit_form\" onsubmit=\"return false\">";
1081
1082                                 print "<table width=\"100%\" class=\"prefFeedCatList\" 
1083                                         cellspacing=\"0\" id=\"prefFeedCatList\">";
1084                                                 
1085                                 $lnum = 0;
1086                                 
1087                                 while ($line = db_fetch_assoc($result)) {
1088                 
1089                                         $class = ($lnum % 2) ? "even" : "odd";
1090                 
1091                                         $cat_id = $line["id"];
1092                                         $this_row_id = "id=\"FCATR-$cat_id\"";
1093                 
1094                                         print "<tr class=\"$class\" $this_row_id>";
1095                 
1096                                         $edit_title = htmlspecialchars($line["title"]);
1097                 
1098                                         print "<td width='5%' align='center'><input 
1099                                                 onclick='toggleSelectPrefRow(this, \"fcat\");' 
1100                                                 type=\"checkbox\" id=\"FCCHK-$cat_id\"></td>";
1101         
1102                                         print "<td><span id=\"FCATT-$cat_id\">" . 
1103                                                 $edit_title . "</span></td>";           
1104                                         
1105                                         print "</tr>";
1106                 
1107                                         ++$lnum;
1108                                 }
1109         
1110                                 print "</table>";
1111
1112                                 print "</form>";
1113
1114                                 print "</div>";
1115
1116                         } else {
1117                                 print "<p>".__('No feed categories defined.')."</p>";
1118                         }
1119
1120                         print "<div style='float : right'>
1121                                 <input type='submit' class='button'                     
1122                                 onclick=\"selectTab('feedConfig')\" value=\"".__('Close this window')."\"></div>";
1123
1124                         print "<div id=\"catOpToolbar\">";
1125         
1126                         print "
1127                                 <input type=\"submit\" class=\"button\" disabled=\"true\"
1128                                         onclick=\"return removeSelectedFeedCats()\" value=\"".__('Remove')."\">";
1129         
1130                         print "</div>";
1131
1132                         print "</div>";
1133
1134                         return;
1135
1136                 }
1137
1138                 if ($quiet) return;
1139
1140                 set_pref($link, "_PREFS_ACTIVE_TAB", "feedConfig");
1141
1142                 $result = db_query($link, "SELECT COUNT(id) AS num_errors
1143                         FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1144
1145                 $num_errors = db_fetch_result($result, 0, "num_errors");
1146
1147                 if ($num_errors > 0) {
1148
1149                         print format_notice("<a href=\"javascript:showFeedsWithErrors()\">".
1150                                 __('Some feeds have update errors (click for details)')."</a>");
1151                 }
1152
1153                 $feed_search = db_escape_string($_GET["search"]);
1154
1155                 if (array_key_exists("search", $_GET)) {
1156                         $_SESSION["prefs_feed_search"] = $feed_search;
1157                 } else {
1158                         $feed_search = $_SESSION["prefs_feed_search"];
1159                 }
1160
1161                 print "<div class=\"feedEditSearch\">
1162                         <input id=\"feed_search\" size=\"20\" type=\"search\"
1163                                 onfocus=\"javascript:disableHotkeys();\" 
1164                                 onblur=\"javascript:enableHotkeys();\"
1165                                 onchange=\"javascript:updateFeedList()\" value=\"$feed_search\">
1166                         <input type=\"submit\" class=\"button\" 
1167                                 onclick=\"javascript:updateFeedList()\" value=\"".__('Search')."\">
1168                         </div>";
1169                 
1170                 print "<input onclick=\"javascript:displayDlg('quickAddFeed')\"
1171                         type=\"submit\" id=\"subscribe_to_feed_btn\" 
1172                         class=\"button\" value=\"".__('Subscribe to feed')."\">"; 
1173
1174                 if (ENABLE_FEED_BROWSER && !SINGLE_USER_MODE) {
1175                         print " <input type=\"submit\" class=\"button\"
1176                                 id=\"top25_feeds_btn\"
1177                                 onclick=\"javascript:browseFeeds()\" value=\"".__('More Feeds')."\">";
1178                 }
1179
1180                 $feeds_sort = db_escape_string($_GET["sort"]);
1181
1182                 if (!$feeds_sort || $feeds_sort == "undefined") {
1183                         $feeds_sort = $_SESSION["pref_sort_feeds"];                     
1184                         if (!$feeds_sort) $feeds_sort = "title";
1185                 }
1186
1187                 $_SESSION["pref_sort_feeds"] = $feeds_sort;
1188
1189                 if ($feed_search) {
1190
1191                         $feed_search = split(" ", $feed_search);
1192                         $tokens = array();
1193
1194                         foreach ($feed_search as $token) {
1195
1196                                 $token = trim($token);
1197
1198                                 array_push($tokens, "(UPPER(F1.title) LIKE UPPER('%$token%') OR
1199                                         UPPER(C1.title) LIKE UPPER('%$token%') OR
1200                                         UPPER(F1.feed_url) LIKE UPPER('%$token%'))");
1201                         }
1202
1203                         $search_qpart = "(" . join($tokens, " AND ") . ") AND ";
1204
1205                 } else {
1206                         $search_qpart = "";
1207                 }
1208
1209                 $show_last_article_info = false;
1210                 $show_last_article_checked = "";
1211                 $show_last_article_qpart = "";
1212
1213                 if ($_GET["slat"] == "true") {
1214                         $show_last_article_info = true;
1215                         $show_last_article_checked = "checked";
1216                         $show_last_article_qpart = ", (SELECT ".SUBSTRING_FOR_DATE."(MAX(updated),1,16) FROM ttrss_user_entries,
1217                                 ttrss_entries WHERE ref_id = ttrss_entries.id
1218                                 AND feed_id = F1.id) AS last_article";
1219                 } else if ($feeds_sort == "last_article") {
1220                         $feeds_sort = "title";
1221                 }
1222
1223                 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1224                         $order_by_qpart = "category,$feeds_sort,title";
1225                 } else {
1226                         $order_by_qpart = "$feeds_sort,title";
1227                 }
1228
1229                 $result = db_query($link, "SELECT 
1230                                 F1.id,
1231                                 F1.title,
1232                                 F1.feed_url,
1233                                 ".SUBSTRING_FOR_DATE."(F1.last_updated,1,16) AS last_updated,
1234                                 F1.parent_feed,
1235                                 F1.update_interval,
1236                                 F1.last_error,
1237                                 F1.purge_interval,
1238                                 F1.cat_id,
1239                                 F2.title AS parent_title,
1240                                 C1.title AS category,
1241                                 F1.hidden,
1242                                 F1.include_in_digest
1243                                 $show_last_article_qpart
1244                         FROM 
1245                                 ttrss_feeds AS F1 
1246                                 LEFT JOIN ttrss_feeds AS F2
1247                                         ON (F1.parent_feed = F2.id)
1248                                 LEFT JOIN ttrss_feed_categories AS C1
1249                                         ON (F1.cat_id = C1.id)
1250                         WHERE 
1251                                 $search_qpart F1.owner_uid = '".$_SESSION["uid"]."'                     
1252                         ORDER by $order_by_qpart");
1253
1254                 if (db_num_rows($result) != 0) {
1255
1256 //                      print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
1257
1258                         print "<p><table width=\"100%\" cellspacing=\"0\" 
1259                                 class=\"prefFeedList\" id=\"prefFeedList\">";
1260                         print "<tr><td class=\"selectPrompt\" colspan=\"8\">".
1261                                 "<div style='float : right'>".
1262                                 "<input id='show_last_article_times' type='checkbox' onchange='feedlistToggleSLAT()'
1263                                 $show_last_article_checked><label 
1264                                         for='show_last_article_times'>".__('Show last article times')."</label></div>".
1265                                 __('Select:')."
1266                                         <a href=\"javascript:selectPrefRows('feed', true)\">".__('All')."</a>,
1267                                         <a href=\"javascript:selectPrefRows('feed', false)\">".__('None')."</a>
1268                                 </td</tr>";
1269
1270                         if (!get_pref($link, 'ENABLE_FEED_CATS')) {
1271                                 print "<tr class=\"title\">
1272                                         <td width='5%' align='center'>&nbsp;</td>";
1273
1274                                 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
1275                                         print "<td width='3%'>&nbsp;</td>";
1276                                 }
1277
1278                                 print "<td width='60%'><a href=\"javascript:updateFeedList('title')\">".__('Title')."</a></td>";
1279
1280                                 if ($show_last_article_info) {
1281                                         print "<td width='20%' align='right'><a href=\"javascript:updateFeedList('last_article')\">".__('Last&nbsp;Article')."</a></td>";
1282                                 }
1283
1284                                 print "<td width='20%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">".__('Updated')."</a></td>";
1285                         }
1286                         
1287                         $lnum = 0;
1288
1289                         $cur_cat_id = -1;
1290                         
1291                         while ($line = db_fetch_assoc($result)) {
1292         
1293                                 $feed_id = $line["id"];
1294                                 $cat_id = $line["cat_id"];
1295
1296                                 $edit_title = htmlspecialchars($line["title"]);
1297                                 $edit_cat = htmlspecialchars($line["category"]);
1298
1299                                 $hidden = sql_bool_to_bool($line["hidden"]);
1300
1301                                 $last_error = $line["last_error"];
1302
1303                                 if (!$edit_cat) $edit_cat = __("Uncategorized");
1304
1305                                 $last_updated = $line["last_updated"];
1306
1307                                 if (!$last_updated) {
1308                                         $last_updated = "&mdash;";
1309                                 } else if (get_pref($link, 'HEADLINES_SMART_DATE')) {
1310                                         $last_updated = smart_date_time(strtotime($last_updated));
1311                                 } else {
1312                                         $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1313                                         $last_updated = date($short_date, strtotime($last_updated));
1314                                 }
1315
1316                                 $last_article = $line["last_article"];
1317
1318                                 if (!$last_article) {
1319                                         $last_article = "&mdash;";      
1320                                 } else if (get_pref($link, 'HEADLINES_SMART_DATE')) {
1321                                         $last_article = smart_date_time(strtotime($last_article));
1322                                 } else {
1323                                         $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1324                                         $last_article = date($short_date, strtotime($last_article));
1325                                 }
1326
1327                                 if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) {
1328                                         $lnum = 0;
1329                                 
1330                                         print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>";
1331
1332                                         print "<tr class=\"title\">
1333                                                 <td width='5%'>&nbsp;</td>";
1334
1335                                         if (get_pref($link, 'ENABLE_FEED_ICONS')) {
1336                                                 print "<td width='3%'>&nbsp;</td>";
1337                                         }
1338
1339                                         print "<td width='60%'><a href=\"javascript:updateFeedList('title')\">".__('Title')."</a></td>";
1340
1341                                         if ($show_last_article_info) {
1342                                                 print "<td width='20%' align='right'>
1343                                                         <a href=\"javascript:updateFeedList('last_article')\">".__('Last&nbsp;Article')."</a></td>";
1344                                         }
1345
1346                                         print "<td width='20%' align='right'>
1347                                                 <a href=\"javascript:updateFeedList('last_updated')\">".__('Updated')."</a></td>";
1348
1349                                         $cur_cat_id = $cat_id;
1350                                 }
1351
1352                                 $class = ($lnum % 2) ? "even" : "odd";
1353                                 $this_row_id = "id=\"FEEDR-$feed_id\"";
1354
1355                                 print "<tr class=\"$class\" $this_row_id>";
1356         
1357                                 $icon_file = ICONS_DIR . "/$feed_id.ico";
1358         
1359                                 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1360                                                 $feed_icon = "<img class=\"tinyFeedIcon\"       src=\"" . ICONS_URL . "/$feed_id.ico\">";
1361                                 } else {
1362                                         $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1363                                 }
1364                                 
1365                                 print "<td class='feedSelect'><input onclick='toggleSelectPrefRow(this, \"feed\");' 
1366                                 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
1367
1368                                 $onclick = "onclick='editFeed($feed_id)' title='".__('Click to edit')."'";
1369
1370                                 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
1371                                         print "<td $onclick class='feedIcon'>$feed_icon</td>";          
1372                                 }
1373
1374                                 if ($hidden) {
1375                                         $edit_title = "<span class=\"insensitive\">$edit_title ".
1376                                                 __('(Hidden)')."</span>";
1377                                         $last_updated = "<span class=\"insensitive\">$last_updated</span>";
1378                                         $last_article = "<span class=\"insensitive\">$last_article</span>";
1379                                 }
1380
1381                                 if ($last_error) {
1382                                         $edit_title = "<span class=\"feed_error\">$edit_title</span>";
1383                                         $last_updated = "<span class=\"feed_error\">$last_updated</span>";
1384                                         $last_article = "<span class=\"feed_error\">$last_article</span>";
1385                                 }
1386
1387                                 $parent_title = $line["parent_title"];
1388                                 if ($parent_title) {
1389                                         $linked_to = sprintf(__("(linked to %s)"), $parent_title);
1390                                         $parent_title = "<span class='groupPrompt'>$linked_to</span>";
1391                                 }
1392
1393                                 print "<td $onclick>" . "$edit_title $parent_title" . "</td>";
1394
1395                                 if ($show_last_article_info) {
1396                                         print "<td align='right' $onclick>" . 
1397                                                 "$last_article</td>";
1398                                 }
1399
1400                                 print "<td $onclick align='right'>$last_updated</td>";
1401
1402                                 print "</tr>";
1403         
1404                                 ++$lnum;
1405                         }
1406         
1407                         print "</table>";
1408
1409                         print "<p>";
1410
1411                         print "<div id=\"feedOpToolbar\">";
1412
1413                         if (get_pref($link, 'ENABLE_FEED_CATS')) {
1414
1415                                 print __('Selection:') . " ";
1416
1417                                 print_feed_cat_select($link, "sfeed_set_fcat", "", "disabled");
1418
1419                                 print " <input type=\"submit\" class=\"button\" disabled=\"true\"
1420                                         onclick=\"javascript:categorizeSelectedFeeds()\" value=\"".
1421                                         __('Recategorize')."\">";
1422                         }
1423                                 
1424                         print "</div>";
1425
1426                         print "<select id=\"feedActionChooser\" onchange=\"feedActionChange()\">
1427                                 <option value=\"facDefault\" selected>".__('Actions...')."</option>
1428                                 <optgroup label=\"".__('Selection:')."\">
1429                                 <option value=\"facEdit\">".__('Edit')."</option>";
1430
1431                         if (FORCE_ARTICLE_PURGE == 0) {
1432                                 print 
1433                                         "<option value=\"facPurge\">".__('Manual purge')."</option>";
1434                         }
1435
1436                         print "
1437                                 <option value=\"facClear\">".__('Clear feed data')."</option>
1438                                 <option value=\"facRescore\">".__('Rescore articles')."</option>
1439                                 <option value=\"facUnsubscribe\">".__('Unsubscribe')."</option>";
1440
1441                         print "</optgroup>";
1442
1443                                 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1444
1445                                         print "<optgroup label=\"".__('Other:')."\">
1446                                                 <option value=\"facEditCats\">".__('Edit categories')."
1447                                                         </option>
1448                                         </optgroup>";
1449
1450                                 }
1451
1452                         print "</select>";
1453                 } else {
1454
1455                         print "<p>";
1456
1457                         if (!$feed_search) { 
1458                                 print_warning(__("You don't have any subscribed feeds."));
1459                         } else {
1460                                 print_warning(__('No matching feeds found.'));
1461                         }
1462                         print "</p>";
1463
1464                 }
1465
1466                 print "<h3>".__('OPML')."</h3>
1467
1468                 <div style='float : left'>
1469                 <form   enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
1470                 ".__('File:')." <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
1471                         <input type=\"hidden\" name=\"op\" value=\"Import\">
1472                         <input class=\"button\" onclick=\"return validateOpmlImport();\"
1473                                 type=\"submit\" value=\"".__('Import')."\">
1474                                 </form></div>";
1475
1476                 print "&nbsp;";
1477
1478                 print "<input type=\"submit\" 
1479                         class=\"button\" onclick=\"gotoExportOpml()\" 
1480                                 value=\"".__('Export OPML')."\">";                      
1481
1482
1483                 print "<h3>" . __("Firefox Integration") . "</h3>";
1484                 
1485                 print "<p>" . __('This Tiny Tiny RSS site can be used as a Firefox Feed Reader by clicking the link below.');
1486                 print "</p><p> <a class='visibleLinkB' href='javascript:window.navigator.registerContentHandler(" .
1487                       "\"application/vnd.mozilla.maybe.feed\", " .
1488                       "\"" . add_feed_url() . "\", " . " \"Tiny Tiny RSS\")'>" .
1489                       __('Click here to register this site as a feed reader.') . "</a></p>";
1490
1491
1492                 print "<h3>".__("Published articles")."</h3>";
1493
1494                 if (!get_pref($link, "_PREFS_PUBLISH_KEY")) {
1495                         set_pref($link, "_PREFS_PUBLISH_KEY", generate_publish_key());
1496                 }
1497                 
1498                 print "<p>".__('Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the URL specified below.')."</p>";
1499
1500                 $url_path = article_publish_url($link);
1501
1502                 print "<p><a class=\"visibleLinkB\" id=\"pubGenAddress\" target=\"_blank\" href=\"$url_path\">".__("Link to published articles feed.")."</a></p>";
1503
1504                 print "<p><input type=\"submit\" onclick=\"return pubRegenKey()\" class=\"button\"
1505                         value=\"".__('Generate another link')."\">";
1506                 /* print " <input type=\"submit\" onclick=\"return pubToClipboard()\" class=\"button\"
1507                         value=\"".__('Copy link to clipboard')."\">"; */
1508                 print "</p>";
1509
1510         }
1511
1512         function print_feed_browser($link, $search, $limit) {
1513
1514                         $owner_uid = $_SESSION["uid"];
1515
1516                         if ($search) {
1517                                 $search_qpart = "AND (UPPER(feed_url) LIKE UPPER('%$search%') OR 
1518                                         UPPER(title) LIKE UPPER('%$search%'))";
1519                         } else {
1520                                 $search_qpart = "";
1521                         }
1522
1523                         $result = db_query($link, "SELECT feed_url, subscribers FROM
1524                                 ttrss_feedbrowser_cache WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf
1525                                 WHERE tf.feed_url = ttrss_feedbrowser_cache.feed_url
1526                                 AND owner_uid = '$owner_uid') $search_qpart 
1527                                 ORDER BY subscribers DESC LIMIT $limit");
1528
1529                         $feedctr = 0;
1530                         
1531                         while ($line = db_fetch_assoc($result)) {
1532                                 $feed_url = $line["feed_url"];
1533                                 $subscribers = $line["subscribers"];
1534
1535                                 $det_result = db_query($link, "SELECT site_url,title,id 
1536                                         FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
1537
1538                                 $details = db_fetch_assoc($det_result);
1539                         
1540                                 $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico";
1541
1542                                 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1543                                                 $feed_icon = "<img class=\"tinyFeedIcon\"       src=\"" . ICONS_URL . 
1544                                                         "/".$details["id"].".ico\">";
1545                                 } else {
1546                                         $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1547                                 }
1548
1549                                 $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB' 
1550                                         type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
1551
1552                                 $class = ($feedctr % 2) ? "even" : "odd";
1553
1554                                 if ($details["site_url"]) {
1555                                         $site_url = "<a target=\"_blank\" href=\"".$details["site_url"]."\">
1556                                                 <img style='border-width : 0px' src='images/www.png' alt='www'></a>";
1557                                 } else {
1558                                         $site_url = "";
1559                                 }
1560
1561                                 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
1562                                         "$feed_icon " . $details["title"] . 
1563                                         "&nbsp;<span class='subscribers'>($subscribers)</span>
1564                                         $site_url
1565                                         </li>";
1566
1567                                         ++$feedctr;
1568                         }
1569
1570                         if ($feedctr == 0) {
1571                                 print "<li style=\"text-align : center\"><p>".__('No feeds found.')."</p></li>";
1572                         }
1573
1574                 return $feedctr;
1575
1576         }
1577 ?>