# favorites.pl in my windows favorites folder. # How to share MS Explorer Favourites as a web page with other browsers. # Author: Rajiv Pant (Betul) betul@rajiv.org http://rajiv.org use CGI ; use Cwd ; # Gets the current working directory. $DEBUG = 0 ; # main section $cgi = new CGI ; print $cgi->header ; $FOLDER = $cgi->param('folder') ; # Just for some security, we check if the requested folder # is inside someone's Windows favorites folder. # You may change the line below to suit your system or needs. undef $FOLDER unless $FOLDER =~ /^C:\\WINNT\\Profiles\\\w+\\Favorites/i ; ($SCRIPT_NAME_ONLY) = ($SCRIPT_NAME = $ENV{'SCRIPT_NAME'}) =~ m{^.*/(.*?)$} ; ($FOLDER) = $ENV{'PATH_TRANSLATED'} =~ /^(.*)\\$SCRIPT_NAME_ONLY$/i unless $FOLDER ; # The following folders under MSIE favorites are not my bookmarks. # They are system folders for my channels, links buttons, etc. @excluded_folders = qw( Channels Links ) ; # Prepending the path to the root favorites folder to each excluded folder. grep $_ = $FOLDER . '\\' . $_ , @excluded_folders ; local $LEVEL ; # level of recursion into folders. &show_bookmarks_in_folder_recursively ($FOLDER) ; # end of main section sub show_bookmarks_in_folder_recursively { my $folder = shift ; local *FOLDER ; my $cwd = cwd() ; chdir $folder or print < EOM ++$LEVEL ; # We are now one level deeper into the folders. print < EOM opendir FOLDER, $folder or print < EOM my @entries = grep $_ ne '.' && $_ ne '..', readdir FOLDER ; closedir FOLDER ; $DEBUG and print < EOM my $entry ; foreach $entry (@entries) { if (-f "$folder/$entry" and $entry =~ /\.url$/i ) { $DEBUG and print < EOM # print '   ' x $LEVEL ; print "
  • \n" ; &show_url ("$folder/$entry") ; print "
  • \n" ; } elsif (-d "$folder/$entry") { $DEBUG and print < EOM next if grep "$folder\\$entry" eq $_ , @excluded_folders ; # print '   ' x $LEVEL ; print "
  • \n" ; &show_folder ("$folder/$entry") ; print "
  • \n" ; &show_bookmarks_in_folder_recursively ("$folder/$entry") ; } } # end foreach $DEBUG and print < EOM chdir $cwd ; --$LEVEL ; # We have now gone up one level in the folders. print < EOM } # end sub show_bookmarks_in_folder_recursively sub show_folder { my $folder = shift ; my ($folder_name) = $folder =~ m{^.*[\\\/](.*)$}o ; $folder_urlencoded = encode_as_url ($folder) ; print < $folder_name
    EOM } # end of sub show_folder sub show_url { my $url_file = shift ; my $url ; my ($url_name) = $url_file =~ m{^.*[\\\/](.*)\.url$}io ; local *FILE ; open FILE, $url_file ; while () { last if ($url) = /^URL=(.*)$/ ; } close FILE ; print < $url_name
    EOM } # end of sub show_url # ------------------------------------------------------------------------ # NOTE: the following functions are from my use-cgi library -- Betul. # this subroutine converts the given string to it's url encoded form. # it converts everything but perl's \W and the space char. Even the & # is converted so that the encoded string may be saved as a nice file name. sub encode_as_url { ($_) = @_ ; s/([^\w ])/&char_2_hex_digits($1)/eg ; s/ /+/g ; return $_ ; } # this returns the two digit hex code for the given character. # it is used by the encode_as_url subroutine sub char_2_hex_digits { my ($c, @hex_digit) = (ord($_[0]), ('0'..'9', 'a'..'f') ) ; return '%' . $hex_digit[$c >> 4] . $hex_digit[$c & 15] ; }