[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.4, Fri Mar 19 20:26:58 2004 UTC revision 1.100, Sun Sep 24 15:22:58 2006 UTC
# Line 1  Line 1 
1    #
2    # Copyright (c) 2003-2006 University of Chicago and Fellowship
3    # for Interpretations of Genomes. All Rights Reserved.
4    #
5    # This file is part of the SEED Toolkit.
6    #
7    # The SEED Toolkit is free software. You can redistribute
8    # it and/or modify it under the terms of the SEED Toolkit
9    # Public License.
10    #
11    # You should have received a copy of the SEED Toolkit Public License
12    # along with this program; if not write to the University of Chicago
13    # at info@ci.uchicago.edu or the Fellowship for Interpretation of
14    # Genomes at veronika@thefig.info or download a copy from
15    # http://www.theseed.org/LICENSE.TXT.
16    #
17    
18  package HTML;  package HTML;
19    
20    use strict;
21    use Tracer;
22    use FIG;
23  use Carp;  use Carp;
24  use Data::Dumper;  use Data::Dumper;
25  use LWP::UserAgent;  use LWP::UserAgent;
26  use LWP::Simple;  use LWP::Simple;
27    use URI::Escape;  # uri_escape()
28  use URI::URL;  use URI::URL;
29  use HTTP::Request::Common;  use HTTP::Request::Common;
30    use POSIX;
31    
32  sub show_page {  #use raelib; # now used for the excel function, that should eventually end up in here. Way too experimental!
33      my($cgi,$html,$no_home) = @_;  my $raelib;
     my $i;  
34    
     #  
     # Find the HTML header  
     #  
35    
36      my $html_hdr_file = "./Html/html.hdr";  my $top_link_cache;
37      if (! -f $html_hdr_file)  
38    
39    sub new
40      {      {
41          $html_hdr_file = "$FIG_Config::fig/CGI/Html/html.hdr";      my($class) = @_;
42    
43        my $self = {};
44    
45        return bless $self, $class;
46      }      }
47    
48      my $html_tail_file = "./Html/html.tail";  sub top_link
     if (! -f $html_tail_file)  
49      {      {
         $html_tail_file = "$FIG_Config::fig/CGI/Html/html.tail";  
     }  
50    
51        #
52        # Determine if this is a toplevel cgi or one in one of the subdirs (currently
53        # just /p2p).
54        #
55    
56        return $top_link_cache if ($top_link_cache);
57    
58      print $cgi->header;      my @parts = split(/\//, $ENV{SCRIPT_NAME});
59      print "<base href=\"" . &FIG::cgi_url . "/\">\n";      my $top;
60      for ($i=0; ($i < @$html) && ($html->[$i] !~ /\<body\>/i); $i++) {}      if ($parts[-2] eq 'FIG')
     if ($i < @$html)  
61      {      {
62          splice(@$html,$i+1,0,`cat $html_hdr_file`);          $top = '.';
63    #       warn "toplevel @parts\n";
64      }      }
65      else      elsif ($parts[-3] eq 'FIG')
     {  
         for ($i=0; ($i < @$html) && ($html->[$i] !~ /\<html\>/i); $i++) {}  
         if ($i < @$html)  
66          {          {
67              splice(@$html,$i+1,0,`cat $html_hdr_file`);          $top = '..';
68    #       warn "subdir @parts\n";
69          }          }
70          else          else
71          {          {
72              splice(@$html,0,0,`cat $html_hdr_file`);          $top = $FIG_Config::cgi_base;
73    #       warn "other @parts\n";
74          }          }
75    
76        $top_link_cache = $top;
77        return $top;
78      }      }
79    
80      @tail = `cat $html_tail_file`;  sub compute_html_header
     if (! $no_home)  
81      {      {
82          my $user = $cgi->param('user');      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
83          $user = $user ? $user : "";      my($additional_insert, $user, %options ) = @_;
84          my $link = $cgi->url();  
85          $link =~ s/[a-zA-Z_]+\.cgi$/index.cgi/;      local $/ = "\n";
86          push(@tail,"<hr><a href=\"$link?user=$user\">FIG search</a>\n");  
87        my $header_name = $options{header_name} ? $options{header_name} : "html.hdr";
88        my $tail_name = $options{tail_name} ? $options{tail_name} : "html.tail";
89    
90        my $html_hdr_file = "./Html/$header_name";
91        if (! -f $html_hdr_file)
92        {
93            $html_hdr_file = "$FIG_Config::fig/CGI/Html/$header_name";
94      }      }
95        my @html_hdr = &FIG::file_read($html_hdr_file);
96    
97        # for my $k (sort keys %ENV) { warn "$k = $ENV{$k}\n"; }
98    
99      if (@tail > 0)      #
100        # Determine if this is a toplevel cgi or one in one of the subdirs (currently
101        # just /p2p).
102        #
103    
104        my @parts = split(/\//, $ENV{SCRIPT_NAME});
105        my $top;
106        if ($parts[-2] eq 'FIG')
107      {      {
108          for ($i=0; ($i < @$html) && ($html->[$i] !~ /\<\/body\>/i); $i++) {}          $top = '.';
109          if ($i < @$html)  #       warn "toplevel @parts\n";
110        }
111        elsif ($parts[-3] eq 'FIG')
112          {          {
113              splice(@$html,$i,0,@tail);          $top = '..';
114    #       warn "subdir @parts\n";
115          }          }
116          else          else
117          {          {
118              for ($i=0; ($i < @$html) && ($html->[$i] !~ /\<\/html\>/i); $i++) {}          $top = $FIG_Config::cgi_base;
119              if ($i < @$html)  #       warn "other @parts\n";
120        }
121    
122        $options{no_fig_search} or push( @html_hdr, "<br><a href=\"$top/index.cgi?user=$user\">FIG search</a>\n" );
123    
124        if (@html_hdr)
125        {
126            my $insert_stuff;
127    
128            if (not $options{no_release_info})
129            {
130                my @ver = &FIG::file_head("$FIG_Config::fig_disk/CURRENT_RELEASE", 1);
131                my $ver = $ver[0];
132                chomp $ver;
133                if ($ver =~ /^cvs\.(\d+)$/)
134              {              {
135                  splice(@$html,$i,0,@tail);                  my $d = asctime(localtime($1));
136                    chomp($d);
137                    $ver .=  " ($d)";
138              }              }
139              else              my $host = &FIG::get_local_hostname();
140                $insert_stuff = "SEED version <b>$ver</b> on $host";
141            }
142    
143            if ($additional_insert)
144            {
145                $insert_stuff .= "<br>" . $additional_insert;
146            }
147    
148            for $_ (@html_hdr)
149              {              {
150                  push(@$html,@tail);              s,(href|img\s+src)="/FIG/,$1="$top/,g;
151                    s,(\?user\=)\",$1$user",;
152                if ($_ eq "<!-- HEADER_INSERT -->\n")
153                {
154                    $_ = $insert_stuff;
155              }              }
156          }          }
157      }      }
158      print @$html;  
159        return @html_hdr;
160  }  }
161    
162  sub make_table {  sub show_page {
163      my($col_hdrs,$tab,$title,$instr) = @_;      #warn "SHOWPAGE: cgi=", Dumper(@_);
164      my(@tab);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
165        my($cgi,$html,$no_home, $alt_header, $css, $javasrc, $cookie, $options) = @_;
166        my $i;
167    
168      push(@tab,"<table border><caption><b>$title</b></caption>\n");      my $top = top_link();
     push(@tab,"<tr><th>" . join("</th><th>",@$col_hdrs) . "</th></tr>\n");  
     my($i,$nowrap);  
169    
170      for ($i=0; ($i < @$instr) && ($instr->[$i] !~ /nowrap/); $i++) {}      # ARGUMENTS:
171      $nowrap = ($i == @$instr) ? "" : " nowrap";      #     $cgi is the CGI method
172        #     $html is an array with all the html in it. It is just joined by "\n" (and not <br> or <p>
173        #     $no_home eliminates ONLY the bottom FIG search link in a page
174        #     $alt_header is a reference to an array for an alternate header banner that you can replace the standard one with
175        #     $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
176        #               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
177        #               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
178        #     $javasrc is a reference to an array of URLs to javascripts to be included (e.g. "FIG/Html/css/styleswitcher.js")
179        #     $cookie is the name and value of the cookie to set. Note that you should probably use raelib->cookie to get/set your cookies
180        #     $options is a reference to a hash of options that you can pass around the pages
181        #
182        # Find the HTML header
183        #
184    
185      my $row;      ### TRS ### "tail_name" has no value here.
186      foreach $row (@$tab)      my $html_tail_file = ""; # "./Html/$tail_name";
187    #    if (! -f $html_tail_file)
188    #    {
189    #        $html_tail_file = "$FIG_Config::fig/CGI/Html/$tail_name";
190    #    }
191    
192        my $user = $cgi->param('user') || "";
193        my @html_hdr;
194        if ($alt_header && ref($alt_header) eq "ARRAY")
195      {      {
196          push(@tab,"<tr>" . join("</td>",map { &expand($_,$nowrap) } @$row) . "</td></tr>\n");         @html_hdr = @$alt_header;
197      }      }
198      push(@tab,"</table>\n");      else
199      return join("",@tab);      {
200            @html_hdr = compute_html_header(undef,$user,%$options);
201  }  }
202    
203  sub expand {      # RAE: I am offloading the handling of cookies to CGI.pm since I don't know how they are set up.
204      my($x,$nowrap) = @_;      # This modification adds the cookies if necessary
205    
206        # Note: 3/10/05 commented this line out pending the discussion of adding cookies into the seed that we are waiting to see about
207        # to add cookies back in replace these two header lines with each other
208    
209        #print $cgi->header(-cookie=>$cookie);
210        print $cgi->header();
211    
212        #
213        #  The SEED header file goes immediately after <BODY>.  Figure out
214        #  what parts of the HTML document skeleton are there, and fill in
215        #  missing ones.
216        #
217        #  This list should be as comprehensive as feasible:
218        #
219    
220      if ($x =~ /^\@([^:]+)\:([^:]+)\:(.*)$/)      my %head_tag = ( base     => 1,
221                         basefont => 1,
222                         html     => 1,
223                         isindex  => 1,
224                         link     => 1,
225                         meta     => 1,
226                         nextid   => 1,
227                         style    => 1,
228                         title    => 1,
229                       );
230    
231        #
232        #  This list need not be comprehensive; it is just stopping conditions:
233        #
234    
235        my %body_tag = ( a      => 1,
236                         br     => 1,
237                         center => 1,
238                         form   => 1,
239                         h1     => 1,
240                         h2     => 1,
241                         h3     => 1,
242                         hr     => 1,
243                         img    => 1,
244                         p      => 1,
245                         pre    => 1,
246                         table  => 1
247                       );
248    
249        my $html_line = -1;
250        my $head_line = -1;
251        my $base_line = -1;
252        my $head_end_line = -1;
253        my $body_line = -1;
254        my $last_head_line = -1;  #  If no head tags are found, text goes at top.
255        my $done = 0;
256    
257        for ( $i = 0; $i < @$html; $i++ )
258      {      {
259          return "<td$nowrap $1=\"$2\">$3";          #  Some special cases:
260      }  
261      else          if ( $html->[$i] =~ /\<html[^0-9a-z]/i ) { $html_line = $i }
262            if ( $html->[$i] =~ /\<head[^0-9a-z]/i ) { $head_line = $i }
263            if ( $html->[$i] =~ /\<base[^0-9a-z]/i ) { $base_line = $i }
264            if ( $html->[$i] =~ /\<\/head\>/i )      { $head_end_line = $i }
265    
266            #  The content goes after this line:
267    
268            if ( $html->[$i] =~ /\<body[^0-9a-z]/i )
269      {      {
270          return "<td$nowrap>$x";              $body_line = $i;
271      }              last;
272  }  }
273    
274  sub ec_link {          #  Now the general case.
275      my($role) = @_;          #  Analyze all the html tags on the line:
276    
277      if ($role =~ /(\d+\.\d+\.\d+\.\d+)/)          foreach ( $html->[$i] =~ /\<\/?([0-9a-z]+)/ig )
278      {      {
279          return "<a href=\"http://www.genome.ad.jp/dbget-bin/www_bget?ec:$1\">$role</a>";              #  At first body tag, we stop the search and put the text
280      }              #  after the last line with a head tag:
281      else  
282                if ( $body_tag{ lc $_ } )
283      {      {
284          return $role;                  $done = 1;
285      }                  last;
286  }  }
287    
288  sub role_link {              #  If this is a head tag, then move the marker forward
     my($cgi,$role) = @_;  
289    
290      my $roleR = ($role =~ /^(\d+\.\d+\.\d+\.\d+)\s+-\s+/) ? $1 : $role;              elsif ( $head_tag{ lc $_ } )
291      my $user = $cgi->param('user');              {
292      if (! $user) { $user = "" }                  $last_head_line = $i;
293      my $link = $cgi->url() . "?role=$roleR&user=$user";              }
294      $link =~ s/[a-z]+\.cgi\?/pom.cgi?/;          }
295      return "<a href=$link>$role</a>";          last if $done;      # When done, break loop to avoid increment
296  }  }
297    
298  sub fid_link {      #  Some sanity checks on structure:
     my($cgi,$fid,$local,$just_url) = @_;  
     my($n);  
299    
300      if ($fid =~ /^fig\|\d+\.\d+\.([a-z]+)\.(\d+)/)      if ( 1 )
301      {      {
302          if ($local)          if ( $html_line >= 0 )
303          {          {
304              if ($1 eq "peg")              if ( ( $head_line >= 0 ) && ( $html_line > $head_line ) )
305              {              {
306                  $n = $2;                  print STDERR "<HTML> tag follows <HEAD> tag\n";
307              }              }
308              else              if ( ( $head_end_line >= 0 ) && ( $html_line > $head_end_line ) )
309              {              {
310                  $n = "$1.$2";                  print STDERR "<HTML> tag follows </HEAD> tag\n";
             }  
311          }          }
         else  
         {  
             $n = $fid;  
312          }          }
313          if ($1 ne "peg") { return $n }          if ( $head_line >= 0 )
         my $user = $cgi->param('user');  
         if (! $user) { $user = "" }  
         my $trans = $cgi->param('translate') ? "&translate=1" : "";  
         my $link = $cgi->url() . "?prot=$fid&user=$user$trans";  
         $link =~ s/[a-z_A-Z]+\.cgi\?/protein.cgi?/;  
         if ($just_url)  
314          {          {
315              return $link;              if ( ( $head_end_line >= 0 ) && ( $head_line > $head_end_line ) )
         }  
         else  
316          {          {
317              return "<a href=$link>$n</a>";                  print STDERR "<HEAD> tag follows </HEAD> tag\n";
318          }          }
319      }      }
     return $fid;  
320  }  }
321    
322  sub family_link {      #
323      my($family,$user) = @_;      #  Okay.  Let's put in the html header file, and missing tags:
324        #
325        #  <BODY> goes after last head line
326        #
327        #  RAE:
328        #  Added the javascript for the buttons immediately after body.
329        #  Note if no buttons are added we still (at the moment) add the script,
330        #  but it only adds a little text (495 characters) to the html and noone will notice!
331        #  RAE: This is now deprecated because everything is in an external file, FIG.js, included later
332    
333      return $family;      if ( $body_line < 0 )
334        {
335            $body_line = $last_head_line + 1;
336            splice( @$html, $body_line, 0, "<BODY>\n" );
337  }  }
338    
339  use URI::Escape;      #
340        #  Seed page header (if it exists) goes after <BODY>
341  sub get_html {      #
     my( $url, $type, $kv_pairs) = @_;  
     my( $encoded, $ua, $args, @args, $out, @output, $x );  
   
     $ua = new LWP::UserAgent;  
     $ua->timeout( 900 );  
342    
343      if ($type =~/post/i)      if (@html_hdr)
     {  
         $args = [];  
         foreach $x (@$kv_pairs)  
344          {          {
345              push(@$args, ( $x->[0], $x->[1]) );          splice( @$html, $body_line + 1, 0, @html_hdr );
         }  
         my $request  = POST $url, $args;  
         my $response = $ua->request($request);  
         $out = $response->content;  
346      }      }
347      else  
348      {      #
349          @args = ();      #  </HEAD> goes before <BODY>
350          foreach $x (@$kv_pairs)      #
351    
352        if ( $head_end_line < 0 )
353          {          {
354              push( @args, "$x->[0]=" . uri_escape($x->[1]) );          $head_end_line = $body_line;
355            splice( @$html, $body_line, 0, "</HEAD>\n" );
356          }          }
357    
358          if (@args > 0)      # RAE:
359        # Add css here
360        # Note that at the moment I define these two sheets here. I think this should
361        # be moved out, but I want to try it and see what happens.  css has the format:
362        #
363        # <link rel='stylesheet' title='default' href='/css/default.css' type='text/css'>
364    
365        # convert the default key to the right case. and eliminate dups
366        foreach my $k (keys %$css) {if (lc($k) eq "default") {$css->{'Default'}=$css->{$k}}}
367    
368        if (!$css || !$css->{'Default'})
369          {          {
370              $url .= "?" . join("&",@args);         $css->{'Default'} = "Html/css/default.css";
371          }          }
372          $request = new HTTP::Request('GET', $url);      if (!$css->{"Sans Serif"})
         my $response = $ua->request($request);  
   
         if ($response->is_success)  
373          {          {
374              $out = $response->content;         $css->{'Sans Serif'} = "Html/css/sanserif.css";
375          }          }
376          else  
377        my $csstext = "<link rel='stylesheet' title='default' href='".$css->{'Default'}."' type='text/css'>\n";
378        $csstext   .= "<link rel='alternate stylesheet' title='Sans Serif' href='".$css->{'Sans Serif'}."' type='text/css'>\n";
379    
380        foreach my $k (keys %$css)
381          {          {
382              $out = "<H1>Error: " . $response->code . "</H1>" . $response->message;         next if (lc($k) eq "default" || lc($k) eq "sans serif");
383           $csstext .= "<link rel='alternate stylesheet' title='$k' href='".$css->{$k}."' type='text/css'>\n";
384          }          }
385    
386        $csstext   .= "<link rel='alternate'  title='SEED RSS feeds' href='Html/rss/SEED.rss' type='application/rss+xml'>\n";
387    
388        # RAE: also added support for external javascripts here.
389        # we are cluttering the HTML code with all the javascripts when they could easily be in external files
390        # this solution allows us to source other files
391    
392        # the file FIG.js contains most of the java script we use routinely. Every browser will just cache this and so
393        # it will reduce our overhead.
394    
395        # $javasrc must be a ref to an array with urls (absolute or relative) to the javascripts
396        push @$javasrc, "Html/css/FIG.js";
397        foreach my $script (@$javasrc) {
398            $csstext .= "<script src=\"$script\" type=\"text/javascript\"></script>\n";
399      }      }
 #   set up a document with proper eol characters  
     @output = split(/[\012\015]+/,$out);  
     foreach $out (@output) { $out .= "\n"; }  
400    
 #   Now splice in a line of the form <base href=URL> to cause all relative links to work  
 #   properly.  Remove the header.  
401    
402      for ($i=0; ($i < @output) && ($output[$i] !~ /^\s*\</); $i++) {}  
403      if ($i < @output)      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.
404    
405        #
406        #  <BASE ...> goes before </HEAD>
407        #
408    
409        if ( $base_line < 0 )
410      {      {
411            #
412            #  Use a relative base address for pages.  Also, because I am
413            #  worried about when FIG_config.pm gets updated (clean installs
414            #  only, or every update?), I provide an alternative derivation
415            #  from $cgi_url. -- GJO
416            #
417            # BASE href needs to be absolute. RDO.
418            #
419            #
420    #        $base_url = &FIG::cgi_url;
421    #       my $base_url = $FIG_Config::cgi_base;
422    #       if ( ! $base_url )                      # if cgi_base was not defined
423    #       {
424    #           $base_url = $FIG_Config::cgi_url;   # get the full cgi url
425    #           $base_url =~ s~^http://[^/]*~~;     # remove protocol and host
426    #           $base_url =~ m~/$~ || $base_url =~ s~$~/~; # check trailing slash
427    #       }
428    
429          splice(@output,0,$i);          $base_line = $head_end_line;
430            #
431            # RDO 2005-1006. Remove this so proxying works better.
432            #
433    #        splice( @$html, $base_line, 0, "<BASE href=\"$base_url/\">\n" );
434      }      }
435    
436      for ($i=0; ($i < @output) && ($output[$i] !~ /\<body\>/i); $i++) {}      #
437      if ($i == @output)      #  <HTML> goes at the top of the output
438        #
439    
440        if ( $html_line < 0 )
441      {      {
442          $i = -1;          $html_line = 0;
443            splice( @$html, $html_line, 0, "<HTML>\n" );
444      }      }
     splice(@output,$i+1,0,"<base href=\"$url\">\n");  
     return @output;  
 }  
   
 sub trim_output {  
     my($out) = @_;  
     my $i;  
445    
446      for ($i=0; ($i < @$out) && ($out->[$i] !~ /^\</); $i++) {}      #
447      splice(@$out,0,$i);      #  <HEAD> goes after <HTML>
448        #
449    
450      for ($i=0; ($i < @$out) && ($out->[$i] !~ /\<body\>/i); $i++) {}      if ( $head_line < 0 )
     if ($i == @$out)  
     {  
         for ($i=0; ($i < @$out) && ($out->[$i] !~ /\<html\>/i); $i++) {}  
         if ($i == @$out)  
451          {          {
452              $i = -1;          $head_line = $html_line + 1;
453          }          splice( @$html, $head_line, 0, "<HEAD>\n" );
454      }      }
455      for ($j=$i+1; ($j < @$out) && ($out->[$j] !~ /^\<hr\>$/); $j++) {}  
456      if ($j < @$out)      #
457        #  Place FIG search link at bottom of page
458        #
459    
460        my @tail = -f $html_tail_file ? `cat $html_tail_file` : ();
461        if (! $no_home)
462      {      {
463          splice(@$out,$i+1,($j-$i));          my $user = $cgi->param('user') || "";
464            push( @tail, "<hr><a href=\"index.cgi?user=$user\">FIG search</a>\n" );
465      }      }
466    
467      for ($i=0; ($i < @$out) && ($out->[$i] !~ /\<\/body\>/i); $i++) {}      #
468      if ($i == @$out)      # See if we have a site-specific tail (for disclaimers, etc).
469        #
470    
471        my $site_tail = "$FIG_Config::fig_disk/config/site_tail.html";
472        my $site_fh;
473        if (open($site_fh, "<$site_tail"))
474      {      {
475          for ($i=0; ($i < @$out) && ($out->[$i] !~ /\<\/html\>/i); $i++) {}          push(@tail, <$site_fh>);
476            close($site_fh);
477      }      }
478    
479      for ($j=$i-1; ($j > 0) && ($out->[$j] !~ /FIG search/); $j--) {}      #
480      if ($j > 0)      #  Figure out where to insert The SEED tail.  Before </body>,
481        #  or before </html>, or at end of page.
482        #
483        my @tags = ();
484        # Check for a tracing queue.
485        my $traceString = QTrace("HTML");
486        if ($traceString) {
487            push @tags, $traceString;
488        }
489        for ($i=0; ($i < @$html) && ($html->[$i] !~ /\<\/body\>/i); $i++) {}
490        if ($i >= @$html)        # </body> not found; look for </html>
491        {
492            push @tags, "\n</BODY>\n";
493            # Even if tag is not found, index points to correct place for splice
494            for ($i=0; ($i < @$html) && ($html->[$i] !~ /\<\/html\>/i); $i++) {}
495            if ($i >= @$html)    # </html> not found; add it
496      {      {
497          my @tmp = `cat $html_tail_file`;              push @tags, "</HTML>\n";
         my $n = @tmp;  
         splice(@$out,$j-$n,$n+1);  
498      }      }
499  }  }
500    
501  sub set_prot_links {      if ( @tail )
     my($cgi,$x) = @_;  
     my($before,$match,$after);  
   
     if ($x =~ /^(.*)(fig\|\d+\.\d+\.peg\.\d+)(.*)$/)  
502      {      {
503          $before = $1;          splice( @$html, $i, 0, @tail, @tags );
         $match = $2;  
         $after = $3;  
         return &set_prot_links($cgi,$before) . &HTML::fid_link($cgi,$match) . &set_prot_links($cgi,$after) . "\n";  
504      }      }
505      elsif ($x =~ /^(.*)(gi\|\d+)(.*)$/)      elsif ( @tags )
506      {      {
507          $before = $1;          splice( @$html, $i, 0, @tags );
         $match = $2;  
         $after = $3;  
         return &set_prot_links($cgi,$before) . &HTML::gi_link($cgi,$match) . &set_prot_links($cgi,$after) . "\n";  
508      }      }
509      elsif ($x =~ /^(.*)(sp\|[A-Z0-9]{6})(.*)$/)  
510        # RAE the chomp will return any new lines at the ends of elements in the array,
511        # and then we can join  with a "\n". This is because somethings put newlines in,
512        # and others don't. This should make nicer looking html
513        #
514        # chomp(@$html);
515        # print join "\n", @$html;
516        #
517        # Apparently the above still breaks things. This is the correct code:
518    
519        foreach $_ (@$html)
520      {      {
521          $before = $1;          print $_;
522          $match = $2;      }
523    
524    }
525    
526    
527    =head1 make_table
528    
529    The main method to convert an array into a table.
530    
531    The col_hdrs are set to the <th> headers, the $tab is an array of arrays. The first is the rows, and the second is the columns. The title is the title of the table.
532    
533    The options define the settings for the table such as border, width, and class for css formatting. If the option "excelfile" is set to a filename that will be created in FIG_Config::temp, and the link included that allows the user to download the file as an excel file.
534    
535    =cut
536    
537    sub make_table {
538        my($col_hdrs,$tab,$title, %options ) = @_;
539        my(@tab);
540    
541        my $border = defined $options{border} ? "border=\"$options{border}\"" : "border";
542        my $width = defined $options{width} ? "width=\"$options{width}\"" : undef;
543        my $class = defined $options{class} ? "class=\"$options{class}\"" : undef;
544        push( @tab, "\n<table $border $width $class>\n",
545                    "\t<caption><b>$title</b></caption>\n",
546                    "\t<tr>\n\t\t"
547                  . join( "\n", map { &expand($_, "th") } @$col_hdrs )
548                  . "\n\t</tr>\n"
549            );
550        my($i);
551    
552        my $row;
553        foreach $row (@$tab)
554        {
555            push( @tab, "\t<tr>\n"
556                      . join( "\n", map { &expand($_) } @$row )
557                      . "\n\t</tr>\n"
558                );
559        }
560        push(@tab,"</table>\n");
561    
562        # excelfile should be appropriate for a filename (no spaces/special characters)
563        if (defined $options{"excelfile"}) {
564            if (! defined($raelib)) {
565                require raelib;
566                $raelib = new raelib;
567            }
568            push @tab, $raelib->tab2excel($col_hdrs,$tab,$title,\%options,$options{"excelfile"})}
569    
570        return join("",@tab);
571    }
572    
573    sub abstract_coupling_table {
574        my($cgi,$prot,$coupling) = @_;
575        my %fc;
576    
577        my $col_hdrs = ["coupled to","Score","Type of Coupling", "Type-specific Data"];
578        my $tab = [];
579        my %by_peg;
580        foreach my $x (@$coupling)
581        {
582            my($peg2,$psc,$type,$extra) = @$x;
583            if (($type !~ /^[ID]FC$/) || (! $fc{$peg2}))
584            {
585                if ($type =~  /^[ID]FC$/)
586                {
587                    $fc{$peg2} = 1;
588                }
589    
590                $by_peg{$peg2} += $psc;
591            }
592        }
593    
594        foreach my $x (sort { ($by_peg{$b->[0]} <=> $by_peg{$a->[0]})
595                              or ($a->[0] cmp $b->[0])
596                              or ($b->[1] <=> $a->[1])
597                              or ($a->[2] cmp $b->[2]) } @$coupling)
598        {
599            my($peg2,$psc,$type,$extra) = @$x;
600            push(@$tab,[&fid_link($cgi,$peg2,1),$psc,$type,&set_prot_links($cgi,join(", ",@$extra))]);
601        }
602    
603    
604         my $help = "<a href=\"Html/abstract_coupling.html\" target=\"SEED_or_SPROUT_help\">for help</a>";
605    #    my @html = &make_table($col_hdrs,$tab,"Abstract Coupling Data for $prot");
606    #    push(@html,"<hr>\n",$cgi->h3($help),"<br>");
607    #    return @html;
608    
609        return &make_table($col_hdrs,$tab,"Abstract Coupling Data for $prot [$help]");
610    }
611    
612    sub expand {
613        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
614        my( $x, $tag ) = @_;
615    
616        $tag = "td" unless $tag;
617        my $endtag = $tag;
618    
619        # RAE modified this so that you can pass in a reference to an array where
620        # the first element is the data to display and the second element is optional
621        # things like colspan and align. Note that in this case you need to include the td
622        # use something like ["some data to appear", "td colspan=4 bgcolor=gray"]
623    
624        # per GJO's request modified this line so it can take any tag.
625        if ( ref($x) eq "ARRAY" ) { ($x, $tag) = @$x; $tag =~ /^(\S+)/; $endtag = $1 }
626    
627        if ( $x =~ /^\@([^:]+)\:(.*)$/ )
628        {
629            return "\t\t<$tag $1>$2</$endtag>";
630        }
631        else
632        {
633            return "\t\t<$tag>$x</$endtag>";
634        }
635    }
636    
637    
638    =head2 merge_table_rows()
639    
640    Merge table rows together. This will merge a table so that adjacent cells with the same content will only be shown once.
641    
642    Something like this:
643    
644        -----------------------
645        |    1     |    a     |
646        -----------------------
647        |    1     |    b     |
648        -----------------------
649        |    2     |    c     |
650        -----------------------
651        |    3     |    d     |
652        -----------------------
653        |    4     |    d     |
654        -----------------------
655        |    5     |    d     |
656        -----------------------
657    
658    Will become:
659    
660        -----------------------
661        |          |    a     |
662        |    1     |-----------
663        |          |    b     |
664        -----------------------
665        |    2     |    c     |
666        -----------------------
667        |    3     |          |
668        ------------          |
669        |    4     |    5     |
670        ------------          |
671        |    5     |          |
672        -----------------------
673    
674    
675    The method takes two arguments. The reference to the array that is the table ($tab). This is the standard table that is created for HTML.pm to draw, and a reference to a hash of columns that you don't want to merge together. The reference to the hash is optional, and if not included, everything will be merged.
676    
677     $tab=&HTML::merge_table_rows($tab);
678    
679     or
680    
681     $skip=(1=>1, 3=>1, 5=>1);
682     $tab=&HTML::merge_table_rows($tab, $skip);  # will merge all columns except 1, 3 and 5. Note the first column in the table is #0
683    
684    
685    =cut
686    
687    
688    
689    
690    sub merge_table_rows {
691     # RAE:
692     # Experimental piece of code. We often want to have rows or columns were cells are merged. It just looks so much nicer
693     # this block should merge adjacent rows that have the same text in them.
694     # use like this:
695     #      $tab=&HTML::merge_table_rows($tab);
696     # before you do a make_table call
697    
698     my $self=shift if UNIVERSAL::isa($_[0],__PACKAGE__);
699     my ($tab, $skip)=@_;
700    
701     my $newtable;
702     my $lastrow;
703     my $rowspan;
704     my $refs;
705    
706     for (my $y=0; $y <= $#$tab; $y++) {
707     #$y is the row in the table;
708      for (my $x=0; $x <= $#{$tab->[$y]}; $x++) {
709       # this is the user definable columns not to merge
710       if ($skip->{$x})
711       {
712        $newtable->[$y]->[$x] = $tab->[$y]->[$x];
713        next;
714       }
715    
716       #$x is the column in the table
717       # if the column in the row we are looking at is the same as the column in the previous row, we don't add
718       # this cell to $newtable. Instead we increment the rowspan of the previous row by one
719    
720       # handle cells that are references to arrays
721       if (ref($tab->[$y]->[$x]) eq "ARRAY") {$refs->[$y]->[$x]=$tab->[$y]->[$x]->[1]; $tab->[$y]->[$x]=$tab->[$y]->[$x]->[0]}
722    
723       # now we go back through the table looking where to draw the merge line:
724       my $lasty=$y;
725       while ($lasty >= 0 && $tab->[$y]->[$x] eq $tab->[$lasty]->[$x]) {$lasty--}
726       $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
727       if ($lasty == $y) {
728        # we always want to have something in rows that may otherwise be empty but should be there (see below)
729        unless ($tab->[$y]->[$x]) {$tab->[$y]->[$x]=" &nbsp; "}
730        $newtable->[$y]->[$x] = $tab->[$y]->[$x];
731       }
732       else {$rowspan->[$lasty]->[$x]++}
733      }
734     }
735    
736     # now just join everything back together
737     for (my $y=0; $y <= $#$tab; $y++) {
738      for (my $x=0; $x <= $#{$tab->[$y]}; $x++) {
739       if ($rowspan->[$y]->[$x]) {
740        if ($refs->[$y]->[$x]) {$refs->[$y]->[$x] .= " rowspan=". ($rowspan->[$y]->[$x]+1)}
741        else {$refs->[$y]->[$x] = "td rowspan=". ($rowspan->[$y]->[$x]+1)}
742        $newtable->[$y]->[$x]=[$newtable->[$y]->[$x], $refs->[$y]->[$x]];
743       }
744       elsif ($newtable->[$y]->[$x] && $refs->[$y]->[$x]) {
745        $newtable->[$y]->[$x]=[$newtable->[$y]->[$x], $refs->[$y]->[$x]];
746       }
747      }
748     }
749    
750    
751     # finally we have to remove any completely empty cells that have been added by the array mechanism
752     # (e.g. if you define $a->[2] then $a->[0] and $a->[1] are now undef).
753     # that is why in the loop above I replace empty cells with nbsp. They are now not undef!
754     # I am sure that Gary can do this in one line, but I am hacking.
755     my @trimmed;
756     foreach my $a (@$newtable) {
757      my @row;
758      foreach my $b (@$a) {
759       push @row, $b if ($b);
760      }
761      push @trimmed, \@row;
762     }
763    
764     return \@trimmed;
765    }
766    
767    
768    
769    
770    sub set_ec_links {
771        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
772        my($cgi,$x) = @_;
773        my($before,$match,$after);
774    
775        if ($x =~ /^(.*)(EC \d+\.\d+\.\d+\.\d+)(.*)/s)
776        {
777            $before = $1;
778            $match = $2;
779            $after = $3;
780            return &set_ec_links($cgi,$before) . &HTML::ec_link($match) . &set_ec_links($cgi,$after);
781        }
782        return $x;
783    }
784    
785    sub ec_link {
786        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
787        my($role) = @_;
788    
789        if ($role =~ /(\d+\.\d+\.\d+\.\d+)/)
790        {
791            return "<a href=\"http://www.genome.ad.jp/dbget-bin/www_bget?ec:$1\">$role</a>";
792        }
793        else
794        {
795            return $role;
796        }
797    }
798    
799    sub role_link {
800        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
801        my($cgi,$role) = @_;
802    
803        my $roleR = ($role =~ /^(\d+\.\d+\.\d+\.\d+)\s+-\s+/) ? $1 : $role;
804        my $user = $cgi->param('user');
805        if (! $user) { $user = "" }
806        my $link = $cgi->url() . "?role=$roleR&user=$user";
807        $link =~ s/[a-z]+\.cgi\?/pom.cgi?/;
808        return "<a href=$link>$role</a>";
809    }
810    
811    #
812    # Local means to eliminate the fig|org.peg from the
813    # text of the link.
814    #
815    sub fid_link {
816        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
817        my($cgi,$fid,$local,$just_url) = @_;
818        my($n);
819    
820        my $top = top_link();
821    
822        if ($fid =~ /^fig\|\d+\.\d+\.([a-z]+)\.(\d+)/)
823        {
824            if ($local)
825            {
826                if ($1 eq "peg")
827                {
828                    $n = $2;
829                }
830                else
831                {
832                    $n = "$1.$2";
833                }
834            }
835            else
836            {
837                $n = $fid;
838            }
839    
840            my $link;
841            my $new_framework = $cgi->param('new_framework') ? 1 : 0;
842            #added to format prophage and path island links to feature.cgi
843            my $sprout = $cgi->param('SPROUT') ? "&SPROUT=1" : "";
844            if ($1 ne "peg" && ! $sprout)
845            {
846               my $user = $cgi->param('user');
847               if (! $user) { $user = "" }
848               $link = "$top/feature.cgi?feature=$fid&user=$user$sprout";
849               $link =~ s/[a-z_A-Z0-9]+\.cgi\?/feature.cgi?/;
850            }
851            else
852            {
853                my $user = $cgi->param('user');
854                if (! $user) { $user = "" }
855                my $trans = $cgi->param('translate') ? "&translate=1" : "";
856                my $sprout = $cgi->param('SPROUT') ? "&SPROUT=1" : "";
857    ###a
858    
859    ### This used to be
860    ###     my $link = &FIG::cgi_url . "/protein.cgi?prot=$fid&user=$user$trans$sprout";
861    ###
862    ### The cost became prohibitive in the subsystem spreadsheets.  Hence, we cache the value
863    ###
864    ### RAO
865    
866                #if (! $cgi_url) { $cgi_url = &FIG::cgi_url }
867                #$link = $cgi_url . "/protein.cgi?prot=$fid&user=$user$trans$sprout";
868                $link = "$top/protein.cgi?prot=$fid&user=$user$trans$sprout\&new_framework=$new_framework";
869                $link =~ s/[a-z_A-Z0-9]+\.cgi\?/protein.cgi?/;
870            }
871            if ($just_url)
872            {
873                return $link;
874            }
875            else
876            {
877                return "<a href='$link'>$n</a>";
878            }
879        }
880        return $fid;
881    }
882    
883    sub family_link {
884        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
885        my($family,$user) = @_;
886    
887        return $family;
888    }
889    
890    
891    sub get_html {
892        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
893        my( $url, $type, $kv_pairs) = @_;
894        my( $encoded, $ua, $args, @args, $out, @output, $x );
895    
896        $ua = new LWP::UserAgent;
897        $ua->timeout( 900 );
898        if ($type =~/post/i)
899        {
900            $args = [];
901            foreach $x (@$kv_pairs)
902            {
903                push(@$args, ( $x->[0], $x->[1]) );
904            }
905            my $request  = POST $url, $args;
906            my $response = $ua->request($request);
907            $out = $response->content;
908        }
909    
910        if ($type =~/get/i)
911        {
912            @args = ();
913            foreach $x (@$kv_pairs)
914            {
915                push( @args, "$x->[0]=" . uri_escape($x->[1]) );
916            }
917    
918            if (@args > 0)
919            {
920                $url .= "?" . join("&",@args);
921            }
922            my $request = new HTTP::Request('GET', $url);
923            my $response = $ua->request($request);
924    
925            if ($response->is_success)
926            {
927                $out = $response->content;
928            }
929            else
930            {
931                $out = "<H1>Error: " . $response->code . "</H1>" . $response->message;
932            }
933        }
934    #   set up a document with proper eol characters
935        @output = split(/[\012\015]+/,$out);
936        foreach $out (@output) { $out .= "\n"; }
937    
938    #   Now splice in a line of the form <base href=URL> to cause all relative links to work
939    #   properly.  Remove the header.
940        my $i;
941        for ($i=0; ($i < @output) && ($output[$i] !~ /^\s*\</); $i++) {}
942        if ($i < @output) {
943            splice(@output,0,$i);
944        }
945    
946        for ($i=0; ($i < @output) && ($output[$i] !~ /\<body\>/i); $i++) {}
947        if ($i == @output)
948        {
949            $i = -1;
950        }
951        splice(@output,$i+1,0,"<base href=\"$url\">\n");
952        return @output;
953    }
954    
955    sub trim_output {
956        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
957        my($out) = @_;
958        my ($i, $j);
959    
960        for ($i=0; ($i < @$out) && ($out->[$i] !~ /^\</); $i++) {}
961        splice(@$out,0,$i);
962    
963        for ($i=0; ($i < @$out) && ($out->[$i] !~ /\<body\>/i); $i++) {}
964        if ($i == @$out)
965        {
966            for ($i=0; ($i < @$out) && ($out->[$i] !~ /\<html\>/i); $i++) {}
967            if ($i == @$out)
968            {
969                $i = -1;
970            }
971        }
972        for ($j=$i+1; ($j < @$out) && ($out->[$j] !~ /^\<hr\>$/); $j++) {}
973        if ($j < @$out)
974        {
975            splice(@$out,$i+1,($j-$i));
976        }
977    
978        for ($i=0; ($i < @$out) && ($out->[$i] !~ /\<\/body\>/i); $i++) {}
979        if ($i == @$out)
980        {
981            for ($i=0; ($i < @$out) && ($out->[$i] !~ /\<\/html\>/i); $i++) {}
982        }
983    
984        for ($j=$i-1; ($j > 0) && ($out->[$j] !~ /FIG search/); $j--) {}
985        if ($j > 0)
986        {
987             ### TRS ###
988    #        my @tmp = `cat $html_tail_file`;
989    #        my $n = @tmp;
990    #        splice(@$out,$j-$n,$n+1);
991        }
992    }
993    
994    sub set_prot_links {
995        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
996        my($cgi,$x) = @_;
997        my($before,$match,$after);
998    
999        if ($x =~ /^(.*)(fig\|\d+\.\d+\.peg\.\d+)(.*)/s)
1000        {
1001            $before = $1;
1002            $match = $2;
1003            $after = $3;
1004            return &set_prot_links($cgi,$before) . &HTML::fid_link($cgi,$match) . &set_prot_links($cgi,$after);
1005        }
1006        elsif ($x =~ /^(.*)\b([NXYZA][PM]_[0-9\.]+)\b(.*)/s)
1007        {
1008            $before = $1;
1009            $match = $2;
1010            $after = $3;
1011            return &set_prot_links($cgi,$before) . &HTML::refseq_link($cgi,$match) . &set_prot_links($cgi,$after);
1012        }
1013        elsif ($x =~ /^(.*)(gi\|\d+)(.*)/s)
1014        {
1015            $before = $1;
1016            $match = $2;
1017            $after = $3;
1018            return &set_prot_links($cgi,$before) . &HTML::gi_link($cgi,$match) . &set_prot_links($cgi,$after);
1019        }
1020        elsif ($x =~ /^(.*)(tigr\|\w+)(.*)/s)
1021        {
1022            $before = $1;
1023            $match = $2;
1024            $after = $3;
1025            return &set_prot_links($cgi,$before) . &HTML::tigr_link($cgi,$match) . &set_prot_links($cgi,$after);
1026        }
1027        elsif ($x =~ /^(.*)\b(eric\|\S+)\b(.*)/s)
1028        {
1029            $before = $1;
1030            $match = $2;
1031            $after = $3;
1032            return &set_prot_links($cgi,$before) . &HTML::eric_link($cgi,$match) . &set_prot_links($cgi,$after);
1033        }
1034    
1035        elsif ($x =~ /^(.*)\b(bhb\|.*?)\b(.*)/s)
1036        {
1037            $before = $1;
1038            $match = $2;
1039            $after = $3;
1040            return &set_prot_links($cgi,$before) . &HTML::bhb_link($cgi,$match) . &set_prot_links($cgi,$after);
1041        }
1042    
1043        elsif ($x =~ /^(.*)\b(apidb\|[0-9\.a-z_]+)\b(.*)/s)
1044        {
1045            $before = $1;
1046            $match = $2;
1047            $after = $3;
1048            return &set_prot_links($cgi,$before) . &HTML::apidb_link($cgi,$match) . &set_prot_links($cgi,$after);
1049        }
1050    
1051        elsif ($x =~ /^(.*)\b(patric\|.*?)\b(.*)/s)
1052        {
1053            $before = $1;
1054            $match = $2;
1055            $after = $3;
1056            return &set_prot_links($cgi,$before) . &HTML::patric_link($cgi,$match) . &set_prot_links($cgi,$after);
1057        }
1058    
1059        elsif ($x =~ /^(.*)\b(vbrc\|.*?)\b(.*)/s)
1060        {
1061            $before = $1;
1062            $match = $2;
1063            $after = $3;
1064            return &set_prot_links($cgi,$before) . &HTML::vbrc_link($cgi,$match) . &set_prot_links($cgi,$after);
1065        }
1066    
1067        elsif ($x =~ /^(.*)\b(vectorbase\|.*?)\b(.*)/s)
1068        {
1069            $before = $1;
1070            $match = $2;
1071            $after = $3;
1072            return &set_prot_links($cgi,$before) . &HTML::vectorbase_link($cgi,$match) . &set_prot_links($cgi,$after);
1073        }
1074        elsif ($x =~  /^(.*)(uni\|[A-Z0-9]{6})(.*)/s)
1075        {
1076            $before = $1;
1077            $match = $2;
1078            $after = $3;
1079            return &set_prot_links($cgi,$before) . &HTML::uni_link($cgi,$match) . &set_prot_links($cgi,$after);
1080        }
1081        elsif ($x =~ /^(.*)(sp\|[A-Z0-9]{6})(.*)/s)
1082        {
1083            $before = $1;
1084            $match = $2;
1085            $after = $3;
1086            return &set_prot_links($cgi,$before) . &HTML::sp_link($cgi,$match) . &set_prot_links($cgi,$after);
1087        }
1088        elsif ($x =~ /^(.*)(pirnr\|NF\d+)(.*)/s)
1089        {
1090            $before = $1;
1091            $match = $2;
1092            $after = $3;
1093            return &set_prot_links($cgi,$before) . &HTML::pir_link($cgi,$match) . &set_prot_links($cgi,$after);
1094        }
1095        elsif ($x =~ /^(.*)(kegg\|[a-z]{2,4}:[a-zA-Z_0-9]+)(.*)/s)
1096        {
1097            $before = $1;
1098            $match = $2;
1099            $after = $3;
1100            return &set_prot_links($cgi,$before) . &HTML::kegg_link($cgi,$match) . &set_prot_links($cgi,$after);
1101        }
1102        elsif ($x =~ /^(.*)(Ensembl[a-zA-Z]+:[a-zA-Z_0-9\.]+)(.*)/s)
1103        {
1104            $before = $1;
1105            $match = $2;
1106            $after = $3;
1107            return &set_prot_links($cgi,$before) . &HTML::ensembl_link($cgi,$match) . &set_prot_links($cgi,$after);
1108        }
1109        elsif ($x =~ /^(.*)(EntrezGene:[a-zA-Z_0-9\.]+)(.*)/s)
1110        {
1111            $before = $1;
1112            $match = $2;
1113            $after = $3;
1114            return &set_prot_links($cgi,$before) . &HTML::entrezgene_link($cgi,$match) . &set_prot_links($cgi,$after);
1115        }
1116        elsif ($x =~ /^(.*)(MIM:[a-zA-Z_0-9\.]+)(.*)/s)
1117        {
1118            $before = $1;
1119            $match = $2;
1120            $after = $3;
1121            return &set_prot_links($cgi,$before) . &HTML::mim_link($cgi,$match) . &set_prot_links($cgi,$after);
1122        }
1123        elsif ($x =~ /^(.*)(HGNC:[a-zA-Z_0-9\.]+)(.*)/s)
1124        {
1125            $before = $1;
1126            $match = $2;
1127            $after = $3;
1128            return &set_prot_links($cgi,$before) . &HTML::hgnc_link($cgi,$match) . &set_prot_links($cgi,$after);
1129        }
1130        elsif ($x =~ /^(.*)(UniGene:[a-zA-Z_0-9\.]+)(.*)/s)
1131        {
1132            $before = $1;
1133            $match = $2;
1134            $after = $3;
1135            return &set_prot_links($cgi,$before) . &HTML::unigene_link($cgi,$match) . &set_prot_links($cgi,$after);
1136        }
1137    # IPI stopped working. turn off for now.
1138    #    elsif ($x =~ /^(.*)(IPI:[a-zA-Z_0-9\.]+)(.*)/s)
1139    #    {
1140    #        $before = $1;
1141    #        $match = $2;
1142    #        $after = $3;
1143    #        return &set_prot_links($cgi,$before) . &HTML::ipi_link($cgi,$match) . &set_prot_links($cgi,$after);
1144    #    }
1145        elsif ($x =~ /^(.*)(WP:[a-zA-Z_0-9\.]+)(.*)/s)
1146        {
1147            #wormbase
1148    
1149            $before = $1;
1150            $match = $2;
1151            $after = $3;
1152            return &set_prot_links($cgi,$before) . &HTML::wp_link($cgi,$match) . &set_prot_links($cgi,$after);
1153        }
1154        elsif ($x =~ /^(.*)(FB:[a-zA-Z_0-9\.]+)(.*)/s)
1155        {
1156            #flybase
1157    
1158            $before = $1;
1159            $match = $2;
1160            $after = $3;
1161            return &set_prot_links($cgi,$before) . &HTML::fb_link($cgi,$match) . &set_prot_links($cgi,$after);
1162        }
1163        elsif ($x =~ /^(.*)(FlyBaseORFNames:[a-zA-Z_0-9\.]+)(.*)/s)
1164        {
1165            #flybase
1166    
1167            $before = $1;
1168            $match = $2;
1169          $after = $3;          $after = $3;
1170          return &set_prot_links($cgi,$before) . &HTML::sp_link($cgi,$match) . &set_prot_links($cgi,$after) . "\n";          return &set_prot_links($cgi,$before) . &HTML::fborf_link($cgi,$match) . &set_prot_links($cgi,$after);
1171      }      }
1172      elsif ($x =~ /^(.*)(pirnr\|NF\d+)(.*)$/)      elsif ($x =~ /^(.*)(SGD_LOCUS:[a-zA-Z_0-9\.]+)(.*)/s)
1173      {      {
1174            #flybase
1175    
1176            $before = $1;
1177            $match = $2;
1178            $after = $3;
1179            return &set_prot_links($cgi,$before) . &HTML::sgd_link($cgi,$match) . &set_prot_links($cgi,$after);
1180        }
1181        elsif ($x =~ /^(.*)(tr\|[a-zA-Z0-9]+)(.*)/s)
1182        {
1183    
1184          $before = $1;          $before = $1;
1185          $match = $2;          $match = $2;
1186          $after = $3;          $after = $3;
1187          return &set_prot_links($cgi,$before) . &HTML::pir_link($cgi,$match) . &set_prot_links($cgi,$after) . "\n";  
1188          return &set_prot_links($cgi,$before) .  &HTML::trembl_link($cgi,$match) . &set_prot_links($cgi,$after);
1189      }      }
1190      return $x;      return $x;
1191  }  }
1192    
1193    sub trembl_link {
1194        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1195        my($cgi,$id) = @_;
1196    
1197        if ($id =~ /^tr\|(.*)/) {
1198          return "<a href='http://ca.expasy.org/uniprot/$1' target=_blank>$id</a>";
1199        } else {
1200          return "invalid call to trembl link";
1201        }
1202    }
1203    
1204    sub refseq_link {
1205        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1206        my($cgi,$id) = @_;
1207    
1208        if ($id =~ /^[NXYZA]P_/)
1209        {
1210            return "<a href='http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=protein&cmd=search&term=$id' target=_blank>$id</a>";
1211        }
1212        elsif ($id =~ /^[NXYZA]M_/)
1213        {
1214            return "<a href='http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=nuccore&cmd=search&term=$id' target=_blank>$id</a>";
1215        }
1216    }
1217    
1218  sub gi_link {  sub gi_link {
1219        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1220      my($cgi,$gi) = @_;      my($cgi,$gi) = @_;
1221    
1222      if ($gi =~ /^gi\|(\d+)$/)      if ($gi =~ /^gi\|(\d+)$/)
1223      {      {
1224          return "<a href=http://www.ncbi.nlm.nih.gov:80/entrez/query.fcgi?cmd=Retrieve&db=Protein&list_uids=$1&dopt=GenPept>$gi</a>";          return "<a href='http://www.ncbi.nlm.nih.gov:80/entrez/query.fcgi?cmd=Retrieve&db=Protein&list_uids=$1&dopt=GenPept' target=_blank>$gi</a>";
1225      }      }
1226      return $gi;      return $gi;
1227  }  }
1228    
1229    sub tigr_link {
1230        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1231        my($cgi,$tigr) = @_;
1232    
1233        if ($tigr =~ /^tigr\|(NT|ntbp|ntbpA|BA|BMAA|BXB|GBA)(\w+)$/)
1234        {
1235            my $id=$1.$2;
1236            return "<a href=\"http://pathema.tigr.org/tigr-scripts/pathema/shared/GenePage.cgi?locus=$id\" target=_blank>$tigr</a> (Pathema)";
1237        }
1238        elsif ($tigr =~ /^tigr\|(\S+)$/)
1239        {
1240            return "<a href=\"http://www.tigr.org/tigr-scripts/CMR2/GenePage.spl?locus=$1\" target=_blank>$tigr</a>";
1241        }
1242        return $tigr;
1243    }
1244    
1245    sub eric_link {
1246        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1247        my($cgi,$eric) = @_;
1248    
1249        if ($eric =~ /^eric\|(\S+)/)
1250        {
1251            return "<a href=\"https://asap.ahabs.wisc.edu/asap/feature_info.php?FeatureID=$1\" target=_blank>$eric</a>";
1252        }
1253        return $eric;
1254    }
1255    
1256    sub bhb_link {
1257        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1258        my($cgi,$bhb) = @_;
1259    
1260        return "<a href=\"http://www.biohealthbase.org\" target=_blank>$bhb</a>";
1261    }
1262    
1263    sub apidb_link {
1264        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1265        my($cgi,$api) = @_;
1266    
1267        if ($api =~ /apidb\|(.*?)\.(.*)$/)
1268        {
1269            return "<a href=\"http://www.apidb.org/cgi-bin/redirect.cgi?taxon_id=$1&source_id=$2\" target=_blank>$api</a>";
1270        }
1271        return $api;
1272    }
1273    
1274    sub patric_link {
1275        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1276        my($cgi,$patric) = @_;
1277    
1278        if ($patric =~ /patric\|(.*)/)
1279        {
1280            return "<a href=\"https://patric.vbi.vt.edu/software/curationTool/gep/pgiCuration.php?locus_name=$1\" target=_blank>$patric</a>";
1281        }
1282        return $patric;
1283    }
1284    
1285    sub vbrc_link {
1286        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1287        my($cgi,$vbrc) = @_;
1288    
1289        if ($vbrc =~ /vbrc\|(.*)/)
1290        {
1291            return "<a href=\"http://www.biovirus.org/gene_detail.asp?name=$1\" target=_blank>$vbrc</a>";
1292        }
1293        return $vbrc;
1294    }
1295    
1296    sub vectorbase_link {
1297        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1298        my($cgi,$vec) = @_;
1299        return "<a href=\"http://www.vectorbase.org\" target=_blank>$vec</a>";
1300    }
1301    
1302    
1303    sub uni_link {
1304        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1305        my($cgi,$uni) = @_;
1306    
1307        if ($uni =~ /^uni\|(\S+)$/)
1308        {
1309            #return "<a href=http://www.pir.uniprot.org/cgi-bin/upEntry?id=$1>$uni</a>";
1310            return "<a href='http://www.ebi.uniprot.org/uniprot-srv/uniProtView.do?proteinAc=$1' target=_blank>$uni</a>";
1311        }
1312        return $uni;
1313    }
1314    
1315  sub sp_link {  sub sp_link {
1316        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1317      my($cgi,$sp) = @_;      my($cgi,$sp) = @_;
1318    
1319      if ($sp =~ /^sp\|(\S+)$/)      if ($sp =~ /^sp\|(\S+)$/)
1320      {      {
1321          return "<a href=http://us.expasy.org/cgi-bin/get-sprot-entry?$1>$sp</a>";          return "<a href='http://us.expasy.org/cgi-bin/get-sprot-entry?$1' target=_blank>$sp</a>";
1322      }      }
1323      return $sp;      return $sp;
1324  }  }
1325    
1326  sub pir_link {  sub pir_link {
1327        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1328      my($cgi,$pir) = @_;      my($cgi,$pir) = @_;
1329    
1330      if ($pir =~ /^pirnr\|(NF\d+)$/)      if ($pir =~ /^pirnr\|(NF\d+)$/)
1331      {      {
1332          return "<a href=http://pir.georgetown.edu/cgi-bin/nfEntry.pl?id=$1>$pir</a>";          return "<a href='http://pir.georgetown.edu/cgi-bin/nfEntry.pl?id=$1' target=_blank>$pir</a>";
1333      }      }
1334      return $pir;      return $pir;
1335  }  }
1336    
1337    sub kegg_link {
1338        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1339        my($cgi,$kegg) = @_;
1340    
1341        if ($kegg =~ /^kegg\|([^:]+):(\S+)$/)
1342        {
1343            return "<a href='http://www.genome.ad.jp/dbget-bin/www_bget?$1+$2' target=_blank>$kegg</a>";
1344        }
1345        return $kegg;
1346    }
1347    
1348    sub ensembl_link {
1349        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1350        my($cgi,$ensembl) = @_;
1351    
1352        if ($ensembl =~ /^(\S+):(\S+)$/)
1353        {
1354            my $what=$1;
1355            my $key=$2;
1356            my $idx="All";
1357            if ($what eq "EnsemblGene") { $idx = "Gene" }
1358            if ($what eq "EnsemblTranscript") { $idx = "All" }
1359            if ($what eq "EnsemblProtein") { $idx = "All" }
1360    
1361            #I really want to get right to the transcript and peptide pages, but
1362            #can't see how to do that without knowing the org name too, which
1363            #I don't know at this point. (ensembl org name, not real org name)
1364    
1365            return "<a href='http://www.ensembl.org/Homo_sapiens/searchview?species=all&idx=$idx&q=$key' target=_blank>$ensembl</a>";
1366        }
1367        return $ensembl;
1368    }
1369    
1370    sub entrezgene_link {
1371        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1372        my($cgi,$entrezgene) = @_;
1373    
1374        if ($entrezgene =~ /^EntrezGene:(\S+)$/)
1375        {
1376            return "<a href='http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=gene&cmd=Retrieve&dopt=full_report&list_uids=$1' target=_blank>$entrezgene</a>";
1377        }
1378        return $entrezgene;
1379    }
1380    
1381    sub mim_link {
1382        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1383        my($cgi,$mim) = @_;
1384    
1385        if ($mim =~ /^MIM:(\S+)$/)
1386        {
1387            return "<a href='http://www3.ncbi.nlm.nih.gov/entrez/dispomim.cgi?id=$1' target=_blank>$mim</a>";
1388        }
1389        return $mim;
1390    }
1391    
1392    sub hgnc_link {
1393        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1394        my($cgi,$hgnc) = @_;
1395    
1396        if ($hgnc =~ /^HGNC:(\S+)$/)
1397        {
1398            return "<a href='http://www.gene.ucl.ac.uk/cgi-bin/nomenclature/searchgenes.pl?field=symbol&anchor=equals&match=$1&symbol_search=Search&number=50&format=html&sortby=symbol' target=_blank>$hgnc</a>";
1399        }
1400        ### TRS ###: was $mim, changed to $hgnc
1401        return $hgnc;
1402    }
1403    
1404    sub unigene_link {
1405        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1406        my($cgi,$unigene) = @_;
1407    
1408        if ($unigene =~ /^UniGene:(\S+)$/)
1409        {
1410            return "<a href='http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=unigene&cmd=search&term=$1' target=_blank>$unigene</a>";
1411        }
1412        return $unigene;
1413    }
1414    
1415    sub ipi_link {
1416        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1417        my($cgi,$ipi) = @_;
1418    
1419        if ($ipi =~ /^IPI:(\S+)$/)
1420        {
1421            return "<a href='http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-id+AEoS1R8Jnn+-e+[IPI:\'$1\']+-qnum+1+-enum+1' target=_blank>$ipi</a>";
1422        }
1423        return $ipi;
1424    }
1425    
1426    sub wp_link {
1427        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1428        my($cgi,$wp) = @_;
1429    
1430        #wormbase
1431    
1432        if ($wp =~ /^WP:(\S+)$/)
1433        {
1434            return "<a href='http://www.wormbase.org/db/searches/basic?class=Any&query=$1&Search=Search' target=_blank>$wp</a>";
1435        }
1436        return $wp;
1437    }
1438    
1439    sub fb_link {
1440        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1441        my($cgi,$fb) = @_;
1442    
1443        #flybase
1444    
1445        if ($fb =~ /^FB:(\S+)$/)
1446        {
1447            return "<a href='http://flybase.bio.indiana.edu/.bin/fbidq.html?$1' target=_blank>$fb</a>";
1448        }
1449        return $fb;
1450    }
1451    
1452    sub fborf_link {
1453        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1454        my($cgi,$fb) = @_;
1455    
1456        #flybase
1457    
1458        if ($fb =~ /^FlyBaseORFNames:(\S+)$/)
1459        {
1460            return "<a href='http://flybase.bio.indiana.edu/.bin/fbidq.html?$1' target=_blank>$fb</a>";
1461        }
1462        return $fb;
1463    }
1464    
1465    sub sgd_link {
1466        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1467        my($cgi,$sgd) = @_;
1468    
1469        #yeast
1470    
1471        if ($sgd =~ /^SGD_LOCUS:(\S+)$/)
1472        {
1473            return "<a href='http://db.yeastgenome.org/cgi-bin/locus.pl?locus=$1' target=_blank>$sgd</a>";
1474        }
1475        return $sgd;
1476    }
1477    
1478    
1479    
1480    
1481    sub set_map_links {
1482        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1483        my($cgi,$x) = @_;
1484        my($before,$match,$after);
1485    
1486        my $org = ($cgi->param('org') || $cgi->param('genome') || "");
1487    
1488        if ($x =~ /^(.*)(MAP\d+)(.*)/s)
1489        {
1490            $before = $1;
1491            $match = $2;
1492            $after = $3;
1493            return &set_map_links($cgi,$before) . &map_link($cgi,$match,$org) . &set_map_links($cgi,$after);
1494        }
1495        return $x;
1496    }
1497    
1498    
1499    
1500    sub map_link {
1501        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1502        my($cgi,$map,$org) = @_;
1503    
1504        my $user = $cgi->param('user');
1505        $user = $user ? $user : "";
1506        $org = $org ? $org : "";
1507    
1508        my $url = "show_kegg_map.cgi?user=$user&map=$map&org=$org";
1509    #rel    my $url = &FIG::cgi_url() . "/show_kegg_map.cgi?user=$user&map=$map&org=$org";
1510        my $link = "<a href=\"$url\">$map</a>";
1511        return $link;
1512    }
1513    
1514    sub java_buttons {
1515        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1516      ## ADDED BY RAE
1517      # Provides code to include check all/first half/second half/none for javascrspt
1518      # this takes two variables - the form name provided in start_form with the
1519      # -name => field and the checkbox name
1520      my ($form, $button)=@_;
1521    
1522      my $java_script="<input type=\"button\" name=\"CheckAll\" value=\"Check All\"\nonClick=\"checkAll(document.$form.$button)\">\n";
1523      $java_script.="<input type=\"button\" name=\"CheckFirst\" value=\"Check First Half\"\nonClick=\"checkFirst(document.$form.$button)\">\n";
1524      $java_script.="<input type=\"button\" name=\"CheckSecond\" value=\"Check Second Half\"\nonClick=\"checkSecond(document.$form.$button)\">\n";
1525      $java_script.="<input type=\"button\" name=\"UnCheckAll\" value=\"Uncheck All\"\nonClick=\"uncheckAll(document.$form.$button)\">\n";
1526    
1527      return $java_script;
1528    }
1529    
1530    sub sub_link {
1531        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1532        my($cgi,$sub) = @_;
1533        my($sub_link);
1534    
1535        my $user = $cgi->param('user');
1536        my $esc_sub = uri_escape( $sub );
1537        $sub =~ s/\_/ /g;
1538        if ($user)
1539        {
1540            $sub_link = "<a href=./subsys.cgi?ssa_name=$esc_sub&request=show_ssa&user=$user>$sub</a>";
1541        }
1542        else
1543        {
1544            $sub_link = "<a href=\"display_subsys.cgi?ssa_name=$esc_sub&request=show_ssa&sort=by_phylo\">$sub</a>";
1545        }
1546        return $sub_link;
1547    }
1548    
1549    sub reaction_link {
1550        my($reaction) = @_;
1551        if ($reaction =~ /^(\*)?(R\d+)/)
1552        {
1553            return "<a href=\"http://www.genome.ad.jp/dbget-bin/www_bget?rn+$2\" target=reaction$$>$reaction</a>";
1554        }
1555        return $reaction;
1556    }
1557    
1558    
1559    sub html_for_assignments {
1560        my($fig,$user,$peg_sets) = @_;
1561        my $i;
1562    
1563        my @vals = ();
1564        my $set = 1;
1565        foreach my $peg_set (@$peg_sets)
1566        {
1567            for ($i=0; ($i < @$peg_set); $i++)
1568            {
1569                my $peg = $peg_set->[$i];
1570                push(@vals,'show=' . join("@",($set,$i+1,$peg,&FIG::abbrev($fig->org_of($peg)),"")));
1571            }
1572            $set++;
1573        }
1574    
1575        $ENV{'REQUEST_METHOD'} = 'GET';
1576        $ENV{'QUERY_STRING'} = join('&',('request=show_commentary',"uni=1","user=$user",@vals));
1577        my $out = join("",`$FIG_Config::fig/CGI/chromosomal_clusters.cgi`);
1578        $out =~ s/^.*?<form/<form/si;
1579        $out =~ s/^(.*)<table.*/$1/si;
1580        return $out;
1581    }
1582    
1583    =head1 rss_feed
1584    
1585    Add something to the RSS feed. The rss feeds are stored in the Html directory, and there are several RSS feeds:
1586            SEED.rss                - everything gets written here
1587            SEEDgenomes.rss                 - whenever a genome is added to the SEED
1588            SEEDsubsystems.rss      - whenever a subsystem is edited (or should this be added?)
1589    
1590    
1591    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.
1592    
1593    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.
1594    
1595    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.
1596    
1597    The has can have these keys:
1598    
1599    REQUIRED:
1600    title       : the title. This is usually what is seen by the user in the pull down menu
1601    description : a more complete description that is often seen is rss viewers but not always
1602    link        : link to the item that was added/edited
1603    All other keys are treated as optional RSS arguments and written to the file.
1604    
1605    At most, $max_entries recent entries are stored in the rss file, and this is currently 50.
1606    
1607    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.
1608    
1609    
1610    =cut
1611    
1612    sub rss_feed {
1613     shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1614     my ($files, $args)=@_;
1615    
1616     # how many entries to store in the file
1617     my $max_entries=50;
1618    
1619     foreach my $a (keys %$args) {if ($a =~ /^-(.*)/) {my $b=$1; $args->{$b}=$args->{$a}; delete $args->{$a}}}
1620    
1621     my $filepath=$FIG_Config::fig."/CGI/Html/rss";
1622     # check for the directory and if not, make it
1623     mkdir $filepath unless (-d $filepath);
1624    
1625     # note that $info is a hash of references to hashes that are written out as headers in the file
1626     my $info=
1627     {
1628      "SEED.rss" =>
1629       {
1630            title           => "The SEED",
1631            description     => "Latest news from the SEED",
1632            link            => "Html/rss/SEED.rss",
1633       },
1634    
1635      "SEEDsubsystems.rss" =>
1636      {
1637            title           => "SEED Subsystems",
1638            description     => "Recently updated SEED subsystems",
1639            link            => "Html/rss/SEEDsubsystems.rss",
1640      },
1641    
1642      "SEEDsubsystems.rss" =>
1643      {
1644            title           => "SEED Genomes",
1645            description     => "Genomes recently added to the SEED",
1646            link            => &FIG::cgi_url()."/Html/rss/SEEDsubsystems.rss",
1647      },
1648    
1649     };
1650    
1651    
1652     # build the new xml
1653     my $xml = "\t<item>\n";
1654     foreach my $qw ("title", "description", "link") {
1655      unless ($args->{$qw}) {
1656       print STDERR "You need to include a $qw tag in your RSS description\n";
1657       return(0);
1658      }
1659      # we need to do something a bit funky with the link. We can't have ampersands in the <link> </link> in valid html
1660      # so we are going to pull out the links and uri_escape just the part after the .cgi
1661      if ($qw eq "link")
1662      {
1663       $args->{$qw} =~ /^(.*?\.cgi.)(.*)$/;
1664       $args->{$qw} = $1.uri_escape($2) if ($1 && $2);
1665      }
1666    
1667      $xml .= "\t\t<$qw>".$args->{$qw}."</$qw>\n";
1668      delete $args->{$qw};
1669     }
1670    
1671     foreach my $tag (grep {!/type/i} keys %$args)
1672     {
1673      $xml .= "\t\t<$tag>".$args->{$tag}."</$tag>\n";
1674     }
1675    
1676     $xml .= "\t</item>\n";
1677    
1678    
1679     my @files=("SEED.rss");
1680     if ($args->{"type"}) {
1681        ### TRS ### "$type" had no value here, so guessed what it should be.
1682        my $type = $args->{type};
1683        push @files, "SEED.$type.rss"
1684    }
1685    
1686     foreach my $file ("SEED.rss", @$files)
1687     {
1688      if (-e "$filepath/$file")
1689      {
1690       my @out; # the new content of the file
1691       my $itemcount=0; # how many <item> </item>'s are we keeping
1692       my $initem; # are we in an item?
1693       open(IN, "$filepath/$file") || die "Can't open $filepath/$file";
1694       while (<IN>)
1695       {
1696        if (/\<item\>/) {
1697         push @out, $xml, unless ($itemcount);
1698         $itemcount++;
1699         $initem=1;
1700        }
1701        if (/\<\/item\>/) {$initem=0; next if ($itemcount > $max_entries)}
1702        next if ($initem && $itemcount > $max_entries);
1703        push @out, $_;
1704       }
1705       close IN;
1706       open(OUT, ">$filepath/$file") || die "Can't open $filepath/$file for writing";
1707       print OUT @out;
1708      }
1709      else
1710      {
1711       open(OUT, ">$filepath/$file") || die "Can't open $filepath/$file for writing";
1712       print OUT "<?xml version=\"1.0\"?>\n<rss version=\"2.0\">\n<channel>\n";
1713       if ($info->{$file})
1714       {
1715         # we're going to sanity check each of the three options we output, just to be sure
1716         foreach my $qw ("title", "description", "link")
1717         {
1718           if ($info->{$file}->{$qw})
1719           {
1720              print OUT "<$qw>", $info->{$file}->{$qw}, "</$qw>\n";
1721           } else {
1722              print STDERR "Please add a $qw for $file\n"; print OUT "<$qw>$file</$qw>\n";
1723           }
1724         }
1725       }
1726       else {
1727        print STDERR "Please define title, link, and description information for $file\n";
1728        print OUT "<title>$file</title>\n<description>An RSS feed</description>\n<link>", &FIG::cgi_url, "</link>\n";
1729       }
1730       print OUT "\n", $xml;
1731       print OUT "\n", "</channel>\n</rss>\n"
1732      }
1733     }
1734    }
1735    
1736    
1737    
1738    1;
1739    
 1  

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.100

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3