[Bio] / FigKernelPackages / HTML.pm Repository:
ViewVC logotype

Diff of /FigKernelPackages/HTML.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.54, Thu Aug 18 19:16:03 2005 UTC revision 1.55, Fri Aug 19 15:47:54 2005 UTC
# Line 278  Line 278 
278      {      {
279         $css->{'Sans Serif'} = &FIG::cgi_url() . "/Html/css/sanserif.css";         $css->{'Sans Serif'} = &FIG::cgi_url() . "/Html/css/sanserif.css";
280      }      }
281    
282      my $csstext = "<link rel='stylesheet' title='default' href='".$css->{'Default'}."' type='text/css'>\n";      my $csstext = "<link rel='stylesheet' title='default' href='".$css->{'Default'}."' type='text/css'>\n";
283      $csstext   .= "<link rel='alternate stylesheet' title='Sans Serif' href='".$css->{'Sans Serif'}."' type='text/css'>\n";      $csstext   .= "<link rel='alternate stylesheet' title='Sans Serif' href='".$css->{'Sans Serif'}."' type='text/css'>\n";
284    
# Line 287  Line 288 
288         $csstext .= "<link rel='alternate stylesheet' title='$k' href='".$css->{$k}."' type='text/css'>\n";         $csstext .= "<link rel='alternate stylesheet' title='$k' href='".$css->{$k}."' type='text/css'>\n";
289      }      }
290    
291        $csstext   .= "<link rel='alternate'  title='SEED RSS feeds' href='".&FIG::cgi_url()."/Html/rss/SEED.rss' type='application/rss+xml'>\n";
292    
293      # RAE: also added support for external javascripts here.      # RAE: also added support for external javascripts here.
294      # we are cluttering the HTML code with all the javascripts when they could easily be in external files      # we are cluttering the HTML code with all the javascripts when they could easily be in external files
# Line 987  Line 989 
989      return $out;      return $out;
990  }  }
991    
992  1  =head1 rss_feed
993    
994    Add something to the RSS feed. The rss feeds are stored in the Html directory, and there are several RSS feeds:
995            SEED.rss                - everything gets written here
996            SEEDgenomes.rss                 - whenever a genome is added to the SEED
997            SEEDsubsystems.rss      - whenever a subsystem is edited (or should this be added?)
998    
999    
1000    RSS feeds must contain a title, description, and link. The title is what is seen e.g. from the firefox or safari pull down menu. The description is seen from within an rss aggregator, and may be displayed on web pages and so on.
1001    
1002    The method takes a reference to an array containing the file names for the RSS feeds to add your item to, and a hash of items for the xml. Only title, description, and link are required tags in the XML.
1003    
1004    The file names are the full name of the file, eg SEEDsubsystems.rss, SEEDgenomes.rss. Be aware that this is a file name, though, so don't uses special characters. The path will be added.
1005    
1006    The has can have these keys:
1007    
1008    REQUIRED:
1009    title       : the title. This is usually what is seen by the user in the pull down menu
1010    description : a more complete description that is often seen is rss viewers but not always
1011    link        : link to the item that was added/edited
1012    All other keys are treated as optional RSS arguments and written to the file. At most, 10 recent entries are stored in the rss file.
1013    
1014    RSS files are quite simple, and contain some standard header information, and then individual items surrounded by an <item> </item> tag. Note that there is also an initial title/description/link set that describes the file.
1015    
1016    
1017    =cut
1018    
1019    sub rss_feed {
1020     shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1021     my ($files, $args)=@_;
1022     foreach my $a (keys %$args) {if ($a =~ /^-(.*)/) {my $b=$1; $args->{$b}=$args->{$a}; delete $args->{$a}}}
1023    
1024     my $filepath=$FIG_Config::fig."/CGI/Html/rss";
1025     # check for the directory and if not, make it
1026     mkdir $filepath unless (-d $filepath);
1027    
1028     # note that $info is a hash of references to hashes that are written out as headers in the file
1029     my $info=
1030     {
1031      "SEED.rss" =>
1032       {
1033            title           => "The SEED",
1034            description     => "Latest news from the SEED",
1035            link            => &FIG::cgi_url()."/Html/rss/SEED.rss",
1036       },
1037    
1038      "SEEDsubsystems.rss" =>
1039      {
1040            title           => "SEED Subsystems",
1041            description     => "Recently updated SEED subsystems",
1042            link            => &FIG::cgi_url()."/Html/rss/SEEDsubsystems.rss",
1043      },
1044    
1045      "SEEDsubsystems.rss" =>
1046      {
1047            title           => "SEED Genomes",
1048            description     => "Genomes recently added to the SEED",
1049            link            => &FIG::cgi_url()."/Html/rss/SEEDsubsystems.rss",
1050      },
1051    
1052     };
1053    
1054    
1055     # build the new xml
1056     my $xml = "\t<item>\n";
1057     foreach my $qw ("title", "description", "link") {
1058      unless ($args->{$qw}) {
1059       print STDERR "You need to include a $qw tag in your RSS description\n";
1060       return(0);
1061      }
1062      # we need to do something a bit funky with the link. We can't have ampersands in the <link> </link> in valid html
1063      # so we are going to pull out the links and uri_escape just the part after the .cgi
1064      if ($qw eq "link")
1065      {
1066       $args->{$qw} =~ /^(.*?\.cgi.)(.*)$/;
1067       print STDERR "Got ->>$1<<- and ->>$2<<-\n";
1068       $args->{$qw} = $1.uri_escape($2) if ($1 && $2);
1069      }
1070    
1071      $xml .= "\t\t<$qw>".$args->{$qw}."</$qw>\n";
1072      delete $args->{$qw};
1073     }
1074    
1075     foreach my $tag (grep {!/type/i} keys %$args)
1076     {
1077      $xml .= "\t\t<$tag>".$args->{$tag}."</$tag>\n";
1078     }
1079    
1080     $xml .= "\t</item>\n";
1081    
1082    
1083     my @files=("SEED.rss");
1084     if ($args->{"type"}) {push @files, "SEED.$type.rss"}
1085    
1086     foreach my $file ("SEED.rss", @$files)
1087     {
1088      if (-e "$filepath/$file")
1089      {
1090       my @out; # the new content of the file
1091       my $itemcount=0; # how many <item> </item>'s are we keeping
1092       my $initem; # are we in an item?
1093       open(IN, "$filepath/$file") || die "Can't open $filepath/$file";
1094       while (<IN>)
1095       {
1096        if (/\<item\>/) {
1097         push @out, $xml, unless ($itemcount);
1098         $itemcount++;
1099         $initem=1;
1100        }
1101        if (/\<\/item\>/) {$initem=0; next if ($itemcount > 9)}
1102        next if ($initem && $itemcount > 9);
1103        push @out, $_;
1104       }
1105       close IN;
1106       open(OUT, ">$filepath/$file") || die "Can't open $filepath/$file for writing";
1107       print OUT @out;
1108      }
1109      else
1110      {
1111       open(OUT, ">$filepath/$file") || die "Can't open $filepath/$file for writing";
1112       print OUT "<?xml version=\"1.0\"?>\n<rss version=\"2.0\">\n<channel>\n";
1113       if ($info->{$file})
1114       {
1115         # we're going to sanity check each of the three options we output, just to be sure
1116         foreach my $qw ("title", "description", "link")
1117         {
1118           if ($info->{$file}->{$qw})
1119           {
1120              print OUT "<$qw>", $info->{$file}->{$qw}, "</$qw>\n";
1121           } else {
1122              print STDERR "Please add a $qw for $file\n"; print OUT "<$qw>$file</$qw>\n";
1123           }
1124         }
1125       }
1126       else {
1127        print STDERR "Please define title, link, and description information for $file\n";
1128        print OUT "<title>$file</title>\n<description>An RSS feed</description>\n<link>", &FIG::cgi_url, "</link>\n";
1129       }
1130       print OUT "\n", $xml;
1131       print OUT "\n", "</channel>\n</rss>\n"
1132      }
1133     }
1134    }
1135    
1136    1;
1137    

Legend:
Removed from v.1.54  
changed lines
  Added in v.1.55

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3