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

Annotation of /FigKernelPackages/HTML.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.70 - (view) (download) (as text)

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3