[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.6, Sun Mar 21 02:20:55 2004 UTC revision 1.59, Fri Sep 16 15:18:26 2005 UTC
# Line 1  Line 1 
1  package HTML;  package HTML;
2    
3    use Tracer;
4    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;
13    
14    sub new
15    {
16        my($class) = @_;
17    
18        my $self = {};
19    
20        return bless $self, $class;
21    }
22    
23    sub compute_html_header
24    {
25        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
26        my($additional_insert, $user, %options ) = @_;
27    
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)
33        {
34            $html_hdr_file = "$FIG_Config::fig/CGI/Html/$header_name";
35        }
36        my @html_hdr = &FIG::file_read($html_hdr_file);
37    
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)
41        {
42            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);
47                my $ver = $ver[0];
48                chomp $ver;
49                if ($ver =~ /^cvs\.(\d+)$/)
50                {
51                    my $d = asctime(localtime($1));
52                    chomp($d);
53                    $ver .=  " ($d)";
54                }
55                my $host = &FIG::get_local_hostname();
56                $insert_stuff = "SEED version <b>$ver</b> on $host";
57            }
58    
59            if ($additional_insert)
60            {
61                $insert_stuff .= "<br>" . $additional_insert;
62            }
63    
64            for $_ (@html_hdr)
65            {
66                s,(href|img\s+src)="/FIG/,\1="$FIG_Config::cgi_base,g;
67                s,(\?user\=)\",$1$user",;
68                if ($_ eq "<!-- HEADER_INSERT -->\n")
69                {
70                    $_ = $insert_stuff;
71                }
72            }
73        }
74    
75        return @html_hdr;
76    }
77    
78  sub show_page {  sub show_page {
79      my($cgi,$html,$no_home) = @_;      #warn "SHOWPAGE: cgi=", Dumper(@_);
80        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
81        my($cgi,$html,$no_home, $alt_header, $css, $javasrc) = @_;
82      my $i;      my $i;
83    
84        # ARGUMENTS:
85        #     $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>
87        #     $no_home eliminates ONLY the bottom FIG search link in a page
88        #     $alt_header is a reference to an array for an alternate header banner that you can replace the standard one with
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
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
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
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_hdr_file = "./Html/html.hdr";      my $html_tail_file = "./Html/$tail_name";
98      if (! -f $html_hdr_file)      if (! -f $html_tail_file)
99      {      {
100          $html_hdr_file = "$FIG_Config::fig/CGI/Html/html.hdr";          $html_tail_file = "$FIG_Config::fig/CGI/Html/$tail_name";
101      }      }
102    
103      my $html_tail_file = "./Html/html.tail";      my $user = $cgi->param('user') || "";
104      if (! -f $html_tail_file)      my @html_hdr;
105        if ($alt_header && ref($alt_header) eq "ARRAY")
106      {      {
107          $html_tail_file = "$FIG_Config::fig/CGI/Html/html.tail";         @html_hdr = @$alt_header;
108        }
109        else
110        {
111            @html_hdr = compute_html_header(undef,$user);
112      }      }
113    
114    
# Line 145  Line 229 
229      #      #
230      #  <BODY> goes after last head line      #  <BODY> goes after last head line
231      #      #
232        #  RAE:
233        #  Added the javascript for the buttons immediately after body.
234        #  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!
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      {      {
# Line 156  Line 245 
245      #  Seed page header (if it exists) goes after <BODY>      #  Seed page header (if it exists) goes after <BODY>
246      #      #
247    
248      if ( -f $html_hdr_file )      if (@html_hdr)
249      {      {
250          splice( @$html, $body_line + 1, 0, `cat $html_hdr_file` );          splice( @$html, $body_line + 1, 0, @html_hdr );
251      }      }
252    
253      #      #
# Line 171  Line 260 
260          splice( @$html, $body_line, 0, "</HEAD>\n" );          splice( @$html, $body_line, 0, "</HEAD>\n" );
261      }      }
262    
263        # RAE:
264        # Add css here
265        # Note that at the moment I define these two sheets here. I think this should
266        # 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'>
269    
270        # convert the default key to the right case. and eliminate dups
271        foreach my $k (keys %$css) {if (lc($k) eq "default") {$css->{'Default'}=$css->{$k}}}
272    
273        if (!$css || !$css->{'Default'})
274        {
275           $css->{'Default'} = &FIG::cgi_url() . "/Html/css/default.css";
276        }
277        if (!$css->{"Sans Serif"})
278        {
279           $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";
283        $csstext   .= "<link rel='alternate stylesheet' title='Sans Serif' href='".$css->{'Sans Serif'}."' type='text/css'>\n";
284    
285        foreach my $k (keys %$css)
286        {
287           next if (lc($k) eq "default" || lc($k) eq "sans serif");
288           $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.
309    
310      #      #
311      #  <BASE ...> goes before </HEAD>      #  <BASE ...> goes before </HEAD>
312      #      #
# Line 183  Line 319 
319          #  only, or every update?), I provide an alternative derivation          #  only, or every update?), I provide an alternative derivation
320          #  from $cgi_url. -- GJO          #  from $cgi_url. -- GJO
321          #          #
322            # BASE href needs to be absolute. RDO.
323          my $base_url = $FIG_Config::cgi_base;          #
324          if ( ! $base_url )                      # if cgi_base was not defined          #
325          {          $base_url = &FIG::cgi_url;
326              $base_url = $FIG_Config::cgi_url;   # get the full cgi url  #       my $base_url = $FIG_Config::cgi_base;
327              $base_url =~ s~^http://[^/]*~~;     # remove protocol and host  #       if ( ! $base_url )                      # if cgi_base was not defined
328              $base_url =~ m~/$~ || $base_url =~ s~$~/~; # check trailing slash  #       {
329          }  #           $base_url = $FIG_Config::cgi_url;   # get the full cgi url
330    #           $base_url =~ s~^http://[^/]*~~;     # remove protocol and host
331    #           $base_url =~ m~/$~ || $base_url =~ s~$~/~; # check trailing slash
332    #       }
333    
334          $base_line = $head_end_line;          $base_line = $head_end_line;
335          splice( @$html, $base_line, 0, "<BASE href=\"$base_url\">\n" );          splice( @$html, $base_line, 0, "<BASE href=\"$base_url/\">\n" );
336      }      }
337    
338      #      #
# Line 228  Line 367 
367      }      }
368    
369      #      #
370        # See if we have a site-specific tail (for disclaimers, etc).
371        #
372    
373        my $site_tail = "$FIG_Config::fig_disk/config/site_tail.html";
374        my $site_fh;
375        if (open($site_fh, "<$site_tail"))
376        {
377            push(@tail, <$site_fh>);
378            close($site_fh);
379        }
380    
381        #
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 255  Line 409 
409          splice( @$html, $i, 0, @tags );          splice( @$html, $i, 0, @tags );
410      }      }
411    
412      print @$html;      # RAE the chomp will return any new lines at the ends of elements in the array,
413        # and then we can join  with a "\n". This is because somethings put newlines in,
414        # and others don't. This should make nicer looking html
415        #
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 {
429      my($col_hdrs,$tab,$title,$instr) = @_;      my($col_hdrs,$tab,$title, %options ) = @_;
430      my(@tab);      my(@tab);
431    
432      push( @tab, "\n<table border>\n",      my $border = defined $options{border} ? "border=\"$options{border}\"" : "border";
433        push( @tab, "\n<table $border>\n",
434                  "\t<caption><b>$title</b></caption>\n",                  "\t<caption><b>$title</b></caption>\n",
435                  "\t<tr>\n\t\t<th>"                  "\t<tr>\n\t\t"
436                . join( "</th>\n\t\t<th>", @$col_hdrs )                . join( "\n", map { &expand($_, "th") } @$col_hdrs )
437                . "</th>\n\t</tr>\n"                . "\n\t</tr>\n"
438          );          );
439      my($i,$nowrap);      my($i);
   
     for ($i=0; ($i < @$instr) && ($instr->[$i] !~ /nowrap/); $i++) {}  
     $nowrap = ($i == @$instr) ? "" : " nowrap";  
440    
441      my $row;      my $row;
442      foreach $row (@$tab)      foreach $row (@$tab)
443      {      {
444          push( @tab, "\t<tr>\n"          push( @tab, "\t<tr>\n"
445                    . join( "\n", map { &expand($_,$nowrap) } @$row )                    . join( "\n", map { &expand($_) } @$row )
446                    . "\n\t</tr>\n"                    . "\n\t</tr>\n"
447              );              );
448      }      }
# Line 286  Line 451 
451  }  }
452    
453  sub expand {  sub expand {
454      my($x,$nowrap) = @_;      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
455        my( $x, $tag ) = @_;
456    
457      if ($x =~ /^\@([^:]+)\:([^:]+)\:(.*)$/)      $tag = "td" unless $tag;
458        my $endtag = $tag;
459    
460        # 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"]
464    
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 =~ /^\@([^:]+)\:(.*)$/ )
469      {      {
470          return "\t\t<td$nowrap $1=\"$2\">$3</td>";          return "\t\t<$tag $1>$2</$endtag>";
471      }      }
472      else      else
473      {      {
474          return "\t\t<td$nowrap>$x</td>";          return "\t\t<$tag>$x</$endtag>";
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 {
553        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
554        my($cgi,$x) = @_;
555        my($before,$match,$after);
556    
557        if ($x =~ /^(.*)(EC \d+\.\d+\.\d+\.\d+)(.*)/s)
558        {
559            $before = $1;
560            $match = $2;
561            $after = $3;
562            return &set_ec_links($cgi,$before) . &HTML::ec_link($match) . &set_ec_links($cgi,$after);
563        }
564        return $x;
565    }
566    
567  sub ec_link {  sub ec_link {
568        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
569      my($role) = @_;      my($role) = @_;
570    
571      if ($role =~ /(\d+\.\d+\.\d+\.\d+)/)      if ($role =~ /(\d+\.\d+\.\d+\.\d+)/)
# Line 312  Line 579 
579  }  }
580    
581  sub role_link {  sub role_link {
582        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
583      my($cgi,$role) = @_;      my($cgi,$role) = @_;
584    
585      my $roleR = ($role =~ /^(\d+\.\d+\.\d+\.\d+)\s+-\s+/) ? $1 : $role;      my $roleR = ($role =~ /^(\d+\.\d+\.\d+\.\d+)\s+-\s+/) ? $1 : $role;
# Line 322  Line 590 
590      return "<a href=$link>$role</a>";      return "<a href=$link>$role</a>";
591  }  }
592    
593    #
594    # Local means to eliminate the fig|org.peg from the
595    # text of the link.
596    #
597  sub fid_link {  sub fid_link {
598        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
599      my($cgi,$fid,$local,$just_url) = @_;      my($cgi,$fid,$local,$just_url) = @_;
600      my($n);      my($n);
601    
# Line 343  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 $link = $cgi->url() . "?prot=$fid&user=$user$trans";              my $sprout = $cgi->param('SPROUT') ? "&SPROUT=1" : "";
637          $link =~ s/[a-z_A-Z]+\.cgi\?/protein.cgi?/;  ###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?/;
649                #
650                # Elimin the p2p part if we're in that subdir. Ugh.
651                #
652                $link =~ s,p2p/protein.cgi,protein.cgi,;
653    
654    
655          if ($just_url)          if ($just_url)
656          {          {
657              return $link;              return $link;
# Line 358  Line 661 
661              return "<a href=$link>$n</a>";              return "<a href=$link>$n</a>";
662          }          }
663      }      }
664        }
665      return $fid;      return $fid;
666  }  }
667    
668  sub family_link {  sub family_link {
669        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
670      my($family,$user) = @_;      my($family,$user) = @_;
671    
672      return $family;      return $family;
673  }  }
674    
 use URI::Escape;  
675    
676  sub get_html {  sub get_html {
677        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
678      my( $url, $type, $kv_pairs) = @_;      my( $url, $type, $kv_pairs) = @_;
679      my( $encoded, $ua, $args, @args, $out, @output, $x );      my( $encoded, $ua, $args, @args, $out, @output, $x );
680    
681      $ua = new LWP::UserAgent;      $ua = new LWP::UserAgent;
682      $ua->timeout( 900 );      $ua->timeout( 900 );
   
683      if ($type =~/post/i)      if ($type =~/post/i)
684      {      {
685          $args = [];          $args = [];
# Line 435  Line 739 
739  }  }
740    
741  sub trim_output {  sub trim_output {
742        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
743      my($out) = @_;      my($out) = @_;
744      my $i;      my $i;
745    
# Line 472  Line 777 
777  }  }
778    
779  sub set_prot_links {  sub set_prot_links {
780        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
781      my($cgi,$x) = @_;      my($cgi,$x) = @_;
782      my($before,$match,$after);      my($before,$match,$after);
783    
784      if ($x =~ /^(.*)(fig\|\d+\.\d+\.peg\.\d+)(.*)$/)      if ($x =~ /^(.*)(fig\|\d+\.\d+\.peg\.\d+)(.*)/s)
785        {
786            $before = $1;
787            $match = $2;
788            $after = $3;
789            return &set_prot_links($cgi,$before) . &HTML::fid_link($cgi,$match) . &set_prot_links($cgi,$after);
790        }
791        elsif ($x =~ /^(.*)\b([NXYZA]P_[0-9\.]+)\b(.*)/s)
792        {
793            $before = $1;
794            $match = $2;
795            $after = $3;
796            return &set_prot_links($cgi,$before) . &HTML::refseq_link($cgi,$match) . &set_prot_links($cgi,$after);
797        }
798        elsif ($x =~ /^(.*)(gi\|\d+)(.*)/s)
799        {
800            $before = $1;
801            $match = $2;
802            $after = $3;
803            return &set_prot_links($cgi,$before) . &HTML::gi_link($cgi,$match) . &set_prot_links($cgi,$after);
804        }
805        elsif ($x =~ /^(.*)(tigr\|[0-9a-zA-Z]+)(.*)/s)
806      {      {
807          $before = $1;          $before = $1;
808          $match = $2;          $match = $2;
809          $after = $3;          $after = $3;
810          return &set_prot_links($cgi,$before) . &HTML::fid_link($cgi,$match) . &set_prot_links($cgi,$after) . "\n";          return &set_prot_links($cgi,$before) . &HTML::tigr_link($cgi,$match) . &set_prot_links($cgi,$after);
811      }      }
812      elsif ($x =~ /^(.*)(gi\|\d+)(.*)$/)      elsif ($x =~  /^(.*)(uni\|[A-Z0-9]{6})(.*)/s)
813      {      {
814          $before = $1;          $before = $1;
815          $match = $2;          $match = $2;
816          $after = $3;          $after = $3;
817          return &set_prot_links($cgi,$before) . &HTML::gi_link($cgi,$match) . &set_prot_links($cgi,$after) . "\n";          return &set_prot_links($cgi,$before) . &HTML::uni_link($cgi,$match) . &set_prot_links($cgi,$after);
818      }      }
819      elsif ($x =~ /^(.*)(sp\|[A-Z0-9]{6})(.*)$/)      elsif ($x =~ /^(.*)(sp\|[A-Z0-9]{6})(.*)/s)
820      {      {
821          $before = $1;          $before = $1;
822          $match = $2;          $match = $2;
823          $after = $3;          $after = $3;
824          return &set_prot_links($cgi,$before) . &HTML::sp_link($cgi,$match) . &set_prot_links($cgi,$after) . "\n";          return &set_prot_links($cgi,$before) . &HTML::sp_link($cgi,$match) . &set_prot_links($cgi,$after);
825      }      }
826      elsif ($x =~ /^(.*)(pirnr\|NF\d+)(.*)$/)      elsif ($x =~ /^(.*)(pirnr\|NF\d+)(.*)/s)
827      {      {
828          $before = $1;          $before = $1;
829          $match = $2;          $match = $2;
830          $after = $3;          $after = $3;
831          return &set_prot_links($cgi,$before) . &HTML::pir_link($cgi,$match) . &set_prot_links($cgi,$after) . "\n";          return &set_prot_links($cgi,$before) . &HTML::pir_link($cgi,$match) . &set_prot_links($cgi,$after);
832        }
833        elsif ($x =~ /^(.*)(kegg\|[a-z]{2,4}:[a-zA-Z_0-9]+)(.*)/s)
834        {
835            $before = $1;
836            $match = $2;
837            $after = $3;
838            return &set_prot_links($cgi,$before) . &HTML::kegg_link($cgi,$match) . &set_prot_links($cgi,$after);
839      }      }
840      return $x;      return $x;
841  }  }
842    
843    sub refseq_link {
844        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
845        my($cgi,$id) = @_;
846    
847        if ($id =~ /^[NXYZA]P_/)
848        {
849            return "<a href=http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=protein&cmd=search&term=$id>$id</a>";
850        }
851    }
852    
853  sub gi_link {  sub gi_link {
854        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
855      my($cgi,$gi) = @_;      my($cgi,$gi) = @_;
856    
857      if ($gi =~ /^gi\|(\d+)$/)      if ($gi =~ /^gi\|(\d+)$/)
# Line 516  Line 861 
861      return $gi;      return $gi;
862  }  }
863    
864    sub tigr_link {
865        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
866        my($cgi,$tigr) = @_;
867    
868        if ($tigr =~ /^tigr\|([0-9a-zA-Z]+)$/)
869        {
870            return "<a href=\"http://pathema.tigr.org/tigr-scripts/CMR/GenePage.cgi?locus=$1\">$tigr</a>";
871        }
872        return $tigr;
873    }
874    
875    sub uni_link {
876        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
877        my($cgi,$uni) = @_;
878    
879        if ($uni =~ /^uni\|(\S+)$/)
880        {
881            return "<a href=http://www.pir.uniprot.org/cgi-bin/upEntry?id=$1>$uni</a>";
882        }
883        return $uni;
884    }
885    
886  sub sp_link {  sub sp_link {
887        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
888      my($cgi,$sp) = @_;      my($cgi,$sp) = @_;
889    
890      if ($sp =~ /^sp\|(\S+)$/)      if ($sp =~ /^sp\|(\S+)$/)
# Line 527  Line 895 
895  }  }
896    
897  sub pir_link {  sub pir_link {
898        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
899      my($cgi,$pir) = @_;      my($cgi,$pir) = @_;
900    
901      if ($pir =~ /^pirnr\|(NF\d+)$/)      if ($pir =~ /^pirnr\|(NF\d+)$/)
# Line 536  Line 905 
905      return $pir;      return $pir;
906  }  }
907    
908    sub kegg_link {
909        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
910        my($cgi,$kegg) = @_;
911    
912        if ($kegg =~ /^kegg\|([^:]+):(\S+)$/)
913        {
914            return "<a href=http://www.genome.ad.jp/dbget-bin/www_bget?$1+$2>$kegg</a>";
915        }
916        return $kegg;
917    }
918    
919    sub set_map_links {
920        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
921        my($cgi,$x) = @_;
922        my($before,$match,$after);
923    
924        my $org = ($cgi->param('org') || $cgi->param('genome') || "");
925    
926        if ($x =~ /^(.*)(MAP\d+)(.*)/s)
927        {
928            $before = $1;
929            $match = $2;
930            $after = $3;
931            return &set_map_links($cgi,$before) . &map_link($cgi,$match,$org) . &set_map_links($cgi,$after);
932        }
933        return $x;
934    }
935    
936    sub map_link {
937        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
938        my($cgi,$map,$org) = @_;
939    
940        $user = $cgi->param('user');
941        $user = $user ? $user : "";
942        $org = $org ? $org : "";
943    
944        my $url = &FIG::cgi_url() . "/show_kegg_map.cgi?user=$user&map=$map&org=$org";
945        my $link = "<a href=\"$url\">$map</a>";
946        return $link;
947    }
948    
949    sub java_buttons {
950        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
951      ## ADDED BY RAE
952      # Provides code to include check all/first half/second half/none for javascrspt
953      # this takes two variables - the form name provided in start_form with the
954      # -name => field and the checkbox name
955      my ($form, $button)=@_;
956    
957      $java_script="<input type=\"button\" name=\"CheckAll\" value=\"Check All\"\nonClick=\"checkAll(document.$form.$button)\">\n";
958      $java_script.="<input type=\"button\" name=\"CheckFirst\" value=\"Check First Half\"\nonClick=\"checkFirst(document.$form.$button)\">\n";
959      $java_script.="<input type=\"button\" name=\"CheckSecond\" value=\"Check Second Half\"\nonClick=\"checkSecond(document.$form.$button)\">\n";
960      $java_script.="<input type=\"button\" name=\"UnCheckAll\" value=\"Uncheck All\"\nonClick=\"uncheckAll(document.$form.$button)\">\n";
961    
962      return $java_script;
963    }
964    
965    sub sub_link {
966        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
967        my($cgi,$sub) = @_;
968        my($sub_link);
969    
970        my $user = $cgi->param('user');
971        if ($user)
972        {
973            my $esc_sub = uri_escape( $sub );
974            $sub_link = "<a href=./subsys.cgi?ssa_name=$esc_sub&request=show_ssa&user=$user>$sub</a>";
975        }
976        else
977        {
978            $sub_link = $sub;
979        }
980        return $sub_link;
981    }
982    
983    sub reaction_link {
984        my($reaction) = @_;
985    
986        if ($reaction =~ /^R\d+/)
987        {
988            return "<a href=\"http://www.genome.ad.jp/dbget-bin/www_bget?rn+$reaction\" target=reaction$$>$reaction</a>";
989        }
990        return $reaction;
991    }
992    
993    sub html_for_assignments {
994        my($fig,$user,$peg_sets) = @_;
995        my $i;
996    
997        my @vals = ();
998        my $set = 1;
999        foreach $peg_set (@$peg_sets)
1000        {
1001            for ($i=0; ($i < @$peg_set); $i++)
1002            {
1003                $peg = $peg_set->[$i];
1004                push(@vals,'show=' . join("@",($set,$i+1,$peg,&FIG::abbrev($fig->org_of($peg)),"")));
1005            }
1006            $set++;
1007        }
1008    
1009        $ENV{'REQUEST_METHOD'} = 'GET';
1010        $ENV{'QUERY_STRING'} = join('&',('request=show_commentary',"uni=1","user=$user",@vals));
1011        my $out = join("",`$FIG_Config::fig/CGI/chromosomal_clusters.cgi`);
1012        $out =~ s/^.*?<form/<form/si;
1013        $out =~ s/^(.*)<table.*/$1/si;
1014        return $out;
1015    }
1016    
1017    =head1 rss_feed
1018    
1019    Add something to the RSS feed. The rss feeds are stored in the Html directory, and there are several RSS feeds:
1020            SEED.rss                - everything gets written here
1021            SEEDgenomes.rss                 - whenever a genome is added to the SEED
1022            SEEDsubsystems.rss      - whenever a subsystem is edited (or should this be added?)
1023    
1024    
1025    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.
1026    
1027    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.
1028    
1029    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.
1030    
1031    The has can have these keys:
1032    
1033    REQUIRED:
1034    title       : the title. This is usually what is seen by the user in the pull down menu
1035    description : a more complete description that is often seen is rss viewers but not always
1036    link        : link to the item that was added/edited
1037    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.
1038    
1039    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.
1040    
1041    
1042    =cut
1043    
1044    sub rss_feed {
1045     shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1046     my ($files, $args)=@_;
1047     foreach my $a (keys %$args) {if ($a =~ /^-(.*)/) {my $b=$1; $args->{$b}=$args->{$a}; delete $args->{$a}}}
1048    
1049     my $filepath=$FIG_Config::fig."/CGI/Html/rss";
1050     # check for the directory and if not, make it
1051     mkdir $filepath unless (-d $filepath);
1052    
1053     # note that $info is a hash of references to hashes that are written out as headers in the file
1054     my $info=
1055     {
1056      "SEED.rss" =>
1057       {
1058            title           => "The SEED",
1059            description     => "Latest news from the SEED",
1060            link            => &FIG::cgi_url()."/Html/rss/SEED.rss",
1061       },
1062    
1063      "SEEDsubsystems.rss" =>
1064      {
1065            title           => "SEED Subsystems",
1066            description     => "Recently updated SEED subsystems",
1067            link            => &FIG::cgi_url()."/Html/rss/SEEDsubsystems.rss",
1068      },
1069    
1070      "SEEDsubsystems.rss" =>
1071      {
1072            title           => "SEED Genomes",
1073            description     => "Genomes recently added to the SEED",
1074            link            => &FIG::cgi_url()."/Html/rss/SEEDsubsystems.rss",
1075      },
1076    
1077     };
1078    
1079    
1080     # build the new xml
1081     my $xml = "\t<item>\n";
1082     foreach my $qw ("title", "description", "link") {
1083      unless ($args->{$qw}) {
1084       print STDERR "You need to include a $qw tag in your RSS description\n";
1085       return(0);
1086      }
1087      # we need to do something a bit funky with the link. We can't have ampersands in the <link> </link> in valid html
1088      # so we are going to pull out the links and uri_escape just the part after the .cgi
1089      if ($qw eq "link")
1090      {
1091       $args->{$qw} =~ /^(.*?\.cgi.)(.*)$/;
1092       print STDERR "Got ->>$1<<- and ->>$2<<-\n";
1093       $args->{$qw} = $1.uri_escape($2) if ($1 && $2);
1094      }
1095    
1096      $xml .= "\t\t<$qw>".$args->{$qw}."</$qw>\n";
1097      delete $args->{$qw};
1098     }
1099    
1100     foreach my $tag (grep {!/type/i} keys %$args)
1101     {
1102      $xml .= "\t\t<$tag>".$args->{$tag}."</$tag>\n";
1103     }
1104    
1105     $xml .= "\t</item>\n";
1106    
1107    
1108     my @files=("SEED.rss");
1109     if ($args->{"type"}) {push @files, "SEED.$type.rss"}
1110    
1111     foreach my $file ("SEED.rss", @$files)
1112     {
1113      if (-e "$filepath/$file")
1114      {
1115       my @out; # the new content of the file
1116       my $itemcount=0; # how many <item> </item>'s are we keeping
1117       my $initem; # are we in an item?
1118       open(IN, "$filepath/$file") || die "Can't open $filepath/$file";
1119       while (<IN>)
1120       {
1121        if (/\<item\>/) {
1122         push @out, $xml, unless ($itemcount);
1123         $itemcount++;
1124         $initem=1;
1125        }
1126        if (/\<\/item\>/) {$initem=0; next if ($itemcount > 9)}
1127        next if ($initem && $itemcount > 9);
1128        push @out, $_;
1129       }
1130       close IN;
1131       open(OUT, ">$filepath/$file") || die "Can't open $filepath/$file for writing";
1132       print OUT @out;
1133      }
1134      else
1135      {
1136       open(OUT, ">$filepath/$file") || die "Can't open $filepath/$file for writing";
1137       print OUT "<?xml version=\"1.0\"?>\n<rss version=\"2.0\">\n<channel>\n";
1138       if ($info->{$file})
1139       {
1140         # we're going to sanity check each of the three options we output, just to be sure
1141         foreach my $qw ("title", "description", "link")
1142         {
1143           if ($info->{$file}->{$qw})
1144           {
1145              print OUT "<$qw>", $info->{$file}->{$qw}, "</$qw>\n";
1146           } else {
1147              print STDERR "Please add a $qw for $file\n"; print OUT "<$qw>$file</$qw>\n";
1148           }
1149         }
1150       }
1151       else {
1152        print STDERR "Please define title, link, and description information for $file\n";
1153        print OUT "<title>$file</title>\n<description>An RSS feed</description>\n<link>", &FIG::cgi_url, "</link>\n";
1154       }
1155       print OUT "\n", $xml;
1156       print OUT "\n", "</channel>\n</rss>\n"
1157      }
1158     }
1159    }
1160    
1161    1;
1162    
 1  

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.59

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3