Annotation of loncom/metadata_database/searchcat.pl, revision 1.57
1.1 harris41 1: #!/usr/bin/perl
2: # The LearningOnline Network
3: # searchcat.pl "Search Catalog" batch script
1.16 harris41 4: #
1.57 ! matthew 5: # $Id: searchcat.pl,v 1.56 2004/04/09 22:04:53 matthew Exp $
1.16 harris41 6: #
7: # Copyright Michigan State University Board of Trustees
8: #
1.29 albertel 9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
1.16 harris41 10: #
1.29 albertel 11: # LON-CAPA is free software; you can redistribute it and/or modify
1.16 harris41 12: # it under the terms of the GNU General Public License as published by
13: # the Free Software Foundation; either version 2 of the License, or
14: # (at your option) any later version.
15: #
1.29 albertel 16: # LON-CAPA is distributed in the hope that it will be useful,
1.16 harris41 17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19: # GNU General Public License for more details.
20: #
21: # You should have received a copy of the GNU General Public License
1.29 albertel 22: # along with LON-CAPA; if not, write to the Free Software
1.16 harris41 23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24: #
25: # /home/httpd/html/adm/gpl.txt
26: #
1.29 albertel 27: # http://www.lon-capa.org/
1.16 harris41 28: #
29: ###
1.33 matthew 30:
1.32 www 31: =pod
1.1 harris41 32:
1.32 www 33: =head1 NAME
34:
35: B<searchcat.pl> - put authoritative filesystem data into sql database.
36:
37: =head1 SYNOPSIS
38:
39: Ordinarily this script is to be called from a loncapa cron job
40: (CVS source location: F<loncapa/loncom/cron/loncapa>; typical
41: filesystem installation location: F</etc/cron.d/loncapa>).
42:
43: Here is the cron job entry.
44:
45: C<# Repopulate and refresh the metadata database used for the search catalog.>
46: C<10 1 * * 7 www /home/httpd/perl/searchcat.pl>
47:
48: This script only allows itself to be run as the user C<www>.
49:
50: =head1 DESCRIPTION
51:
52: This script goes through a loncapa resource directory and gathers metadata.
53: The metadata is entered into a SQL database.
54:
55: This script also does general database maintenance such as reformatting
56: the C<loncapa:metadata> table if it is deprecated.
57:
58: This script evaluates dynamic metadata from the authors'
1.48 www 59: F<nohist_resevaldata.db> database file in order to store it in MySQL.
1.32 www 60:
61: This script is playing an increasingly important role for a loncapa
62: library server. The proper operation of this script is critical for a smooth
63: and correct user experience.
64:
65: =cut
1.1 harris41 66:
1.45 www 67: use strict;
68:
1.55 matthew 69: use DBI;
1.17 harris41 70: use lib '/home/httpd/lib/perl/';
71: use LONCAPA::Configuration;
1.55 matthew 72: use LONCAPA::lonmetadata;
1.17 harris41 73:
1.56 matthew 74: use Getopt::Long;
1.1 harris41 75: use IO::File;
76: use HTML::TokeParser;
1.21 www 77: use GDBM_File;
1.24 www 78: use POSIX qw(strftime mktime);
1.56 matthew 79:
1.55 matthew 80: use File::Find;
1.1 harris41 81:
1.56 matthew 82: #
83: # Set up configuration options
84: my ($simulate,$oneuser,$help,$verbose,$logfile,$debug);
85: GetOptions (
86: 'help' => \$help,
87: 'simulate' => \$simulate,
88: 'only=s' => \$oneuser,
89: 'verbose=s' => \$verbose,
90: 'debug' => \$debug,
91: );
92:
93: if ($help) {
94: print <<"ENDHELP";
95: $0
96: Rebuild and update the LON-CAPA metadata database.
97: Options:
98: -help Print this help
99: -simulate Do not modify the database.
100: -only=user Only compute for the given user. Implies -simulate
101: -verbose=val Sets logging level, val must be a number
102: -debug Turns on debugging output
103: ENDHELP
104: exit 0;
105: }
106:
107: if (! defined($debug)) {
108: $debug = 0;
109: }
110:
111: if (! defined($verbose)) {
112: $verbose = 0;
113: }
114:
115: if (defined($oneuser)) {
116: $simulate=1;
117: }
118:
1.55 matthew 119: ##
120: ## Use variables for table names so we can test this routine a little easier
121: my $oldname = 'metadata';
122: my $newname = 'newmetadata';
1.45 www 123:
1.55 matthew 124: #
125: # Read loncapa_apache.conf and loncapa.conf
126: my $perlvarref=LONCAPA::Configuration::read_conf('loncapa.conf');
127: my %perlvar=%{$perlvarref};
128: undef $perlvarref;
129: delete $perlvar{'lonReceipt'}; # remove since sensitive (really?) & not needed
130: #
131: # Only run if machine is a library server
132: exit if ($perlvar{'lonRole'} ne 'library');
133: #
134: # Make sure this process is running from user=www
135: my $wwwid=getpwnam('www');
136: if ($wwwid!=$<) {
137: my $emailto="$perlvar{'lonAdmEMail'},$perlvar{'lonSysEMail'}";
138: my $subj="LON: $perlvar{'lonHostID'} User ID mismatch";
139: system("echo 'User ID mismatch. searchcat.pl must be run as user www.' |\
140: mailto $emailto -s '$subj' > /dev/null");
141: exit 1;
142: }
143: #
144: # Let people know we are running
145: open(LOG,'>'.$perlvar{'lonDaemons'}.'/logs/searchcat.log');
1.56 matthew 146: &log(0,'==== Searchcat Run '.localtime()."====");
1.57 ! matthew 147:
! 148:
1.56 matthew 149: if ($debug) {
150: &log(0,'simulating') if ($simulate);
151: &log(0,'only processing user '.$oneuser) if ($oneuser);
152: &log(0,'verbosity level = '.$verbose);
153: }
1.55 matthew 154: #
155: # Connect to database
156: my $dbh;
157: if (! ($dbh = DBI->connect("DBI:mysql:loncapa","www",$perlvar{'lonSqlAccess'},
158: { RaiseError =>0,PrintError=>0}))) {
1.56 matthew 159: &log(0,"Cannot connect to database!");
1.55 matthew 160: die "MySQL Error: Cannot connect to database!\n";
161: }
162: # This can return an error and still be okay, so we do not bother checking.
163: # (perhaps it should be more robust and check for specific errors)
164: $dbh->do('DROP TABLE IF EXISTS '.$newname);
165: #
166: # Create the new table
167: my $request = &LONCAPA::lonmetadata::create_metadata_storage($newname);
168: $dbh->do($request);
169: if ($dbh->err) {
170: $dbh->disconnect();
1.56 matthew 171: &log(0,"MySQL Error Create: ".$dbh->errstr);
1.55 matthew 172: die $dbh->errstr;
173: }
174: #
175: # find out which users we need to examine
1.56 matthew 176: my $dom = $perlvar{'lonDefDomain'};
177: opendir(RESOURCES,"$perlvar{'lonDocRoot'}/res/$dom");
1.55 matthew 178: my @homeusers =
179: grep {
1.56 matthew 180: &ishome("$perlvar{'lonDocRoot'}/res/$dom/$_");
1.55 matthew 181: } grep {
182: !/^\.\.?$/;
183: } readdir(RESOURCES);
184: closedir RESOURCES;
185: #
1.56 matthew 186: if ($oneuser) {
187: @homeusers=($oneuser);
188: }
189: #
1.55 matthew 190: # Loop through the users
191: foreach my $user (@homeusers) {
1.56 matthew 192: &log(0,"=== User: ".$user);
193: &process_dynamic_metadata($user,$dom);
1.55 matthew 194: #
195: # Use File::Find to get the files we need to read/modify
196: find(
197: {preprocess => \&only_meta_files,
198: # wanted => \&print_filename,
199: # wanted => \&log_metadata,
200: wanted => \&process_meta_file,
201: },
202: "$perlvar{'lonDocRoot'}/res/$perlvar{'lonDefDomain'}/$user");
203: }
204: #
205: # Rename the table
1.56 matthew 206: if (! $simulate) {
207: $dbh->do('DROP TABLE IF EXISTS '.$oldname);
208: if (! $dbh->do('RENAME TABLE '.$newname.' TO '.$oldname)) {
209: &log(0,"MySQL Error Rename: ".$dbh->errstr);
210: die $dbh->errstr;
211: } else {
212: &log(1,"MySQL table rename successful.");
213: }
1.55 matthew 214: }
1.56 matthew 215:
1.55 matthew 216: if (! $dbh->disconnect) {
1.56 matthew 217: &log(0,"MySQL Error Disconnect: ".$dbh->errstr);
1.55 matthew 218: die $dbh->errstr;
219: }
220: ##
221: ## Finished!
1.56 matthew 222: &log(0,"==== Searchcat completed ".localtime()." ====");
1.55 matthew 223: close(LOG);
1.21 www 224:
1.55 matthew 225: &write_type_count();
226: &write_copyright_count();
1.36 www 227:
1.55 matthew 228: exit 0;
1.28 harris41 229:
1.56 matthew 230: ##
231: ## Status logging routine. Inputs: $level, $message
232: ##
233: ## $level 0 should be used for normal output and error messages
234: ##
235: ## $message does not need to end with \n. In the case of errors
236: ## the message should contain as much information as possible to
237: ## help in diagnosing the problem.
238: ##
239: sub log {
240: my ($level,$message)=@_;
241: $level = 0 if (! defined($level));
242: if ($verbose >= $level) {
243: print LOG $message.$/;
244: }
245: }
246:
1.55 matthew 247: ########################################################
248: ########################################################
249: ### ###
250: ### File::Find support routines ###
251: ### ###
252: ########################################################
253: ########################################################
254: ##
255: ## &only_meta_files
256: ##
257: ## Called by File::Find.
258: ## Takes a list of files/directories in and returns a list of files/directories
259: ## to search.
260: sub only_meta_files {
261: my @PossibleFiles = @_;
262: my @ChosenFiles;
263: foreach my $file (@PossibleFiles) {
264: if ( ($file =~ /\.meta$/ && # Ends in meta
265: $file !~ /\.\d+\.[^\.]+\.meta$/ # is not for a prior version
266: ) || (-d $file )) { # directories are okay
267: # but we do not want /. or /..
268: push(@ChosenFiles,$file);
269: }
1.38 www 270: }
1.55 matthew 271: return @ChosenFiles;
1.38 www 272: }
273:
1.55 matthew 274: ##
275: ##
276: ## Debugging routines, use these for 'wanted' in the File::Find call
277: ##
278: sub print_filename {
279: my ($file) = $_;
280: my $fullfilename = $File::Find::name;
1.56 matthew 281: if ($debug) {
282: if (-d $file) {
283: &log(5," Got directory ".$fullfilename);
284: } else {
285: &log(5," Got file ".$fullfilename);
286: }
1.38 www 287: }
1.55 matthew 288: $_=$file;
1.38 www 289: }
1.28 harris41 290:
1.55 matthew 291: sub log_metadata {
292: my ($file) = $_;
293: my $fullfilename = $File::Find::name;
294: return if (-d $fullfilename); # No need to do anything here for directories
1.56 matthew 295: if ($debug) {
296: &log(6,$fullfilename);
297: my $ref=&metadata($fullfilename);
298: if (! defined($ref)) {
299: &log(6," No data");
300: return;
301: }
302: while (my($key,$value) = each(%$ref)) {
303: &log(6," ".$key." => ".$value);
304: }
305: &count_copyright($ref->{'copyright'});
1.55 matthew 306: }
307: $_=$file;
1.31 harris41 308: }
1.21 www 309:
1.55 matthew 310: ##
311: ## process_meta_file
312: ## Called by File::Find.
313: ## Only input is the filename in $_.
314: sub process_meta_file {
315: my ($file) = $_;
1.56 matthew 316: my $filename = $File::Find::name; # full filename
1.55 matthew 317: return if (-d $filename); # No need to do anything here for directories
318: #
1.56 matthew 319: &log(3,$filename) if ($debug);
1.55 matthew 320: #
321: my $ref=&metadata($filename);
322: #
323: # $url is the original file url, not the metadata file
324: my $url='/res/'.&declutter($filename);
325: $url=~s/\.meta$//;
1.56 matthew 326: &log(3," ".$url) if ($debug);
1.55 matthew 327: #
328: # Ignore some files based on their metadata
329: if ($ref->{'obsolete'}) {
1.56 matthew 330: &log(3,"obsolete") if ($debug);
1.55 matthew 331: return;
332: }
333: &count_copyright($ref->{'copyright'});
334: if ($ref->{'copyright'} eq 'private') {
1.56 matthew 335: &log(3,"private") if ($debug);
1.55 matthew 336: return;
337: }
338: #
339: # Find the dynamic metadata
340: my %dyn;
341: if ($url=~ m:/default$:) {
342: $url=~ s:/default$:/:;
1.56 matthew 343: &log(3,"Skipping dynamic data") if ($debug);
1.55 matthew 344: } else {
1.56 matthew 345: &log(3,"Retrieving dynamic data") if ($debug);
346: %dyn=&get_dynamic_metadata($url);
1.55 matthew 347: &count_type($url);
348: }
349: #
350: $ref->{'creationdate'} = &sqltime($ref->{'creationdate'});
351: $ref->{'lastrevisiondate'} = &sqltime($ref->{'lastrevisiondate'});
352: my %Data = (
353: %$ref,
354: %dyn,
355: 'url'=>$url,
356: 'version'=>'current');
1.56 matthew 357: if (! $simulate) {
358: my ($count,$err) = &LONCAPA::lonmetadata::store_metadata($dbh,$newname,
359: \%Data);
360: if ($err) {
361: &log(0,"MySQL Error Insert: ".$err);
362: }
363: if ($count < 1) {
364: &log(0,"Unable to insert record into MySQL database for $url");
365: }
1.55 matthew 366: }
367: #
368: # Reset $_ before leaving
369: $_ = $file;
370: }
371:
372: ########################################################
373: ########################################################
374: ### ###
375: ### &metadata($uri) ###
376: ### Retrieve metadata for the given file ###
377: ### ###
378: ########################################################
379: ########################################################
380: sub metadata {
381: my ($uri)=@_;
382: my %metacache=();
383: $uri=&declutter($uri);
384: my $filename=$uri;
385: $uri=~s/\.meta$//;
386: $uri='';
387: if ($filename !~ /\.meta$/) {
388: $filename.='.meta';
389: }
390: my $metastring=&getfile($perlvar{'lonDocRoot'}.'/res/'.$filename);
391: return undef if (! defined($metastring));
392: my $parser=HTML::TokeParser->new(\$metastring);
393: my $token;
394: while ($token=$parser->get_token) {
395: if ($token->[0] eq 'S') {
396: my $entry=$token->[1];
397: my $unikey=$entry;
398: if (defined($token->[2]->{'part'})) {
399: $unikey.='_'.$token->[2]->{'part'};
400: }
401: if (defined($token->[2]->{'name'})) {
402: $unikey.='_'.$token->[2]->{'name'};
403: }
404: if ($metacache{$uri.'keys'}) {
405: $metacache{$uri.'keys'}.=','.$unikey;
406: } else {
407: $metacache{$uri.'keys'}=$unikey;
408: }
409: foreach ( @{$token->[3]}) {
410: $metacache{$uri.''.$unikey.'.'.$_}=$token->[2]->{$_};
411: }
412: if (! ($metacache{$uri.''.$unikey}=$parser->get_text('/'.$entry))){
413: $metacache{$uri.''.$unikey} =
414: $metacache{$uri.''.$unikey.'.default'};
415: }
416: } # End of ($token->[0] eq 'S')
417: }
418: return \%metacache;
1.31 harris41 419: }
1.28 harris41 420:
1.55 matthew 421: ##
422: ## &getfile($filename)
423: ## Slurps up an entire file into a scalar.
424: ## Returns undef if the file does not exist
425: sub getfile {
426: my $file = shift();
427: if (! -e $file ) {
428: return undef;
429: }
430: my $fh=IO::File->new($file);
431: my $contents = '';
432: while (<$fh>) {
433: $contents .= $_;
434: }
435: return $contents;
436: }
1.28 harris41 437:
1.55 matthew 438: ########################################################
439: ########################################################
440: ### ###
441: ### Dynamic Metadata ###
442: ### ###
443: ########################################################
444: ########################################################
1.56 matthew 445: ##
446: ## Dynamic metadata description
447: ##
448: ## Field Type
449: ##-----------------------------------------------------------
450: ## count integer
451: ## course integer
452: ## course_list comma seperated list of course ids
453: ## avetries real
454: ## avetries_list comma seperated list of real numbers
455: ## stdno real
456: ## stdno_list comma seperated list of real numbers
457: ## usage integer
458: ## usage_list comma seperated list of resources
459: ## goto scalar
460: ## goto_list comma seperated list of resources
461: ## comefrom scalar
462: ## comefrom_list comma seperated list of resources
463: ## difficulty real
464: ## difficulty_list comma seperated list of real numbers
465: ## sequsage scalar
466: ## sequsage_list comma seperated list of resources
467: ## clear real
468: ## technical real
469: ## correct real
470: ## helpful real
471: ## depth real
472: ## comments html of all the comments made
473: ##
474: {
475:
476: my %DynamicData;
477: my %Counts;
478:
479: sub process_dynamic_metadata {
480: my ($user,$dom) = @_;
481: undef(%DynamicData);
482: undef(%Counts);
483: #
484: my $prodir = &propath($dom,$user);
1.55 matthew 485: #
1.56 matthew 486: # Read in the dynamic metadata
1.55 matthew 487: my %evaldata;
488: if (! tie(%evaldata,'GDBM_File',
489: $prodir.'/nohist_resevaldata.db',&GDBM_READER(),0640)) {
1.56 matthew 490: return 0;
1.55 matthew 491: }
1.56 matthew 492: #
1.57 ! matthew 493: %DynamicData = &LONCAPA::lonmetadata::process_reseval_data(\%evaldata);
1.55 matthew 494: untie(%evaldata);
1.56 matthew 495: #
496: # Read in the access count data
497: &log(7,'Reading access count data') if ($debug);
498: my %countdata;
499: if (! tie(%countdata,'GDBM_File',
500: $prodir.'/nohist_accesscount.db',&GDBM_READER(),0640)) {
501: return 0;
502: }
503: while (my ($key,$count) = each(%countdata)) {
504: next if ($key !~ /^$dom/);
505: $key = &unescape($key);
506: &log(8,' Count '.$key.' = '.$count) if ($debug);
507: $Counts{$key}=$count;
508: }
509: untie(%countdata);
510: if ($debug) {
511: &log(7,scalar(keys(%Counts)).
512: " Counts read for ".$user."@".$dom);
513: &log(7,scalar(keys(%DynamicData)).
514: " Dynamic metadata read for ".$user."@".$dom);
515: }
516: #
517: return 1;
518: }
519:
520: sub get_dynamic_metadata {
521: my ($url) = @_;
522: $url =~ s:^/res/::;
523: if (! exists($DynamicData{$url})) {
524: &log(7,' No dynamic data for '.$url) if ($debug);
525: return ();
526: }
1.57 ! matthew 527: my %data = &LONCAPA::lonmetadata::process_dynamic_metadata($url,
! 528: \%DynamicData);
1.56 matthew 529: # find the count
530: $data{'count'} = $Counts{$url};
531: #
532: # Log the dynamic metadata
533: if ($debug) {
534: while (my($k,$v)=each(%data)) {
535: &log(8," ".$k." => ".$v);
536: }
1.44 www 537: }
1.56 matthew 538: return %data;
1.30 www 539: }
1.28 harris41 540:
1.56 matthew 541: } # End of %DynamicData and %Counts scope
542:
1.55 matthew 543: ########################################################
544: ########################################################
545: ### ###
546: ### Counts ###
547: ### ###
548: ########################################################
549: ########################################################
550: {
1.1 harris41 551:
1.55 matthew 552: my %countext;
1.15 harris41 553:
1.55 matthew 554: sub count_type {
555: my $file=shift;
556: $file=~/\.(\w+)$/;
557: my $ext=lc($1);
558: $countext{$ext}++;
1.31 harris41 559: }
1.1 harris41 560:
1.55 matthew 561: sub write_type_count {
562: open(RESCOUNT,'>/home/httpd/html/lon-status/rescount.txt');
563: while (my ($extension,$count) = each(%countext)) {
564: print RESCOUNT $extension.'='.$count.'&';
1.47 www 565: }
1.55 matthew 566: print RESCOUNT 'time='.time."\n";
567: close(RESCOUNT);
1.31 harris41 568: }
1.27 www 569:
1.55 matthew 570: } # end of scope for %countext
1.34 matthew 571:
1.55 matthew 572: {
1.34 matthew 573:
1.55 matthew 574: my %copyrights;
1.44 www 575:
1.55 matthew 576: sub count_copyright {
577: $copyrights{@_[0]}++;
1.31 harris41 578: }
1.33 matthew 579:
1.55 matthew 580: sub write_copyright_count {
581: open(COPYCOUNT,'>/home/httpd/html/lon-status/copyrightcount.txt');
582: while (my ($copyright,$count) = each(%copyrights)) {
583: print COPYCOUNT $copyright.'='.$count.'&';
1.31 harris41 584: }
1.55 matthew 585: print COPYCOUNT 'time='.time."\n";
586: close(COPYCOUNT);
1.31 harris41 587: }
1.28 harris41 588:
1.55 matthew 589: } # end of scope for %copyrights
1.28 harris41 590:
1.55 matthew 591: ########################################################
592: ########################################################
593: ### ###
594: ### Miscellanous Utility Routines ###
595: ### ###
596: ########################################################
597: ########################################################
598: ##
599: ## &ishome($username)
600: ## Returns 1 if $username is a LON-CAPA author, 0 otherwise
601: ## (copied from lond, modification of the return value)
1.31 harris41 602: sub ishome {
603: my $author=shift;
604: $author=~s/\/home\/httpd\/html\/res\/([^\/]*)\/([^\/]*).*/$1\/$2/;
605: my ($udom,$uname)=split(/\//,$author);
606: my $proname=propath($udom,$uname);
607: if (-e $proname) {
608: return 1;
609: } else {
610: return 0;
611: }
612: }
1.28 harris41 613:
1.55 matthew 614: ##
615: ## &propath($udom,$uname)
616: ## Returns the path to the users LON-CAPA directory
617: ## (copied from lond)
1.31 harris41 618: sub propath {
619: my ($udom,$uname)=@_;
620: $udom=~s/\W//g;
621: $uname=~s/\W//g;
622: my $subdir=$uname.'__';
623: $subdir =~ s/(.)(.)(.).*/$1\/$2\/$3/;
624: my $proname="$perlvar{'lonUsersDir'}/$udom/$subdir/$uname";
625: return $proname;
626: }
1.28 harris41 627:
1.55 matthew 628: ##
629: ## &sqltime($timestamp)
630: ##
631: ## Convert perl $timestamp to MySQL time. MySQL expects YYYY-MM-DD HH:MM:SS
632: ##
1.31 harris41 633: sub sqltime {
1.55 matthew 634: my ($time) = @_;
635: my $mysqltime;
636: if ($time =~
637: /(\d+)-(\d+)-(\d+) # YYYY-MM-DD
638: \s # a space
639: (\d+):(\d+):(\d+) # HH:MM::SS
640: /x ) {
641: # Some of the .meta files have the time in mysql
642: # format already, so just make sure they are 0 padded and
643: # pass them back.
644: $mysqltime = sprintf('%04d-%02d-%02d %02d:%02d:%02d',
645: $1,$2,$3,$4,$5,$6);
646: } elsif ($time =~ /^\d+$/) {
647: my @TimeData = gmtime($time);
648: # Alter the month to be 1-12 instead of 0-11
649: $TimeData[4]++;
650: # Alter the year to be from 0 instead of from 1900
651: $TimeData[5]+=1900;
652: $mysqltime = sprintf('%04d-%02d-%02d %02d:%02d:%02d',
653: @TimeData[5,4,3,2,1,0]);
1.56 matthew 654: } elsif (! defined($time) || $time == 0) {
655: $mysqltime = 0;
1.55 matthew 656: } else {
1.56 matthew 657: &log(0," sqltime:Unable to decode time ".$time);
1.55 matthew 658: $mysqltime = 0;
659: }
660: return $mysqltime;
1.31 harris41 661: }
1.28 harris41 662:
1.55 matthew 663: ##
664: ## &declutter($filename)
665: ## Given a filename, returns a url for the filename.
666: sub declutter {
667: my $thisfn=shift;
668: $thisfn=~s/^$perlvar{'lonDocRoot'}//;
669: $thisfn=~s/^\///;
670: $thisfn=~s/^res\///;
671: return $thisfn;
1.31 harris41 672: }
1.28 harris41 673:
1.55 matthew 674: ##
675: ## Escape / Unescape special characters
676: sub unescape {
677: my $str=shift;
678: $str =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
679: return $str;
1.31 harris41 680: }
1.28 harris41 681:
1.55 matthew 682: sub escape {
683: my $str=shift;
684: $str =~ s/(\W)/"%".unpack('H2',$1)/eg;
685: return $str;
1.45 www 686: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>