[LON-CAPA-cvs] cvs: doc /loncapafiles loncapafiles.lpml loncom LONCAPA.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Mon, 08 May 2006 22:06:27 -0000
albertel Mon May 8 18:06:27 2006 EDT
Added files:
/loncom LONCAPA.pm
Modified files:
/doc/loncapafiles loncapafiles.lpml
Log:
- adding the LONCAPA.pm base
Index: doc/loncapafiles/loncapafiles.lpml
diff -u doc/loncapafiles/loncapafiles.lpml:1.480 doc/loncapafiles/loncapafiles.lpml:1.481
--- doc/loncapafiles/loncapafiles.lpml:1.480 Mon May 8 14:53:54 2006
+++ doc/loncapafiles/loncapafiles.lpml Mon May 8 18:06:26 2006
@@ -2,7 +2,7 @@
"http://lpml.sourceforge.net/DTD/lpml.dtd">
<!-- loncapafiles.lpml -->
-<!-- $Id: loncapafiles.lpml,v 1.480 2006/05/08 18:53:54 albertel Exp $ -->
+<!-- $Id: loncapafiles.lpml,v 1.481 2006/05/08 22:06:26 albertel Exp $ -->
<!--
@@ -6345,6 +6345,14 @@
</description>
</file>
<file>
+ <source>loncom/LONCAPA.pm</source>
+ <target dist='default'>home/httpd/lib/perl/LONCAPA.pm</target>
+ <categoryname>handler</categoryname>
+ <description>
+ Some basic Lon-CAPA functionality
+ </description>
+</file>
+<file>
<source>loncom/interface/lonnotify.pm</source>
<target dist='default'>home/httpd/lib/perl/Apache/lonnotify.pm</target>
<categoryname>handler</categoryname>
Index: loncom/LONCAPA.pm
+++ loncom/LONCAPA.pm
# The LearningOnline Network
# Base routines
#
# $Id: LONCAPA.pm,v 1.1 2006/05/08 22:05:54 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA 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.
#
# LON-CAPA 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 LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
###
package LONCAPA;
use strict;
require Exporter;
our @ISA = qw (Exporter);
our @EXPORT = qw(&add_get_param &escape &unescape);
# Inputs are a url, adn a hash ref of
# form name => value pairs
# takes care of properly adding the form name elements and values to the
# the url doing proper escaping of the values and joining with ? or & as
# needed
sub add_get_param {
my ($url,$form_data) = @_;
my $needs_question_mark = ($url !~ /\?/);
while (my ($name,$value) = each(%$form_data)) {
if ($needs_question_mark) {
$url.='?';
$needs_question_mark = 0;
} else {
$url.='&';
}
$url.=$name.'='.&escape($form_data->{$name});
}
return $url;
}
# -------------------------------------------------------- Escape Special Chars
sub escape {
my $str=shift;
$str =~ s/(\W)/"%".unpack('H2',$1)/eg;
return $str;
}
# ----------------------------------------------------- Un-Escape Special Chars
sub unescape {
my $str=shift;
$str =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
return $str;
}
1;
__END__
=pod
=head1 NAME
LONCAPA - Basic routines
=head1 SYNOPSIS
Generally useful routines
=head1 EXPORTED SUBROUTINES
=over 4
=item *
escape() : unpack non-word characters into CGI-compatible hex codes
=item *
unescape() : pack CGI-compatible hex codes into actual non-word ASCII character
=item *
add_get_param() :
Inputs: url (with or without exit GET from parameters), hash ref of
form name => value pairs
Return: url with properly added the form name elements and values to the
the url doing proper escaping of the values and joining with ? or &
as needed
=back