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

Diff of /FigKernelPackages/Tracer.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.77, Sat Oct 7 13:21:08 2006 UTC revision 1.78, Fri Nov 3 17:00:38 2006 UTC
# Line 950  Line 950 
950  Returns a PERL time, that is, a number of seconds since the epoch, or C<undef> if  Returns a PERL time, that is, a number of seconds since the epoch, or C<undef> if
951  the time string is invalid.  the time string is invalid.
952    
953    =back
954    
955  =cut  =cut
956    
957  sub ParseTraceDate {  sub ParseTraceDate {
# Line 3066  Line 3068 
3068      return $retVal;      return $retVal;
3069  }  }
3070    
3071    =head3 ApplyURL
3072    
3073    C<< Tracer::ApplyURL($table, $target, $url); >>
3074    
3075    Run through a two-dimensional table (or more accurately, a list of lists), converting the
3076    I<$target> column to HTML text having a hyperlink to a URL in the I<$url> column. The
3077    URL column will be deleted by this process and the target column will be HTML-escaped.
3078    
3079    This provides a simple way to process the results of a database query into something
3080    displayable by combining a URL with text.
3081    
3082    =over 4
3083    
3084    =item table
3085    
3086    Reference to a list of lists. The elements in the containing list will be updated by
3087    this method.
3088    
3089    =item target
3090    
3091    The index of the column to be converted into HTML.
3092    
3093    =item url
3094    
3095    The index of the column containing the URL. Note that the URL must have a recognizable
3096    C<http:> at the beginning.
3097    
3098    =back
3099    
3100    =cut
3101    
3102    sub ApplyURL {
3103        # Get the parameters.
3104        my ($table, $target, $url) = @_;
3105        # Loop through the table.
3106        for my $row (@{$table}) {
3107            # Apply the URL to the target cell.
3108            $row->[$target] = CombineURL($row->[$target], $row->[$url]);
3109            # Delete the URL from the row.
3110            delete $row->[$url];
3111        }
3112    }
3113    
3114    =head3 CombineURL
3115    
3116    C<< my $combinedHtml = Tracer::CombineURL($text, $url); >>
3117    
3118    This method will convert the specified text into HTML hyperlinked to the specified
3119    URL. The hyperlinking will only take place if the URL looks legitimate: that is, it
3120    is defined and begins with an C<http:> header.
3121    
3122    =over 4
3123    
3124    =item text
3125    
3126    Text to return. This will be HTML-escaped automatically.
3127    
3128    =item url
3129    
3130    A URL to be hyperlinked to the text. If it does not look like a URL, then the text
3131    will be returned without any hyperlinking.
3132    
3133    =item RETURN
3134    
3135    Returns the original text, HTML-escaped, with the URL hyperlinked to it. If the URL
3136    doesn't look right, the HTML-escaped text will be returned without any further
3137    modification.
3138    
3139    =back
3140    
3141    =cut
3142    
3143    sub CombineURL {
3144        # Get the parameters.
3145        my ($text, $url) = @_;
3146        # Declare the return variable.
3147        my $retVal = CGI::escapeHTML($text);
3148        # Verify the URL.
3149        if (defined($url) && $url =~ m!http://!i) {
3150            # It's good, so we apply it to the text.
3151            $retVal = "<a href=\"$url\">$retVal</a>";
3152        }
3153        # Return the result.
3154        return $retVal;
3155    }
3156    
3157  1;  1;

Legend:
Removed from v.1.77  
changed lines
  Added in v.1.78

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3