[Bio] / Sprout / ResultHelper.pm Repository:
ViewVC logotype

Diff of /Sprout/ResultHelper.pm

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

revision 1.1, Mon Jul 16 20:04:51 2007 UTC revision 1.2, Wed Jul 25 16:20:20 2007 UTC
# Line 91  Line 91 
91  Identifies how the column should be downloaded. An empty string means it should not  Identifies how the column should be downloaded. An empty string means it should not
92  be downloaded at all. The other values are C<num>, indicating that the column contains  be downloaded at all. The other values are C<num>, indicating that the column contains
93  numeric data, C<text>, indicating that the column contains an html-escaped string,  numeric data, C<text>, indicating that the column contains an html-escaped string,
94  C<link>, indicating that the column contains a L</Formlet>, C<list>, indicating that  C<link>, indicating that the column contains a L</Formlet> or L</FakeButton>,
95  the column contains a comma-separated list with optional hyperlinks, or C<align>,  C<list>, indicating that the column contains a comma-separated list with optional
96  indicating that the column contains multi-line aligned text with individual lines  hyperlinks, or C<align>,indicating that the column contains multi-line
97  separated by a C<br> tag.  aligned text with individual lines separated by a C<br> tag.
98    
99  =item style  =item style
100    
# Line 490  Line 490 
490  Take a string of Html text and clean it up so it appears as real text.  Take a string of Html text and clean it up so it appears as real text.
491  Note that this method is not yet sophisticated enough to detect right-angle brackets  Note that this method is not yet sophisticated enough to detect right-angle brackets
492  inside tag parameters, nor can it handle style or script tags. Its only sophistication  inside tag parameters, nor can it handle style or script tags. Its only sophistication
493  is that it knows how to convert a formlet to a URL. Otherwise, it is a dirt simple  is that it knows how to convert formlets or fake buttons URLs. Otherwise, it is a dirt simple
494  method that suffices for search result processing.  method that suffices for search result processing.
495    
496  =over 4  =over 4
# Line 519  Line 519 
519      my $retVal;      my $retVal;
520      # Check for a formlet.      # Check for a formlet.
521      if ($type eq 'link') {      if ($type eq 'link') {
522          # Here we have a formlet and we want to convert it to a URL.          # Here we have a formlet or fake button and we want to convert it to a URL.
523          $retVal = FormletToLink($htmlText);          $retVal = ButtonToLink($htmlText);
524      } elsif ($type eq 'align') {      } elsif ($type eq 'align') {
525          # Here we have multiple lines. Convert the new-lines to serial commas.          # Here we have multiple lines. Convert the new-lines to serial commas.
526          $retVal =~ s/<br\s*\/?>/, /g;          $retVal =~ s/<br\s*\/?>/, /g;
# Line 552  Line 552 
552  =item type  =item type
553    
554  Type of column: C<num> for a number, C<text> for a string, C<list> for a  Type of column: C<num> for a number, C<text> for a string, C<list> for a
555  comma-separated list, and C<link> for a formlet link.  comma-separated list, and C<link> for a formlet or fake button.
556    
557  =item RETURN  =item RETURN
558    
# Line 569  Line 569 
569      my $retVal;      my $retVal;
570      # Check for a formlet.      # Check for a formlet.
571      if ($type eq 'link') {      if ($type eq 'link') {
572          # Here we have a formlet and we want to convert it to a URL. We begin          # Here we have a formlet or fake button and we want to convert it to a URL.
573          # with the action.          $retVal = ButtonToLink($htmlText);
         if ($htmlText =~ /action="([^"]+)"/i) {  
             $retVal = $1;  
             # Now, parse out the parameters, all of which are stored in the formlet as hidden  
             # input fields. This is the point where we assume that the formlet generates things  
             # in a well-defined format.  
             my @parms = ();  
             while ($htmlText =~ /<input\s+type="hidden"\s+name="([^"]+)"\s+value="([^"]+)"/ig) {  
                 push @parms, "$1=" . uri_escape($2);  
             }  
             # If there were any parameters, assemble them into the URL.  
             if (scalar(@parms)) {  
                 $retVal .= "?" . join(";", @parms);  
             }  
         } else {  
             # Here the column is empty. We output an empty string.  
             $retVal = '';  
         }  
574      } elsif ($type eq 'num' || $type eq 'text') {      } elsif ($type eq 'num' || $type eq 'text') {
575          # Here we have a number or text. Return the raw value.          # Here we have a number or text. Return the raw value.
576          $retVal = $htmlText;          $retVal = $htmlText;
# Line 621  Line 604 
604      return $retVal;      return $retVal;
605  }  }
606    
607  =head3 FormletToLink  =head3 ButtonToLink
608    
609  C<< my $url = ResultHelper::FormletToLink($htmlText); >>  C<< my $url = ResultHelper::ButtonToLink($htmlText); >>
610    
611  Convert a formlet to a link. This process is bound very tightly with  Convert a formlet or fake button to a link. This process is bound very tightly with
612  the way L</Formlet> generates Html. A change there requires a change  the way L</Formlet> and L</FakeButton> generate Html. A change there requires a
613  here.  change here.
614    
615  =over 4  =over 4
616    
# Line 643  Line 626 
626    
627  =cut  =cut
628    
629  sub FormletToLink {  sub ButtonToLink {
630      # Get the parameters.      # Get the parameters.
631      my ($htmlText) = @_;      my ($htmlText) = @_;
632      # Declare the return variable.      # Declare the return variable.
633      my $retVal;      my $retVal;
634      # We begin with the action.      # We begin with the action.
635      $htmlText =~ /action="([^"]+)"/i;      if ($htmlText =~ /action="([^"]+)"/i) {
636            # Action found, so this is a formlet. The action is the base of the URL.
637      $retVal = $1;      $retVal = $1;
638      # Now, parse out the parameters, all of which are stored in the formlet as hidden      # Now, parse out the parameters, all of which are stored in the formlet as hidden
639      # input fields. This is the point where we assume that the formlet generates things      # input fields. This is the point where we assume that the formlet generates things
# Line 662  Line 646 
646      if (scalar(@parms)) {      if (scalar(@parms)) {
647          $retVal .= "?" . join(";", @parms);          $retVal .= "?" . join(";", @parms);
648      }      }
649        } elsif ($htmlText =~ /<a\s+href="([^"]+)"/) {
650            # Here we have a fake button. The URL is the HREF.
651            $retVal = $1;
652        } else {
653            # Here the column is empty. We output an empty string.
654            $retVal = '';
655        }
656        # Now a final cleanup. If we have a URL and it's relative, we need to add our path to it.
657        if ($retVal && $retVal !~ m#http://#) {
658            # The link doesn't begin with http, so we must fix it. Get our URL.
659            my $cgi = CGI->new();
660            my $selfURL = $cgi->url(-full => 1);
661            # Strip off the page name.
662            $selfURL =~ m#^(.+)/[^/]+$#;
663            my $path = $1;
664            # Combine it with the relative URL.
665            $retVal = "$1/$retVal";
666        }
667      # Return the result.      # Return the result.
668      return $retVal;      return $retVal;
669  }  }

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3