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