]> git.wh0rd.org Git - tt-rss.git/blob - modules/pref-feeds.php
454dd17851d34462f1f596ab3798d2ac37eb7a3d
[tt-rss.git] / modules / pref-feeds.php
1 <?php
2         function module_pref_feeds($link) {
3
4                 $subop = $_REQUEST["subop"];
5                 $quiet = $_REQUEST["quiet"];
6
7                 if ($subop == "massSubscribe") {
8                         $ids = split(",", db_escape_string($_GET["ids"]));
9
10                         $subscribed = array();
11
12                         foreach ($ids as $id) {
13                                 $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds
14                                         WHERE id = '$id'");
15
16                                 $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url"));
17                                 $title = db_escape_string(db_fetch_result($result, 0, "title"));
18
19                                 $title_orig = db_fetch_result($result, 0, "title");
20
21                                 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
22                                         feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
23
24                                 if (db_num_rows($result) == 0) {                        
25                                         $result = db_query($link,
26                                                 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id) 
27                                                 VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)");
28
29                                         array_push($subscribed, $title_orig);
30                                 }
31                         }
32
33                         if (count($subscribed) > 0) {
34                                 print "<div class=\"notice\">";
35                                 print "<b>Subscribed to feeds:</b>";
36                                 print "<ul class=\"nomarks\">";
37                                 foreach ($subscribed as $title) {
38                                         print "<li>$title</li>";
39                                 }
40                                 print "</ul>";
41                                 print "</div>";
42                         }
43                 }               
44
45                 if ($subop == "browse") {
46
47                         if (!ENABLE_FEED_BROWSER) {
48                                 print "Feed browser is administratively disabled.";
49                                 return;
50                         }
51
52                         print "<div id=\"infoBoxTitle\">Other feeds: Top 25</div>";
53                         
54                         print "<div class=\"infoBoxContents\">";
55
56                         print "<p>Showing top 25 registered feeds, sorted by popularity:</p>";
57
58 #                       $result = db_query($link, "SELECT feed_url,count(id) AS subscribers 
59 #                               FROM ttrss_feeds 
60 #                               WHERE auth_login = '' AND auth_pass = '' AND private = false
61 #                               GROUP BY feed_url ORDER BY subscribers DESC LIMIT 25");
62
63                         $owner_uid = $_SESSION["uid"];
64
65                         $result = db_query($link, "SELECT feed_url,COUNT(id) AS subscribers
66                                 FROM ttrss_feeds WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf 
67                                         WHERE tf.feed_url = ttrss_feeds.feed_url 
68                                                 AND owner_uid = '$owner_uid') GROUP BY feed_url 
69                                                         ORDER BY subscribers DESC LIMIT 25");
70
71                         print "<ul class='browseFeedList' id='browseFeedList'>";
72
73                         $feedctr = 0;
74                         
75                         while ($line = db_fetch_assoc($result)) {
76                                 $feed_url = $line["feed_url"];
77                                 $subscribers = $line["subscribers"];
78
79                                 $det_result = db_query($link, "SELECT site_url,title,id 
80                                         FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
81
82                                 $details = db_fetch_assoc($det_result);
83                         
84                                 $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico";
85
86                                 if (file_exists($icon_file) && filesize($icon_file) > 0) {
87                                                 $feed_icon = "<img class=\"tinyFeedIcon\"       src=\"" . ICONS_URL . 
88                                                         "/".$details["id"].".ico\">";
89                                 } else {
90                                         $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
91                                 }
92
93                                 $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB' 
94                                         type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
95
96                                 $class = ($feedctr % 2) ? "even" : "odd";
97
98                                 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
99                                         "$feed_icon " . db_unescape_string($details["title"]) . 
100                                         "&nbsp;<span class='subscribers'>($subscribers)</span></li>";
101
102                                         ++$feedctr;
103                         }
104
105                         if ($feedctr == 0) {
106                                 print "<li>No feeds found to subscribe.</li>";
107                         }
108
109                         print "</ul>";
110
111                         print "<div align='center'>
112                                 <input type=\"submit\" class=\"button\" 
113                                 onclick=\"feedBrowserSubscribe()\" value=\"Subscribe\">
114                                 <input type='submit' class='button'                     
115                                 onclick=\"closeInfoBox()\" value=\"Cancel\"></div>";
116
117                         print "</div>";
118                         return;
119                 }
120
121                 if ($subop == "editfeed") {
122                         $feed_id = db_escape_string($_REQUEST["id"]);
123
124                         $result = db_query($link, 
125                                 "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND
126                                         owner_uid = " . $_SESSION["uid"]);
127
128                         $title = htmlspecialchars(db_unescape_string(db_fetch_result($result,
129                                 0, "title")));
130
131                         $icon_file = ICONS_DIR . "/$feed_id.ico";
132         
133                         if (file_exists($icon_file) && filesize($icon_file) > 0) {
134                                         $feed_icon = "<img width=\"16\" height=\"16\"
135                                                 src=\"" . ICONS_URL . "/$feed_id.ico\">";
136                         } else {
137                                 $feed_icon = "";
138                         }
139
140                         print "<div id=\"infoBoxTitle\">Feed editor</div>";
141
142                         print "<div class=\"infoBoxContents\">";
143
144                         print "<form id=\"edit_feed_form\">";   
145
146                         print "<input type=\"hidden\" name=\"id\" value=\"$feed_id\">";
147                         print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
148                         print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
149
150                         print "<table width='100%'>";
151
152                         print "<tr><td>Title:</td>";
153                         print "<td><input class=\"iedit\" onkeypress=\"return filterCR(event, feedEditSave)\"
154                                 name=\"title\" value=\"$title\"></td></tr>";
155
156                         $feed_url = db_fetch_result($result, 0, "feed_url");
157                         $feed_url = htmlspecialchars(db_unescape_string(db_fetch_result($result,
158                                 0, "feed_url")));
159                                 
160                         print "<tr><td>Feed URL:</td>";
161                         print "<td><input class=\"iedit\" onkeypress=\"return filterCR(event, feedEditSave)\"
162                                 name=\"feed_url\" value=\"$feed_url\"></td></tr>";
163
164                         if (get_pref($link, 'ENABLE_FEED_CATS')) {
165
166                                 $cat_id = db_fetch_result($result, 0, "cat_id");
167
168                                 print "<tr><td>Category:</td>";
169                                 print "<td>";
170
171                                 $parent_feed = db_fetch_result($result, 0, "parent_feed");
172
173                                 if (sprintf("%d", $parent_feed) > 0) {
174                                         $disabled = "disabled";
175                                 } else {
176                                         $disabled = "";
177                                 }
178
179                                 print_feed_cat_select($link, "cat_id", $cat_id, "class=\"iedit\" $disabled");
180
181                                 print "</td>";
182                                 print "</td></tr>";
183         
184                         }
185
186                         $update_interval = db_fetch_result($result, 0, "update_interval");
187
188                         print "<tr><td>Update Interval:</td>";
189
190                         print "<td>";
191
192                         print_select_hash("update_interval", $update_interval, $update_intervals,
193                                 "class=\"iedit\"");
194
195                         print "</td>";
196
197                         print "<tr><td>Link to:</td><td>";
198
199                         $tmp_result = db_query($link, "SELECT COUNT(id) AS count
200                                 FROM ttrss_feeds WHERE parent_feed = '$feed_id'");
201
202                         $linked_count = db_fetch_result($tmp_result, 0, "count");
203
204                         $parent_feed = db_fetch_result($result, 0, "parent_feed");
205
206                         if ($linked_count > 0) {
207                                 $disabled = "disabled";
208                         } else {
209                                 $disabled = "";
210                         }
211
212                         print "<select class=\"iedit\" $disabled name=\"parent_feed\">";
213                         
214                         print "<option value=\"0\">Not linked</option>";
215
216                         if (get_pref($link, 'ENABLE_FEED_CATS')) {
217                                 if ($cat_id) {
218                                         $cat_qpart = "AND cat_id = '$cat_id'";
219                                 } else {
220                                         $cat_qpart = "AND cat_id IS NULL";
221                                 }
222                         }
223
224                         $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
225                                 WHERE id != '$feed_id' AND owner_uid = ".$_SESSION["uid"]." AND
226                                         (SELECT COUNT(id) FROM ttrss_feeds AS T2 WHERE T2.id = ttrss_feeds.parent_feed) = 0
227                                         $cat_qpart ORDER BY title");
228
229                                 if (db_num_rows($tmp_result) > 0) {
230                                         print "<option disabled>--------</option>";
231                                 }
232
233                                 while ($tmp_line = db_fetch_assoc($tmp_result)) {
234                                         if ($tmp_line["id"] == $parent_feed) {
235                                                 $is_selected = "selected";
236                                         } else {
237                                                 $is_selected = "";
238                                         }
239                                         printf("<option $is_selected value='%d'>%s</option>", 
240                                                 $tmp_line["id"], $tmp_line["title"]);
241                                 }
242
243                         print "</select>";
244                         print "</td></tr>";
245
246                         $purge_interval = db_fetch_result($result, 0, "purge_interval");
247
248                         print "<tr><td>Article purging:</td>";
249
250                         print "<td>";
251
252                         print_select_hash("purge_interval", $purge_interval, $purge_intervals, 
253                                 "class=\"iedit\"");
254                         
255                         print "</td>";
256
257                         $auth_login = escape_for_form(db_fetch_result($result, 0, "auth_login"));
258
259                         print "<tr><td>Login:</td>";
260                         print "<td><input class=\"iedit\" onkeypress=\"return filterCR(event, feedEditSave)\"
261                                 name=\"auth_login\" value=\"$auth_login\"></td></tr>";
262
263                         $auth_pass = escape_for_form(db_fetch_result($result, 0, "auth_pass"));
264
265                         print "<tr><td>Password:</td>";
266                         print "<td><input class=\"iedit\" type=\"password\" name=\"auth_pass\" 
267                                 onkeypress=\"return filterCR(event, feedEditSave)\"
268                                 value=\"$auth_pass\"></td></tr>";
269
270                         $private = sql_bool_to_bool(db_fetch_result($result, 0, "private"));
271
272                         if ($private) {
273                                 $checked = "checked";
274                         } else {
275                                 $checked = "";
276                         }
277
278                         print "<tr><td valign='top'>Options:</td>";
279                         print "<td><input type=\"checkbox\" name=\"private\" id=\"private\" 
280                                 $checked><label for=\"private\">Hide from \"Other Feeds\"</label>";
281
282                         $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
283
284                         if ($rtl_content) {
285                                 $checked = "checked";
286                         } else {
287                                 $checked = "";
288                         }
289
290                         print "<br><input type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"
291                                 $checked><label for=\"rtl_content\">Right-to-left content</label>";
292
293                         $hidden = sql_bool_to_bool(db_fetch_result($result, 0, "hidden"));
294
295                         if ($hidden) {
296                                 $checked = "checked";
297                         } else {
298                                 $checked = "";
299                         }
300
301                         print "<br><input type=\"checkbox\" id=\"hidden\" name=\"hidden\"
302                                 $checked><label for=\"hidden\">Hide from my feed list</label>";
303
304                         $include_in_digest = sql_bool_to_bool(db_fetch_result($result, 0, "include_in_digest"));
305
306                         if ($include_in_digest) {
307                                 $checked = "checked";
308                         } else {
309                                 $checked = "";
310                         }
311
312                         print "<br><input type=\"checkbox\" id=\"include_in_digest\" 
313                                 name=\"include_in_digest\"
314                                 $checked><label for=\"include_in_digest\">Include in e-mail digest</label>";
315
316                         print "</td></tr>";
317
318                         print "</table>";
319
320                         print "</form>";
321
322                         print "<div align='right'>
323                                 <input type=\"submit\" class=\"button\" 
324                                 onclick=\"return feedEditSave()\" value=\"Save\">
325                                 <input type='submit' class='button'                     
326                                 onclick=\"return feedEditCancel()\" value=\"Cancel\"></div>";
327
328                         print "</div>";
329
330                         return;
331                 }
332
333                 if ($subop == "editSave") {
334
335                         $feed_title = db_escape_string(trim($_POST["title"]));
336                         $feed_link = db_escape_string(trim($_POST["feed_url"]));
337                         $upd_intl = db_escape_string($_POST["update_interval"]);
338                         $purge_intl = db_escape_string($_POST["purge_interval"]);
339                         $feed_id = db_escape_string($_POST["id"]);
340                         $cat_id = db_escape_string($_POST["cat_id"]);
341                         $auth_login = db_escape_string(trim($_POST["auth_login"]));
342                         $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
343                         $parent_feed = db_escape_string($_POST["parent_feed"]);
344                         $private = checkbox_to_sql_bool(db_escape_string($_POST["private"]));
345                         $rtl_content = checkbox_to_sql_bool(db_escape_string($_POST["rtl_content"]));
346                         $hidden = checkbox_to_sql_bool(db_escape_string($_POST["hidden"]));
347                         $include_in_digest = checkbox_to_sql_bool(
348                                 db_escape_string($_POST["include_in_digest"]));
349
350                         if (get_pref($link, 'ENABLE_FEED_CATS')) {                      
351                                 if ($cat_id && $cat_id != 0) {
352                                         $category_qpart = "cat_id = '$cat_id',";
353                                         $category_qpart_nocomma = "cat_id = '$cat_id'";
354                                 } else {
355                                         $category_qpart = 'cat_id = NULL,';
356                                         $category_qpart_nocomma = 'cat_id = NULL';
357                                 }
358                         } else {
359                                 $category_qpart = "";
360                                 $category_qpart_nocomma = "";
361                         }
362
363                         if ($parent_feed && $parent_feed != 0) {
364                                 $parent_qpart = "parent_feed = '$parent_feed'";
365                         } else {
366                                 $parent_qpart = 'parent_feed = NULL';
367                         }
368
369                         $result = db_query($link, "UPDATE ttrss_feeds SET 
370                                 $category_qpart $parent_qpart,
371                                 title = '$feed_title', feed_url = '$feed_link',
372                                 update_interval = '$upd_intl',
373                                 purge_interval = '$purge_intl',
374                                 auth_login = '$auth_login',
375                                 auth_pass = '$auth_pass',
376                                 private = $private,
377                                 rtl_content = $rtl_content,
378                                 hidden = $hidden,
379                                 include_in_digest = $include_in_digest
380                                 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
381
382                         if (get_pref($link, 'ENABLE_FEED_CATS')) {
383                                 # update linked feed categories
384                                 $result = db_query($link, "UPDATE ttrss_feeds SET
385                                         $category_qpart_nocomma WHERE parent_feed = '$feed_id' AND
386                                         owner_uid = " . $_SESSION["uid"]);
387                         }
388                 }
389
390                 if ($subop == "saveCat") {
391                         $cat_title = db_escape_string(trim($_GET["title"]));
392                         $cat_id = db_escape_string($_GET["id"]);
393
394                         $result = db_query($link, "UPDATE ttrss_feed_categories SET
395                                 title = '$cat_title' WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
396
397                 }
398
399                 if ($subop == "remove") {
400
401                         if (!WEB_DEMO_MODE) {
402
403                                 $ids = split(",", db_escape_string($_GET["ids"]));
404
405                                 foreach ($ids as $id) {
406
407                                         if ($id > 0) {
408
409                                                 db_query($link, "DELETE FROM ttrss_feeds 
410                                                         WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
411
412                                                 $icons_dir = ICONS_DIR;
413                                         
414                                                 if (file_exists($icons_dir . "/$id.ico")) {
415                                                         unlink($icons_dir . "/$id.ico");
416                                                 }
417                                         } else if ($id < -10) {
418
419                                                 $label_id = -$id - 11;
420
421                                                 db_query($link, "DELETE FROM ttrss_labels
422                                                         WHERE   id = '$label_id' AND owner_uid = " . $_SESSION["uid"]);
423                                         }
424                                 }
425                         }
426                 }
427
428                 if ($subop == "add") {
429                 
430                         if (!WEB_DEMO_MODE) {
431
432                                 $feed_url = db_escape_string(trim($_GET["feed_url"]));
433                                 $cat_id = db_escape_string($_GET["cat_id"]);
434
435                                 if (subscribe_to_feed($link, $feed_url, $cat_id)) {
436                                         print "Added feed.";
437                                 } else {
438                                         print "<div class=\"warning\">
439                                                 Feed <b>$feed_url</b> already exists in the database.
440                                         </div>";
441                                 }
442                         }
443                 }
444
445                 if ($subop == "addCat") {
446
447                         if (!WEB_DEMO_MODE) {
448
449                                 $feed_cat = db_escape_string(trim($_GET["cat"]));
450
451                                 $result = db_query($link,
452                                         "SELECT id FROM ttrss_feed_categories
453                                         WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
454
455                                 if (db_num_rows($result) == 0) {
456                                         
457                                         $result = db_query($link,
458                                                 "INSERT INTO ttrss_feed_categories (owner_uid,title) 
459                                                 VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
460
461                                 } else {
462
463                                         print "<div class=\"warning\">
464                                                 Category <b>$feed_cat</b> already exists in the database.
465                                         </div>";
466                                 }
467
468
469                         }
470                 }
471
472                 if ($subop == "removeCats") {
473
474                         if (!WEB_DEMO_MODE) {
475
476                                 $ids = split(",", db_escape_string($_GET["ids"]));
477
478                                 foreach ($ids as $id) {
479
480                                         db_query($link, "BEGIN");
481
482                                         $result = db_query($link, 
483                                                 "SELECT count(id) as num_feeds FROM ttrss_feeds 
484                                                         WHERE cat_id = '$id'");
485
486                                         $num_feeds = db_fetch_result($result, 0, "num_feeds");
487
488                                         if ($num_feeds == 0) {
489                                                 db_query($link, "DELETE FROM ttrss_feed_categories
490                                                         WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
491                                         } else {
492
493                                                 print "<div class=\"warning\">
494                                                         Unable to delete non empty feed categories.</div>";
495                                                         
496                                         }
497
498                                         db_query($link, "COMMIT");
499                                 }
500                         }
501                 }
502
503                 if ($subop == "categorize") {
504
505                         if (!WEB_DEMO_MODE) {
506
507                                 $ids = split(",", db_escape_string($_GET["ids"]));
508
509                                 $cat_id = db_escape_string($_GET["cat_id"]);
510
511                                 if ($cat_id == 0) {
512                                         $cat_id_qpart = 'NULL';
513                                 } else {
514                                         $cat_id_qpart = "'$cat_id'";
515                                 }
516
517                                 db_query($link, "BEGIN");
518
519                                 foreach ($ids as $id) {
520                                 
521                                         db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
522                                                 WHERE id = '$id' AND parent_feed IS NULL
523                                                 AND owner_uid = " . $_SESSION["uid"]);
524
525                                         # update linked feed categories
526                                         db_query($link, "UPDATE ttrss_feeds SET
527                                                 cat_id = $cat_id_qpart WHERE parent_feed = '$id' AND 
528                                                 owner_uid = " . $_SESSION["uid"]);
529
530                                 }
531
532                                 db_query($link, "COMMIT");
533                         }
534
535                 }
536
537                 if ($quiet) return;
538
539 //              print "<h3>Edit Feeds</h3>";
540
541                 $result = db_query($link, "SELECT id,title,feed_url,last_error
542                         FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
543
544                 if (db_num_rows($result) > 0) {
545                 
546                         print "<div class=\"warning\">";
547                         
548 //                      print"<img class=\"closeButton\" 
549 //                              onclick=\"javascript:hideParentElement(this);\" src=\"images/close.png\">";
550         
551                         print "<a href=\"javascript:showBlockElement('feedUpdateErrors')\">
552                                 <b>Some feeds have update errors (click for details)</b></a>";
553
554                         print "<ul id=\"feedUpdateErrors\" class=\"nomarks\">";
555                                                 
556                         while ($line = db_fetch_assoc($result)) {
557                                 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " . 
558                                         $line["last_error"];
559                         }
560
561                         print "</ul>";
562                         print "</div>";
563
564                 }
565
566                 $feed_search = db_escape_string($_GET["search"]);
567
568                 if (array_key_exists("search", $_GET)) {
569                         $_SESSION["prefs_feed_search"] = $feed_search;
570                 } else {
571                         $feed_search = $_SESSION["prefs_feed_search"];
572                 }
573
574                 print "<div class=\"feedEditSearch\">
575                         <input id=\"feed_search\" size=\"20\"  
576                                 onchange=\"javascript:updateFeedList()\" value=\"$feed_search\">
577                         <input type=\"submit\" class=\"button\" 
578                                 onclick=\"javascript:updateFeedList()\" value=\"Search\">
579                         </div>";
580
581                 print "<div class=\"prefGenericAddBox\">
582                         <input id=\"fadd_link\" 
583                                 onkeyup=\"toggleSubmitNotEmpty(this, 'fadd_submit_btn')\"
584                                 size=\"40\">
585                         <input type=\"submit\" class=\"button\"
586                                 disabled=\"true\" id=\"fadd_submit_btn\"
587                                 onclick=\"addFeed()\" value=\"Subscribe\">";
588
589                 if (ENABLE_FEED_BROWSER && !SINGLE_USER_MODE) {
590                         print " <input type=\"submit\" class=\"button\"
591                                 onclick=\"javascript:browseFeeds()\" value=\"Top 25\">";
592                 }
593
594                 print "</div>";
595
596                 $feeds_sort = db_escape_string($_GET["sort"]);
597
598                 if (!$feeds_sort || $feeds_sort == "undefined") {
599                         $feeds_sort = $_SESSION["pref_sort_feeds"];                     
600                         if (!$feeds_sort) $feeds_sort = "title";
601                 }
602
603                 $_SESSION["pref_sort_feeds"] = $feeds_sort;
604
605                 if ($feed_search) {
606                         $search_qpart = "(UPPER(F1.title) LIKE UPPER('%$feed_search%') OR
607                                 UPPER(F1.feed_url) LIKE UPPER('%$feed_search%')) AND";
608                 } else {
609                         $search_qpart = "";
610                 }
611
612                 if (get_pref($link, 'ENABLE_FEED_CATS')) {
613                         $order_by_qpart = "category,$feeds_sort,title";
614                 } else {
615                         $order_by_qpart = "$feeds_sort,title";
616                 }
617
618                 $result = db_query($link, "SELECT 
619                                 F1.id,
620                                 F1.title,
621                                 F1.feed_url,
622                                 substring(F1.last_updated,1,16) AS last_updated,
623                                 F1.parent_feed,
624                                 F1.update_interval,
625                                 F1.purge_interval,
626                                 F1.cat_id,
627                                 F2.title AS parent_title,
628                                 C1.title AS category,
629                                 F1.hidden,
630                                 F1.include_in_digest,
631                                 (SELECT SUBSTRING(MAX(updated),1,16) FROM ttrss_user_entries, 
632                                         ttrss_entries WHERE ref_id = ttrss_entries.id 
633                                         AND feed_id = F1.id) AS last_article
634                         FROM 
635                                 ttrss_feeds AS F1 
636                                 LEFT JOIN ttrss_feeds AS F2
637                                         ON (F1.parent_feed = F2.id)
638                                 LEFT JOIN ttrss_feed_categories AS C1
639                                         ON (F1.cat_id = C1.id)
640                         WHERE 
641                                 $search_qpart F1.owner_uid = '".$_SESSION["uid"]."'                     
642                         ORDER by $order_by_qpart");
643
644                 if (db_num_rows($result) != 0) {
645
646 //                      print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
647
648                         print "<p><table width=\"100%\" cellspacing=\"0\" 
649                                 class=\"prefFeedList\" id=\"prefFeedList\">";
650                         print "<tr><td class=\"selectPrompt\" colspan=\"8\">
651                                 Select: 
652                                         <a href=\"javascript:selectPrefRows('feed', true)\">All</a>,
653                                         <a href=\"javascript:selectPrefRows('feed', false)\">None</a>
654                                 </td</tr>";
655
656                         if (!get_pref($link, 'ENABLE_FEED_CATS')) {
657                                 print "<tr class=\"title\">
658                                         <td width='5%' align='center'>&nbsp;</td>";
659
660                                 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
661                                         print "<td width='3%'>&nbsp;</td>";
662                                 }
663
664                                 print "
665                                         <td width='35%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
666                                         <td width='35%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
667                                         <td width='15%'><a href=\"javascript:updateFeedList('last_article')\">Last&nbsp;Article</a></td>
668                                         <td width='15%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">Updated</a></td>";
669                         }
670                         
671                         $lnum = 0;
672
673                         $cur_cat_id = -1;
674                         
675                         while ($line = db_fetch_assoc($result)) {
676         
677                                 $feed_id = $line["id"];
678                                 $cat_id = $line["cat_id"];
679
680                                 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
681                                 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
682                                 $edit_cat = htmlspecialchars(db_unescape_string($line["category"]));
683
684                                 $hidden = sql_bool_to_bool($line["hidden"]);
685
686                                 if (!$edit_cat) $edit_cat = "Uncategorized";
687
688                                 $last_updated = $line["last_updated"];
689
690                                 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
691                                         $last_updated = smart_date_time(strtotime($last_updated));
692                                 } else {
693                                         $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
694                                         $last_updated = date($short_date, strtotime($last_updated));
695                                 }
696
697                                 $last_article = $line["last_article"];
698
699                                 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
700                                         $last_article = smart_date_time(strtotime($last_article));
701                                 } else {
702                                         $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
703                                         $last_article = date($short_date, strtotime($last_article));
704                                 }
705
706                                 if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) {
707                                         $lnum = 0;
708                                 
709                                         print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>";
710
711                                         print "<tr class=\"title\">
712                                                 <td width='5%'>&nbsp;</td>";
713
714                                         if (get_pref($link, 'ENABLE_FEED_ICONS')) {
715                                                 print "<td width='3%'>&nbsp;</td>";
716                                         }
717
718                                         print "<td width='35%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
719                                                 <td width='35%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
720                                                 <td width='15%'><a href=\"javascript:updateFeedList('last_article')\">Last&nbsp;Article</a></td>
721                                                 <td width='15%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">Updated</a></td>";
722
723                                         $cur_cat_id = $cat_id;
724                                 }
725
726                                 $class = ($lnum % 2) ? "even" : "odd";
727                                 $this_row_id = "id=\"FEEDR-$feed_id\"";
728
729                                 print "<tr class=\"$class\" $this_row_id>";
730         
731                                 $icon_file = ICONS_DIR . "/$feed_id.ico";
732         
733                                 if (file_exists($icon_file) && filesize($icon_file) > 0) {
734                                                 $feed_icon = "<img class=\"tinyFeedIcon\"       src=\"" . ICONS_URL . "/$feed_id.ico\">";
735                                 } else {
736                                         $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
737                                 }
738                                 
739                                 print "<td class='feedSelect'><input onclick='toggleSelectPrefRow(this, \"feed\");' 
740                                 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
741
742                                 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
743                                         print "<td class='feedIcon'>$feed_icon</td>";           
744                                 }
745
746                                 $edit_title = truncate_string($edit_title, 40);
747                                 $edit_link = truncate_string($edit_link, 60);
748
749                                 if ($hidden) {
750                                         $edit_title = "<span class=\"insensitive\">$edit_title (Hidden)</span>";
751                                         $edit_link = "<span class=\"insensitive\">$edit_link</span>";
752                                         $last_updated = "<span class=\"insensitive\">$last_updated</span>";
753                                         $last_article = "<span class=\"insensitive\">$last_article</span>";
754                                 }
755
756                                 $parent_title = $line["parent_title"];
757                                 if ($parent_title) {
758                                         $parent_title = "<span class='groupPrompt'>(linked to 
759                                                 $parent_title)</span>";
760                                 }
761
762                                 print "<td><a href=\"javascript:editFeed($feed_id);\">" . 
763                                         "$edit_title $parent_title" . "</a></td>";              
764                                         
765                                 print "<td><a href=\"javascript:editFeed($feed_id);\">" . 
766                                         $edit_link . "</a></td>";               
767
768                                 print "<td><a href=\"javascript:editFeed($feed_id);\">" . 
769                                         "$last_article</a></td>";
770
771                                 print "<td align='right'><a href=\"javascript:editFeed($feed_id);\">" . 
772                                         "$last_updated</a></td>";
773
774                                 print "</tr>";
775         
776                                 ++$lnum;
777                         }
778         
779                         print "</table>";
780
781                         print "<p><span id=\"feedOpToolbar\">";
782         
783                         if ($subop == "edit") {
784                                 print "Edit feed:&nbsp;
785                                         <input type=\"submit\" class=\"button\" 
786                                                 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
787                                         <input type=\"submit\" class=\"button\" 
788                                                 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
789                         } else {
790         
791                                 print "
792                                         Selection:&nbsp;
793                                 <input type=\"submit\" class=\"button\" disabled=\"true\"
794                                         onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
795                                 <input type=\"submit\" class=\"button\" disabled=\"true\"
796                                         onclick=\"javascript:removeSelectedFeeds()\" value=\"Unsubscribe\">";
797
798                                 if (get_pref($link, 'ENABLE_FEED_CATS')) {
799
800                                         print "&nbsp;|&nbsp;";                          
801
802                                         print_feed_cat_select($link, "sfeed_set_fcat", "", "disabled");
803
804                                         print " <input type=\"submit\" class=\"button\" disabled=\"true\"
805                                         onclick=\"javascript:categorizeSelectedFeeds()\" value=\"Recategorize\">";
806
807                                 }
808                                 
809                                 print "</span>
810                                         &nbsp;All feeds: <input type=\"submit\" 
811                                                         class=\"button\" onclick=\"gotoExportOpml()\" 
812                                                         value=\"Export OPML\">";                        
813                                 }
814                 } else {
815
816                         print "<p>No feeds defined.</p>";
817
818                 }
819
820                 if (get_pref($link, 'ENABLE_FEED_CATS')) {
821
822                         print "<h3>Edit Categories</h3>";
823
824                         print "<div class=\"prefGenericAddBox\">
825                                 <input id=\"fadd_cat\" 
826                                         onkeyup=\"toggleSubmitNotEmpty(this, 'catadd_submit_btn')\"
827                                         size=\"40\">&nbsp;
828                                 <input 
829                                         type=\"submit\" class=\"button\" disabled=\"true\" id=\"catadd_submit_btn\"
830                                         onclick=\"javascript:addFeedCat()\" value=\"Create category\"></div>";
831         
832                         $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
833                                 WHERE owner_uid = ".$_SESSION["uid"]."
834                                 ORDER BY title");
835
836                         if (db_num_rows($result) != 0) {
837         
838                                 print "<form id=\"feed_cat_edit_form\">";
839                                 
840                                 print "<p><table width=\"100%\" class=\"prefFeedCatList\" 
841                                         cellspacing=\"0\" id=\"prefFeedCatList\">";
842
843                                 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
844                                 Select: 
845                                         <a href=\"javascript:selectPrefRows('fcat', true)\">All</a>,
846                                         <a href=\"javascript:selectPrefRows('fcat', false)\">None</a>
847                                 </td</tr>";
848
849                                 print "<tr class=\"title\">
850                                                         <td width=\"5%\">&nbsp;</td><td width=\"80%\">Title</td>
851                                                 </tr>";
852                                                 
853                                 $lnum = 0;
854                                 
855                                 while ($line = db_fetch_assoc($result)) {
856                 
857                                         $class = ($lnum % 2) ? "even" : "odd";
858                 
859                                         $cat_id = $line["id"];
860                 
861                                         $edit_cat_id = $_GET["id"];
862                 
863                                         if ($subop == "editCat" && $cat_id != $edit_cat_id) {
864                                                         $class .= "Grayed";
865                                                         $this_row_id = "";
866                                         } else {
867                                                 $this_row_id = "id=\"FCATR-$cat_id\"";
868                                         }
869                 
870                                         print "<tr class=\"$class\" $this_row_id>";
871                 
872                                         $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
873                 
874                                         if (!$edit_cat_id || $subop != "editCat") {
875                 
876                                                 print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"fcat\");' 
877                                                         type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>";
878                 
879                                                 print "<td><a href=\"javascript:editFeedCat($cat_id);\">" . 
880                                                         $edit_title . "</a></td>";              
881                 
882                                         } else if ($cat_id != $edit_cat_id) {
883                 
884                                                 print "<td align='center'><input disabled=\"true\" type=\"checkbox\" 
885                                                         id=\"FRCHK-".$line["id"]."\"></td>";
886                 
887                                                 print "<td>$edit_title</td>";           
888                 
889                                         } else {
890                 
891                                                 print "<td align='center'><input disabled=\"true\" type=\"checkbox\" checked>";
892                                                 
893                                                 print "<input type=\"hidden\" name=\"id\" value=\"$cat_id\">";
894                                                 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
895                                                 print "<input type=\"hidden\" name=\"subop\" value=\"saveCat\">";
896                                         
897                                                 print "</td>";
898                 
899                                                 print "<td><input onkeypress=\"return filterCR(event)\"
900                                                         name=\"title\" class=\"iedit\" value=\"$edit_title\"></td>";
901                                                 
902                                         }
903                                         
904                                         print "</tr>";
905                 
906                                         ++$lnum;
907                                 }
908         
909                                 print "</table>";
910
911                                 print "</form>";
912         
913                                 print "<p id=\"catOpToolbar\">";
914         
915                                 if ($subop == "editCat") {
916                                         print "Edit category:&nbsp;
917                                                 <input type=\"submit\" class=\"button\"
918                                                         onclick=\"return feedCatEditSave()\" value=\"Save\">
919                                                 <input type=\"submit\" class=\"button\"
920                                                         onclick=\"return feedCatEditCancel()\" value=\"Cancel\">";
921                                         } else {
922                 
923                                         print "
924                                                 Selection:&nbsp;
925                                         <input type=\"submit\" class=\"button\" disabled=\"true\"
926                                                 onclick=\"return editSelectedFeedCat()\" value=\"Edit\">
927                                         <input type=\"submit\" class=\"button\" disabled=\"true\"
928                                                 onclick=\"return removeSelectedFeedCats()\" value=\"Remove\">";
929         
930                                 }
931         
932                         } else {
933                                 print "<p>No feed categories defined.</p>";
934                         }
935                 }
936
937                 print "<h3>Import OPML</h3>
938                 <form   enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
939                         File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
940                         <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
941                                 type=\"submit\" value=\"Import\">
942                         </form>";
943         }
944 ?>