[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm lonindexer.pm
foxr
lon-capa-cvs@mail.lon-capa.org
Thu, 21 Oct 2004 09:53:44 -0000
foxr Thu Oct 21 05:53:44 2004 EDT
Modified files:
/loncom/interface loncommon.pm lonindexer.pm
Log:
Move javascript_escape into loncommon.pm per Guy's good suggestion.
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.220 loncom/interface/loncommon.pm:1.221
--- loncom/interface/loncommon.pm:1.220 Fri Oct 15 12:51:29 2004
+++ loncom/interface/loncommon.pm Thu Oct 21 05:53:44 2004
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.220 2004/10/15 16:51:29 matthew Exp $
+# $Id: loncommon.pm,v 1.221 2004/10/21 09:53:44 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -3732,6 +3732,31 @@
return $c->aborted();
}
+#
+# Escapes strings that may have embedded 's that will be put into
+# javascript strings as 'strings'.
+# The assumptions are:
+# There has been no effort to escape ' with \'
+# Any \'s in the string are intended to be there as part of the URL
+# and must also be escaped.
+# Parameters:
+# input - The string to escape.
+# Returns:
+# The escaped string (' replaced by \' and \ replaced by \\).
+#
+sub javascript_escape {
+ my ($input) = @_;
+
+ # I imagine a regexp wizard could combine the two expressions below.
+ # If you do you might want to comment the result.
+
+ $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
+ $input =~ s/\'/\\\'/g; # Esacpe the 's....
+
+ return $input;
+}
+
+
=pod
=back
Index: loncom/interface/lonindexer.pm
diff -u loncom/interface/lonindexer.pm:1.126 loncom/interface/lonindexer.pm:1.127
--- loncom/interface/lonindexer.pm:1.126 Wed Oct 20 06:54:08 2004
+++ loncom/interface/lonindexer.pm Thu Oct 21 05:53:44 2004
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Directory Indexer
#
-# $Id: lonindexer.pm,v 1.126 2004/10/20 10:54:08 foxr Exp $
+# $Id: lonindexer.pm,v 1.127 2004/10/21 09:53:44 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -846,7 +846,7 @@
$diropen.'.gif"');
$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
"\n");
- my $quotable_filecom = &javascript_escape($filecom[0]);
+ my $quotable_filecom = &Apache::loncommon::javascript_escape($filecom[0]);
$r->print ('<a href="javascript:gothere(\''.$quotable_filecom.
'\')"><img src="'.$iconpath.'server.gif"');
$r->print (' border="0" /></a>'."\n");
@@ -874,7 +874,7 @@
'.gif"');
$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
"\n");
- my $quotable_curdir = &javascript_escape($curdir);
+ my $quotable_curdir = &Apache::loncommon::javascript_escape($curdir);
$r->print ('<a href="javascript:gothere(\''.$quotable_curdir
.'\')"><img src='.
$iconpath.'quill.gif border="0" name="'.$msg.
@@ -905,7 +905,7 @@
$r->print("<tr valign='$valign' bgcolor=$fileclr><td nowrap='1' align='top'>");
if ($ENV{'form.catalogmode'} eq 'interactive') {
- my $quotable_filelink = &javascript_escape($filelink);
+ my $quotable_filelink = &Apache::loncommon::javascript_escape($filelink);
$r->print("<a href=\"javascript:select_data(\'",
$quotable_filelink,"')\">");
$r->print("<img src='",$iconpath,"select.gif' border='0' /></a>".
@@ -966,7 +966,7 @@
if ($filelink=~/\.(page|sequence)$/) {
$r->print('</form>');
}
- my $quotable_filelink = &javascript_escape($filelink);
+ my $quotable_filelink = &Apache::loncommon::javascript_escape($filelink);
$r->print (" <a href=\"javascript:openWindow('".$quotable_filelink.
@@ -1033,7 +1033,7 @@
my $source = &Apache::lonnet::metadata($filelink,'sourceavail');
if($source eq 'open') {
my $sourcelink = &Apache::lonsource::make_link($filelink,$listname);
- my $quotable_sourcelink = &javascript_escape($sourcelink);
+ my $quotable_sourcelink = &Apache::loncommon::javascript_escape($sourcelink);
$r->print('<td>'."<a href=\"javascript:openWindow('"
.$quotable_sourcelink.
"', 'previewsource', '700', '700', 'no', 'yes','yes')\";".
@@ -1112,7 +1112,7 @@
'folder_pointer_'.$diropen.'.gif"');
$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
"\n");
- my $quotable_curdir = &javascript_escape($curdir);
+ my $quotable_curdir = &Apache::loncommon::javascript_escape($curdir);
$r->print ('<a href="javascript:gothere(\''
.$quotable_curdir.'\')"><img src="'.
$iconpath.'folder_'.$diropen.'.gif" border="0" /></a>'.
@@ -1233,29 +1233,6 @@
}
-#
-# Escapes strings that may have embedded 's that will be put into
-# javascript strings as 'strings'.
-# The assumptions are:
-# There has been no effort to escape ' with \'
-# Any \'s in the string are intended to be there as part of the URL
-# and must also be escaped.
-# Parameters:
-# input - The string to escape.
-# Returns:
-# The escaped string (' replaced by \' and \ replaced by \\).
-#
-sub javascript_escape {
- my ($input) = @_;
-
- # I imagine a regexp wizard could combine the two expressions below.
- # If you do you might want to comment the result.
-
- $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
- $input =~ s/\'/\\\'/g; # Esacpe the 's....
-
- return $input;
-}