cvsuser     02/02/08 12:43:36

  Modified:    P5EEx/Blue/P5EEx/Blue/Widget HTML.pm
  Log:
  added escaping utility methods
  
  Revision  Changes    Path
  1.2       +60 -2     p5ee/P5EEx/Blue/P5EEx/Blue/Widget/HTML.pm
  
  Index: HTML.pm
  ===================================================================
  RCS file: /cvs/public/p5ee/P5EEx/Blue/P5EEx/Blue/Widget/HTML.pm,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- HTML.pm   5 Feb 2002 22:16:05 -0000       1.1
  +++ HTML.pm   8 Feb 2002 20:43:36 -0000       1.2
  @@ -1,10 +1,10 @@
   
   ######################################################################
  -## $Id: HTML.pm,v 1.1 2002/02/05 22:16:05 spadkins Exp $
  +## $Id: HTML.pm,v 1.2 2002/02/08 20:43:36 spadkins Exp $
   ######################################################################
   
   package P5EEx::Blue::Widget::HTML;
  -$VERSION = do { my @r=(q$Revision: 1.1 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
  +$VERSION = do { my @r=(q$Revision: 1.2 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
   
   use P5EEx::Blue::Widget;
   @ISA = ( "P5EEx::Blue::Widget" );
  @@ -53,6 +53,64 @@
       $args = "";
       $args = "(" . join(",",@args) . ")" if ($#args > -1);
       "<input type=hidden name='p5ee.event' value='${name}.${event}${args}'/>";
  +}
  +
  +# unescape URL-encoded data
  +sub url_unescape {
  +   my $self = shift;
  +   my($todecode) = @_;
  +   $todecode =~ tr/+/ /;       # pluses become spaces
  +   $todecode =~ s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge;
  +   return $todecode;
  +}
  +
  +# URL-encode data
  +sub url_escape {
  +   my $self = shift;
  +   my ($toencode,$charset) = @_;
  +   if ($charset) {
  +      $toencode=~s/($charset)/uc sprintf("%%%02x",ord($1))/eg;
  +   }
  +   else {
  +      $toencode=~s/([^a-zA-Z0-9_\-. ])/uc sprintf("%%%02x",ord($1))/eg;
  +      $toencode =~ tr/ /+/;       # spaces become pluses
  +   }
  +   return $toencode;
  +}
  +
  +# HTML-escape data
  +sub html_escape {
  +   my ($self, $text) = @_;
  +   $text =~ s{&}{&amp;}gso;
  +   $text =~ s{<}{&lt;}gso;
  +   $text =~ s{>}{&gt;}gso;
  +   $text =~ s{\"}{&quot;}gso;
  +   return $text;
  +}
  +
  +# get the URL of the host
  +sub host_url {
  +   my ($url, $protocol, $server, $port, $port_str);
  +
  +   $protocol = "http";                            # assume it's vanilla HTTP
  +   $protocol = "https" if (defined $ENV{HTTPS});  # this is how Apache does it
  +
  +   $server = $ENV{SERVER_NAME};
  +   $server = "localhost" if (!$server);
  +
  +   $port = $ENV{SERVER_PORT};
  +   $port = "80" if (!$port);
  +
  +   $port_str = "";
  +   if ($protocol eq "http") {
  +      $port_str = ($port == 80) ? "" : ":$port";
  +   }
  +   elsif ($protocol eq "https") {
  +      $port_str = ($port == 443) ? "" : ":$port";
  +   }
  +
  +   $url = "${protocol}://${server}${port_str}";
  +   $url;
   }
   
   ######################################################################
  
  
  


Reply via email to