koha-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Koha-cvs] CVS: koha/C4 Charset.pm,NONE,1.1 Auth.pm,1.18,1.19


From: Ambrose Li
Subject: [Koha-cvs] CVS: koha/C4 Charset.pm,NONE,1.1 Auth.pm,1.18,1.19
Date: Sat, 18 Jan 2003 22:15:46 -0800

Update of /cvsroot/koha/koha/C4
In directory sc8-pr-cvs1:/tmp/cvs-serv10738/C4

Modified Files:
        Auth.pm 
Added Files:
        Charset.pm 
Log Message:
Preliminary fix of the CGI.pm problem of always assuming that everything is
in ISO-8859-1.

A new C4::Charset module (tentative name) has been created to guess the
charset of a piece of HTML markup. The CGI programs will be modified to use
this module as they are encountered during translation.


--- NEW FILE ---
package C4::Charset;

# $Id: Charset.pm,v 1.1 2003/01/19 06:15:44 acli Exp $

#package to work around problems in HTTP headers
# Note: This is just a utility module; it should not be instantiated.


# Copyright 2003 Katipo Communications
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA  02111-1307 USA

use strict;
require Exporter;

use vars qw($VERSION @ISA @EXPORT);

# set the version for version checking
$VERSION = 0.01;

=head1 NAME

C4::Charset - Functions for handling charsets in HTML pages

=head1 SYNOPSIS

  use C4::Charset;

  print $query->header(-type => C4::Charset::gettype($output)), $output;

=head1 DESCRIPTION

The functions in this module peek into a piece of HTML and return strings
related to the (guessed) charset.

=head1 FUNCTIONS

=over 2

=cut

@ISA = qw(Exporter);
@EXPORT = qw(
                &guesscharset
                &guesstype
             );

=pod

  &guesscharset($output)

"Guesses" the charset from the some HTML that would be output.

C<$output> is the HTML page to be output. If it contains a META tag
with a Content-Type, the tag will be scanned for a language code.
This code is returned if it is found; undef is returned otherwise.

This function only does sloppy guessing; it will be confused by
unexpected things like SGML comments. What it basically does is to
grab something that looks like a META tag and scan it.

=cut

sub guesscharset ($) {
   my($html) = @_;
   my $charset = undef;
   local($`, $&, $', $1, $2, $3);
   # FIXME... These regular expressions will miss a lot of valid tags!
   if ($html =~ 
/<meta\s+http-equiv=(["']?)Content-Type\1\s+content=(["'])text\/html\s*;\s*charset=([^\2\s\r\n]+)\2\s*(?:\/?)>/is)
 {
      $charset = $3;
   } elsif ($html =~ 
/<meta\s+content=(["'])text\/html\s*;\s*charset=([^\1\s\r\n]+)\1\s+http-equiv=(["']?)Content-Type\3\s*(?:\/?)>/is)
 {
      $charset = $2;
   }
   return $charset;
} # guess

sub guesstype ($) {
   my($html) = @_;
   my $charset = guesscharset($html);
   return defined $charset? "text/html; charset=$charset": "text/html";
}

#---------------------------------

END { }       # module clean-up code here (global destructor)

1;
__END__

=back

=head1 AUTHOR

Koha Developement team <address@hidden>

=cut

Index: Auth.pm
===================================================================
RCS file: /cvsroot/koha/koha/C4/Auth.pm,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -r1.18 -r1.19
*** Auth.pm     10 Dec 2002 15:52:49 -0000      1.18
--- Auth.pm     19 Jan 2003 06:15:44 -0000      1.19
***************
*** 24,27 ****
--- 24,28 ----
  use C4::Context;
  use C4::Output;              # to get the template
+ use C4::Charset;
  use C4::Circulation::Circ2;  # getpatroninformation
  
***************
*** 50,54 ****
                          });
  
!   print $query->header(-cookie => $cookie), $template->output;
  
  
--- 51,58 ----
                          });
  
!   print $query->header(
!     -type => guesstype($template->output),
!     -cookie => $cookie
!   ), $template->output;
  
  
***************
*** 285,289 ****
        }
        return ($userid, $cookie, $sessionID, $flags);
-       exit;
      }
      # else we have a problem...
--- 289,292 ----
***************
*** 306,310 ****
                                  -value => $sessionID,
                                  -expires => '+1y');
!     print $query->header(-cookie=>$cookie), $template->output;
      exit;
  }
--- 309,316 ----
                                  -value => $sessionID,
                                  -expires => '+1y');
!     print $query->header(
!       -type => guesstype($template->output),
!       -cookie => $cookie
!     ), $template->output;
      exit;
  }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]