[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.36, Tue Mar 15 21:01:14 2005 UTC revision 1.58, Fri Sep 16 15:09:32 2005 UTC
# Line 1  Line 1 
1  package HTML;  package HTML;
2    
3    use Tracer;
4  use FIG;  use FIG;
5  use Carp;  use Carp;
6  use Data::Dumper;  use Data::Dumper;
7  use LWP::UserAgent;  use LWP::UserAgent;
8  use LWP::Simple;  use LWP::Simple;
9    use URI::Escape;  # uri_escape()
10  use URI::URL;  use URI::URL;
11  use HTTP::Request::Common;  use HTTP::Request::Common;
12  use POSIX;  use POSIX;
# Line 21  Line 23 
23  sub compute_html_header  sub compute_html_header
24  {  {
25      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
26      my($additional_insert,$user) = @_;      my($additional_insert, $user, %options ) = @_;
27      my $html_hdr_file = "./Html/html.hdr";  
28        my $header_name = $options{header_name} ? $options{header_name} : "html.hdr";
29        my $tail_name = $options{tail_name} ? $options{tail_name} : "html.tail";
30    
31        my $html_hdr_file = "./Html/$header_name";
32      if (! -f $html_hdr_file)      if (! -f $html_hdr_file)
33      {      {
34          $html_hdr_file = "$FIG_Config::fig/CGI/Html/html.hdr";          $html_hdr_file = "$FIG_Config::fig/CGI/Html/$header_name";
35      }      }
36      my @html_hdr = &FIG::file_read($html_hdr_file);      my @html_hdr = &FIG::file_read($html_hdr_file);
37      push( @html_hdr, "<br><a href=\"index.cgi?user=$user\">FIG search</a>\n" );  
38        $options{no_fig_search} or push( @html_hdr, "<br><a href=\"index.cgi?user=$user\">FIG search</a>\n" );
39    
40      if (@html_hdr)      if (@html_hdr)
41      {      {
42          my $insert_stuff;          my $insert_stuff;
43    
44            if (not $options{no_release_info})
45            {
46          my @ver = &FIG::file_head("$FIG_Config::fig_disk/CURRENT_RELEASE", 1);          my @ver = &FIG::file_head("$FIG_Config::fig_disk/CURRENT_RELEASE", 1);
47          my $ver = $ver[0];          my $ver = $ver[0];
48          chomp $ver;          chomp $ver;
# Line 44  Line 54 
54          }          }
55          my $host = &FIG::get_local_hostname();          my $host = &FIG::get_local_hostname();
56          $insert_stuff = "SEED version <b>$ver</b> on $host";          $insert_stuff = "SEED version <b>$ver</b> on $host";
57            }
58    
59          if ($additional_insert)          if ($additional_insert)
60          {          {
61              $insert_stuff .= "<br>" . $additional_insert;              $insert_stuff .= "<br>" . $additional_insert;
# Line 52  Line 64 
64          for $_ (@html_hdr)          for $_ (@html_hdr)
65          {          {
66              s,(href|img\s+src)="/FIG/,\1="$FIG_Config::cgi_base,g;              s,(href|img\s+src)="/FIG/,\1="$FIG_Config::cgi_base,g;
67                s,(\?user\=)\",$1$user",;
68              if ($_ eq "<!-- HEADER_INSERT -->\n")              if ($_ eq "<!-- HEADER_INSERT -->\n")
69              {              {
70                  $_ = $insert_stuff;                  $_ = $insert_stuff;
# Line 65  Line 78 
78  sub show_page {  sub show_page {
79      #warn "SHOWPAGE: cgi=", Dumper(@_);      #warn "SHOWPAGE: cgi=", Dumper(@_);
80      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
81      my($cgi,$html,$no_home, $alt_header, $css) = @_;      my($cgi,$html,$no_home, $alt_header, $css, $javasrc) = @_;
82      my $i;      my $i;
83    
   
84      # ARGUMENTS:      # ARGUMENTS:
85      #     $cgi is the CGI method      #     $cgi is the CGI method
86      #     $html is an array with all the html in it. It is just joined by "\n" (and not <br> or <p>      #     $html is an array with all the html in it. It is just joined by "\n" (and not <br> or <p>
# Line 77  Line 89 
89      #     $css is a reference to a hash. The key is the name of the CSS sheet and the value is the URL of that sheet. Note the usual rules about relative css urls      #     $css is a reference to a hash. The key is the name of the CSS sheet and the value is the URL of that sheet. Note the usual rules about relative css urls
90      #               the sheet named "Default" is considered to be the default style sheet, and if this is not set it points at $FIG_Config::HTML/css/default.css      #               the sheet named "Default" is considered to be the default style sheet, and if this is not set it points at $FIG_Config::HTML/css/default.css
91      #               the sheet named "Sans Serif" is considered to the the first alternate, and if this is not set it points at $FIG_Config::HTML/css/sanserif.css      #               the sheet named "Sans Serif" is considered to the the first alternate, and if this is not set it points at $FIG_Config::HTML/css/sanserif.css
92        #     $javasrc is a reference to an array of URLs to javascripts to be included (e.g. "/FIG/Html/css/styleswitcher.js")
93      #      #
94      # Find the HTML header      # Find the HTML header
95      #      #
96    
97      my $html_tail_file = "./Html/html.tail";      my $html_tail_file = "./Html/$tail_name";
98      if (! -f $html_tail_file)      if (! -f $html_tail_file)
99      {      {
100          $html_tail_file = "$FIG_Config::fig/CGI/Html/html.tail";          $html_tail_file = "$FIG_Config::fig/CGI/Html/$tail_name";
101      }      }
102    
103      my $user = $cgi->param('user') || "";      my $user = $cgi->param('user') || "";
104      my @html_hdr;      my @html_hdr;
105      if ($alt_header)      if ($alt_header && ref($alt_header) eq "ARRAY")
106      {      {
107         @html_hdr = @$alt_header;         @html_hdr = @$alt_header;
108      }      }
# Line 221  Line 233 
233      #  Added the javascript for the buttons immediately after body.      #  Added the javascript for the buttons immediately after body.
234      #  Note if no buttons are added we still (at the moment) add the script,      #  Note if no buttons are added we still (at the moment) add the script,
235      #  but it only adds a little text (495 characters) to the html and noone will notice!      #  but it only adds a little text (495 characters) to the html and noone will notice!
236        #  RAE: This is now deprecated because everything is in an external file, FIG.js, included later
237    
238      if ( $body_line < 0 )      if ( $body_line < 0 )
239      {      {
         my $js=&javascript;  
240          $body_line = $last_head_line + 1;          $body_line = $last_head_line + 1;
241          splice( @$html, $body_line, 0, "<BODY>\n$js\n" );          splice( @$html, $body_line, 0, "<BODY>\n" );
242      }      }
243    
244      #      #
# Line 250  Line 262 
262    
263      # RAE:      # RAE:
264      # Add css here      # Add css here
265      # Note that at the moment I define these two sheets here. I think this should be moved out, but I want to try it and see what happens      # Note that at the moment I define these two sheets here. I think this should
266      # css has the format      # be moved out, but I want to try it and see what happens.  css has the format:
267        #
268      # <link rel='stylesheet' title='default' href='/css/default.css' type='text/css'>      # <link rel='stylesheet' title='default' href='/css/default.css' type='text/css'>
269    
270      # convert the default key to the right case. and eliminate dups      # convert the default key to the right case. and eliminate dups
# Line 259  Line 272 
272    
273      if (!$css || !$css->{'Default'})      if (!$css || !$css->{'Default'})
274      {      {
275         $css->{'Default'}="/FIG/Html/css/default.css";         $css->{'Default'} = &FIG::cgi_url() . "/Html/css/default.css";
276      }      }
277      if (!$css->{"Sans Serif"})      if (!$css->{"Sans Serif"})
278      {      {
279         $css->{'Sans Serif'}="/FIG/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    
285      foreach my $k (keys %$css)      foreach my $k (keys %$css)
286      {      {
287         next if (lc($k) eq "default" || lc($k) eq "sans serif");         next if (lc($k) eq "default" || lc($k) eq "sans serif");
288         $csstext .= "<link rel='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.
294        # we are cluttering the HTML code with all the javascripts when they could easily be in external files
295        # this solution allows us to source other files
296    
297        # the file FIG.js contains most of the java script we use routinely. Every browser will just cache this and so
298        # it will reduce our overhead.
299    
300        # $javasrc must be a ref to an array with urls (absolute or relative) to the javascripts
301        push @$javasrc, &FIG::cgi_url() . "/Html/css/FIG.js";
302        foreach my $script (@$javasrc) {
303            $csstext .= "<script src=\"$script\" type=\"text/javascript\"></script>\n";
304        }
305    
306    
307    
308      splice( @$html, $head_end_line, 1, "$csstext</HEAD>\n" );  # note here I am replacing the </head> line. Could be bad...? But it doesn't increment everything else.      splice( @$html, $head_end_line, 1, "$csstext</HEAD>\n" );  # note here I am replacing the </head> line. Could be bad...? But it doesn't increment everything else.
309    
310      #      #
# Line 350  Line 382 
382      #  Figure out where to insert The SEED tail.  Before </body>,      #  Figure out where to insert The SEED tail.  Before </body>,
383      #  or before </html>, or at end of page.      #  or before </html>, or at end of page.
384      #      #
   
385      my @tags = ();      my @tags = ();
386        # Check for a tracing queue.
387        my $traceString = QTrace("HTML");
388        if ($traceString) {
389            push @tags, $traceString;
390        }
391      for ($i=0; ($i < @$html) && ($html->[$i] !~ /\<\/body\>/i); $i++) {}      for ($i=0; ($i < @$html) && ($html->[$i] !~ /\<\/body\>/i); $i++) {}
392      if ($i >= @$html)        # </body> not found; look for </html>      if ($i >= @$html)        # </body> not found; look for </html>
393      {      {
# Line 374  Line 409 
409          splice( @$html, $i, 0, @tags );          splice( @$html, $i, 0, @tags );
410      }      }
411    
412      # RAE the chomp will return any new lines at the ends of elements in the array, and then we can join  with a "\n"      # RAE the chomp will return any new lines at the ends of elements in the array,
413      # this is because somethings put newlines in, and others don't. This should make nicer looking html      # and then we can join  with a "\n". This is because somethings put newlines in,
414      chomp(@$html);      # and others don't. This should make nicer looking html
415      print join "\n", @$html;      #
416        # chomp(@$html);
417        # print join "\n", @$html;
418        #
419        # Apparently the above still breaks things. This is the correct code:
420    
421        foreach $_ (@$html)
422        {
423            print $_;
424        }
425    
426  }  }
427    
428  sub make_table {  sub make_table {
# Line 411  Line 456 
456    
457      $tag = "td" unless $tag;      $tag = "td" unless $tag;
458      my $endtag=$tag;      my $endtag=$tag;
459      # RAE modified this so that you can pass in a reference to an array where the first element is the data to  
460      # display and the second element is optional things like colspan and align. Note that in this case you need to include the td      # RAE modified this so that you can pass in a reference to an array where
461        # the first element is the data to display and the second element is optional
462        # things like colspan and align. Note that in this case you need to include the td
463      # use something like ["some data to appear", "td colspan=4 bgcolor=gray"]      # use something like ["some data to appear", "td colspan=4 bgcolor=gray"]
464      if (ref($x) eq "ARRAY") {($x, $tag)=@$x; if ($tag =~ /td/) {$endtag = "td"}}  
465        # per GJO's request modified this line so it can take any tag.
466        if ( ref($x) eq "ARRAY" ) { ($x, $tag) = @$x; $tag =~ /^(\S+)/; $endtag = $1 }
467    
468      if ($x =~ /^\@([^:]+)\:(.*)$/)      if ($x =~ /^\@([^:]+)\:(.*)$/)
469      {      {
# Line 426  Line 475 
475      }      }
476  }  }
477    
478    
479    sub merge_table_rows {
480     # RAE:
481     # Experimental piece of code. We often want to have rows or columns were cells are merged. It just looks so much nicer
482     # this block should merge adjacent rows that have the same text in them.
483     # use like this:
484     #      $tab=&HTML::merge_table_rows($tab);
485     # before you do a make_table call
486    
487     my $self=shift if UNIVERSAL::isa($_[0],__PACKAGE__);
488     my ($tab)=@_;
489    
490     my $newtable;
491     my $lastrow;
492     my $rowspan;
493     my $refs;
494    
495     for (my $y=0; $y <= $#$tab; $y++) {
496     #$y is the row in the table;
497      for (my $x=0; $x <= $#{$tab->[$y]}; $x++) {
498       #$x is the column in the table
499       # if the column in the row we are looking at is the same as the column in the previous row, we don't add
500       # this cell to $newtable. Instead we increment the rowspan of the previous row by one
501    
502       # handle cells that are references to arrays
503       if (ref($tab->[$y]->[$x]) eq "ARRAY") {$refs->[$y]->[$x]=$tab->[$y]->[$x]->[1]; $tab->[$y]->[$x]=$tab->[$y]->[$x]->[0]}
504    
505       # now we go back through the table looking where to draw the merge line:
506       my $lasty=$y;
507       while ($lasty >= 0 && $tab->[$y]->[$x] eq $tab->[$lasty]->[$x]) {$lasty--}
508       $lasty++; # this is the last identical cell. If lasty==y it is the current cell, so we just save the data. Otherwise we increment the rowspan
509       if ($lasty == $y) {
510        # we always want to have something in rows that may otherwise be empty but should be there (see below)
511        unless ($tab->[$y]->[$x]) {$tab->[$y]->[$x]=" &nbsp; "}
512        $newtable->[$y]->[$x] = $tab->[$y]->[$x];
513       }
514       else {$rowspan->[$lasty]->[$x]++}
515      }
516     }
517    
518     # now just join everything back together
519     for (my $y=0; $y <= $#$tab; $y++) {
520      for (my $x=0; $x <= $#{$tab->[$y]}; $x++) {
521       if ($rowspan->[$y]->[$x]) {
522        if ($refs->[$y]->[$x]) {$refs->[$y]->[$x] .= " rowspan=". ($rowspan->[$y]->[$x]+1)}
523        else {$refs->[$y]->[$x] = "td rowspan=". ($rowspan->[$y]->[$x]+1)}
524        $newtable->[$y]->[$x]=[$newtable->[$y]->[$x], $refs->[$y]->[$x]];
525       }
526       elsif ($newtable->[$y]->[$x] && $refs->[$y]->[$x]) {
527        $newtable->[$y]->[$x]=[$newtable->[$y]->[$x], $refs->[$y]->[$x]];
528       }
529      }
530     }
531    
532    
533     # finally we have to remove any completely empty cells that have been added by the array mechanism
534     # (e.g. if you define $a->[2] then $a->[0] and $a->[1] are now undef).
535     # that is why in the loop above I replace empty cells with nbsp. They are now not undef!
536     # I am sure that Gary can do this in one line, but I am hacking.
537     my @trimmed;
538     foreach my $a (@$newtable) {
539      my @row;
540      foreach my $b (@$a) {
541       push @row, $b if ($b);
542      }
543      push @trimmed, \@row;
544     }
545    
546     return \@trimmed;
547    }
548    
549    
550    
551    
552  sub set_ec_links {  sub set_ec_links {
553      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
554      my($cgi,$x) = @_;      my($cgi,$x) = @_;
# Line 493  Line 616 
616          {          {
617              $n = $fid;              $n = $fid;
618          }          }
619          if ($1 ne "peg") { return $n }  
620            #added to format prophage and path island links to feature.cgi
621            if ($1 ne "peg")
622            {
623               my $user = $cgi->param('user');
624               if (! $user) { $user = "" }
625               my $sprout = $cgi->param('SPROUT') ? "&SPROUT=1" : "";
626               my $link = &FIG::cgi_url . "/feature.cgi?feature=$fid&user=$user$trans$sprout";
627               $link =~ s/[a-z_A-Z0-9]+\.cgi\?/feature.cgi?/;
628               return "<a href=$link>$n</a>";
629            }
630    
631            if ($1 eq "peg")
632            {
633          my $user = $cgi->param('user');          my $user = $cgi->param('user');
634          if (! $user) { $user = "" }          if (! $user) { $user = "" }
635          my $trans = $cgi->param('translate') ? "&translate=1" : "";          my $trans = $cgi->param('translate') ? "&translate=1" : "";
636          my $sprout = $cgi->param('SPROUT') ? "&SPROUT=1" : "";          my $sprout = $cgi->param('SPROUT') ? "&SPROUT=1" : "";
637          my $link = &FIG::cgi_url . "/protein.cgi?prot=$fid&user=$user$trans$sprout";  ###a
638    
639    ### This used to be
640    ###     my $link = &FIG::cgi_url . "/protein.cgi?prot=$fid&user=$user$trans$sprout";
641    ###
642    ### The cost became prohibitive in the subsystem spreadsheets.  Hence, we cache the value
643    ###
644    ### RAO
645    
646                if (! $cgi_url) { $cgi_url = &FIG::cgi_url }
647                my $link = $cgi_url . "/protein.cgi?prot=$fid&user=$user$trans$sprout";
648          $link =~ s/[a-z_A-Z0-9]+\.cgi\?/protein.cgi?/;          $link =~ s/[a-z_A-Z0-9]+\.cgi\?/protein.cgi?/;
649          #          #
650          # Elimin the p2p part if we're in that subdir. Ugh.          # Elimin the p2p part if we're in that subdir. Ugh.
651          #          #
652          $link =~ s,p2p/protein.cgi,protein.cgi,;          $link =~ s,p2p/protein.cgi,protein.cgi,;
653    
654                }
655          if ($just_url)          if ($just_url)
656          {          {
657              return $link;              return $link;
# Line 524  Line 671 
671      return $family;      return $family;
672  }  }
673    
 use URI::Escape;  
674    
675  sub get_html {  sub get_html {
676      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
# Line 655  Line 801 
801          $after = $3;          $after = $3;
802          return &set_prot_links($cgi,$before) . &HTML::gi_link($cgi,$match) . &set_prot_links($cgi,$after);          return &set_prot_links($cgi,$before) . &HTML::gi_link($cgi,$match) . &set_prot_links($cgi,$after);
803      }      }
804        elsif ($x =~ /^(.*)(tigr\|[0-9a-zA-Z]+)(.*)/s)
805        {
806            $before = $1;
807            $match = $2;
808            $after = $3;
809            return &set_prot_links($cgi,$before) . &HTML::tigr_link($cgi,$match) . &set_prot_links($cgi,$after);
810        }
811      elsif ($x =~  /^(.*)(uni\|[A-Z0-9]{6})(.*)/s)      elsif ($x =~  /^(.*)(uni\|[A-Z0-9]{6})(.*)/s)
812      {      {
813          $before = $1;          $before = $1;
# Line 707  Line 860 
860      return $gi;      return $gi;
861  }  }
862    
863    sub tigr_link {
864        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
865        my($cgi,$tigr) = @_;
866    
867        if ($tigr =~ /^tigr\|([0-9a-zA-Z]+)$/)
868        {
869            return "<a href=\"http://pathema.tigr.org/tigr-scripts/CMR/GenePage.cgi?locus=$1\">$tigr</a>";
870        }
871        return $tigr;
872    }
873    
874  sub uni_link {  sub uni_link {
875      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
876      my($cgi,$uni) = @_;      my($cgi,$uni) = @_;
# Line 775  Line 939 
939      $user = $cgi->param('user');      $user = $cgi->param('user');
940      $user = $user ? $user : "";      $user = $user ? $user : "";
941      $org = $org ? $org : "";      $org = $org ? $org : "";
942      my $url = "$FIG_Config::cgi_url/show_kegg_map.cgi?user=$user&map=$map&org=$org";  
943        my $url = &FIG::cgi_url() . "/show_kegg_map.cgi?user=$user&map=$map&org=$org";
944      my $link = "<a href=\"$url\">$map</a>";      my $link = "<a href=\"$url\">$map</a>";
945      return $link;      return $link;
946  }  }
947    
 sub javascript {  
     shift if UNIVERSAL::isa($_[0],__PACKAGE__);  
         #### MODIFIED BY RAE TO ADD JAVA SUPPORT FOR CHECK ALL/UNCHECK ALL  
         # This routine takes three arguments, $html, $form, and $button  
         # $html is the ref to the array with the html in it  
         # $form is the name of the form. This must be added whenever start_form is called  
         # by including a -name entry. This is only used for the javascript  
         # $button is the name of the button that should be checked/unchecked.  
         #  
         # At the moment this add's four buttons:  
         # Check all, check's all  
         # Check first half will check the first 50% of the entries  
         # Check second half will check the second 50% of the entries  
         # Uncheck all will remove the checks.  
   
         # Note that the other change is I added a -name=>'fig_checked' to the start_form  
         # field. The name is needed for the java script.  
         #  
   
           $java_script=<<EOF;  
   <SCRIPT LANGUAGE="JavaScript">  
   <!-- Begin  
   function checkAll(field)  
   {  
    for (i = 0; i < field.length; i++)  
    field[i].checked = true ;  
   }  
   
   function checkFirst(field)  
   {  
    for (i = 0; i < field.length/2; i++)  
    field[i].checked = true;  
   }  
   
   function checkSecond(field)  
   {  
    for (i=Math.round(field.length/2); i < field.length; i++)  
    field[i].checked = true ;  
   }  
   
   function uncheckAll(field)  
   {  
    for (i = 0; i < field.length; i++)  
    field[i].checked = false ;  
   }  
   //  End -->  
   </script>  
 EOF  
         return $java_script;  
 }  
   
948  sub java_buttons {  sub java_buttons {
949      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
950    ## ADDED BY RAE    ## ADDED BY RAE
# Line 855  Line 969 
969      my $user = $cgi->param('user');      my $user = $cgi->param('user');
970      if ($user)      if ($user)
971      {      {
972          $sub_link = "<a href=./subsys.cgi?ssa_name=$sub&request=show_ssa&user=$user>$sub</a>";          my $esc_sub = uri_escape( $sub );
973            $sub_link = "<a href=./subsys.cgi?ssa_name=$esc_sub&request=show_ssa&user=$user>$sub</a>";
974      }      }
975      else      else
976      {      {
# Line 864  Line 979 
979      return $sub_link;      return $sub_link;
980  }  }
981    
982  1  sub reaction_link {
983        my($reaction) = @_;
984    
985        if ($reaction =~ /^R\d+/)
986        {
987            return "<a href=\"http://www.genome.ad.jp/dbget-bin/www_bget?rn+$reaction\" target=reaction$$>$reaction</a>";
988        }
989        return $reaction;
990    }
991    
992    sub html_for_assignments {
993        my($fig,$user,$peg_sets) = @_;
994        my $i;
995    
996        my @vals = ();
997        my $set = 1;
998        foreach $peg_set (@$peg_sets)
999        {
1000            for ($i=0; ($i < @$peg_set); $i++)
1001            {
1002                $peg = $peg_set->[$i];
1003                push(@vals,'show=' . join("@",($set,$i+1,$peg,&FIG::abbrev($fig->org_of($peg)),"")));
1004            }
1005            $set++;
1006        }
1007    
1008        $ENV{'REQUEST_METHOD'} = 'GET';
1009        $ENV{'QUERY_STRING'} = join('&',('request=show_commentary',"uni=1","user=$user",@vals));
1010        my $out = join("",`$FIG_Config::fig/CGI/chromosomal_clusters.cgi`);
1011        $out =~ s/^.*?<form/<form/si;
1012        $out =~ s/^(.*)<table.*/$1/si;
1013        return $out;
1014    }
1015    
1016    =head1 rss_feed
1017    
1018    Add something to the RSS feed. The rss feeds are stored in the Html directory, and there are several RSS feeds:
1019            SEED.rss                - everything gets written here
1020            SEEDgenomes.rss                 - whenever a genome is added to the SEED
1021            SEEDsubsystems.rss      - whenever a subsystem is edited (or should this be added?)
1022    
1023    
1024    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.
1025    
1026    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.
1027    
1028    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.
1029    
1030    The has can have these keys:
1031    
1032    REQUIRED:
1033    title       : the title. This is usually what is seen by the user in the pull down menu
1034    description : a more complete description that is often seen is rss viewers but not always
1035    link        : link to the item that was added/edited
1036    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.
1037    
1038    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.
1039    
1040    
1041    =cut
1042    
1043    sub rss_feed {
1044     shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1045     my ($files, $args)=@_;
1046     foreach my $a (keys %$args) {if ($a =~ /^-(.*)/) {my $b=$1; $args->{$b}=$args->{$a}; delete $args->{$a}}}
1047    
1048     my $filepath=$FIG_Config::fig."/CGI/Html/rss";
1049     # check for the directory and if not, make it
1050     mkdir $filepath unless (-d $filepath);
1051    
1052     # note that $info is a hash of references to hashes that are written out as headers in the file
1053     my $info=
1054     {
1055      "SEED.rss" =>
1056       {
1057            title           => "The SEED",
1058            description     => "Latest news from the SEED",
1059            link            => &FIG::cgi_url()."/Html/rss/SEED.rss",
1060       },
1061    
1062      "SEEDsubsystems.rss" =>
1063      {
1064            title           => "SEED Subsystems",
1065            description     => "Recently updated SEED subsystems",
1066            link            => &FIG::cgi_url()."/Html/rss/SEEDsubsystems.rss",
1067      },
1068    
1069      "SEEDsubsystems.rss" =>
1070      {
1071            title           => "SEED Genomes",
1072            description     => "Genomes recently added to the SEED",
1073            link            => &FIG::cgi_url()."/Html/rss/SEEDsubsystems.rss",
1074      },
1075    
1076     };
1077    
1078    
1079     # build the new xml
1080     my $xml = "\t<item>\n";
1081     foreach my $qw ("title", "description", "link") {
1082      unless ($args->{$qw}) {
1083       print STDERR "You need to include a $qw tag in your RSS description\n";
1084       return(0);
1085      }
1086      # we need to do something a bit funky with the link. We can't have ampersands in the <link> </link> in valid html
1087      # so we are going to pull out the links and uri_escape just the part after the .cgi
1088      if ($qw eq "link")
1089      {
1090       $args->{$qw} =~ /^(.*?\.cgi.)(.*)$/;
1091       print STDERR "Got ->>$1<<- and ->>$2<<-\n";
1092       $args->{$qw} = $1.uri_escape($2) if ($1 && $2);
1093      }
1094    
1095      $xml .= "\t\t<$qw>".$args->{$qw}."</$qw>\n";
1096      delete $args->{$qw};
1097     }
1098    
1099     foreach my $tag (grep {!/type/i} keys %$args)
1100     {
1101      $xml .= "\t\t<$tag>".$args->{$tag}."</$tag>\n";
1102     }
1103    
1104     $xml .= "\t</item>\n";
1105    
1106    
1107     my @files=("SEED.rss");
1108     if ($args->{"type"}) {push @files, "SEED.$type.rss"}
1109    
1110     foreach my $file ("SEED.rss", @$files)
1111     {
1112      if (-e "$filepath/$file")
1113      {
1114       my @out; # the new content of the file
1115       my $itemcount=0; # how many <item> </item>'s are we keeping
1116       my $initem; # are we in an item?
1117       open(IN, "$filepath/$file") || die "Can't open $filepath/$file";
1118       while (<IN>)
1119       {
1120        if (/\<item\>/) {
1121         push @out, $xml, unless ($itemcount);
1122         $itemcount++;
1123         $initem=1;
1124        }
1125        if (/\<\/item\>/) {$initem=0; next if ($itemcount > 9)}
1126        next if ($initem && $itemcount > 9);
1127        push @out, $_;
1128       }
1129       close IN;
1130       open(OUT, ">$filepath/$file") || die "Can't open $filepath/$file for writing";
1131       print OUT @out;
1132      }
1133      else
1134      {
1135       open(OUT, ">$filepath/$file") || die "Can't open $filepath/$file for writing";
1136       print OUT "<?xml version=\"1.0\"?>\n<rss version=\"2.0\">\n<channel>\n";
1137       if ($info->{$file})
1138       {
1139         # we're going to sanity check each of the three options we output, just to be sure
1140         foreach my $qw ("title", "description", "link")
1141         {
1142           if ($info->{$file}->{$qw})
1143           {
1144              print OUT "<$qw>", $info->{$file}->{$qw}, "</$qw>\n";
1145           } else {
1146              print STDERR "Please add a $qw for $file\n"; print OUT "<$qw>$file</$qw>\n";
1147           }
1148         }
1149       }
1150       else {
1151        print STDERR "Please define title, link, and description information for $file\n";
1152        print OUT "<title>$file</title>\n<description>An RSS feed</description>\n<link>", &FIG::cgi_url, "</link>\n";
1153       }
1154       print OUT "\n", $xml;
1155       print OUT "\n", "</channel>\n</rss>\n"
1156      }
1157     }
1158    }
1159    
1160    1;
1161    

Legend:
Removed from v.1.36  
changed lines
  Added in v.1.58

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3