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