[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.1, Mon Dec 1 16:54:26 2003 UTC revision 1.37, Tue Mar 15 22:29:27 2005 UTC
# Line 1  Line 1 
1  package HTML;  package HTML;
2    
3    use FIG;
4  use Carp;  use Carp;
5  use Data::Dumper;  use Data::Dumper;
6  use LWP::UserAgent;  use LWP::UserAgent;
7  use LWP::Simple;  use LWP::Simple;
8  use URI::URL;  use URI::URL;
9  use HTTP::Request::Common;  use HTTP::Request::Common;
10    use POSIX;
11    
12    sub new
13    {
14        my($class) = @_;
15    
16        my $self = {};
17    
18        return bless $self, $class;
19    }
20    
21    sub compute_html_header
22    {
23        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
24        my($additional_insert,$user) = @_;
25        my $html_hdr_file = "./Html/html.hdr";
26        if (! -f $html_hdr_file)
27        {
28            $html_hdr_file = "$FIG_Config::fig/CGI/Html/html.hdr";
29        }
30        my @html_hdr = &FIG::file_read($html_hdr_file);
31        push( @html_hdr, "<br><a href=\"index.cgi?user=$user\">FIG search</a>\n" );
32    
33        if (@html_hdr)
34        {
35            my $insert_stuff;
36            my @ver = &FIG::file_head("$FIG_Config::fig_disk/CURRENT_RELEASE", 1);
37            my $ver = $ver[0];
38            chomp $ver;
39            if ($ver =~ /^cvs\.(\d+)$/)
40            {
41                my $d = asctime(localtime($1));
42                chomp($d);
43                $ver .=  " ($d)";
44            }
45            my $host = &FIG::get_local_hostname();
46            $insert_stuff = "SEED version <b>$ver</b> on $host";
47            if ($additional_insert)
48            {
49                $insert_stuff .= "<br>" . $additional_insert;
50            }
51    
52            for $_ (@html_hdr)
53            {
54                s,(href|img\s+src)="/FIG/,\1="$FIG_Config::cgi_base,g;
55                if ($_ eq "<!-- HEADER_INSERT -->\n")
56                {
57                    $_ = $insert_stuff;
58                }
59            }
60        }
61    
62        return @html_hdr;
63    }
64    
65  sub show_page {  sub show_page {
66      my($cgi,$html,$no_home) = @_;      #warn "SHOWPAGE: cgi=", Dumper(@_);
67        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
68        my($cgi,$html,$no_home, $alt_header, $css) = @_;
69      my $i;      my $i;
70    
71      print $cgi->header;  
72      print "<base href=\"" . &FIG::cgi_url . "/\">\n";      # ARGUMENTS:
73      for ($i=0; ($i < @$html) && ($html->[$i] !~ /\<body\>/i); $i++) {}      #     $cgi is the CGI method
74      if ($i < @$html)      #     $html is an array with all the html in it. It is just joined by "\n" (and not <br> or <p>
75        #     $no_home eliminates ONLY the bottom FIG search link in a page
76        #     $alt_header is a reference to an array for an alternate header banner that you can replace the standard one with
77        #     $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
78        #               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
79        #               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
80    
81        #
82        # Find the HTML header
83        #
84    
85        my $html_tail_file = "./Html/html.tail";
86        if (! -f $html_tail_file)
87        {
88            $html_tail_file = "$FIG_Config::fig/CGI/Html/html.tail";
89        }
90    
91        my $user = $cgi->param('user') || "";
92        my @html_hdr;
93        if ($alt_header)
94      {      {
95          splice(@$html,$i+1,0,`cat ./Html/html.hdr`);         @html_hdr = @$alt_header;
96      }      }
97      else      else
98      {      {
99          for ($i=0; ($i < @$html) && ($html->[$i] !~ /\<html\>/i); $i++) {}          @html_hdr = compute_html_header(undef,$user);
100          if ($i < @$html)      }
101    
102    
103        print $cgi->header;
104    
105        #
106        #  The SEED header file goes immediately after <BODY>.  Figure out
107        #  what parts of the HTML document skeleton are there, and fill in
108        #  missing ones.
109        #
110        #  This list should be as comprehensive as feasible:
111        #
112    
113        my %head_tag = ( base     => 1,
114                         basefont => 1,
115                         html     => 1,
116                         isindex  => 1,
117                         link     => 1,
118                         meta     => 1,
119                         nextid   => 1,
120                         style    => 1,
121                         title    => 1
122                       );
123    
124        #
125        #  This list need not be comprehensive; it is just stopping conditions:
126        #
127    
128        my %body_tag = ( a      => 1,
129                         br     => 1,
130                         center => 1,
131                         form   => 1,
132                         h1     => 1,
133                         h2     => 1,
134                         h3     => 1,
135                         hr     => 1,
136                         img    => 1,
137                         p      => 1,
138                         pre    => 1,
139                         table  => 1
140                       );
141    
142        my $html_line = -1;
143        my $head_line = -1;
144        my $base_line = -1;
145        my $head_end_line = -1;
146        my $body_line = -1;
147        my $last_head_line = -1;  #  If no head tags are found, text goes at top.
148        my $done = 0;
149    
150        for ( $i = 0; $i < @$html; $i++ )
151        {
152            #  Some special cases:
153    
154            if ( $html->[$i] =~ /\<html[^0-9a-z]/i ) { $html_line = $i }
155            if ( $html->[$i] =~ /\<head[^0-9a-z]/i ) { $head_line = $i }
156            if ( $html->[$i] =~ /\<base[^0-9a-z]/i ) { $base_line = $i }
157            if ( $html->[$i] =~ /\<\/head\>/i )      { $head_end_line = $i }
158    
159            #  The content goes after this line:
160    
161            if ( $html->[$i] =~ /\<body[^0-9a-z]/i )
162          {          {
163              splice(@$html,$i+1,0,`cat ./Html/html.hdr`);              $body_line = $i;
164                $last;
165          }          }
166          else  
167            #  Now the general case.
168            #  Analyze all the html tags on the line:
169    
170            foreach ( $html->[$i] =~ /\<\/?([0-9a-z]+)/ig )
171            {
172                #  At first body tag, we stop the search and put the text
173                #  after the last line with a head tag:
174    
175                if ( $body_tag{ lc $_ } )
176          {          {
177              splice(@$html,0,0,`cat ./Html/html.hdr`);                  $done = 1;
178                    last;
179          }          }
180    
181                #  If this is a head tag, then move the marker forward
182    
183                elsif ( $head_tag{ lc $_ } )
184                {
185                    $last_head_line = $i;
186                }
187            }
188            last if $done;      # When done, break loop to avoid increment
189      }      }
190    
191      @tail = `cat ./Html/html.tail`;      #  Some sanity checks on structure:
192      if (! $no_home)  
193        if ( 1 )
194      {      {
195          my $user = $cgi->param('user');          if ( $html_line >= 0 )
196          $user = $user ? $user : "";          {
197          my $link = $cgi->url();              if ( ( $head_line >= 0 ) && ( $html_line > $head_line ) )
198          $link =~ s/[a-zA-Z_]+\.cgi$/index.cgi/;              {
199          push(@tail,"<hr><a href=\"$link?user=$user\">FIG search</a>\n");                  print STDERR "<HTML> tag follows <HEAD> tag\n";
200                }
201                if ( ( $head_end_line >= 0 ) && ( $html_line > $head_end_line ) )
202                {
203                    print STDERR "<HTML> tag follows </HEAD> tag\n";
204                }
205            }
206            if ( $head_line >= 0 )
207            {
208                if ( ( $head_end_line >= 0 ) && ( $head_line > $head_end_line ) )
209                {
210                    print STDERR "<HEAD> tag follows </HEAD> tag\n";
211                }
212      }      }
213        }
214    
215        #
216        #  Okay.  Let's put in the html header file, and missing tags:
217        #
218        #  <BODY> goes after last head line
219        #
220        #  RAE:
221        #  Added the javascript for the buttons immediately after body.
222        #  Note if no buttons are added we still (at the moment) add the script,
223        #  but it only adds a little text (495 characters) to the html and noone will notice!
224    
225      if (@tail > 0)      if ( $body_line < 0 )
226      {      {
227          for ($i=0; ($i < @$html) && ($html->[$i] !~ /\<\/body\>/i); $i++) {}          my $js=&javascript;
228          if ($i < @$html)          $body_line = $last_head_line + 1;
229            splice( @$html, $body_line, 0, "<BODY>\n$js\n" );
230        }
231    
232        #
233        #  Seed page header (if it exists) goes after <BODY>
234        #
235    
236        if (@html_hdr)
237          {          {
238              splice(@$html,$i,0,@tail);          splice( @$html, $body_line + 1, 0, @html_hdr );
239          }          }
240          else  
241        #
242        #  </HEAD> goes before <BODY>
243        #
244    
245        if ( $head_end_line < 0 )
246          {          {
247              for ($i=0; ($i < @$html) && ($html->[$i] !~ /\<\/html\>/i); $i++) {}          $head_end_line = $body_line;
248              if ($i < @$html)          splice( @$html, $body_line, 0, "</HEAD>\n" );
249        }
250    
251        # RAE:
252        # Add css here
253        # Note that at the moment I define these two sheets here. I think this should be moved out, but I want to try it and see what happens
254        # css has the format
255        # <link rel='stylesheet' title='default' href='/css/default.css' type='text/css'>
256    
257        # convert the default key to the right case. and eliminate dups
258        foreach my $k (keys %$css) {if (lc($k) eq "default") {$css->{'Default'}=$css->{$k}}}
259    
260        if (!$css || !$css->{'Default'})
261              {              {
262                  splice(@$html,$i,0,@tail);         $css->{'Default'}="/FIG/Html/css/default.css";
263              }              }
264              else      if (!$css->{"Sans Serif"})
265        {
266           $css->{'Sans Serif'}="/FIG/Html/css/sanserif.css";
267        }
268        my $csstext = "<link rel='stylesheet' title='default' href='".$css->{'Default'}."' type='text/css'>\n";
269        $csstext   .= "<link rel='alternate stylesheet' title='Sans Serif' href='".$css->{'Sans Serif'}."' type='text/css'>\n";
270    
271        foreach my $k (keys %$css)
272        {
273           next if (lc($k) eq "default" || lc($k) eq "sans serif");
274           $csstext .= "<link rel='stylesheet' title='$k' href='".$css->{$k}."' type='text/css'>\n";
275        }
276        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.
277    
278        #
279        #  <BASE ...> goes before </HEAD>
280        #
281    
282        if ( $base_line < 0 )
283        {
284            #
285            #  Use a relative base address for pages.  Also, because I am
286            #  worried about when FIG_config.pm gets updated (clean installs
287            #  only, or every update?), I provide an alternative derivation
288            #  from $cgi_url. -- GJO
289            #
290            # BASE href needs to be absolute. RDO.
291            #
292            #
293            $base_url = &FIG::cgi_url;
294    #       my $base_url = $FIG_Config::cgi_base;
295    #       if ( ! $base_url )                      # if cgi_base was not defined
296    #       {
297    #           $base_url = $FIG_Config::cgi_url;   # get the full cgi url
298    #           $base_url =~ s~^http://[^/]*~~;     # remove protocol and host
299    #           $base_url =~ m~/$~ || $base_url =~ s~$~/~; # check trailing slash
300    #       }
301    
302            $base_line = $head_end_line;
303            splice( @$html, $base_line, 0, "<BASE href=\"$base_url/\">\n" );
304        }
305    
306        #
307        #  <HTML> goes at the top of the output
308        #
309    
310        if ( $html_line < 0 )
311        {
312            $html_line = 0;
313            splice( @$html, $html_line, 0, "<HTML>\n" );
314        }
315    
316        #
317        #  <HEAD> goes after <HTML>
318        #
319    
320        if ( $head_line < 0 )
321        {
322            $head_line = $html_line + 1;
323            splice( @$html, $head_line, 0, "<HEAD>\n" );
324        }
325    
326        #
327        #  Place FIG search link at bottom of page
328        #
329    
330        my @tail = -f $html_tail_file ? `cat $html_tail_file` : ();
331        if (! $no_home)
332        {
333            my $user = $cgi->param('user') || "";
334            push( @tail, "<hr><a href=\"index.cgi?user=$user\">FIG search</a>\n" );
335        }
336    
337        #
338        # See if we have a site-specific tail (for disclaimers, etc).
339        #
340    
341        my $site_tail = "$FIG_Config::fig_disk/config/site_tail.html";
342        my $site_fh;
343        if (open($site_fh, "<$site_tail"))
344        {
345            push(@tail, <$site_fh>);
346            close($site_fh);
347        }
348    
349        #
350        #  Figure out where to insert The SEED tail.  Before </body>,
351        #  or before </html>, or at end of page.
352        #
353    
354        my @tags = ();
355    
356        for ($i=0; ($i < @$html) && ($html->[$i] !~ /\<\/body\>/i); $i++) {}
357        if ($i >= @$html)        # </body> not found; look for </html>
358        {
359            push @tags, "\n</BODY>\n";
360            # Even if tag is not found, index points to correct place for splice
361            for ($i=0; ($i < @$html) && ($html->[$i] !~ /\<\/html\>/i); $i++) {}
362            if ($i >= @$html)    # </html> not found; add it
363              {              {
364                  push(@$html,@tail);              push @tags, "</HTML>\n";
365              }              }
366          }          }
367    
368        if ( @tail )
369        {
370            splice( @$html, $i, 0, @tail, @tags );
371        }
372        elsif ( @tags )
373        {
374            splice( @$html, $i, 0, @tags );
375      }      }
376    
377        # RAE the chomp will return any new lines at the ends of elements in the array, and then we can join  with a "\n"
378        # this is because somethings put newlines in, and others don't. This should make nicer looking html
379        #chomp(@$html);
380        #print join "\n", @$html;
381    
382        # Apparently the above still breaks things. This is the correct code:
383      print @$html;      print @$html;
384  }  }
385    
386  sub make_table {  sub make_table {
387      my($col_hdrs,$tab,$title,$instr) = @_;      my($col_hdrs,$tab,$title, %options ) = @_;
388      my(@tab);      my(@tab);
389    
390      push(@tab,"<table border><caption><b>$title</b></caption>\n");      my $border = defined $options{border} ? "border=\"$options{border}\"" : "border";
391      push(@tab,"<tr><th>" . join("</th><th>",@$col_hdrs) . "</th></tr>\n");      push( @tab, "\n<table $border>\n",
392      my($i,$nowrap);                  "\t<caption><b>$title</b></caption>\n",
393                    "\t<tr>\n\t\t"
394                  . join( "\n", map { &expand($_, "th") } @$col_hdrs )
395                  . "\n\t</tr>\n"
396            );
397        my($i);
398    
399        my $row;
400        foreach $row (@$tab)
401        {
402            push( @tab, "\t<tr>\n"
403                      . join( "\n", map { &expand($_) } @$row )
404                      . "\n\t</tr>\n"
405                );
406        }
407        push(@tab,"</table>\n");
408        return join("",@tab);
409    }
410    
411      for ($i=0; ($i < @$instr) && ($instr->[$i] !~ /nowrap/); $i++) {}  sub expand {
412      $nowrap = ($i == @$instr) ? "" : " nowrap";      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
413        my($x, $tag) = @_;
414    
415        $tag = "td" unless $tag;
416        my $endtag=$tag;
417        # RAE modified this so that you can pass in a reference to an array where the first element is the data to
418        # display and the second element is optional things like colspan and align. Note that in this case you need to include the td
419        # use something like ["some data to appear", "td colspan=4 bgcolor=gray"]
420        if (ref($x) eq "ARRAY") {($x, $tag)=@$x; if ($tag =~ /td/) {$endtag = "td"}}
421    
422      foreach $_ (@$tab)      if ($x =~ /^\@([^:]+)\:(.*)$/)
423      {      {
424          push(@tab,"<tr><td$nowrap>" . join("</td><td$nowrap>",@$_) . "</td></tr>\n");          return "\t\t<$tag $1>$2</$endtag>";
425        }
426        else
427        {
428            return "\t\t<$tag>$x</$endtag>";
429      }      }
430      push(@tab,"</table>\n");  }
431      return join("",@tab);  
432    sub set_ec_links {
433        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
434        my($cgi,$x) = @_;
435        my($before,$match,$after);
436    
437        if ($x =~ /^(.*)(EC \d+\.\d+\.\d+\.\d+)(.*)/s)
438        {
439            $before = $1;
440            $match = $2;
441            $after = $3;
442            return &set_ec_links($cgi,$before) . &HTML::ec_link($match) . &set_ec_links($cgi,$after);
443        }
444        return $x;
445  }  }
446    
447  sub ec_link {  sub ec_link {
448        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
449      my($role) = @_;      my($role) = @_;
450    
451      if ($role =~ /(\d+\.\d+\.\d+\.\d+)/)      if ($role =~ /(\d+\.\d+\.\d+\.\d+)/)
# Line 97  Line 459 
459  }  }
460    
461  sub role_link {  sub role_link {
462        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
463      my($cgi,$role) = @_;      my($cgi,$role) = @_;
464    
465      my $roleR = ($role =~ /^(\d+\.\d+\.\d+\.\d+)\s+-\s+/) ? $1 : $role;      my $roleR = ($role =~ /^(\d+\.\d+\.\d+\.\d+)\s+-\s+/) ? $1 : $role;
# Line 107  Line 470 
470      return "<a href=$link>$role</a>";      return "<a href=$link>$role</a>";
471  }  }
472    
473    #
474    # Local means to eliminate the fig|org.peg from the
475    # text of the link.
476    #
477  sub fid_link {  sub fid_link {
478        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
479      my($cgi,$fid,$local,$just_url) = @_;      my($cgi,$fid,$local,$just_url) = @_;
480      my($n);      my($n);
481    
# Line 132  Line 500 
500          my $user = $cgi->param('user');          my $user = $cgi->param('user');
501          if (! $user) { $user = "" }          if (! $user) { $user = "" }
502          my $trans = $cgi->param('translate') ? "&translate=1" : "";          my $trans = $cgi->param('translate') ? "&translate=1" : "";
503          my $link = $cgi->url() . "?prot=$fid&user=$user$trans";          my $sprout = $cgi->param('SPROUT') ? "&SPROUT=1" : "";
504          $link =~ s/[a-z_A-Z]+\.cgi\?/protein.cgi?/;          my $link = &FIG::cgi_url . "/protein.cgi?prot=$fid&user=$user$trans$sprout";
505            $link =~ s/[a-z_A-Z0-9]+\.cgi\?/protein.cgi?/;
506            #
507            # Elimin the p2p part if we're in that subdir. Ugh.
508            #
509            $link =~ s,p2p/protein.cgi,protein.cgi,;
510    
511          if ($just_url)          if ($just_url)
512          {          {
513              return $link;              return $link;
# Line 147  Line 521 
521  }  }
522    
523  sub family_link {  sub family_link {
524        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
525      my($family,$user) = @_;      my($family,$user) = @_;
526    
527      return $family;      return $family;
# Line 155  Line 530 
530  use URI::Escape;  use URI::Escape;
531    
532  sub get_html {  sub get_html {
533        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
534      my( $url, $type, $kv_pairs) = @_;      my( $url, $type, $kv_pairs) = @_;
535      my( $encoded, $ua, $args, @args, $out, @output, $x );      my( $encoded, $ua, $args, @args, $out, @output, $x );
536    
537      $ua = new LWP::UserAgent;      $ua = new LWP::UserAgent;
538      $ua->timeout( 900 );      $ua->timeout( 900 );
   
539      if ($type =~/post/i)      if ($type =~/post/i)
540      {      {
541          $args = [];          $args = [];
# Line 220  Line 595 
595  }  }
596    
597  sub trim_output {  sub trim_output {
598        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
599      my($out) = @_;      my($out) = @_;
600      my $i;      my $i;
601    
# Line 250  Line 626 
626      for ($j=$i-1; ($j > 0) && ($out->[$j] !~ /FIG search/); $j--) {}      for ($j=$i-1; ($j > 0) && ($out->[$j] !~ /FIG search/); $j--) {}
627      if ($j > 0)      if ($j > 0)
628      {      {
629          my @tmp = `cat ./Html/html.tail`;          my @tmp = `cat $html_tail_file`;
630          my $n = @tmp;          my $n = @tmp;
631          splice(@$out,$j-$n,$n+1);          splice(@$out,$j-$n,$n+1);
632      }      }
633  }  }
634    
635  sub set_prot_links {  sub set_prot_links {
636        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
637      my($cgi,$x) = @_;      my($cgi,$x) = @_;
638      my($before,$match,$after);      my($before,$match,$after);
639    
640      if ($x =~ /^(.*)(fig\|\d+\.\d+\.peg\.\d+)(.*)$/)      if ($x =~ /^(.*)(fig\|\d+\.\d+\.peg\.\d+)(.*)/s)
641        {
642            $before = $1;
643            $match = $2;
644            $after = $3;
645            return &set_prot_links($cgi,$before) . &HTML::fid_link($cgi,$match) . &set_prot_links($cgi,$after);
646        }
647        elsif ($x =~ /^(.*)\b([NXYZA]P_[0-9\.]+)\b(.*)/s)
648        {
649            $before = $1;
650            $match = $2;
651            $after = $3;
652            return &set_prot_links($cgi,$before) . &HTML::refseq_link($cgi,$match) . &set_prot_links($cgi,$after);
653        }
654        elsif ($x =~ /^(.*)(gi\|\d+)(.*)/s)
655        {
656            $before = $1;
657            $match = $2;
658            $after = $3;
659            return &set_prot_links($cgi,$before) . &HTML::gi_link($cgi,$match) . &set_prot_links($cgi,$after);
660        }
661        elsif ($x =~  /^(.*)(uni\|[A-Z0-9]{6})(.*)/s)
662      {      {
663          $before = $1;          $before = $1;
664          $match = $2;          $match = $2;
665          $after = $3;          $after = $3;
666          return &set_prot_links($cgi,$before) . &HTML::fid_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);
667      }      }
668      elsif ($x =~ /^(.*)(gi\|\d+)(.*)$/)      elsif ($x =~ /^(.*)(sp\|[A-Z0-9]{6})(.*)/s)
669      {      {
670          $before = $1;          $before = $1;
671          $match = $2;          $match = $2;
672          $after = $3;          $after = $3;
673          return &set_prot_links($cgi,$before) . &HTML::gi_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);
674      }      }
675      elsif ($x =~ /^(.*)(sp\|[A-Z0-9]{6})(.*)$/)      elsif ($x =~ /^(.*)(pirnr\|NF\d+)(.*)/s)
676      {      {
677          $before = $1;          $before = $1;
678          $match = $2;          $match = $2;
679          $after = $3;          $after = $3;
680          return &set_prot_links($cgi,$before) . &HTML::sp_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);
681      }      }
682      elsif ($x =~ /^(.*)(pirnr\|NF\d+)(.*)$/)      elsif ($x =~ /^(.*)(kegg\|[a-z]{2,4}:[a-zA-Z_0-9]+)(.*)/s)
683      {      {
684          $before = $1;          $before = $1;
685          $match = $2;          $match = $2;
686          $after = $3;          $after = $3;
687          return &set_prot_links($cgi,$before) . &HTML::pir_link($cgi,$match) . &set_prot_links($cgi,$after) . "\n";          return &set_prot_links($cgi,$before) . &HTML::kegg_link($cgi,$match) . &set_prot_links($cgi,$after);
688      }      }
689      return $x;      return $x;
690  }  }
691    
692    sub refseq_link {
693        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
694        my($cgi,$id) = @_;
695    
696        if ($id =~ /^[NXYZA]P_/)
697        {
698            return "<a href=http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=protein&cmd=search&term=$id>$id</a>";
699        }
700    }
701    
702  sub gi_link {  sub gi_link {
703        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
704      my($cgi,$gi) = @_;      my($cgi,$gi) = @_;
705    
706      if ($gi =~ /^gi\|(\d+)$/)      if ($gi =~ /^gi\|(\d+)$/)
# Line 301  Line 710 
710      return $gi;      return $gi;
711  }  }
712    
713    sub uni_link {
714        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
715        my($cgi,$uni) = @_;
716    
717        if ($uni =~ /^uni\|(\S+)$/)
718        {
719            return "<a href=http://www.pir.uniprot.org/cgi-bin/upEntry?id=$1>$uni</a>";
720        }
721        return $uni;
722    }
723    
724  sub sp_link {  sub sp_link {
725        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
726      my($cgi,$sp) = @_;      my($cgi,$sp) = @_;
727    
728      if ($sp =~ /^sp\|(\S+)$/)      if ($sp =~ /^sp\|(\S+)$/)
# Line 312  Line 733 
733  }  }
734    
735  sub pir_link {  sub pir_link {
736        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
737      my($cgi,$pir) = @_;      my($cgi,$pir) = @_;
738    
739      if ($pir =~ /^pirnr\|(NF\d+)$/)      if ($pir =~ /^pirnr\|(NF\d+)$/)
# Line 321  Line 743 
743      return $pir;      return $pir;
744  }  }
745    
746    sub kegg_link {
747        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
748        my($cgi,$kegg) = @_;
749    
750        if ($kegg =~ /^kegg\|([^:]+):(\S+)$/)
751        {
752            return "<a href=http://www.genome.ad.jp/dbget-bin/www_bget?$1+$2>$kegg</a>";
753        }
754        return $kegg;
755    }
756    
757    sub set_map_links {
758        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
759        my($cgi,$x) = @_;
760        my($before,$match,$after);
761    
762        my $org = ($cgi->param('org') || $cgi->param('genome') || "");
763    
764        if ($x =~ /^(.*)(MAP\d+)(.*)/s)
765        {
766            $before = $1;
767            $match = $2;
768            $after = $3;
769            return &set_map_links($cgi,$before) . &map_link($cgi,$match,$org) . &set_map_links($cgi,$after);
770        }
771        return $x;
772    }
773    
774    sub map_link {
775        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
776        my($cgi,$map,$org) = @_;
777    
778        $user = $cgi->param('user');
779        $user = $user ? $user : "";
780        $org = $org ? $org : "";
781        my $url = "$FIG_Config::cgi_url/show_kegg_map.cgi?user=$user&map=$map&org=$org";
782        my $link = "<a href=\"$url\">$map</a>";
783        return $link;
784    }
785    
786    sub javascript {
787        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
788            #### MODIFIED BY RAE TO ADD JAVA SUPPORT FOR CHECK ALL/UNCHECK ALL
789            # This routine takes three arguments, $html, $form, and $button
790            # $html is the ref to the array with the html in it
791            # $form is the name of the form. This must be added whenever start_form is called
792            # by including a -name entry. This is only used for the javascript
793            # $button is the name of the button that should be checked/unchecked.
794            #
795            # At the moment this add's four buttons:
796            # Check all, check's all
797            # Check first half will check the first 50% of the entries
798            # Check second half will check the second 50% of the entries
799            # Uncheck all will remove the checks.
800    
801            # Note that the other change is I added a -name=>'fig_checked' to the start_form
802            # field. The name is needed for the java script.
803            #
804    
805              $java_script=<<EOF;
806      <SCRIPT LANGUAGE="JavaScript">
807      <!-- Begin
808      function checkAll(field)
809      {
810       for (i = 0; i < field.length; i++)
811       field[i].checked = true ;
812      }
813    
814      function checkFirst(field)
815      {
816       for (i = 0; i < field.length/2; i++)
817       field[i].checked = true;
818      }
819    
820      function checkSecond(field)
821      {
822       for (i=Math.round(field.length/2); i < field.length; i++)
823       field[i].checked = true ;
824      }
825    
826      function uncheckAll(field)
827      {
828       for (i = 0; i < field.length; i++)
829       field[i].checked = false ;
830      }
831      //  End -->
832      </script>
833    EOF
834            return $java_script;
835    }
836    
837    sub java_buttons {
838        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
839      ## ADDED BY RAE
840      # Provides code to include check all/first half/second half/none for javascrspt
841      # this takes two variables - the form name provided in start_form with the
842      # -name => field and the checkbox name
843      my ($form, $button)=@_;
844    
845      $java_script="<input type=\"button\" name=\"CheckAll\" value=\"Check All\"\nonClick=\"checkAll(document.$form.$button)\">\n";
846      $java_script.="<input type=\"button\" name=\"CheckFirst\" value=\"Check First Half\"\nonClick=\"checkFirst(document.$form.$button)\">\n";
847      $java_script.="<input type=\"button\" name=\"CheckSecond\" value=\"Check Second Half\"\nonClick=\"checkSecond(document.$form.$button)\">\n";
848      $java_script.="<input type=\"button\" name=\"UnCheckAll\" value=\"Uncheck All\"\nonClick=\"uncheckAll(document.$form.$button)\">\n";
849    
850      return $java_script;
851    }
852    
853    sub sub_link {
854        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
855        my($cgi,$sub) = @_;
856        my($sub_link);
857    
858        my $user = $cgi->param('user');
859        if ($user)
860        {
861            $sub_link = "<a href=./subsys.cgi?ssa_name=$sub&request=show_ssa&user=$user>$sub</a>";
862        }
863        else
864        {
865            $sub_link = $sub;
866        }
867        return $sub_link;
868    }
869    
870  1  1

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.37

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3