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